Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Need Help to translate c++ into lua

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Shirabrixx
How do I cheat?
Reputation: 0

Joined: 13 Jul 2017
Posts: 8

PostPosted: Sat Jul 21, 2018 12:32 am    Post subject: Need Help to translate c++ into lua Reply with quote

Hi, can maybe anyone help me, to translate this from c++ into lua?!

Code:
GlobalPointer = Game.patternScan("4D 8A 02 ? ? ? ? 4D 8C 08 4C 83 C8 72 15");
GlobalPointer = GlobalPointer + Game.read<int>(GlobalPointer + 3) + 7;

uint64_t getPointer(int index)
{
   return Game.read<uint64_t>(GlobalPointer + (sizeof(uint64_t) * (index >> 0x12 & 0x3F))) + (sizeof(uint64_t) * (index & 0x3FFFF));
}


To get the GlobalPointer I think I am right with this example...

Code:
[ENABLE]
{$lua}
autoAssemble([[
aobscanmodule(GlobalPointer,GTA5.exe,4D 8A 02 ? ? ? ? 4D 8C 08 4C 83 C8 72 15)
registersymbol(GlobalPointer)
]])
local address = getAddress("GlobalPointer")
address = address + readInteger(address + 3) + 7
unregisterSymbol("GlobalPointer")
registerSymbol("GlobalPointer", address, true)

[DISABLE]
unregisterSymbol("GlobalPointer")
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Sat Jul 21, 2018 5:29 am    Post subject: Reply with quote

yeah that should work, though I'd probably use just lua rather than a mix of lua and AA for no stated reason.

Code:
loca res = AOBScan('4D 8A 02 ? ? ? ? 4D 8C 08 4C 83 C8 72 15');
if not res then return 'assert(false)' end -- don't enable if in AA
local GlobalPointer = getAddress(res[0]) -- get first address, as number from string
res.destroy() -- free the list list
-- read 4 bytes (offset) and add to GobalPointer and add 7
GlobalPointer = GlobalPointer + readInteger(GlobalPointer + 3) + 7;
-- potentially register as a symbol if necessary.

getPointer = (function()
  -- closure so type table is only created once
  local uint64_t = 'uint64_t';
  local sizeof = {[uint64_t]=8};
  setmetatable(sizeof,{__call=function(t,k) return t[k] end});
  return function(index)
    local off1 = sizeof(uint64_t) * (index >> 0x12 & 0x3F);
    local off2 = sizeof(uint64_t) * (index & 0x3FFFF);
    if GlobalPointer then -- if in scope
      return readQword(GlobalPointer + off1 + off2);
    else -- if GlobalPointer is not in scope and is a symbol
      return readQword(getAddress('GlobalPointer') + off1 + off2));
    end
  end
end)()
--[[ alternatively just this, but the above is more fun/interesting lol
function getPointer(index)
   return readQword(GlobalPointer + (8 * (index >> 0x12 & 0x3F))) + (8 * (index & 0x3FFFF));
end
]]

_________________
https://github.com/FreeER/ has a few CE related repos
Back to top
View user's profile Send private message
Shirabrixx
How do I cheat?
Reputation: 0

Joined: 13 Jul 2017
Posts: 8

PostPosted: Mon Jul 23, 2018 2:10 pm    Post subject: Reply with quote

FreeER wrote:
yeah that should work, though I'd probably use just lua rather than a mix of lua and AA for no stated reason.

Code:
loca res = AOBScan('4D 8A 02 ? ? ? ? 4D 8C 08 4C 83 C8 72 15');
if not res then return 'assert(false)' end -- don't enable if in AA
local GlobalPointer = getAddress(res[0]) -- get first address, as number from string
res.destroy() -- free the list list
-- read 4 bytes (offset) and add to GobalPointer and add 7
GlobalPointer = GlobalPointer + readInteger(GlobalPointer + 3) + 7;
-- potentially register as a symbol if necessary.

getPointer = (function()
  -- closure so type table is only created once
  local uint64_t = 'uint64_t';
  local sizeof = {[uint64_t]=8};
  setmetatable(sizeof,{__call=function(t,k) return t[k] end});
  return function(index)
    local off1 = sizeof(uint64_t) * (index >> 0x12 & 0x3F);
    local off2 = sizeof(uint64_t) * (index & 0x3FFFF);
    if GlobalPointer then -- if in scope
      return readQword(GlobalPointer + off1 + off2);
    else -- if GlobalPointer is not in scope and is a symbol
      return readQword(getAddress('GlobalPointer') + off1 + off2));
    end
  end
end)()
--[[ alternatively just this, but the above is more fun/interesting lol
function getPointer(index)
   return readQword(GlobalPointer + (8 * (index >> 0x12 & 0x3F))) + (8 * (index & 0x3FFFF));
end
]]


Ty for your help! It works great, after I ve change smth!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites