Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # written in Lua script
- # bizhawk version 2.2 (x64)
- # resources from external sources: http://lua-users.org/wiki/TableUtils
- # author: cleartonic
- memory.usememorydomain("WRAM")
- filename = "dumps/ff6-steps-log.txt"
- file = io.open(filename,"w+")
- io.output(file)
- io.write("#INTENTIONAL BLANK#\n")
- io.close()
- -- Table to string code --
- function table.val_to_str ( v )
- if "string" == type( v ) then
- v = string.gsub( v, "\n", "\\n" )
- if string.match( string.gsub(v,"[^'\"]",""), '^"+$' ) then
- return "'" .. v .. "'"
- end
- return '"' .. string.gsub(v,'"', '\\"' ) .. '"'
- else
- return "table" == type( v ) and table.tostring( v ) or
- tostring( v )
- end
- end
- function table.key_to_str ( k )
- if "string" == type( k ) and string.match( k, "^[_%a][_%a%d]*$" ) then
- return k
- else
- return "[" .. table.val_to_str( k ) .. "]"
- end
- end
- function table.tostring( tbl )
- local result, done = {}, {}
- for k, v in ipairs( tbl ) do
- table.insert( result, table.val_to_str( v ) )
- done[ k ] = true
- end
- for k, v in pairs( tbl ) do
- if not done[ k ] then
- table.insert( result,
- table.key_to_str( k ) .. "=" .. table.val_to_str( v ) )
- end
- end
- return "{" .. table.concat( result, "," ) .. "}"
- end
- stepcounter = memory.read_u16_le(0x001866) -- 1 byte
- threat = memory.read_u16_le(0x001F6E) --
- seed = memory.readbyte(0x001FA3) -- seed changed upon reset
- Xcoord = memory.readbyte(0x0000C6) -- 0x0000C6 #if its 160, press left. If its 144, press right.
- battlemode = memory.readbyte(0x000087) --0x000087 #if its 224, world map. if its 0, battle. Used for reset & load as well
- currentstepstring = {} -- will temporarily house steps for any given threat, then will be written upon finished loop
- laststeps = 0 -- set every time a new stepcounter is readbyte
- newsteps = 0 -- temporary "last round's steps to a battle"
- iteration = 1 -- current number of loops, used for logging
- maxiterations = 128 -- total number of loops
- battlecounter = 99 -- number of battles looped for a threat (will be eventually 99)
- stepscalled = 0 -- temporary viewer of how many times insert.table gets called
- savestate.loadslot(1) -- later needs to be REMOVED
- function wait(number)
- while number > 0 do
- displayfunc()
- emu.frameadvance()
- number = number - 1
- updatevalues()
- end
- end
- function displayfunc()
- gui.text(200,0,"Ins: "..stepscalled)
- end
- function updatevalues()
- stepcounter = memory.read_u16_le(0x001866) -- 1 byte
- threat = memory.read_u16_le(0x001F6E) -- logged upon first
- Xcoord = memory.readbyte(0x0000C6) -- 0x0000C6 #if its 160, press left. If its 144, press right.
- battlemode = memory.readbyte(0x000087) --0x000087 #if its 224, world map. if its 0, battle. Used for reset & load as well
- end
- function updatecounters()
- seed = memory.readbyte(0x001FA3)
- battlecounter = 99 -- number of battles looped for a threat (will be eventually 99)
- laststeps = 0
- newsteps = 0
- currentstepstring = {}
- end
- function reset()
- joypad.set({Reset=true})
- console.log(joypad.get())
- gui.text(1,1,"Power")
- temp = 470
- while temp > 0 do
- onoff()
- temp = temp - 1
- end
- end
- function onoff()
- joypad.set({A=true},1)
- wait(1)
- joypad.set({A=false},1)
- wait(1)
- end
- while iteration <= maxiterations do
- while battlecounter >= 0 do
- updatevalues()
- gui.text(1,1,"First Step")
- --take first step
- if Xcoord == 160 then
- joypad.set({Left=true},1)
- wait(24)
- elseif Xcoord == 144 then
- joypad.set({Right=true},1)
- wait(24)
- else
- gui.text(1,1,"Failure")
- wait(1)
- end
- -- loop world map movements
- updatevalues()
- while threat > 0 do
- wait(1)
- if Xcoord == 160 then
- joypad.set({Left=true},1)
- wait(24)
- elseif Xcoord == 144 then
- joypad.set({Right=true},1)
- wait(24)
- else
- gui.text(1,1,"Failure")
- wait(1)
- end
- end
- -- transition to battle
- wait(30)
- -- get through a battle
- while battlemode == 0 do
- gui.text(1,20,"Laststeps: "..laststeps)
- joypad.set({A=true},1)
- wait(1)
- updatevalues()
- end
- -- log steps
- newsteps = stepcounter - laststeps
- table.insert(currentstepstring, newsteps)
- stepscalled = stepscalled + 1
- laststeps = stepcounter
- battlecounter = battlecounter - 1
- wait(1)
- end
- -- write to file, move to next iteration
- file = io.open(filename,"a+")
- io.output(file)
- io.write('Iteration ',iteration," | Seed ",seed,': ',table.tostring(currentstepstring))
- io.write("\n")
- io.close()
- iteration = iteration + 1
- reset()
- updatevalues()
- updatecounters()
- end
- while true do
- gui.text(1,1,"Finished.")
- wait(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement