1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2025-12-08 21:33:28 +08:00

move some functions into MechaDroneTweaks

This commit is contained in:
2023-08-23 21:45:20 +08:00
parent b454a1400f
commit 118e1b85e3
2 changed files with 121 additions and 106 deletions

View File

@@ -60,8 +60,6 @@ public class Patch : BaseUnityPlugin, IModCanSave
new ConfigDescription("Speed multiplier for EM-Rail Ejectors", new AcceptableValueRange<int>(1, 10))).Value;
Cfg.SiloMultiplier = Config.Bind("DysonSphere", "SiloMultiplier", Cfg.SiloMultiplier,
new ConfigDescription("Speed multiplier for Rocket Silos", new AcceptableValueRange<int>(1, 10))).Value;
Cfg.InventoryStackMultiplier = Config.Bind("Inventory", "StackMultiplier", Cfg.InventoryStackMultiplier,
new ConfigDescription("Stack count multiplier for inventory items", new AcceptableValueRange<int>(1, 10))).Value;
Harmony.CreateAndPatchAll(typeof(Patch));
Harmony.CreateAndPatchAll(typeof(BeltFix));
}
@@ -124,66 +122,6 @@ public class Patch : BaseUnityPlugin, IModCanSave
}
*/
[HarmonyTranspiler]
[HarmonyPatch(typeof(UIReplicatorWindow), "OnOkButtonClick")]
private static IEnumerable<CodeInstruction> UIReplicatorWindow_OnOkButtonClick_Transpiler(IEnumerable<CodeInstruction> instructions)
{
foreach (var instr in instructions)
{
if (instr.opcode == OpCodes.Ldc_I4_S && instr.OperandIs(10))
{
instr.opcode = OpCodes.Ldc_I4;
instr.operand = 1000;
}
yield return instr;
}
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(UIReplicatorWindow), "OnPlusButtonClick")]
[HarmonyPatch(typeof(UIReplicatorWindow), "OnMinusButtonClick")]
private static IEnumerable<CodeInstruction> UIReplicatorWindow_OnPlusButtonClick_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
var ilist = instructions.ToList();
for (var i = 0; i < ilist.Count; i++)
{
var instr = ilist[i];
if (instr.opcode == OpCodes.Ldloc_0 && ilist[i + 1].opcode == OpCodes.Ldc_I4_1 && (ilist[i + 2].opcode == OpCodes.Add || ilist[i + 2].opcode == OpCodes.Sub))
{
var label1 = generator.DefineLabel();
var label2 = generator.DefineLabel();
var label3 = generator.DefineLabel();
var label4 = generator.DefineLabel();
yield return instr;
yield return new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(VFInput), "control"));
yield return new CodeInstruction(OpCodes.Brfalse_S, label1);
yield return new CodeInstruction(OpCodes.Ldc_I4_S, 10);
yield return new CodeInstruction(OpCodes.Br_S, label4);
yield return new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(VFInput), "shift")).WithLabels(label1);
yield return new CodeInstruction(OpCodes.Brfalse_S, label2);
yield return new CodeInstruction(OpCodes.Ldc_I4_S, 100);
yield return new CodeInstruction(OpCodes.Br_S, label4);
yield return new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(VFInput), "alt")).WithLabels(label2);
yield return new CodeInstruction(OpCodes.Brfalse_S, label3);
yield return new CodeInstruction(OpCodes.Ldc_I4, 1000);
yield return new CodeInstruction(OpCodes.Br_S, label4);
yield return new CodeInstruction(OpCodes.Ldc_I4_1).WithLabels(label3);
ilist[i + 2] = ilist[i + 2].WithLabels(label4);
i++;
continue;
}
if (instr.opcode == OpCodes.Ldc_I4_S && instr.OperandIs(10))
{
instr.opcode = OpCodes.Ldc_I4;
instr.operand = 1000;
}
yield return instr;
}
}
[HarmonyPostfix, HarmonyPatch(typeof(LabComponent), "SetFunction")]
private static void LabComponent_SetFunction_Postfix(ref LabComponent __instance)
{
@@ -208,33 +146,6 @@ public class Patch : BaseUnityPlugin, IModCanSave
}
}
[HarmonyPrefix, HarmonyPatch(typeof(StorageComponent), "LoadStatic")]
private static bool StorageComponent_LoadStatic_Prefix()
{
if (StorageComponent.staticLoaded) return false;
foreach (var proto in LDB.items.dataArray)
{
proto.StackSize *= Cfg.InventoryStackMultiplier;
}
return true;
}
[HarmonyPostfix, HarmonyPatch(typeof(StorageComponent), "Import")]
private static void StorageComponent_Import_Postfix(StorageComponent __instance)
{
if (Cfg.InventoryStackMultiplier <= 1) return;
var size = __instance.size;
for (var i = 0; i < size; i++)
{
var itemId = __instance.grids[i].itemId;
if (itemId != 0)
{
__instance.grids[i].stackSize = StorageComponent.itemStackCount[itemId];
}
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(GameSave), nameof(GameSave.LoadCurrentGame))]
private static void GameSave_LoadCurrentGame_Prefix()