Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Cheat Engine Forum Index
PostGo back to topic
Rydian
Grandmaster Cheater Supreme
Reputation: 31
Joined: 17 Sep 2012
Posts: 1358

PostPosted: Tue Feb 03, 2015 2:32 am    Post subject: Rydian's Guide To Custom Trainers

- Introduction
Tired of Cheat Engine's generic trainer style? Want better ability to edit a trainer that you've already made?
Want to make a trainer that uses more than just hotkeys and can read and write custom values for ease of use?
Follow this tutorial and you should be spitting out fancy trainers at the end!




- Setup / Software / Downloads
  • This tutorial was written for Cheat Engine 6.4, though it should work on 6.3 or later(barring future UI changes).
  • We will be using the freeware game Cave Story as the target.
    You can download it here, the translation patch is linked right below the main download.
  • This post has some attachments which include the table and resources we'll be working with.
    So make sure to scroll down and download those now.


- Meet The Lua Script And Form Interface
The first thing you'll want to do once you have all the files set up is to attach CE to the game (Doukutsu.exe) and then load
the table. You'll see the various addresses and scripts in the table, but we'll barely be touching those. Instead, click the
"Table" menu at the top and click "Show Cheat Table Lua Script". This will bring up a new window where all the coding goes.



It's important to remember that you should not click the "Execute" button at the bottom of this form until you are ready to
actually test the script/trainer's functionality. Changes are automatically saved into the table, so always click the X at
the upper-right to close this form when you want it out of your way.

Now go to "Table" again and click "Create Form". This will bring up three windows... the Form Designer, Object Inspector, and
the Trainer Form itself. However you can think of the three windows using the below labels as well if it makes more sense.



This form will be the actual visible trainer that the users will see and interact with, and it will interact with the Lua
script to actually do stuff. After you've created a form, it has a sub-menu for it added in the "Table" menu, so you can bring
it back up or go edit it some more later.




- Basic Setup
The first goal will be to give the Lua script some basic working code and then set the trainer form up with a working "About"
button. To start, we'll copy-paste some basic code to the bottom of the Lua script window.
Code:
AboutText=[[Sample About Text Here]]

form_show(UDF1)
getAutoAttachList().add("doukutsu.exe")

function CloseClick()
  closeCE()
  return caFree
end

UDF1.OnClose = CloseClick

addresslist=getAddressList()

  • The first line sets some text for our "about" box, feel free to replace it with what you want (linebreaks work too).

  • The second line tells the script to show the form when the trainer runs. It uses the default name of "UDF1" for the main
    form, if you rename the main form then make sure to change this line as well.

  • The third line tells CE which process name you want the trainer to automatically attach to. If, for some reason there's
    more than one process name (DX/GL or DX9/11 installs) then you can copy-paste that line to add more process names the
    trainer should look for.

  • The lines that involve closing tells the background processes and such to close when the user closes the trainer,
    so leave these alone.

  • The final line loads the table's address list, for when we want to freeze values and such.

Now you'll want to look at the Trainer form (those three boxes). In the Object Inspector box (where you edit the properties
of things) click on the main form in the list at the top (UDF1, the default name for the trainer in general) and scroll down
to see the properties. You can click in the property boxes to edit them. You'll want to change the Width and Height of the
trainer to 300 each, and also change the Caption, because that's what determines what the Trainer window is named.



Now look at the Tool Box (Form Designer), click the second button and then click and drag in the trainer form somewhere to
make a simple button.



