Decompiled source of ForgottenManRoom v1.0.0

Mods/ForgottenManRoom.dll

Decompiled 3 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using ForgottenManRoom;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppRUMBLE.Audio;
using Il2CppRUMBLE.Managers;
using Il2CppRUMBLE.Players.Subsystems;
using Il2CppRUMBLE.Utilities;
using MelonLoader;
using RumbleModdingAPI.RMAPI;
using UnityEngine;
using UnityEngine.Rendering.Universal;
using UnityEngine.SceneManagement;

[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), "ForgottenManRoom", "1.0.0", "TacoSlayer36", null)]
[assembly: MelonGame("Buckethead Entertainment", "RUMBLE")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("ForgottenManRoom")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ForgottenManRoom")]
[assembly: AssemblyTitle("ForgottenManRoom")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ForgottenManRoom;

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

	public const string Author = "TacoSlayer36";

	public const string Version = "1.0.0";
}
public class Core : MelonMod
{
	public static bool MainInit = false;

	public static Camera camera = null;

	public static Vector3 cameraPos;

	public static Quaternion cameraRot;

	public static float cameraFOV;

	public static bool loadedEgg = false;

	public static int BuildIndex = -1;

	private float lerpSpeed = 0.01f;

	public override void OnUpdate()
	{
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_012f: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0171: Unknown result type (might be due to invalid IL or missing references)
		//IL_017c: 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_0082: 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_00ac: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)camera != (Object)null)
		{
			Vector3 position = Singleton<PlayerManager>.Instance.LocalPlayer.Controller.PlayerVR.headset.Transform.position;
			if (position.z > -4.9f && ((Vector3)(ref position)).magnitude < 20f)
			{
				lerpSpeed = 0.01f;
				((Component)camera).transform.position = Vector3.Lerp(((Component)camera).transform.position, cameraPos, lerpSpeed);
				((Component)camera).transform.rotation = Quaternion.Slerp(((Component)camera).transform.rotation, cameraRot, lerpSpeed);
				camera.fieldOfView = Mathf.Lerp(camera.fieldOfView, cameraFOV, lerpSpeed);
			}
			else
			{
				lerpSpeed = Mathf.Min(1f, lerpSpeed + Time.deltaTime);
				((Component)camera).transform.position = Vector3.Lerp(((Component)camera).transform.position, position, lerpSpeed);
				((Component)camera).transform.rotation = Quaternion.Slerp(((Component)camera).transform.rotation, Singleton<PlayerManager>.Instance.LocalPlayer.Controller.PlayerVR.headset.Transform.rotation, lerpSpeed);
				camera.fieldOfView = Mathf.Lerp(camera.fieldOfView, Singleton<RecordingCamera>.Instance.LegacyCamera.fieldOfView, lerpSpeed);
			}
		}
	}

	public override void OnFixedUpdate()
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)camera != (Object)null && Singleton<PlayerManager>.Instance.LocalPlayer.Controller.PlayerVR.headset.Transform.position.y < -10f)
		{
			SceneManager.LoadScene(1);
			camera = null;
		}
	}

	public override void OnSceneWasInitialized(int buildIndex, string sceneName)
	{
		BuildIndex = buildIndex;
		if (sceneName == "Loader")
		{
			string[] embeddedResources = Utilities.EmbeddedResources;
			foreach (string text in embeddedResources)
			{
				if (text.StartsWith("ForgottenManRoom.Assets.bundles"))
				{
					Utilities.GetBundleFromEmbeddedResource(text);
				}
			}
		}
		if (buildIndex == -1)
		{
			SetManager.OnSceneWasInitalized(buildIndex, sceneName);
		}
		if (sceneName == "Gym" && !loadedEgg && Random.RandomRangeInt(0, 1000) == 0)
		{
			LoadForgottenRoom();
		}
		if (sceneName == "Gym" && loadedEgg)
		{
			MelonCoroutines.Start(_());
		}
		static IEnumerator _()
		{
			yield return (object)new WaitForSeconds(10f);
			loadedEgg = false;
		}
	}

	public static void LoadForgottenRoom()
	{
		MelonCoroutines.Start(_());
		static IEnumerator _()
		{
			loadedEgg = true;
			StageSystem.LoadSet(0);
			StageSystem.UnloadBaseScene();
			yield return (object)new WaitForSeconds(1f);
			((Behaviour)Singleton<PlayerManager>.Instance.LocalPlayer.Controller.PlayerPoseSystem).enabled = true;
			Singleton<PlayerManager>.Instance.localPlayer.Controller.PlayerMovement.TogglePIDController(true);
			AudioCall audio = AudioManager.CreateAudioCall("UserData/ForgottenManRoom/egg_room.wav", 1f);
			AudioManager.PlaySound(audio, Vector3.zero, true).AudioSource.spatialBlend = 0f;
			GameObject obj = GameObject.Find("GymMatchInfo");
			if (obj != null)
			{
				obj.SetActive(false);
			}
			GameObject obj2 = GameObject.Find("FlatLand");
			if (obj2 != null)
			{
				obj2.SetActive(false);
			}
			GameObject obj3 = GameObject.Find("VoidLand");
			if (obj3 != null)
			{
				obj3.SetActive(false);
			}
			GameObject obj4 = GameObject.Find("Replay Table");
			if (obj4 != null)
			{
				obj4.SetActive(false);
			}
			GameObject obj5 = GameObject.Find("Metadata Text");
			if (obj5 != null)
			{
				obj5.SetActive(false);
			}
			Transform playerPos = ((Component)Singleton<PlayerManager>.Instance.LocalPlayer.Controller.PlayerPhysics.FootCollider).transform;
			Singleton<PlayerManager>.Instance.LocalPlayer.Controller.PlayerMovement.RepositionWithFade(playerPos.position, Quaternion.identity, 0.3f, 0f, true, (Features)0, true);
		}
	}

	public override void OnLateInitializeMelon()
	{
		SetManager.RegisterSets();
	}
}
public static class SetManager
{
	public enum SetId
	{
		EggRoom
	}

