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 


I can't figure out how to read/write to R8W

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

Joined: 20 Mar 2015
Posts: 2
Location: San Jose, California

PostPosted: Wed Mar 13, 2024 3:45 pm    Post subject: I can't figure out how to read/write to R8W Reply with quote

Hi, I'm writing a script to nullify damage against the player but allow damage against enemies. I wrote the script successfully in assembly with the auto assembler but now I would like to try the same cheat using LUA. The issue I have is that when I try to read from or write to R8W it fails. This is what I have at the breakpoint, should be pretty simple so i know I must be missing something:

Code:
function debugger_onBreakpoint()
  if (dec2Hex(RIP) == damageBP) then
    local targetBase = getAddress(RCX)
    local playerBase = getAddressSafe'[playerBasePtr]'
    if (targetBase == playerBase) then
      local fufu = writeSmallInteger(R8W, 0)
      print('fufu  ' .. tostring(fufu))
    end
  end
  debug_continueFromBreakpoint(co_run)
  return 1
end


I had also tried using getaddress to get the R8W address to read/write but that fails as well, or at least I'm using it wrong. Anyhow, I'm a bit stuck so any advice would be appreciated
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4307

PostPosted: Wed Mar 13, 2024 4:29 pm    Post subject: Reply with quote

r8w is just the lower 16 bits of the 64-bit r8 register.

writeSmallInteger takes an address. R8W is a 16-bit value- not an address. If you want to change the register, then modify the variable and CE will change the thread context after the Lua function returns.

Use debug_setBreakpoint callback, not debugger_onBreakpoint. No need to return anything or use debug_continueFromBreakpoint either with the callback.
Code:
debug_setBreakpoint(damageBP, function()
  local targetBase = RCX
  local playerBase = readPointer'playerBasePtr'
  if (targetBase == playerBase) then
    R8 = 0
  end
end)

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

Joined: 20 Mar 2015
Posts: 2
Location: San Jose, California

PostPosted: Wed Mar 13, 2024 4:34 pm    Post subject: Reply with quote

Aha! Yes, I was just trying to learn about the R8-R15 registers. But I was thinking I would need an offset from R8 to write to R8W.
Also, I appreciate your advice on how to write this more efficiently. Thank you! This really does help me understand the problem and I appreciate your time Very Happy
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