Using a form from within Cheat Engine in your own cheat table

Ensure you have the source code from Cheat Engine’s GitHub. To use the source code you can install Lazarus 2.2.2

Note: not all forms can be used because Cheat Engine doesn’t have the appropriate controls for use, but many still can be used.

If you have Lazarus installed already you can skip steps 1 and 2.

  1. Download Lazarus 2.2.2 from Lazarus 2.2.2

  2. First install lazarus-2.2.2-fpc-3.2.2-win64.exe followed by lazarus-2.2.2-fpc-3.2.2-cross-i386-win32-win64.exe

  3. Run Lazarus and click on Project > Open Project. Select cheatengine.lpi from the Cheat Engine Source Folder folder as the project.

  4. Ensure that the Project Inspector window is visible via this menu:

  5. Filter the form you want to use; as an example I will be using the Hotkeys form

  6. Double-click the form you want to use. If you see the form directly then continue to the next step. If you do not see the form, but see the Source Editor window then from this window press F12 to view the form.

  7. From the form window, select View Source (.lfm) via the right-click context menu, by right-clicking anywhere on the form. See attached image:

  8. You will then see the Source Editor window. Go to File from the main window of Lazarus > Save As… > Select a location, and appropriate name for your form. Lazarus will prompt you to delete the file that exists click No to ensure that you delete the original files. You can now close Lazarus, we are done with it.

  9. Open Cheat Engine, and from within the main window navigate to Table > Create Form; now that you see the Form Designer window, navigate to File > Load LFM > select the form file you saved from within Lazarus.

  10. Once the form is loaded within the Form Designer. Navigate to File from the menu and then click Save. We need to save it as a form that Cheat Engine can use, but first we must delete the form from within Cheat Engine, and then add the form as a table file:

  11. Now we move onto the code so that we can actually use the form. From the Cheat Table Lua Script window we use this code:

-- We need a global reference to the form
formReference = nil
-- We need to use the filename of form including extension, in my case I saved it as "mHotkeys.frm"
formName = 'mHotkeys.frm'

-- Check if the reference exists, or not.
if not formReference then
	 -- Find the form within the table.
	 local nf = findTableFile(formName)
   if nf == nil then error('Unable to find \"' .. formName .. '\" within the cheat table') end

   -- Create a new memory stream, check its validity.
   local fs = nf.Stream
   if fs.Size == 0 then error('Form stream is empty, or corrupted.') end

   -- Create a new form from a memory stream
   formReference = createFormFromStream(fs)
   if formReference == nil then error('Failed to create form from the stream.') end

   -- This is so that you can show/hide the form from a script within the cheat table.
   -- But also disable the show form script when the form is not visible.
   formReference.OnClose = function(sender)
                             sender.Hide()
                             -- Set the name of the script to the description of the script you
                             -- want to control the form from.
                             AddressList['Show Form'].Active = false
                             return caHide
                            end

   -- TODO: Add control events/properties here
end

I have a script within the table called Show Form with the code:

[ENABLE]
{$LUA}
if syntaxcheck then return end
formReference.show()
{$ASM}
[DISABLE]

I hope that this gives you some insight into using forms from within Cheat Engine in your own tables. You can also use it to modify the forms before saving and using them in your own way.

If you use this technique, or I have taught you something, please show appreciation by giving rep.

Many thanks,
LeFiXER

3 Likes