Decompiled source of PForProduct v1.0.4

Mods/PForProduct.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using Il2CppScheduleOne.UI;
using Il2CppScheduleOne.UI.Phone;
using Il2CppScheduleOne.UI.Phone.ProductManagerApp;
using MelonLoader;
using MelonLoader.Preferences;
using ModManagerPhoneApp;
using P_For_Product;
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(PForProduct), "P For Product", "1.0.4", "KrakHedKorps", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: ComVisible(false)]
[assembly: Guid("4e6edb57-1af5-4c7b-babb-4e2af88c640a")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("PForProduct")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.4.0")]
[assembly: AssemblyInformationalVersion("1.0.4")]
[assembly: AssemblyProduct("PForProduct")]
[assembly: AssemblyTitle("PForProduct")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.4.0")]
[module: UnverifiableCode]
namespace P_For_Product;

public class PForProduct : MelonMod
{
	private KeyCode toggleKey = (KeyCode)112;

	private bool isInitialized = false;

	private const string APP_OBJECT_NAME = "ModSettingsApp";

	private static MelonPreferences_Entry<KeyCode> toggleKeyEntry;

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

	private IEnumerator InitializeMod()
	{
		yield return (object)new WaitForSeconds(1f);
		try
		{
			try
			{
				ModSettingsEvents.OnPreferencesSaved += HandleSettingsUpdate;
				MelonLogger.Msg("Successfully subscribed to Mod Manager save event.");
			}
			catch (Exception ex3)
			{
				Exception ex2 = ex3;
				MelonLogger.Warning("Could not subscribe to Mod Manager event: " + ex2.Message);
			}
			MelonPreferences_Category category = MelonPreferences.CreateCategory("PForProduct", "P For Product Config");
			toggleKeyEntry = category.CreateEntry<KeyCode>("Keybind", (KeyCode)112, "Keybind", (string)null, false, false, (ValueValidator)null, (string)null);
			toggleKey = toggleKeyEntry.Value;
			MelonLogger.Msg("P For Product Mod ready in Main Scene.");
			isInitialized = true;
		}
		catch (Exception ex)
		{
			MelonLogger.Error("Error initializing P For Product: " + ex.Message);
		}
	}

	private void HandleSettingsUpdate()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			toggleKey = toggleKeyEntry.Value;
			MelonLogger.Msg($"Keybind for PForProduct updated to: {toggleKey}");
		}
		catch (Exception ex)
		{
			MelonLogger.Error("Error handling settings update: " + 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>();
			GameObject val4 = GameObject.Find("ModSettingsApp");
			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.");
				return;
			}
			if ((Object)(object)val4 != (Object)null && val4.activeSelf)
			{
				MelonLogger.Msg("Closing Mod Manager App.");
				val4.SetActive(false);
			}
			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.");
					Object.FindObjectOfType<Phone>().RequestCloseApp();
					((App<ProductManagerApp>)(object)val2).SetOpen(true);
				}
			}
			else
			{
				MelonLogger.Msg("Opening the phone with the Product Manager App.");
				Object.FindObjectOfType<Phone>().RequestCloseApp();
				val.SetIsOpen(true);
				((App<ProductManagerApp>)(object)val2).SetOpen(true);
			}
		}
		catch (Exception ex)
		{
			MelonLogger.Error("Error toggling Product Manager App: " + ex.Message);
		}
	}

	public override void OnDeinitializeMelon()
	{
		GameplayMenu val = Object.FindObjectOfType<GameplayMenu>();
		if ((Object)(object)val != (Object)null && val.IsOpen)
		{
			val.SetIsOpen(false);
		}
		try
		{
			ModSettingsEvents.OnPreferencesSaved -= HandleSettingsUpdate;
			MelonLogger.Msg("Unsubscribed from Mod Manager save event.");
		}
		catch
		{
		}
	}
}