Decompiled source of EasySpeedUp v1.1.0

EasySpeedUp.dll

Decompiled 11 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("EasySpeedUp")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+3ff26b4956c17cf51d50f6dc60a9f7df7ce6e085")]
[assembly: AssemblyProduct("EasySpeedUp")]
[assembly: AssemblyTitle("EasySpeedUp")]
[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 EasySpeedUp
{
	[HarmonyPatch(typeof(AssemblerComponent), "InternalUpdate")]
	public class AssemblerComponentPatch
	{
		public static void Prefix(ref AssemblerComponent __instance, out PatchState __state)
		{
			__state = new PatchState
			{
				TimeSpend = __instance.timeSpend,
				ExtraTimeSpend = __instance.extraTimeSpend
			};
			__instance.timeSpend /= EasySpeedUpLib.SpeedScale;
			__instance.extraTimeSpend /= EasySpeedUpLib.SpeedScale;
		}

		public static void Postfix(ref AssemblerComponent __instance, PatchState __state)
		{
			__instance.timeSpend = __state.TimeSpend;
			__instance.extraTimeSpend = __state.ExtraTimeSpend;
		}
	}
	public static class CargoTrafficPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(CargoTraffic), "CargoPathsGameTickSync")]
		public static bool CargoPathSyncPrefix(CargoTraffic __instance)
		{
			PerformanceMonitor.BeginSample((ECpuWorkEntry)9);
			for (int i = 0; i < EasySpeedUpLib.SpeedScale; i++)
			{
				for (int j = 1; j < __instance.pathCursor; j++)
				{
					if (__instance.pathPool[j] != null && __instance.pathPool[j].id == j)
					{
						__instance.pathPool[j].Update();
					}
				}
			}
			PerformanceMonitor.EndSample((ECpuWorkEntry)9);
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(CargoTraffic), "CargoPathsGameTickAsync")]
		public static bool CargoPathAsyncPrefix(CargoTraffic __instance, int _usedThreadCnt, int _curThreadIdx, int _minimumMissionCnt)
		{
			int num = default(int);
			int num2 = default(int);
			if (!WorkerThreadExecutor.CalculateMissionIndex(1, __instance.pathCursor - 1, _usedThreadCnt, _curThreadIdx, _minimumMissionCnt, ref num, ref num2))
			{
				return false;
			}
			for (int i = 0; i < EasySpeedUpLib.SpeedScale; i++)
			{
				for (int j = num; j < num2; j++)
				{
					if (__instance.pathPool[j] != null && __instance.pathPool[j].id == j)
					{
						__instance.pathPool[j].Update();
					}
				}
			}
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(CargoTraffic), "SpraycoaterGameTick")]
		public static bool SplitterGameTickPrefix(CargoTraffic __instance)
		{
			AnimData[] entityAnimPool = __instance.factory.entityAnimPool;
			int[] consumeRegister = GameMain.statistics.production.factoryStatPool[__instance.factory.index].consumeRegister;
			PerformanceMonitor.BeginSample((ECpuWorkEntry)9);
			for (int i = 0; i < EasySpeedUpLib.SpeedScale; i++)
			{
				for (int j = 1; j < __instance.spraycoaterCursor; j++)
				{
					if (__instance.spraycoaterPool[j].id == j)
					{
						((SpraycoaterComponent)(ref __instance.spraycoaterPool[j])).InternalUpdate(__instance, entityAnimPool, consumeRegister);
					}
				}
			}
			PerformanceMonitor.EndSample((ECpuWorkEntry)9);
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(CargoTraffic), "PilerGameTick")]
		public static bool PilerGameTickPrefix(CargoTraffic __instance)
		{
			PerformanceMonitor.BeginSample((ECpuWorkEntry)9);
			AnimData[] entityAnimPool = __instance.factory.entityAnimPool;
			float num = 0f;
			for (int i = 1; i < __instance.pilerCursor; i++)
			{
				if (__instance.pilerPool[i].id == i)
				{
					for (int j = 0; j < EasySpeedUpLib.SpeedScale; j++)
					{
						uint num2 = ((PilerComponent)(ref __instance.pilerPool[i])).InternalUpdate(__instance, entityAnimPool, ref num);
						int entityId = __instance.pilerPool[i].entityId;
						entityAnimPool[entityId].state = (uint)((int)num2 + __instance.pilerPool[i].slowlyBeltSpeed * 10 + (((PilerComponent)(ref __instance.pilerPool[i])).isWorkForward ? 100 : 0));
						entityAnimPool[entityId].power = num;
						float time = entityAnimPool[entityId].time;
						entityAnimPool[entityId].time = (((PilerComponent)(ref __instance.pilerPool[i])).isWorkForward ? ((float)(((double)time + 0.01666666753590107 * (double)num * (double)__instance.pilerPool[i].slowlyBeltSpeed) % 10.0)) : ((float)(((double)time - 0.01666666753590107 * (double)num * (double)__instance.pilerPool[i].slowlyBeltSpeed) % 10.0)));
					}
				}
			}
			PerformanceMonitor.EndSample((ECpuWorkEntry)9);
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(CargoTraffic), "SplitterGameTick")]
		public static bool SplitterGameTickPrefix(CargoTraffic __instance, long time)
		{
			PerformanceMonitor.BeginSample((ECpuWorkEntry)11);
			for (int i = 0; i < EasySpeedUpLib.SpeedScale; i++)
			{
				for (int j = 1; j < __instance.splitterCursor; j++)
				{
					if (__instance.splitterPool[j].id == j)
					{
						__instance.UpdateSplitter(ref __instance.splitterPool[j], time + i);
					}
				}
			}
			PerformanceMonitor.EndSample((ECpuWorkEntry)11);
			return false;
		}
	}
	[BepInPlugin("EasySpeedUp", "Easy Speed Up", "1.0.1")]
	[BepInProcess("DSPGAME.exe")]
	public class EasySpeedUpLib : BaseUnityPlugin
	{
		private const string Version = "1.0.1";

		private static ConfigEntry<int> _speedScale;

		public static int SpeedScale
		{
			get
			{
				int value = _speedScale.Value;
				if (value >= 1)
				{
					if (value > 10)
					{
						return 10;
					}
					return _speedScale.Value;
				}
				return 1;
			}
		}

		public static int MechaScale
		{
			get
			{
				int num = SpeedScale / 2;
				if (num < 1)
				{
					return 1;
				}
				if (num <= 4)
				{
					return num;
				}
				return 4;
			}
		}

		private void Start()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: 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_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			InitConfig();
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"EasySpeedUp Enable: speedup {_speedScale.Value}x ");
			Harmony val = new Harmony("EasySpeedUpLib");
			val.PatchAll(typeof(MinerComponentPatch));
			val.PatchAll(typeof(StationComponentPatch));
			val.PatchAll(typeof(AssemblerComponentPatch));
			val.PatchAll(typeof(CargoTrafficPatch));
			val.PatchAll(typeof(InserterComponentPatch));
			val.PatchAll(typeof(LabComponentPatch));
			val.PatchAll(typeof(MechaForgePatch));
			val.PatchAll(typeof(MechaLabPatch));
			val.PatchAll(typeof(ForgeTaskPatch));
			val.PatchAll(typeof(PowerGeneratorComponentPatch));
		}

		public void InitConfig()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			_speedScale = ((BaseUnityPlugin)this).Config.Bind<int>("Config/配置", "Speed Scale/加速倍率", 4, new ConfigDescription("Default:4 ", (AcceptableValueBase)(object)new AcceptableValueRange<int>(2, 10), new object[2]));
		}
	}
	[HarmonyPatch(typeof(ForgeTask), "Produce")]
	public class ForgeTaskPatch
	{
		public static void Prefix(ref ForgeTask __instance, out int __state)
		{
			__state = __instance.tickSpend;
			ForgeTask obj = __instance;
			obj.tickSpend /= EasySpeedUpLib.MechaScale;
		}

		public static void Postfix(ref ForgeTask __instance, int __state)
		{
			__instance.tickSpend = __state;
		}
	}
	public static class InserterComponentPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(InserterComponent), "InternalUpdate")]
		public static void UpdatePrefix(ref InserterComponent __instance, out int __state)
		{
			__state = __instance.stt;
			__instance.stt /= EasySpeedUpLib.SpeedScale;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(InserterComponent), "InternalUpdate")]
		public static void UpdatePostfix(ref InserterComponent __instance, int __state)
		{
			__instance.stt = __state;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(InserterComponent), "InternalUpdateNoAnim")]
		public static void UpdateNoAnimPrefix(ref InserterComponent __instance, out int __state)
		{
			__state = __instance.stt;
			__instance.stt /= EasySpeedUpLib.SpeedScale;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(InserterComponent), "InternalUpdateNoAnim")]
		public static void UpdateNoAnimPostfix(ref InserterComponent __instance, int __state)
		{
			__instance.stt = __state;
		}
	}
	public static class LabComponentPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(LabComponent), "InternalUpdateAssemble")]
		public static void AssemblePrefix(ref LabComponent __instance, out PatchState __state)
		{
			__state = new PatchState
			{
				TimeSpend = __instance.timeSpend,
				ExtraTimeSpend = __instance.extraTimeSpend
			};
			__instance.timeSpend /= EasySpeedUpLib.SpeedScale;
			__instance.extraTimeSpend /= EasySpeedUpLib.SpeedScale;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(LabComponent), "InternalUpdateAssemble")]
		public static void AssemblePostfix(ref LabComponent __instance, PatchState __state)
		{
			__instance.timeSpend = __state.TimeSpend;
			__instance.extraTimeSpend = __state.ExtraTimeSpend;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(LabComponent), "InternalUpdateResearch")]
		public static void ResearchPrefix(float power, ref float research_speed, int[] consumeRegister, ref TechState ts, ref int techHashedThisFrame, ref long uMatrixPoint, ref long hashRegister)
		{
			research_speed *= EasySpeedUpLib.SpeedScale;
		}
	}
	[HarmonyPatch(typeof(MechaForge), "GameTick")]
	public class MechaForgePatch
	{
		public static void Prefix(ref MechaForge __instance, out int __state)
		{
			__state = 0;
			if (__instance.tasks == null)
			{
				Assert.NotNull((object)__instance.tasks);
			}
			else if (__instance.tasks.Count > 0)
			{
				ForgeTask val = __instance.tasks[0];
				__state = val.tickSpend;
				val.tickSpend /= EasySpeedUpLib.MechaScale;
			}
		}

		public static void Postfix(ref MechaForge __instance, int __state)
		{
			if (__state != 0 && __instance.tasks.Count > 0)
			{
				__instance.tasks[0].tickSpend = __state;
				MechaForge obj = __instance;
				obj.totalTime /= (float)EasySpeedUpLib.MechaScale;
			}
		}
	}
	[HarmonyPatch(typeof(MechaLab), "GameTick")]
	public class MechaLabPatch
	{
		public static void Prefix(MechaLab __instance, out int __state)
		{
			__state = __instance.gameHistory.techSpeed;
			GameHistoryData gameHistory = __instance.gameHistory;
			gameHistory.techSpeed *= EasySpeedUpLib.MechaScale;
		}

		public static void Postfix(MechaLab __instance, int __state)
		{
			__instance.gameHistory.techSpeed = __state;
		}
	}
	[HarmonyPatch(typeof(MinerComponent), "InternalUpdate")]
	public class MinerComponentPatch
	{
		public static void Prefix(ref MinerComponent __instance, out int __state)
		{
			__state = __instance.period;
			__instance.period /= EasySpeedUpLib.SpeedScale;
		}

		public static void Postfix(ref MinerComponent __instance, int __state)
		{
			__instance.period = __state;
		}
	}
	public class PatchState
	{
		public int TimeSpend;

		public int ExtraTimeSpend;
	}
	[HarmonyPatch(typeof(PowerGeneratorComponent), "GameTick_Gamma")]
	public class PowerGeneratorComponentPatch
	{
		public static void Prefix(ref PowerGeneratorComponent __instance, out long __state)
		{
			__state = __instance.capacityCurrentTick;
			__instance.capacityCurrentTick *= EasySpeedUpLib.SpeedScale;
		}

		public static void Postfix(ref PowerGeneratorComponent __instance, long __state)
		{
			__instance.capacityCurrentTick = __state;
		}
	}
	[HarmonyPatch(typeof(StationComponent), "UpdateCollection")]
	public class StationComponentPatch
	{
		public static void Prefix(PlanetFactory factory, ref float collectSpeedRate, int[] productRegister)
		{
			collectSpeedRate *= EasySpeedUpLib.SpeedScale;
		}
	}
}