Decompiled source of LoadMirror v1.1.1

Patch3_MelonLoader0.5/Mods/LoadMirror.P3.ML5.dll

Decompiled 6 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using HarmonyLib;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using SLZ.Marrow.SceneStreaming;
using SLZ.Marrow.Warehouse;
using SLZ.Rig;
using SLZ.SaveData;
using Sst.LoadMirror;
using Sst.Utilities;
using UnhollowerBaseLib;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.XR;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("LoadMirror")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany(null)]
[assembly: AssemblyProduct("LoadMirror")]
[assembly: AssemblyCopyright("Created by jakzo")]
[assembly: AssemblyTrademark(null)]
[assembly: ComVisible(false)]
[assembly: AssemblyFileVersion("1.1.1")]
[assembly: NeutralResourcesLanguage("en")]
[assembly: MelonInfo(typeof(Mod), "LoadMirror", "1.1.1", "jakzo", "https://bonelab.thunderstore.io/package/jakzo/LoadMirror/")]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.1.1.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Sst
{
	public class Metadata
	{
		public const string AUTHOR = "jakzo";

		public const string COMPANY = null;

		public const string DEVELOPER = "Stress Level Zero";

		public const string GAME = "BONELAB";

		public const string GAME_BONEWORKS = "BONEWORKS";
	}
	public class Dbg
	{
		private static MelonPreferences_Entry<bool> _prefPrintDebugLogs;

		public static void Init(string prefCategoryId)
		{
			_prefPrintDebugLogs = MelonPreferences.CreateCategory(prefCategoryId).CreateEntry<bool>("printDebugLogs", false, "Print debug logs to console", (string)null, false, false, (ValueValidator)null, (string)null);
		}

		public static void Log(string msg, params object[] data)
		{
			if (_prefPrintDebugLogs.Value)
			{
				MelonLogger.Msg("dbg: " + msg);
			}
		}
	}
}
namespace Sst.Utilities
{
	internal static class LevelHooks
	{
		[HarmonyPatch(typeof(BasicTrackingRig), "Awake")]
		private class BasicTrackingRig_Awake_Patch
		{
			[CompilerGenerated]
			private static class <>O
			{
				public static LemonAction <0>__WaitForLoadFinished;
			}

			[HarmonyPrefix]
			internal static void Prefix(BasicTrackingRig __instance)
			{
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_006b: 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_0076: Expected O, but got Unknown
				Dbg.Log("BasicTrackingRig_Awake_Patch");
				_loadingScene = ((Component)__instance).gameObject.scene;
				if (Object.op_Implicit((Object)(object)CurrentLevel))
				{
					PrevLevel = CurrentLevel;
				}
				CurrentLevel = null;
				NextLevel = SceneStreamer.Session.Level;
				RigManager = null;
				BasicTrackingRig = __instance;
				MelonEvent onUpdate = MelonEvents.OnUpdate;
				object obj = <>O.<0>__WaitForLoadFinished;
				if (obj == null)
				{
					LemonAction val = WaitForLoadFinished;
					<>O.<0>__WaitForLoadFinished = val;
					obj = (object)val;
				}
				((MelonEventBase<LemonAction>)(object)onUpdate).Subscribe((LemonAction)obj, 0, false);
				LevelCrate nextLevel = NextLevel;
				Dbg.Log("OnLoad " + ((nextLevel != null) ? ((Scannable)nextLevel).Title : null));
				SafeInvoke("OnLoad", LevelHooks.OnLoad, NextLevel);
			}
		}

		[HarmonyPatch(typeof(RigManager), "Awake")]
		private class RigManager_Awake_Patch
		{
			[HarmonyPrefix]
			internal static void Prefix(RigManager __instance)
			{
				Dbg.Log("RigManager_Awake_Patch");
				RigManager = __instance;
				BasicTrackingRig = null;
			}
		}

		[CompilerGenerated]
		private static class <>O
		{
			public static LemonAction <0>__WaitForLoadFinished;
		}

		public static LevelCrate PrevLevel;

		public static LevelCrate CurrentLevel;

		public static LevelCrate NextLevel;

		public static RigManager RigManager;

		public static BasicTrackingRig BasicTrackingRig;

		private static Scene _loadingScene;

		public static bool IsLoading => !Object.op_Implicit((Object)(object)CurrentLevel);

		public static event Action<LevelCrate> OnLoad;

		public static event Action<LevelCrate> OnLevelStart;

		private static void SafeInvoke(string name, Action<LevelCrate> action, LevelCrate level)
		{
			try
			{
				action?.Invoke(level);
			}
			catch (Exception ex)
			{
				MelonLogger.Error("Failed to execute " + name + " event: " + ex.ToString());
			}
		}

