From 02abebf02fb8bbf508510e3ced3d4f229d84603f Mon Sep 17 00:00:00 2001 From: Soar Qin Date: Mon, 5 Dec 2022 04:55:33 +0800 Subject: [PATCH] Work in progress --- CheatEnabler/CheatEnabler.cs | 12 ++--- OverclockEverything/OverclockEverything.cs | 58 ++++++++++++++++++++-- 2 files changed, 60 insertions(+), 10 deletions(-) diff --git a/CheatEnabler/CheatEnabler.cs b/CheatEnabler/CheatEnabler.cs index b86bc92..153fda8 100644 --- a/CheatEnabler/CheatEnabler.cs +++ b/CheatEnabler/CheatEnabler.cs @@ -190,7 +190,7 @@ public class CheatEnabler : BaseUnityPlugin } } - private static void UnlockTechRecursive(GameHistoryData history, int currentTech, int maxLevel = 10001) + private static void UnlockTechRecursive(GameHistoryData history, int currentTech, int maxLevel = 10000) { var techStates = history.techStates; if (techStates == null || !techStates.ContainsKey(currentTech)) @@ -203,7 +203,7 @@ public class CheatEnabler : BaseUnityPlugin return; } var value = techStates[currentTech]; - var maxLvl = Math.Min(maxLevel, value.maxLevel) + 1; + var maxLvl = Math.Min(maxLevel, value.maxLevel); if (value.unlocked && value.curLevel >= maxLvl && value.hashUploaded >= value.hashNeeded) { return; @@ -225,7 +225,7 @@ public class CheatEnabler : BaseUnityPlugin } } - while (value.curLevel < maxLvl) + while (value.curLevel <= maxLvl) { for (var j = 0; j < techProto.UnlockFunctions.Length; j++) { @@ -233,10 +233,10 @@ public class CheatEnabler : BaseUnityPlugin } value.curLevel++; } - value.curLevel = maxLvl - 1; - value.unlocked = maxLvl > value.maxLevel; + value.unlocked = maxLvl >= value.maxLevel; + value.curLevel = value.unlocked ? maxLvl : maxLvl + 1; value.hashNeeded = techProto.GetHashNeeded(value.curLevel); - value.hashUploaded = maxLvl >= value.maxLevel ? value.hashNeeded : 0; + value.hashUploaded = value.unlocked ? value.hashNeeded : 0; techStates[currentTech] = value; } } diff --git a/OverclockEverything/OverclockEverything.cs b/OverclockEverything/OverclockEverything.cs index 29320f5..2516e83 100644 --- a/OverclockEverything/OverclockEverything.cs +++ b/OverclockEverything/OverclockEverything.cs @@ -1,4 +1,6 @@ -using BepInEx; +using System.Collections.Generic; +using System.Reflection.Emit; +using BepInEx; using BepInEx.Configuration; using HarmonyLib; using UnityEngine; @@ -57,6 +59,48 @@ public class Patch : BaseUnityPlugin Harmony.CreateAndPatchAll(typeof(BeltFix)); } + [HarmonyTranspiler, HarmonyPatch(typeof(LabComponent), "SetFunction")] + private static IEnumerable LabComponent_SetFunction_Transpiler(IEnumerable instructions) + { + var lastIsLdc10000 = false; + foreach (var instr in instructions) + { + if (instr.opcode == OpCodes.Ldc_I4 && instr.OperandIs(10000)) + { + lastIsLdc10000 = true; + } + else + { + if (lastIsLdc10000) + { + lastIsLdc10000 = false; + if (instr.opcode == OpCodes.Stfld) + { + yield return new CodeInstruction(OpCodes.Ldc_I4, assembleSpeedMultiplier); + yield return new CodeInstruction(OpCodes.Mul); + } + } + } + yield return instr; + } + } + + [HarmonyTranspiler, HarmonyPatch(typeof(MechaForge), "GameTick")] + private static IEnumerable MechaForge_GameTick_Transpiler(IEnumerable instructions) + { + foreach (var instr in instructions) + { + if (instr.opcode == OpCodes.Ldc_R4 && instr.OperandIs(10000f)) + { + yield return new CodeInstruction(OpCodes.Ldc_R4, 10000f * assembleSpeedMultiplier); + } + else + { + yield return instr; + } + } + } + [HarmonyPostfix, HarmonyPriority(Priority.Last), HarmonyPatch(typeof(VFPreload), "InvokeOnLoadWorkEnded")] private static void VFPreload_InvokeOnLoadWorkEnded_Postfix() { @@ -70,10 +114,14 @@ public class Patch : BaseUnityPlugin var prefabDesc = proto.prefabDesc; if (prefabDesc.isInserter) { - prefabDesc.inserterSTT *= sorterSpeedMultiplier; + prefabDesc.inserterSTT /= sorterSpeedMultiplier; prefabDesc.idleEnergyPerTick *= sorterPowerConsumptionMultiplier; prefabDesc.workEnergyPerTick *= sorterPowerConsumptionMultiplier; } + if (prefabDesc.isLab) + { + prefabDesc.labAssembleSpeed *= assembleSpeedMultiplier; + } if (prefabDesc.isAssembler) { prefabDesc.assemblerSpeed *= assembleSpeedMultiplier; @@ -108,10 +156,12 @@ public class Patch : BaseUnityPlugin } if (prefabDesc.isPowerNode) { + var ival = Mathf.Floor(prefabDesc.powerConnectDistance); prefabDesc.powerConnectDistance = - Mathf.Floor(prefabDesc.powerConnectDistance) * prefabDesc.powerConnectDistance + 0.5f; + ival * powerSupplyAreaMultiplier + (prefabDesc.powerConnectDistance - ival); + ival = Mathf.Floor(prefabDesc.powerCoverRadius); prefabDesc.powerCoverRadius = - Mathf.Floor(prefabDesc.powerCoverRadius) * prefabDesc.powerConnectDistance + 0.5f; + ival * powerSupplyAreaMultiplier + (prefabDesc.powerCoverRadius - ival); } } }