Decompiled source of Longplay v1.0.0

Longplay.dll

Decompiled 4 days ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using HarmonyLib;
using Il2CppScheduleOne.Growing;
using Il2CppScheduleOne.ObjectScripts;
using Longplay;
using MelonLoader;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
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), "Longplay", "1.0.0", "Freshairkaboom", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("Longplay")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+0a849ce03ee29282db5e25004f0119593a7885cd")]
[assembly: AssemblyProduct("Longplay")]
[assembly: AssemblyTitle("Longplay")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Longplay
{
	public class Core : MelonMod
	{
		[HarmonyPatch(typeof(Plant), "Initialize")]
		private class PlantPatches
		{
			private static void Postfix(Plant __instance)
			{
				__instance.GrowthTime = (int)((double)newGrowthTime + 0.5);
			}
		}

		[HarmonyPatch(typeof(ChemistryStation), "SetCookOperation")]
		public class ChemistryStationPatches
		{
			private static void Postfix(ChemistryStation __instance)
			{
				if (__instance.CurrentCookOperation != null)
				{
					int cookTime_Mins = CalculateAdjustedCookTime();
					__instance.CurrentCookOperation.Recipe.CookTime_Mins = cookTime_Mins;
				}
			}

			private static int CalculateAdjustedCookTime()
			{
				return (int)((double)newCookDuration + 0.5);
			}
		}

		private class Config
		{
			public int GrowthTime { get; set; }

			public int CookDuration { get; set; }
		}

		private static int newGrowthTime;

		private static int newCookDuration;

		public override void OnApplicationStart()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			Object.DontDestroyOnLoad((Object)new GameObject("Longplay"));
			((MelonBase)this).LoggerInstance.Msg("Longplay initialized.");
			LoadConfig();
			Harmony val = new Harmony("com.freshairkaboom.longplay");
			val.PatchAll();
		}

		private void LoadConfig()
		{
			try
			{
				string path = Path.Combine(MelonEnvironment.UserDataDirectory, "LongplayConfig.json");
				if (File.Exists(path))
				{
					string text = File.ReadAllText(path);
					Config config = JsonConvert.DeserializeObject<Config>(text);
					newGrowthTime = (int)((double)config.GrowthTime + 0.5);
					newCookDuration = (int)((double)config.CookDuration + 0.5);
					((MelonBase)this).LoggerInstance.Msg($"Config loaded. GrowthTime set to {newGrowthTime}, CookDuration set to {newCookDuration}.");
				}
				else
				{
					Config config2 = new Config
					{
						GrowthTime = 60,
						CookDuration = 960
					};
					File.WriteAllText(path, JsonConvert.SerializeObject((object)config2, (Formatting)1));
					newGrowthTime = config2.GrowthTime;
					newCookDuration = config2.CookDuration;
					((MelonBase)this).LoggerInstance.Msg("Default config created with GrowthTime = 9 and CookDuration = 480.");
				}
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Error("Error loading config: " + ex.Message);
				newGrowthTime = 48;
				newCookDuration = 480;
			}
		}

		public override void OnDeinitializeMelon()
		{
			((MelonBase)this).LoggerInstance.Msg("Longplay deinitialized.");
		}
	}
}