public void ReplaceStatementsWithReturn()
        {
            DummyCompiledClass compiledClass = new DummyCompiledClass();

            MethodInfo methodToReplace = typeof(DummyCompiledClass).GetMethod("SomeMethod");
            MethodInfo transpiler      = typeof(DummyHarmonyClass).GetMethod("ReplaceStatementsWithReturnTranspiler");

            Assert.IsFalse(compiledClass.SomeMethod());

            harmony.Patch(methodToReplace, transpiler: new HarmonyMethod(transpiler));

            Assert.IsTrue(compiledClass.SomeMethod());
        }
        public void SetValueDirect()
        {
            DummyCompiledClass madeClass = new DummyCompiledClass();
            DummyModClass      mc        = new DummyModClass();

            TypedReference reference = __makeref(mc);

            FieldInfo info = madeClass.GetType().GetField("thing", BindingFlags.NonPublic | BindingFlags.Instance);

            Assert.AreEqual(5, (int)info.GetValueDirect(reference));

            info.SetValueDirect(reference, 9);
            Assert.AreEqual(9, (int)info.GetValueDirect(reference));
        }
        public void SetPublicInstanceVariableTest()
        {
            DummyCompiledClass compiledClass = new DummyCompiledClass();

            MethodInfo methodToReplace = typeof(DummyCompiledClass).GetMethod("SetPublicInstanceVariable");
            MethodInfo transpiler      = typeof(DummyHarmonyClass).GetMethod("SetPublicInstanceVariableTranspiler");

            compiledClass.SetPublicInstanceVariable();
            Assert.AreEqual(10, compiledClass.testVar);

            harmony.Patch(methodToReplace, transpiler: new HarmonyMethod(transpiler));

            compiledClass.SetPublicInstanceVariable();
            Assert.AreEqual(20, compiledClass.testVar);
        }
        public void RemoveStatements()
        {
            int yValue = 0;

            DummyCompiledClass compiledClass = new DummyCompiledClass();

            MethodInfo methodToReplace = typeof(DummyCompiledClass).GetMethod("ComplexMethod");
            MethodInfo transpiler      = typeof(DummyHarmonyClass).GetMethod("RemoveStatementsNoReturnTranspiler");

            Assert.AreEqual(10, compiledClass.ComplexMethod(yValue));

            harmony.Patch(methodToReplace, transpiler: new HarmonyMethod(transpiler));

            Assert.AreEqual(yValue, compiledClass.ComplexMethod(yValue));
        }
        public void SetPrivateInstanceVariableTest()
        {
            DummyCompiledClass compiledClass = new DummyCompiledClass();

            MethodInfo methodToReplace = typeof(DummyCompiledClass).GetMethod("SetPrivateInstanceVariable");
            MethodInfo transpiler      = typeof(DummyHarmonyClass).GetMethod("SetPrivateInstanceVariableTranspiler");

            int privateVar;

            compiledClass.SetPrivateInstanceVariable();
            privateVar = (int)compiledClass.GetType().GetField("thing", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(compiledClass);
            Assert.AreEqual(1, privateVar);

            harmony.Patch(methodToReplace, transpiler: new HarmonyMethod(transpiler));

            compiledClass.SetPrivateInstanceVariable();
            privateVar = (int)compiledClass.GetType().GetField("thing", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(compiledClass);
            Assert.AreEqual(2, privateVar);
        }