Refactor employee patches
This commit is contained in:
@@ -43,7 +43,6 @@ namespace DavesPhatStore {
|
||||
var originalMethods = harmony.GetPatchedMethods();
|
||||
Logger.LogInfo("Patched " + originalMethods.Count() + " methods");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(GameData), "UserCode_CmdAlterFunds__Single")]
|
||||
@@ -90,58 +89,4 @@ namespace DavesPhatStore {
|
||||
Console.WriteLine($"maxCustomersNPCs: {__instance.maxCustomersNPCs}");
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(UpgradesManager), "ManageExtraPerks")]
|
||||
public static class ConsoleProductionReductionPatch {
|
||||
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) {
|
||||
var codes = new List<CodeInstruction>(instructions);
|
||||
|
||||
for (int i = 0; i < codes.Count; i++) {
|
||||
var codeInstruction = codes[i];
|
||||
// if (codeInstruction.operand != null) {
|
||||
// Console.WriteLine($"'{codeInstruction.operand.ToString()}'");
|
||||
// Console.WriteLine(codeInstruction.operand.ToString() == "NPC_Manager::extraEmployeeSpeedFactor");
|
||||
// }
|
||||
|
||||
if (codeInstruction.opcode == OpCodes.Ldfld &&
|
||||
codeInstruction.operand?.ToString() == "System.Int32 maxEmployees") {
|
||||
Console.WriteLine($"Found {codeInstruction.operand}");
|
||||
codes[i + 1].opcode = OpCodes.Nop;
|
||||
codes.Insert(i + 2,
|
||||
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(Main), "employeePerPerk")));
|
||||
codes.Insert(i + 3,
|
||||
new CodeInstruction(OpCodes.Call,
|
||||
AccessTools.PropertyGetter(typeof(Main).GetField("employeePerPerk").FieldType, "Value")));
|
||||
}
|
||||
|
||||
if (codeInstruction.opcode == OpCodes.Ldfld &&
|
||||
codeInstruction.operand?.ToString() == "System.Single extraEmployeeSpeedFactor") {
|
||||
Console.WriteLine($"Found {codeInstruction.operand}");
|
||||
codes[i + 1].opcode = OpCodes.Nop;
|
||||
codes.Insert(i + 2,
|
||||
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(Main), "employeeSpeedPerk")));
|
||||
codes.Insert(i + 3,
|
||||
new CodeInstruction(OpCodes.Call,
|
||||
AccessTools.PropertyGetter(typeof(Main).GetField("employeeSpeedPerk").FieldType, "Value")));
|
||||
}
|
||||
|
||||
if (codeInstruction.opcode == OpCodes.Ldfld &&
|
||||
codeInstruction.operand?.ToString() == "System.Single extraCheckoutMoney") {
|
||||
Console.WriteLine($"Found {codeInstruction.operand}");
|
||||
codes[i + 1].opcode = OpCodes.Nop;
|
||||
codes.Insert(i + 2,
|
||||
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(Main), "employeeExtraMoneyPerk")));
|
||||
codes.Insert(i + 3,
|
||||
new CodeInstruction(OpCodes.Call,
|
||||
AccessTools.PropertyGetter(typeof(Main).GetField("employeeExtraMoneyPerk").FieldType,
|
||||
"Value")));
|
||||
}
|
||||
}
|
||||
|
||||
return codes.AsEnumerable();
|
||||
}
|
||||
}
|
||||
|
||||
// region player faking
|
||||
// endregion
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection.Emit;
|
||||
using HarmonyLib;
|
||||
|
||||
namespace DavesPhatStore {
|
||||
[HarmonyPatch]
|
||||
public class EmployeeBuffs {
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(UpgradesManager), "ManageExtraPerks")]
|
||||
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) {
|
||||
var codes = new List<CodeInstruction>(instructions);
|
||||
|
||||
for (int i = 0; i < codes.Count; i++) {
|
||||
var codeInstruction = codes[i];
|
||||
// if (codeInstruction.operand != null) {
|
||||
// Console.WriteLine($"'{codeInstruction.operand.ToString()}'");
|
||||
// Console.WriteLine(codeInstruction.operand.ToString() == "NPC_Manager::extraEmployeeSpeedFactor");
|
||||
// }
|
||||
|
||||
if (codeInstruction.opcode == OpCodes.Ldfld &&
|
||||
codeInstruction.operand?.ToString() == "System.Int32 maxEmployees") {
|
||||
Console.WriteLine($"Found {codeInstruction.operand}");
|
||||
codes[i + 1].opcode = OpCodes.Nop;
|
||||
codes.Insert(i + 2,
|
||||
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(Main), "employeePerPerk")));
|
||||
codes.Insert(i + 3,
|
||||
new CodeInstruction(OpCodes.Call,
|
||||
AccessTools.PropertyGetter(typeof(Main).GetField("employeePerPerk").FieldType, "Value")));
|
||||
}
|
||||
|
||||
if (codeInstruction.opcode == OpCodes.Ldfld &&
|
||||
codeInstruction.operand?.ToString() == "System.Single extraEmployeeSpeedFactor") {
|
||||
Console.WriteLine($"Found {codeInstruction.operand}");
|
||||
codes[i + 1].opcode = OpCodes.Nop;
|
||||
codes.Insert(i + 2,
|
||||
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(Main), "employeeSpeedPerk")));
|
||||
codes.Insert(i + 3,
|
||||
new CodeInstruction(OpCodes.Call,
|
||||
AccessTools.PropertyGetter(typeof(Main).GetField("employeeSpeedPerk").FieldType, "Value")));
|
||||
}
|
||||
|
||||
if (codeInstruction.opcode == OpCodes.Ldfld &&
|
||||
codeInstruction.operand?.ToString() == "System.Single extraCheckoutMoney") {
|
||||
Console.WriteLine($"Found {codeInstruction.operand}");
|
||||
codes[i + 1].opcode = OpCodes.Nop;
|
||||
codes.Insert(i + 2,
|
||||
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(Main), "employeeExtraMoneyPerk")));
|
||||
codes.Insert(i + 3,
|
||||
new CodeInstruction(OpCodes.Call,
|
||||
AccessTools.PropertyGetter(typeof(Main).GetField("employeeExtraMoneyPerk").FieldType,
|
||||
"Value")));
|
||||
}
|
||||
}
|
||||
|
||||
return codes.AsEnumerable();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,7 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Class1.cs"/>
|
||||
<Compile Include="EmployeeBuffs.cs" />
|
||||
<Compile Include="PlayerFaking.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs"/>
|
||||
<Compile Include="WaitTimes.cs" />
|
||||
|
||||
Reference in New Issue
Block a user