Decompiled source of TimeStuffMod v1.1.3

TimeStuffMod.dll

Decompiled 5 months ago
using System;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using HarmonyLib;
using Il2CppScheduleOne.DevUtilities;
using Il2CppScheduleOne.Money;
using Il2CppScheduleOne.UI;
using Il2CppScheduleOne.UI.Phone;
using MelonLoader;
using MelonLoader.Utils;
using Newtonsoft.Json;
using TimeStuffMod;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: MelonInfo(typeof(global::TimeStuffMod.TimeStuffMod), "TimeStuffMod", "1.1.3", "Convict999", null)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("TimeStuffMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+d16797b82638cb358f4d66ebaebc8c11e000da0e")]
[assembly: AssemblyProduct("TimeStuffMod")]
[assembly: AssemblyTitle("TimeStuffMod")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace TimeStuffMod
{
	public static class BuildInfo
	{
		public const string Name = "TimeStuffMod";

		public const string Description = "Control time keybinds + On screen clock + On screen networth";

		public const string Author = "Convict999";

		public const string Company = null;

		public const string Version = "1.1.3";

		public const string DownloadLink = null;
	}
	public class Configurations
	{
		public float MaxTimeScale = 4f;

		public float MinTimeScale = 0.1f;

		public float ButtonPosX = 380f;

		public float ButtonPosY = 20f;

		public float ClockPosX = 70f;

		public float ClockPosY = 15f;

		public float NetPosX = 70f;

		public float NetPosY = 50f;

		public string ClockStyle = "<b><color=white><size=25>";

		public string SpeedStyle = "<b><color=red><size=25>";

		public string NetStyle = "<b><color=green><size=18>";

		public string LabelStyle = "<b><color=white><size=40>";

		public string Label1Style = "<b><color=white><size=14>";

		public string ButtonStyle = "<b><color=white><size=20>";

		public bool EnableClock = true;

		public bool EnableSpeedChange = true;

		public bool EnableNet = true;

		public KeyCode FastModeKey = (KeyCode)273;

		public KeyCode SlowModeKey = (KeyCode)274;

		public KeyCode ResetSpeedKey = (KeyCode)276;

		public KeyCode ResetSpeedKey2 = (KeyCode)275;
	}
	internal class DrawTimeStuff
	{
		private static readonly string POST = "</size></color></b>";

		public static GUIStyle myCenterStyle = new GUIStyle();

		public static GUIStyle myLeftStyle = new GUIStyle();

		public static string TimeAsText
		{
			get
			{
				HomeScreen instance = PlayerSingleton<HomeScreen>.Instance;
				object obj;
				if (instance == null)
				{
					obj = null;
				}
				else
				{
					Text timeText = instance.timeText;
					obj = ((timeText != null) ? timeText.text : null);
				}
				if (obj == null)
				{
					obj = string.Empty;
				}
				return (string)obj;
			}
		}

		private static string RoundX(float a)
		{
			return Math.Round(a, 1) + "x";
		}

		public static void DrawAllButtons()
		{
			//IL_0036: 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)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			if (TimeStuff.ShowClock && (!TimeConfig.config.EnableSpeedChange || TimeStuff.IsGamePaused))
			{
				GUI.backgroundColor = Color.yellow;
				GUI.Box(new Rect(TimeConfig.config.ButtonPosX - 4f, TimeConfig.config.ButtonPosY - 4f, 353f, 87f), "");
				GUI.Box(new Rect(TimeConfig.config.ButtonPosX, TimeConfig.config.ButtonPosY, 85f, 25f), TimeConfig.config.Label1Style + "Slow" + POST);
				GUI.Box(new Rect(TimeConfig.config.ButtonPosX + 260f, TimeConfig.config.ButtonPosY, 85f, 25f), TimeConfig.config.Label1Style + "Fast" + POST);
				bool flag = DrawButton("↑", 90f, 0f, 80f, 40f);
				bool flag2 = DrawButton("↓", 90f, 40f, 80f, 40f);
				bool flag3 = DrawButton("↑", 175f, 0f, 80f, 40f);
				bool flag4 = DrawButton("↓", 175f, 40f, 80f, 40f);
				float num = (Input.GetKey((KeyCode)304) ? 1f : 0.1f);
				if (flag)
				{
					TimeStuff.ModifySlowTimeScale(num);
				}
				else if (flag2)
				{
					TimeStuff.ModifySlowTimeScale(0f - num);
				}
				else if (flag3)
				{
					TimeStuff.ModifyFastTimeScale(num);
				}
				else if (flag4)
				{
					TimeStuff.ModifyFastTimeScale(0f - num);
				}
				GUI.Box(new Rect(TimeConfig.config.ButtonPosX, TimeConfig.config.ButtonPosY + 25f, 85f, 55f), TimeConfig.config.LabelStyle + RoundX(TimeStuff.SlowTimeScale) + POST);
				GUI.Box(new Rect(TimeConfig.config.ButtonPosX + 260f, TimeConfig.config.ButtonPosY + 25f, 85f, 55f), TimeConfig.config.LabelStyle + RoundX(TimeStuff.FastTimeScale) + POST);
			}
		}

		public static void DrawNetworth()
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			if (TimeConfig.config.EnableNet && TimeStuff.ShowClock && TimeStuffMod.NETworth > 1f)
			{
				string text = MoneyManager.FormatAmount(TimeStuffMod.NETworth, false, true);
				GUI.Label(new Rect(TimeConfig.config.NetPosX, TimeConfig.config.NetPosY, 180f, 35f), TimeConfig.config.NetStyle + text + POST, myLeftStyle);
			}
		}

		public static void DrawTime()
		{
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			if (TimeStuff.ShowButtons || !string.IsNullOrWhiteSpace(TimeAsText))
			{
				string text = TimeConfig.config.ClockStyle + TimeAsText + POST;
				if (TimeStuff.ShowClock && TimeConfig.config.EnableClock && TimeStuffMod.CurrentMode == TimeStuff.SpeedMode.NORM)
				{
					GUI.Label(new Rect(TimeConfig.config.ClockPosX, TimeConfig.config.ClockPosY, 180f, 35f), text, myLeftStyle);
					return;
				}
				string text2 = string.Concat(text, "  " + TimeConfig.config.SpeedStyle + RoundX(TimeStuff.GetSpeed(TimeStuffMod.CurrentMode)) + POST);
				GUI.Label(new Rect(TimeConfig.config.ClockPosX, TimeConfig.config.ClockPosY, 180f, 35f), text2, myLeftStyle);
			}
		}

		private static bool DrawButton(string text, float x, float y, float width, float height)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			string text2 = TimeConfig.config.ButtonStyle + text + POST;
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(TimeConfig.config.ButtonPosX + x, TimeConfig.config.ButtonPosY + y, width, height);
			return GUI.Button(val, text2);
		}
	}
	internal class TimeConfig
	{
		private static readonly string configPath = Path.Combine(MelonEnvironment.UserDataDirectory, "TimeStuffConfig.json");

		public static Configurations config;

		public static void LoadConfig()
		{
			try
			{
				config = JsonConvert.DeserializeObject<Configurations>(File.ReadAllText(configPath));
				MelonLogger.Msg("[TimeStuff] Parsing config");
				return;
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("Failed to parse config: " + ex.Message + ". Recreating default config.");
			}
			SaveNewConfig();
		}

		private static void SaveNewConfig()
		{
			MelonLogger.Msg("[TimeStuff] Creating new config");
			config = new Configurations();
			string contents = JsonConvert.SerializeObject((object)config, (Formatting)1);
			File.WriteAllText(configPath, contents);
		}
	}
	public static class TimeStuff
	{
		public enum SpeedMode
		{
			FAST,
			NORM,
			SLOW
		}

		public static bool IsGamePaused { get; set; } = false;


		public static bool ShowClock { get; set; }

		public static bool ShowButtons { get; set; }

		public static float FastTimeScale { get; set; } = 2f;


		public static float SlowTimeScale { get; set; } = 0.5f;


		public static float GetSpeed(SpeedMode mode)
		{
			return mode switch
			{
				SpeedMode.FAST => FastTimeScale, 
				SpeedMode.SLOW => SlowTimeScale, 
				_ => 1f, 
			};
		}

		public static void ModifyFastTimeScale(float ammount)
		{
			FastTimeScale = Mathf.Clamp(FastTimeScale + ammount, 1.1f, TimeConfig.config.MaxTimeScale);
		}

		public static void ModifySlowTimeScale(float ammount)
		{
			SlowTimeScale = Mathf.Clamp(SlowTimeScale + ammount, TimeConfig.config.MinTimeScale, 0.9f);
		}
	}
	public class TimeStuffMod : MelonMod
	{
		[HarmonyPatch(typeof(PauseMenu), "Pause")]
		public static class Attach_PausedGame_Patch
		{
			public static void Postfix()
			{
				TimeStuff.ShowButtons = true;
				TimeStuff.IsGamePaused = true;
			}
		}

		[HarmonyPatch(typeof(PauseMenu), "Resume")]
		public static class Attach_ResumeGame_Patch
		{
			public static void Postfix()
			{
				TimeStuff.ShowButtons = false;
				TimeStuff.IsGamePaused = false;
				Time.timeScale = TimeStuff.GetSpeed(CurrentMode);
			}
		}

		[HarmonyPatch(typeof(MoneyManager), "Loaded")]
		public static class Loaded_Money_Patch
		{
			public static void Postfix()
			{
				NETworth = NetworkSingleton<MoneyManager>.instance.GetNetWorth();
			}
		}

		[HarmonyPatch(typeof(MoneyManager), "ChangeCashBalance")]
		public static class Worth_Patch
		{
			public static void Prefix(float change, bool visualizeChange, bool playCashSound)
			{
				NETworth = NetworkSingleton<MoneyManager>.instance.GetNetWorth();
			}
		}

		public static float NETworth = 0f;

		public static TimeStuff.SpeedMode CurrentMode = TimeStuff.SpeedMode.NORM;

		public override void OnInitializeMelon()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Expected O, but got Unknown
			TimeConfig.LoadConfig();
			DrawTimeStuff.myCenterStyle.alignment = (TextAnchor)4;
			DrawTimeStuff.myLeftStyle.alignment = (TextAnchor)3;
			((MelonEventBase<LemonAction>)(object)MelonEvents.OnGUI).Subscribe(new LemonAction(DrawTimeStuff.DrawTime), 0, false);
			((MelonEventBase<LemonAction>)(object)MelonEvents.OnGUI).Subscribe(new LemonAction(DrawTimeStuff.DrawAllButtons), 0, false);
			((MelonEventBase<LemonAction>)(object)MelonEvents.OnGUI).Subscribe(new LemonAction(DrawTimeStuff.DrawNetworth), 0, false);
		}

		public override void OnLateUpdate()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			if (!TimeConfig.config.EnableSpeedChange)
			{
				return;
			}
			((MelonBase)this).OnLateUpdate();
			if (!TimeStuff.IsGamePaused)
			{
				if (Input.GetKeyDown(TimeConfig.config.FastModeKey))
				{
					CurrentMode = TimeStuff.SpeedMode.FAST;
				}
				else if (Input.GetKeyDown(TimeConfig.config.SlowModeKey))
				{
					CurrentMode = TimeStuff.SpeedMode.SLOW;
				}
				else if (Input.GetKeyDown(TimeConfig.config.ResetSpeedKey) || Input.GetKeyDown(TimeConfig.config.ResetSpeedKey2))
				{
					CurrentMode = TimeStuff.SpeedMode.NORM;
				}
				Time.timeScale = TimeStuff.GetSpeed(CurrentMode);
			}
		}

		public override void OnSceneWasInitialized(int buildIndex, string sceneName)
		{
			if (sceneName == "Main" && buildIndex == 1)
			{
				TimeStuff.ShowButtons = false;
				TimeStuff.ShowClock = TimeConfig.config.EnableClock;
			}
		}

		public override void OnDeinitializeMelon()
		{
			if (CurrentMode != TimeStuff.SpeedMode.NORM)
			{
				Time.timeScale = TimeStuff.GetSpeed(TimeStuff.SpeedMode.NORM);
			}
		}

		public override void OnSceneWasUnloaded(int buildIndex, string sceneName)
		{
			if (sceneName == "Main" && buildIndex == 1)
			{
				TimeStuff.ShowButtons = false;
				TimeStuff.ShowClock = false;
			}
		}
	}
}
namespace TimeStuffMod.Properties
{
	[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
	[DebuggerNonUserCode]
	[CompilerGenerated]
	internal class Resources
	{
		private static ResourceManager resourceMan;

		private static CultureInfo resourceCulture;

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static ResourceManager ResourceManager
		{
			get
			{
				if (resourceMan == null)
				{
					ResourceManager resourceManager = new ResourceManager("TimeStuffMod.Properties.Resources", typeof(Resources).Assembly);
					resourceMan = resourceManager;
				}
				return resourceMan;
			}
		}

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static CultureInfo Culture
		{
			get
			{
				return resourceCulture;
			}
			set
			{
				resourceCulture = value;
			}
		}

		internal Resources()
		{
		}
	}
}