Example #1
0
    public override void Enable(GameContext ctx)
    {
        int off = GetOffset(ctx, "Terraria.Entity", "position");
        var ass = AssemblySnippet.FromCode(
            new AssemblyCode[] {
            Instruction.Create("pushad"),
            Instruction.Create($"cmp byte ptr [{ctx.MapFullScreen_Address}],0"),
            Instruction.Create("je _rwualfna"),
            Instruction.Create($"cmp byte ptr [{ctx.MouseRight_Address}],0"),
            Instruction.Create("je _rwualfna"),
            Instruction.Create($"cmp byte ptr [{ctx.MouseRightRelease_Address}],0"),
            Instruction.Create("je _rwualfna"),
            AssemblySnippet.FromCode(
                new AssemblyCode[] {
                Instruction.Create($"mov byte ptr [{ctx.MapFullScreen_Address}],0"),
                Instruction.Create($"mov byte ptr [{ctx.MouseRightRelease_Address}],0"),
                AssemblySnippet.FromClrCall(
                    ctx.GameModuleHelper.GetFunctionAddress("Terraria.Main", "get_LocalPlayer"), false, null, null, null, Array.Empty <object>()),
                Instruction.Create("mov ebx,eax"),
                Instruction.Create("push eax"),
                Instruction.Create("mov dword ptr [esp],2"),
                Instruction.Create($"fild dword ptr [{ctx.ScreenWidth_Address}]"),
                Instruction.Create("fild dword ptr [esp]"),
                Instruction.Create("fdivp"),
                Instruction.Create($"fild dword ptr [{ctx.MouseX_Address}]"),
                Instruction.Create("fsubp"),
                Instruction.Create($"fld dword ptr [{ctx.MapFullScreenScale_Address}]"),
                Instruction.Create("fdivp"),
                Instruction.Create($"fld dword ptr [{ctx.MapFullscreenPos_Address + 4}]"),
                Instruction.Create("fsubrp"),
                Instruction.Create("mov dword ptr [esp],16"),
                Instruction.Create("fild dword ptr [esp]"),
                Instruction.Create("fmulp"),
                Instruction.Create($"fstp dword ptr [ebx+{off}]"),
                Instruction.Create("mov dword ptr [esp],2"),
                Instruction.Create($"fild dword ptr [{ctx.ScreenHeight_Address}]"),
                Instruction.Create("fild dword ptr [esp]"),
                Instruction.Create("fdivp"),
                Instruction.Create($"fild dword ptr [{ctx.MouseY_Address}]"),
                Instruction.Create("fsubp"),
                Instruction.Create($"fld dword ptr [{ctx.MapFullScreenScale_Address}]"),
                Instruction.Create("fdivp"),
                Instruction.Create($"fld dword ptr [{ctx.MapFullscreenPos_Address + 8}]"),
                Instruction.Create("fsubrp"),
                Instruction.Create("mov dword ptr [esp],16"),
                Instruction.Create("fild dword ptr [esp]"),
                Instruction.Create("fmulp"),
                Instruction.Create($"fstp dword ptr [ebx+{off + 0x4}]"),

                Instruction.Create("pop eax"),
            }),
            Instruction.Create("_rwualfna:"),
            Instruction.Create("popad")
        });
        HookParameters ps = new HookParameters(ctx.GameModuleHelper.GetFunctionAddress("Terraria.Main", "Update") + 5, 4096);

        InlineHook.Hook(ctx.HContext, ass, ps);
    }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EventHook{T}" /> class.
        /// </summary>
        /// <param name="flags">Options.</param>
        /// <param name="key">The key.</param>
        /// <param name="args">The arguments.</param>
        /// <exception cref="System.ArgumentNullException">argFunc</exception>
        public EventHook(EventHookFlags flags, string key, params EventHookParameters <T>[] args) : base(key)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }
            if (args.Any(q => q.ArgFunc == null))
            {
                throw new ArgumentNullException("args[].ArgFunc");
            }

            this.HookFlags = flags;

            this.Arguments = args.ToArray();
            for (int i = 0; i < this.Arguments.Length; i++)
            {
                var a = this.Arguments[i];

                var p = new HookParameters();
                p.Address = a.Address;
                int ix   = i;
                int incl = a.IncludeLength;
                if (incl >= 0)
                {
                    p.Before = cpu => EventHook_Action(cpu, ix);
                }
                else
                {
                    p.After = cpu => EventHook_Action(cpu, ix);
                }
                p.Pattern       = a.Pattern;
                p.IncludeLength = Math.Abs(a.IncludeLength);
                p.ReplaceLength = a.ReplaceLength;

                Memory.WriteHook(p);
            }
        }