[Warning this is both complex and terribly written. You’ve been warned.]
Lua scripting as you might guess is a bit like coding though in this case far easier since I’m not trying to make a program but merely make interesting cheats. I felt it’d be nice to write the steps from random guessing to my first working (and obviously quite simple) script.
The easiest thing to do in lua is ‘memory.readbyte(Address)’ and ‘memory.writebyte(Address, Number)’ but merely patching them together with an if, then and return wasn’t working and I was confused. What was happening was no matter what the readbyte was always getting ignored and doing the writebyte anyway. It took looking through someone else’s script to realise that you don’t put the value in the ‘()’ like the writebyte but actually put something like ‘== Number’. That actually got it to cheat itself to work properly but having a static value was a bit boring.
What I learned after that is if you set a readbyte to a word (e.g. rings = memory.readbyte(Address)) then you can do cooler stuff using maths. For example my test script had rings+1 as a value which would basically mean you could make some way to make the ring counter slowly go up. My plan was to make it so it went up by 1 if an address hit a certain value like it your character looked up or the rings hit 0. However while it did actually turn out to be written almost correctly I ran into my biggest problem, the script was only running once.
I tried all sorts of stuff I found while looking for answers like ‘while true do’, ‘repeat’ and the ways you can piece it together but it either did nothing or almost killed the emulator (which thankfully will let you kill a script before it goes haywire). And even when I finally realised I had to put in something like emu.frameadvance() it still only ran once but at least this time.
I finally got it up and running when I realised while true did nothing and instead told it to do it while an address was at a certain value. Of course I gave it a random address that never changed so it lasted forever and that’s how I finally got it working. This is what it looks like at the time of writing this:
while memory.readbyte(0x00000000) == 0x06 do
ringno = memory.readbyte(0x03004fec)
time = memory.readword(0x03005034)
character = math.random(0,3)
if memory.readbyte(0x03004fec) == 0x0 then
Yes, that not only makes sure you always have plus 1 ring instead of 0 I also tied the score to the time for no reason and set your currently selected character to math.random so they change every frame which is insane. With this it means that I can now potentially carry on doing GodMode videos but I could go beyond simple cheats now, I hope the time and effort will pay off though.