Lua:onAutoGuess

From Cheat Engine
(Redirected from onAutoGuess)
Jump to navigation Jump to search

<> Lua API Reference

function onAutoGuess(callback) : void

Registers a callback function that is called whenever Cheat Engine's auto guess feature is used to predict a variable type.

The callback can override the guessed variable type by returning a different value type. If the guess should not be changed, return the provided ceguess value.

Function Parameters[edit]

Parameter Type Description
callback Function The function to call when Cheat Engine auto-guesses a variable type.

Returns[edit]

This function does not return a value.

Callback Parameters[edit]

Parameter Type Description
address Integer The address for which Cheat Engine is guessing the variable type.
ceguess ValueType The variable type guessed by Cheat Engine.

Callback Return Value[edit]

Return Type Description
ValueType Return the variable type that should be used. Return ceguess if the guessed type should not be changed.

Common Value Types[edit]

Constant Description
vtByte Byte value.
vtWord 2-byte value.
vtDword 4-byte integer value.
vtQword 8-byte integer value.
vtSingle 4-byte floating-point value.
vtDouble 8-byte floating-point value.
vtString String value.
vtPointer Pointer value.

Examples[edit]

Keep Cheat Engine's guessed type[edit]

1 onAutoGuess(function(address, ceguess)
2   return ceguess
3 end)

Force all guesses to 4-byte[edit]

1 onAutoGuess(function(address, ceguess)
2   return vtDword
3 end)

Override guesses for a specific address range[edit]

 1 onAutoGuess(function(address, ceguess)
 2   local startAddress = getAddress("game.exe+1000")
 3   local endAddress = getAddress("game.exe+2000")
 4 
 5   if address >= startAddress and address <= endAddress then
 6     return vtSingle
 7   end
 8 
 9   return ceguess
10 end)

Treat pointer-looking addresses as pointers[edit]

1 onAutoGuess(function(address, ceguess)
2   local value = readPointer(address)
3 
4   if value ~= nil and value ~= 0 then
5     return vtPointer
6   end
7 
8   return ceguess
9 end)

Log auto guess activity[edit]

1 onAutoGuess(function(address, ceguess)
2   print(string.format("Auto guess at %X: %s", address, tostring(ceguess)))
3 
4   return ceguess
5 end)

Use a named callback function[edit]

1 local function autoGuessOverride(address, ceguess)
2   if ceguess == vtDword then
3     return vtQword
4   end
5 
6   return ceguess
7 end
8 
9 onAutoGuess(autoGuessOverride)

Only override unknown or unwanted guesses[edit]

1 onAutoGuess(function(address, ceguess)
2   if ceguess == nil then
3     return vtDword
4   end
5 
6   return ceguess
7 end)

Main Pages

Core Lua documentation entry points

Lua
Script Engine