Difference between revisions of "Lua Debugging"

From Cheat Engine
Jump to navigation Jump to search
(Created page with '== Lua Debugging == There are functions exposed to LUA that enable scripts to control the debugger: * '''openProcess(name)''' - Open a running process * '''debugProcess()''' - …')
 
(debug_continueFromBreakpoint takes an integer)
Line 25: Line 25:
 
         if (EIP ~= 0x00406002) then return 0 end -- ignore user-set breakpoints
 
         if (EIP ~= 0x00406002) then return 0 end -- ignore user-set breakpoints
 
         armors[ECX] = readFloat(ECX+0x60) -- store armor in table
 
         armors[ECX] = readFloat(ECX+0x60) -- store armor in table
         debug_continueFromBreakpoint(":co_run") -- continue execution
+
         debug_continueFromBreakpoint(co_run) -- continue execution
 
         return 1 -- let CE know we handled breakpoint, no need to update debugger form
 
         return 1 -- let CE know we handled breakpoint, no need to update debugger form
 
end
 
end

Revision as of 06:17, 12 December 2011

Lua Debugging

There are functions exposed to LUA that enable scripts to control the debugger:

  • openProcess(name) - Open a running process
  • debugProcess() - Start debugging the open process
  • debug_setBreakpoint(address) - Add a breakpoint at an address
  • debug_continueFromBreakpoint(method) - Continue execution, methods are "co_run", "co_stepinto" and "co_stepover"

(and possibly "co_runtill" which is in TContinueOption but not shown in main.lua).

In addition, you can create the event function debugger_onBreakpoint() that will be called by Cheat Engine whenever a breakpoint is hit.

Here's an example for Space Pirates and Zomies that tracks ships that have their armor decreased. By debugging I found that at 0x406002, ECX has a pointer to a structure with the armor float at 0x60. This code will track those values in the armors table with the key being the address and the value being the actual armor value:

if not armors then
   armors = { }
end

function debugger_onBreakpoint()
         if (EIP ~= 0x00406002) then return 0 end -- ignore user-set breakpoints
         armors[ECX] = readFloat(ECX+0x60) -- store armor in table
         debug_continueFromBreakpoint(co_run) -- continue execution
         return 1 -- let CE know we handled breakpoint, no need to update debugger form
end

openProcess("SpazGame.exe")
debugProcess()
debug_setBreakpoint(0x00406002)