Decompiled source of FasterChem v1.0.2

FasterChem.dll

Decompiled 3 months 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 FasterChem;
using HarmonyLib;
using Il2CppScheduleOne.ObjectScripts;
using MelonLoader;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Core), "FasterChem", "1.0.1", "Owlgames_", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("FasterChem")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1")]
[assembly: AssemblyInformationalVersion("1.0.0+c3c7261d05b6fabb6732eba38a0554277e72673d")]
[assembly: AssemblyProduct("FasterChem")]
[assembly: AssemblyTitle("FasterChem")]
[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 FasterChem
{
	public class Core : MelonMod
	{
		[HarmonyPatch(typeof(ChemistryStation), "SetCookOperation")]
		public class Patch_CookTime
		{
			[HarmonyPostfix]
			public static void Postfix(ChemistryStation __instance)
			{
				object obj;
				if (__instance == null)
				{
					obj = null;
				}
				else
				{
					ChemistryCookOperation currentCookOperation = __instance.CurrentCookOperation;
					obj = ((currentCookOperation != null) ? currentCookOperation.Recipe : null);
				}
				if ((Object)obj != (Object)null)
				{
					int num = Math.Max(1, newCookDuration / _divider);
					__instance.CurrentCookOperation.Recipe.CookTime_Mins = num;
					MelonLogger.Msg($"CookTime set to {num} minutes.");
				}
			}
		}

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

			public int SpeedUpDivider { get; set; }
		}

		private static int newCookDuration = 180;

		private static int _divider = 2;

		private static string configPath;

		private static Config config;

		public override void OnInitializeMelon()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Expected O, but got Unknown
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			Object.DontDestroyOnLoad((Object)new GameObject("FasterChem"));
			MelonLogger.Msg("FasterChem initialized.");
			new Harmony("com.xaender.FasterChem").PatchAll();
			configPath = Path.Combine(MelonEnvironment.UserDataDirectory, "FasterChemConfig.json");
			LoadOrCreateConfig();
		}

		private static void LoadOrCreateConfig()
		{
			try
			{
				if (File.Exists(configPath))
				{
					config = JsonConvert.DeserializeObject<Config>(File.ReadAllText(configPath));
					MelonLogger.Msg("Config loaded successfully.");
				}
				else
				{
					config = new Config
					{
						CookDuration = 180,
						SpeedUpDivider = 2
					};
					SaveConfig();
					MelonLogger.Msg("Config not found. Created default FasterChemConfig.json.");
				}
				newCookDuration = config.CookDuration;
				_divider = config.SpeedUpDivider;
			}
			catch (Exception value)
			{
				MelonLogger.Error($"Failed to load or create config: {value}");
			}
		}

		private static void SaveConfig()
		{
			try
			{
				string contents = JsonConvert.SerializeObject((object)config, (Formatting)1);
				File.WriteAllText(configPath, contents);
			}
			catch (Exception value)
			{
				MelonLogger.Error($"Failed to save config: {value}");
			}
		}
	}
}