Post subject: Using a lua script to automate resets for seed (DeSMuMe)?
Active player (261)
Joined: 12/13/2016
Posts: 352
Hey guys, wondering if you could help me with something. I'm currently TASing a game that fortunately does not have any clock-based lags. This means that given a possible desired outcome, I can write the movie file for it and find a seed that gives me the outcome later. So basically, what I'm asking is the following: I've got a move file of roughly 7000 frames, and I want to find an initial seed that gives me a particular result. To know if I got the "result," I just need to check and compare certain addresses in the memory with certain values. I've spent quite a few hours doing this manually (changing the clock time by 1 second, turboing through game movie, and then checking result), but am wondering if this can be automated entirely. Ideally, I would like such a script to dump the "good" datetimes (ones that give a seed that yields the result) into some text file/csv so I can go check those seeds later. For what it's worth, I'm fairly comfortable with programming and imagine I can probably achieve this with a .bat file or an autofire script, but I think things would be a lot cleaner (and maybe faster) if I could just run this through lua scripting. Any ideas? Code would be nice, but even just pointing me to a reference with the right lua commands (like for resetting the emulator and for editing the date in a dsm file would be useful).
Masterjun
He/Him
Site Developer, Skilled player (1988)
Joined: 10/12/2010
Posts: 1185
Location: Germany
Luckily, DeSmuME has a movie.play() function which automatically resets the emulator and runs the movie. I made a quick script that you can adjust to fit your needs. Things you might want to edit:
  • the moviepath string at the top
  • the getTime() function (currently only supports seconds, minutes and hours)
  • the checkResult() function
  • the frames to wait in the while true do loop (currently 7000)
  • what to do when checkResult() returned true (currently prints the time)
Language: lua

local moviepath = "movie.dsm" local function getTime(newtime) local s = newtime%60 local m = math.floor(newtime/60)%60 local h = math.floor(newtime/3600)%24 return string.format("2009-JAN-01 %02d:%02d:%02d:000",h,m,s) end local function editFile(newtime) local file = io.open(moviepath,"r") local filestring = file:read("*a") file:close() filestring = filestring:gsub("(rtcStartNew )([^%c]+)","%1"..getTime(newtime)) file = io.open(moviepath,"w") file:write(filestring) file:close() end local function checkResult() if memory.readbyte("0x02000000")==0xFF then return true end return false end local newtime = 0 while true do editFile(newtime) movie.play(moviepath) for i=1,7000 do -- frames to wait emu.frameadvance() end if checkResult() then print("it worked with "..getTime(newtime)) end newtime=newtime+1 end
Warning: Might glitch to credits I will finish this ACE soon as possible (or will I?)
Active player (261)
Joined: 12/13/2016
Posts: 352
Thank you so much! I'll give this a try and let you know how it goes.
Active player (261)
Joined: 12/13/2016
Posts: 352
It ended up working out very well! The bot actually helped me discover a faster route that I didn't anticipate!