Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- This script is for a Japanese version of 'A Link to the Past', or 'Zelda no Densetsu - Kamigami no Triforce'.
- -- version 2
- -- Source code is not sophisticated at all. Names of variables are strange. So, you can revise them freely.
- -- for fastforwarding to the frame
- function toFrame(frame)
- if movie.framecount()+1 == frame then
- emu.pause()
- end
- end
- -- for rough indication of the next input frame
- lastLagFr = 0
- function lastLag()
- if emu.lagged() then
- lastLagFr = movie.framecount() - 2
- end
- gui.text(0, 0, string.format("%d",lastLagFr))
- end
- local eHP={} -- enemy HP
- local eHPDisp={} -- enemy HP Display
- local itemDrop={} -- item Drop (prize pack manipulation)
- local eX = {} -- enemy's X position
- local eY = {} -- enemy's Y position
- local relEneX = {} -- relative enemy's X position, (enemy's X postion) - (camara's X position), actually means top-left X position of enemy's hitbox
- local relEneY = {} -- relative enemy's Y position, (enemy's Y postion) - (camara's Y position), actually means top-left Y position of enemy's hitbox
- -- reads RAM
- function ramRead()
- rupee = memory.readword(0x7EF360) -- rupee
- numBomb = memory.readbyte(0x7EF343) -- number of bombs for after YBA with spin attack
- numArrows = memory.readbyte(0x7EF377) -- number of arrows for after YBA with spin attack
- x = memory.readbyte(0x7E0022) -- Link's X position
- superX = memory.readbyte(0x7E0023)
- X = memory.readword(0x7E0022)
- y = memory.readbyte(0x7E0020) -- Link's Y position
- superY = memory.readbyte(0x7E0021)
- Y = memory.readword(0x7E0020)
- pos = string.format("(%2x,%2x)",x,y) -- means Link's position, (X, Y). I think HEXed value is more useful.
- cameraX = memory.readbyte(0x7E011E) -- camera's X
- CX = memory.readword(0x7E011E)
- cameraY = memory.readbyte(0x7E0122) -- camera's Y
- CY = memory.readword(0x7E0122)
- hitX = (x-cameraX) % 256 -- top-left X position of Link's hitbox
- hitY = (y-cameraY) % 256 -- top-left Y position of Link's hitbox
- gui.box(hitX, hitY, hitX+16, hitY+24) -- displaying Link's hitbox
- armedEG = memory.readbyte(0x7E047A)
- waterWalk = memory.readbyte(0x7E005B)
- -- assigns enemy's HP, X and Y position, and top-left X and Y position of enemy's hitbox
- -- In Arrghus fight, there are 14 enemies.
- for i=0,13 do
- eHP[i] = memory.readbyte(0x7E0E50+i)
- eHPDisp[i]=string.format("%3d",eHP[i])
- eX[i] = memory.readbyte(0x7E0D10+i)
- eY[i] = memory.readbyte(0x7E0D00+i)
- relEneX[i] = (eX[i] - cameraX) % 256
- relEneY[i] = (eY[i] - cameraY) % 256
- end
- HP=memory.readbyte(0x7EF36D) -- Link's HP
- string.format("%3d",HP)
- MP=memory.readbyte(0x7EF36E) -- Link's MP
- string.format("%3d",MP)
- xSpeed=memory.readbytesigned(0x7E0031) -- Link's X speed
- ySpeed=memory.readbytesigned(0x7E0030) -- Link's Y speed
- posSpeed = string.format(" %4d,%4d ",xSpeed,ySpeed) -- means Link's (X speed, Y speed)
- peg=memory.readbyte(0x7E0374) -- 0=pegasus boots dash; 29=spin dash
- bomb=memory.readbyte(0x7E03A0) -- timer for exploding a bomb
- spinAttack=memory.readbyte(0x7E0079) -- charging time for spin attack
- rng=memory.readword(0x7E0FA0) -- RNG
- grab=memory.readbyte(0x7E0DFF) -- timer for grabbing
- --[[ -- assigns prize pack manipulation, but this code does not display for the lack of gui.text. should use 'RAM Watch.'
- for i=0,6 do
- itemDrop[i]=memory.readbyte(0x7E0FC7+i)
- end
- -- Quards, Rupees, Magic, Bombs, Arrows, Skeleton, Big
- --]]
- --[[
- layer=memory.readbyte(0x7E0476) -- Link's current Layer
- 0x7E00A0 -- Link's current room for EG. HEXed value should be used on 'RAM Watch.'
- -]]
- p=string.format("peg %2d",peg)
- s=string.format("spn %2x",spinAttack)
- b=string.format("bom %2d",bomb)
- r=string.format("rng %4x",rng)
- g=string.format("grb %2d",grab)
- status = memory.readbyte(0x7E004D) -- Link's current status. 0=able to be inputted.
- recoil = memory.readbyte(0x7E0046) -- Link's current recoiling status. 0=able to be inputted.
- push = memory.readbyte(0x7E0371) - 13 -- state of pushing a block. 0=begin to move the block.
- ledge = memory.readbyte(0x7E0375) -- Link's current ledge off status. 0=begin to ledge off. used when you don't have pegasus boots.
- motion = memory.readbyte(0x7E0354) -- Link's current motion (slashing, using staff, arrow, etc). 0=able to be inputted.
- EG = memory.readbyte(0x7E00A0) -- Dungeon Room ID. useful for EG.
- layer=memory.readbyte(0x7E0476) -- Link's current Layer
- gui.text(116,0,string.format("mtn %d ldg %d sta %d rcl %d psh %d",motion,ledge,status,recoil,push)) -- displaying above 5 things.
- gui.text(0,30,string.format("EG %02X",EG)) -- displaying EG ID
- gui.text(0,37,string.format("lyr%2d",layer)) -- displaying Link's current layer
- X2 = math.floor(bit.rshift(bit.band(X,0xFF00),8)/2)
- Y2 = math.floor(bit.rshift(bit.band(Y,0xFF00),8)/2)
- CX2 = math.floor(bit.rshift(bit.band(CX,0xFF00),8)/2)
- CY2 = math.floor(bit.rshift(bit.band(CY,0xFF00),8)/2)
- gui.text(0,52,string.format("p %01X%01X",Y2,X2))
- gui.text(0,59,string.format("c %01X%01X",CY2,CX2))
- dungeonID = memory.readbyte(0x7E010E)
- gui.text(0,44,string.format("ID %X",dungeonID))
- gui.text(0,72,string.format("amdEG %d",armedEG))
- gui.text(0,79,string.format("WWlk %d",waterWalk))
- direction = memory.readbyte(0x7E002F)
- -- useful after YBA with spinattack in Swamp
- Direc = ""
- if direction == 0 then
- Direc = "UP"
- elseif direction == 2 then
- Direc = "DOWN"
- elseif direction == 4 then
- Direc = "LEFT"
- elseif direction == 6 then
- Direc = "RIGHT"
- end
- gui.text(234,108,Direc)
- end
- -- auto scroll text messages. when msgWait is not 0, you have to scroll them manually.
- function autoMsg()
- windowBox = memory.readword(0x7E0010) -- This may be bad name. It should be GameMode.
- msg = memory.readbyte(0x7E1CE9) - 1
- msgWait = memory.readbyte(0x7E1CE0) -- It seems used in opening
- gui.text(40, 0, string.format("%d %d %X", msg, msgWait, windowBox))
- if windowBox == 0x20E or windowBox == 0x219 then -- 0x219: Triforce Room
- ---[[
- if msg == 0 then
- joypad.set(1, {A=1})
- end
- --]]
- --[[ -- should be used at opening
- if (msgWait > 0) then
- print("message: "..movie.framecount()-1)
- emu.pause()
- end
- ]]
- --[[
- if (msgWait > 0) then
- joypad.set(1, {A=1})
- -- emu.pause()
- end
- --]]
- end
- --[[ -- This is used at the top of the Pyramid after Agahnim 1.
- if windowBox == 0x715 then
- if msg == -1 then
- joypad.set(1, {A=1})
- end
- end
- --]]
- end
- -- the next function is auto-displaying the last frame of no input available
- lastGameMode = 0
- lastStatus = 0
- lastRecoil = 0
- lastMotion = 0
- lastGameModeValue = 0
- function chkNoInput()
- gameMode = bit.band(windowBox,0xFF00)
- if gameMode > 0 then
- lastGameMode = movie.framecount()
- end
- if status > 0 then
- lastStatus = movie.framecount()
- end
- if recoil > 0 then
- lastRecoil = movie.framecount()
- end
- if motion > 0 then
- lastMotion = movie.framecount()-1
- end
- gui.text(80,0,string.format("%d",lastGameMode))
- gui.text(204,7,string.format("%d",lastStatus))
- gui.text(128,7,string.format("%d",lastMotion))
- -- gui.text(210,7,string.format("%d",lastRecoil))
- if lastGameModeValue > 0 and gameMode == 0 then
- print("end "..movie.framecount()-1)
- end
- if lastGameModeValue == 0 and gameMode > 0 then
- print("begin "..movie.framecount()-1)
- end
- lastGameModeValue = gameMode
- end
- -- displays Link's position and velocity
- function position()
- gui.text(212,184,string.format("(%04x,%04x)",X,Y))
- gui.text(212,176,posSpeed)
- gui.text(192,194,string.format("ovr (6-e7,4-e3)\nin (6-ea,12-e3)\nEG (8-ea,4-db)"))
- gui.text(164,184,string.format("(%04x,%04x)",CX,CY))
- end
- -- displays enemie's HP and a hitbox
- -- In Arrghus fight, there are 14 enemies.
- function eHPF()
- for j=0,13 do
- if (eHP[j] ~= 0) and (eHP[j] < 250) then
- gui.text(240,0+(j)*8,eHPDisp[j])
- gui.box(relEneX[j], relEneY[j], relEneX[j]+16, relEneY[j]+24)
- -- this meant to target enemies with arrows or stuffs.
- --[[
- gui.line(relEneX[j]+8, 0, relEneX[j]+8, 225)
- gui.line(0, relEneY[j]+12, 255, relEneY[j]+12)
- --]]
- --[[
- gui.line(relEneX[j], 0, relEneX[j], 225)
- gui.line(0, relEneY[j], 255, relEneY[j])
- gui.line(relEneX[j]+16, 0, relEneX[j]+16, 225)
- gui.line(0, relEneY[j]+24, 255, relEneY[j]+24)
- --]]
- end
- end
- end
- -- displays Link's HP and MP
- function HPDisp()
- gui.text(166,14,HP)
- gui.text(24,60,MP)
- end
- -- displays Link's various states
- function state()
- gui.text(220,128,p) -- 0=pegasus boots dash; 29=spin dash
- gui.text(220,136,s) -- charging time for spin attack
- gui.text(220,144,b) -- timer for exploding a bomb
- gui.text(220,152,g) -- timer for grabbing
- gui.text(220,164,r) -- RNG
- end
- lastGrab = 0
- grabCount = 0
- function grabTimer()
- if (grab > 0 and grab ~= 30 and grab ~= 1) and (lastGrab == 0 or lastGrab == 30) then
- grabCount = movie.framecount() + 17
- end
- gui.text(220,118,grabCount.."+4 A")
- lastGrab = grab
- end
- -- displays the number of rupees, bombs and arrows for after YBA with spin attack
- function RupeeBombArrow()
- gui.text(80,16,rupee)
- gui.text(108,16,numBomb)
- gui.text(128,16,numArrows)
- end
- -- floating glitch without Macro (to deal with odd/even problem)
- function oddA()
- if movie.framecount() % 2 == 0 then
- joypad.set(1,{A=1})
- end
- end
- -- same above
- function evenA()
- if movie.framecount() % 2 == 1 then
- joypad.set(1,{A=1})
- end
- end
- -- poke sword
- function pokeSword()
- joypad.set(1,{B=1})
- end
- function playbackStopsAtLast()
- if movie.readonly() then
- if movie.framecount()+1 == movie.length() then
- emu.pause()
- end
- end
- end
- function AnyHitBox(Xul,Yul,Xdr,Ydr) -- ul=upleft, dr=downright
- Xul = (Xul - cameraX) % 256
- Yul = (Yul - cameraY) % 256
- Xdr = (Xdr - cameraX) % 256
- Ydr = (Ydr - cameraY) % 256
- gui.box(Xul,Yul,Xdr,Ydr)
- end
- -- for chest game, digging game, Agahnim manipulation or something. repeats input with one frame delay
- function try()
- -- emu.speedmode("turbo")
- local state = savestate.create()
- savestate.save(state)
- emu.frameadvance()
- savestate.load(state)
- local try1=0
- for i=1,200 do
- savestate.load(state)
- joypad.set(1,{B=1})
- emu.frameadvance()
- savestate.save(state)
- joypad.set(1,{B=1})
- emu.frameadvance()
- ---[[
- for j=1,500 do
- -- joypad.set(1,{A=1})
- -- joypad.set(1,{Y=1})
- -- joypad.set(1,{B=1})
- gui.text(16,52,try1)
- emu.frameadvance()
- end
- --]]
- try1=try1+1
- print(try1)
- end
- end
- while true do
- lastLag() -- for rough indication of the next input frame
- ramRead() -- reads RAM
- autoMsg() -- auto scroll text messages. when msgWait is not 0, you have to scroll them manually.
- RupeeBombArrow() -- displays the number of rupees, bombs and arrows for after YBA with spin attack
- position() -- displays Link's position and velocity
- eHPF() -- displays enemie's HP and a hitbox
- HPDisp() -- displays Link's HP and MP
- -- toFrame(100000) -- for fastforwarding to the frame
- state() -- displays Link's various states
- chkNoInput() -- check you cannot input
- grabTimer() -- estimate when you can begin moving after grab something.
- -- the next function is auto-displaying the last frame of no input available.
- -- try() -- for chest game and digging game or something. repeats input with one frame delay
- -- oddA() -- floating glitch without Macro (to deal with odd/even problem)
- -- evenA() -- same above
- -- pokeSword() -- poke sword
- playbackStopsAtLast()
- -- AnyHitBox(0x5c,0x48,0x6c,0x58)
- -- emu.pause()
- emu.frameadvance()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement