Update count faker to reflect on NCP spawning
This commit is contained in:
@@ -54,6 +54,7 @@ namespace CykaMod {
|
||||
}
|
||||
}
|
||||
|
||||
// region player faking
|
||||
[HarmonyPatch(typeof(GameData), "UserCode_CmdOpenSupermarket")]
|
||||
public static class PlayersAddedTranspilePatch {
|
||||
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) {
|
||||
@@ -67,6 +68,8 @@ namespace CykaMod {
|
||||
for (int i = 1; i < codes.Count; i++) {
|
||||
if (previous.opcode == OpCodes.Ldsfld && codes[i].opcode == OpCodes.Callvirt) {
|
||||
Console.WriteLine("Found Ldsfld and Callvirt");
|
||||
Console.WriteLine(previous);
|
||||
Console.WriteLine(codes[i]);
|
||||
codes.Insert(i + 1,
|
||||
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(Main), "playersAdded")));
|
||||
codes.Insert(i + 2,
|
||||
@@ -85,4 +88,39 @@ namespace CykaMod {
|
||||
return codes.AsEnumerable();
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(NPC_Manager), "SpawnCustomerNCP")]
|
||||
public static class PlayersAddedTranspilePatch2 {
|
||||
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) {
|
||||
var codes = new List<CodeInstruction>(instructions);
|
||||
|
||||
// foreach (var codeInstruction in codes) {
|
||||
// Console.WriteLine(codeInstruction);
|
||||
// }
|
||||
|
||||
CodeInstruction previous = codes[0];
|
||||
for (int i = 1; i < codes.Count; i++) {
|
||||
if (previous.opcode == OpCodes.Ldsfld && codes[i].opcode == OpCodes.Callvirt) {
|
||||
Console.WriteLine("Found Ldsfld and Callvirt:");
|
||||
Console.WriteLine(previous);
|
||||
Console.WriteLine(codes[i]);
|
||||
codes.Insert(i + 1,
|
||||
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(Main), "playersAdded")));
|
||||
codes.Insert(i + 2,
|
||||
new CodeInstruction(OpCodes.Call,
|
||||
AccessTools.PropertyGetter(typeof(Main).GetField("playersAdded").FieldType, "Value")));
|
||||
codes.Insert(i + 3, new CodeInstruction(OpCodes.Add));
|
||||
}
|
||||
|
||||
previous = codes[i];
|
||||
}
|
||||
|
||||
// foreach (var codeInstruction in codes) {
|
||||
// Console.WriteLine(codeInstruction);
|
||||
// }
|
||||
|
||||
return codes.AsEnumerable();
|
||||
}
|
||||
}
|
||||
// endregion
|
||||
}
|
||||
Reference in New Issue
Block a user