using 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.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("Empress")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.6.0")] [assembly: AssemblyInformationalVersion("1.0.6+5f1b735e473ca4ccf3b383128fbebd889cb564da")] [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_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0016: 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 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?)((!((Object)(object)RunManager.instance != (Object)null)) ? ((Array)Array.Empty()) : ((Array)new Level[1] { RunManager.instance.levelCurrent }))); } private bool EmpressTryRepairLevel(IEnumerable? 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? 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(((Object)candidate).name, "Sisyphus", StringComparison.OrdinalIgnoreCase) && (string.IsNullOrWhiteSpace(candidate.NarrativeName) || candidate.NarrativeName.IndexOf("sisyphus", StringComparison.OrdinalIgnoreCase) < 0) && (string.IsNullOrWhiteSpace(((Object)candidate).name) || ((Object)candidate).name.IndexOf("sisyphus", StringComparison.OrdinalIgnoreCase) < 0))) { continue; } 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(); foreach (StartRoom val in array) { if ((Object)(object)val != (Object)null && EmpressLooksLikeSisyphusStartRoom(((Component)val).gameObject, level)) { return ((Component)val).gameObject; } } GameObject[] array2 = bundle.LoadAllAssets(); foreach (GameObject val2 in array2) { if ((Object)(object)val2 != (Object)null && EmpressLooksLikeSisyphusStartRoom(val2, level)) { return val2; } } Object[] array3 = bundle.LoadAssetWithSubAssets("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_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) StartRoom[] array = Resources.FindObjectsOfTypeAll(); 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)) { continue; } return gameObject; } Module[] array2 = Resources.FindObjectsOfTypeAll(); 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() != (Object)null) || !EmpressLooksLikeSisyphusStartRoom(gameObject2, level)) { continue; } return gameObject2; } GameObject[] array3 = Resources.FindObjectsOfTypeAll(); 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)) { continue; } return val3; } return null; } private static bool EmpressLooksLikeSisyphusStartRoom(GameObject gameObject, Level level) { if ((Object)(object)gameObject == (Object)null) { return false; } bool flag = (Object)(object)gameObject.GetComponent() != (Object)null; bool flag2 = (Object)(object)gameObject.GetComponent() != (Object)null; string name = ((Object)gameObject).name ?? string.Empty; if (!flag && !flag2) { return false; } if (EmpressSisyphusStartRoomNames.Any((string candidate) => string.Equals(name, candidate, StringComparison.OrdinalIgnoreCase))) { return true; } if (name.IndexOf(((Object)level).name ?? "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(); } val = level; if (val.ModulesNormal1 == null) { val.ModulesNormal1 = new List(); } val = level; if (val.ModulesPassage1 == null) { val.ModulesPassage1 = new List(); } val = level; if (val.ModulesDeadEnd1 == null) { val.ModulesDeadEnd1 = new List(); } val = level; if (val.ModulesExtraction1 == null) { val.ModulesExtraction1 = new List(); } val = level; if (val.ModulesNormal2 == null) { val.ModulesNormal2 = new List(); } val = level; if (val.ModulesPassage2 == null) { val.ModulesPassage2 = new List(); } val = level; if (val.ModulesDeadEnd2 == null) { val.ModulesDeadEnd2 = new List(); } val = level; if (val.ModulesExtraction2 == null) { val.ModulesExtraction2 = new List(); } val = level; if (val.ModulesNormal3 == null) { val.ModulesNormal3 = new List(); } val = level; if (val.ModulesPassage3 == null) { val.ModulesPassage3 = new List(); } val = level; if (val.ModulesDeadEnd3 == null) { val.ModulesDeadEnd3 = new List(); } val = level; if (val.ModulesExtraction3 == null) { val.ModulesExtraction3 = new List(); } val = level; if (val.ValuablePresets == null) { val.ValuablePresets = new List(); } val = level; if (val.AmbiencePresets == null) { val.AmbiencePresets = new List(); } 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(); } val = level; if (val.AmbiencePresets == null) { val.AmbiencePresets = new List(); } 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() { return EmpressIsSisyphusLevel(((Object)(object)LevelGenerator.Instance != (Object)null) ? LevelGenerator.Instance.Level : null) || EmpressIsSisyphusLevel(((Object)(object)RunManager.instance != (Object)null) ? RunManager.instance.levelCurrent : null); } private static bool EmpressIsSisyphusLevel(Level? level) { if ((Object)(object)level == (Object)null) { return false; } return string.Equals(((Object)level).name, "Level - Sisyphus", StringComparison.OrdinalIgnoreCase) || string.Equals(((Object)level).name, "Sisyphus", StringComparison.OrdinalIgnoreCase) || (!string.IsNullOrWhiteSpace(level.NarrativeName) && level.NarrativeName.IndexOf("sisyphus", StringComparison.OrdinalIgnoreCase) >= 0) || (!string.IsNullOrWhiteSpace(((Object)level).name) && ((Object)level).name.IndexOf("sisyphus", StringComparison.OrdinalIgnoreCase) >= 0); } 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() != (Object)null; } internal static IEnumerator EmpressSkipCoroutine() { yield break; } private static void EmpressApplyHideFlags(Object obj) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0068: 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_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: 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(true); foreach (Transform val2 in componentsInChildren) { ((Object)val2).hideFlags = (HideFlags)(((Object)val2).hideFlags | 0x23); GameObject gameObject = ((Component)val2).gameObject; ((Object)gameObject).hideFlags = (HideFlags)(((Object)gameObject).hideFlags | 0x23); Component[] components = ((Component)val2).GetComponents(); foreach (Component val3 in components) { if ((Object)(object)val3 != (Object)null) { ((Object)val3).hideFlags = (HideFlags)(((Object)val3).hideFlags | 0x23); } } } } internal static void EmpressEnsureExtractionPointCompatibility(ExtractionPoint extractionPoint) { //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0063: 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_007e: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: 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(); if ((Object)(object)component != (Object)null) { ((Renderer)component).enabled = false; } Collider component2 = val.GetComponent(); if ((Object)(object)component2 != (Object)null) { } 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; } } }