using System; using System.Collections.Generic; using System.Reflection; using System.Runtime.CompilerServices; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using LethalLevelLoader; using UnityEngine; [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: CompilationRelaxations(8)] [assembly: AssemblyVersion("0.0.0.0")] namespace WesleyInteriorsCompat; [BepInPlugin("Christian.WesleyInteriorsCompat", "Wesley Interiors Compatibility Pack", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public sealed class WesleyInteriorsCompatPlugin : BaseUnityPlugin { [HarmonyPatch(typeof(Plugin), "CompleteSetup")] private static class CompleteSetupPatch { [HarmonyPostfix] private static void Postfix() { if ((Object)(object)Instance != (Object)null) { Instance.ApplyWesleyMoonOverrides(); } } } [HarmonyPatch(typeof(Plugin), "LobbyInitialized")] private static class LobbyInitializedPatch { [HarmonyPostfix] private static void Postfix() { if ((Object)(object)Instance != (Object)null) { Instance.ApplyWesleyMoonOverrides(); Instance.TryUpdateTerminalCatalogue(); } } } [HarmonyPatch(typeof(Terminal), "Start")] private static class TerminalStartPatch { [HarmonyPostfix] private static void Postfix() { if ((Object)(object)Instance != (Object)null) { Instance.ApplyWesleyMoonOverrides(); Instance.TryUpdateTerminalCatalogue(); } } } [HarmonyPatch(typeof(DungeonManager), "GetValidExtendedDungeonFlows")] private static class VowRubberRoomsPatch { [HarmonyPostfix] private static void Postfix(ExtendedLevel extendedLevel, ref List __result) { if ((Object)(object)Instance != (Object)null) { Instance.ForceVowToRubberRooms(extendedLevel, ref __result); } } } public const string PluginGuid = "Christian.WesleyInteriorsCompat"; public const string PluginName = "Wesley Interiors Compatibility Pack"; public const string PluginVersion = "1.0.0"; private static readonly HashSet WesleyMoonNames = new HashSet(StringComparer.OrdinalIgnoreCase) { "trite", "oldred", "duckstroid14", "filitrios", "gratar", "etern", "dreck", "release", "motra", "calist", "alcatras", "fissionc", "berunah", "faith", "crowd", "lecaro", "demetrica", "gloom", "roart", "thalasso", "cosmocos", "hyx", "atlantica", "infernis", "infernus", "extort", "desolation", "narcotic", "cubatres", "empra", "asteroid13", "hyve", "repress", "utril", "descent", "acidir", "junic", "core", "polarus", "galetry", "end" }; internal static WesleyInteriorsCompatPlugin Instance; private ConfigEntry forceVowRubberRooms; private ConfigEntry makeWesleyMoonsFree; private bool terminalCatalogueUpdated; private bool vowOverrideLogged; private void Awake() { //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Expected O, but got Unknown Instance = this; forceVowRubberRooms = ((BaseUnityPlugin)this).Config.Bind("Vow", "Force Rubber Rooms", true, "When enabled, Vow has a 100% chance to use the Rubber Rooms interior."); makeWesleyMoonsFree = ((BaseUnityPlugin)this).Config.Bind("Wesley Moons", "Always Unlock and Make Free", true, "Removes Wesley moon progression locks, unhides the moons, and sets their route prices to 0."); Harmony val = new Harmony("Christian.WesleyInteriorsCompat"); val.PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Wesley Interiors Compatibility Pack 1.0.0 loaded."); } private void Update() { if (!terminalCatalogueUpdated && Plugin.IsSetupComplete) { ApplyWesleyMoonOverrides(); terminalCatalogueUpdated = TryUpdateTerminalCatalogue(); } } internal void ApplyWesleyMoonOverrides() { if (makeWesleyMoonsFree == null || !makeWesleyMoonsFree.Value) { return; } List customExtendedLevels = PatchedContent.CustomExtendedLevels; if (customExtendedLevels == null) { return; } int num = 0; foreach (ExtendedLevel item in customExtendedLevels) { if (!((Object)(object)item == (Object)null) && IsWesleyMoon(item)) { bool flag = false; if (item.IsRouteLocked) { item.IsRouteLocked = false; flag = true; } if (item.IsRouteHidden) { item.IsRouteHidden = false; flag = true; } if (item.RoutePrice != 0) { item.ForceSetRoutePrice(0); flag = true; } if (flag) { num++; } } } if (num > 0) { ((BaseUnityPlugin)this).Logger.LogInfo((object)("Unlocked and made free " + num + " Wesley moon(s).")); } } private bool TryUpdateTerminalCatalogue() { Terminal val = Object.FindObjectOfType(); if ((Object)(object)val == (Object)null) { return false; } List customExtendedLevels = PatchedContent.CustomExtendedLevels; if (customExtendedLevels == null) { return true; } List list = new List(); if (val.moonsCatalogueList != null) { list.AddRange(val.moonsCatalogueList); } foreach (ExtendedLevel item in customExtendedLevels) { if (!((Object)(object)item == (Object)null) && IsWesleyMoon(item) && !((Object)(object)item.SelectableLevel == (Object)null) && !list.Contains(item.SelectableLevel)) { list.Add(item.SelectableLevel); } } val.moonsCatalogueList = list.ToArray(); return true; } private void ForceVowToRubberRooms(ExtendedLevel extendedLevel, ref List results) { //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Expected O, but got Unknown if (forceVowRubberRooms == null || !forceVowRubberRooms.Value || (Object)(object)extendedLevel == (Object)null || !string.Equals(Normalize(extendedLevel.NumberlessPlanetName), "vow", StringComparison.Ordinal)) { return; } ExtendedDungeonFlow val = null; List extendedDungeonFlows = PatchedContent.ExtendedDungeonFlows; if (extendedDungeonFlows != null) { foreach (ExtendedDungeonFlow item in extendedDungeonFlows) { if (!((Object)(object)item == (Object)null) && !((Object)(object)item.DungeonFlow == (Object)null)) { string text = Normalize(item.DungeonName); if (text.Contains("rubberroom")) { val = item; break; } } } } if ((Object)(object)val == (Object)null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"Vow was not changed because LethalLevelLoader did not register a valid Rubber Rooms flow. Check the preloader messages above."); return; } results = new List { new ExtendedDungeonFlowWithRarity(val, 10000) }; if (!vowOverrideLogged) { vowOverrideLogged = true; ((BaseUnityPlugin)this).Logger.LogInfo((object)"Vow is restricted to Rubber Rooms (100%)."); } } private static bool IsWesleyMoon(ExtendedLevel level) { string item = Normalize(level.NumberlessPlanetName); if (WesleyMoonNames.Contains(item)) { return true; } string text = Normalize(level.contentSourceName); return text.Contains("wesleysmoon") || text.Contains("magicwesley"); } private static string Normalize(string value) { if (string.IsNullOrEmpty(value)) { return string.Empty; } char[] array = new char[value.Length]; int length = 0; foreach (char c in value) { if (char.IsLetterOrDigit(c)) { array[length++] = char.ToLowerInvariant(c); } } return new string(array, 0, length); } }