using System; using System.Collections; using System.Collections.Generic; using System.Reflection; using System.Runtime.CompilerServices; using BepInEx; using BepInEx.Logging; using HarmonyLib; using REPOLib.Modules; using REPOLib.Objects.Sdk; using UnityEngine; [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: CompilationRelaxations(8)] [assembly: AssemblyVersion("0.0.0.0")] namespace REPOMapRepair; [BepInPlugin("chatgpt.repo.maprepair", "REPO Map Repair", "0.3.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public sealed class Plugin : BaseUnityPlugin { internal static ManualLogSource Log; private Harmony _harmony; private void Awake() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Expected O, but got Unknown //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; _harmony = new Harmony("chatgpt.repo.maprepair.v020"); MethodInfo methodInfo = AccessTools.Method(typeof(Levels), "RegisterLevel", new Type[1] { typeof(LevelContent) }, (Type[])null); if (methodInfo == null) { ((BaseUnityPlugin)this).Logger.LogError((object)"[MapRepair] REPOLib Levels.RegisterLevel(LevelContent) introuvable."); return; } MethodInfo methodInfo2 = AccessTools.Method(typeof(LevelRegisterPatch), "Prefix", (Type[])null, (Type[])null); _harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); MethodInfo methodInfo3 = AccessTools.Method(typeof(ExtractionPoint), "Start", (Type[])null, (Type[])null); MethodInfo methodInfo4 = AccessTools.Method(typeof(UndergroundExtractionPatch), "Prefix", (Type[])null, (Type[])null); if (methodInfo3 != null && methodInfo4 != null) { _harmony.Patch((MethodBase)methodInfo3, new HarmonyMethod(methodInfo4), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); ((BaseUnityPlugin)this).Logger.LogInfo((object)"[MapRepair] Underground Cave extraction compatibility patch active."); } else { ((BaseUnityPlugin)this).Logger.LogWarning((object)"[MapRepair] ExtractionPoint.Start patch could not be installed."); } ((BaseUnityPlugin)this).Logger.LogInfo((object)"REPO Map Repair 0.3.0 loaded - Underground Cave + BluePrince patch."); } } internal static class UndergroundExtractionPatch { private static readonly FieldInfo ExtractionAreaField = AccessTools.Field(typeof(ExtractionPoint), "extractionArea"); private static readonly FieldInfo GrossUpField = AccessTools.Field(typeof(ExtractionPoint), "grossUp"); internal static void Prefix(ExtractionPoint __instance) { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Expected O, but got Unknown //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Expected O, but got Unknown if ((Object)(object)__instance == (Object)null) { return; } try { if (IsUndergroundCave(__instance)) { int num = 0; if (ExtractionAreaField != null && ExtractionAreaField.GetValue(__instance) == null) { GameObject val = new GameObject("REPOMapRepair_ExtractionArea"); val.transform.SetParent(((Component)__instance).transform, false); ExtractionAreaField.SetValue(__instance, val); num++; } if (GrossUpField != null && GrossUpField.GetValue(__instance) == null) { GameObject val2 = new GameObject("REPOMapRepair_GrossUp"); val2.transform.SetParent(((Component)__instance).transform, false); GrossUpField.SetValue(__instance, val2); num++; } if (num > 0) { Plugin.Log.LogInfo((object)("[MapRepair] UNDERGROUND EXTRACTION repaired " + num + " missing field(s) on " + GetPath(((Component)__instance).transform) + ".")); } } } catch (Exception ex) { Plugin.Log.LogError((object)("[MapRepair] Underground ExtractionPoint.Start repair failed: " + ex)); } } private static bool IsUndergroundCave(ExtractionPoint point) { try { if ((Object)(object)RunManager.instance != (Object)null && (Object)(object)RunManager.instance.levelCurrent != (Object)null) { string a = ((Object)RunManager.instance.levelCurrent).name ?? ""; if (string.Equals(a, "Level - Underground Cave", StringComparison.OrdinalIgnoreCase)) { return true; } } } catch { } Transform val = ((Component)point).transform; while ((Object)(object)val != (Object)null) { string text = ((Object)val).name ?? ""; if (text.StartsWith("Module - Custom - ", StringComparison.Ordinal) || text.StartsWith("Start Room - Custom - Lobby", StringComparison.Ordinal)) { return true; } val = val.parent; } return false; } private static string GetPath(Transform t) { if ((Object)(object)t == (Object)null) { return ""; } string text = ((Object)t).name; Transform parent = t.parent; while ((Object)(object)parent != (Object)null) { text = ((Object)parent).name + "/" + text; parent = parent.parent; } return text; } } internal static class LevelRegisterPatch { private static readonly FieldInfo LevelField = AccessTools.Field(typeof(LevelContent), "_level"); private static readonly Dictionary UndergroundMap = new Dictionary { { "_startRooms", new string[1] { "Start Room - Custom - Lobby" } }, { "_modulesNormal1", new string[4] { "Module - Custom - N - 1", "Module - Custom - N - 2", "Module - Custom - N - 3", "Module - Custom - N - 4" } }, { "_modulesNormal2", new string[4] { "Module - Custom - N - 1", "Module - Custom - N - 2", "Module - Custom - N - 3", "Module - Custom - N - 4" } }, { "_modulesNormal3", new string[4] { "Module - Custom - N - 1", "Module - Custom - N - 2", "Module - Custom - N - 3", "Module - Custom - N - 4" } }, { "_modulesPassage1", new string[4] { "Module - Custom - P - 1", "Module - Custom - P - 2", "Module - Custom - P - 3", "Module - Custom - P - 4" } }, { "_modulesPassage2", new string[4] { "Module - Custom - P - 1", "Module - Custom - P - 2", "Module - Custom - P - 3", "Module - Custom - P - 4" } }, { "_modulesPassage3", new string[4] { "Module - Custom - P - 1", "Module - Custom - P - 2", "Module - Custom - P - 3", "Module - Custom - P - 4" } }, { "_modulesDeadEnd1", new string[2] { "Module - Custom - DE - 1", "Module - Custom - DE - 2" } }, { "_modulesDeadEnd2", new string[2] { "Module - Custom - DE - 1", "Module - Custom - DE - 2" } }, { "_modulesDeadEnd3", new string[2] { "Module - Custom - DE - 1", "Module - Custom - DE - 2" } }, { "_modulesExtraction1", new string[2] { "Module - Custom - E - 1", "Module - Custom - E - 2" } }, { "_modulesExtraction2", new string[2] { "Module - Custom - E - 1", "Module - Custom - E - 2" } }, { "_modulesExtraction3", new string[2] { "Module - Custom - E - 1", "Module - Custom - E - 2" } } }; internal static void Prefix(LevelContent levelContent) { if ((Object)(object)levelContent == (Object)null || LevelField == null) { return; } try { object? value = LevelField.GetValue(levelContent); Object val = (Object)((value is Object) ? value : null); if (!(val == (Object)null)) { string text = val.name ?? ""; string a = (text.StartsWith("Level - ", StringComparison.Ordinal) ? text.Substring("Level - ".Length) : text); if (string.Equals(a, "Underground Cave", StringComparison.OrdinalIgnoreCase)) { RepairUnderground(levelContent); } } } catch (Exception ex) { Plugin.Log.LogError((object)("[MapRepair] RegisterLevel diagnostic/repair failed: " + ex)); } } private static void RepairUnderground(LevelContent content) { IList list = GetList(content, "_startRooms"); if (list != null && list.Count > 0) { Plugin.Log.LogInfo((object)("[MapRepair] Underground Cave: StartRooms already populated (" + list.Count + "); repair not needed.")); return; } HashSet hashSet = new HashSet(StringComparer.Ordinal); foreach (KeyValuePair item in UndergroundMap) { for (int i = 0; i < item.Value.Length; i++) { hashSet.Add(item.Value[i]); } } Dictionary dictionary = new Dictionary(StringComparer.Ordinal); GameObject[] array = Resources.FindObjectsOfTypeAll(); foreach (GameObject val in array) { if (!((Object)(object)val == (Object)null)) { string name = ((Object)val).name; if (hashSet.Contains(name) && !dictionary.ContainsKey(name)) { dictionary.Add(name, val); } } } int num = 0; int num2 = 0; foreach (KeyValuePair item2 in UndergroundMap) { IList list2 = GetList(content, item2.Key); if (list2 == null) { Plugin.Log.LogWarning((object)("[MapRepair] Underground Cave: LevelContent field missing: " + item2.Key)); num += item2.Value.Length; continue; } for (int k = 0; k < item2.Value.Length; k++) { string text = item2.Value[k]; num++; if (!dictionary.TryGetValue(text, out var value) || (Object)(object)value == (Object)null) { Plugin.Log.LogWarning((object)("[MapRepair] Underground Cave: prefab not found: " + text)); continue; } bool flag = false; for (int l = 0; l < list2.Count; l++) { if (object.ReferenceEquals(list2[l], value)) { flag = true; break; } } if (!flag) { list2.Add(value); } num2++; } } Plugin.Log.LogInfo((object)("[MapRepair] UNDERGROUND RELINK complete: " + num2 + "/" + num + " module references restored; StartRooms=" + Count(content, "_startRooms") + ", N1=" + Count(content, "_modulesNormal1") + ", P1=" + Count(content, "_modulesPassage1") + ", DE1=" + Count(content, "_modulesDeadEnd1") + ", E1=" + Count(content, "_modulesExtraction1") + ".")); } private static IList GetList(LevelContent content, string fieldName) { FieldInfo fieldInfo = AccessTools.Field(typeof(LevelContent), fieldName); if (!(fieldInfo != null)) { return null; } return fieldInfo.GetValue(content) as IList; } private static int Count(LevelContent content, string fieldName) { return GetList(content, fieldName)?.Count ?? (-1); } }