Exemplo n.º 1
0
        protected override bool PrepareAsm(out IEnumerable <string> assembly)
        {
            byte[] luaJumpBytes = Encoding.ASCII.GetBytes("JumpOrAscendStart();AscendStop()");

            uint memoryNeeded = (uint)(4 + 40 + luaJumpBytes.Length + 1);

            if (MemoryApi.AllocateMemory(memoryNeeded, out IntPtr memory))
            {
                ExecuteAddress = memory;
                CommandAddress = ExecuteAddress + 4;
                DataAddress    = CommandAddress + 40;

                MemoryApi.WriteBytes(CommandAddress, luaJumpBytes);

                IntPtr distancePointer = DataAddress;
                IntPtr startPointer    = IntPtr.Add(distancePointer, 0x4);
                IntPtr endPointer      = IntPtr.Add(startPointer, 0xC);
                IntPtr resultPointer   = IntPtr.Add(endPointer, 0xC);

                assembly = new List <string>()
                {
                    "X:",
                    $"TEST DWORD [{ExecuteAddress}], 1",
                    "JE @out",
                    "PUSH 0",
                    "PUSH 0x120171",
                    $"PUSH {distancePointer}",
                    $"PUSH {resultPointer}",
                    $"PUSH {endPointer}",
                    $"PUSH {startPointer}",
                    $"CALL {OffsetList.FunctionTraceline}",
                    "ADD ESP, 0x18",
                    "TEST AL, 1",
                    "JE @out",
                    "PUSH 0",
                    $"PUSH {CommandAddress}",
                    $"PUSH {CommandAddress}",
                    $"CALL {OffsetList.FunctionLuaDoString}",
                    "ADD ESP, 0xC",
                    $"MOV DWORD [{ExecuteAddress}], 0",
                    "@out:",
                    "RET"
                };

                return(true);
            }

            assembly = Array.Empty <string>();
            return(false);
        }
Exemplo n.º 2
0
        protected override bool PrepareAsm(out IEnumerable <string> assembly)
        {
            byte[] luaBytes    = Encoding.ASCII.GetBytes(Lua);
            byte[] luaVarBytes = Encoding.ASCII.GetBytes(VarName);

            uint memoryNeeded = (uint)(4 + luaBytes.Length + 1 + luaVarBytes.Length + 1);

            if (MemoryApi.AllocateMemory(memoryNeeded, out IntPtr memory))
            {
                ReturnAddress  = memory;
                CommandAddress = ReturnAddress + 4;
                VarAddress     = CommandAddress + luaBytes.Length + 1;

                MemoryApi.WriteBytes(CommandAddress, luaBytes);
                MemoryApi.WriteBytes(VarAddress, luaVarBytes);

                assembly = new List <string>()
                {
                    "X:",
                    "PUSH 0",
                    $"PUSH {CommandAddress}",
                    $"PUSH {CommandAddress}",
                    $"CALL {OffsetList.FunctionLuaDoString}",
                    "ADD ESP, 0xC",
                    $"CALL {OffsetList.FunctionGetActivePlayerObject}",
                    "MOV ECX, EAX",
                    "PUSH -1",
                    $"PUSH {VarAddress}",
                    $"CALL {OffsetList.FunctionGetLocalizedText}",
                    $"MOV DWORD [{ReturnAddress}], EAX",
                    $"RET"
                };

                return(true);
            }

            assembly = Array.Empty <string>();
            return(false);
        }