Decompiled source of SampleAndHoldSim v0.7.3
SampleAndHoldSim.dll
Decompiled 3 hours ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Threading; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using CheatEnabler.Patches; using HarmonyLib; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("SampleAndHoldSim")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.7.2.0")] [module: UnverifiableCode] namespace SampleAndHoldSim; internal class Combat_Patch { [HarmonyTranspiler] [HarmonyPatch(typeof(EnemyUnitComponent), "ApproachToTargetPoint_SLancer")] [HarmonyPatch(typeof(EnemyUnitComponent), "Attack_SLancer")] [HarmonyPatch(typeof(EnemyUnitComponent), "RunBehavior_OrbitTarget_SLancer")] private static IEnumerable<CodeInstruction> ScaleDamageDown(IEnumerable<CodeInstruction> instructions) { //IL_0056: 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) //IL_0077: Expected O, but got Unknown FieldInfo plasma = AccessTools.Field(typeof(GeneralProjectile), "damage"); FieldInfo laser = AccessTools.Field(typeof(SpaceLaserOneShot), "damage"); FieldInfo sweep = AccessTools.Field(typeof(SpaceLaserSweep), "damage"); return new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1] { new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Stfld && ((FieldInfo)i.operand == plasma || (FieldInfo)i.operand == laser || (FieldInfo)i.operand == sweep)), (string)null) }).Repeat((Action<CodeMatcher>)delegate(CodeMatcher matcher) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Expected O, but got Unknown //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Expected O, but got Unknown matcher.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[2] { new CodeInstruction(OpCodes.Ldarg_2, (object)null), new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(Combat_Patch), "ModDamageDown", (Type[])null, (Type[])null)) }).Advance(5); }, (Action<string>)null).InstructionEnumeration(); } private static int ModDamageDown(int originValue, EnemyDFHiveSystem enemyDFHive) { if (MainManager.UpdatePeriod <= 1 || enemyDFHive.starData.index == MainManager.FocusStarIndex) { return originValue; } return originValue / MainManager.UpdatePeriod; } [HarmonyTranspiler] [HarmonyPatch(typeof(TurretComponent), "Shoot_Plasma")] [HarmonyPatch(typeof(TurretComponent), "Shoot_Missile")] private static IEnumerable<CodeInstruction> ScaleDamageUp(IEnumerable<CodeInstruction> instructions) { //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Expected O, but got Unknown FieldInfo plasma = AccessTools.Field(typeof(GeneralProjectile), "damage"); FieldInfo missile = AccessTools.Field(typeof(GeneralMissile), "damage"); return new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1] { new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Stfld && ((FieldInfo)i.operand == plasma || (FieldInfo)i.operand == missile)), (string)null) }).Repeat((Action<CodeMatcher>)delegate(CodeMatcher matcher) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Expected O, but got Unknown //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Expected O, but got Unknown matcher.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[2] { new CodeInstruction(OpCodes.Ldarg_1, (object)null), new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(Combat_Patch), "ModDamageUp", (Type[])null, (Type[])null)) }).Advance(5); }, (Action<string>)null).InstructionEnumeration(); } private static int ModDamageUp(int originValue, PlanetFactory factory) { if (MainManager.UpdatePeriod <= 1 || factory.index == MainManager.FocusFactoryIndex) { return originValue; } return originValue * MainManager.UpdatePeriod; } [HarmonyPrefix] [HarmonyPatch(typeof(PlanetATField), "TestRelayCondition")] private static bool TestRelayCondition() { return Plugin.instance.EnableRelayLanding.Value; } } public struct ProjectileData { public int PlanetId; public int TargetId; public Vector3 LocalPos; } public class FactoryManager { public long EnergyReqCurrentTick; private ConcurrentBag<ProjectileData> dysonBag; private readonly List<ProjectileData> dysonList = new List<ProjectileData>(); private int idleCount; public bool IsActive; public bool IsNextIdle; public int Index; public PlanetFactory factory; private StationData[] stationDataPool; public void AddDysonData(int planetId, int targetId, in Vector3 localPos) { //IL_0034: 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) if (dysonBag == null) { dysonBag = new ConcurrentBag<ProjectileData>(); } dysonBag.Add(new ProjectileData { PlanetId = planetId, TargetId = targetId, LocalPos = localPos }); } public void DysonBeforeTick() { EnergyReqCurrentTick = 0L; } public void DysonColletEnd() { if (dysonBag != null) { idleCount = 0; dysonList.Clear(); ProjectileData result; while (dysonBag.TryTake(out result)) { dysonList.Add(result); } } } public void DysonIdleTick() { if (factory.dysonSphere == null) { return; } DysonSphere dysonSphere = factory.dysonSphere; dysonSphere.energyReqCurrentTick += EnergyReqCurrentTick; if (dysonList.Count <= 0) { return; } idleCount++; foreach (ProjectileData dyson in dysonList) { ProjectileData projectile = dyson; if (projectile.TargetId < 0) { Dyson_Patch.AddBullet(factory.dysonSphere.swarm, in projectile); } else { Dyson_Patch.AddRocket(factory.dysonSphere, in projectile, idleCount); } } } public FactoryManager(int index, PlanetFactory factory) { Index = index; this.factory = factory; } public void SetMineral(StationComponent station, int mineralCount) { if (stationDataPool != null && station.id < stationDataPool.Length) { StationData stationData = stationDataPool[station.id]; if (stationData != null) { StationData.SetMineral(stationData, mineralCount); } } } public void StationBeforeTick() { if (IsActive) { Traversal(StationData.ActiveBegin, record: false); } } public void StationBeforeTransport() { if (IsActive) { Traversal(StationData.ActiveBeforeTransport, record: false); } } public void StationAfterTransport() { if (IsActive) { Traversal(StationData.ActiveAfterTransport, record: false); } } public void StationAfterTick() { if (IsActive) { Traversal(StationData.ActiveEnd, Index == UIstation.ViewFactoryIndex); } else { Traversal(StationData.IdleEnd, record: false); } } public void EnsureStationDataPoolSize(int size) { if (stationDataPool == null || stationDataPool.Length < size) { StationData[] destinationArray = new StationData[size + 32]; if (stationDataPool != null) { Array.Copy(stationDataPool, destinationArray, stationDataPool.Length); } stationDataPool = destinationArray; } } private void Traversal(Action<StationData, StationComponent> action, bool record) { PlanetTransport transport = factory.transport; if (stationDataPool == null || stationDataPool.Length <= transport.stationCursor) { EnsureStationDataPoolSize(transport.stationCursor); } for (int i = 1; i < transport.stationCursor; i++) { StationComponent val = transport.stationPool[i]; if (val != null) { if (stationDataPool[i] == null) { stationDataPool[i] = new StationData(val); } action(stationDataPool[i], val); if (record && i == UIstation.ViewStationId) { UIstation.Record(stationDataPool[i]); } } else if (stationDataPool[i] != null) { stationDataPool[i] = null; } } } } internal class Ejector_Patch { [HarmonyTranspiler] [HarmonyPatch(typeof(EjectorComponent), "InternalUpdate")] public static IEnumerable<CodeInstruction> EjectorComponent_Transpiler(IEnumerable<CodeInstruction> instructions) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Expected O, but got Unknown //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Expected O, but got Unknown //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Expected O, but got Unknown //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Expected O, but got Unknown //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Expected O, but got Unknown //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Expected O, but got Unknown //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Expected O, but got Unknown //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Expected O, but got Unknown try { CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[2] { new CodeMatch((OpCode?)OpCodes.Ldloc_S, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Stfld, (object)AccessTools.Field(typeof(SailBullet), "lBegin"), (string)null) }); if (val.IsInvalid) { Log.Warn("EjectorComponent_Transpiler: Can't find SailBullet.lBegin"); return instructions; } CodeInstruction instruction = val.Instruction; val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[2] { new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.Method(typeof(DysonSwarm), "AddBullet", (Type[])null, (Type[])null), (string)null), new CodeMatch((OpCode?)OpCodes.Pop, (object)null, (string)null) }); if (val.IsInvalid) { Log.Warn("EjectorComponent_Transpiler: Can't find AddBullet"); return instructions; } val.Advance(1).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[6] { new CodeInstruction(OpCodes.Ldarg_0, (object)null), new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(EjectorComponent), "planetId")), instruction, new CodeInstruction(OpCodes.Ldarg_0, (object)null), new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(EjectorComponent), "orbitId")), Transpilers.EmitDelegate<Action<int, Vector3, int>>((Action<int, Vector3, int>)delegate(int planetId, Vector3 localPos, int orbitId) { if (MainManager.Planets.TryGetValue(planetId, out var value) && value.IsNextIdle) { value.AddDysonData(planetId, -orbitId, in localPos); } }) }); return val.InstructionEnumeration(); } catch (Exception obj) { Log.Warn("EjectorComponent_Transpiler error!"); Log.Warn(obj); return instructions; } } } internal class Dyson_Patch { internal static void AddEnergyReqCurrentTick(PlanetFactory factory, long value) { if (MainManager.TryGet(factory.index, out var factoryData)) { Interlocked.Add(ref factoryData.EnergyReqCurrentTick, value); } } [HarmonyTranspiler] [HarmonyPriority(200)] [HarmonyPatch(typeof(PowerSystem), "RequestDysonSpherePower")] private static IEnumerable<CodeInstruction> RequestDysonSpherePower_Transpiler(IEnumerable<CodeInstruction> instructions) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Expected O, but got Unknown //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Expected O, but got Unknown //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Expected O, but got Unknown //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Expected O, but got Unknown try { CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).End().MatchBack(false, (CodeMatch[])(object)new CodeMatch[1] { new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Stfld && ((FieldInfo)i.operand).Name == "energyReqCurrentTick"), (string)null) }); CodeInstruction val2 = val.InstructionAt(-2); val.Advance(1).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[4] { new CodeInstruction(OpCodes.Ldarg_0, (object)null), new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(PowerSystem), "factory")), val2, new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(Dyson_Patch), "AddEnergyReqCurrentTick", (Type[])null, (Type[])null)) }); return val.InstructionEnumeration(); } catch { Log.Warn("PowerSystem.RequestDysonSpherePower Transpiler failed."); return instructions; } } [HarmonyTranspiler] [HarmonyPriority(200)] [HarmonyPatch(typeof(GameLogic), "_power_gen_gamma_parallel")] private static IEnumerable<CodeInstruction> _power_gen_gamma_parallel_Transpiler(IEnumerable<CodeInstruction> instructions) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Expected O, but got Unknown //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Expected O, but got Unknown //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Expected O, but got Unknown //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Expected O, but got Unknown //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Expected O, but got Unknown //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Expected O, but got Unknown //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Expected O, but got Unknown //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Expected O, but got Unknown //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Expected O, but got Unknown //IL_0151: Unknown result type (might be due to invalid IL or missing references) //IL_0157: Expected O, but got Unknown try { CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null); val.MatchForward(true, (CodeMatch[])(object)new CodeMatch[5] { new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null), new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Ldfld && ((FieldInfo)i.operand).Name == "factories"), (string)null), new CodeMatch((OpCode?)OpCodes.Ldloc_S, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldelem_Ref, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Stloc_S, (object)null, (string)null) }); CodeInstruction val2 = new CodeInstruction(OpCodes.Ldloc_S, val.Operand); val.End().MatchBack(true, (CodeMatch[])(object)new CodeMatch[3] { new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Ldflda && ((FieldInfo)i.operand).Name == "energyReqCurrentTick"), (string)null), new CodeMatch((OpCode?)OpCodes.Ldloc_S, (object)null, (string)null), new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Call && ((MethodInfo)i.operand).Name == "Add"), (string)null) }); CodeInstruction val3 = val.InstructionAt(-1); val.Advance(2).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[3] { val2, val3, new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(Dyson_Patch), "AddEnergyReqCurrentTick", (Type[])null, (Type[])null)) }); return val.InstructionEnumeration(); } catch { Log.Warn("Transpiler GameLogic._power_gen_gamma_parallel Transpiler failed."); return instructions; } } [HarmonyTranspiler] [HarmonyPatch(typeof(SiloComponent), "InternalUpdate")] private static IEnumerable<CodeInstruction> SiloComponent_Transpiler(IEnumerable<CodeInstruction> instructions) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Expected O, but got Unknown //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Expected O, but got Unknown //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Expected O, but got Unknown //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Expected O, but got Unknown //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Expected O, but got Unknown try { CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1] { new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.Method(typeof(DysonSphere), "AddDysonRocket", (Type[])null, (Type[])null), (string)null) }); CodeInstruction val2 = val.InstructionAt(-1); val.Advance(2).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[6] { new CodeInstruction(OpCodes.Ldarg_0, (object)null), new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(SiloComponent), "planetId")), new CodeInstruction(OpCodes.Ldarg_0, (object)null), new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(SiloComponent), "localPos")), val2, Transpilers.EmitDelegate<Action<int, Vector3, DysonNode>>((Action<int, Vector3, DysonNode>)delegate(int planetId, Vector3 localPos, DysonNode autoDysonNode) { if (MainManager.Planets.TryGetValue(planetId, out var value) && value.IsNextIdle) { value.AddDysonData(planetId, (autoDysonNode.layerId << 12) | (autoDysonNode.id & 0xFFF), in localPos); } }) }); return val.InstructionEnumeration(); } catch { Log.Warn("SiloComponent.InternalUpdate Transpiler failed."); return instructions; } } public static void AddBullet(DysonSwarm swarm, in ProjectileData projectile) { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0073: 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_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008d: 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_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: 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_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_0171: Unknown result type (might be due to invalid IL or missing references) //IL_0177: Unknown result type (might be due to invalid IL or missing references) ref AstroData[] astrosData = ref GameMain.data.galaxy.astrosData; int num = -projectile.TargetId; if (swarm.OrbitExist(num)) { VectorLF3 uPos = astrosData[projectile.PlanetId / 100 * 100].uPos; SailBullet val = default(SailBullet); val.lBegin = projectile.LocalPos; val.uBegin = astrosData[projectile.PlanetId].uPos + Maths.QRotateLF(astrosData[projectile.PlanetId].uRot, VectorLF3.op_Implicit(projectile.LocalPos)); VectorLF3 val2 = VectorLF3.Cross(VectorLF3.op_Implicit(swarm.orbits[num].up), uPos - val.uBegin); val.uEnd = uPos + ((VectorLF3)(ref val2)).normalized * (double)swarm.orbits[num].radius; val2 = val.uEnd - val.uBegin; val.maxt = (float)(((VectorLF3)(ref val2)).magnitude / 4000.0); val2 = VectorLF3.Cross(val.uEnd - uPos, VectorLF3.op_Implicit(swarm.orbits[num].up)); val.uEndVel = VectorLF3.op_Implicit(((VectorLF3)(ref val2)).normalized * Math.Sqrt(swarm.dysonSphere.gravity / swarm.orbits[num].radius)); swarm.AddBullet(val, num); } } public static void AddRocket(DysonSphere sphere, in ProjectileData projectile, int idleCount) { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_006c: 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_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_009f: 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_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: 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_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Unknown result type (might be due to invalid IL or missing references) //IL_0143: Unknown result type (might be due to invalid IL or missing references) //IL_0151: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_0162: Unknown result type (might be due to invalid IL or missing references) //IL_0178: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Unknown result type (might be due to invalid IL or missing references) ref AstroData[] astrosData = ref GameMain.data.galaxy.astrosData; int num = projectile.TargetId >> 12; int num2 = projectile.TargetId & 0xFFF; DysonNode val = sphere.FindNode(num, num2); if (val != null) { DysonRocket val2 = default(DysonRocket); val2.planetId = projectile.PlanetId; VectorLF3 uPos = astrosData[projectile.PlanetId].uPos; Quaternion uRot = astrosData[projectile.PlanetId].uRot; Vector3 localPos = projectile.LocalPos; Vector3 localPos2 = projectile.LocalPos; val2.uPos = uPos + Maths.QRotateLF(uRot, VectorLF3.op_Implicit(localPos + ((Vector3)(ref localPos2)).normalized * 6.1f)); val2.uRot = astrosData[projectile.PlanetId].uRot * Maths.SphericalRotation(projectile.LocalPos, 0f) * Quaternion.Euler(-90f, 0f, 0f); val2.uVel = val2.uRot * Vector3.forward; val2.uSpeed = 0f; localPos2 = projectile.LocalPos; val2.launch = ((Vector3)(ref localPos2)).normalized; ref VectorLF3 uPos2 = ref val2.uPos; uPos2 -= new VectorLF3(VectorLF3.op_Implicit(val2.uVel)) * 15.0 * (double)idleCount; if (val._spReq - val.spOrdered > 0) { sphere.AddDysonRocket(val2, val); } else if (sphere.GetAutoNodeCount() > 0 && (val = sphere.GetAutoDysonNode(num2)) != null) { sphere.AddDysonRocket(val2, val); } } } } public class Fix_Patch { [HarmonyPrefix] [HarmonyPatch(typeof(ScatterTaskContext), "ResetFrame", new Type[] { typeof(int), typeof(int) })] [HarmonyPatch(typeof(ScatterTaskContext), "ResetFrame", new Type[] { typeof(long), typeof(int), typeof(int) })] public static void ResetFrame_Prefix(ref int _batchCount) { if (_batchCount == 0) { _batchCount = 1; } } [HarmonyPrefix] [HarmonyPriority(600)] [HarmonyPatch(typeof(PowerExchangerComponent), "CalculateActualEnergyPerTick")] public static bool CalculateActualEnergyPerTick_Overwrite(ref PowerExchangerComponent __instance, bool isOutput, ref long __result) { int num; if (isOutput) { num = __instance.poolInc; } else { int emptyCount = __instance.emptyCount; int emptyInc = __instance.emptyInc; num = ((PowerExchangerComponent)(ref __instance)).split_inc(ref emptyCount, ref emptyInc, 1); } if (num > 0) { if (num >= Cargo.accTableMilli.Length) { num = Cargo.accTableMilli.Length - 1; } __result = __instance.energyPerTick + (long)((double)__instance.energyPerTick * Cargo.accTableMilli[num] + 0.1); return false; } __result = __instance.energyPerTick; return false; } [HarmonyTranspiler] [HarmonyPatch(typeof(GameLogic), "_spraycoater_parallel")] public static IEnumerable<CodeInstruction> _spraycoater_parallel_Transpiler(IEnumerable<CodeInstruction> instructions) { //IL_0002: 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_0036: Expected O, but got Unknown //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Expected O, but got Unknown //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Expected O, but got Unknown //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Expected O, but got Unknown //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Expected O, but got Unknown //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Expected O, but got Unknown //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Expected O, but got Unknown //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Expected O, but got Unknown try { CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[4] { new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.IsLdloc(ci, (LocalBuilder)null)), (string)null), new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.IsLdloc(ci, (LocalBuilder)null)), (string)null), new CodeMatch((OpCode?)OpCodes.Ldelem_Ref, (object)null, (string)null), new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => ci.opcode == OpCodes.Ldfld && ((FieldInfo)ci.operand).Name == "consumeRegister"), (string)null) }); if (val.IsValid) { val.Advance(1); CodeInstruction instruction = val.Instruction; val.RemoveInstruction().Insert((CodeInstruction[])(object)new CodeInstruction[5] { new CodeInstruction(OpCodes.Ldarg_0, (object)null), new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(GameLogic), "factories")), instruction, new CodeInstruction(OpCodes.Ldelem_Ref, (object)null), new CodeInstruction(OpCodes.Callvirt, (object)AccessTools.PropertyGetter(typeof(PlanetFactory), "index")) }); } else { Log.Warn("Transpiler GameLogic._spraycoater_parallel fail. Can't find the target"); } return val.InstructionEnumeration(); } catch (Exception obj) { Log.Warn("Transpiler GameLogic._spraycoater_parallel error:"); Log.Warn(obj); return instructions; } } [HarmonyPrefix] [HarmonyPriority(200)] [HarmonyPatch(typeof(GameLogic), "ContextCollect_FactoryComponents_MultiMain")] private static void ContextCollect_FactoryComponents_MultiMain_Prefix(GameLogic __instance, ref PlanetFactory __state) { if (__instance.factoryCount != GameMain.data.factoryCount) { __state = __instance.localLoadedFactory; __instance.localLoadedFactory = null; } } [HarmonyPostfix] [HarmonyPatch(typeof(GameLogic), "ContextCollect_FactoryComponents_MultiMain")] private static void ContextCollect_FactoryComponents_MultiMain_Postfix(GameLogic __instance, int threadCount, PlanetFactory __state) { if (__state == null) { return; } __instance.localLoadedFactory = __state; DeepProfiler.BeginSample((DPEntry)33, -1, 0L); ScatterTaskContext presentCargo = __instance.threadController.gameThreadContext.presentCargo; int[] ordinals = presentCargo.ordinals; presentCargo.ResetFrame(__instance.factoryCount, threadCount); int num = -1; for (int i = 0; i < __instance.factoryCount; i++) { if (__instance.factories[i] == __instance.localLoadedFactory) { num = i; break; } } if (num != -1) { int num2 = __instance.localLoadedFactory.cargoTraffic.pathCursor - 1; for (int j = num + 1; j <= __instance.factoryCount; j++) { ordinals[j] = num2; } } presentCargo.DetermineThreadTasks(); DeepProfiler.EndSample(-1, -2L); } public static void FixMinerProductCount() { int factoryCount = GameMain.data.factoryCount; for (int i = 0; i < factoryCount; i++) { PlanetFactory val = GameMain.data.factories[i]; if (val == null) { continue; } FactorySystem factorySystem = val.factorySystem; for (int j = 0; j < factorySystem.minerCursor; j++) { ref MinerComponent reference = ref factorySystem.minerPool[j]; if (reference.productCount < 0) { reference.productCount = 0; } else if (reference.productCount > 50) { reference.productCount = 50; } } } } } public class GameLogic_Patch { private static PlanetFactory[] idleFactories; private static PlanetFactory[] workFactories; private static long[] workFactoryTimes; private static int idleFactoryCount; private static int workFactoryCount; [HarmonyPrefix] [HarmonyPatch(typeof(GameMain), "Begin")] public static void GameMain_Begin() { if (GameMain.data != null) { int num = GameMain.data.factories.Length; workFactories = (PlanetFactory[])(object)new PlanetFactory[num]; idleFactories = (PlanetFactory[])(object)new PlanetFactory[num]; workFactoryTimes = new long[num]; MainManager.Init(); UIstation.SetVeiwStation(-1, -1, 0); ManagerLogic.OnGameStart(); Fix_Patch.FixMinerProductCount(); } } [HarmonyPrefix] [HarmonyPatch(typeof(GameMain), "End")] public static void GameMain_End() { Plugin.instance.SaveConfig(MainManager.UpdatePeriod, MainManager.FocusLocalFactory); } [HarmonyPrefix] [HarmonyPatch(typeof(ThreadManager), "ProcessFrame")] private static void BeforeLogicFrameBegin() { workFactoryCount = MainManager.SetFactories(workFactories, idleFactories, workFactoryTimes); idleFactoryCount = GameMain.data.factoryCount - workFactoryCount; } [HarmonyPrefix] [HarmonyPatch(typeof(GameLogic), "RefreshFactoryArray")] private static bool RefreshFactoryArray_Prefix(GameLogic __instance) { if (MainManager.UpdatePeriod <= 1) { return true; } __instance.factories = workFactories; __instance.factoryCount = workFactoryCount; return false; } [HarmonyPostfix] [HarmonyPatch(typeof(GameLogic), "UniverseGameTick")] [HarmonyPatch(typeof(GameLogic), "PlayerGameTick")] private static void ResetLocalLoadFactory(GameLogic __instance) { bool flag = false; for (int i = 0; i < workFactoryCount; i++) { if (workFactories[i] == __instance.localLoadedFactory) { flag = true; break; } } if (!flag) { __instance.localLoadedFactory = null; } } [HarmonyPrefix] [HarmonyPatch(typeof(GameLogic), "OnFactoryFrameBegin")] private static void OnFactoryBegin(GameLogic __instance) { int updatePeriod = MainManager.UpdatePeriod; __instance.timef = __instance.main.timef / (double)updatePeriod; __instance.timei = __instance.main.timei / updatePeriod; __instance.timef_once = __instance.main.timef_once / (double)updatePeriod; __instance.timei_once = __instance.main.timei_once / updatePeriod; ManagerLogic.OnFactoryFrameBegin(); } public static IEnumerable<CodeInstruction> ReplaceFactories(IEnumerable<CodeInstruction> instructions) { //IL_0002: 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_0036: Expected O, but got Unknown //IL_0066: 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_009a: Expected O, but got Unknown return new CodeMatcher(new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1] { new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Ldfld && ((FieldInfo)i.operand).Name == "factories"), (string)null) }).Repeat((Action<CodeMatcher>)delegate(CodeMatcher matcher) { matcher.SetAndAdvance(OpCodes.Ldsfld, (object)AccessTools.Field(typeof(GameLogic_Patch), "workFactories")).Advance(-2).SetAndAdvance(OpCodes.Nop, (object)null); }, (Action<string>)null).InstructionEnumeration(), (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1] { new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Ldfld && ((FieldInfo)i.operand).Name == "factoryCount"), (string)null) }).Repeat((Action<CodeMatcher>)delegate(CodeMatcher matcher) { //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Expected O, but got Unknown //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Expected O, but got Unknown matcher.SetAndAdvance(OpCodes.Ldsfld, (object)AccessTools.Field(typeof(GameLogic_Patch), "workFactoryCount")).Advance(-2).SetAndAdvance(OpCodes.Nop, (object)null); if (matcher.InstructionAt(1).opcode == OpCodes.Blt) { matcher.Advance(-6); CodeInstruction instruction = matcher.Instruction; while (matcher.Opcode != OpCodes.Br) { if (matcher.Opcode == OpCodes.Ldarg_1) { matcher.RemoveInstruction().Insert((CodeInstruction[])(object)new CodeInstruction[3] { new CodeInstruction(OpCodes.Ldsfld, (object)AccessTools.Field(typeof(GameLogic_Patch), "workFactoryTimes")), instruction, new CodeInstruction(OpCodes.Ldelem_I8, (object)null) }); matcher.Advance(-2); } matcher.Advance(-1); } } }, (Action<string>)null).InstructionEnumeration(); } } public class GameTick_Patch { public static long GetGameTick(FactorySystem factorySystem) { int num = ((factorySystem.factory.planetId == MainManager.FocusPlanetId) ? 1 : MainManager.UpdatePeriod); return GameMain.gameTick / num; } [HarmonyPrefix] [HarmonyPriority(700)] [HarmonyPatch(typeof(TrashSystem), "GameTick")] [HarmonyPatch(typeof(DysonSwarm), "GameTick")] [HarmonyPatch(typeof(DysonSwarm), "BulletGameTick")] private static void Time_Correct(ref long time) { time = GameMain.gameTick; } [HarmonyPrefix] [HarmonyPriority(700)] [HarmonyPatch(typeof(DysonSphere), "GameTick")] private static void GameTick_Correct(ref long gameTick) { gameTick = GameMain.gameTick; } [HarmonyPrefix] [HarmonyPriority(600)] [HarmonyPatch(typeof(TrashSystem), "AddTrashFromGroundEnemy")] public static void AddTrashFromGroundEnemy_Prefix(PlanetFactory factory, ref int life) { if (factory.planetId != MainManager.FocusPlanetId) { life *= MainManager.UpdatePeriod; } } [HarmonyPrefix] [HarmonyPriority(600)] [HarmonyPatch(typeof(FactorySystem), "GameTick")] private static void FactorySystemGameTick_Prefix(FactorySystem __instance, ref long time) { time = GetGameTick(__instance); } [HarmonyTranspiler] [HarmonyPatch(typeof(FactorySystem), "GameTickLabOutputToNext")] private static IEnumerable<CodeInstruction> GameTickLabOutput_Transpiler(IEnumerable<CodeInstruction> instructions) { //IL_0002: 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_0036: Expected O, but got Unknown //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Expected O, but got Unknown //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Expected O, but got Unknown try { CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1] { new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Call && ((MethodInfo)i.operand).Name == "get_gameTick"), (string)null) }); if (val.IsInvalid) { Log.Warn("GameTickLabOutput_Transpiler: Can't find get_gameTick!"); return instructions; } val.Set(OpCodes.Nop, (object)null).Advance(1).Insert((CodeInstruction[])(object)new CodeInstruction[2] { new CodeInstruction(OpCodes.Ldarg_0, (object)null), new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(GameTick_Patch), "GetGameTick", (Type[])null, (Type[])null)) }); return val.InstructionEnumeration(); } catch { Log.Error("Transpiler FactorySystem.GameTickLabOutputToNext failed."); return instructions; } } [HarmonyPrefix] [HarmonyPatch(typeof(PowerSystem), "GameTick")] private static void PowerSystem_Gametick(PowerSystem __instance, ref long time) { if (MainManager.TryGet(__instance.factory.index, out var factoryData) && factoryData.IsNextIdle) { time /= MainManager.UpdatePeriod; } } } public class KillStatLogic2 { [HarmonyPrefix] [HarmonyPatch(typeof(KillStatistics), "PrepareTick")] [HarmonyPatch(typeof(KillStatistics), "PrepareTick_Parallel")] private static bool KillStatistics_PrepareTick() { int updatePeriod = MainManager.UpdatePeriod; if (updatePeriod <= 1) { return true; } return GameMain.gameTick % updatePeriod == 1; } [HarmonyPrefix] [HarmonyPatch(typeof(KillStatistics), "GameTick")] private static bool KillStatistics_GameTick(KillStatistics __instance) { int updatePeriod = MainManager.UpdatePeriod; if (updatePeriod <= 1) { return true; } if (GameMain.gameTick % updatePeriod != 0L) { return false; } long gameTick = GameMain.gameTick; long num = gameTick - updatePeriod; if (num < 0) { num = 0L; } for (int i = 0; i < __instance.starKillStatPool.Length; i++) { if (__instance.starKillStatPool[i] != null) { for (long num2 = num; num2 <= gameTick; num2++) { __instance.starKillStatPool[i].GameTick(num2); } } } for (int j = 0; j < __instance.factoryKillStatPool.Length; j++) { if (__instance.factoryKillStatPool[j] != null) { for (long num3 = num; num3 <= gameTick; num3++) { __instance.factoryKillStatPool[j].GameTick(num3); } } } if (__instance.mechaKillStat != null) { for (long num4 = num; num4 <= gameTick; num4++) { __instance.mechaKillStat.GameTick(num4); } } return false; } [HarmonyPrefix] [HarmonyPatch(typeof(KillStatistics), "GameTick_Parallel")] private static bool KillStatistics_GameTick_Parallel(KillStatistics __instance, int threadOrdinal, int threadCount) { int updatePeriod = MainManager.UpdatePeriod; if (updatePeriod <= 1) { return true; } if (GameMain.gameTick % updatePeriod != 0L) { return false; } long gameTick = GameMain.gameTick; long num = gameTick - updatePeriod; if (num < 0) { num = 0L; } for (int i = threadOrdinal; i < __instance.starKillStatPool.Length; i += threadCount) { if (__instance.starKillStatPool[i] != null) { for (long num2 = num; num2 <= gameTick; num2++) { __instance.starKillStatPool[i].GameTick(num2); } } } for (int j = threadOrdinal; j < __instance.factoryKillStatPool.Length; j += threadCount) { if (__instance.factoryKillStatPool[j] != null) { for (long num3 = num; num3 <= gameTick; num3++) { __instance.factoryKillStatPool[j].GameTick(num3); } } } if (threadOrdinal == 0 && __instance.mechaKillStat != null) { for (long num4 = num; num4 <= gameTick; num4++) { __instance.mechaKillStat.GameTick(num4); } } return false; } } public static class MainManager { public static int UpdatePeriod { get; set; } = 1; public static bool FocusLocalFactory { get; set; } = true; public static int StationStoreLowerbound { get; private set; } = -64; public static List<FactoryManager> Factories { get; } = new List<FactoryManager>(); public static Dictionary<int, FactoryManager> Planets { get; } = new Dictionary<int, FactoryManager>(); public static int FocusStarIndex { get; set; } = -1; public static int FocusPlanetId { get; private set; } = -1; public static int FocusFactoryIndex { get; private set; } = -1; public static void Init() { Factories.Clear(); Planets.Clear(); StationStoreLowerbound = UpdatePeriod * -64; Log.Debug("UpdatePeriod = " + UpdatePeriod + ", FocusLocalFactory = " + FocusLocalFactory + ", StoreLowerbound = " + StationStoreLowerbound); } public static int SetFactories(PlanetFactory[] workFactories, PlanetFactory[] idleFactories, long[] workFactoryTimes) { for (int i = Factories.Count; i < GameMain.data.factoryCount; i++) { FactoryManager factoryManager = new FactoryManager(i, GameMain.data.factories[i]); Factories.Add(factoryManager); Planets.Add(GameMain.data.factories[i].planetId, factoryManager); } int num = 0; int num2 = 0; int num3 = (int)GameMain.gameTick; PlanetFactory[] factories = GameMain.data.factories; PlanetData localPlanet = GameMain.localPlanet; int? obj; if (localPlanet == null) { obj = null; } else { PlanetFactory factory = localPlanet.factory; obj = ((factory != null) ? new int?(factory.index) : null); } int num4 = obj ?? (-1); for (int j = 0; j < GameMain.data.factoryCount; j++) { if (Factories[j].factory != factories[j]) { Factories[j].factory = factories[j]; } if (FocusLocalFactory && j == num4) { workFactories[num] = factories[j]; workFactoryTimes[num] = num3; num++; Factories[j].IsActive = true; Factories[j].IsNextIdle = false; } else if ((j + num3) % UpdatePeriod == 0) { workFactories[num] = factories[j]; workFactoryTimes[num] = num3 / UpdatePeriod; num++; Factories[j].IsActive = true; Factories[j].IsNextIdle = UpdatePeriod > 1; } else { idleFactories[num2++] = factories[j]; Factories[j].IsActive = false; Factories[j].IsNextIdle = false; } } FocusFactoryIndex = ((FocusLocalFactory && UpdatePeriod > 1) ? num4 : (-1)); FocusPlanetId = ((FocusLocalFactory && UpdatePeriod > 1 && GameMain.localPlanet != null) ? GameMain.localPlanet.id : (-1)); FocusStarIndex = ((FocusLocalFactory && UpdatePeriod > 1 && GameMain.localStar != null) ? GameMain.localStar.index : (-1)); return num; } public static bool TryGet(int index, out FactoryManager factoryData) { factoryData = null; if (0 <= index && index < Factories.Count) { factoryData = Factories[index]; return true; } return false; } } public class ManagerLogic { private static long totalHashByIdle; public static void OnGameStart() { totalHashByIdle = 0L; } public static void OnFactoryFrameBegin() { GameMain.data.history.AddTechHash(totalHashByIdle); totalHashByIdle = 0L; GameLogic logic = GameMain.logic; for (int i = 0; i < logic.factoryCount; i++) { if (MainManager.TryGet(logic.factories[i].index, out var factoryData) && factoryData.IsActive) { factoryData.StationBeforeTick(); factoryData.DysonBeforeTick(); } } } [HarmonyPrefix] [HarmonyPatch(typeof(ProductionStatistics), "PrepareTick")] private static bool PrepareTick_Prefix(ProductionStatistics __instance) { for (int i = 0; i < __instance.gameData.factoryCount; i++) { PrepareTick(i); } return false; } [HarmonyPrefix] [HarmonyPatch(typeof(ProductionStatistics), "PrepareTick_Parallel")] private static bool PrepareTick_Parallel_Prefix(ProductionStatistics __instance, int threadOrdinal, int threadCount) { int num = default(int); int num2 = default(int); if (ParallelUtils.CalculateWorkSegment(threadOrdinal, threadCount, __instance.gameData.factoryCount, 0, ref num, ref num2)) { for (int i = num; i < num2; i++) { PrepareTick(i); } } return false; } [HarmonyTranspiler] [HarmonyPatch(typeof(ProductionStatistics), "GameTick")] [HarmonyPatch(typeof(ProductionStatistics), "GameTick_Parallel")] private static IEnumerable<CodeInstruction> GameTick_Transpiler(IEnumerable<CodeInstruction> instructions) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Expected O, but got Unknown //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Expected O, but got Unknown try { return new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1] { new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.Method(typeof(FactoryProductionStat), "GameTick", (Type[])null, (Type[])null), (string)null) }).Advance(-2).RemoveInstructions(3) .Insert((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(ManagerLogic), "GameTick", (Type[])null, (Type[])null)) }) .InstructionEnumeration(); } catch { Log.Error("Transpiler ProductionStatistics.GameTick failed."); return instructions; } } private static void PrepareTick(int index) { //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Invalid comparison between Unknown and I4 FactoryProductionStat val = GameMain.data.statistics.production.factoryStatPool[index]; if (val != null) { MainManager.TryGet(index, out var factoryData); if (factoryData == null || factoryData.IsActive || (int)GameMain.data.factories[index].planet.type == 5) { val.PrepareTick(); return; } val.itemChanged = false; val.consumeRegister[1210] = 0; val.consumeRegister[11901] = 0; val.productRegister[11901] = 0; val.productRegister[11902] = 0; val.productRegister[11903] = 0; } } private static void GameTick(FactoryProductionStat[] factoryStatPool, int index) { factoryStatPool[index].GameTick(GameMain.gameTick); if (MainManager.TryGet(index, out var factoryData)) { factoryData.StationAfterTick(); if (factoryData.IsActive) { factoryData.DysonColletEnd(); return; } Lab_IdleTick(index); factoryData.DysonIdleTick(); } } private static void Lab_IdleTick(int index) { long hashRegister = GameMain.data.statistics.production.factoryStatPool[index].hashRegister; if (hashRegister > 0 && GameMain.data.history.currentTech > 0) { Interlocked.Add(ref totalHashByIdle, hashRegister); } } } public class Station_Patch { [HarmonyPrefix] [HarmonyPatch(typeof(StationComponent), "UpdateVeinCollection")] private static void UpdateVeinCollection_Prefix(StationComponent __instance, ref int __state) { __state = __instance.storage[0].count; } [HarmonyPostfix] [HarmonyPatch(typeof(StationComponent), "UpdateVeinCollection")] private static void UpdateVeinCollection_Postfix(StationComponent __instance, int __state, PlanetFactory factory) { if (MainManager.TryGet(factory.index, out var factoryData) && factoryData.IsActive) { factoryData.SetMineral(__instance, __instance.storage[0].count - __state); ref MinerComponent reference = ref factory.factorySystem.minerPool[__instance.minerId]; if (reference.productCount < 0) { reference.productCount = 0; } } } [HarmonyPrefix] [HarmonyPriority(600)] [HarmonyPatch(typeof(DispenserComponent), "InternalTick")] private static bool StopIdle(PlanetFactory factory) { if (MainManager.TryGet(factory.index, out var factoryData)) { return factoryData.IsActive; } return true; } [HarmonyPrefix] [HarmonyPatch(typeof(GameLogic), "FactoryTransportGameTick")] private static bool FactoryTransportGameTick_Postfix(GameLogic __instance) { DeepProfiler.BeginSample((DPEntry)36, -1, -1L); for (int i = 0; i < GameMain.data.factoryCount; i++) { PlanetFactory val = GameMain.data.factories[i]; bool flag = __instance.localLoadedFactory == val; val.transport.GameTick(GameMain.gameTick, flag, false, -1); } DeepProfiler.EndSample(-1, -2L); return false; } [HarmonyPrefix] [HarmonyPatch(typeof(GameLogic), "FactoryTransportGameTick_Parallel")] private static bool FactoryTransportGameTick_Parallel(GameLogic __instance, int threadOrdinal) { BatchTaskContext planetTransport = __instance.threadController.gameThreadContext.planetTransport; bool flag; do { DeepProfiler.BeginSample((DPEntry)82, threadOrdinal, -1L); flag = false; int num = -1; int num2 = Interlocked.Increment(ref planetTransport.batchCursor) - 1; if (num2 < GameMain.data.factoryCount) { num = num2; flag = true; } DeepProfiler.EndSample(threadOrdinal, -2L); if (flag) { num = planetTransport.batchIndices[num]; PlanetFactory val = GameMain.data.factories[num]; bool flag2 = __instance.localLoadedFactory == val; DeepProfiler.BeginSample((DPEntry)36, threadOrdinal, (long)val.planetId); val.transport.GameTick(GameMain.gameTick, flag2, true, threadOrdinal); DeepProfiler.EndSample(threadOrdinal, -2L); } } while (flag); return false; } } public class StationData { public int[] deltaCount; public int[] deltaInc; public int deltaWarperCount; private int[] tmpCount; private int[] tmpInc; private int tmpWarperCount; private int tmpMineralCount; public StationData(StationComponent station) { StationStore[] storage = station.storage; SetArray((storage != null) ? storage.Length : 0); } private void SetArray(int length) { deltaCount = new int[length]; deltaInc = new int[length]; tmpCount = new int[length]; tmpInc = new int[length]; deltaWarperCount = 0; tmpWarperCount = 0; tmpMineralCount = 0; } public static void SetMineral(StationData data, int mineralCount) { data.tmpMineralCount = mineralCount; } public static void ActiveBegin(StationData data, StationComponent station) { StationStore[] storage = station.storage; int num = ((storage != null) ? storage.Length : 0); if (num != data.tmpCount.Length) { data.SetArray(num); } for (int i = 0; i < num; i++) { data.tmpCount[i] = station.storage[i].count; data.tmpInc[i] = station.storage[i].inc; data.deltaCount[i] = 0; data.deltaInc[i] = 0; } data.tmpWarperCount = station.warperCount; data.deltaWarperCount = 0; } public static void ActiveBeforeTransport(StationData data, StationComponent station) { StationStore[] storage = station.storage; int num = ((storage != null) ? storage.Length : 0); if (num != data.tmpCount.Length) { data.SetArray(num); return; } for (int i = 0; i < num; i++) { data.deltaCount[i] += station.storage[i].count - data.tmpCount[i]; data.deltaInc[i] += station.storage[i].inc - data.tmpInc[i]; } data.deltaWarperCount += station.warperCount - data.tmpWarperCount; } public static void ActiveAfterTransport(StationData data, StationComponent station) { StationStore[] storage = station.storage; int num = ((storage != null) ? storage.Length : 0); if (num != data.tmpCount.Length) { data.SetArray(num); } for (int i = 0; i < num; i++) { data.tmpCount[i] = station.storage[i].count; data.tmpInc[i] = station.storage[i].inc; } data.tmpWarperCount = station.warperCount; } public static void ActiveEnd(StationData data, StationComponent station) { StationStore[] storage = station.storage; int num = ((storage != null) ? storage.Length : 0); if (num != data.tmpCount.Length) { data.SetArray(num); return; } for (int i = 0; i < num; i++) { data.deltaCount[i] += station.storage[i].count - data.tmpCount[i]; data.deltaInc[i] += station.storage[i].inc - data.tmpInc[i]; if (data.deltaCount[i] > 64) { data.deltaCount[i] = 64; } else if (data.deltaCount[i] < -64) { data.deltaCount[i] = -64; } } data.deltaWarperCount += station.warperCount - data.tmpWarperCount; if (data.deltaWarperCount > 64) { data.deltaWarperCount = 64; } else if (data.deltaWarperCount < -64) { data.deltaWarperCount = -64; } } public static void IdleEnd(StationData data, StationComponent station) { StationStore[] storage = station.storage; int num = ((storage != null) ? storage.Length : 0); if (num != data.tmpCount.Length) { data.SetArray(num); } for (int i = 0; i < num; i++) { station.storage[i].count += data.deltaCount[i]; station.storage[i].inc += data.deltaInc[i]; if (station.storage[i].count < MainManager.StationStoreLowerbound) { station.storage[i].count = MainManager.StationStoreLowerbound; } } if (station.isVeinCollector && data.tmpMineralCount > 0) { station.storage[0].count += data.tmpMineralCount; } else { station.warperCount += data.deltaWarperCount; } } } public static class ThreadManager_Patch { private static EGameLogicTask currentTask; public static void OnTaskBegin(int taskNum) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Invalid comparison between Unknown and I4 //IL_001f: Unknown result type (might be due to invalid IL or missing references) try { currentTask = (EGameLogicTask)taskNum; if ((int)currentTask == 1700) { BeforeTransport(); } } catch (Exception ex) { Debug.LogError((object)($"[SampleAndHoldSim] Error on task begin {currentTask}: \n" + ex.ToString())); } } public static void OnPhaseEnd() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Invalid comparison between Unknown and I4 //IL_0019: Unknown result type (might be due to invalid IL or missing references) try { if ((int)currentTask == 1800) { AfterTransport(); } } catch (Exception ex) { Debug.LogError((object)($"[SampleAndHoldSim] Error on phase end {currentTask}: \n" + ex.ToString())); } } private static void BeforeTransport() { GameLogic logic = GameMain.logic; for (int i = 0; i < logic.factoryCount; i++) { if (MainManager.TryGet(logic.factories[i].index, out var factoryData) && factoryData.IsActive) { factoryData.StationBeforeTransport(); } } if (logic.factoryCount != GameMain.data.factoryCount) { int enabledWorkerThreadCount = logic.threadController.threadManager.enabledWorkerThreadCount; BatchTaskContext planetTransport = logic.threadController.gameThreadContext.planetTransport; planetTransport.ResetFrame(logic.factoryCount, enabledWorkerThreadCount); for (int j = 0; j < GameMain.data.factoryCount; j++) { PlanetFactory val = GameMain.data.factories[j]; planetTransport.batchValues[j] = val.transport.workerThreadWeight; } planetTransport.SortValues(); } } private static void AfterTransport() { GameLogic logic = GameMain.logic; for (int i = 0; i < logic.factoryCount; i++) { if (MainManager.TryGet(logic.factories[i].index, out var factoryData) && factoryData.IsActive) { factoryData.StationAfterTransport(); } } } private static void Test() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Invalid comparison between Unknown and I4 //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Invalid comparison between Unknown and I4 //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Invalid comparison between Unknown and I4 //IL_0024: Unknown result type (might be due to invalid IL or missing references) if ((int)currentTask != 1751 && (int)currentTask != 1800 && (int)currentTask != 1700) { Log.Warn(currentTask); } } [HarmonyTranspiler] [HarmonyPatch(typeof(ThreadManager), "ProcessFrame")] private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator il) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Expected O, but got Unknown //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Expected O, but got Unknown //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Expected O, but got Unknown //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Expected O, but got Unknown //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Expected O, but got Unknown //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Expected O, but got Unknown //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Expected O, but got Unknown //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Expected O, but got Unknown //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Expected O, but got Unknown //IL_0193: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Expected O, but got Unknown CodeMatcher val = new CodeMatcher(instructions, il); val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[3] { new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(ThreadManager), "OnTaskLogic"), (string)null), new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => CodeInstructionExtensions.IsLdloc(i, (LocalBuilder)null)), (string)null) }); if (val.IsValid) { CodeInstruction val2 = val.InstructionAt(2); val.Insert((CodeInstruction[])(object)new CodeInstruction[2] { new CodeInstruction(val2.opcode, val2.operand), new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(ThreadManager_Patch), "OnTaskBegin", (Type[])null, (Type[])null)) }); } else { Log.Error("Transpiler ThreadManager.ProcessFrame Error: Could not find injection point for OnTaskBegin"); } val.MatchForward(true, (CodeMatch[])(object)new CodeMatch[4] { new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.DeclaredPropertyGetter(typeof(ThreadManager), "phaseBarrier"), (string)null), new CodeMatch((OpCode?)OpCodes.Ldc_I4_0, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.Method(typeof(HybridBarrier), "SignalAndWait", (Type[])null, (Type[])null), (string)null) }); if (val.IsValid) { val.Advance(1); val.Insert((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(ThreadManager_Patch), "OnPhaseEnd", (Type[])null, (Type[])null)) }); } else { Log.Error("Transpiler ThreadManager.ProcessFrame Error: Could not find injection point for OnPhaseEnd"); } return val.InstructionEnumeration(); } } public class Compatibility { public static class Weaver { public const string GUID = "Weaver"; public static void Init(Harmony _) { if (Chainloader.PluginInfos.TryGetValue("Weaver", out var _)) { warnMessage += "SampleAndHoldSim is not compatible with Weaver: stats may be incorrect\nSampleAndHoldSim对Weaver尚未兼容,可能会统计数据异常"; } } } public static class CommonAPI { public const string GUID = "dsp.common-api.CommonAPI"; public static void Init(Harmony harmony) { //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Expected O, but got Unknown try { if (Chainloader.PluginInfos.TryGetValue("dsp.common-api.CommonAPI", out var value)) { Type type = ((object)value.Instance).GetType().Assembly.GetType("CommonAPI.Systems.PlanetExtensionSystem"); HarmonyMethod val = new HarmonyMethod(typeof(GameLogic_Patch).GetMethod("ReplaceFactories")); harmony.Patch((MethodBase)type.GetMethod("PowerUpdateOnlySinglethread"), (HarmonyMethod)null, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null); harmony.Patch((MethodBase)type.GetMethod("PreUpdateOnlySinglethread"), (HarmonyMethod)null, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null); harmony.Patch((MethodBase)type.GetMethod("UpdateOnlySinglethread"), (HarmonyMethod)null, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null); harmony.Patch((MethodBase)type.GetMethod("PostUpdateOnlySinglethread"), (HarmonyMethod)null, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null); Log.Debug("CommonAPI compatibility - OK"); } } catch (Exception obj) { string text = "CommonAPI compatibility failed! Last working version: 1.6.7"; Log.Warn(text); Log.Warn(obj); errorMessage = errorMessage + text + "\n"; } } } public static class Auxilaryfunction_Patch { public const string GUID = "cn.blacksnipe.dsp.Auxilaryfunction"; private static bool enable = false; private static int storedUpdatePeriod = 1; public static void Init(Harmony harmony) { //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Expected O, but got Unknown try { if (Chainloader.PluginInfos.TryGetValue("cn.blacksnipe.dsp.Auxilaryfunction", out var value)) { Type type = ((object)value.Instance).GetType().Assembly.GetType("Auxilaryfunction.Patch.GameTickPatch"); harmony.Patch((MethodBase)type.GetMethod("set_Enable"), new HarmonyMethod(typeof(Auxilaryfunction_Patch).GetMethod("OnStopFactory")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); Log.Debug("Auxilaryfunction compatibility - OK"); } } catch (Exception obj) { string text = "Auxilaryfunction compatibility failed! Last working version: 3.0.2"; Log.Warn(text); Log.Warn(obj); errorMessage = errorMessage + text + "\n"; } } public static void OnStopFactory(bool value) { if (enable != value) { enable = value; if (enable) { storedUpdatePeriod = MainManager.UpdatePeriod; MainManager.UpdatePeriod = 1; } else { MainManager.UpdatePeriod = storedUpdatePeriod; storedUpdatePeriod = 1; } Log.Debug($"Auxilaryfunction stop factory:{enable} ratio => {MainManager.UpdatePeriod}"); } } } public static class Multfunction_mod_Patch { public static class Warper { } public const string GUID = "cn.blacksnipe.dsp.Multfuntion_mod"; public static void Init(Harmony harmony) { try { if (Chainloader.PluginInfos.TryGetValue("cn.blacksnipe.dsp.Multfuntion_mod", out var _)) { harmony.PatchAll(typeof(Warper)); warnMessage += "Multifunction: some game-breaking features are not compatible\nSampleAndHoldSim对Multifunction的改机制功能(跳过太阳帆子弹阶段,星球矿机等)兼容性不佳,可能会造成统计数据异常"; } } catch (Exception obj) { string text = "Multfunction_mod compatibility failed! Last working version: 3.4.4"; Log.Warn(text); Log.Warn(obj); errorMessage = errorMessage + text + "\n"; } } } public static class PlanetMiner { public const string GUID = "crecheng.PlanetMiner"; public static void Init(Harmony harmony) { //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Expected O, but got Unknown //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Expected O, but got Unknown //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Expected O, but got Unknown try { if (Chainloader.PluginInfos.TryGetValue("crecheng.PlanetMiner", out var value)) { Assembly assembly = ((object)value.Instance).GetType().Assembly; MethodInfo methodInfo = AccessTools.Method(assembly.GetType("PlanetMiner.PlanetMiner"), "Miner", (Type[])null, (Type[])null); harmony.CreateReversePatcher((MethodBase)methodInfo, new HarmonyMethod(AccessTools.Method(typeof(PlanetMiner), "Miner_Original", (Type[])null, (Type[])null))).Patch((HarmonyReversePatchType)0); harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(AccessTools.Method(typeof(PlanetMiner), "Miner_Transpiler", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null); methodInfo = AccessTools.Method(assembly.GetType("PlanetMiner.PlanetMiner"), "GenerateEnergy", (Type[])null, (Type[])null); harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(AccessTools.Method(typeof(PlanetMiner), "GenerateEnergy_Transpiler", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null); Log.Debug("PlanetMiner compatibility - OK"); } } catch (Exception obj) { string text = "PlanetMiner compatibility failed! Last working version: 3.1.1"; Log.Warn(text); Log.Warn(obj); errorMessage = errorMessage + text + "\n"; } } private static IEnumerable<CodeInstruction> GenerateEnergy_Transpiler(IEnumerable<CodeInstruction> instructions) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Expected O, but got Unknown //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Expected O, but got Unknown //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Expected O, but got Unknown //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Expected O, but got Unknown //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Expected O, but got Unknown try { CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null); val.End().MatchBack(false, (CodeMatch[])(object)new CodeMatch[2] { new CodeMatch((OpCode?)OpCodes.Add, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Stfld, (object)AccessTools.Field(typeof(StationComponent), "energy"), (string)null) }).Insert((CodeInstruction[])(object)new CodeInstruction[3] { new CodeInstruction(OpCodes.Call, (object)AccessTools.DeclaredPropertyGetter(typeof(MainManager), "UpdatePeriod")), new CodeInstruction(OpCodes.Conv_I8, (object)null), new CodeInstruction(OpCodes.Mul, (object)null) }); return val.InstructionEnumeration(); } catch (Exception obj) { Log.Warn("PlanetMiner GenerateEnergy_Transpiler failed."); Log.Warn(obj); return instructions; } } private static IEnumerable<CodeInstruction> Miner_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator iLGenerator) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Expected O, but got Unknown //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Expected O, but got Unknown //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Expected O, but got Unknown //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Expected O, but got Unknown //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Expected O, but got Unknown //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Expected O, but got Unknown //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Expected O, but got Unknown //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Expected O, but got Unknown //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Expected O, but got Unknown //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Expected O, but got Unknown //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Expected O, but got Unknown //IL_0177: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Expected O, but got Unknown //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_018b: Expected O, but got Unknown //IL_01a7: Unknown result type (might be due to invalid IL or missing references) //IL_01ad: Expected O, but got Unknown //IL_01ce: Unknown result type (might be due to invalid IL or missing references) //IL_01d4: Expected O, but got Unknown //IL_01e2: Unknown result type (might be due to invalid IL or missing references) //IL_01e8: Expected O, but got Unknown //IL_01f6: Unknown result type (might be due to invalid IL or missing references) //IL_01fc: Expected O, but got Unknown //IL_020a: Unknown result type (might be due to invalid IL or missing references) //IL_0210: Expected O, but got Unknown //IL_021e: Unknown result type (might be due to invalid IL or missing references) //IL_0224: Expected O, but got Unknown //IL_0232: Unknown result type (might be due to invalid IL or missing references) //IL_0238: Expected O, but got Unknown //IL_0260: Unknown result type (might be due to invalid IL or missing references) //IL_0266: Expected O, but got Unknown //IL_026e: Unknown result type (might be due to invalid IL or missing references) //IL_0274: Expected O, but got Unknown //IL_0290: Unknown result type (might be due to invalid IL or missing references) //IL_0296: Expected O, but got Unknown //IL_02b7: Unknown result type (might be due to invalid IL or missing references) //IL_02bd: Expected O, but got Unknown //IL_02cb: Unknown result type (might be due to invalid IL or missing references) //IL_02d1: Expected O, but got Unknown //IL_02df: Unknown result type (might be due to invalid IL or missing references) //IL_02e5: Expected O, but got Unknown //IL_02f3: Unknown result type (might be due to invalid IL or missing references) //IL_02f9: Expected O, but got Unknown //IL_0307: Unknown result type (might be due to invalid IL or missing references) //IL_030d: Expected O, but got Unknown //IL_0335: Unknown result type (might be due to invalid IL or missing references) //IL_033b: Expected O, but got Unknown //IL_0343: Unknown result type (might be due to invalid IL or missing references) //IL_0349: Expected O, but got Unknown try { CodeMatcher val = new CodeMatcher(instructions, iLGenerator); Label label = default(Label); val.Advance(2).CreateLabel(ref label); val.Insert((CodeInstruction[])(object)new CodeInstruction[8] { new CodeInstruction(OpCodes.Ldarg_0, (object)null), new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(FactorySystem), "planet")), new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(PlanetData), "id")), new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(MainManager), "get_FocusPlanetId", (Type[])null, (Type[])null)), new CodeInstruction(OpCodes.Bne_Un_S, (object)label), new CodeInstruction(OpCodes.Ldarg_0, (object)null), new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(PlanetMiner), "Miner_Original", (Type[])null, (Type[])null)), new CodeInstruction(OpCodes.Ret, (object)null) }); val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1] { new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Ldsfld && ((FieldInfo)i.operand).Name == "frame"), (string)null) }).RemoveInstruction().Insert((CodeInstruction[])(object)new CodeInstruction[4] { new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(GameMain), "get_gameTick", (Type[])null, (Type[])null)), new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(MainManager), "get_UpdatePeriod", (Type[])null, (Type[])null)), new CodeInstruction(OpCodes.Conv_I8, (object)null), new CodeInstruction(OpCodes.Div, (object)null) }); val.MatchForward(true, (CodeMatch[])(object)new CodeMatch[7] { new CodeMatch((OpCode?)OpCodes.Ldelema, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldflda, (object)AccessTools.Field(typeof(StationStore), "count"), (string)null), new CodeMatch((OpCode?)OpCodes.Dup, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldind_I4, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldloc_S, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Conv_I4, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Add, (object)null, (string)null) }).Insert((CodeInstruction[])(object)new CodeInstruction[2] { new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(MainManager), "get_UpdatePeriod", (Type[])null, (Type[])null)), new CodeInstruction(OpCodes.Mul, (object)null) }); val.MatchForward(true, (CodeMatch[])(object)new CodeMatch[6] { new CodeMatch((OpCode?)OpCodes.Ldelema, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldflda, (object)AccessTools.Field(typeof(StationStore), "count"), (string)null), new CodeMatch((OpCode?)OpCodes.Dup, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldind_I4, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldc_I4_S, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Add, (object)null, (string)null) }).Insert((CodeInstruction[])(object)new CodeInstruction[2] { new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(MainManager), "get_UpdatePeriod", (Type[])null, (Type[])null)), new CodeInstruction(OpCodes.Mul, (object)null) }); return val.InstructionEnumeration(); } catch (Exception obj) { Log.Warn("PlanetMiner Miner_Transpiler failed."); Log.Warn(obj); return instructions; } } public static void Miner_Original(FactorySystem _) { } } public static class CheatEnabler_Patch { private static class Warper { public static void Init() { DysonSpherePatch.SkipBulletEnabled.SettingChanged += delegate { OnSettingChanged(); }; } private static void OnSettingChanged() { Log.Debug(DysonSpherePatch.SkipBulletEnabled.Value); } [HarmonyPrefix] [HarmonyPatch(typeof(SkipBulletPatch), "AddDysonSail")] public static bool AddDysonSail_Prefix(ref EjectorComponent ejector, DysonSwarm swarm, VectorLF3 uPos, VectorLF3 endVec, int[] consumeRegister) { //IL_0029: 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_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) int num = ((ejector.planetId == MainManager.FocusPlanetId) ? 1 : MainManager.UpdatePeriod); int index = swarm.starData.index; int orbitId = ejector.orbitId; VectorLF3 val = endVec - swarm.starData.uPosition; VectorLF3 val2 = VectorLF3.Cross(endVec - uPos, VectorLF3.op_Implicit(swarm.orbits[orbitId].up)); VectorLF3 val3 = ((VectorLF3)(ref val2)).normalized * Math.Sqrt(swarm.dysonSphere.gravity / swarm.orbits[orbitId].radius); int bulletCount = ejector.bulletCount; lock (swarm) { DysonSailCache[] array = SkipBulletPatch._sailsCache[index]; int num2 = SkipBulletPatch._sailsCacheLen[index]; if (array == null) { SkipBulletPatch.SetSailsCacheCapacity(index, 256); array = SkipBulletPatch._sailsCache[index]; } int num3 = (SkipBulletPatch._fireAllBullets ? (bulletCount * num) : num); int num4 = SkipBulletPatch._sailsCacheCapacity[index]; int num5 = num2 + num3; if (num5 > num4) { do { num4 *= 2; } while (num5 > num4); SkipBulletPatch.SetSailsCacheCapacity(index, num4); array = SkipBulletPatch._sailsCache[index]; } SkipBulletPatch._sailsCacheLen[index] = num2 + num3; int num6 = num2 + num3; for (int i = num2; i < num6; i++) { ref DysonSailCache reference = ref array[i]; val2 = val3 + RandomTable.SphericNormal(ref swarm.randSeed, 0.5); ((DysonSailCache)(ref reference)).FromData(ref val, ref val2, orbitId); } } if (SkipBulletPatch._fireAllBullets) { if (!ejector.incUsed) { ejector.incUsed = ejector.bulletInc >= bulletCount; } ejector.bulletInc = 0; ejector.bulletCount = 0; lock (consumeRegister) { consumeRegister[ejector.bulletId] += bulletCount; } } else { int num7 = ejector.bulletInc / bulletCount; if (!ejector.incUsed) { ejector.incUsed = num7 > 0; } ejector.bulletInc -= num7; ejector.bulletCount = bulletCount - 1; if (ejector.bulletCount == 0) { ejector.bulletInc = 0; } lock (consumeRegister) { consumeRegister[ejector.bulletId]++; } } ejector.time = ejector.coldSpend; ejector.direction = -1; return false; } } public const string GUID = "org.soardev.cheatenabler"; public static void Init(Harmony harmony) { if (!Chainloader.PluginInfos.TryGetValue("org.soardev.cheatenabler", out var _)) { return; } try { harmony.PatchAll(typeof(Warper)); Warper.Init(); Log.Debug("CheatEnabler compatibility - OK"); } catch (Exception obj) { string text = "CheatEnabler 'Skip bullet period'(跳过子弹阶段) compatibility failed! Last working version: 2.4.0"; Log.Warn(text); Log.Warn(obj); errorMessage = errorMessage + text + "\n"; } } } public static class GenesisBook_Patch { public const string GUID = "org.LoShin.GenesisBook"; public static void Init(Harmony harmony) { try { if (Chainloader.PluginInfos.TryGetValue("org.LoShin.GenesisBook", out var _)) { harmony.PatchAll(typeof(GenesisBook_Patch)); Log.Debug("GenesisBook compatibility - OK"); } } catch (Exception obj) { string text = "GenesisBook compatibility failed! Last working version: 3.1.4"; Log.Warn(text); Log.Warn(obj); errorMessage = errorMessage + text + "\n"; } } [HarmonyTranspiler] [HarmonyPatch(typeof(EjectorComponent), "InternalUpdate")] public static IEnumerable<CodeInstruction> EjectorComponent_Transpiler(IEnumerable<CodeInstruction> instructions) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Expected O, but got Unknown //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Expected O, but got Unknown //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Expected O, but got Unknown //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Expected O, but got Unknown //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Expected O, but got Unknown //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Expected O, but got Unknown //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Expected O, but got Unknown //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Expected O, but got Unknown //IL_016b: Unknown result type (might be due to invalid IL or missing references) //IL_0171: Expected O, but got Unknown //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Expected O, but got Unknown try { CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[2] { new CodeMatch((OpCode?)OpCodes.Ldloc_S, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Stfld, (object)AccessTools.Field(typeof(SailBullet), "lBegin"), (string)null) }); if (val.IsInvalid) { Log.Warn("EjectorComponent_Transpiler: Can't find SailBullet.lBegin"); return instructions; } CodeInstruction instruction = val.Instruction; val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1] { new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Call && ((MethodInfo)i.operand).Name == "Ejector_PatchMethod"), (string)null) }); if (val.IsInvalid) { Log.Warn("EjectorComponent_Transpiler: Can't find Ejector_PatchMethod"); return instructions; } val.MatchBack(false, (CodeMatch[])(object)new CodeMatch[1] { new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Stfld && ((FieldInfo)i.operand).Name == "time"), (string)null) }); val.Advance(1).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[8] { new CodeInstruction(OpCodes.Ldarg_0, (object)null), new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(EjectorComponent), "planetId")), instruction, new CodeInstruction(OpCodes.Ldarg_0, (object)null), new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(EjectorComponent), "orbitId")), new CodeInstruction(OpCodes.Ldarg_0, (object)null), new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(EjectorComponent), "bulletCount")), Transpilers.EmitDelegate<Action<int, Vector3, int, int>>((Action<int, Vector3, int, int>)delegate(int planetId, Vector3 localPos, int orbitId, int bulletCount) { if (MainManager.Planets.TryGetValue(planetId, out var value) && value.IsNextIdle) { int stationPilerLevel = GameMain.history.stationPilerLevel; int num = ((stationPilerLevel > bulletCount) ? bulletCount : stationPilerLevel); for (int j = 0; j < num; j++) { value.AddDysonData(planetId, -orbitId, in localPos); } } }) }); return val.InstructionEnumeration(); } catch (Exception obj) { string text = "GenesisBook compatibility failed! Last working version: 3.1.4"; errorMessage = errorMessage + text + "\n"; Log.Warn(text); Log.Warn(obj); return instructions; } } } [Serializable] [CompilerGenerated] private sealed class <>c { public static readonly <>c <>9 = new <>c(); public static Response <>9__9_0; public static Response <>9__9_1; internal void <ShowMessage>b__9_0() { Plugin.instance.WarnIncompat.Value = false; } internal void <ShowMessage>b__9_1() { Plugin.instance.WarnIncompat.Value = false; } } private static string errorMessage = ""; private static string warnMessage = ""; public static bool IsNoticed { get; set; } = false; public static bool ShouldPatchEjector() { return !Chainloader.PluginInfos.ContainsKey("org.LoShin.GenesisBook"); } public static void Init(Harmony harmony) { Version version = typeof(BaseUnityPlugin).Assembly.GetName().Version; if (version.Minor != 4 || version.Build != 17) { warnMessage = $"You are using BepInEx version {version}. The version that is not 5.4.17 may not work correctly.\n"; warnMessage += $"您使用的BepInEx版本为{version}。非5.4.17可能无法正常运作"; } Weaver.Init(harmony); CommonAPI.Init(harmony); CheatEnabler_Patch.Init(harmony); Auxilaryfunction_Patch.Init(harmony); Multfunction_mod_Patch.Init(harmony); PlanetMiner.Init(harmony); GenesisBook_Patch.Init(harmony); if (!string.IsNullOrEmpty(errorMessage) || !string.IsNullOrEmpty(warnMessage)) { harmony.PatchAll(typeof(Compatibility)); } } public static void OnDestory() { } [HarmonyPostfix] [HarmonyPatch(typeof(VFPreload), "InvokeOnLoadWorkEnded")] private static void ShowMessage() { //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Expected O, but got Unknown //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Expected O, but got Unknown if (IsNoticed || !Plugin.instance.WarnIncompat.Value) { return; } IsNoticed = true; if (!string.IsNullOrEmpty(errorMessage)) { errorMessage = "The following compatible patches didn't success:\n模拟帧对以下mod的兼容性补丁失效:\n" + errorMessage; string text = errorMessage; string text2 = Localization.Translate("确定"); object obj = <>c.<>9__9_0; if (obj == null) { Response val = delegate { Plugin.instance.WarnIncompat.Value = false; }; <>c.<>9__9_0 = val; obj = (object)val; } UIMessageBox.Show("SampleAndHoldSim Report 模拟帧兼容提示", text, text2, "Don't show", 3, (Response)null, (Response)obj); } if (string.IsNullOrEmpty(warnMessage)) { return; } Log.Warn(warnMessage); string text3 = warnMessage; string text4 = Localization.Translate("确定"); object obj2 = <>c.<>9__9_1; if (obj2 == null) { Response val2 = delegate { Plugin.instance.WarnIncompat.Value = false; }; <>c.<>9__9_1 = val2; obj2 = (object)val2; } UIMessageBox.Show("SampleAndHoldSim Report 模拟帧兼容提示", text3, text4, "Don't show", 3, (Response)null, (Response)obj2); } } public static class Log { private static ManualLogSource _logger; private static int count; public static void Init(ManualLogSource logger) { _logger = logger; } public static void Error(object obj) { _logger.LogError(obj); } public static void Warn(object obj) { _logger.LogWarning(obj); } public static void Info(object obj) { _logger.LogInfo(obj); } public static void Debug(object obj) { _logger.LogDebug(obj); } public static void Print(int period, object obj) { if (count++ % period == 0) { _logger.LogDebug(obj); } } public static void PrintInstruction(IEnumerable<CodeInstruction> instructions, int start, int end) { int num = -1; foreach (CodeInstruction instruction in instructions) { if (num++ > start) { if (num >= end) { break; } if (instruction.opcode == OpCodes.Call || instruction.opcode == OpCodes.Callvirt) { Warn($"{num,2} {instruction}"); } else if (CodeInstructionExtensions.IsLdarg(instruction, (int?)null)) { Info($"{num,2} {instruction}"); } else { Debug($"{num,2} {instruction}"); } } } } } [BepInPlugin("starfi5h.plugin.SampleAndHoldSim", "SampleAndHoldSim", "0.7.2")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { public const string GUID = "starfi5h.plugin.SampleAndHoldSim"; public const string NAME = "SampleAndHoldSim"; public const string VERSION = "0.7.2"; public static Plugin instance; private Harmony harmony; public ConfigEntry<int> UpdatePeriod; public ConfigEntry<bool> FocusLocalFactory; public ConfigEntry<int> SliderMaxUpdatePeriod; public ConfigEntry<int> UIStationStoragePeriod; public ConfigEntry<bool> UnitPerMinute; public ConfigEntry<bool> WarnIncompat; public ConfigEntry<bool> EnableRelayLanding; public void LoadConfig() { UpdatePeriod = ((BaseUnityPlugin)this).Config.Bind<int>("General", "UpdatePeriod", 10, "Compute actual factory simulation every x ticks.\n更新周期: 每x逻辑帧运行一次实际计算"); FocusLocalFactory = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "FocusLocalFactory", true, "Let local planet factory always active.使本地工厂保持每帧运行\n"); SliderMaxUpdatePeriod = ((BaseUnityPlugin)this).Config.Bind<int>("UI", "SliderMaxUpdatePeriod", 20, "Max value of upate period slider\n更新周期滑动条的最大值"); UIStationStoragePeriod = ((BaseUnityPlugin)this).Config.Bind<int>("UI", "UIStationStoragePeriod", 600, "Display item count change rate in station storages in x ticks. 0 = no display\n显示过去x帧内物流塔货物的流入或流出速率, 0 = 不显示"); UnitPerMinute = ((BaseUnityPlugin)this).Config.Bind<bool>("UI", "UnitPerMinute", false, "If true, show rate in unit per minute. otherwise show rate in unit per second. \ntrue: 显示单位设为每分钟速率 false: 显示每秒速率"); WarnIncompat = ((BaseUnityPlugin)this).Config.Bind<bool>("UI", "WarnIncompat", true, "Show warning for incompatible mods\n显示不兼容mod的警告"); EnableRelayLanding = ((BaseUnityPlugin)this).Config.Bind<bool>("Combat", "EnableRelayLanding", true, "Allow Dark Fog relay to land on planet.\n允许黑雾中继器登陆星球"); if (UpdatePeriod.Value < 1) { UpdatePeriod.Value = 1; } MainManager.UpdatePeriod = UpdatePeriod.Value; MainManager.FocusLocalFactory = FocusLocalFactory.Value; UIcontrol.SliderMax = SliderMaxUpdatePeriod.Value; UIstation.Period = (int)Math.Ceiling((float)UIStationStoragePeriod.Value / 10f); UIstation.UnitPerMinute = UnitPerMinute.Value; Log.Debug($"UpdatePeriod:{MainManager.UpdatePeriod} StationUI:{UIstation.Period * 10}"); if (!EnableRelayLanding.Value) { Log.Info("Disable Dark Fog relay landing"); } } public void SaveConfig(int updatePeriod, bool focusLocalFactory) { UpdatePeriod.Value = updatePeriod; FocusLocalFactory.Value = focusLocalFactory; } public void Awake() { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Expected O, but got Unknown instance = this; harmony = new Harmony("starfi5h.plugin.SampleAndHoldSim"); Log.Init(((BaseUnityPlugin)this).Logger); LoadConfig(); GameLogic_Patch.GameMain_Begin(); harmony.PatchAll(typeof(GameLogic_Patch)); harmony.PatchAll(typeof(ThreadManager_Patch)); harmony.PatchAll(typeof(GameTick_Patch)); harmony.PatchAll(typeof(ManagerLogic)); harmony.PatchAll(typeof(UIcontrol)); harmony.PatchAll(typeof(Station_Patch)); harmony.PatchAll(typeof(Dyson_Patch)); if (Compatibility.ShouldPatchEjector()) { harmony.PatchAll(typeof(Ejector_Patch)); } else { Log.Debug("Skip Ejector_Patch due to Genesis Book mod exist!"); } harmony.PatchAll(typeof(Combat_Patch)); harmony.PatchAll(typeof(Fix_Patch)); if (UIstation.Period > 0) { harmony.PatchAll(typeof(UIstation)); } harmony.PatchAll(typeof(KillStatLogic2)); } public void Start() { Compatibility.Init(harmony); } } public class Threading { private static readonly ManualResetEvent completeEvent = new ManualResetEvent(initialState: false); public static void ForEachParallel(Action<int> work, int dataCount, int workerCount = -1) { if (workerCount < 0) { workerCount = Mathf.Max(2, Environment.ProcessorCount); } else if (workerCount == 0) { throw new ArgumentException("Need at least 1 worker", "workerCount"); } int currentIndex = dataCount; completeEvent.Reset(); int runningCount = workerCount; Exception exceptionThrown = null; for (int i = 0; i < workerCount - 1; i++) { ThreadPool.QueueUserWorkItem(DoWork); } DoWork(null); completeEvent.WaitOne(); if (exceptionThrown != null) { throw new TargetInvocationException("An exception was thrown inside one of the threads", exceptionThrown); } void DoWork(object _) { try { while (exceptionThrown == null) { int num = Interlocked.Decrement(ref currentIndex); if (num < 0) { break; } work(num); } } catch (Exception ex) { exceptionThrown = ex; } finally { if (Interlocked.Decrement(ref runningCount) <= 0) { completeEvent.Set(); } } } } } internal class UIcontrol { public static int SliderMax = 20; private static bool initialized; private static GameObject group; private static Slider slider; private static InputField input; private static Text text_factory; private static Toggle toggle_local; private static bool eventLock; private static UItooltip tip1; private static UItooltip tip2; private static UItooltip tip3; [HarmonyPostfix] [HarmonyPatch(typeof(UIPerformancePanel), "_OnOpen")] public static void Init() { //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Expected O, but got Unknown //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_0198: Unknown result type (might be due to invalid IL or missing references) //IL_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_025e: Unknown result type (might be due to invalid IL or missing references) //IL_0278: Unknown result type (might be due to invalid IL or missing references) //IL_0334: Unknown result type (might be due to invalid IL or missing references) //IL_03ed: Unknown result type (might be due to invalid IL or missing references) //IL_0406: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)group == (Object)null) { try { Slider slider = UIRoot.instance.uiGame.dysonEditor.controlPanel.inspector.layerInfo.slider0; InputField input = UIRoot.instance.uiGame.dysonEditor.controlPanel.inspector.layerInfo.input0; Text cpuValueText = UIRoot.instance.uiGame.statWindow.performancePanelUI.cpuValueText1; GameObject gameObject = ((Component)((Component)UIRoot.instance.optionWindow.vsyncComp).transform.parent).gameObject; GameObject gameObject2 = ((Compone