-- pokered.lua -- author: Bryan Bishop -- date: 2012-01-19 -- -- Play through the first few minutes of Pokmon Red. local json = require("json") -- grab current random registers function grab_randoms() randoms = {memory.readbyte(0xfd3), memory.readbyte(0xffd4)} return randoms end -- useful for recording new actions function record_frames() local stop = false local frame_count = 0 local frames = {} frames[""] = "" -- wtf? print("begin recording frames") while not stop do -- get current keypresses keypresses = joypad.getdown(1) print(keypresses) -- get current random variables randoms = grab_randoms() -- store this information -- only if there has been a keypress if next(keypresses) == nil then print "is nil" else frames[frame_count] = {keypresses=keypresses, randoms=randoms} end -- stop recording check if keypresses["select"] == true and keypresses["B"] == true then print("select+b pressed... recording stopped; saving progress.") stop = true end -- ok let's continue vba.frameadvance() -- for figuring out where we are in the game run frame_count = frame_count + 1 end print("done recording frames") -- save information to file print("saving information to output.json...") file = io.open("output.json", "w") file:write(json.encode(frames)) file:close() end -- record_frames() -- while 1 do -- print("debug1") -- -- joypad.set(1, {A=1}) -- print(joypad.getdown(0)) -- vba.frameadvance() -- -- results = joypad.getdown(0) -- if results["L"] == true then -- print("setting A=1...") -- joypad.set(1, {A=1}) -- vba.frameadvance() -- end -- end function delay_frames(count) x = 0 while x < count do vba.frameadvance() x = x + 1 end end -- continue advancing frames until the player touches something function frame_advancer() x = 0 stop = false while not stop do print(vba.framecount()) results = joypad.getdown(0) if keypresses == nil then vba.frameadvance() x = x + 1 elseif next(keypresses) == nil then vba.frameadvance() x = x + 1 else stop = true end end end -- wait until the frame count is ok function wait_until(framecount) stop = false while not stop do x = vba.framecount() if x < framecount then vba.frameadvance() else stop = true end end end function send_keypress(keypresses) x = 0 while x < 4 do joypad.set(1, keypresses) vba.frameadvance() x = x + 1 end end function walker(keypresses) send_keypress(keypresses) delay_frames(25) --maybe? end function walk_up() walker({up=1}) end function walk_down() walker({down=1}) end function walk_right() walker({right=1}) end function walk_left() walker({left=1}) end -- skip gamefreak logo wait_until(350) joypad.set(1, {start=1, A=1}) print("skipped gamefreak logo") -- skip nidorino/gangar wait_until(400) send_keypress({start=1}) print("skipped nidorino/gangar") -- start screen wait_until(650) send_keypress({start=1}) print("skipped start screen") delay_frames(137) wait_until(650+137) send_keypress({start=1}) print("started new game") -- get oak on screen wait_until(650+137+200) print("oak appears") -- get past oak's speech wait_until(1100) send_keypress({A=1, B=1}) print("oak 1st line") wait_until(1190) send_keypress({A=1, B=1}) print("oak 2nd line") wait_until(1300) send_keypress({A=1, B=1}) print("oak 3rd line") wait_until(1400) send_keypress({A=1, B=1}) print("oak 4th line") wait_until(1590) send_keypress({A=1, B=1}) print("oak 5th line") wait_until(1650) send_keypress({A=1, B=1}) print("oak 6th line") wait_until(1750) send_keypress({A=1, B=1}) print("oak 7th line") wait_until(1890) send_keypress({A=1, B=1}) print("oak 8th line") wait_until(2000) send_keypress({A=1, B=1}) print("oak 9th line") wait_until(2150) send_keypress({A=1, B=1}) print("oak 10th line") wait_until(2300) send_keypress({A=1, B=1}) print("oak 11th line") wait_until(2450) send_keypress({A=1, B=1}) print("oak 12th line") wait_until(2550) send_keypress({A=1, B=1}) print("oak 13th line") wait_until(2610) send_keypress({A=1, B=1}) print("First, what is your name?") wait_until(2680) send_keypress({down=1}) wait_until(2685) send_keypress({A=1}) print("RED") wait_until(2830) send_keypress({A=1, B=1}) print("Right! So your name is RED.") wait_until(3100) send_keypress({A=1, B=1}) print("This is your rival.") wait_until(3200) send_keypress({A=1, B=1}) print("He's been your rival since") wait_until(3280) send_keypress({A=1, B=1}) print("you were a baby") wait_until(3350) send_keypress({A=1, B=1}) print("erm, what was his name again?") wait_until(3500) send_keypress({A=1, B=1}) wait_until(3650) print("sending down") send_keypress({down=1}) wait_until(3660) print("sending A") send_keypress({A=1}) print("BLUE") wait_until(3890) print("Oh I remember now") send_keypress({A=1}) wait_until(3950) print("His name is BLUE") send_keypress({A=1}) wait_until(4100) send_keypress({A=1}) wait_until(4200) send_keypress({A=1}) wait_until(4300) send_keypress({A=1}) wait_until(4400) send_keypress({A=1}) wait_until(4500) send_keypress({A=1}) wait_until(4600) send_keypress({A=1}) wait_until(4700) send_keypress({A=1}) wait_until(5000) print("walk path: reds house 2f") walk_right() walk_right() walk_up() walk_up() walk_up() walk_up() walk_up() walk_right() walk_right() delay_frames(200) print("walk path: reds house 1f") walk_down() walk_down() walk_down() walk_down() walk_down() walk_down() walk_left() walk_left() walk_left() walk_left() walk_down() --go outside wait_until(5800) walk_right() walk_right() walk_right() walk_right() walk_right() walk_up() walk_up() walk_up() walk_up() walk_right() walk_up() --into the grass --oak walks up and gives speech wait_until(6650) send_keypress({A=1}) delay_frames(50) send_keypress({A=1}) delay_frames(150) send_keypress({A=1}) --A on "you need your own pokemon for protection" delay_frames(25) send_keypress({A=1}) --A on protection delay_frames(150) print("I know!") send_keypress({A=1}) --A on "I know!" delay_frames(100) send_keypress({A=1}) --A on "I know!" print("Here, come with me!") delay_frames(200) send_keypress({A=1}) --A on "Here, come with me!" send_keypress({A=1}) --yes i mean it.. wait_until(8100) print("Gramps, I'm fed up with.. shut up, blue") send_keypress({A=1}) --on "I'm fed up with" text delay_frames(100) send_keypress({A=1}) --on "waiting" delay_frames(150) send_keypress({A=1}) --on "BLUE? Let me think..." delay_frames(150) send_keypress({A=1}) --on "I told you to" delay_frames(150) send_keypress({A=1}) --on "Just wait!" delay_frames(100) send_keypress({A=1}) --on "Here, RED!" delay_frames(150) send_keypress({A=1}) --on "There are 3 pokemon here!" delay_frames(100) send_keypress({A=1}) --on "HAHA" delay_frames(100) send_keypress({A=1}) --on "They are inside pokeballs" delay_frames(150) send_keypress({A=1}) --on "When I was young, I was a serious" delay_frames(100) send_keypress({A=1}) --on "serious pokemon trainer" delay_frames(150) send_keypress({A=1}) --on "in my old age, i only have 3 left" delay_frames(100) send_keypress({A=1}) --on "but you can have" delay_frames(100) send_keypress({A=1}) --on "one! Choose!" delay_frames(150) send_keypress({A=1}) delay_frames(150) send_keypress({A=1}) delay_frames(150) send_keypress({A=1}) delay_frames(150) send_keypress({A=1}) --on "Hey gramps, what about me" delay_frames(100) send_keypress({A=1}) --on "me?" delay_frames(200) send_keypress({A=1}) --on "be patient! blue you can have" delay_frames(100) send_keypress({A=1}) --on "one too" print("done with speech?") wait_until(10800) walk_down() walk_right() walk_up() print("I choose CHARMANDER...") send_keypress({A=1}) delay_frames(300) --pokedex and roar send_keypress({A=1}) delay_frames(50) --next page send_keypress({A=1}) delay_frames(200) send_keypress({A=1}) --on "So, you want the" delay_frames(150) send_keypress({A=1}) --on "YES" delay_frames(150) send_keypress({A=1}) --on "really energetic!" delay_frames(400) send_keypress({A=1}) --on "Do you want to" delay_frames(200) send_keypress({B=1}) --on "give charmander a nickname?" wait_until(12500) send_keypress({A=1}) --on "I'll take this one" delay_frames(300) --"BLUE received a squirtle" send_keypress({A=1}) send_keypress({A=1}) delay_frames(150) send_keypress({A=1}) delay_frames(150) send_keypress({A=1}) delay_frames(300) print "starting walk sequence in oak's lab" walk_down() walk_left() walk_down() delay_frames(100) send_keypress({A=1}) --on "BLUE: Wait, RED!" delay_frames(80) send_keypress({A=1}) --on "Let's check out" delay_frames(80) send_keypress({A=1}) --on "our pokemon!" delay_frames(100) send_keypress({A=1}) --on "Come on, I'll take you on!" print "fight beginning..." delay_frames(600) print "BLUE wants to fight?" send_keypress({A=1}) --on "BLUE wants to fight!" wait_until(14960) send_keypress({A=1}) --FIGHT delay_frames(50) send_keypress({A=1}) --SCRATCH wait_until(15400) --after squirtle's attack -- ok i dunno what to do now frame_advancer()