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 


How to print register value whenever the instruction is bein

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

Joined: 04 Nov 2021
Posts: 2

PostPosted: Thu Nov 04, 2021 12:15 am    Post subject: How to print register value whenever the instruction is bein Reply with quote

[ENABLE]
//code from here to '[DISABLE]' will be used to enable the cheat
alloc(newmem,2048)
label(returnhere)
label(originalcode)
label(exit)

newmem:
mov [eax+00005578],ecx
????
....

code inject / How to print [eax] to console

I have just started learning CE so simple answers will be appreciated, thanks.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4696

PostPosted: Thu Nov 04, 2021 1:46 am    Post subject: Reply with quote

Maybe using "Find out what addresses this instruction accesses" in the right click menu of the disassembler would be better?

You could use the new {$luacode} feature.
https://forum.cheatengine.org/viewtopic.php?t=618134

_________________
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: Thu Nov 04, 2021 1:52 am    Post subject: Reply with quote

You should use code tags when posting code.

(code)
... code here ...
(/code)

Note: replace parentheses "()" with square brackets "[]"

One way you can achieve this is like so:
Code:

[ENABLE]
...
alloc(newmem,2048)
alloc(registerToConsole,8) // use 4 if 32-bit

label(returnhere)
label(originalcode)
label(exit)

newmem:
mov [eax+00005578],ecx
mov [registerToConsole],eax

return:
// ...
{$LUA}
local eax = getAddressSafe('[registerToConsole]')
print(string.format("%X", eax))
{$ASM}
//...
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

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

PostPosted: Thu Nov 04, 2021 5:25 am    Post subject: This post has 1 review(s) Reply with quote

Code:


[ENABLE]
//code from here to '[DISABLE]' will be used to enable the cheat
alloc(newmem,2048)
label(returnhere)
label(originalcode)
label(exit)

newmem:
mov [eax+00005578],ecx
{$luacode r1=eax r2=ecx}
printf("eax=%x ecx=%x address=%x", r1,r2,r1+0x5578)
{$asm}
...

_________________
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
MH00
Newbie cheater
Reputation: 0

Joined: 29 Jul 2024
Posts: 10
Location: Ohio

PostPosted: Mon Oct 07, 2024 9:20 am    Post subject: Does not work for me. Reply with quote

I tried $luacode after newmem: but got popup error and could not assign to the table - so I commented out that code.
Crying or Very sad

I tried $lua after return: - got the print when assign to the table but it does not ever execute when the exe runs. I used debug to step and it does jmp to the inject point, does the one instruction and then jmp back to main code. I did not see any sign of code of lua print.
Code:

newmem:
//{$luacode rrv1=rax rrv2=r14}
//-- printf('20  rax =%x r14 =%x', rrv1,rrv2 )
//print('  start lua')
//{$asm}

code:
  inc [rax+r14*4+08]
  jmp return

INJECT20:
  jmp newmem
return:
{$lua}
print('  start lua')
{$asm}


What am I missing? What do I need to do to do a simple print value of a register in my CT??


[/list]



LUASYN2.gif
 Description:
 Filesize:  12.14 KB
 Viewed:  11537 Time(s)

LUASYN2.gif


Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

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

PostPosted: Mon Oct 07, 2024 1:06 pm    Post subject: Reply with quote

execute it once regardless of the error
_________________
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
MH00
Newbie cheater
Reputation: 0

Joined: 29 Jul 2024
Posts: 10
Location: Ohio

PostPosted: Fri Oct 11, 2024 8:17 am    Post subject: Crash the browser Reply with quote

I tried that and the browser crashed. I used the debugger - jmp to the inject, then call to routine which saved to the stack then call to another routine which caused the window to disappear because the browser crashed.
I can copy the code if you wish to see this part.
Back to top
View user's profile Send private message
MH00
Newbie cheater
Reputation: 0

Joined: 29 Jul 2024
Posts: 10
Location: Ohio

PostPosted: Thu Oct 24, 2024 11:27 pm    Post subject: Reply with quote

The browser crashes when I try to use $luacode - what am I missing or what am I doing wrong that there is a complete crash when I try to do a simple print inside $luacode section??

Also - how do I get $lua to work with every inject code instead of only when I inject but not with each invoke of the injection? What am I miswing or doing wrong to be able to use $lua??
Back to top
View user's profile Send private message
jgoemat
Master Cheater
Reputation: 23

Joined: 25 Sep 2011
Posts: 264

PostPosted: Fri Jan 24, 2025 11:34 pm    Post subject: Reply with quote

Wow, learning something new every day! {luacode} worked fine for me, just tried it with a function I was hooking in 7 days to die. It's executed each frame, so I did this right after enable:

Code:
[enable]

{$lua}
lc = 0
{$asm}


Then in the injection:

Code:
newmem:
{$luacode r1=ecx}
lc = lc + 1
if lc > 100 then
  printf("ecx=%x", r1)
  lc = 0
end
{$asm}


No errors for me, I'm using CE 7.6.0 if that matters.

The normal {$lua} ... {$asm} block only executes when the script is syntax checked when saving or when the code is assembled, not each time the injected code is called by the game.
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