Decompiled source of LongerDays Il2cpp v1.13.2

longerdays.dll

Decompiled a month ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using HarmonyLib;
using Il2CppScheduleOne.DevUtilities;
using Il2CppScheduleOne.GameTime;
using Il2CppScheduleOne.Persistence;
using MelonLoader;
using MelonLoader.Preferences;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(LongerDaysMod), "LongerDays", "1.13.1", "xVilho", null)]
[assembly: MelonColor(255, 200, 150, 255)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
public class LongerDaysMod : MelonMod
{
	[HarmonyPatch(typeof(TimeManager), "Start")]
	public static class TimeManager_Start_Patch
	{
		public static void Postfix(TimeManager __instance)
		{
			if (!((Object)(object)__instance == (Object)null) && !initialized)
			{
				ApplyMultiplier(__instance, "Initial Load");
			}
		}
	}

	[HarmonyPatch(typeof(TimeManager), "OnStartClient")]
	public static class TimeManager_OnStartClient_Patch
	{
		public static void Postfix(TimeManager __instance)
		{
			if (!((Object)(object)__instance == (Object)null))
			{
				ApplyMultiplier(__instance, "Network Sync");
			}
		}
	}

	private static MelonPreferences_Category cfgCategory;

	private static MelonPreferences_Entry<float> cfgMultiplier;

	private static Instance Logger;

	private static bool initialized;

	public override void OnInitializeMelon()
	{
		Logger = ((MelonBase)this).LoggerInstance;
		cfgCategory = MelonPreferences.CreateCategory("LongerDays", "Longer Days Mod Settings");
		cfgMultiplier = cfgCategory.CreateEntry<float>("TimeMultiplier", 0.5f, "Time Speed Multiplier", "Controls how fast in-game time passes.\n1.0 = normal speed (100%), 0.5 = 50% (slower), 2.0 = 200% (faster).\nAllowed range: 0.1 (very slow) to 2.0 (very fast).", false, false, (ValueValidator)null, (string)null);
		Log("✅ LongerDays 1.13.1 initialized. State will reset in Menu and apply in Gameplay.");
	}

	public override void OnSceneWasInitialized(int buildIndex, string sceneName)
	{
		if (sceneName == SaveManager.MENU_SCENE_NAME)
		{
			initialized = false;
			Log("\ud83d\udd01 Scene 'menu' loaded — reset mod state.");
		}
		if (sceneName == SaveManager.MAIN_SCENE_NAME || sceneName == SaveManager.TUTORIAL_SCENE_NAME)
		{
			Log("\ud83e\udde9 Scene '" + sceneName + "' initialized. TimeManager will be patched on Start.");
		}
	}

	public override void OnPreferencesSaved()
	{
		if (initialized && (Object)(object)NetworkSingleton<TimeManager>.instance != (Object)null)
		{
			ApplyMultiplier(NetworkSingleton<TimeManager>.instance, "Config Updated");
		}
	}

	public static void ApplyMultiplier(TimeManager timeManager, string source)
	{
		if (!((Object)(object)timeManager == (Object)null))
		{
			float num = Mathf.Clamp(cfgMultiplier.Value, 0.1f, 2f);
			timeManager.SetTimeSpeedMultiplier(num);
			Log($"⏳ [{source}] Time speed set to {num:0.##}x ({num * 100f:0.#}% of normal speed).");
			initialized = true;
		}
	}

	private static void Log(string msg)
	{
		Logger.Msg(msg ?? "");
	}
}