Decompiled source of LegacyCamFixes v1.0.0

Mods/LegacyCamFixes.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using HarmonyLib;
using Il2CppRUMBLE.Managers;
using Il2CppRUMBLE.Players;
using Il2CppRUMBLE.Players.Subsystems;
using Il2CppRUMBLE.Utilities;
using LegacyCamFix;
using LegacyCamFixes;
using MelonLoader;
using MelonLoader.Preferences;
using UIFramework;
using UIFramework.Models;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Core), "LegacyCamFixes", "1.0.0", "TacoSlayer36", null)]
[assembly: MelonGame("Buckethead Entertainment", "RUMBLE")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("LegacyCamFixes")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LegacyCamFixes")]
[assembly: AssemblyTitle("LegacyCamFixes")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LegacyCamFixes
{
	public static class BuildInfo
	{
		public const string Name = "LegacyCamFixes";

		public const string Author = "TacoSlayer36";

		public const string Version = "1.0.0";
	}
	public class Core : MelonMod
	{
		[HarmonyPatch(typeof(RecordingCamera), "BeginFrameRendering")]
		public static class CamPatch
		{
			private static void Prefix()
			{
				if (!localPlayerLoaded)
				{
					return;
				}
				try
				{
					UpdateCamera();
				}
				catch
				{
				}
			}
		}

		[HarmonyPatch(typeof(PlayerManager), "SpawnPlayerController", new Type[]
		{
			typeof(Player),
			typeof(Vector3),
			typeof(Quaternion)
		})]
		public static class SpawnPlayerPatch
		{
			private static void Postfix(PlayerManager __instance, Player __0, Vector3 __1, Quaternion __2)
			{
				if (HasDeprecatedVersion)
				{
					warnDeprecated();
				}
				else if (!localPlayerLoaded)
				{
					localFadeScreen = ((Component)((Component)Singleton<PlayerManager>.Instance.LocalPlayer.Controller.PlayerVR.headset.Transform).GetComponentInChildren<SimpleScreenFadeInstance>()).gameObject;
					localPlayerLoaded = true;
					SetFadeScreen(_: false, Config.ScreenFade.EditedValue);
				}
			}
		}

		public static Core Instance;

		private static bool localPlayerLoaded;

		private static GameObject localFadeScreen;

		private static float interpolatedHeadTilt;

		public static bool HasDeprecatedVersion;

		public static RecordingCamera LegacyCam => Singleton<RecordingCamera>.Instance;

		private static float headTilt
		{
			get
			{
				//IL_0078: Unknown result type (might be due to invalid IL or missing references)
				PlayerManager instance = Singleton<PlayerManager>.Instance;
				float? obj;
				if (instance == null)
				{
					obj = null;
				}
				else
				{
					Player localPlayer = instance.LocalPlayer;
					if (localPlayer == null)
					{
						obj = null;
					}
					else
					{
						PlayerController controller = localPlayer.Controller;
						if (controller == null)
						{
							obj = null;
						}
						else
						{
							PlayerVR playerVR = controller.PlayerVR;
							if (playerVR == null)
							{
								obj = null;
							}
							else
							{
								VRTransform headset = playerVR.Headset;
								if (headset == null)
								{
									obj = null;
								}
								else
								{
									Transform transform = headset.Transform;
									obj = ((transform != null) ? new float?(transform.eulerAngles.z) : ((float?)null));
								}
							}
						}
					}
				}
				float? num = obj;
				return num.GetValueOrDefault();
			}
		}

		public override void OnLateInitializeMelon()
		{
			Instance = this;
			Config.SetUpUI();
			if (MelonBase.RegisteredMelons.Any((MelonBase m) => m.Info.Name == "LegacyCamRollFix"))
			{
				HasDeprecatedVersion = true;
				warnDeprecated();
			}
		}

		public override void OnSceneWasUnloaded(int buildIndex, string sceneName)
		{
			localPlayerLoaded = false;
			localFadeScreen = null;
		}

		public static void SetFadeScreen(bool _, bool enabled)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			if (HasDeprecatedVersion)
			{
				warnDeprecated();
			}
			else if (localPlayerLoaded)
			{
				localFadeScreen.transform.localScale = Vector3.one * (enabled ? 1000f : 0.1692f);
				localFadeScreen.layer = ((!enabled) ? LayerMask.NameToLayer("ScreenFade") : 0);
			}
		}

		public override void OnUpdate()
		{
			if (!HasDeprecatedVersion && localPlayerLoaded)
			{
				float value = LegacyCam.rotationalSlider.value;
				float num = Mathf.Clamp(value, 0.0001f, float.MaxValue);
				float num2 = 1f - Mathf.Exp((0f - Time.deltaTime) / num);
				interpolatedHeadTilt = Mathf.LerpAngle(interpolatedHeadTilt, headTilt, num2);
			}
		}

		public static void UpdateCamera()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			if (!HasDeprecatedVersion)
			{
				Quaternion rotation = ((Component)LegacyCam).gameObject.transform.rotation;
				Vector3 eulerAngles = ((Quaternion)(ref rotation)).eulerAngles;
				if (Config.HeadRoll.EditedValue)
				{
					((Component)LegacyCam).gameObject.transform.rotation = Quaternion.Euler(eulerAngles.x, eulerAngles.y, interpolatedHeadTilt);
				}
				else
				{
					((Component)LegacyCam).gameObject.transform.rotation = Quaternion.Euler(eulerAngles.x, eulerAngles.y, 0f);
				}
			}
		}

		private static void warnDeprecated()
		{
			((MelonBase)Instance).LoggerInstance.Warning("LegacyCamFixes is meant to replace LegacyCamRollFix. Uninstall LegacyCamRollFix for it to work properly");
		}
	}
}
namespace LegacyCamFix
{
	public static class Config
	{
		public static MelonModel Instance;

		public static MelonPreferences_Category Cat_Settings;

		public static MelonPreferences_Entry<bool> HeadRoll;

		public static MelonPreferences_Entry<bool> ScreenFade;

		public static string UserDataPath => Path.Combine("UserData", "LegacyCamFixes");

		public static string ConfigFilePath => Path.Combine(UserDataPath, "Config.cfg");

		public static void SetUpUI()
		{
			Directory.CreateDirectory(ConfigFilePath);
			Cat_Settings = MelonPreferences.CreateCategory("LegacyCamFixes_Settings", "Settings");
			Cat_Settings.SetFilePath(ConfigFilePath);
			HeadRoll = Cat_Settings.CreateEntry<bool>("LegacyCamFixes_HeadRoll", true, "Apply the tilt of your head to the Legacy Cam", (string)null, false, false, (ValueValidator)null, (string)null);
			ScreenFade = Cat_Settings.CreateEntry<bool>("LegacyCamFixes_ScreenFade", true, "Show the fade to black on the Legacy Cam", (string)null, false, false, (ValueValidator)null, (string)null);
			Instance = UI.RegisterMelon((MelonBase)(object)Core.Instance, (MelonPreferences_Category[])(object)new MelonPreferences_Category[1] { Cat_Settings });
			((MelonEventBase<LemonAction<bool, bool>>)(object)ScreenFade.OnEntryValueChanged).Subscribe((LemonAction<bool, bool>)Core.SetFadeScreen, 0, false);
		}
	}
}