Then select this button (either click it in the Form or click it's entry in the Properties / Object Inspector) and tweak
it as well. Make it have "About" for a caption, and then change the Width, Height, Top and Left properties to resize and move
it. The Top and Left properties are the distance in pixels from the upper-left corner. For this tutorial, you're going to want
to position the button in the bottom-right, and remember to change "Caption" for the display text, not "name"!

Once the button is positioned where you want and looks the way you want it to, it's time to make it do something. Make sure
the button is selected and then go to the "events" tab and check out the "OnClick" entry. It will have both a dropdown box and
a "..." button. The dropdown box will list various functions to be run when the button is clicked... but we don't have a
function for it yet, so clicking the "..." button will open the Lua form and insert a function for it at the bottom.




So when the user clicks the button, it will call this function. The function is just one blank line right now, so you'll
want to copy-paste "showMessage(AboutText)" into it, which is the function it should call. This is a function that shows a
message box containing the AboutText that was part of the first stuff we put into the script.



So overall the Lua script should look something like this right now.

Code:
AboutText=[[Sample About Text Here]]

form_show(UDF1)
getAutoAttachList().add("doukutsu.exe")

function CloseClick()
  closeCE()
  return caFree
end

UDF1.OnClose = CloseClick

addresslist=getAddressList()

function CEButton1Click(sender)
  showMessage(AboutText)
end


The next thing we'll be doing is adding a sidebar image. Click the picture button in the Form Designer and then click in
the Trainer form to insert the image.



Then with the image selected in the Object Inspector, go to the "Picture" attribute, click the "..." button, then browse to
and select the sidebar image I attached to this post.



Make sure to change the image object's size and location to 100x300 (the size of the included sidebar image) and position it
on the left (top 0 and left 0 will make it fit exactly on the lefthand side).



When you're done resizing it and such, it's time to test it. Close the Form windows and leave just the main CE window and Lua
form open. Then in the Lua form, click the "Execute" button at the bottom. This should open the trainer and you should be able
to click the "About" button and have it show the info.



If so, move onto the next section. If not, make sure you didn't typo or accidentally misname something.




- Checkbox & Button Toggles
Well it's about time to actually add some cheat scripts and make the trainer do something useful, isn't it? The first thing
we're going to add is a checkbox that will toggle an address freeze. In The Form Designer click the checkbox tool and then
click in the Trainer Form to add the checkbox. Give it a nice Caption (not "name") and position it the way you want.



After that, just like we did for the About button, we're going to add a function to the "OnChange" event.



This time, we're going to need to make the script a little more involved. When the user clicks the checkbox, we want the
script to determine the new state (checked or unchecked) and act based on that. So we'll use this, sticking it inside the
blank function that CE inserted for us.
Code:
  if (checkbox_getState(UDF1.CECheckBox1) == 1) then

  else

  end


Note the phrase "UDF1.CECheckbox1". This is made up of two parts. The "UDF1" part is the name of the trainer form, while
"CECheckbox1" is the name of the checkbox we added. If you've renamed anything or when you go to add more things, be sure
that the names match.

So now that the function checks the status of the checkbox and does two separate things based on that, let's actually tell it
to freeze or unfreeze the first address in the cheat table (which is index 0).
Code:
  if (checkbox_getState(UDF1.CECheckbox1) == 1) then
    CheatEntry=addresslist_getMemoryRecordByID(addresslist,0)
    memoryrecord_freeze(CheatEntry)
  else
    CheatEntry=addresslist_getMemoryRecordByID(addresslist,0)
    memoryrecord_unfreeze(CheatEntry)
  end


So the entire function should look like this.



And it's time to test it! Close the Trainer Form and related boxes, then click "Execute" on the Lua Script window, if
everything went well you should see the trainer, and checking the box should have the desired effect.

But simply freezing values isn't enough in a lot of cases. Cave Story in particular starts you out with 3 HP, but the
starting area has spikes that do more than 3 damage, so they'll still kill you. In this case, we want to take the
"No HP Loss" script from the table and use that.

This time we'll make a toggle box (button) for the script. Find the "Togglebox" icon on the Form Designer toolbar
and then click and drag in the Trainer Form to create a toggle box. Resize and position and name it the way you want.
After this, just like before you want to go to the Events tab, and click "..." on the OnChange event to add the
function like you've done twice now. Go ahead and add the "if / else /end" code from before too since we're working
with a toggleable object, and make sure to rename the object being checked. If you did it right, it'll be this.
Code:
function CEToggleBox1Change(sender)
  if (checkbox_getState(UDF1.CEToggleBox1) == 1) then

  else

  end
end


Now, in those two blank spaces we want to run our script for "No HP Loss". For this we want to use the autoAssemble()
function which will let us run AA scripts. We'll want to copy everything in the [ENABLE] section of the "No HP Loss"
script into the first blank section, and everything under [DISABLE] into the second blank section, like below.
(Note that the script has [[ at the start and ]] at the end, this is used to denote multi-line scripts.)
Code:
function CEToggleBox1Change(sender)
  if (checkbox_getState(UDF1.CEToggleBox1) == 1) then
    autoAssemble([[
      alloc(newmem,2048) //2kb should be enough
      label(returnhere)
      label(originalcode)
      label(exit)
      newmem:
      originalcode:
      exit:
      jmp returnhere
      "Doukutsu.exe"+1997A:
      jmp newmem
      nop
      nop
      returnhere:
    ]])
  else
    autoAssemble([[
      dealloc(newmem)
      "Doukutsu.exe"+1997A:
      mov [Doukutsu.exe+9E6CC],cx
    ]])
  end
end


Quite a bit to put in, eh? But once you have this, you can just copy-paste it for each code you want and then replace
the script with the one from the table (I just strip comments and empty lines when doing this for visual clarity).

Anyways like before, once you have this in there, close the Trainer Form and related windows, then click the "Execute"
button at the bottom of the Lua window to run your trainer script and make sure stuff works out.




- Read & Write Forms
Let's say that we want to add some basic teleport functions to the trainer. We have addresses for the X and Y
coordinates in the table, and we want to let the user edit those values in the trainer for controlled teleportation.
In order to do this, we'll need two Edit boxes and two normal buttons. Add them, and this time we actually do want
to change the Names, not just the Captions. I'll name the boxes CEEditX and CEEditY, and the buttons will be
CEButtonRead and CEButtonWrite so that we don't get confused. You'll want to clear their "Text" properties as well
so you don't have the placeholder text that I left in the screenshot there...



Now in order to make this setup functional, we'll first add a script to the OnClick Event of the "Read" button we made.
Code:
function CEButtonReadClick(sender)
  setProperty(UDF1.CEEditX,"Text", readInteger("Doukutsu.exe+9E654"))
  setProperty(UDF1.CEEditY,"Text", readInteger("Doukutsu.exe+9E658"))
end

The setProperty() function changes the Trainer Form, editing a property of one of the objects. In this case we're
targeting (by Name) the X and Y edit boxes we made. We're editing their Text properties (their contents) and for the
value to put in there we're using the readInteger() function to pull the coordinates in from the addresses (in the table).

Now we want to make the Write button do something too, so as usual select it and give it an OnClick event, use this code.
It's basically the last stuff but in reverse, we give it an address and then a value to write to, reading from the form.
Code:
function CEButtonWriteClick(sender)
  writeInteger("Doukutsu.exe+9E654", getProperty(UDF1.CEEditX,"Text"))
  writeInteger("Doukutsu.exe+9E658", getProperty(UDF1.CEEditY,"Text"))
end


If everything went as planned, you should be able to Execute the script and get the controlled teleportation!



- Saving / Distributing
Now that you have a (relatively-)fancy trainer, it's time to share it with the world, right? Go to File -> Save As
and choose to save the table as a standalone trainer (.exe). I highly suggest renaming the trainer (even just
appending "_trainer" to the name), you don't want it to have the same name as the process you're targeting,
despite the default name in CE tending to be just that.



After you've selected the location and file name to save as, you get the final step of making the trainer. This is
where you can choose an icon file (32x32 or 48x48 .ico format, I unfortunately can't attach the one I used) and some
final technical details. In general the options are either self-explanatory or CE will choose the right default for
your trainer, the only suggestion I have is to set the compression to "None" because AVs tend to complain about it.



Once you click the "Generate" button, you're done! There's your fancy-pants trainer, have fun with it.
If you need some software to make an image into a, .ico file, IcoFX's freeware version is here.
_________________
Intro to AOBs And Scripts
Invincibility Code Fixes
Modern Pointers + AOB/Hooks To Data
Value Searching Examples
Custom Trainers


Last edited by Rydian on Tue Feb 03, 2015 1:16 pm; edited 3 times in total
Back to top
View user's profile Send private message
Post reviews:   Approve 1
Author Review
Dark Byte
Review: Approve
Post reference:
ReviewPosted: Tue Feb 03, 2015 6:25 am


Back to top
View user's profile Send private message MSN Messenger
Display:  
Cheat Engine Forum Index


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites