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 


Correct way for address pointers and offsets

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Bit Byte
Advanced Cheater
Reputation: 0

Joined: 28 Nov 2022
Posts: 62

PostPosted: Sat Jul 29, 2023 4:40 am    Post subject: Correct way for address pointers and offsets Reply with quote

I have this c#:

Code:
Entity= Memory.GetPointerAddress64Bit(ModuleBase + 0x1CBBA78, new int[] { 0x308, 0x8, 0 }, 3);


In CE script I can write same thing:
Code:
local Entity = readInteger('[[[game.exe+1CBBA78]+308]+8]+0')

Now using from above I have c#:
Code:
EnemyHp = Memory.GetPointerAddress64Bit(Entity+ 0x1a8, new int[] { 0x28 }, 1);


My question which one or any other correct way to write in CE Script:

Code:
local EnemyHp = readInteger('[[[[[game.exe+1CBBA78]+308]+8]+0]+1A8]+28')


or

Code:
local EnemyHp = readInteger('[[Entity]+1A8]+28')


or

Code:
local EnemyHp = readInteger('[Entity+1A8]+28')
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1069
Location: 0x90

PostPosted: Sat Jul 29, 2023 6:54 am    Post subject: Reply with quote

I would use getAddress():
Code:

local Entity = getAddress('[[[game.exe+1CBBA78]+308]+8]+0')
local EnemyHP = getAddress('[[' .. Entity .. ']+1A8]+28')


Perhaps there are other ways. But I like this method; I find it makes for easier reading.
Back to top
View user's profile Send private message
Bit Byte
Advanced Cheater
Reputation: 0

Joined: 28 Nov 2022
Posts: 62

PostPosted: Sat Jul 29, 2023 7:38 am    Post subject: Reply with quote

Would both these return the same value?:

Code:
local EnemyHP = getAddress('[[Entity]+1A8]+28')

Code:
local EnemyHp = getAddress('[[[[[game.exe+1CBBA78]+308]+8]+0]+1A8]+28')



How might I see in console?
Also would creating a pointer like this work?



Pointer.JPG
 Description:
 Filesize:  26.22 KB
 Viewed:  3464 Time(s)

Pointer.JPG


Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1069
Location: 0x90

PostPosted: Sat Jul 29, 2023 9:10 am    Post subject: Reply with quote

If 'Entity' was a registered symbol to a valid address then yes, otherwise no.

Use print:
Code:

local EnemyHp = getAddress('[[[[[game.exe+1CBBA78]+308]+8]+0]+1A8]+28')
print(string.format('%X', EnemyHp))
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4700

PostPosted: Sat Jul 29, 2023 11:21 am    Post subject: This post has 1 review(s) Reply with quote

a2z wrote:
readInteger('[Entity+1A8]+28')
The argument you're passing to readInteger is a string. Writing a variable name in a string isn't going to do anything magical. It's just going to be a string with a variable name in it.
Code:
local foo = 5
print('foo')  -- prints `foo`
print(foo)    -- prints `5`

LeFiXER wrote:
Code:
local EnemyHP = getAddress('[[' .. Entity .. ']+1A8]+28')
`Entity` is an integer. The string concatenation operation `..` converts integers to their decimal string representation. CE assumes it should be hexadecimal.

I'm going to answer the first post based on this pointer path being valid:
Code:
local EnemyHp = readInteger('[[[[[game.exe+1CBBA78]+308]+8]+0]+1A8]+28')
Also:
a2z wrote:
Code:
local Entity = readInteger('[[[game.exe+1CBBA78]+308]+8]+0')
`Entity` is a node in the pointer path. It should really be readPointer not readInteger.

You could use string.format:
Code:
local EnemyHp = readInteger(('[%X+1A8]+28'):format(Entity))
But converting to a string just so CE can convert it back to an integer is a little weird.
readPointer would be more appropriate but perhaps less ergonomic the more offsets you have:
Code:
local EnemyHp = readInteger(readPointer(Entity+0x1A8)+0x28)


If you're doing this often, maybe write a helper function:
Code:
function traversePointerPath(baseAddress, offsets)
  local node = baseAddress
  for _,o in ipairs(offsets) do
    node = readPointer(node) + o
  end
  return node
end

-- NB: in the pointer path `[game.exe+1234]+3C`, the base address is _not_ `game.exe` and
-- the first offset is _not_ 0x1234: they're `game.exe+1234` and 0xC3 respectively
-- similar story here
local EnemyHP = readInteger(traversePointerPath(Entity+0x1A8, {0x28}))

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1069
Location: 0x90

PostPosted: Sat Jul 29, 2023 3:01 pm    Post subject: Reply with quote

ParkourPenguin wrote:

LeFiXER wrote:
Code:
local EnemyHP = getAddress('[[' .. Entity .. ']+1A8]+28')
`Entity` is an integer. The string concatenation operation `..` converts integers to their decimal string representation. CE assumes it should be hexadecimal.


Makes sense since I format the address as a hex string anyway. Either way, it's good to know. Thanks for the tip! It's highly appreciated.
Back to top
View user's profile Send private message
Bit Byte
Advanced Cheater
Reputation: 0

Joined: 28 Nov 2022
Posts: 62

PostPosted: Sun Jul 30, 2023 5:41 am    Post subject: Reply with quote

Thank you guys for the help.
Why is EnemyHp1 & EnemyHp2 having 2 different outputs:



test.JPG
 Description:
 Filesize:  44.53 KB
 Viewed:  3342 Time(s)

test.JPG


Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1069
Location: 0x90

PostPosted: Sun Jul 30, 2023 1:04 pm    Post subject: Reply with quote

Because EnemyHp2 is adding offsets to the address rather than adding to the address value held at the address.
Back to top
View user's profile Send private message
Bit Byte
Advanced Cheater
Reputation: 0

Joined: 28 Nov 2022
Posts: 62

PostPosted: Mon Jul 31, 2023 5:14 am    Post subject: Reply with quote

LeFiXER wrote:
Because EnemyHp2 is adding offsets to the address rather than adding to the address value held at the address.


Ok, what is being done here:
Code:
Entity = Memory.GetPointerAddress64Bit(ModuleBase + 0x1CBBA78, new int[] { 0x308, 0x8, 0 }, 3);


Code:
IntPtr EnemyHp = Memory.GetPointerAddress64Bit(Entity + 0x1a8, new int[] { 0x28 }, 1);


Is EnemyHp adding offsets to the address or address value held at the address?
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1069
Location: 0x90

PostPosted: Mon Jul 31, 2023 9:10 am    Post subject: Reply with quote

I'm unfamiliar with C# and the functions used by the Memory module so cannot explain exactly what's happening. Although from a glance it appears to take several arguments as described here:
Code:

Memory.GetPointerAddress64Bit(address, array_of_offsets, offset_count)

Which then would loop through the array adding the offset to each value returned by the function.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting 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