Decompiled source of StaticLIVCamera v3.0.2

Mods/StaticLIVCamera.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppLIV.SDK.Unity;
using Il2CppRUMBLE.Managers;
using Il2CppRUMBLE.Utilities;
using Il2CppTMPro;
using MelonLoader;
using Microsoft.CodeAnalysis;
using RumbleModUI;
using RumbleModdingAPI;
using StaticLIVCamera;
using StaticLIVCamera.modes;
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(Main), "StaticLIVCamera", "3.0.2", "PeppaStone", null)]
[assembly: MelonGame("Buckethead Entertainment", "RUMBLE")]
[assembly: MelonColor(255, 255, 51, 238)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("StaticLIVCamera")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("StaticLIVCamera")]
[assembly: AssemblyTitle("StaticLIVCamera")]
[assembly: AssemblyVersion("1.0.0.0")]
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;
		}
	}
}
namespace StaticLIVCamera
{
	public static class BuildInfo
	{
		public const string ModName = "StaticLIVCamera";

		public const string ModVersion = "3.0.2";

		public const string Description = "A fully custom camera mod that overrides the default LIV camera";

		public const string Author = "PeppaStone";

		public const string Company = "PeppaStone";
	}
	[RegisterTypeInIl2Cpp]
	internal class CustomLIVCamera : MonoBehaviour
	{
		private LIV liv;

		private bool switchingCamera = false;

		private GameObject modeTextObject;

		private int activeTexts = 0;

		private Transform cameraOutput;

		private void Start()
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			GameObject gameObject = ((Component)((Component)Singleton<PlayerManager>.instance.localPlayer.Controller).transform.GetChild(9).GetChild(0)).gameObject;
			gameObject.transform.localPosition = new Vector3(0f, 0f, 0f);
			gameObject.transform.localRotation = Quaternion.Euler(0f, 0f, 0f);
			liv = gameObject.GetComponent<LIV>();
			CreateModeText();
			cameraOutput = ((Component)this).transform.GetChild(1);
			GoToDefaultPos();
			SetCameraMode(Main.currentMode);
		}

