Difference between revisions of "Lua:autoAssemble"

From Cheat Engine
Jump to navigation Jump to search
(Did I forgot to mention this wiki has syntax highlighting now?)
m (Syntax Highlighting.)
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
[[Category:Lua]]
 
[[Category:Lua]]
−
[[Category:Assembler]]
+
{{CodeBox|'''function''' autoAssemble(''text'', [''targetself'', ''disableInfo'']) ''':''' Boolean, Table}}
−
'''function''' autoAssemble(''AutoAssemblerScript'', ''TargetSelf'' OPTIONAL, ''DisableInfo'' OPTIONAL) ''':''' nil,errorstring '''-''' boolean, table
 
  
−
'''function''' autoAssemble(''AutoAssemblerScript'', ''DisableInfo'' OPTIONAL) ''':''' nil,errorstring '''-''' boolean, table
+
Runs the Auto Assembler with the given text. 
  
−
runs the auto assembler with the given text. Returns true on success, with as secondary a table you can use when disabling (if ''TargetSelf'' is set it will assemble into Cheat Engine itself). If ''DisableInfo'' is provided the [Disable] section will be handled.
+
* If ''targetself'' is set, it will assemble into Cheat Engine itself.
 +
* Returns ''true'' on success.
 +
* As a secondary return, it provides a table you can use for disabling.
 +
* If ''disableInfo'' is provided, the ''[Disable]'' section will be handled automatically.
  
−
Tip: Use '[[ ]]' or '[==[ ]==]' quotes for multiline script.
 
  
−
=== Function Parameters ===
+
===Function Parameters===
−
 
+
{|width="85%" cellpadding="5%" cellspacing="0" border="0"
−
{|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: 60%;background-color:white;" align="left"|Description
−
|-
 
−
|AutoAssemblerScript
 
−
|string
 
−
|The script to run with Cheat Engine's auto assembler
 
−
|-
 
−
|TargetSelf
 
−
|boolean
 
−
|If set it will assemble into Cheat Engine itself
 
 
|-
 
|-
−
|DisableInfo
+
|text
−
|boolean
+
|String
−
|If provided the [Disable] section will be handled
+
|The Auto Assembler script text to run.
−
|}
 
−
 
 
−
{|width="85%" cellpadding="10%" cellpadding="5%" cellspacing="0" border="0"
 
−
!align="left"|Parameter
 
−
!align="left"|Type
 
−
!style="width: 80%;background-color:white;" align="left"|Description
 
 
|-
 
|-
−
|AutoAssemblerScript
+
|targetself
−
|string
+
|Boolean (optional)
−
|The script to run with Cheat Engine's auto assembler
+
|If true, assembles into Cheat Engine itself. Default is false.
 
|-
 
|-
−
|DisableInfo
+
|disableInfo
−
|boolean
+
|Table (optional)
−
|If provided the [Disable] section will be handled
+
|If provided, will handle the ''[Disable]'' section.
 
|}
 
|}
  
 +
===Returns===
 +
Boolean — ''true'' if the assembly succeeded.<br>
 +
Table — Optional secondary table for handling disable info.
  
 +
===Example===
 +
<syntaxhighlight lang="lua" line>
 +
-- Simple AutoAssembler script
 +
local disableTable
 +
local success, disableTable = autoAssemble([[
 +
  alloc(newmem,1024)
 +
  // ...
 +
]], true)
  
−
== Examples ==
+
if success then
−
 
+
   print("Script assembled successfully")
−
<syntaxhighlight lang="lua">
+
end
−
  autoAssemble("{$lua}\n print('Printed Form Auto Assembler Script!')")
 
−
 
 
−
 
 
−
  local scriptStr = &#91;==&#91;
 
−
    alloc(memExample)
 
−
    label(returnHere)
 
−
    &nbsp;
 
−
    memExample:
 
−
      mov eax,123
 
−
      jmp returnHere
 
−
    &nbsp;
 
−
    00400500:
 
−
      jmp memExample
 
−
      returnHere:
 
−
  &#93;==&#93;
 
−
  &nbsp;
 
−
  if autoAssemble(scriptStr) then
 
−
    print('The auto assembler script was successful.')
 
−
   else
 
−
    print('There was an error with the auto assembler script.')
 
−
  end
 
−
 
 
−
 
 
−
  local scriptStr = [==[
 
−
    alloc(memExample)
 
−
    label(returnHere)
 
−
   
 
−
    memExample:
 
−
      mov eax,123
 
−
      jmp returnHere
 
−
   
 
−
    00400500:
 
−
      jmp memExample
 
−
      returnHere:
 
−
  ]==]
 
−
  ---- Enable script
 
