Refactor player faking
This commit is contained in:
@@ -143,72 +143,5 @@ namespace DavesPhatStore {
|
||||
}
|
||||
|
||||
// region player faking
|
||||
[HarmonyPatch(typeof(GameData), "UserCode_CmdOpenSupermarket")]
|
||||
public static class PlayersAddedTranspilePatch {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
[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
|
||||
}
|
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection.Emit;
|
||||
using HarmonyLib;
|
||||
|
||||
namespace DavesPhatStore {
|
||||
[HarmonyPatch]
|
||||
public class PlayerFaking {
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(GameData), "UserCode_CmdOpenSupermarket")]
|
||||
static IEnumerable<CodeInstruction> TranspilerOpenMarket(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();
|
||||
}
|
||||
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(NPC_Manager), "SpawnCustomerNCP")]
|
||||
static IEnumerable<CodeInstruction> TranspilerSpawnNPC(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();
|
||||
}
|
||||
}
|
||||
}
|
@@ -36,6 +36,7 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Class1.cs"/>
|
||||
<Compile Include="PlayerFaking.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs"/>
|
||||
<Compile Include="WaitTimes.cs" />
|
||||
</ItemGroup>
|
||||
|
Reference in New Issue
Block a user