		private static void WaitForLoadFinished()
		{
			//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_002d: Expected O, but got Unknown
			if (!((Scene)(ref _loadingScene)).isLoaded)
			{
				MelonEvent onUpdate = MelonEvents.OnUpdate;
				object obj = <>O.<0>__WaitForLoadFinished;
				if (obj == null)
				{
					LemonAction val = WaitForLoadFinished;
					<>O.<0>__WaitForLoadFinished = val;
					obj = (object)val;
				}
				((MelonEventBase<LemonAction>)(object)onUpdate).Unsubscribe((LemonAction)obj);
				CurrentLevel = NextLevel ?? SceneStreamer.Session.Level ?? CurrentLevel;
				NextLevel = null;
				LevelCrate currentLevel = CurrentLevel;
				Dbg.Log("OnLevelStart " + ((currentLevel != null) ? ((Scannable)currentLevel).Title : null));
				SafeInvoke("OnLevelStart", LevelHooks.OnLevelStart, CurrentLevel);
			}
		}
	}
}
namespace Sst.LoadMirror
{
	internal static class AppVersion
	{
		public const string Value = "1.1.1";
	}
	public static class BuildInfo
	{
		public const string NAME = "LoadMirror";
	}
	public class Mod : MelonMod
	{
		private GameObject _overlay;

		public override void OnInitializeMelon()
		{
			Dbg.Init("LoadMirror");
			LevelHooks.OnLoad += OnLoad;
		}

		private void OnLoad(LevelCrate nextLevel)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Invalid comparison between Unknown and I4
			Scene scene = ((Component)LevelHooks.BasicTrackingRig).gameObject.scene;
			Il2CppReferenceArray<GameObject> rootGameObjects = ((Scene)(ref scene)).GetRootGameObjects();
			_overlay = ((IEnumerable<GameObject>)rootGameObjects).FirstOrDefault((Func<GameObject, bool>)((GameObject go) => ((Object)go).name == "2D_Overlay")) ?? ((IEnumerable<GameObject>)rootGameObjects).FirstOrDefault((Func<GameObject, bool>)((GameObject go) => ((Object)go).name == "Canvas"));
			if ((Object)(object)_overlay != (Object)null)
			{
				_overlay.SetActive(false);
			}
			else
			{
				MelonLogger.Warning("Overlay not found in loading screen");
			}
			if ((int)DataManager.Instance._settings.SpectatorSettings.SpectatorCameraMode == 1)
			{
				Dbg.Log("XRSettings.gameViewRenderMode = GameViewRenderMode.LeftEye");
				XRSettings.gameViewRenderMode = (GameViewRenderMode)1;
			}
		}
	}
}

Patch4_MelonLoader0.6/Mods/LoadMirror.P4.ML6.dll