	public static Dictionary<SetId, Scene> SetIdToLoadedScene = new Dictionary<SetId, Scene>();

	public static void RegisterSets()
	{
		SetId[] values = Enum.GetValues<SetId>();
		foreach (SetId setId in values)
		{
			StageSystem.RegisterSet((int)setId, loadSet);
		}
		static void loadSet(int id, StageSystem.SetEvent eventType)
		{
			LoadSet((SetId)id);
		}
	}

	public static void OnSceneWasInitalized(int buildIndex, string sceneName)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: 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_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		Scene sceneByName = SceneManager.GetSceneByName(sceneName);
		SceneManager.SetActiveScene(sceneByName);
		if (Enum.TryParse<SetId>(sceneName, out var result) && !SetIdToLoadedScene.ContainsKey(result))
		{
			SetIdToLoadedScene.Add(result, sceneByName);
		}
		foreach (Camera item in (Il2CppArrayBase<Camera>)(object)Camera.allCameras)
		{
			item.useOcclusionCulling = false;
		}
		Core.camera = GameObject.Find("Camera").GetComponent<Camera>();
		CameraExtensions.GetUniversalAdditionalCameraData(Core.camera).allowXRRendering = false;
		Core.cameraPos = ((Component)Core.camera).transform.position;
		Core.cameraRot = ((Component)Core.camera).transform.rotation;
		Core.cameraFOV = Core.camera.fieldOfView;
		Singleton<PlayerManager>.Instance.LocalPlayer.Controller.PlayerMovement.Reposition(new Vector3(0f, 13.7f, -6f), Quaternion.Euler(Vector3.forward));
		((Component)Singleton<PlayerManager>.Instance.LocalPlayer.Controller.PlayerUI.ActiveUIBar).gameObject.SetActive(false);
		((Component)Singleton<PlayerManager>.Instance.LocalPlayer.Controller.PlayerLIV.LckTablet).gameObject.SetActive(false);
	}

	private static void loadBundleIfNotAlreadyLoaded(string resourcePath)
	{
		if (!Utilities.LoadedBundles.ContainsKey(resourcePath))
		{
			Utilities.GetBundleFromEmbeddedResource(resourcePath);
		}
	}

	public static AsyncOperation LoadSet(SetId setId)
	{
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		if (SetIdToLoadedScene.TryGetValue(setId, out var value) && ((Scene)(ref value)).IsValid())
		{
			SceneManager.UnloadScene(value);
		}
		return SceneManager.LoadSceneAsync(setId.ToString(), (LoadSceneMode)1);
	}

	public static void UnloadSet(SetId setId)
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		if (SetIdToLoadedScene.TryGetValue(setId, out var value))
		{
			SetIdToLoadedScene.Remove(setId);
			SceneManager.UnloadScene(value);
		}
	}
}
public static class StageSystem
{
	public enum SetEvent : short
	{
		Load,
		Unload
	}

