using System; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using TMPro; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("0.0.0.0")] namespace SidewaysGuns; [HarmonyPatch(typeof(PlayerToolMovement), "ApplyPosRotToModel")] internal static class PlayerToolMovement_ApplyPosRotToModel_Patch { private static void Postfix(PlayerToolMovement __instance) { SidewaysController.Apply(__instance); } } [HarmonyPatch(typeof(ButtonManager), "SetupUI")] internal static class ButtonManager_SetupUI_Patch { private static void Postfix(ButtonManager __instance) { SettingsToggleInjector.Inject(__instance); } } internal static class SidewaysController { public static void Apply(PlayerToolMovement movement) { //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) if (!SidewaysGunsPlugin.Enabled || (Object)(object)movement == (Object)null) { return; } Tool currentTool = movement.CurrentTool; if ((Object)(object)currentTool == (Object)null || (Object)(object)((Item)currentTool).Weapon == (Object)null) { return; } Transform swayTransform = currentTool.SwayTransform; Transform swayRotAroundTransform = currentTool.SwayRotAroundTransform; if (!((Object)(object)swayTransform == (Object)null) && !((Object)(object)swayRotAroundTransform == (Object)null)) { float num = 90f; if ((Object)(object)SidewaysGunsPlugin.Instance != (Object)null) { num = SidewaysGunsPlugin.Instance.RollAngle.Value; } swayTransform.RotateAround(swayRotAroundTransform.position, swayTransform.forward, num); } } } internal static class SettingsToggleInjector { private const string RowObjectName = "SidewaysGunsRow"; private static readonly FieldInfo _itemDotsToggleField = typeof(ButtonManager).GetField("_itemDotsToggle", BindingFlags.Instance | BindingFlags.NonPublic); public static void Inject(ButtonManager instance) { if ((Object)(object)instance == (Object)null) { return; } if (_itemDotsToggleField == null) { Debug.LogWarning((object)"[SidewaysGuns] _itemDotsToggle field not found."); return; } object? value = _itemDotsToggleField.GetValue(instance); Toggle val = (Toggle)((value is Toggle) ? value : null); if (val == null || (Object)(object)val == (Object)null) { Debug.LogWarning((object)"[SidewaysGuns] Item Dots toggle not found."); return; } Transform parent = ((Component)val).transform.parent; if ((Object)(object)parent == (Object)null) { return; } Transform parent2 = parent.parent; if ((Object)(object)parent2 == (Object)null) { return; } Transform val2 = parent2.Find("SidewaysGunsRow"); if ((Object)(object)val2 != (Object)null) { Toggle componentInChildren = ((Component)val2).GetComponentInChildren(true); if ((Object)(object)componentInChildren != (Object)null) { WireToggle(componentInChildren); } return; } GameObject val3 = Object.Instantiate(((Component)parent).gameObject, parent2); ((Object)val3).name = "SidewaysGunsRow"; Toggle componentInChildren2 = val3.GetComponentInChildren(true); if ((Object)(object)componentInChildren2 == (Object)null) { Object.Destroy((Object)(object)val3); Debug.LogWarning((object)"[SidewaysGuns] Cloned row has no Toggle."); return; } TextMeshProUGUI val4 = FindLabel(val3.transform); if ((Object)(object)val4 != (Object)null) { DisableLocalization(val4); ((TMP_Text)val4).text = "Sideways Guns"; } val3.transform.SetSiblingIndex(parent.GetSiblingIndex() + 1); WireToggle(componentInChildren2); RebuildLayouts(parent2); } private static void WireToggle(Toggle toggle) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Expected O, but got Unknown toggle.onValueChanged = new ToggleEvent(); toggle.isOn = SidewaysGunsPlugin.Enabled; ((UnityEvent)(object)toggle.onValueChanged).AddListener((UnityAction)delegate(bool value) { SidewaysGunsPlugin.SetEnabled(value); }); } private static TextMeshProUGUI FindLabel(Transform row) { Toggle componentInChildren = ((Component)row).GetComponentInChildren(true); TextMeshProUGUI[] componentsInChildren = ((Component)row).GetComponentsInChildren(true); if (componentsInChildren == null || componentsInChildren.Length == 0) { return null; } TextMeshProUGUI[] array = componentsInChildren; foreach (TextMeshProUGUI val in array) { if (!((Object)(object)componentInChildren != (Object)null) || !((TMP_Text)val).transform.IsChildOf(((Component)componentInChildren).transform)) { return val; } } return null; } private static void DisableLocalization(TextMeshProUGUI label) { MonoBehaviour[] components = ((Component)label).GetComponents(); foreach (MonoBehaviour val in components) { if (!((Object)(object)val == (Object)null)) { string name = ((object)val).GetType().Name; if (name.IndexOf("Localize", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("Localized", StringComparison.OrdinalIgnoreCase) >= 0) { ((Behaviour)val).enabled = false; } } } } private static void RebuildLayouts(Transform panel) { if ((Object)(object)((Component)panel).GetComponent() != (Object)null) { LayoutRebuilder.ForceRebuildLayoutImmediate((RectTransform)(object)((panel is RectTransform) ? panel : null)); } Canvas.ForceUpdateCanvases(); } } [BepInPlugin("com.pulsion.howtofish.sidewaysguns", "Sideways Guns", "1.1.0")] public class SidewaysGunsPlugin : BaseUnityPlugin { public const string EnabledPrefKey = "SidewaysGuns"; internal ConfigEntry RollAngle; private Harmony _harmony; public static SidewaysGunsPlugin Instance { get; private set; } public static bool Enabled { get; private set; } = true; private void Awake() { //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Expected O, but got Unknown Instance = this; Enabled = PlayerPrefs.GetInt("SidewaysGuns", 1) == 1; RollAngle = ((BaseUnityPlugin)this).Config.Bind("General", "RollAngle", 90f, "Degrees to roll held guns sideways. 90 = fully sideways, -90 = tilted the other way."); _harmony = new Harmony("com.pulsion.howtofish.sidewaysguns"); _harmony.PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded Sideways Guns v1.1.0"); } private void OnDestroy() { Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } _harmony = null; } public static void SetEnabled(bool value) { Enabled = value; PlayerPrefs.SetInt("SidewaysGuns", value ? 1 : 0); PlayerPrefs.Save(); } } internal static class PluginInfo { public const string PLUGIN_GUID = "com.pulsion.howtofish.sidewaysguns"; public const string PLUGIN_NAME = "Sideways Guns"; public const string PLUGIN_VERSION = "1.1.0"; }