Lua:registerAutoAssemblerCommand

From Cheat Engine
Revision as of 19:20, 13 January 2018 by TheyCallMeTim13 (talk | contribs) (Created page with 'Category:Lua '''function''' registerAutoAssemblerCommand(''Command'', ''Function'''(parameters, syntaxcheckonly)''' '') Registers an auto assembler command to call the speci…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

function registerAutoAssemblerCommand(Command, Function(parameters, syntaxcheckonly) )

Registers an auto assembler command to call the specified function. The command will be replaced by the string this function returns when executed. The function can be called twice. Once for syntax check and symbol lookup (1), and the second time for actual execution by the assembler (2) if it has not been removed in phase 1.

If the function returns nil, and as secondary parameter a string, this will make the auto assembler fail with that error.

Note: You will only get a message pop-up if the Auto Assembler is preforming a syntax check.

The Auto Assembler form syntax highlighter will highlight the registered command.


Function Parameters

Parameter Type Description
Command String The command string it self
Function Function The Lua function to be called when the command string is found in an Auto Assembler script


Callback Function Parameters

Parameter Type Description
parameters String This will be the string between parenthesis after the command string
syntaxcheckonly Boolean This will be true if the script is running though a syntax check

Callback Function Return(s)

Parameter Type Description
ReplaceString String or Nil This will replace the commands line in the Auto Assembler script, can be a multi-line string, if Nil the commands line is removed
ErrorMessage String or Nil (OPTIONAL) if the ReplaceString is nil and this is set to a string then, this will raise an error with the given error message for the command


Examples

Example 1

local t = translate local LineEnd = '\r\n' local ExitOnSyntaxCheck = false local function registerLabel(parameters, syntaxcheck) ---- registerLabel(name) if ExitOnSyntaxCheck and syntaxcheck then return end local le = LineEnd local name = parameters if name == nil then return nil, t('Wrong number of parameters, no "name", for "registerLabel" custom AA command.') end local str = 'label(' .. name .. ')' .. le str = str .. 'registerSymbol(' .. name .. ')' return str end local function unregisterLabel(parameters, syntaxcheck) ---- unregisterLabel(name) if ExitOnSyntaxCheck and syntaxcheck then return end local name = parameters if name == nil then return nil, t('Wrong number of parameters, no "name", for "unregisterLabel" custom AA command.') end local str = 'unregisterSymbol(' .. name .. ')' return str end registerAutoAssemblerCommand('registerLabel', registerLabel) ---- Register the command registerAutoAssemblerCommand('unregisterLabel', unregisterLabel) ---- Register the command ---- Usage in an Auto Assembler script ---------------------------------------------------- -- alloc(memTestMemory, 0x400) -- registerSymbol(memTestMemory) -- registerLabel(memTestMemoryEND) -- memTestMemory: -- db 90 90 90 90 -- memTestMemoryEND: ----------------------------------------------------


Example 2

local t = translate local LineEnd = '\r\n' local ExitOnSyntaxCheck = false local function split(s, delimiter) result = {} for match in (s .. delimiter):gmatch('(.-)' .. delimiter) do table.insert(result, match) end return result end function repeteBytes(parameters, syntaxcheck) ---- repeteBytes(numberOfByte, arrayOfBytes) if ExitOnSyntaxCheck and syntaxcheck then return end local le = LineEnd local args = split(parameters, ',') local numberOfBytes = args[1] if numberOfBytes == nil then return nil, t('Wrong number of parameters, no "numberOfBytes", for "repeteBytes" custom AA command.') end local arrayOfBytes = args[2] if arrayOfBytes == nil then return nil, t('Wrong number of parameters, no "arrayOfBytes", for "repeteBytes" custom AA command.') end arrayOfBytes = arrayOfBytes:upper() if arrayOfBytes:find('#') or arrayOfBytes:find('(INT)') or arrayOfBytes:find('(FLOAT)') or arrayOfBytes:find('(DOUBLE)') then return nil, t('Wrong format of parameters, "arrayOfBytes" must be in hexadecimal format, for "repeteBytes" custom AA command.') end local bc = (#(arrayOfBytes:gsub('0X', ''):gsub('$', ''):gsub(' ', ''))) / 2 numberOfBytes = numberOfBytes:upper():gsub(' ', '') if numberOfBytes:sub(1, 5) == '(INT)' then numberOfBytes = tonumber(numberOfBytes:sub(6)) elseif numberOfBytes:sub(1, 1) == '#' then numberOfBytes = tonumber(numberOfBytes:sub(2)) elseif numberOfBytes:sub(1, 1) == '$' then numberOfBytes = tonumber(numberOfBytes:sub(2), 16) elseif numberOfBytes:sub(1, 2) == '0X' then numberOfBytes = tonumber(numberOfBytes:sub(3), 16) else numberOfBytes = tonumber(numberOfBytes, 16) end if type(numberOfBytes) ~= 'number' then return nil, t('Could not parse "numberOfBytes" for "repeteBytes" custom AA command.') end local str = '' for i = 1, numberOfBytes / bc do str = str .. 'db ' .. arrayOfBytes .. le end return str end registerAutoAssemblerCommand('repeteBytes', repeteBytes) ---- Register the command ---- Usage in an Auto Assembler script ---------------------------------------------------- -- alloc(memTestMemory, 0x400) -- registerSymbol(memTestMemory) -- memTestMemory: -- repeteBytes(0x64, 90 52) ---------------------------------------------------- ---- Memory View Form copy of "memTestMemory" ---------------------------------------------------- -- 0032FFFE - - ?? -- 0032FFFF - - ?? -- memTestMemory- 90 - nop -- 00330001 - 52 - push edx -- 00330002 - 90 - nop -- 00330003 - 52 - push edx -- 00330004 - 90 - nop -- ... -- 00330060 - 90 - nop -- 00330061 - 52 - push edx -- 00330062 - 90 - nop -- 00330063 - 52 - push edx -- 00330064 - 00 00 - add [eax],al ----------------------------------------------------


See also