1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2025-12-09 06:13:36 +08:00

Work in progress

This commit is contained in:
2022-12-05 04:55:33 +08:00
parent cb85462a75
commit 02abebf02f
2 changed files with 60 additions and 10 deletions

View File

@@ -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;
}
}

View File

@@ -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<CodeInstruction> LabComponent_SetFunction_Transpiler(IEnumerable<CodeInstruction> 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<CodeInstruction> MechaForge_GameTick_Transpiler(IEnumerable<CodeInstruction> 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);
}
}
}