−
  local enabledOk, disableInfo = autoAssemble(scriptStr)
 
−
  if enabledOk then
 
−
    print('The auto assembler script was enabled successfully.')
 
−
  else
 
−
    print('There was an error enabling the auto assembler script.')
 
−
  end
 
−
  ---- Disable script
 
−
  local disabledOk = autoAssemble(scriptStr, disableInfo)
 
−
  if disabledOk then
 
−
    disableInfo = nil
 
−
    print('The auto assembler script was disabled successfully.')
 
−
  else
 
−
    print('There was an error disabling the auto assembler script.')
 
−
  end
 
−
 
 
−
 
 
−
  local scriptStr = &#91;==&#91;
 
−
    alloc(memExample2)
 
−
    memExample2:
 
−
      dd (float)364.12458729
 
−
      dd (float)12.65594753
 
−
      dd (float)50.75331054
 
−
      dd 0
 
−
      // player base
 
−
      dq 0
 
−
      // map base
 
−
      dq 0
 
−
  &#93;==&#93;
 
−
  &nbsp;
 
−
  if not autoAssemble(scriptStr, true) then
 
−
    return 1, 'There was an error with the auto assembler script.'
 
−
  end
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
{{LuaSeeAlso}}
 
{{LuaSeeAlso}}
  
−
=== Related Functions ===
+
{{Assembly}}
−
* [[Lua:autoAssembleCheck|autoAssembleCheck]]
 
−
* [[Lua:AOBScan|AOBScan]]
 
−
* [[Lua:disassemble|disassemble]]
 
−
* [[Lua:getInstructionSize|getInstructionSize]]
 
−
* [[Lua:getPreviousOpcode|getPreviousOpcode]]
 
−
* [[Lua:allocateSharedMemory|allocateSharedMemory]]
 
−
* [[Lua:mapMemory|mapMemory]]
 
−
* [[Lua:unmapMemory|unmapMemory]]
 
−
* [[Lua:readBytes|readBytes]]
 
−
* [[Lua:readPointer|readPointer]]
 
−
* [[Lua:writeBytes|writeBytes]]
 
−
* [[Lua:readBytesLocal|readBytesLocal]]
 
−
* [[Lua:readPointerLocal|readPointerLocal]]
 
−
* [[Lua:writeBytesLocal|writeBytesLocal]]
 
−
* [[Lua:wordToByteTable|wordToByteTable]]
 
−
* [[Lua:dwordToByteTable|dwordToByteTable]]
 
−
* [[Lua:qwordToByteTable|qwordToByteTable]]
 
−
* [[Lua:floatToByteTable|floatToByteTable]]
 
−
* [[Lua:doubleToByteTable|doubleToByteTable]]
 
−
* [[Lua:stringToByteTable|stringToByteTable]]
 
−
* [[Lua:wideStringToByteTable|wideStringToByteTable]]
 
−
* [[Lua:byteTableToWord|byteTableToWord]]
 
−
* [[Lua:byteTableToDword|byteTableToDword]]
 
−
* [[Lua:byteTableToQword|byteTableToQword]]
 
−
* [[Lua:byteTableToFloat|byteTableToFloat]]
 
−
* [[Lua:byteTableToDouble|byteTableToDouble]]
 
−
* [[Lua:byteTableToString|byteTableToString]]
 
−
* [[Lua:byteTableToWideString|byteTableToWideString]]
 

Latest revision as of 19:26, 25 June 2026

<> Lua API Reference

function autoAssemble(text, [targetself, disableInfo]) : Boolean, Table

Runs the Auto Assembler with the given text.

  • If targetself is set, it will assemble into Cheat Engine itself.
  • Returns true on success.
  • As a secondary return, it provides a table you can use for disabling.
  • If disableInfo is provided, the [Disable] section will be handled automatically.


Function Parameters[edit]

Parameter Type Description
text String The Auto Assembler script text to run.
targetself Boolean (optional) If true, assembles into Cheat Engine itself. Default is false.
disableInfo Table (optional) If provided, will handle the [Disable] section.

Returns[edit]

Boolean — true if the assembly succeeded.
Table — Optional secondary table for handling disable info.

Example[edit]

 1 -- Simple AutoAssembler script
 2 local disableTable
 3 local success, disableTable = autoAssemble([[
 4   alloc(newmem,1024)
 5   // ...
 6 ]], true)
 7 
 8 if success then
 9   print("Script assembled successfully")
10 end

Main Pages

Core Lua documentation entry points

◆ Lua
◆ Script Engine

Assembler and Disassembler Related Lua Functions

Auto assembler, disassembly helpers, instruction size lookup, and assembler callbacks