Solved: Harmony doesn't seem able to patch static methods.
Besides, my requirement meant checking the instance type, which isn't possible in a static method.
I solved this by patching a different, non-static method to achieve what I wanted to do
Is there something special I need to do to patch static methods?
Take this example
class Tim_Test {
public class Tim_Test_Init : IHarmony {
public void Start () {
Debug.Log (" Loading Patch: " + this.GetType ().ToString ());
var harmony = HarmonyInstance.Create (GetType ().ToString ());
harmony.PatchAll (Assembly.GetExecutingAssembly ());
}
}
[HarmonyPatch (typeof (BlockPoweredDoor))]
[HarmonyPatch ("Init")]
public class Tim_BlockPoweredDoor_Init {
public static bool Prefix (BlockPoweredDoor __instance) {
Debug.Log ("Type: " + __instance.GetType ().Name);
return true;
}
}
[HarmonyPatch (typeof (BlockPoweredDoor))]
[HarmonyPatch ("IsDoorOpen")]
public class Tim_BlockPoweredDoor_IsDoorOpen {
public static bool Prefix (BlockPoweredDoor __instance) {
Debug.Log ("Type: " + __instance.GetType ().Name);
return true;
}
}
}
In this case, the patch for "Init" works, as the log can be seen in the console, however the patch for "IsDoorOpen", does not, as under no circumstance does a log appear in the console (placing, turning on power, etc).
The only difference between the two methods is vanilla "Init" is:
public override void Init()
whereas vanilla "IsDoorOpen" is:
public static bool IsDoorOpen(byte _metadata)
Any help pointing me in the right direction would be greatly appreciated
DMT Modding Tool
in Tools
Posted · Edited by timbeswick
Solved (see edit history)
Solved: Harmony doesn't seem able to patch static methods.
Besides, my requirement meant checking the instance type, which isn't possible in a static method.
I solved this by patching a different, non-static method to achieve what I wanted to do
Is there something special I need to do to patch static methods?
Take this example
In this case, the patch for "Init" works, as the log can be seen in the console, however the patch for "IsDoorOpen", does not, as under no circumstance does a log appear in the console (placing, turning on power, etc).
The only difference between the two methods is vanilla "Init" is:
whereas vanilla "IsDoorOpen" is:
Any help pointing me in the right direction would be greatly appreciated