Difference between revisions of "Lua:registerAutoAssemblerTemplate"

From Cheat Engine
Jump to navigation Jump to search
(Created page with 'Category:Lua '''function''' registerAutoAssemblerTemplate(''name'',''function'') Registers a template to be used with the auto assembler window template menu Returns an ID …')
 
(Related Functions)
 
(6 intermediate revisions by 3 users not shown)
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): ID
+
|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.
 
|}
 
|}
  
 +
===Returns===
 +
The ID of the registered template (useful for [[Lua:unregisterAutoAssemblerTemplate|unregisterAutoAssemblerTemplate]]).
  
== Examples ==
+
===Examples===
registerAutoAssemblerTemplate('Better AOBScan script generator',function(script, sender)
+
<pre>
   print("Do something with the script")
+
-- Register a simple template that inserts a comment at the top of the script
end )
+
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}}
Line 36: Line 48:
 
* [[Lua:registerAutoAssemblerPrologue|registerAutoAssemblerPrologue]]
 
* [[Lua:registerAutoAssemblerPrologue|registerAutoAssemblerPrologue]]
 
* [[Lua:unregisterAutoAssemblerPrologue|unregisterAutoAssemblerPrologue]]
 
* [[Lua:unregisterAutoAssemblerPrologue|unregisterAutoAssemblerPrologue]]
* [[Lua:registerAutoAssemblerTemplate|registerAutoAssemblerTemplate]]
 
 
* [[Lua:unregisterAutoAssemblerTemplate|unregisterAutoAssemblerTemplate]]
 
* [[Lua:unregisterAutoAssemblerTemplate|unregisterAutoAssemblerTemplate]]
 
* [[Lua:generateCodeInjectionScript|generateCodeInjectionScript]]
 
* [[Lua:generateCodeInjectionScript|generateCodeInjectionScript]]
 
* [[Lua:generateAOBInjectionScript|generateAOBInjectionScript]]
 
* [[Lua:generateAOBInjectionScript|generateAOBInjectionScript]]
 
* [[Lua:generateFullInjectionScript|generateFullInjectionScript]]
 
* [[Lua:generateFullInjectionScript|generateFullInjectionScript]]

Latest 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[edit]

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[edit]

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

Examples[edit]

-- 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[edit]

Related Functions[edit]