예제 #1
0
 public void H2HIL()
 {
     Setup();
     h2.Apply();
     hIL.Apply();
     DoNothing();
     Assert.False(h1Run);
     Assert.True(h2Run);
     Assert.True(hILRun);
     hIL.Undo();
     h2.Undo();
     TearDown();
 }
예제 #2
0
 public override void ChangeState(bool enable)
 {
     if (enable != _currentlyHooked)
     {
         if (enable)
         {
             _removeVeinDecrementHook.Apply();
         }
         else
         {
             _removeVeinDecrementHook.Undo();
         }
         _currentlyHooked = enable;
     }
 }
예제 #3
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;
     }
 }
예제 #4
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);
        }