Decompiled source of LegacyCamRollFix v1.0.1

Mods/LegacyCamRollFix.dll

Decompiled 2 months ago
using System.Diagnostics;
using System.IO;
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 UnityEngine;
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(global::LegacyCamRollFix.LegacyCamRollFix), "LegacyCamRollFix", "1.0.1", "TacoSlayer36", null)]
[assembly: MelonGame("Buckethead Entertainment", "RUMBLE")]
[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.1";
}
[HarmonyPatch(typeof(RecordingCamera), "Update")]
public static class Patch
{
	private static void Prefix()
	{
		LegacyCamRollFix.Instance.UpdateCamera();
	}

	private static void Postfix()
	{
		LegacyCamRollFix.Instance.UpdateCamera();
	}
}
public class LegacyCamRollFix : MelonMod
{
	private RecordingCamera recordingCamera;

	private GameObject menuLabel;

	private GameObject playerHead;

	private string currentScene = "Loader";

	private bool rollEnabled = false;

	private bool rollEnabledPrev = false;

	private bool init = false;

	private bool recordedToggle = false;

	private float headRot = 0f;

	private float interpolatedHeadRot = 0f;

	private float rotationSmoothing = 0.1f;

	private Slider slider;

	public static LegacyCamRollFix Instance;

	public override void OnLateInitializeMelon()
	{
		rollEnabled = readFile();
		rollEnabledPrev = rollEnabled;
		Instance = this;
	}

	public override void OnSceneWasLoaded(int buildIndex, string sceneName)
	{
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		currentScene = sceneName;
		if (currentScene == "Loader")
		{
			if (!init)
			{
				recordingCamera = Singleton<RecordingCamera>.instance;
				GameObject val = GameObject.Find("Game Instance/UI/Recording UI/Panel/Enabled/Toggle - Standard");
				menuLabel = Object.Instantiate<GameObject>(val);
				((Object)menuLabel).name = "LegacyCamRollFixToggle";
				menuLabel.transform.SetParent(val.transform.parent, false);
				menuLabel.transform.localPosition = new Vector3(81.1998f, -225f, 0f);
				((TMP_Text)((Component)menuLabel.transform.GetChild(1)).GetComponent<TextMeshProUGUI>()).text = "Apply Roll";
			}
			init = true;
		}
	}

	public override void OnUpdate()
	{
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if ((Object)(object)playerHead == (Object)null)
			{
				playerHead = ((Component)((Component)Singleton<PlayerManager>.Instance.LocalPlayer.Controller).gameObject.transform.GetChild(2).GetChild(0).GetChild(0)).gameObject;
			}
			else
			{
				Quaternion rotation = playerHead.transform.rotation;
				headRot = ((Quaternion)(ref rotation)).eulerAngles.z;
			}
			if ((Object)(object)slider == (Object)null)
			{
				slider = GameObject.Find("Game Instance/UI/Recording UI/Panel/RotationSmoothing/Slider - Outline").GetComponent<Slider>();
			}
			else
			{
				rotationSmoothing = (rotationSmoothing = RemapSmoothing(slider.value));
			}
		}
		catch
		{
		}
		float num = ((rotationSmoothing == 0f) ? 0.0001f : rotationSmoothing);
		float num2 = 1f - Mathf.Exp((0f - Time.deltaTime) / num);
		interpolatedHeadRot = Mathf.LerpAngle(interpolatedHeadRot, headRot, num2);
		UpdateCamera();
	}

	public override void OnFixedUpdate()
	{
		if (recordedToggle)
		{
			if ((Object)(object)menuLabel != (Object)null)
			{
				rollEnabled = ((Component)menuLabel.transform.GetChild(0)).gameObject.GetComponent<Toggle>().isOn;
				menuLabel.SetActive(((Component)menuLabel.transform.parent.parent.GetChild(0)).gameObject.active);
			}
			if (rollEnabledPrev != rollEnabled)
			{
				writeFile(rollEnabled);
			}
			rollEnabledPrev = rollEnabled;
			return;
		}
		try
		{
			((Component)menuLabel.transform.GetChild(0)).gameObject.GetComponent<Toggle>().isOn = rollEnabled;
			recordedToggle = true;
		}
		catch
		{
			recordedToggle = false;
		}
	}

	public void UpdateCamera()
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: 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_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		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, interpolatedHeadRot);
			}
			else
			{
				((Component)recordingCamera).gameObject.transform.rotation = Quaternion.Euler(eulerAngles.x, eulerAngles.y, 0f);
			}
		}
		catch
		{
		}
	}

	private float RemapSmoothing(float input)
	{
		float num = 0.1f;
		float num2 = 1f;
		float num3 = 0.1f;
		float num4 = 4f;
		float num5 = Mathf.Clamp01((input - num) / (num2 - num));
		float num6 = 4.52f;
		return num3 + (num4 - num3) * Mathf.Pow(num5, num6);
	}

	private void writeFile(bool enabled)
	{
		if (!Directory.Exists("UserData/LegacyCamRollFix"))
		{
			Directory.CreateDirectory("UserData/LegacyCamRollFix");
		}
		File.WriteAllText("UserData/LegacyCamRollFix/toggle.txt", enabled ? "1" : "0");
	}

	private bool readFile()
	{
		if (File.Exists("UserData/LegacyCamRollFix/toggle.txt"))
		{
			string text = File.ReadAllText("UserData/LegacyCamRollFix/toggle.txt");
			return text == "1";
		}
		return false;
	}

	private void grabStuff()
	{
	}
}