Decompiled source of CustomParkThemes v1.0.1

Mods/CustomParkThemes.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using CustomParkThemes;
using HarmonyLib;
using Il2CppPhoton.Pun;
using Il2CppPhoton.Realtime;
using Il2CppRUMBLE.Interactions.InteractionBase;
using Il2CppSystem;
using Il2CppTMPro;
using MelonLoader;
using MelonLoader.Preferences;
using RumbleModdingAPI.RMAPI;
using UIFramework;
using UIFramework.Models;
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(Core), "CustomParkThemes", "1.0.1", "TacoSlayer36", null)]
[assembly: MelonGame("Buckethead Entertainment", "RUMBLE")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("CustomParkThemes")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CustomParkThemes")]
[assembly: AssemblyTitle("CustomParkThemes")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace CustomParkThemes;

public static class Config
{
	public static MelonModel UIModel;

	public static MelonPreferences_Category Cat_CustomThemes;

	public static MelonPreferences_Entry<string> Theme1;

	public static MelonPreferences_Entry<string> Theme2;

	public static MelonPreferences_Entry<string> Theme3;

	public static MelonPreferences_Entry<string> Theme4;

	public static string ConfigFilePath => Path.Combine(Core.UserDataPath, "Config.cfg");

	public static void SetUpUI()
	{
		Cat_CustomThemes = MelonPreferences.CreateCategory("CustomThemes", "Custom Themes");
		Theme1 = Cat_CustomThemes.CreateEntry<string>("Theme1", "Anything goes", "Theme 1", "", false, false, (ValueValidator)null, (string)null);
		Theme2 = Cat_CustomThemes.CreateEntry<string>("Theme2", "Mini-Games", "Theme 2", "", false, false, (ValueValidator)null, (string)null);
		Theme3 = Cat_CustomThemes.CreateEntry<string>("Theme3", "Training", "Theme 3", "", false, false, (ValueValidator)null, (string)null);
		Theme4 = Cat_CustomThemes.CreateEntry<string>("Theme4", "Tournament", "Theme 4", "", false, false, (ValueValidator)null, (string)null);
		UI.CreateButtonEntry(Cat_CustomThemes, "Reset", "Reset To Defaults", "", (Action)Core.ResetToDefaults);
		UIModel = UI.RegisterMelon((MelonBase)(object)Core.Instance, (MelonPreferences_Category[])(object)new MelonPreferences_Category[1] { Cat_CustomThemes });
	}
}
public static class BuildInfo
{
	public const string Name = "CustomParkThemes";

	public const string Author = "TacoSlayer36";

	public const string Version = "1.0.1";
}
public class Core : MelonMod
{
	[HarmonyPatch(typeof(PhotonNetwork), "CreateRoom")]
	public static class ParkPatch
	{
		private static void Prefix(ref string roomName, TypedLobby typedLobby)
		{
			try
			{
				if (!((Object)(object)Slider == (Object)null) && typedLobby != null && ((Object)typedLobby).ToString().Contains("Park"))
				{
					string[] array = roomName.Split('|');
					string value = array[2];
					switch (((InteractionNumericalBase)Slider).snappedStep)
					{
					case 0:
						value = Config.Theme1.Value;
						break;
					case 1:
						value = Config.Theme2.Value;
						break;
					case 2:
						value = Config.Theme3.Value;
						break;
					case 3:
						value = Config.Theme4.Value;
						break;
					}
					roomName = $"{array[0]}|{array[1]}|{value}";
				}
			}
			catch (Exception ex)
			{
				((MelonBase)Instance).LoggerInstance.Error(ex.Message);
			}
		}
	}

	public static Core Instance;

	internal static TextMeshPro[] ThemeTexts = (TextMeshPro[])(object)new TextMeshPro[4];

	internal static InteractionSlider Slider;

	private static string currentScene = "Loader";

	internal static string UserDataPath => Path.Combine("UserData", "CustomParkThemes");

	public override void OnInitializeMelon()
	{
		Instance = this;
		Config.SetUpUI();
		((MelonEventBase<LemonAction<string>>)(object)MelonPreferences.OnPreferencesSaved).Subscribe((LemonAction<string>)onConfigSaved, 0, false);
	}

	public override void OnSceneWasLoaded(int buildIndex, string sceneName)
	{
		currentScene = sceneName;
		if (currentScene == "Gym")
		{
			fetchReferences();
			updateText();
		}
	}

	internal static void ResetToDefaults()
	{
		Config.Theme1.EditedValue = Config.Theme1.DefaultValue;
		Config.Theme2.EditedValue = Config.Theme2.DefaultValue;
		Config.Theme3.EditedValue = Config.Theme3.DefaultValue;
		Config.Theme4.EditedValue = Config.Theme4.DefaultValue;
		((ModModelBase)Config.UIModel).RequestUpdateUI();
	}

	private static void fetchReferences()
	{
		ThemeTexts[0] = TagCanvas.GetGameObject().GetComponent<TextMeshPro>();
		ThemeTexts[1] = TagCanvas3.GetGameObject().GetComponent<TextMeshPro>();
		ThemeTexts[2] = TagCanvas2.GetGameObject().GetComponent<TextMeshPro>();
		ThemeTexts[3] = TagCanvas1.GetGameObject().GetComponent<TextMeshPro>();
		Slider = Sliderhandle.GetGameObject().GetComponent<InteractionSlider>();
	}

	private static void updateText()
	{
		if (!ThemeTexts.Any((TextMeshPro t) => (Object)(object)t == (Object)null))
		{
			((TMP_Text)ThemeTexts[0]).text = Config.Theme1.Value;
			((TMP_Text)ThemeTexts[1]).text = Config.Theme2.Value;
			((TMP_Text)ThemeTexts[2]).text = Config.Theme3.Value;
			((TMP_Text)ThemeTexts[3]).text = Config.Theme4.Value;
		}
	}

	private static void onConfigSaved(string _)
	{
		updateText();
	}
}