示例#1
0
        public void TestMethod6()
        {
            var originalClass = typeof(Class6);

            Assert.IsNotNull(originalClass);
            var originalMethod = originalClass.GetMethod("Method6");

            Assert.IsNotNull(originalMethod);

            var patchClass = typeof(Class6Patch);
            var realPrefix = patchClass.GetMethod("Prefix");

            Assert.IsNotNull(realPrefix);

            var instance6 = new Class6();

            MethodInfo prefixMethod;
            MethodInfo postfixMethod;
            MethodInfo transpilerMethod;

            PatchTools.GetPatches(typeof(Class6Patch), out prefixMethod, out postfixMethod, out transpilerMethod);

            Assert.AreSame(realPrefix, prefixMethod);

            var instance = HarmonyInstance.Create("test");

            Assert.IsNotNull(instance);

            var patcher = new PatchProcessor(instance, new List <MethodBase> {
                originalMethod
            }, new HarmonyMethod(prefixMethod), null);

            Assert.IsNotNull(patcher);

            patcher.Patch();

            instance6.someFloat  = 999;
            instance6.someString = "original";
            instance6.someStruct = new Class6Struct()
            {
                d1 = 1, d2 = 2, d3 = 3
            };
            var res = instance6.Method6();

            Assert.AreEqual(123, res.Item1);
            Assert.AreEqual("patched", res.Item2);
            Assert.AreEqual(10.0, res.Item3.d1);
        }
示例#2
0
        public void Test_Method6()
        {
            var originalClass = typeof(Class6);

            Assert.NotNull(originalClass);
            var originalMethod = originalClass.GetMethod("Method6");

            Assert.NotNull(originalMethod);

            var patchClass = typeof(Class6Patch);
            var prefix     = patchClass.GetMethod("Prefix");

            Assert.NotNull(prefix);

            var instance = new Harmony("test");

            Assert.NotNull(instance);

            var patcher = instance.CreateProcessor(originalMethod);

            Assert.NotNull(patcher);
            _ = patcher.AddPrefix(prefix);
            Assert.NotNull(patcher);

            _ = patcher.Patch();

            var instance6 = new Class6
            {
                someFloat  = 999,
                someString = "original",
                someStruct = new Class6Struct()
                {
                    d1 = 1, d2 = 2, d3 = 3
                }
            };
            var res = instance6.Method6();

            Assert.AreEqual(res[0], 123);
            Assert.AreEqual(res[1], "patched");
            Assert.AreEqual(((Class6Struct)res[2]).d1, 10.0);
        }
示例#3
0
        public void TestMethod6()
        {
            var originalClass = typeof(Class6);

            Assert.IsNotNull(originalClass);
            var originalMethod = originalClass.GetMethod("Method6");

            Assert.IsNotNull(originalMethod);

            var patchClass = typeof(Class6Patch);
            var prefix     = patchClass.GetMethod("Prefix");

            Assert.IsNotNull(prefix);

            var instance = HarmonyInstance.Create("test");

            Assert.IsNotNull(instance);

            var patcher = new PatchProcessor(instance, new List <MethodBase> {
                originalMethod
            }, new HarmonyMethod(prefix), null);

            Assert.IsNotNull(patcher);

            patcher.Patch();

            var instance6 = new Class6
            {
                someFloat  = 999,
                someString = "original",
                someStruct = new Class6Struct()
                {
                    d1 = 1, d2 = 2, d3 = 3
                }
            };
            var res = instance6.Method6();

            Assert.AreEqual(123, res.Item1);
            Assert.AreEqual("patched", res.Item2);
            Assert.AreEqual(10.0, res.Item3.d1);
        }