Difference between revisions of "Lua:registerAutoAssemblerTemplate"

From Cheat Engine
Jump to navigation Jump to search
m (Reverted edits by This content is not available (Talk) to last revision by Dark Byte)
Line 1: Line 1:
 
[[Category:Lua]]
 
[[Category:Lua]]
'''function''' registerAutoAssemblerTemplate(''name'',''function'')
+
'''function''' registerAutoAssemblerTemplate(''Name'', ''Callback'', [''Shortcut'']) ''':''' id
  
Registers a template to be used with the auto assembler window template menu
+
Registers a template for the Auto Assembler window in Cheat Engine. 
 +
The callback function receives the current script as a TStrings object and the sender form. 
 +
All script parsing and template logic is handled by your callback. 
 +
Returns an ID that can be used to unregister the template if needed.
  
Returns an ID you can use with [[Lua:unregisterAutoAssemblerTemplate|unregisterAutoAssemblerTemplate]]
+
===Function Parameters===
 
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 
 
 
 
== Function Parameters ==
 
{|width="85%" cellpadding="10%" cellpadding="5%" cellspacing="0" border="0"
 
 
!align="left"|Parameter
 
!align="left"|Parameter
 
!align="left"|Type
 
!align="left"|Type
 
!style="width: 80%;background-color:white;" align="left"|Description
 
!style="width: 80%;background-color:white;" align="left"|Description
 
|-
 
|-
|name
+
|Name
 
|String
 
|String
|The command string it self
+
|The name of the template as it appears in the Auto Assembler's template menu.
 +
|-
 +
|Callback
 +
|Function
 +
|A function with the signature <code>function(script: TStrings, sender: TFrmAutoInject)</code> that is called when the template is selected. <br> <code>script</code> is a TStrings object directly connected to the current script.
 
|-
 
|-
|function
+
|Shortcut
|function(script, sender)
+
|String (optional)
|The function called when the user picks the script. (script is a StringList object. sender is a frmAutoInject object)
+
|A keyboard shortcut for the template (e.g., "Ctrl+Alt+T"). Optional.
 
|}
 
|}
  
== Examples ==
+
===Returns===
registerAutoAssemblerTemplate('Better AOBScan script generator',function(script, sender)
+
The ID of the registered template (useful for [[Lua:unregisterAutoAssemblerTemplate|unregisterAutoAssemblerTemplate]]).
   print("Do something with the script")
+
 
  script.add('//this is added by my script. Your script was '..script.Count..' lines long before this was added')
+
===Examples===
   script.add(string.format("//%.8x is the address you had selected in the disassembler", getMemoryViewForm().DisassemblerView.SelectedAddress))
+
<pre>
end )
+
-- Register a simple template that inserts a comment at the top of the script
 +
local templateID = registerAutoAssemblerTemplate("Insert Comment", function(script, sender)
 +
   script.insert(0, "-- Inserted by template!")
 +
end)
 +
 
 +
-- Register a template with a shortcut
 +
registerAutoAssemblerTemplate("NOP All", function(script, sender)
 +
   script.text = "[ENABLE]\nalloc(newmem,$1000)\nlabel(return)\nnewmem:\nnop\njmp return\n[DISABLE]\n", sender
 +
end, "Ctrl+Alt+N")
 +
</pre>
  
 
{{LuaSeeAlso}}
 
{{LuaSeeAlso}}

Revision as of 00:20, 11 July 2025

function registerAutoAssemblerTemplate(Name, Callback, [Shortcut]) : id

Registers a template for the Auto Assembler window in Cheat Engine. The callback function receives the current script as a TStrings object and the sender form. All script parsing and template logic is handled by your callback. Returns an ID that can be used to unregister the template if needed.

Function Parameters

Parameter Type Description
Name String The name of the template as it appears in the Auto Assembler's template menu.
Callback Function A function with the signature function(script: TStrings, sender: TFrmAutoInject) that is called when the template is selected.
script is a TStrings object directly connected to the current script.
Shortcut String (optional) A keyboard shortcut for the template (e.g., "Ctrl+Alt+T"). Optional.

Returns

The ID of the registered template (useful for unregisterAutoAssemblerTemplate).

Examples

-- Register a simple template that inserts a comment at the top of the script
local templateID = registerAutoAssemblerTemplate("Insert Comment", function(script, sender)
  script.insert(0, "-- Inserted by template!")
end)

-- Register a template with a shortcut
registerAutoAssemblerTemplate("NOP All", function(script, sender)
  script.text = "[ENABLE]\nalloc(newmem,$1000)\nlabel(return)\nnewmem:\nnop\njmp return\n[DISABLE]\n", sender
end, "Ctrl+Alt+N")

See also

Related Functions