Decompiled 6 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSLZ.Bonelab.SaveData;
using Il2CppSLZ.Marrow.SaveData;
using Il2CppSLZ.Marrow.SceneStreaming;
using Il2CppSLZ.Marrow.Warehouse;
using Il2CppSLZ.Rig;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using Sst.LoadMirror;
using Sst.Utilities;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.XR;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("LoadMirror")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany(null)]
[assembly: AssemblyProduct("LoadMirror")]
[assembly: AssemblyCopyright("Created by jakzo")]
[assembly: AssemblyTrademark(null)]
[assembly: ComVisible(false)]
[assembly: AssemblyFileVersion("1.1.1")]
[assembly: NeutralResourcesLanguage("en")]
[assembly: MelonInfo(typeof(Mod), "LoadMirror", "1.1.1", "jakzo", "https://bonelab.thunderstore.io/package/jakzo/LoadMirror/")]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyVersion("1.1.1.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Sst
{
	public class Metadata
	{
		public const string AUTHOR = "jakzo";

		public const string COMPANY = null;

		public const string DEVELOPER = "Stress Level Zero";

		public const string GAME = "BONELAB";

		public const string GAME_BONEWORKS = "BONEWORKS";
	}
	public class Dbg
	{
		private static MelonPreferences_Entry<bool> _prefPrintDebugLogs;

		public static void Init(string prefCategoryId)
		{
			_prefPrintDebugLogs = MelonPreferences.CreateCategory(prefCategoryId).CreateEntry<bool>("printDebugLogs", false, "Print debug logs to console", (string)null, false, false, (ValueValidator)null, (string)null);
		}

		public static void Log(string msg, params object[] data)
		{
			if (_prefPrintDebugLogs.Value)
			{
				MelonLogger.Msg("dbg: " + msg);
			}
		}
	}
}
namespace Sst.Utilities
{
	internal static class LevelHooks
	{
		[HarmonyPatch(typeof(BasicTrackingRig), "Awake")]
		private class BasicTrackingRig_Awake_Patch
		{
			[CompilerGenerated]
			private static class <>O
			{
				public static LemonAction <0>__WaitForLoadFinished;
			}

			[HarmonyPrefix]
			internal static void Prefix(BasicTrackingRig __instance)
			{
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_006b: 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_0076: Expected O, but got Unknown
				Dbg.Log("BasicTrackingRig_Awake_Patch");
				_loadingScene = ((Component)__instance).gameObject.scene;
				if (Object.op_Implicit((Object)(object)CurrentLevel))
				{
					PrevLevel = CurrentLevel;
				}
				CurrentLevel = null;
				NextLevel = SceneStreamer.Session.Level;
				RigManager = null;
				BasicTrackingRig = __instance;
				MelonEvent onUpdate = MelonEvents.OnUpdate;
				object obj = <>O.<0>__WaitForLoadFinished;
				if (obj == null)
				{
					LemonAction val = WaitForLoadFinished;
					<>O.<0>__WaitForLoadFinished = val;
					obj = (object)val;
				}
				((MelonEventBase<LemonAction>)(object)onUpdate).Subscribe((LemonAction)obj, 0, false);
				LevelCrate nextLevel = NextLevel;
				Dbg.Log("OnLoad " + ((nextLevel != null) ? ((Scannable)nextLevel).Title : null));
				SafeInvoke("OnLoad", LevelHooks.OnLoad, NextLevel);
			}
		}

		[HarmonyPatch(typeof(RigManager), "Awake")]
		private class RigManager_Awake_Patch
		{
			[HarmonyPrefix]
			internal static void Prefix(RigManager __instance)
			{
				Dbg.Log("RigManager_Awake_Patch");
				RigManager = __instance;
				BasicTrackingRig = null;
			}
		}

		[CompilerGenerated]
		private static class <>O
		{
			public static LemonAction <0>__WaitForLoadFinished;
		}

		public static LevelCrate PrevLevel;

		public static LevelCrate CurrentLevel;

		public static LevelCrate NextLevel;

		public static RigManager RigManager;

		public static BasicTrackingRig BasicTrackingRig;

		private static Scene _loadingScene;

		public static bool IsLoading => !Object.op_Implicit((Object)(object)CurrentLevel);

		public static event Action<LevelCrate> OnLoad;

		public static event Action<LevelCrate> OnLevelStart;

		private static void SafeInvoke(string name, Action<LevelCrate> action, LevelCrate level)
		{
			try
			{
				action?.Invoke(level);
			}
			catch (Exception ex)
			{
				MelonLogger.Error("Failed to execute " + name + " event: " + ex.ToString());
			}
		}

		private static void WaitForLoadFinished()
		{
			//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_002d: Expected O, but got Unknown
			if (!((Scene)(ref _loadingScene)).isLoaded)
			{
				MelonEvent onUpdate = MelonEvents.OnUpdate;
				object obj = <>O.<0>__WaitForLoadFinished;
				if (obj == null)
				{
					LemonAction val = WaitForLoadFinished;
					<>O.<0>__WaitForLoadFinished = val;
					obj = (object)val;
				}
				((MelonEventBase<LemonAction>)(object)onUpdate).Unsubscribe((LemonAction)obj);
				CurrentLevel = NextLevel ?? SceneStreamer.Session.Level ?? CurrentLevel;
				NextLevel = null;
				LevelCrate currentLevel = CurrentLevel;
				Dbg.Log("OnLevelStart " + ((currentLevel != null) ? ((Scannable)currentLevel).Title : null));
				SafeInvoke("OnLevelStart", LevelHooks.OnLevelStart, CurrentLevel);
			}
		}
	}
}
namespace Sst.LoadMirror
{
	internal static class AppVersion
	{
		public const string Value = "1.1.1";
	}
	public static class BuildInfo
	{
		public const string NAME = "LoadMirror";
	}
	public class Mod : MelonMod
	{
		private GameObject _overlay;

		public override void OnInitializeMelon()
		{
			Dbg.Init("LoadMirror");
			LevelHooks.OnLoad += OnLoad;
		}

		private void OnLoad(LevelCrate nextLevel)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Invalid comparison between Unknown and I4
			Scene scene = ((Component)LevelHooks.BasicTrackingRig).gameObject.scene;
			Il2CppReferenceArray<GameObject> rootGameObjects = ((Scene)(ref scene)).GetRootGameObjects();
			_overlay = ((IEnumerable<GameObject>)rootGameObjects).FirstOrDefault((Func<GameObject, bool>)((GameObject go) => ((Object)go).name == "2D_Overlay")) ?? ((IEnumerable<GameObject>)rootGameObjects).FirstOrDefault((Func<GameObject, bool>)((GameObject go) => ((Object)go).name == "Canvas"));
			if ((Object)(object)_overlay != (Object)null)
			{
				_overlay.SetActive(false);
			}
			else
			{
				MelonLogger.Warning("Overlay not found in loading screen");
			}
			if ((int)((MarrowDataManager<DataManager, Save, Settings, PlayerProgression, PlayerUnlocks>)(object)DataManager.Instance)._settings.SpectatorSettings.SpectatorCameraMode == 1)
			{
				Dbg.Log("XRSettings.gameViewRenderMode = GameViewRenderMode.LeftEye");
				XRSettings.gameViewRenderMode = (GameViewRenderMode)1;
			}
		}
	}
}