Posted by N.
in lua scripts for Bizhawk (06-29-23) (Started by N. June 21, 2021, 11:06:10 pm
Board: Resource Releases
Board: Resource Releases
It's a script that tries to *automate brute-force checking values to an address (you can modify it for other things, but I initially made it to see if I could find the Character Test in Street Fighter Alpha 2 yet again) minus the inconvenience of the value sometimes getting reset for whatever reason (ex: loading a savestate and increasing the value at the same time. I'm looking at you, artmoney/cheat engine). Since this saves the (decimal) value to a .txt file as it increments it (it'll appear in the same folder as this script), it doesn't matter if the emulator crashes or you can't do it in one sitting.
*What it does is add 1 to the current value of an address, save that value to a text file, load savestate 1 after 60 frames, and write the saved value in the text file to the address. It also shows you the value of the address on the screen in decimal and hexadcimal so you don't have to do a RAM watch.
Set up:
You need save state slot 1 containing the thing you want to observe. Increasing the emulator speed or going to "if frameCount == 60 then" and changing 60 to a lower value (but not too low. The frame counter is ticking as it loads your savestate) can make it go faster. Opening the RAM Search and Hex Editor will make it slow down.
Every instance of 0x8000 needs to be changed to the address you want to observe. memory.write_u16_le and memory.read_u16_le need to be changed depending on what you're doing with the values. MainRAM needs to be changed to the memory domain containing the value you want to observe.
Code:
memory.usememorydomain("MainRAM")
local valueFile = "value.txt"
function saveValue(value)
local file = io.open(valueFile, "w")
file:write(value)
file:close()
end
function loadValue()
local file = io.open(valueFile, "r")
if file then
local value = file:read("*n")
file:close()
return value
else
return 0
end
end
local frameCount = 0
local savestateLoaded = false
function hex(val)
val = string.format("%X", val)
return val
end
while true do
gui.drawText(0x0, 0x0, "0x8000 (Dec): " .. (memory.read_u16_le(0x8000)), 0XFFFFFFFF, 0XFF000000, 0x0B, "Arial", "normal", "left", "top")
gui.drawText(0x0, 0x0B, "0x8000 (Hex): " .. hex(memory.read_u16_le(0x8000)), 0XFFFFFFFF, 0XFF000000, 0x0B, "Arial", "normal", "left", "top")
local value = loadValue() or 0
memory.write_u16_le(0x8000, value + 0x01)
emu.frameadvance()
frameCount = frameCount + 1
if frameCount == 60 then
savestate.loadslot(1)
value = value + 0x01
memory.write_u16_le(0x8000, value)
saveValue(value)
frameCount = 0
savestateLoaded = false
end
end