Decompiled source of PForProduct Mono v1.0.2

Mods/PForProductMono.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using MelonLoader;
using P_For_Product_Mono;
using ScheduleOne.UI;
using ScheduleOne.UI.Phone;
using ScheduleOne.UI.Phone.ProductManagerApp;
using UnityEngine;
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(PForProductMono), "Product Hotkey Mod", "1.0.1", "KHK", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: AssemblyTitle("PForProductMono")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PForProductMono")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("a32f9410-4bdd-4e21-854f-635a17f0a050")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace P_For_Product_Mono;

public class PForProductMono : MelonMod
{
	[Serializable]
	private class ConfigData
	{
		public string ToggleKey = "P";
	}

	private string configPath;

	private KeyCode toggleKey = (KeyCode)112;

	private bool isInitialized = false;

	private ConfigData configData;

	public override void OnInitializeMelon()
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
		configPath = Path.Combine(directoryName, "PForProductConfig.json");
		LoadConfig();
		MelonLogger.Msg($"PForProduct Mod initialized. Using key: {toggleKey}");
	}

	private void LoadConfig()
	{
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if (!File.Exists(configPath))
			{
				configData = new ConfigData();
				SaveConfig();
				MelonLogger.Msg("Created new config file with default settings.");
			}
			else
			{
				string text = File.ReadAllText(configPath);
				configData = JsonUtility.FromJson<ConfigData>(text);
				MelonLogger.Msg("Config file loaded successfully.");
			}
			if (!Enum.TryParse<KeyCode>(configData.ToggleKey, ignoreCase: true, out toggleKey))
			{
				toggleKey = (KeyCode)112;
				MelonLogger.Warning("Invalid key in config file. Falling back to default: P.");
			}
		}
		catch (Exception ex)
		{
			MelonLogger.Error("Error loading config file: " + ex.Message);
			toggleKey = (KeyCode)112;
		}
	}

	private void SaveConfig()
	{
		try
		{
			string contents = JsonUtility.ToJson((object)configData, true);
			File.WriteAllText(configPath, contents);
		}
		catch (Exception ex)
		{
			MelonLogger.Error("Error saving config file: " + ex.Message);
		}
	}

	public override void OnSceneWasLoaded(int buildIndex, string sceneName)
	{
		if (sceneName != "Main")
		{
			MelonLogger.Msg("Scene '" + sceneName + "' detected. Product Manager is disabled in non-gameplay scenes.");
			isInitialized = false;
		}
		else
		{
			MelonCoroutines.Start(InitializeMod());
		}
	}

	private IEnumerator InitializeMod()
	{
		yield return (object)new WaitForSeconds(1f);
		try
		{
			MelonLogger.Msg("Product Manager Mod ready in Main Scene.");
			isInitialized = true;
		}
		catch (Exception ex)
		{
			MelonLogger.Error("Error initializing Product Manager: " + ex.Message);
		}
	}

	public override void OnUpdate()
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		if (isInitialized)
		{
			Scene activeScene = SceneManager.GetActiveScene();
			if (!(((Scene)(ref activeScene)).name != "Main") && Input.GetKeyDown(toggleKey))
			{
				Toggle();
			}
		}
	}

	private void Toggle()
	{
		try
		{
			GameplayMenu val = Object.FindObjectOfType<GameplayMenu>();
			ProductManagerApp val2 = Object.FindObjectOfType<ProductManagerApp>();
			Phone val3 = Object.FindObjectOfType<Phone>();
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null || (Object)(object)val3 == (Object)null)
			{
				MelonLogger.Warning("One or more required UI components were not found.");
			}
			else if (val.IsOpen)
			{
				if ((Object)(object)Phone.ActiveApp == (Object)(object)((Component)val2).gameObject)
				{
					MelonLogger.Msg("Closing the phone.");
					val.SetIsOpen(false);
				}
				else
				{
					MelonLogger.Msg("Switching to the Product Manager App.");
					val3.closeApps();
					((App<ProductManagerApp>)(object)val2).SetOpen(true);
				}
			}
			else
			{
				MelonLogger.Msg("Opening the phone with the Product Manager App.");
				val3.closeApps();
				val.SetIsOpen(true);
				((App<ProductManagerApp>)(object)val2).SetOpen(true);
			}
		}
		catch (Exception ex)
		{
			MelonLogger.Error("Error toggling Product Manager: " + ex.Message);
		}
	}

	public override void OnDeinitializeMelon()
	{
		GameplayMenu val = Object.FindObjectOfType<GameplayMenu>();
		if ((Object)(object)val != (Object)null && val.IsOpen)
		{
			val.SetIsOpen(false);
		}
	}
}