	public enum ChapterEvent : short
	{
		PlayNormally,
		SkipTo
	}

	private static Dictionary<int, Action<int, SetEvent>> _registeredSets = new Dictionary<int, Action<int, SetEvent>>();

	private static Dictionary<int, Action<int, ChapterEvent>> _registeredChapters = new Dictionary<int, Action<int, ChapterEvent>>();

	private static Dictionary<string, Action> _registeredEvents = new Dictionary<string, Action>();

	public static int[] RegisteredSets => _registeredSets.Keys.ToArray();

	public static int[] RegisteredChapters => _registeredChapters.Keys.ToArray();

	public static int CurrentSet { get; private set; } = -1;

	public static void RegisterSet(int setId, Action<int, SetEvent> handler)
	{
		if (_registeredSets.ContainsKey(setId))
		{
			throw new ArgumentException($"Set: {setId}, was already registered!");
		}
		_registeredSets.Add(setId, handler);
	}

	public static void LoadSet(int setId)
	{
		CurrentSet = setId;
		if (_registeredSets.TryGetValue(setId, out var value))
		{
			value(setId, SetEvent.Load);
			return;
		}
		throw new KeyNotFoundException($"Could not find set {setId}, is it registered? ");
	}

	public static void UnloadSet(int setId)
	{
		CurrentSet = setId;
		if (_registeredSets.TryGetValue(setId, out var value))
		{
			value(setId, SetEvent.Unload);
			return;
		}
		throw new KeyNotFoundException($"Could not find set {setId}, is it registered? ");
	}

	public static void UnloadBaseScene()
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: 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_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		List<Scene> list = new List<Scene>();
		list.Add(SceneManager.GetSceneByName("Loader"));
		list.Add(SceneManager.GetSceneByName("Gym"));
		list.Add(SceneManager.GetSceneByName("Park"));
		list.Add(SceneManager.GetSceneByName("Map0"));
		list.Add(SceneManager.GetSceneByName("Map1"));
		List<Scene> list2 = list.Where((Scene s) => ((Scene)(ref s)).isLoaded).ToList();
		foreach (Scene item in list2)
		{
			Scene current = item;
			foreach (GameObject item2 in (Il2CppArrayBase<GameObject>)(object)((Scene)(ref current)).GetRootGameObjects())
			{
				if (((Object)item2).name != "Player Controller(Clone)")
				{
					item2.SetActive(false);
				}
			}
		}
	}
}
public static class Utilities
{
	internal static Dictionary<string, AssetBundle> LoadedBundles = new Dictionary<string, AssetBundle>();

	public static string[] EmbeddedResources => typeof(Utilities).Assembly.GetManifestResourceNames();

	public static byte[] LoadEmbeddedResource(string resourcePath)
	{
		Stream manifestResourceStream = typeof(Utilities).Assembly.GetManifestResourceStream(resourcePath);
		using MemoryStream memoryStream = new MemoryStream();
		manifestResourceStream.CopyTo(memoryStream);
		return memoryStream.ToArray();
	}

	public static AssetBundle GetBundleFromEmbeddedResource(string resourcePath)
	{
		if (LoadedBundles.TryGetValue(resourcePath, out var value))
		{
			return value;
		}
		value = AssetBundle.LoadFromMemory(Il2CppStructArray<byte>.op_Implicit(LoadEmbeddedResource(resourcePath)));
		LoadedBundles.Add(resourcePath, value);
		return value;
	}

	public static string SanitizeName(string Input)
	{
		string pattern = "<[^>]*>";
		return Regex.Replace(Input, pattern, string.Empty);
	}
}