Decompiled source of TournamentCamera v1.0.0

Mods/TournamentCamera.dll

Decompiled 2 years ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using Il2CppSystem.Collections.Generic;
using LIV.SDK.Unity;
using MelonLoader;
using RUMBLE.Managers;
using RUMBLE.Players;
using RUMBLE.Utilities;
using RumbleModdingAPI;
using TournamentCamera;
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(Class1), "TournamentCamera", "1.0.0", "PeppaStone", null)]
[assembly: MelonGame("Buckethead Entertainment", "RUMBLE")]
[assembly: AssemblyTitle("TournamentCamera")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TournamentCamera")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4305189c-ddcc-443a-aeff-f1e8cbcc7f52")]
[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 TournamentCamera;

public class Class1 : MelonMod
{
	private GameObject playerLiv;

	private PlayerController playerController;

	private GameObject cameraOperator;

	private GameObject cameraOffset;

	private PlayerController cameraOffsetPlayerController;

	private int timer = 0;

	private bool isScenePark;

	private LIV liv;

	private bool init = false;

	private PlayerManager playerManager;

	private GameObject UECam;

	private bool[] numberKeys = new bool[5];

	private int[] playerKeys = new int[5] { 54, 55, 56, 57, 48 };

	private Transform[] nametags = (Transform[])(object)new Transform[6];

	private Transform[] healthBars = (Transform[])(object)new Transform[6];

	private bool bKeyHeld = false;

	private bool nKeyHeld = false;

	private int cameraMode = 0;

	private bool isFreeCam = false;

	private Transform headset;

	private List<Player> players;

	public override void OnSceneWasLoaded(int buildIndex, string sceneName)
	{
		timer = 0;
		init = false;
		if (sceneName == "Park")
		{
			isScenePark = true;
		}
		else
		{
			isScenePark = false;
		}
	}

	public override void OnLateUpdate()
	{
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		if (!isScenePark)
		{
			return;
		}
		if (!init)
		{
			if (timer >= 120)
			{
				SetupLivCamera();
			}
			else
			{
				timer++;
			}
			return;
		}
		try
		{
			CheckKeysDown();
			MoveCameraOnFrame();
			liv.render.SetPose(cameraOffset.transform.position, cameraOffset.transform.rotation, 75f, false);
		}
		catch
		{
		}
	}

	public void MoveCameraOnFrame()
	{
		//IL_0011: 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_0028: 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_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: 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_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: 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_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 1; i < players._size; i++)
		{
			Vector3 val = cameraOffset.transform.position - ((Component)nametags[i]).transform.position;
			Quaternion rotation = Quaternion.LookRotation(((Vector3)(ref val)).normalized);
			nametags[i].rotation = rotation;
			healthBars[i].rotation = rotation;
		}
		if (cameraMode == 1)
		{
			Quaternion localRotation = cameraOperator.transform.localRotation;
			Vector3 eulerAngles = ((Quaternion)(ref localRotation)).eulerAngles;
			localRotation = ((Component)headset).transform.localRotation;
			eulerAngles.y = ((Quaternion)(ref localRotation)).eulerAngles.y;
			cameraOperator.transform.localRotation = Quaternion.Euler(eulerAngles);
		}
		else if (cameraMode != 3)
		{
		}
	}

	public void CheckKeysDown()
	{
		//IL_0105: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0136: Unknown result type (might be due to invalid IL or missing references)
		//IL_014c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		if (Input.GetKeyDown((KeyCode)98))
		{
			if (!bKeyHeld)
			{
				bKeyHeld = true;
				InitializePlayers();
			}
		}
		else
		{
			bKeyHeld = false;
		}
		for (int i = 0; i < players._size - 1; i++)
		{
			if (Input.GetKeyDown((KeyCode)playerKeys[i]))
			{
				if (!numberKeys[i])
				{
					numberKeys[i] = true;
					AttachCameraToPlayer(i + 1);
					cameraMode = 1;
				}
			}
			else
			{
				numberKeys[i] = false;
			}
		}
		if (Input.GetKeyDown((KeyCode)110))
		{
			if (!nKeyHeld)
			{
				nKeyHeld = true;
				if (isFreeCam)
				{
					cameraOperator.transform.parent = UECam.transform;
					cameraOperator.transform.localPosition = Vector3.zero;
					cameraOperator.transform.localRotation = Quaternion.Euler(Vector3.zero);
					cameraOffset.transform.localPosition = Vector3.zero;
					cameraOffset.transform.localRotation = Quaternion.Euler(Vector3.zero);
					cameraMode = 2;
				}
				else
				{
					MelonLogger.Msg("There was an error trying to find the Free Cam. Please press B to synchronize it.");
				}
			}
		}
		else
		{
			nKeyHeld = false;
		}
	}

	public void AttachCameraToPlayer(int playerIndex)
	{
		//IL_0040: 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_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			cameraOperator.transform.parent = ((Component)players[playerIndex].Controller).transform.GetChild(1).GetChild(3);
			cameraOperator.transform.localPosition = Vector3.zero;
			cameraOperator.transform.localRotation = Quaternion.Euler(Vector3.zero);
			cameraOffset.transform.localPosition = new Vector3(0f, 1.5f, -2.5f);
			cameraOffset.transform.localRotation = Quaternion.Euler(Vector3.zero);
			headset = ((Component)players[playerIndex].Controller).transform.GetChild(1).GetChild(0).GetChild(0);
		}
		catch
		{
			MelonLogger.Msg("There was an error trying to find the player. Please activate the Free Cam and press B to synchronize the player list.");
		}
	}

	public void InitializePlayers()
	{
		MelonLogger.Msg("Getting Free Cam...");
		isFreeCam = true;
		UECam = GameObject.Find("UE_Freecam");
		if ((Object)(object)UECam == (Object)null)
		{
			MelonLogger.Msg("Unity Explorer Free Cam not detected. If you wish to use Free Cam features, make sure that you have Unity Explorer and the Free Cam activated.");
			isFreeCam = false;
		}
		else
		{
			MelonLogger.Msg("Free Cam found!");
		}
		MelonLogger.Msg("Getting players...");
		players = playerManager.AllPlayers;
		for (int i = 0; i < players._size; i++)
		{
			bool flag = false;
			string text = "";
			switch (i)
			{
			case 0:
				text = "Yourself: ";
				break;
			case 1:
				text = "6: ";
				break;
			case 2:
				text = "7: ";
				break;
			case 3:
				text = "8: ";
				break;
			case 4:
				text = "9: ";
				break;
			case 5:
				text = "0: ";
				break;
			default:
				flag = true;
				MelonLogger.Msg("There are more than 6 players in the park. Some players will not be synched with the mod");
				break;
			}
			if (!flag)
			{
				if (i != 0)
				{
					nametags[i] = ((Component)players[i].Controller).transform.GetChild(8).GetChild(0);
					healthBars[i] = ((Component)players[i].Controller).transform.GetChild(2).GetChild(0);
					((Component)healthBars[i].GetChild(1)).gameObject.SetActive(false);
				}
				MelonLogger.Msg(text + players[i].Data.GeneralData.PublicUsername);
			}
		}
		MelonLogger.Msg("Players found! Player count: " + players._size);
	}

	public void SetupLivCamera()
	{
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0114: Expected O, but got Unknown
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: Expected O, but got Unknown
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		//IL_019c: Unknown result type (might be due to invalid IL or missing references)
		cameraMode = 0;
		playerManager = Managers.GetPlayerManager();
		playerController = playerManager.localPlayer.Controller;
		((Behaviour)((Component)((Component)playerController).transform.GetChild(1).GetChild(0).GetChild(0)).GetComponent<AudioListener>()).enabled = false;
		playerLiv = ((Component)((Component)playerController).transform.GetChild(8)).gameObject;
		playerLiv.transform.localPosition = new Vector3(0f, 0f, 0f);
		playerLiv.transform.localRotation = Quaternion.Euler(0f, 0f, 0f);
		liv = playerLiv.GetComponent<LIV>();
		try
		{
			RecordingCamera component = GameObject.Find("Game Instance/Initializable/RecordingCamera").GetComponent<RecordingCamera>();
			component.OnModernRecordingCameraEnabledChanged(true);
			component.SaveConfiguration();
			MelonLogger.Msg("F10 Camera Enabled");
		}
		catch
		{
			MelonLogger.Msg("liv camera wasnt found");
			return;
		}
		cameraOperator = new GameObject();
		((Object)cameraOperator).name = "CameraOperator";
		cameraOffset = new GameObject();
		((Object)cameraOffset).name = "CameraOffset";
		cameraOffset.transform.parent = cameraOperator.transform;
		cameraOffset.transform.localPosition = new Vector3(0f, 0f, 0f);
		cameraOffset.transform.localRotation = Quaternion.Euler(0f, 0f, 0f);
		cameraOffset.AddComponent<AudioListener>();
		cameraOffsetPlayerController = cameraOffset.AddComponent<PlayerController>();
		MelonLogger.Msg("liv camera setup");
		init = true;
	}
}