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 


Why do I have to use multiple brackets to reuse a symbol

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

Joined: 28 May 2020
Posts: 8

PostPosted: Tue Feb 14, 2023 6:34 pm    Post subject: Why do I have to use multiple brackets to reuse a symbol Reply with quote

Let's say I have two scripts.
In script A I set a symbol called symbolA, and then I want to reuse that symbol in script B.

So, script A:

Code:

[ENABLE]
alloc(symbol, 4)
registersymbol(symbol)

symbol:
  dd (float)1.5

[DISABLE]

unregistersymbol(*)
dealloc(*)


And then, when I want to use that symbol in script B, let's say to multiply xmm0:

Code:

mulss xmm0, symbol // This doesn't compile, all good!
mulss xmm0, [symbol] // This should work, right? Well, [symbol] is being interpreted as the ADDRESS of symbol, not the value!
mulss xmm0, [[symbol]] // Following the previous logic, this does work!


Why is this the case? I expected [symbol] to contain the value (float)1.5, since that would be the case in script A.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4706

PostPosted: Tue Feb 14, 2023 7:20 pm    Post subject: Reply with quote

`mulss xmm0, [symbol]` is correct. You're doing something wrong.

This works as expected w/ your script A:
Code:
[ENABLE]
{$lua}
assert(getAddressSafe'symbol', 'Enable the other script first')
{$asm}
alloc(newmem,4096,symbol)
label(multiplier)

newmem:
  movss xmm0,[symbol]
  mulss xmm0,[multiplier]
  movss [symbol],xmm0
  ret

newmem+800:
multiplier:
  dd (float)2.0

createthreadandwait(newmem,1000)

[DISABLE]
dealloc(*)

Try clearing the userdefined symbols (Memory Viewer -> View -> Userdefined symbols) and restarting CE.

_________________
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
Sp4rt
How do I cheat?
Reputation: 0

Joined: 28 May 2020
Posts: 8

PostPosted: Tue Feb 14, 2023 9:54 pm    Post subject: Reply with quote

Hey, thanks for the response! I tried all sorts of things and it keeps working ONLY with [[symbol]], just to be sure though, what CE version are you using? I tried it on 7.5 and 7.4.

EDIT: Actually you're right, with your example it does work with [symbol], hmmm.. alright
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25807
Location: The netherlands

PostPosted: Wed Feb 15, 2023 12:39 am    Post subject: Reply with quote

Code:

mulss xmm0, [symbol]

will fail if the distance is greater than 2gb

to deal with this first load the address into a register

Code:

mov rax,symbol
mulss xmm0,[rax]

that way the code works regardless of where it is located

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4706

PostPosted: Wed Feb 15, 2023 1:31 am    Post subject: Reply with quote

Longer explanation of RIP-relative addressing:
https://forum.cheatengine.org/viewtopic.php?t=620587

There's still no way [[symbol]] would work if that were the problem. Unless of course OP didn't test if it actually works. Just because an instruction assembles doesn't mean it does what you expect it to do.

_________________
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
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine 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