using System.Collections.Generic; using System.Reflection.Emit; using System.Threading; using BepInEx.Configuration; using HarmonyLib; using Random = UnityEngine.Random; namespace CheatEnabler; public static class PlanetFunctions { public static ConfigEntry PlayerActionsInGlobeViewEnabled; public static void Init() { PlayerActionsInGlobeViewEnabled.SettingChanged += (_, _) => PlayerActionInGlobeViewValueChanged(); PlayerActionInGlobeViewValueChanged(); } public static void Uninit() { PlayerActionInGlobeView.Enable(false); } private static void PlayerActionInGlobeViewValueChanged() { PlayerActionInGlobeView.Enable(PlayerActionsInGlobeViewEnabled.Value); } public static class PlayerActionInGlobeView { private static Harmony _patch; public static void Enable(bool on) { if (on) { _patch ??= Harmony.CreateAndPatchAll(typeof(PlayerActionInGlobeView)); return; } _patch?.UnpatchSelf(); _patch = null; } [HarmonyTranspiler] [HarmonyPatch(typeof(VFInput), nameof(VFInput.UpdateGameStates))] private static IEnumerable VFInput_UpdateGameStates_Transpiler(IEnumerable instructions, ILGenerator generator) { var matcher = new CodeMatcher(instructions, generator); /* remove UIGame.viewMode != EViewMode.Globe in two places: * so search for: * ldsfld bool VFInput::viewMode * ldc.i4.3 */ matcher.MatchForward(false, new CodeMatch(OpCodes.Ldsfld, AccessTools.Field(typeof(UIGame), nameof(UIGame.viewMode))), new CodeMatch(OpCodes.Ldc_I4_3) ); matcher.Repeat(codeMatcher => { var labels = codeMatcher.Labels; codeMatcher.Labels = new List