Decompiled source of PlanterCoreClusters v2.0.0

plugins/TTMod-PlanterCoreClusters/TTMod-PlanterCoreClusters.dll

Decompiled 7 months ago
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using EquinoxsModUtils;
using HarmonyLib;
using PlanterCoreClusters.Patches;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("TTMod_PlanterCoreClusters")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TTMod_PlanterCoreClusters")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("eaaa5600-803c-4fdd-8fd6-28e03dc5e71e")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace PlanterCoreClusters
{
	[BepInPlugin("com.equinox.TTMod_PlanterCoreClusters", "TTMod_PlanterCoreClusters", "2.0.0")]
	public class PlanterCoreClustersPlugin : BaseUnityPlugin
	{
		private const string MyGUID = "com.equinox.TTMod_PlanterCoreClusters";

		private const string PluginName = "TTMod_PlanterCoreClusters";

		private const string VersionString = "2.0.0";

		private static readonly Harmony Harmony = new Harmony("com.equinox.TTMod_PlanterCoreClusters");

		public static ManualLogSource Log = new ManualLogSource("TTMod_PlanterCoreClusters");

		public static string coreBoostGrowingName = "Core Boost (Growing)";

		public static float perClusterBoost = 5f;

		public static bool logEMU = false;

		private void Awake()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: 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_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: 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)
			//IL_008a: Expected O, but got Unknown
			((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: TTMod_PlanterCoreClusters, VersionString: 2.0.0 is loading...");
			Harmony.PatchAll();
			Harmony.CreateAndPatchAll(typeof(PlanterInstancePatch), (string)null);
			ModUtils.AddNewUnlock(new NewUnlockDetails
			{
				category = (TechCategory)5,
				coreTypeNeeded = (CoreType)2,
				coreCountNeeded = 100,
				description = $"Increases speed of all Planters by {perClusterBoost}% per Core Cluster.",
				displayName = coreBoostGrowingName,
				numScansNeeded = 0,
				requiredTier = (ResearchTier)2,
				treePosition = 0
			}, logEMU);
			ModUtils.GameDefinesLoaded += OnGameDefinesLoaded;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: TTMod_PlanterCoreClusters, VersionString: 2.0.0 is loaded.");
			Log = ((BaseUnityPlugin)this).Logger;
		}

		private void OnGameDefinesLoaded(object sender, EventArgs e)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			Unlock unlockByName = ModUtils.GetUnlockByName("Core Boost (Smelting)", logEMU);
			Unlock unlockByName2 = ModUtils.GetUnlockByName("Core Boost (Threshing)", logEMU);
			Unlock unlockByName3 = ModUtils.GetUnlockByName("Planter", logEMU);
			ModUtils.UpdateUnlockTier(coreBoostGrowingName, unlockByName.requiredTier, logEMU);
			ModUtils.UpdateUnlockTreePosition(coreBoostGrowingName, unlockByName2.treePosition, logEMU);
			ModUtils.UpdateUnlockSprite(coreBoostGrowingName, unlockByName3.sprite, logEMU);
		}
	}
}
namespace PlanterCoreClusters.Patches
{
	internal class PlanterInstancePatch
	{
		private static Unlock coreBoostGrowing;

		private static bool techUnlocked;

		[HarmonyPatch(typeof(PlanterInstance), "SimUpdate")]
		[HarmonyPrefix]
		private static void applyCoreBoost(PlanterInstance __instance)
		{
			//IL_011e: 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)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)coreBoostGrowing == (Object)null)
			{
				coreBoostGrowing = ModUtils.GetUnlockByName(PlanterCoreClustersPlugin.coreBoostGrowingName, false);
			}
			if (!techUnlocked)
			{
				techUnlocked = TechTreeState.instance.IsUnlockActive(((UniqueIdScriptableObject)coreBoostGrowing).uniqueId);
				if (!techUnlocked)
				{
					return;
				}
			}
			if (TechTreeState.instance.freeCores == 0)
			{
				return;
			}
			float num = (float)TechTreeState.instance.freeCores * PlanterCoreClustersPlugin.perClusterBoost * 0.0001f;
			num += 1f;
			for (int i = 0; i < __instance.plantSlots.Count(); i++)
			{
				if (__instance.plantSlots[i].growthProgress > __instance.plantSlots[i].totalGrowthDuration)
				{
					__instance.plantSlots[i].growthProgress = __instance.plantSlots[i].totalGrowthDuration;
				}
				int plantId = __instance.plantSlots[i].plantId;
				if (plantId == -1)
				{
					break;
				}
				SaveState.GetResInfoFromId(plantId);
				if (__instance.plantSlots[i].totalGrowthDuration == 120f)
				{
					float totalGrowthDuration = Mathf.Max(120f / num, 1E-07f);
					__instance.plantSlots[i].totalGrowthDuration = totalGrowthDuration;
				}
			}
		}
	}
}