示例#1
0
 public void HIL()
 {
     Setup();
     hIL.Apply();
     DoNothing();
     Assert.False(h1Run);
     Assert.False(h2Run);
     Assert.True(hILRun);
     TearDown();
 }
示例#2
0
        /// <summary>Applies the patch</summary>
        ///
        public void Patch(HarmonyReversePatchType type = HarmonyReversePatchType.Original)
        {
            if (original == null)
            {
                throw new NullReferenceException($"Null method for {instance.Id}");
            }

            // TODO: Wrapped type (do we even need it?)
            ilHook.Apply();
        }
示例#3
0
        // Awake is called once when both the game and the plug-in are loaded
        void Awake()
        {
            InitConfig();

            UnityEngine.Debug.Log("UILayoutHeightFix Plugin Loaded!");

            _changeFixUILayoutHeightILHook.Apply();

            //harmony = new Harmony(VersionInfo.BEPINEX_FQDN_ID);
            //harmony.PatchAll();

            //GameOption_Import.OverrideLayoutHeight();
        }
示例#4
0
        public override void Apply()
        {
            if (ilHook == null)
            {
                ilHook = new ILHook(Original, Manipulator, new ILHookConfig
                {
                    ManualApply = true
                });
            }

            // Reset IsApplied to force MonoMod to reapply the ILHook without removing it
            SetIsApplied(ilHook, false);
            ilHook.Apply();
        }
示例#5
0
        static void Main(string[] args)
        {
            Program a = new Program();

            a.Tester(10);
            a.Tester(1000);
            a.Tester(4000);

            _changeWalkSpeedHook.Apply();

            a.Tester(10);
            a.Tester(1000);
            a.Tester(4000);
        }
示例#6
0
 public override void ChangeState(bool enable)
 {
     if (enable != _currentlyHooked)
     {
         if (enable)
         {
             _removeVeinDecrementHook.Apply();
         }
         else
         {
             _removeVeinDecrementHook.Undo();
         }
         _currentlyHooked = enable;
     }
 }
示例#7
0
 /// <inheritdoc />
 public override MethodBase DetourTo(MethodBase replacement)
 {
     ilHook ??= new ILHook(Original, Manipulator, new ILHookConfig {
         ManualApply = true
     });
     // Reset IsApplied to force MonoMod to reapply the ILHook without removing it
     SetIsApplied(ilHook, false);
     try
     {
         ilHook.Apply();
     }
     catch (Exception e)
     {
         throw HarmonyException.Create(e, hookBody);
     }
     return(ilHook.GetCurrentTarget());
 }
示例#8
0
 public override void ChangeState(bool enable)
 {
     if (enable != _currentlyHooked)
     {
         if (enable)
         {
             _takeItemsHook.Apply();
             _okButtonHook.Apply();
             _refreshIconsHook.Apply();
             _replicatorWindowUpdateHook.Apply();
         }
         else
         {
             _takeItemsHook.Undo();
             _okButtonHook.Undo();
             _refreshIconsHook.Undo();
             _replicatorWindowUpdateHook.Undo();
         }
         _currentlyHooked = enable;
     }
 }
示例#9
0
        public void TestMultiHooks()
        {
            Counter = 1;
            DoNothing();
            Assert.Equal(1, Counter);

            using (Hook h1 = new Hook(
                       typeof(MultiHookTest).GetMethod("DoNothing"),
                       new Action <Action <MultiHookTest>, MultiHookTest>((orig, self) => {
                orig(self);
                Counter += 2;
            }),
                       new HookConfig {
                ManualApply = true
            }
                       ))
                using (Hook h2 = new Hook(
                           typeof(MultiHookTest).GetMethod("DoNothing"),
                           new Action <Action <MultiHookTest>, MultiHookTest>((orig, self) => {
                    orig(self);
                    Counter *= 2;
                }),
                           new HookConfig {
                    ManualApply = true
                }
                           ))
                    using (ILHook hIL = new ILHook(
                               typeof(MultiHookTest).GetMethod("DoNothing"),
                               il => {
                        ILCursor c = new ILCursor(il);
                        FieldInfo f_Counter = typeof(MultiHookTest).GetField("Counter", BindingFlags.NonPublic | BindingFlags.Instance);
                        c.Emit(OpCodes.Ldarg_0);
                        c.Emit(OpCodes.Dup);
                        c.Emit(OpCodes.Ldfld, f_Counter);
                        c.Emit(OpCodes.Ldc_I4_3);
                        c.Emit(OpCodes.Mul);
                        c.Emit(OpCodes.Stfld, f_Counter);
                    },
                               new ILHookConfig {
                        ManualApply = true
                    }
                               )) {
                        Counter = 1;
                        DoNothing();
                        Assert.Equal(1, Counter);

                        hIL.Apply();
                        h1.Apply();
                        Counter = 1;
                        DoNothing();
                        Assert.Equal((1 * 3) + 2, Counter);
                        h1.Undo();
                        hIL.Undo();

                        h2.Apply();
                        hIL.Apply();
                        Counter = 1;
                        DoNothing();
                        Assert.Equal((1 * 3) * 2, Counter);
                        hIL.Undo();
                        h2.Undo();

                        h1.Apply();
                        hIL.Apply();
                        h2.Apply();
                        Counter = 1;
                        DoNothing();
                        Assert.Equal(((1 * 3) + 2) * 2, Counter);
                        h2.Undo();
                        hIL.Undo();
                        h1.Undo();

                        Counter = 1;
                        DoNothing();
                        Assert.Equal(1, Counter);
                    }

            Counter = 1;
            DoNothing();
            Assert.Equal(1, Counter);
        }