Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of MapUnlocker v1.2.0
MapUnlocker.dll
Decompiled 6 months agousing System; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("MapUnlocker")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.2.0.0")] [assembly: AssemblyInformationalVersion("1.2.0+c4443989dc70c211efe912ba1ee9a0eb51d54bf2")] [assembly: AssemblyProduct("MapUnlocker")] [assembly: AssemblyTitle("MapUnlocker")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.2.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace MapUnlocker { public class ConfigUI { private ManualLogSource Logger; private ResetManager resetManager; private MapUnlocker plugin; public ConfigEntry<bool>? debugMode; public ConfigEntry<bool>? resetDataAfterLeaving; public ConfigEntry<bool>? hasQuill; public ConfigEntry<bool>? unlockAllMapsAtStart; public ConfigEntry<bool>? unlockAllMaps; public ConfigEntry<bool>[]? mapConfigs; public ConfigEntry<bool>? unlockAllPinsAtStart; public ConfigEntry<bool>? unlockAllPins; public ConfigEntry<bool>[]? pinConfigs; public ConfigEntry<bool>? unlockAllMarkersAtStart; public ConfigEntry<bool>? unlockAllMarkers; public ConfigEntry<bool>[]? markerConfigs; private static bool allowChangeAllMaps = true; private static bool isChangingAllMaps = false; private static bool allowChangeAllPins = true; private static bool isChangingAllPins = false; private static bool allowChangeAllMarkers = true; private static bool isChangingAllMarkers = false; private ConfigFile Config => ((BaseUnityPlugin)plugin).Config; public ConfigUI(ManualLogSource logger, ResetManager resetManager, MapUnlocker plugin) { Logger = logger; this.resetManager = resetManager; this.plugin = plugin; } public void InitializeConfig() { debugMode = Config.Bind<bool>("Debug", "Debug mode", false, "Enables log messages for debugging purposes."); resetDataAfterLeaving = Config.Bind<bool>("General", "Reset Maps after leaving", false, "Resets all maps to original state after leaving."); hasQuill = Config.Bind<bool>("General", "Has Quill", false, "Enables the quill tool."); unlockAllMapsAtStart = Config.Bind<bool>("Maps", "Unlock All Maps At Start", false, "Unlock All Maps At the Start"); mapConfigs = new ConfigEntry<bool>[29] { unlockAllMaps = Config.Bind<bool>("Maps", "Unlock All Maps Now", false, "Unlock All Maps"), Config.Bind<bool>("Maps", "Unlock the Map for Moss Grotto", false, "Unlock Moss Grotto"), Config.Bind<bool>("Maps", "Unlock the Map for Wilds", false, "Unlock Wilds"), Config.Bind<bool>("Maps", "Unlock the Map for Bone forest", false, "Unlock Bone forest"), Config.Bind<bool>("Maps", "Unlock the Map for Docks", false, "Unlock Docks"), Config.Bind<bool>("Maps", "Unlock the Map for Greymoor", false, "Unlock Greymoor"), Config.Bind<bool>("Maps", "Unlock the Map for Bellhart", false, "Unlock Bellhart"), Config.Bind<bool>("Maps", "Unlock the Map for Shellwood", false, "Unlock Shellwood"), Config.Bind<bool>("Maps", "Unlock the Map for Crawl", false, "Unlock Crawl"), Config.Bind<bool>("Maps", "Unlock the Map for Hunters Nest", false, "Unlock Hunters Nest"), Config.Bind<bool>("Maps", "Unlock the Map for Judge Steps", false, "Unlock Judge Steps"), Config.Bind<bool>("Maps", "Unlock the Map for Dustpens", false, "Unlock Dustpens"), Config.Bind<bool>("Maps", "Unlock the Map for Slab", false, "Unlock Slab"), Config.Bind<bool>("Maps", "Unlock the Map for Peak", false, "Unlock Peak"), Config.Bind<bool>("Maps", "Unlock the Map for Citadel Understore", false, "Unlock Citadel Understore"), Config.Bind<bool>("Maps", "Unlock the Map for Coral", false, "Unlock Coral"), Config.Bind<bool>("Maps", "Unlock the Map for Swamp", false, "Unlock Swamp"), Config.Bind<bool>("Maps", "Unlock the Map for Clover", false, "Unlock Clover"), Config.Bind<bool>("Maps", "Unlock the Map for Abyss", false, "Unlock Abyss"), Config.Bind<bool>("Maps", "Unlock the Map for Hang", false, "Unlock Hang"), Config.Bind<bool>("Maps", "Unlock the Map for SongGate", false, "Unlock SongGate"), Config.Bind<bool>("Maps", "Unlock the Map for Halls", false, "Unlock Halls"), Config.Bind<bool>("Maps", "Unlock the Map for Ward", false, "Unlock Ward"), Config.Bind<bool>("Maps", "Unlock the Map for Cog", false, "Unlock Cog"), Config.Bind<bool>("Maps", "Unlock the Map for Library", false, "Unlock Library"), Config.Bind<bool>("Maps", "Unlock the Map for Cradle", false, "Unlock Cradle"), Config.Bind<bool>("Maps", "Unlock the Map for Arborium", false, "Unlock Arborium"), Config.Bind<bool>("Maps", "Unlock the Map for Aqueduct", false, "Unlock Aqueduct"), Config.Bind<bool>("Maps", "Unlock the Map for Weavehome", false, "Unlock Weavehome") }; unlockAllPinsAtStart = Config.Bind<bool>("Pins", "Unlock All Pins At Start", false, "Unlock All Pins At the Start"); unlockAllPins = Config.Bind<bool>("Pins", "Unlock All Pins Now", false, "Unlock All Pins"); pinConfigs = new ConfigEntry<bool>[12] { Config.Bind<bool>("Pins", "Unlock the Bench Pin", false, "Unlock Bench Pin"), Config.Bind<bool>("Pins", "Unlock the Cocoon Pin", false, "Unlock Cocoon Pin"), Config.Bind<bool>("Pins", "Unlock the Shop Pin forest", false, "Unlock Bone Shop Pin"), Config.Bind<bool>("Pins", "Unlock the Spa Pin", false, "Unlock Spa Pin"), Config.Bind<bool>("Pins", "Unlock the Stag Pin", false, "Unlock Stag Pin"), Config.Bind<bool>("Pins", "Unlock the Tube Pin", false, "Unlock Tube Pin"), Config.Bind<bool>("Pins", "Unlock the FleaMarrowlands Pin", false, "Unlock FleaMarrowlands Pin"), Config.Bind<bool>("Pins", "Unlock the FleaMidlands Pin", false, "Unlock FleaMidlands Pin"), Config.Bind<bool>("Pins", "Unlock the FleaBlastedlands Pin Nest", false, "Unlock Hunters FleaBlastedlands Pin"), Config.Bind<bool>("Pins", "Unlock the FleaCitadel Pin Steps", false, "Unlock Judge FleaCitadel Pin"), Config.Bind<bool>("Pins", "Unlock the FleaPeaklands Pin", false, "Unlock FleaPeaklands Pin"), Config.Bind<bool>("Pins", "Unlock the FleaMucklands Pin", false, "Unlock FleaMucklands Pin") }; unlockAllMarkersAtStart = Config.Bind<bool>("Markers", "Unlock All Markers At Start", false, "Unlock All Markers At the Start"); unlockAllMarkers = Config.Bind<bool>("Markers", "Unlock All Markers Now", false, "Unlock All Markers"); markerConfigs = new ConfigEntry<bool>[5] { Config.Bind<bool>("Markers", "Unlock the hasMarker_a", false, "Unlock hasMarker_a"), Config.Bind<bool>("Markers", "Unlock the hasMarker_b", false, "Unlock hasMarker_b"), Config.Bind<bool>("Markers", "Unlock the hasMarker_c", false, "Unlock hasMarker_c"), Config.Bind<bool>("Markers", "Unlock the hasMarker_d", false, "Unlock hasMarker_d"), Config.Bind<bool>("Markers", "Unlock the hasMarker_e", false, "Unlock hasMarker_e") }; Config.Save(); resetDataAfterLeaving.SettingChanged += delegate { if (resetDataAfterLeaving.Value) { resetManager.StoreOriginalData(); } }; hasQuill.SettingChanged += delegate { plugin.changeQuillBool(hasQuill.Value); }; unlockAllMaps.SettingChanged += delegate { OnConfigChangeAll(unlockAllMaps.Value, MapUnlocker.MAPS); }; unlockAllPins.SettingChanged += delegate { OnConfigChangeAll(unlockAllPins.Value, MapUnlocker.PINS); }; unlockAllMarkers.SettingChanged += delegate { OnConfigChangeAll(unlockAllMarkers.Value, MapUnlocker.MARKERS); }; for (int i = 1; i < mapConfigs.Length; i++) { int currentMap = i; mapConfigs[currentMap].SettingChanged += delegate { OnConfigChange(MapUnlocker.playerDataFieldsBools[MapUnlocker.MAPS][currentMap], mapConfigs[currentMap].Value, ref allowChangeAllMaps, ref isChangingAllMaps, ref unlockAllMaps); if (!mapConfigs[currentMap].Value) { plugin.SetPlayerDataBool(MapUnlocker.playerDataFieldsBools[MapUnlocker.MAPS][MapUnlocker.ALL_FIELDS], value: false); } }; } for (int j = 0; j < pinConfigs.Length; j++) { int currentPin = j; pinConfigs[currentPin].SettingChanged += delegate { OnConfigChange(MapUnlocker.playerDataFieldsBools[MapUnlocker.PINS][currentPin], pinConfigs[currentPin].Value, ref allowChangeAllPins, ref isChangingAllPins, ref unlockAllPins); }; } for (int k = 0; k < markerConfigs.Length; k++) { int currentMarker = k; markerConfigs[currentMarker].SettingChanged += delegate { OnConfigChange(MapUnlocker.playerDataFieldsBools[MapUnlocker.MARKERS][currentMarker + 1], markerConfigs[currentMarker].Value, ref allowChangeAllMarkers, ref isChangingAllMarkers, ref unlockAllMarkers); bool? playerDataBoolValue = MapUnlocker.GetPlayerDataBoolValue(MapUnlocker.playerDataFieldsBools[MapUnlocker.MARKERS][0]); if (playerDataBoolValue.HasValue) { if (markerConfigs[currentMarker].Value && playerDataBoolValue == false) { plugin.SetPlayerDataBool(MapUnlocker.playerDataFieldsBools[MapUnlocker.MARKERS][0], value: true); } } else { Logger.LogError((object)"hasMarkerField is null!"); } }; } if (debugMode.Value) { Logger.LogInfo((object)$"Configuration initialized with {mapConfigs.Length} map configs"); } } public void ChangeConfigData(ConfigEntry<bool>[] configBools, string[] dataFields) { if (PlayerData.instance != null) { for (int i = 0; i < dataFields.Length && i < configBools.Length; i++) { FieldInfo field = ((object)PlayerData.instance).GetType().GetField(dataFields[i], BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field != null && field.FieldType == typeof(bool)) { bool value = (bool)field.GetValue(PlayerData.instance); configBools[i].Value = value; if (debugMode.Value) { Logger.LogInfo((object)$"{dataFields[i]}: {configBools[i].Value}"); } } } } else if (debugMode.Value) { Logger.LogInfo((object)"(PlayerData.instance is null"); } } public void ChangeConfigData(ConfigEntry<bool>[] configBools, FieldInfo[] dataFields) { if (PlayerData.instance != null) { for (int i = 0; i < dataFields.Length && i < configBools.Length; i++) { FieldInfo fieldInfo = dataFields[i]; if (fieldInfo != null && fieldInfo.FieldType == typeof(bool)) { bool value = (bool)fieldInfo.GetValue(PlayerData.instance); configBools[i].Value = value; if (debugMode.Value) { Logger.LogInfo((object)$"{dataFields[i]}: {configBools[i].Value}"); } } } } else if (debugMode.Value) { Logger.LogInfo((object)"(PlayerData.instance is null"); } } public void OnConfigChangeAll(bool value, int choice) { switch (choice) { default: OnConfigChangeAll(value, mapConfigs, ref allowChangeAllMaps, ref isChangingAllMaps); break; case 1: OnConfigChangeAll(value, pinConfigs, ref allowChangeAllPins, ref isChangingAllPins); break; case 2: OnConfigChangeAll(value, markerConfigs, ref allowChangeAllMarkers, ref isChangingAllMarkers); break; } } public void OnConfigChangeAll(bool value, ConfigEntry<bool>[] entries, ref bool allowChangeAll, ref bool isChangingAll) { if (debugMode.Value) { Logger.LogInfo((object)("allowChangeAll: " + allowChangeAll)); } if (!allowChangeAll) { allowChangeAll = true; return; } if (PlayerData.instance != null) { isChangingAll = true; for (int i = 0; i < entries.Length; i++) { entries[i].Value = value; } } else if (debugMode.Value) { Logger.LogInfo((object)"PlayerData could not be found"); } isChangingAll = false; } private void OnConfigChange(string fieldName, bool value, ref bool allowChangeAll, ref bool isChangingAll, ref ConfigEntry<bool> unlockAllConfig) { string text = (value ? "Unlocked" : "Locked"); if (PlayerData.instance == null) { return; } if (plugin.SetPlayerDataBool(PlayerData.instance, fieldName, value)) { if (!value) { if (debugMode.Value) { Logger.LogInfo((object)("before isChangingAll: " + isChangingAll)); } if (!isChangingAll) { allowChangeAll = false; } if (debugMode.Value) { Logger.LogInfo((object)("after allowChangeAll: " + allowChangeAll)); } unlockAllConfig.Value = value; } } else if (debugMode.Value) { Logger.LogInfo((object)(fieldName + " could not be " + text + "!")); } } private void OnConfigChange(FieldInfo fieldInfo, bool value, ref bool allowChangeAll, ref bool isChangingAll, ref ConfigEntry<bool> unlockAllConfig) { string text = (value ? "Unlocked" : "Locked"); if (PlayerData.instance != null && fieldInfo != null) { if (!(fieldInfo.FieldType == typeof(bool))) { return; } if (plugin.SetPlayerDataBool(fieldInfo, value)) { if (!value) { if (debugMode.Value) { Logger.LogInfo((object)("before isChangingAll: " + isChangingAll)); } if (!isChangingAll) { allowChangeAll = false; } if (debugMode.Value) { Logger.LogInfo((object)("after allowChangeAll: " + allowChangeAll)); } unlockAllConfig.Value = value; } } else if (debugMode.Value) { Logger.LogInfo((object)(fieldInfo.Name + " could not be " + text + "!")); } } else if (debugMode.Value) { Logger.LogInfo((object)"FieldInfo is null or PlayerData.instance is null"); } } } [BepInPlugin("MapUnlocker", "MapUnlocker", "1.2.0")] public class MapUnlocker : BaseUnityPlugin { private Harmony harmony; public static readonly int ALL_FIELDS = 0; public static readonly int MAPS = 0; public static readonly int PINS = 1; public static readonly int MARKERS = 2; public ResetManager resetManager; public ConfigUI configUI; private OnStartManager onStartManager; public static readonly string[] mapFields = new string[29] { "mapAllRooms", "HasMossGrottoMap", "HasWildsMap", "HasBoneforestMap", "HasDocksMap", "HasGreymoorMap", "HasBellhartMap", "HasShellwoodMap", "HasCrawlMap", "HasHuntersNestMap", "HasJudgeStepsMap", "HasDustpensMap", "HasSlabMap", "HasPeakMap", "HasCitadelUnderstoreMap", "HasCoralMap", "HasSwampMap", "HasCloverMap", "HasAbyssMap", "HasHangMap", "HasSongGateMap", "HasHallsMap", "HasWardMap", "HasCogMap", "HasLibraryMap", "HasCradleMap", "HasArboriumMap", "HasAqueductMap", "HasWeavehomeMap" }; public static readonly string[] pinFields = new string[12] { "hasPinBench", "hasPinCocoon", "hasPinShop", "hasPinSpa", "hasPinStag", "hasPinTube", "hasPinFleaMarrowlands", "hasPinFleaMidlands", "hasPinFleaBlastedlands", "hasPinFleaCitadel", "hasPinFleaPeaklands", "hasPinFleaMucklands" }; public static readonly string[] markerFields = new string[6] { "hasMarker", "hasMarker_a", "hasMarker_b", "hasMarker_c", "hasMarker_d", "hasMarker_e" }; public static readonly FieldInfo[][] playerDataFieldsBools = new FieldInfo[3][] { mapFields.Select((string fieldName) => typeof(PlayerData).GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)).ToArray(), pinFields.Select((string fieldName) => typeof(PlayerData).GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)).ToArray(), markerFields.Select((string fieldName) => typeof(PlayerData).GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)).ToArray() }; public ManualLogSource Logger => ((BaseUnityPlugin)this).Logger; public static MapUnlocker Instance { get; private set; } = null; private void Awake() { //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Expected O, but got Unknown Logger.LogInfo((object)"Plugin MapUnlocker has loaded!"); Logger.LogInfo((object)"Plugin version: 1.2.0"); Instance = this; resetManager = new ResetManager(Logger, this); configUI = new ConfigUI(Logger, resetManager, this); resetManager.SetConfigUI(configUI); configUI.InitializeConfig(); harmony = new Harmony("MapUnlocker"); harmony.PatchAll(); Logger.LogInfo((object)"Harmony patches applied successfully!"); onStartManager = new OnStartManager(Logger, this); Logger.LogInfo((object)"Map Unlocker mod initialization completed"); } private void OnDestroy() { Harmony obj = harmony; if (obj != null) { obj.UnpatchSelf(); } } public static bool GetPlayerDataBoolValue(int category, int index) { if (PlayerData.instance == null || category < 0 || category >= playerDataFieldsBools.Length || index < 0 || index >= playerDataFieldsBools[category].Length || playerDataFieldsBools[category][index] == null) { return false; } FieldInfo fieldInfo = playerDataFieldsBools[category][index]; if (fieldInfo.FieldType == typeof(bool)) { return (bool)fieldInfo.GetValue(PlayerData.instance); } return false; } public static bool? GetPlayerDataBoolValue(FieldInfo fieldInfo) { if (PlayerData.instance != null && fieldInfo != null && fieldInfo.FieldType == typeof(bool)) { return (bool)fieldInfo.GetValue(PlayerData.instance); } return null; } public bool SetPlayerDataBool(object playerData, string fieldName, bool value) { try { FieldInfo field = playerData.GetType().GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field != null && field.FieldType == typeof(bool)) { field.SetValue(playerData, value); Logger.LogInfo((object)$"{fieldName}: {value}"); return true; } ConfigEntry<bool>? debugMode = configUI.debugMode; if (debugMode != null && debugMode.Value) { Logger.LogWarning((object)("Field " + fieldName + " not found or not boolean")); } return false; } catch (Exception ex) { ConfigEntry<bool>? debugMode2 = configUI.debugMode; if (debugMode2 != null && debugMode2.Value) { Logger.LogError((object)("Error setting " + fieldName + ": " + ex.Message)); } return false; } } public bool SetPlayerDataBool(FieldInfo fieldInfo, bool value) { if (PlayerData.instance != null && fieldInfo != null) { if (fieldInfo.FieldType == typeof(bool)) { fieldInfo.SetValue(PlayerData.instance, value); ConfigEntry<bool>? debugMode = configUI.debugMode; if (debugMode != null && debugMode.Value) { Logger.LogInfo((object)$"{fieldInfo.Name}: {value}"); } return true; } ConfigEntry<bool>? debugMode2 = configUI.debugMode; if (debugMode2 != null && debugMode2.Value) { Logger.LogInfo((object)(fieldInfo.Name + " is not a boolean.")); } } return false; } public void changeQuillBool(bool value) { string text = (configUI.hasQuill.Value ? "Enabled" : "Disabled"); if (SetPlayerDataBool(PlayerData.instance, "hasQuill", configUI.hasQuill.Value)) { Logger.LogInfo((object)(text + " Quill.")); } } public void DebugArrayContents(string arrayName, bool[] array) { Logger.LogInfo((object)("=== " + arrayName + " Contents ===")); for (int i = 0; i < array.Length; i++) { Logger.LogInfo((object)$"{arrayName}[{i}] = {array[i]} ({mapFields[i]})"); } Logger.LogInfo((object)("=== End " + arrayName + " ===")); } } public class OnStartManager { [HarmonyPatch] internal static class HeroController_Start_Patch { private static MethodBase TargetMethod() { Type type = AccessTools.TypeByName("HeroController"); if (type == null) { throw new Exception("Could not find type HeroController"); } return AccessTools.Method(type, "Start", (Type[])null, (Type[])null); } private static void Postfix(object __instance) { MapUnlocker instance = MapUnlocker.Instance; bool value = instance.configUI.debugMode.Value; if ((Object)(object)instance != (Object)null) { ConfigEntry<bool>? resetDataAfterLeaving = instance.configUI.resetDataAfterLeaving; if (resetDataAfterLeaving != null && resetDataAfterLeaving.Value) { instance.resetManager.StoreOriginalData(); if (value) { instance.Logger.LogInfo((object)"Stored original map data from HeroController_Start"); } } ConfigEntry<bool>? unlockAllMapsAtStart = instance.configUI.unlockAllMapsAtStart; if (unlockAllMapsAtStart != null && unlockAllMapsAtStart.Value) { instance.configUI.unlockAllMaps.Value = true; if (value) { instance.Logger.LogInfo((object)"UnlockAtStart unlockAllMaps finished."); } } else { instance.configUI.ChangeConfigData(instance.configUI.mapConfigs, MapUnlocker.playerDataFieldsBools[MapUnlocker.MAPS]); if (value) { instance.Logger.LogInfo((object)"Stored config data from HeroController_Start"); } } ConfigEntry<bool>? unlockAllPinsAtStart = instance.configUI.unlockAllPinsAtStart; if (unlockAllPinsAtStart != null && unlockAllPinsAtStart.Value) { instance.configUI.unlockAllPins.Value = true; if (value) { instance.Logger.LogInfo((object)"UnlockAtStart unlockAllPins finished."); } } else { instance.configUI.ChangeConfigData(instance.configUI.pinConfigs, MapUnlocker.playerDataFieldsBools[MapUnlocker.PINS]); if (value) { instance.Logger.LogInfo((object)"Stored config data from HeroController_Start"); } } ConfigEntry<bool>? unlockAllMarkersAtStart = instance.configUI.unlockAllMarkersAtStart; if (unlockAllMarkersAtStart != null && unlockAllMarkersAtStart.Value) { instance.configUI.unlockAllMarkers.Value = true; if (value) { instance.Logger.LogInfo((object)"UnlockAtStart unlockAllMarkers finished."); } } else { instance.configUI.ChangeConfigData(instance.configUI.markerConfigs, MapUnlocker.playerDataFieldsBools[MapUnlocker.MARKERS]); if (value) { instance.Logger.LogInfo((object)"Stored config data from HeroController_Start"); } } ConfigEntry<bool>? hasQuill = instance.configUI.hasQuill; if (hasQuill != null && hasQuill.Value) { instance.changeQuillBool(value: true); if (value) { instance.Logger.LogInfo((object)"enabled quill from HeroController_Start"); } } return; } throw new Exception("Could not find MapUnlocker mod."); } } private ManualLogSource Logger; private MapUnlocker plugin; public OnStartManager(ManualLogSource logger, MapUnlocker plugin) { Logger = logger; this.plugin = plugin; } } public class ResetManager { [HarmonyPatch] internal static class SaveGameData_Constructor_Patch { private static MethodBase TargetMethod() { Type type = AccessTools.TypeByName("SaveGameData"); if (type != null) { return AccessTools.Constructor(type, new Type[2] { AccessTools.TypeByName("PlayerData"), AccessTools.TypeByName("SceneData") }, false); } return null; } private static void Prefix(PlayerData playerData, SceneData sceneData) { MapUnlocker instance = MapUnlocker.Instance; if (!((Object)(object)instance != (Object)null)) { return; } ConfigEntry<bool>? resetDataAfterLeaving = instance.configUI.resetDataAfterLeaving; if (resetDataAfterLeaving != null && resetDataAfterLeaving.Value) { instance.resetManager.StoreBoolData(moddedMapData, MapUnlocker.playerDataFieldsBools[MapUnlocker.MAPS]); instance.resetManager.StoreBoolData(moddedPinData, MapUnlocker.playerDataFieldsBools[MapUnlocker.PINS]); instance.resetManager.StoreBoolData(moddedMarkerData, MapUnlocker.playerDataFieldsBools[MapUnlocker.MARKERS]); ConfigUI configUI = instance.configUI; if (configUI != null && configUI.debugMode.Value) { instance.DebugArrayContents("originalMapData", originalMapData); } ConfigUI configUI2 = instance.configUI; if (configUI2 != null && configUI2.debugMode.Value) { instance.DebugArrayContents("originalPinData", originalPinData); } ConfigUI configUI3 = instance.configUI; if (configUI3 != null && configUI3.debugMode.Value) { instance.DebugArrayContents("originalMarkerData", originalMarkerData); } instance.resetManager.OverwriteBoolData(originalMapData, MapUnlocker.playerDataFieldsBools[MapUnlocker.MAPS]); instance.resetManager.OverwriteBoolData(originalPinData, MapUnlocker.playerDataFieldsBools[MapUnlocker.PINS]); instance.resetManager.OverwriteBoolData(originalMarkerData, MapUnlocker.playerDataFieldsBools[MapUnlocker.MARKERS]); instance.Logger.LogInfo((object)"Restored original map states before SaveGameData constructor"); } } private static void Postfix(PlayerData playerData, SceneData sceneData) { MapUnlocker mapUnlocker = Object.FindAnyObjectByType<MapUnlocker>(); if ((Object)(object)mapUnlocker != (Object)null) { ConfigEntry<bool>? resetDataAfterLeaving = mapUnlocker.configUI.resetDataAfterLeaving; if (resetDataAfterLeaving != null && resetDataAfterLeaving.Value) { mapUnlocker.resetManager.OverwriteBoolData(moddedMapData, MapUnlocker.playerDataFieldsBools[MapUnlocker.MAPS]); mapUnlocker.resetManager.OverwriteBoolData(moddedPinData, MapUnlocker.playerDataFieldsBools[MapUnlocker.PINS]); mapUnlocker.resetManager.OverwriteBoolData(moddedMarkerData, MapUnlocker.playerDataFieldsBools[MapUnlocker.MARKERS]); mapUnlocker.Logger.LogInfo((object)"Re-applied mod states after SaveGameData constructor"); } } } } private ManualLogSource Logger; private MapUnlocker plugin; private ConfigUI configUI; public static bool[] originalMapData = new bool[MapUnlocker.mapFields.Length]; public static bool[] moddedMapData = new bool[MapUnlocker.mapFields.Length]; public static bool[] originalPinData = new bool[MapUnlocker.pinFields.Length]; public static bool[] moddedPinData = new bool[MapUnlocker.pinFields.Length]; public static bool[] originalMarkerData = new bool[MapUnlocker.pinFields.Length]; public static bool[] moddedMarkerData = new bool[MapUnlocker.pinFields.Length]; public ResetManager(ManualLogSource logger, MapUnlocker plugin) { Logger = logger; this.plugin = plugin; } public void SetConfigUI(ConfigUI configUI) { this.configUI = configUI; } public void StoreBoolData(bool[] boolData, string[] playerDataFields) { if (PlayerData.instance != null && boolData != null) { for (int i = 0; i < playerDataFields.Length && i < boolData.Length; i++) { FieldInfo field = ((object)PlayerData.instance).GetType().GetField(playerDataFields[i], BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field != null && field.FieldType == typeof(bool)) { bool flag = (bool)field.GetValue(PlayerData.instance); boolData[i] = flag; ConfigEntry<bool>? debugMode = configUI.debugMode; if (debugMode != null && debugMode.Value) { Logger.LogInfo((object)$"{playerDataFields[i]}: {boolData[i]}"); } } } ConfigEntry<bool>? debugMode2 = configUI.debugMode; if (debugMode2 != null && debugMode2.Value) { Logger.LogInfo((object)"Stored original data"); plugin.DebugArrayContents("originalBoolData", boolData); } } else { Logger.LogInfo((object)"(PlayerData.instance is null or configUI not initialized"); } } public void StoreBoolData(bool[] boolData, FieldInfo[] playerDataFields) { if (PlayerData.instance != null && boolData != null) { for (int i = 0; i < playerDataFields.Length && i < boolData.Length; i++) { bool? playerDataBoolValue = MapUnlocker.GetPlayerDataBoolValue(playerDataFields[i]); if (playerDataBoolValue.HasValue) { boolData[i] = playerDataBoolValue.Value; ConfigEntry<bool>? debugMode = configUI.debugMode; if (debugMode != null && debugMode.Value) { Logger.LogInfo((object)$"{playerDataFields[i]}: {boolData[i]}"); } } else { Logger.LogError((object)$"Could not get playerDataField value {i}!"); } } ConfigEntry<bool>? debugMode2 = configUI.debugMode; if (debugMode2 != null && debugMode2.Value) { Logger.LogInfo((object)"Stored original data"); plugin.DebugArrayContents("originalBoolData", boolData); } } else { Logger.LogInfo((object)"(PlayerData.instance is null or configUI not initialized"); } } public void OverwriteBoolData(bool[] boolData, string[] playerDataFields) { if (PlayerData.instance == null || boolData == null || configUI == null) { return; } ConfigEntry<bool>? debugMode = configUI.debugMode; if (debugMode != null && debugMode.Value) { Logger.LogInfo((object)"OverwriteMapData Start --------------------------------"); } for (int i = 0; i < playerDataFields.Length && i < boolData.Length; i++) { if (plugin.SetPlayerDataBool(PlayerData.instance, playerDataFields[i], boolData[i])) { ConfigEntry<bool>? debugMode2 = configUI.debugMode; if (debugMode2 != null && debugMode2.Value) { Logger.LogInfo((object)$"{playerDataFields[i]} -> {boolData[i]}!"); } } } ConfigEntry<bool>? debugMode3 = configUI.debugMode; if (debugMode3 != null && debugMode3.Value) { Logger.LogInfo((object)"Restored pin states"); } } public void OverwriteBoolData(bool[] boolData, FieldInfo[] playerDataFields) { if (PlayerData.instance == null || boolData == null || configUI == null) { return; } ConfigEntry<bool>? debugMode = configUI.debugMode; if (debugMode != null && debugMode.Value) { Logger.LogInfo((object)"OverwriteBoolData Start --------------------------------"); } for (int i = 0; i < playerDataFields.Length && i < boolData.Length; i++) { if (plugin.SetPlayerDataBool(playerDataFields[i], boolData[i])) { ConfigEntry<bool>? debugMode2 = configUI.debugMode; if (debugMode2 != null && debugMode2.Value) { Logger.LogInfo((object)$"playerDataFields: {playerDataFields[i]} -> {boolData[i]}!"); } } } ConfigEntry<bool>? debugMode3 = configUI.debugMode; if (debugMode3 != null && debugMode3.Value) { Logger.LogInfo((object)"Restored pin states"); } } public void StoreOriginalData() { if (PlayerData.instance != null && configUI != null) { StoreBoolData(originalMapData, MapUnlocker.playerDataFieldsBools[MapUnlocker.MAPS]); StoreBoolData(originalPinData, MapUnlocker.playerDataFieldsBools[MapUnlocker.PINS]); StoreBoolData(originalMarkerData, MapUnlocker.playerDataFieldsBools[MapUnlocker.MARKERS]); } else { Logger.LogInfo((object)"(PlayerData.instance is null or configUI not initialized"); } } } public static class PluginInfo { public const string PLUGIN_GUID = "MapUnlocker"; public const string PLUGIN_NAME = "MapUnlocker"; public const string PLUGIN_VERSION = "1.2.0"; } }