Decompiled source of LegacyCamRollFix v1.0.3

Mods/LegacyCamRollFix.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using HarmonyLib;
using Il2CppRUMBLE.Managers;
using Il2CppRUMBLE.Utilities;
using Il2CppTMPro;
using LegacyCamRollFix;
using MelonLoader;
using MelonLoader.Preferences;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[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), "LegacyCamRollFix", "1.0.3", "TacoSlayer36", null)]
[assembly: MelonGame("Buckethead Entertainment", "RUMBLE")]
[assembly: MelonColor(255, 255, 248, 231)]
[assembly: MelonAuthorColor(255, 255, 248, 231)]
[assembly: AssemblyTitle("LegacyCamRollFix")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LegacyCamRollFix")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("7aa16221-46a5-4a28-ab77-9094350b3711")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LegacyCamRollFix;

public static class BuildInfo
{
	public const string Name = "LegacyCamRollFix";

	public const string Author = "TacoSlayer36";

	public const string Version = "1.0.3";
}
[HarmonyPatch(typeof(RecordingCamera), "BeginFrameRendering")]
public static class CamPatch
{
	private static void Prefix()
	{
		Core.Instance.UpdateCamera();
	}
}
public class Core : MelonMod
{
	public bool GlobalInit = false;

	private GameObject applyRollButton;

	private GameObject fadeScreenButton;

	private bool rollEnabled = false;

	private bool showFadeScreen = false;

	private bool legacyCamEnabled = false;

	private float interpolatedHeadTilt = 0f;

	public static Core Instance;

	private MelonPreferences_Category prefs_Category;

	private MelonPreferences_Entry<bool> prefs_ApplyRoll;

	private MelonPreferences_Entry<bool> prefs_ShowFadeScreen;

	private RecordingCamera recordingCamera => Singleton<RecordingCamera>.instance;

	private GameObject fadeScreenRenderer => ((Component)((Component)recordingCamera).transform.GetChild(0)).gameObject;

	private Transform legacyCamUI => recordingCamera.recordingUIRoot;

	private Transform playerHead => ((Component)Singleton<PlayerManager>.Instance.localPlayer.Controller).transform.GetChild(2).GetChild(0).GetChild(0);

	private float headTilt
	{
		get
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			Quaternion rotation = playerHead.rotation;
			return ((Quaternion)(ref rotation)).eulerAngles.z;
		}
	}

	private float rotationSmoothing => recordingCamera.rotationalSlider.value;

	public override void OnLateInitializeMelon()
	{
		prefs_Category = MelonPreferences.CreateCategory("LegacyCamRollFix");
		prefs_ApplyRoll = prefs_Category.CreateEntry<bool>("ApplyRoll", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		prefs_ShowFadeScreen = prefs_Category.CreateEntry<bool>("ShowFadeScreen", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		Instance = this;
	}

	public override void OnSceneWasLoaded(int buildIndex, string sceneName)
	{
		if (sceneName == "Gym" && !GlobalInit)
		{
			GlobalInit = true;
			addUIButtons();
		}
	}

	private void addUIButtons()
	{
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0149: Unknown result type (might be due to invalid IL or missing references)
		bool value = prefs_ApplyRoll.Value;
		bool value2 = prefs_ShowFadeScreen.Value;
		applyRollButton = Object.Instantiate<GameObject>(((Component)legacyCamUI.Find("Enabled/Toggle - Standard")).gameObject);
		applyRollButton.transform.SetParent(legacyCamUI, false);
		((Object)applyRollButton).name = "ApplyRoll";
		applyRollButton.transform.Translate(new Vector3(0f, -70f, 0f), (Space)1);
		((TMP_Text)((Component)applyRollButton.transform.GetChild(1)).GetComponent<TextMeshProUGUI>()).text = "Apply Roll";
		Toggle componentInChildren = applyRollButton.GetComponentInChildren<Toggle>();
		((UnityEventBase)componentInChildren.onValueChanged).RemoveAllListeners();
		((UnityEvent<bool>)(object)componentInChildren.onValueChanged).AddListener(UnityAction<bool>.op_Implicit((Action<bool>)delegate(bool isOn)
		{
			onApplyRollToggle(isOn);
		}));
		componentInChildren.isOn = value;
		fadeScreenButton = Object.Instantiate<GameObject>(((Component)legacyCamUI.Find("Enabled/Toggle - Standard")).gameObject);
		fadeScreenButton.transform.SetParent(legacyCamUI, false);
		((Object)fadeScreenButton).name = "ShowFadeScreen";
		fadeScreenButton.transform.Translate(new Vector3(-165f, -70f, 0f), (Space)1);
		((TMP_Text)((Component)fadeScreenButton.transform.GetChild(1)).GetComponent<TextMeshProUGUI>()).text = "Show Fade Screen";
		Toggle componentInChildren2 = fadeScreenButton.GetComponentInChildren<Toggle>();
		((UnityEventBase)componentInChildren2.onValueChanged).RemoveAllListeners();
		((UnityEvent<bool>)(object)componentInChildren2.onValueChanged).AddListener(UnityAction<bool>.op_Implicit((Action<bool>)delegate(bool isOn)
		{
			onShowFadeScreenToggle(isOn);
		}));
		componentInChildren2.isOn = value2;
	}

	public override void OnUpdate()
	{
		if (!GlobalInit)
		{
			return;
		}
		if (((Component)legacyCamUI.parent).gameObject.activeSelf && recordingCamera.legacyCameraEnabledToggle.isOn && !legacyCamEnabled)
		{
			onLegacyCamEnabledToggle(isOn: true);
		}
		if (((Component)legacyCamUI.parent).gameObject.activeSelf && recordingCamera.legacyCameraEnabledToggle.isOn && legacyCamEnabled)
		{
			MelonCoroutines.Start(modifyUI());
		}
		float num = Mathf.Clamp(rotationSmoothing, 0.0001f, float.MaxValue);
		float num2 = 1f - Mathf.Exp((0f - Time.deltaTime) / num);
		try
		{
			interpolatedHeadTilt = Mathf.LerpAngle(interpolatedHeadTilt, headTilt, num2);
		}
		catch
		{
		}
	}

	public void UpdateCamera()
	{
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: 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_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		if (!GlobalInit)
		{
			return;
		}
		try
		{
			Quaternion rotation = ((Component)recordingCamera).gameObject.transform.rotation;
			Vector3 eulerAngles = ((Quaternion)(ref rotation)).eulerAngles;
			if (rollEnabled)
			{
				((Component)recordingCamera).gameObject.transform.rotation = Quaternion.Euler(eulerAngles.x, eulerAngles.y, interpolatedHeadTilt);
			}
			else
			{
				((Component)recordingCamera).gameObject.transform.rotation = Quaternion.Euler(eulerAngles.x, eulerAngles.y, 0f);
			}
		}
		catch
		{
		}
	}

	private void onLegacyCamEnabledToggle(bool isOn)
	{
		legacyCamEnabled = isOn;
		if (legacyCamEnabled)
		{
			MelonCoroutines.Start(modifyUI());
		}
		applyRollButton.SetActive(legacyCamEnabled);
		fadeScreenButton.SetActive(legacyCamEnabled);
	}

	private IEnumerator modifyUI()
	{
		Toggle enabledToggle = ((Component)legacyCamUI.Find("Enabled")).GetComponentInChildren<Toggle>();
		((UnityEvent<bool>)(object)enabledToggle.onValueChanged).AddListener(UnityAction<bool>.op_Implicit((Action<bool>)delegate(bool isOn)
		{
			onLegacyCamEnabledToggle(isOn);
		}));
		RectTransform rect = ((Component)legacyCamUI).GetComponent<RectTransform>();
		if (rect.sizeDelta.y != 500f)
		{
			yield return (object)new WaitForEndOfFrame();
			rect.sizeDelta = new Vector2(rect.sizeDelta.x, 500f);
			float newY = ((Component)legacyCamUI).transform.localPosition.x * -0.7582f + 820f;
			((Component)legacyCamUI).transform.localPosition = new Vector3(((Component)legacyCamUI).transform.localPosition.x, newY, ((Component)legacyCamUI).transform.localPosition.z);
		}
	}

	private void onApplyRollToggle(bool isOn)
	{
		rollEnabled = isOn;
		SetPrefs();
	}

	private void onShowFadeScreenToggle(bool isOn)
	{
		showFadeScreen = isOn;
		fadeScreenRenderer.layer = (isOn ? LayerMask.NameToLayer("PlayerController") : LayerMask.NameToLayer("PlayerFade"));
		SetPrefs();
	}

	public void SetPrefs()
	{
		if (GlobalInit)
		{
			prefs_ApplyRoll.Value = rollEnabled;
			prefs_ShowFadeScreen.Value = showFadeScreen;
			prefs_Category.SaveToFile(false);
		}
	}
}