Decompiled source of CustomParkMaps v1.0.0

Mods/CustomParkMaps.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using CustomParkMaps;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppPhoton.Pun;
using Il2CppRUMBLE.Interactions.InteractionBase;
using Il2CppRUMBLE.Managers;
using Il2CppRUMBLE.Utilities;
using Il2CppSystem;
using MelonLoader;
using MelonLoader.Preferences;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using RumbleModdingAPI.RMAPI;
using UIFramework;
using UIFramework.UiExtensions;
using UnityEngine;
using UnityEngine.Events;
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), "CustomParkMaps", "1.0.0", "OmniGooberPB", null)]
[assembly: MelonColor(255, 66, 164, 255)]
[assembly: MelonAdditionalDependencies(new string[] { "UlvakSkillz-RumbleModdingAPI-5.3.0", "Reverb_and___and_Spice-UIFramework-0.10.2" })]
[assembly: MelonGame("Buckethead Entertainment", "RUMBLE")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("CustomParkMaps")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+47338693e009e28107e2bb2a9d5b1ab65388f4d5")]
[assembly: AssemblyProduct("CustomParkMaps")]
[assembly: AssemblyTitle("CustomParkMaps")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CustomParkMaps
{
	public class Core : MelonMod
	{
		private string bundlePath;

		internal static MelonPreferences_Category MapTarget;

		private static List<DropdownItem> mapList = new List<DropdownItem>
		{
			new DropdownItem("Park", (object)0)
		};

		internal static MelonPreferences_Entry<int> mapDropdown;

		private SceneManager sceneManager;

		private GameObject ddolButton;

		private GameObject tpButton;

		public static DynamicDropdownDescriptor DropdownDescriptor = new DynamicDropdownDescriptor();

		private AssetBundle customBundle;

		public override void OnInitializeMelon()
		{
			((MelonBase)this).LoggerInstance.Msg("Initialized.");
			InitPrefs();
			LoadBundle();
			UI.RegisterMelon((MelonBase)(object)this, (MelonPreferences_Category[])(object)new MelonPreferences_Category[1] { MapTarget });
			Actions.onMapInitialized += OnParkLoad;
		}

		public static void InitPrefs()
		{
			MapTarget = MelonPreferences.CreateCategory("Settings");
			mapDropdown = MapTarget.CreateEntry<int>("MapDropdown", 0, "Map Selection Dropdown", "Dynamic Map Selection. Updates whenever you install new maps.", false, false, (ValueValidator)(object)DropdownDescriptor.WithDropdownItemList(mapList));
			((MelonEventBase<LemonAction<int, int>>)(object)mapDropdown.OnEntryValueChanged).Subscribe((LemonAction<int, int>)ItemSelectionChanged, 0, false);
		}

		internal static void ItemSelectionChanged(int old, int neew)
		{
			Debug.Log(Object.op_Implicit($"Selected Item: {neew}"));
			mapDropdown.Value = neew;
		}

		private void LoadBundle()
		{
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Expected O, but got Unknown
			string path = Path.Combine(MelonEnvironment.UserDataDirectory, "CustomParkMaps");
			if (!Directory.Exists(path))
			{
				((MelonBase)this).LoggerInstance.Error("Map Bundles Directory not Found.");
				Directory.CreateDirectory(path);
				return;
			}
			((MelonBase)this).LoggerInstance.Msg("Found Map Bundles.");
			string[] files = Directory.GetFiles(path, "*.map");
			foreach (string path2 in files)
			{
				((MelonBase)this).LoggerInstance.Msg("Found Map: " + Path.GetFileNameWithoutExtension(path2));
				string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path2);
				int count = DropdownDescriptor.GetDropdownItems().Count;
				DropdownDescriptor.AddDropdownItem(new DropdownItem(fileNameWithoutExtension, (object)count));
				((MelonBase)this).LoggerInstance.Msg("Added Map to Dropdown: " + fileNameWithoutExtension);
			}
		}

		public void OnParkLoad(string mapName)
		{
			if (mapName != "Park")
			{
				((MelonBase)this).LoggerInstance.Msg("Map is not Park. Skipping map replacement.");
			}
			else if (mapName == "Park" && !PhotonNetwork.CurrentRoom.IsOpen)
			{
				sceneManager = Singleton<SceneManager>.instance;
				string displayName = DropdownDescriptor.GetDropdownItems()[mapDropdown.Value].DisplayName;
				((MelonBase)this).LoggerInstance.Msg("Selected Map: " + displayName);
				if (displayName != "Park")
				{
					string text = Path.Combine(MelonEnvironment.UserDataDirectory, "CustomParkMaps", displayName + ".map");
					if (File.Exists(text))
					{
						customBundle = AssetBundle.LoadFromFile(text);
						((MelonBase)this).LoggerInstance.Msg("Loading Map: " + displayName);
						ReplacePark();
					}
					else
					{
						((MelonBase)this).LoggerInstance.Error("Map Bundle not found: " + text);
					}
				}
				else
				{
					((MelonBase)this).LoggerInstance.Msg("No map selected.");
				}
			}
			else
			{
				((MelonBase)this).LoggerInstance.Msg("Map selection is disabled in Public Parks.");
			}
		}

		private void ReplacePark()
		{
			string[] array = Il2CppArrayBase<string>.op_Implicit((Il2CppArrayBase<string>)(object)customBundle.GetAllScenePaths());
			((MelonBase)this).LoggerInstance.Msg("Found " + array.Length + " scenes in the bundle.");
			if (array.Length == 0)
			{
				((MelonBase)this).LoggerInstance.Error("No scenes found in the bundle.");
			}
			string path = array[0];
			string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path);
			foreach (Camera item in Object.FindObjectsOfType<Camera>())
			{
				item.useOcclusionCulling = false;
			}
			AsyncOperation val = SceneManager.LoadSceneAsync(fileNameWithoutExtension, (LoadSceneMode)1);
			CleanPark();
			MelonCoroutines.Start(WaitForSeconds());
		}

		private IEnumerator WaitForSeconds()
		{
			yield return (object)new WaitForSeconds(1f);
			TPTime();
			yield return null;
		}

		private void TPTime()
		{
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			((MelonBase)this).LoggerInstance.Msg("One second later!");
			string[] array = Il2CppArrayBase<string>.op_Implicit((Il2CppArrayBase<string>)(object)customBundle.GetAllScenePaths());
			if (array.Length == 0)
			{
				((MelonBase)this).LoggerInstance.Error("No scenes found in the bundle.");
			}
			string path = array[0];
			string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path);
			ddolButton = Create.NewButton();
			ddolButton.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)ddolButton);
			tpButton = Object.Instantiate<GameObject>(ddolButton);
			((Object)tpButton).name = "TPButton";
			tpButton.SetActive(true);
			GameObject val = GameObject.Find("TTPButton");
			if ((Object)(object)val == (Object)null)
			{
				((MelonBase)this).LoggerInstance.Error("TTPButton not found.");
			}
			else
			{
				((MelonBase)this).LoggerInstance.Msg("TTPButton found.");
			}
			GameObject tpDestination = GameObject.Find("TPDestination");
			if ((Object)(object)tpDestination == (Object)null)
			{
				((MelonBase)this).LoggerInstance.Error("TPDestination not found.");
			}
			else
			{
				((MelonBase)this).LoggerInstance.Msg("TPDestination found.");
			}
			tpButton.transform.position = val.transform.position;
			((Component)tpButton.transform.GetChild(0)).gameObject.GetComponent<InteractionButton>().onPressed.AddListener(UnityAction.op_Implicit((Action)delegate
			{
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0021: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: 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_0066: Unknown result type (might be due to invalid IL or missing references)
				//IL_006b: Unknown result type (might be due to invalid IL or missing references)
				TeleportPlayer(new Vector3(tpDestination.transform.position.x, tpDestination.transform.position.y, tpDestination.transform.position.z));
				((MelonBase)this).LoggerInstance.Msg("Teleported to: " + ((object)tpDestination.transform.position/*cast due to .constrained prefix*/).ToString());
			}));
		}

		private static void TeleportPlayer(Vector3 pos)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: 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_0050: 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)
			Quaternion rotation = ((Component)Singleton<PlayerManager>.instance.localPlayer.Controller.PlayerCamera).transform.rotation;
			Quaternion val = Quaternion.Euler(0f, ((Quaternion)(ref rotation)).eulerAngles.y, 0f);
			Singleton<PlayerManager>.instance.localPlayer.Controller.PlayerMovement.Reposition(pos, val);
		}

		private void CleanPark()
		{
			((MelonBase)this).LoggerInstance.Msg("Starting CleanUp!");
			PARK.GetGameObject().SetActive(false);
			((MelonBase)this).LoggerInstance.Msg("disabled: PARK Play Area");
			PARKCollission.GetGameObject().SetActive(false);
			((MelonBase)this).LoggerInstance.Msg("disabled: PARK Collisions");
			PARKMos.GetGameObject().SetActive(false);
			((MelonBase)this).LoggerInstance.Msg("disabled: PARK Moss");
			Fruit.GetGameObject().SetActive(false);
			((MelonBase)this).LoggerInstance.Msg("disabled: PARK Fruit");
			TetherBalls.GetGameObject().SetActive(false);
			TargetSpawns.GetGameObject().SetActive(false);
			MatchCounter.GetGameObject().SetActive(false);
			BoulderballHoops.GetGameObject().SetActive(false);
			SmallRockSpawns.GetGameObject().SetActiveRecursively(false);
			LargeRockSpawns.GetGameObject().SetActiveRecursively(false);
			((MelonBase)this).LoggerInstance.Msg("disabled: PARK Toys");
			PoolWrappedWallRUMBLEMoveSystemStructure.GetGameObject().SetActive(false);
			PoolBoulderBallRUMBLEMoveSystemStructure.GetGameObject().SetActive(false);
			PoolPrisonedPillarRUMBLEMoveSystemStructure.GetGameObject().SetActive(false);
			PoolDockedDiskRUMBLEMoveSystemStructure.GetGameObject().SetActive(false);
			PoolCageCubeRUMBLEMoveSystemStructure.GetGameObject().SetActive(false);
			((MelonBase)this).LoggerInstance.Msg("disabled: PARK Caged Structures");
		}
	}
}