public void TestMethod1() { var originalClass = typeof(Class1); Assert.IsNotNull(originalClass); var originalMethod = originalClass.GetMethod("Method1"); Assert.IsNotNull(originalMethod); var patchClass = typeof(Class1Patch); var prefix = patchClass.GetMethod("Prefix"); var postfix = patchClass.GetMethod("Postfix"); var transpiler = patchClass.GetMethod("Transpiler"); Assert.IsNotNull(prefix); Assert.IsNotNull(postfix); Assert.IsNotNull(transpiler); Class1Patch._reset(); var instance = HarmonyInstance.Create("test"); Assert.IsNotNull(instance); var patcher = new PatchProcessor(instance, new List <MethodBase> { originalMethod }, new HarmonyMethod(prefix), new HarmonyMethod(postfix), new HarmonyMethod(transpiler)); Assert.IsNotNull(patcher); var originalMethodStartPre = Memory.GetMethodStart(originalMethod, out var exception); patcher.Patch(); var originalMethodStartPost = Memory.GetMethodStart(originalMethod, out exception); Assert.AreEqual(originalMethodStartPre, originalMethodStartPost); unsafe { var patchedCode = *(byte *)originalMethodStartPre; if (IntPtr.Size == sizeof(long)) { Assert.IsTrue(patchedCode == 0x48); } else { Assert.IsTrue(patchedCode == 0x68); } } Class1.Method1(); Assert.IsTrue(Class1Patch.prefixed, "Prefix was not executed"); Assert.IsTrue(Class1Patch.originalExecuted, "Original was not executed"); Assert.IsTrue(Class1Patch.postfixed, "Postfix was not executed"); }
public void TestMethod1() { var originalClass = typeof(Class1); Assert.IsNotNull(originalClass); var originalMethod = originalClass.GetMethod("Method1"); Assert.IsNotNull(originalMethod); var patchClass = typeof(Class1Patch); var realPrefix = patchClass.GetMethod("Prefix"); var realPostfix = patchClass.GetMethod("Postfix"); var realTranspiler = patchClass.GetMethod("Transpiler"); Assert.IsNotNull(realPrefix); Assert.IsNotNull(realPostfix); Assert.IsNotNull(realTranspiler); Class1Patch._reset(); MethodInfo prefixMethod; MethodInfo postfixMethod; MethodInfo transpilerMethod; PatchTools.GetPatches(typeof(Class1Patch), out prefixMethod, out postfixMethod, out transpilerMethod); Assert.AreSame(realPrefix, prefixMethod); Assert.AreSame(realPostfix, postfixMethod); Assert.AreSame(realTranspiler, transpilerMethod); var instance = HarmonyInstance.Create("test"); Assert.IsNotNull(instance); var patcher = new PatchProcessor(instance, new List <MethodBase> { originalMethod }, new HarmonyMethod(prefixMethod), new HarmonyMethod(postfixMethod), new HarmonyMethod(transpilerMethod)); Assert.IsNotNull(patcher); var originalMethodStartPre = Memory.GetMethodStart(originalMethod, out var exception); patcher.Patch(); var originalMethodStartPost = Memory.GetMethodStart(originalMethod, out exception); Assert.AreEqual(originalMethodStartPre, originalMethodStartPost); Class1.Method1(); Assert.IsTrue(Class1Patch.prefixed, "Prefix was not executed"); Assert.IsTrue(Class1Patch.originalExecuted, "Original was not executed"); Assert.IsTrue(Class1Patch.postfixed, "Postfix was not executed"); }
public void NUnitTestMethod1() { var originalClass = typeof(Class1); Assert.IsNotNull(originalClass); var originalMethod = originalClass.GetMethod("Method1"); Assert.IsNotNull(originalMethod); var patchClass = typeof(Class1Patch); var realPrefix = patchClass.GetMethod("Prefix"); var realPostfix = patchClass.GetMethod("Postfix"); Assert.IsNotNull(realPrefix); Assert.IsNotNull(realPostfix); Class1Patch._reset(); MethodInfo prefixMethod; MethodInfo postfixMethod; MethodInfo infixMethod; PatchTools.GetPatches(typeof(Class1Patch), originalMethod, out prefixMethod, out postfixMethod, out infixMethod); Assert.AreSame(realPrefix, prefixMethod); Assert.AreSame(realPostfix, postfixMethod); var instance = HarmonyInstance.Create("test"); Assert.IsNotNull(instance); instance.Patch(originalMethod, new HarmonyMethod(prefixMethod), new HarmonyMethod(postfixMethod)); Class1.Method1(); Assert.IsTrue(Class1Patch.prefixed); Assert.IsTrue(Class1Patch.originalExecuted); Assert.IsTrue(Class1Patch.postfixed); }
public void TestMethod1() { var originalClass = typeof(Class1); Assert.IsNotNull(originalClass); var originalMethod = originalClass.GetMethod("Method1"); Assert.IsNotNull(originalMethod); var patchClass = typeof(Class1Patch); var realPrefix = patchClass.GetMethod("Prefix"); var realPostfix = patchClass.GetMethod("Postfix"); var realTranspiler = patchClass.GetMethod("Transpiler"); Assert.IsNotNull(realPrefix); Assert.IsNotNull(realPostfix); Assert.IsNotNull(realTranspiler); Class1Patch._reset(); MethodInfo prefixMethod; MethodInfo postfixMethod; MethodInfo transpilerMethod; PatchTools.GetPatches(typeof(Class1Patch), originalMethod, out prefixMethod, out postfixMethod, out transpilerMethod); Assert.AreSame(realPrefix, prefixMethod); Assert.AreSame(realPostfix, postfixMethod); Assert.AreSame(realTranspiler, transpilerMethod); var instance = HarmonyInstance.Create("test"); Assert.IsNotNull(instance); var patcher = new PatchProcessor(instance, originalMethod, new HarmonyMethod(prefixMethod), new HarmonyMethod(postfixMethod), new HarmonyMethod(transpilerMethod)); Assert.IsNotNull(patcher); var originalMethodStartPre = Memory.GetMethodStart(originalMethod); patcher.Patch(); var originalMethodStartPost = Memory.GetMethodStart(originalMethod); Assert.AreEqual(originalMethodStartPre, originalMethodStartPost); unsafe { byte patchedCode = *(byte *)originalMethodStartPre; if (IntPtr.Size == sizeof(long)) { Assert.IsTrue(patchedCode == 0x48); } else { Assert.IsTrue(patchedCode == 0x68); } } Class1.Method1(); Assert.IsTrue(Class1Patch.prefixed); Assert.IsTrue(Class1Patch.originalExecuted); Assert.IsTrue(Class1Patch.postfixed); }