		private void Update()
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			CheckInputs();
			try
			{
				Main.cameraModes[Main.currentMode].OnUpdate();
				if ((bool)((ModSetting)Main.lockZRot).Value)
				{
					Transform transform = ((Component)this).transform;
					Quaternion localRotation = ((Component)this).transform.localRotation;
					float x = ((Quaternion)(ref localRotation)).eulerAngles.x;
					localRotation = ((Component)this).transform.localRotation;
					transform.localRotation = Quaternion.Euler(x, ((Quaternion)(ref localRotation)).eulerAngles.y, 0f);
				}
			}
			catch
			{
			}
			try
			{
				if (Main.cameraModes[Main.currentMode].name != "Default")
				{
					liv.render.SetPose(cameraOutput.position, cameraOutput.rotation, (float)((ModSetting)Main.fov).Value, false);
				}
			}
			catch
			{
			}
		}

		private void GoToDefaultPos()
		{
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			switch (Main.currentScene)
			{
			case "Gym":
				num = 0;
				break;
			case "Park":
				num = 1;
				break;
			case "Map0":
				num = 2;
				break;
			case "Map1":
				num = 3;
				break;
			}
			float[] array = Main.ParseInputString((string)((ModSetting)Main.defaultCameraPos[num]).Value);
			try
			{
				Main.camera.transform.position = new Vector3(array[0], array[1], array[2]);
				Main.camera.transform.rotation = Quaternion.Euler(array[3], array[4], array[5]);
			}
			catch
			{
				MelonLogger.Msg("DEFAULT CAMERA POSITION IS NOT VALID. MAKE SURE TO FOLLOW THIS FORMAT: XPosition YPosition ZPosition XRotation YRotation Zrotation");
			}
		}

		private void CheckInputs()
		{
			try
			{
				if ((RightController.GetJoystickClick() == 1f && RightController.GetTrigger() >= 0.9f) || Input.GetKeyDown((KeyCode)117))
				{
					if (!switchingCamera)
					{
						switchingCamera = true;
						SetCameraMode(Main.currentMode + 1);
						if ((bool)((ModSetting)Main.isModeAnnounced).Value)
						{
							MelonCoroutines.Start(AnnounceCameraMode());
						}
					}
				}
				else
				{
					switchingCamera = false;
				}
				if (LeftController.GetSecondary() == 1f)
				{
					((ModSetting)Main.fov).Value = (float)((ModSetting)Main.fov).Value - (float)((ModSetting)Main.fovChangeSpeed).Value * Time.deltaTime;
				}
				if (RightController.GetSecondary() == 1f)
				{
					((ModSetting)Main.fov).Value = (float)((ModSetting)Main.fov).Value + (float)((ModSetting)Main.fovChangeSpeed).Value * Time.deltaTime;
				}
			}
			catch
			{
			}
		}

		private void CreateModeText()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: 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)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			modeTextObject = Create.NewText("Debugging Mode", 3f, Color.white, Vector3.zero, Quaternion.identity);
			modeTextObject.transform.parent = ((Component)((Component)((Component)((Component)Singleton<PlayerManager>.instance.localPlayer.Controller).transform.GetChild(1)).transform.GetChild(0)).transform.GetChild(0)).transform;
			modeTextObject.transform.localPosition = new Vector3(0f, 0f, 1f);
			modeTextObject.transform.localRotation = Quaternion.Euler(0f, 0f, 0f);
			TextMeshPro component = modeTextObject.GetComponent<TextMeshPro>();
			((TMP_Text)component).alignment = (TextAlignmentOptions)514;
			((TMP_Text)component).enableWordWrapping = false;
			((TMP_Text)component).outlineWidth = 0.1f;
			modeTextObject.active = false;
		}

		private IEnumerator AnnounceCameraMode()
		{
			if ((bool)((ModSetting)Main.isModeAnnounced).Value)
			{
				activeTexts++;
				modeTextObject.active = true;
				TextMeshPro modeText = modeTextObject.GetComponent<TextMeshPro>();
				((TMP_Text)modeText).text = Main.cameraModes[Main.currentMode].name + " Mode";
				yield return (object)new WaitForSeconds(1f);
				activeTexts--;
				if (activeTexts == 0)
				{
					modeTextObject.active = false;
				}
			}
		}

		private void SetCameraMode(int mode)
		{
			int num = 0;
			for (int i = 0; i < Main.cameraModes.Count; i++)
			{
				if ((bool)((ModSetting)Main.cameraModes[i].isModeEnabled).Value)
				{
					num++;
				}
			}
			if (num == 0)
			{
				MelonLogger.Msg("No modes are enabled");
				return;
			}
			if (mode >= Main.cameraModes.Count)
			{
				mode = 0;
			}
			if (!(bool)((ModSetting)Main.cameraModes[mode].isModeEnabled).Value)
			{
				SetCameraMode(mode + 1);
				return;
			}
			Main.cameraModes[Main.currentMode].OnExitingMode();
			Main.cameraModes[mode].OnEnteringMode();
			Main.currentMode = mode;
			if ((bool)((ModSetting)Main.hideCameraModel).Value)
			{
				((Component)Main.camera.transform.GetChild(0)).gameObject.active = false;
			}
		}
	}
	public class Main : MelonMod
	{
		public static List<CameraMode> cameraModes = new List<CameraMode>();

		public static int currentMode = 1;

		public static GameObject camera;

		public static string currentScene = "";

		public static Mod Mod = new Mod();

		public static ModSetting<string>[] defaultCameraPos = new ModSetting<string>[4];

		public static ModSetting<float> fov;

		public static ModSetting<float> fovChangeSpeed;

		public static ModSetting<bool> isStaticByDefault;

		public static ModSetting<bool> isModeAnnounced;

		public static ModSetting<float> orbitSpeed;

		public static ModSetting<float> lockedSpeed;

		public static ModSetting<float> autoPosSpeed;

		public static ModSetting<float> autoRotSpeed;

		public static ModSetting<bool> switchProfile;

		public static ModSetting<bool> alternateControls;

		public static ModSetting<bool> lockZRot;

		public static ModSetting<bool> hideCameraModel;

		public static Il2CppAssetBundle cameraBundle;

		public void SceneLoaded()
		{
			if (!(currentScene == "Loader"))
			{
				camera = Object.Instantiate<GameObject>(cameraBundle.LoadAsset<GameObject>("Camera"));
				camera.AddComponent<CustomLIVCamera>();
			}
		}

		[Obsolete]
		public void OnUIInit()
		{
			Mod.ModName = "StaticLIVCamera";
			Mod.ModVersion = "3.0.2";
			Mod.SetFolder("StaticLIVCamera");
			Mod.AddDescription("Description", "", "A fully custom camera mod that overrides the default LIV camera", true, false);
			fov = Mod.AddToList("FOV", 75f, "The FOV of the LIV Camera (doesn't work in Default Mode)");
			fovChangeSpeed = Mod.AddToList("FOV Change Speed", 0f, "The speed at which your secondary buttons will impact your FOV in degrees per second");
			orbitSpeed = Mod.AddToList("Orbit Speed", 10f, "The speed at which the camera orbits in Orbit Mode.");
			autoPosSpeed = Mod.AddToList("Camera Position Smoothing", 3f, "The lower the number, the more smooth the camera position will be. Except for 0, where there is no smoothing.");
			autoRotSpeed = Mod.AddToList("Camera Rotation Smoothing", 3f, "The lower the number, the more smooth the camera rotation will be. Except for 0, where there is no smoothing.");
			defaultCameraPos[0] = Mod.AddToList("Default Gym Camera Position", "2.2 6.2 -9.0 30 4.7 0", "The default camera position on the Gym Map. Uses this syntax: XPosition YPosition ZPosition XRotation YRotation ZRotation");
			defaultCameraPos[1] = Mod.AddToList("Default Park Camera Position", "-15.2 12.7 -0.6 57.9 90.0 0", "The default camera position on the Park Map. Uses this syntax: XPosition YPosition ZPosition XRotation YRotation ZRotation");
			defaultCameraPos[2] = Mod.AddToList("Default Ring Camera Position", "-10.6 11.9 7.8 47.4 133.4 0", "The default camera position on the Ring Map. Uses this syntax: XPosition YPosition ZPosition XRotation YRotation ZRotation");
			defaultCameraPos[3] = Mod.AddToList("Default Pit Camera Position", "-2 9 -11.4 33 7.5 0", "The default camera position on the Pit Map. Uses this syntax: XPosition YPosition ZPosition XRotation YRotation ZRotation");
			isModeAnnounced = Mod.AddToList("Announce mode when changing", true, 0, "If this setting is enabled, your camera mode will be announced with text in front of you whenever you switch modes");
			lockZRot = Mod.AddToList("Lock Z Rotation", true, 0, "If turned on, the Z rotation of the camera will be locked to 0");
			hideCameraModel = Mod.AddToList("Hide Camera Model", false, 0, "If turned on, the camera model will not show up. This doesn't update automatically, you'll need to change camera modes or restart your game for it to take effect");
			AddCameraModes();
			Mod.GetFromFile();
			Mod.SaveModData("StaticLIVCamera");
			UI.instance.AddMod(Mod);
		}

		public override void OnLateInitializeMelon()
		{
			((MelonBase)this).OnLateInitializeMelon();
			UI.instance.UI_Initialized += OnUIInit;
			Calls.onMapInitialized += SceneLoaded;
			cameraBundle = LoadBundle("StaticLIVCamera.bundles.camera");
		}

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			currentScene = sceneName;
		}

		public Il2CppAssetBundle LoadBundle(string path)
		{
			using Stream stream = ((MelonBase)this).MelonAssembly.Assembly.GetManifestResourceStream(path);
			byte[] array = new byte[stream.Length];
			stream.Read(array, 0, array.Length);
			return Il2CppAssetBundleManager.LoadFromMemory(Il2CppStructArray<byte>.op_Implicit(array));
		}

		public void AddCameraModes()
		{
			cameraModes.Add(new DefaultMode("Default", "The default LIV camera", isModeEnabled: true));
			cameraModes.Add(new HandheldMode("Handheld", "Click your left joystick to pick up the camera. Click your left joystick again to drop it", isModeEnabled: true));
			cameraModes.Add(new StaticMode("Static", "Click on both of your joysticks to move the camera to your head position", isModeEnabled: true));
			cameraModes.Add(new OrbitMode("Orbit", "A camera that rotates around a point. Press Left Joystick to set the center point and press Right Joystick to set the circle radius.", isModeEnabled: false));
		}

		public static float[] ParseInputString(string input)
		{
			string[] array = input.Split(' ');
			if (array.Length != 6)
			{
				return null;
			}
			float[] array2 = new float[6];
			for (int i = 0; i < 6; i++)
			{
				if (!float.TryParse(array[i], out array2[i]))
				{
					Console.WriteLine($"Error parsing number at position {i + 1}");
					return null;
				}
			}
			return array2;
		}
	}
}
namespace StaticLIVCamera.modes
{
	public abstract class CameraMode
	{
		public string name;

