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 SisyphusStaircaseLevel Fix v1.0.3
EmpressSisyphusFix.dll
Decompiled 3 weeks agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using HarmonyLib; using Microsoft.CodeAnalysis; using REPOLib; using REPOLib.Modules; using UnityEngine; using UnityEngine.SceneManagement; [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("Empress")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.6.0")] [assembly: AssemblyInformationalVersion("1.0.6")] [assembly: AssemblyProduct("EmpressSisyphusFix")] [assembly: AssemblyTitle("EmpressSisyphusFix")] [assembly: AssemblyVersion("1.0.6.0")] [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 EmpressSisyphusFix { [BepInPlugin("empress.repo.empresssisyphusfix", "EmpressSisyphusFix", "1.0.6")] [BepInDependency(/*Could not decode attribute arguments.*/)] public sealed class EmpressSisyphusFixPlugin : BaseUnityPlugin { internal const string PluginGuid = "empress.repo.empresssisyphusfix"; internal const string PluginName = "EmpressSisyphusFix"; internal const string PluginVersion = "1.0.6"; private const string EmpressSisyphusBundleFileName = "SisyphusStaircaseLevel.repobundle"; private const string EmpressSisyphusBundleAssetName = "assets/repo mods/levels/sisyphus/level - sisyphus.asset"; private const string EmpressSisyphusLevelName = "Level - Sisyphus"; private const string EmpressSisyphusResourcePath = "Sisyphus"; private static readonly string[] EmpressSisyphusStartRoomNames = new string[3] { "Start Room - Sisyphus - Sisyphus", "Start Room - Sisyphus", "Sisyphus" }; private readonly Harmony _empressHarmony = new Harmony("empress.repo.empresssisyphusfix"); private AssetBundle? _empressSisyphusBundle; private bool _empressRepairApplied; private bool _empressRepairQueued; private bool _empressLoggedMissingBundle; private bool _empressLoggedMissingStartRoom; internal static EmpressSisyphusFixPlugin? Instance { get; private set; } private void Awake() { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) Instance = this; GameObject gameObject = ((Component)this).gameObject; ((Object)gameObject).hideFlags = (HideFlags)(((Object)gameObject).hideFlags | 0x23); BundleLoader.OnAllBundlesLoaded += EmpressHandleBundlesLoaded; _empressHarmony.PatchAll(); if ((Object)(object)RunManager.instance != (Object)null) { ((MonoBehaviour)this).StartCoroutine(EmpressRepairWhenReady()); } } private void OnDestroy() { BundleLoader.OnAllBundlesLoaded -= EmpressHandleBundlesLoaded; _empressHarmony.UnpatchSelf(); if (Instance == this) { Instance = null; } } private void EmpressHandleBundlesLoaded() { if (!_empressRepairQueued && !_empressRepairApplied) { _empressRepairQueued = true; ((MonoBehaviour)this).StartCoroutine(EmpressRepairWhenReady()); } } private IEnumerator EmpressRepairWhenReady() { yield return null; for (int attempt = 0; attempt < 120; attempt++) { if (_empressRepairApplied) { break; } if (EmpressTryRepairLevel()) { break; } yield return null; } _empressRepairQueued = false; } internal bool EmpressTryRepairCurrentLevel() { return EmpressTryRepairLevel((IEnumerable<Level>?)((!((Object)(object)RunManager.instance != (Object)null)) ? ((Array)Array.Empty<Level>()) : ((Array)new Level[1] { RunManager.instance.levelCurrent }))); } private bool EmpressTryRepairLevel(IEnumerable<Level>? candidates = null) { if (_empressRepairApplied) { return true; } Level val = EmpressFindLevel(candidates) ?? EmpressFindLevel(Levels.AllLevels); if ((Object)(object)val == (Object)null) { return false; } AssetBundle val2 = EmpressGetSisyphusBundle(); if ((Object)(object)val2 == (Object)null) { if (!_empressLoggedMissingBundle) { _empressLoggedMissingBundle = true; ((BaseUnityPlugin)this).Logger.LogWarning((object)"EmpressSisyphusFix could not locate the Sisyphus bundle."); } return false; } _empressLoggedMissingBundle = false; GameObject val3 = EmpressFindStartRoomPrefab(val2, val); if ((Object)(object)val3 == (Object)null) { if (!_empressLoggedMissingStartRoom) { _empressLoggedMissingStartRoom = true; ((BaseUnityPlugin)this).Logger.LogError((object)"EmpressSisyphusFix could not find the Sisyphus start room prefab."); } return false; } _empressLoggedMissingStartRoom = false; EmpressPrepareLevel(val); EmpressApplyHideFlags((Object)(object)val2); EmpressApplyHideFlags((Object)(object)val); EmpressApplyHideFlags((Object)(object)val3); string text = EmpressBuildStartRoomPrefabId(val, val3); PrefabRef val4 = NetworkPrefabs.RegisterNetworkPrefab(text, val3); if (val4 == null) { ((BaseUnityPlugin)this).Logger.LogError((object)"EmpressSisyphusFix failed to register the Sisyphus start room prefab."); return false; } val.StartRooms.Clear(); val.StartRooms.Add(val4); _empressRepairApplied = true; ((BaseUnityPlugin)this).Logger.LogInfo((object)("EmpressSisyphusFix repaired " + ((Object)val).name + " with prefab " + text + ".")); return true; } private static Level? EmpressFindLevel(IEnumerable<Level>? candidates) { if (candidates == null) { return null; } foreach (Level candidate in candidates) { if (!((Object)(object)candidate == (Object)null) && (string.Equals(((Object)candidate).name, "Level - Sisyphus", StringComparison.OrdinalIgnoreCase) || string.Equals(candidate.ResourcePath, "Sisyphus", StringComparison.OrdinalIgnoreCase))) { return candidate; } } return null; } private AssetBundle? EmpressGetSisyphusBundle() { if ((Object)(object)_empressSisyphusBundle != (Object)null) { return _empressSisyphusBundle; } foreach (AssetBundle allLoadedAssetBundle in AssetBundle.GetAllLoadedAssetBundles()) { if (allLoadedAssetBundle.GetAllAssetNames().Any((string assetName) => string.Equals(assetName, "assets/repo mods/levels/sisyphus/level - sisyphus.asset", StringComparison.OrdinalIgnoreCase))) { _empressSisyphusBundle = allLoadedAssetBundle; return _empressSisyphusBundle; } } string text = Directory.GetFiles(Paths.PluginPath, "SisyphusStaircaseLevel.repobundle", SearchOption.AllDirectories).FirstOrDefault(); if (string.IsNullOrWhiteSpace(text)) { return null; } _empressSisyphusBundle = AssetBundle.LoadFromFile(text); return _empressSisyphusBundle; } private static GameObject? EmpressFindStartRoomPrefab(AssetBundle bundle, Level level) { return EmpressFindStartRoomFromMemory(level) ?? EmpressFindStartRoomFromBundle(bundle, level) ?? EmpressFindStartRoomFromMemory(level, allowSceneObjects: true); } private static GameObject? EmpressFindStartRoomFromBundle(AssetBundle bundle, Level level) { StartRoom[] array = bundle.LoadAllAssets<StartRoom>(); foreach (StartRoom val in array) { if ((Object)(object)val != (Object)null && EmpressLooksLikeSisyphusStartRoom(((Component)val).gameObject, level)) { return ((Component)val).gameObject; } } GameObject[] array2 = bundle.LoadAllAssets<GameObject>(); foreach (GameObject val2 in array2) { if ((Object)(object)val2 != (Object)null && EmpressLooksLikeSisyphusStartRoom(val2, level)) { return val2; } } Object[] array3 = bundle.LoadAssetWithSubAssets<Object>("assets/repo mods/levels/sisyphus/level - sisyphus.asset"); foreach (Object val3 in array3) { GameObject val4 = (GameObject)(object)((val3 is GameObject) ? val3 : null); if (val4 != null && EmpressLooksLikeSisyphusStartRoom(val4, level)) { return val4; } StartRoom val5 = (StartRoom)(object)((val3 is StartRoom) ? val3 : null); if (val5 != null && EmpressLooksLikeSisyphusStartRoom(((Component)val5).gameObject, level)) { return ((Component)val5).gameObject; } } return null; } private static GameObject? EmpressFindStartRoomFromMemory(Level level, bool allowSceneObjects = false) { //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) StartRoom[] array = Resources.FindObjectsOfTypeAll<StartRoom>(); Scene scene; foreach (StartRoom val in array) { if ((Object)(object)val == (Object)null) { continue; } GameObject gameObject = ((Component)val).gameObject; if (!allowSceneObjects) { scene = gameObject.scene; if (((Scene)(ref scene)).IsValid()) { continue; } } if (EmpressLooksLikeSisyphusStartRoom(gameObject, level)) { return gameObject; } } Module[] array2 = Resources.FindObjectsOfTypeAll<Module>(); foreach (Module val2 in array2) { if ((Object)(object)val2 == (Object)null) { continue; } GameObject gameObject2 = ((Component)val2).gameObject; if (!allowSceneObjects) { scene = gameObject2.scene; if (((Scene)(ref scene)).IsValid()) { continue; } } if ((Object)(object)gameObject2.GetComponent<StartRoom>() != (Object)null && EmpressLooksLikeSisyphusStartRoom(gameObject2, level)) { return gameObject2; } } GameObject[] array3 = Resources.FindObjectsOfTypeAll<GameObject>(); foreach (GameObject val3 in array3) { if ((Object)(object)val3 == (Object)null) { continue; } if (!allowSceneObjects) { scene = val3.scene; if (((Scene)(ref scene)).IsValid()) { continue; } } if (EmpressLooksLikeSisyphusStartRoom(val3, level)) { return val3; } } return null; } private static bool EmpressLooksLikeSisyphusStartRoom(GameObject gameObject, Level level) { if ((Object)(object)gameObject == (Object)null) { return false; } bool num = (Object)(object)gameObject.GetComponent<StartRoom>() != (Object)null; bool flag = (Object)(object)gameObject.GetComponent<Module>() != (Object)null; string name = ((Object)gameObject).name ?? string.Empty; if (!num && !flag) { return false; } if (EmpressSisyphusStartRoomNames.Any((string candidate) => string.Equals(name, candidate, StringComparison.OrdinalIgnoreCase))) { return true; } if (name.IndexOf(level.ResourcePath ?? "Sisyphus", StringComparison.OrdinalIgnoreCase) >= 0) { return true; } return name.IndexOf("Sisyphus", StringComparison.OrdinalIgnoreCase) >= 0; } private static string EmpressBuildStartRoomPrefabId(Level level, GameObject startRoom) { return "Level/" + ((Object)level).name + "/StartRoom/" + ((Object)startRoom).name; } private static void EmpressPrepareLevel(Level level) { Level val = level; if (val.StartRooms == null) { val.StartRooms = new List<PrefabRef>(); } val = level; if (val.ModulesNormal1 == null) { val.ModulesNormal1 = new List<PrefabRef>(); } val = level; if (val.ModulesPassage1 == null) { val.ModulesPassage1 = new List<PrefabRef>(); } val = level; if (val.ModulesDeadEnd1 == null) { val.ModulesDeadEnd1 = new List<PrefabRef>(); } val = level; if (val.ModulesExtraction1 == null) { val.ModulesExtraction1 = new List<PrefabRef>(); } val = level; if (val.ModulesNormal2 == null) { val.ModulesNormal2 = new List<PrefabRef>(); } val = level; if (val.ModulesPassage2 == null) { val.ModulesPassage2 = new List<PrefabRef>(); } val = level; if (val.ModulesDeadEnd2 == null) { val.ModulesDeadEnd2 = new List<PrefabRef>(); } val = level; if (val.ModulesExtraction2 == null) { val.ModulesExtraction2 = new List<PrefabRef>(); } val = level; if (val.ModulesNormal3 == null) { val.ModulesNormal3 = new List<PrefabRef>(); } val = level; if (val.ModulesPassage3 == null) { val.ModulesPassage3 = new List<PrefabRef>(); } val = level; if (val.ModulesDeadEnd3 == null) { val.ModulesDeadEnd3 = new List<PrefabRef>(); } val = level; if (val.ModulesExtraction3 == null) { val.ModulesExtraction3 = new List<PrefabRef>(); } val = level; if (val.ValuablePresets == null) { val.ValuablePresets = new List<LevelValuables>(); } val = level; if (val.AmbiencePresets == null) { val.AmbiencePresets = new List<LevelAmbience>(); } level.ModulesNormal1.Clear(); level.ModulesPassage1.Clear(); level.ModulesDeadEnd1.Clear(); level.ModulesExtraction1.Clear(); level.ModulesNormal2.Clear(); level.ModulesPassage2.Clear(); level.ModulesDeadEnd2.Clear(); level.ModulesExtraction2.Clear(); level.ModulesNormal3.Clear(); level.ModulesPassage3.Clear(); level.ModulesDeadEnd3.Clear(); level.ModulesExtraction3.Clear(); EmpressEnsureLevelFallbackData(level); } internal static void EmpressEnsureLevelFallbackData(Level? level) { if (EmpressIsSisyphusLevel(level)) { Level val = level; if (val.ValuablePresets == null) { val.ValuablePresets = new List<LevelValuables>(); } val = level; if (val.AmbiencePresets == null) { val.AmbiencePresets = new List<LevelAmbience>(); } if (level.ValuablePresets.Count == 0 && (Object)(object)ValuablePresets.GenericValuablePreset != (Object)null) { level.ValuablePresets.Add(ValuablePresets.GenericValuablePreset); } if (level.AmbiencePresets.Count == 0 && EmpressTryGetFallbackAmbience(out LevelAmbience empressAmbience)) { level.AmbiencePresets.Add(empressAmbience); } } } internal static bool EmpressIsSisyphusCurrentLevel() { if (!EmpressIsSisyphusLevel(((Object)(object)LevelGenerator.Instance != (Object)null) ? LevelGenerator.Instance.Level : null)) { return EmpressIsSisyphusLevel(((Object)(object)RunManager.instance != (Object)null) ? RunManager.instance.levelCurrent : null); } return true; } private static bool EmpressIsSisyphusLevel(Level? level) { if ((Object)(object)level == (Object)null) { return false; } if (!string.Equals(((Object)level).name, "Level - Sisyphus", StringComparison.OrdinalIgnoreCase)) { return string.Equals(level.ResourcePath, "Sisyphus", StringComparison.OrdinalIgnoreCase); } return true; } private static bool EmpressTryGetFallbackAmbience(out LevelAmbience empressAmbience) { empressAmbience = null; if ((Object)(object)AudioManager.instance != (Object)null && AudioManager.instance.levelAmbiences != null) { foreach (LevelAmbience levelAmbience in AudioManager.instance.levelAmbiences) { if ((Object)(object)levelAmbience != (Object)null) { empressAmbience = levelAmbience; return true; } } } if ((Object)(object)RunManager.instance != (Object)null && RunManager.instance.levels != null) { foreach (Level level in RunManager.instance.levels) { if (level?.AmbiencePresets == null) { continue; } foreach (LevelAmbience ambiencePreset in level.AmbiencePresets) { if ((Object)(object)ambiencePreset != (Object)null) { empressAmbience = ambiencePreset; return true; } } } } return false; } internal static bool EmpressShouldSkipSisyphusLevelPointValidation(LevelPoint? levelPoint) { if ((Object)(object)levelPoint == (Object)null || !EmpressIsSisyphusCurrentLevel()) { return false; } return (Object)(object)((Component)levelPoint).GetComponentInParent<StartRoom>() != (Object)null; } internal static IEnumerator EmpressSkipCoroutine() { yield break; } private static void EmpressApplyHideFlags(Object obj) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) if (obj == (Object)null) { return; } obj.hideFlags = (HideFlags)(obj.hideFlags | 0x23); GameObject val = (GameObject)(object)((obj is GameObject) ? obj : null); if (val == null) { return; } Transform[] componentsInChildren = val.GetComponentsInChildren<Transform>(true); foreach (Transform obj2 in componentsInChildren) { ((Object)obj2).hideFlags = (HideFlags)(((Object)obj2).hideFlags | 0x23); GameObject gameObject = ((Component)obj2).gameObject; ((Object)gameObject).hideFlags = (HideFlags)(((Object)gameObject).hideFlags | 0x23); Component[] components = ((Component)obj2).GetComponents<Component>(); foreach (Component val2 in components) { if ((Object)(object)val2 != (Object)null) { ((Object)val2).hideFlags = (HideFlags)(((Object)val2).hideFlags | 0x23); } } } } internal static void EmpressEnsureExtractionPointCompatibility(ExtractionPoint extractionPoint) { //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Expected O, but got Unknown if ((Object)(object)extractionPoint == (Object)null) { return; } if ((Object)(object)extractionPoint.extractionArea == (Object)null) { GameObject val = GameObject.CreatePrimitive((PrimitiveType)2); ((Object)val).name = "Empress Extraction Area"; val.transform.SetParent(((Component)extractionPoint).transform, false); val.transform.localPosition = Vector3.zero; val.transform.localRotation = Quaternion.identity; val.transform.localScale = Vector3.one * 0.1f; MeshRenderer component = val.GetComponent<MeshRenderer>(); if ((Object)(object)component != (Object)null) { ((Renderer)component).enabled = false; } Collider component2 = val.GetComponent<Collider>(); if ((Object)(object)component2 != (Object)null) { Object.Destroy((Object)(object)component2); } val.SetActive(false); EmpressApplyHideFlags((Object)(object)val); extractionPoint.extractionArea = val; } if ((Object)(object)extractionPoint.grossUp == (Object)null) { GameObject val2 = new GameObject("Empress GrossUp"); val2.transform.SetParent(((Component)extractionPoint).transform, false); val2.SetActive(false); EmpressApplyHideFlags((Object)(object)val2); extractionPoint.grossUp = val2; } } } [HarmonyPatch(typeof(LevelGenerator), "StartRoomGeneration")] internal static class EmpressSisyphusStartRoomPatch { [HarmonyPrefix] private static void EmpressPrefix() { EmpressSisyphusFixPlugin.Instance?.EmpressTryRepairCurrentLevel(); } } [HarmonyPatch(typeof(ExtractionPoint), "Start")] internal static class EmpressSisyphusExtractionPointStartPatch { [HarmonyPostfix] private static void EmpressPostfix(ExtractionPoint __instance) { EmpressSisyphusFixPlugin.EmpressEnsureExtractionPointCompatibility(__instance); } } [HarmonyPatch(typeof(Levels), "RegisterLevelWithGame")] internal static class EmpressSisyphusRegisterLevelPatch { [HarmonyPrefix] private static void EmpressPrefix(Level level) { EmpressSisyphusFixPlugin.EmpressEnsureLevelFallbackData(level); } } [HarmonyPatch(typeof(EnvironmentDirector), "Setup")] internal static class EmpressSisyphusEnvironmentDirectorPatch { [HarmonyPrefix] private static void EmpressPrefix() { if ((Object)(object)LevelGenerator.Instance != (Object)null) { EmpressSisyphusFixPlugin.EmpressEnsureLevelFallbackData(LevelGenerator.Instance.Level); } } } [HarmonyPatch(typeof(LevelPoint), "NavMeshCheck")] internal static class EmpressSisyphusLevelPointNavMeshCheckPatch { [HarmonyPrefix] private static bool EmpressPrefix(LevelPoint __instance, ref IEnumerator __result) { if (!EmpressSisyphusFixPlugin.EmpressShouldSkipSisyphusLevelPointValidation(__instance)) { return true; } __result = EmpressSisyphusFixPlugin.EmpressSkipCoroutine(); return false; } } }