Make employee perk transpile more robust
This commit is contained in:
@@ -16,10 +16,12 @@ namespace CykaMod {
|
||||
|
||||
public static ConfigEntry<int> playersAdded;
|
||||
public static ConfigEntry<int> employeePerPerk;
|
||||
public static ConfigEntry<float> employeeSpeedPerk;
|
||||
|
||||
public void Awake() {
|
||||
playersAdded = Config.Bind("General", "PlayersAdded", 0);
|
||||
employeePerPerk = Config.Bind("General", "EmployeePerPerk", 1);
|
||||
employeeSpeedPerk = Config.Bind("General", "EmployeeSpeedPerk", 0.2f);
|
||||
|
||||
Logger.LogInfo("Cyka mod loaded");
|
||||
HarmonyFileLog.Enabled = true;
|
||||
@@ -46,15 +48,31 @@ namespace CykaMod {
|
||||
var codes = new List<CodeInstruction>(instructions);
|
||||
|
||||
for (int i = 0; i < codes.Count; i++) {
|
||||
if (codes[i].opcode == OpCodes.Ldc_I4_1) {
|
||||
Console.WriteLine("Found Ldc_I4_1");
|
||||
codes[i].opcode = OpCodes.Nop;
|
||||
codes.Insert(i + 1,
|
||||
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(Main), "employeePerPerk")));
|
||||
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.Ldc_R4) {
|
||||
// Console.WriteLine("Found Ldc_R4");
|
||||
// codeInstruction.opcode = OpCodes.Nop;
|
||||
// codes.Insert(i + 1,
|
||||
// new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(Main), "employeeSpeedPerk")));
|
||||
// codes.Insert(i + 2,
|
||||
// new CodeInstruction(OpCodes.Call,
|
||||
// AccessTools.PropertyGetter(typeof(Main).GetField("employeeSpeedPerk").FieldType, "Value")));
|
||||
// }
|
||||
}
|
||||
|
||||
return codes.AsEnumerable();
|
||||
@@ -95,7 +113,7 @@ namespace CykaMod {
|
||||
return codes.AsEnumerable();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[HarmonyPatch(typeof(NPC_Manager), "SpawnCustomerNCP")]
|
||||
public static class PlayersAddedTranspilePatch2 {
|
||||
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) {
|
||||
|
Reference in New Issue
Block a user