		public string description;

		public ModSetting<bool> isModeEnabled;

		public CameraMode(string name, string description, bool isModeEnabled)
		{
			this.name = name;
			this.description = description;
			this.isModeEnabled = Main.Mod.AddToList(name + " Mode", isModeEnabled, 0, description);
		}

		public virtual void OnUpdate()
		{
		}

		public virtual void OnEnteringMode()
		{
		}

		public virtual void OnExitingMode()
		{
		}
	}
	public class DefaultMode : CameraMode
	{
		public DefaultMode(string name, string description, bool isModeEnabled)
			: base(name, description, isModeEnabled)
		{
		}

		public override void OnEnteringMode()
		{
			((Component)Main.camera.transform.GetChild(0)).gameObject.active = false;
		}

		public override void OnExitingMode()
		{
			((Component)Main.camera.transform.GetChild(0)).gameObject.active = true;
		}
	}
	public class HandheldMode : CameraMode
	{
		private Transform hand;

		private bool isInHand = false;

		private bool switchingMode = false;

		public HandheldMode(string name, string description, bool isModeEnabled)
			: base(name, description, isModeEnabled)
		{
		}

		public override void OnEnteringMode()
		{
			isInHand = false;
			hand = ((Component)Singleton<PlayerManager>.instance.localPlayer.Controller).gameObject.transform.GetChild(1).GetChild(1);
		}

		public override void OnExitingMode()
		{
		}

		public override void OnUpdate()
		{
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: 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_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			if (LeftController.GetJoystickClick() == 1f)
			{
				if (!switchingMode)
				{
					switchMode();
					switchingMode = true;
				}
			}
			else
			{
				switchingMode = false;
			}
			if (isInHand)
			{
				if ((float)((ModSetting)Main.autoPosSpeed).Value == 0f)
				{
					Main.camera.transform.position = hand.position + new Vector3(0f, -0.2f, 0f);
				}
				else
				{
					Main.camera.transform.position = Vector3.Lerp(Main.camera.transform.position, hand.position + new Vector3(0f, -0.2f, 0f), Time.deltaTime * (float)((ModSetting)Main.autoPosSpeed).Value);
				}
				if ((float)((ModSetting)Main.autoRotSpeed).Value == 0f)
				{
					Main.camera.transform.rotation = hand.rotation;
				}
				else
				{
					Main.camera.transform.rotation = Quaternion.Lerp(Main.camera.transform.rotation, hand.rotation * Quaternion.Euler(0f, 0f, 0f), (float)((ModSetting)Main.autoRotSpeed).Value * Time.deltaTime);
				}
			}
		}

		public void switchMode()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				isInHand = !isInHand;
				if (isInHand)
				{
					Main.camera.transform.position = hand.position + new Vector3(0f, -0.1f, 0f);
					Main.camera.transform.localRotation = Quaternion.Euler(0f, 0f, 0f);
				}
			}
			catch
			{
			}
		}
	}
	public class OrbitMode : CameraMode
	{
		private Vector3 target = Vector3.zero;

		public OrbitMode(string name, string description, bool isModeEnabled)
			: base(name, description, isModeEnabled)
		{
		}//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)


		public override void OnEnteringMode()
		{
		}

		public override void OnExitingMode()
		{
		}

		public override void OnUpdate()
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			if (LeftController.GetJoystickClick() == 1f)
			{
				Main.camera.transform.position = ((Component)((Component)((Component)((Component)Singleton<PlayerManager>.instance.localPlayer.Controller).transform.GetChild(1)).transform.GetChild(0)).transform.GetChild(0)).transform.position;
			}
			if (RightController.GetJoystickClick() == 1f)
			{
				target = ((Component)((Component)((Component)((Component)Singleton<PlayerManager>.instance.localPlayer.Controller).transform.GetChild(1)).transform.GetChild(0)).transform.GetChild(0)).transform.position;
			}
			Main.camera.transform.RotateAround(target, Vector3.up, (float)((ModSetting)Main.orbitSpeed).Value * Time.deltaTime);
			Main.camera.transform.LookAt(target);
		}
	}
	internal class StaticMode : CameraMode
	{
		public StaticMode(string name, string description, bool isModeEnabled)
			: base(name, description, isModeEnabled)
		{
		}

		public override void OnEnteringMode()
		{
		}

		public override void OnExitingMode()
		{
		}

		public override void OnUpdate()
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			if ((RightController.GetJoystickClick() == 1f && LeftController.GetJoystickClick() == 1f) || Input.GetKeyDown((KeyCode)121))
			{
				Main.camera.transform.position = ((Component)((Component)((Component)((Component)Singleton<PlayerManager>.instance.localPlayer.Controller).transform.GetChild(1)).transform.GetChild(0)).transform.GetChild(0)).transform.position;
				Main.camera.transform.rotation = ((Component)((Component)((Component)((Component)Singleton<PlayerManager>.instance.localPlayer.Controller).transform.GetChild(1)).transform.GetChild(0)).transform.GetChild(0)).transform.rotation;
			}
		}
	}
}