Advertisement
Guest User

Untitled

a guest
Dec 8th, 2017
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.52 KB | None | 0 0
  1. -- This script is for a Japanese version of 'A Link to the Past', or 'Zelda no Densetsu - Kamigami no Triforce'.
  2. -- version 2
  3. -- Source code is not sophisticated at all. Names of variables are strange. So, you can revise them freely.
  4.  
  5.  
  6. -- for fastforwarding to the frame
  7. function toFrame(frame)
  8.     if movie.framecount()+1 == frame then
  9.         emu.pause()
  10.     end
  11. end
  12.  
  13. -- for rough indication of the next input frame
  14. lastLagFr = 0
  15. function lastLag()
  16.     if emu.lagged() then
  17.         lastLagFr = movie.framecount() - 2
  18.     end
  19.     gui.text(0, 0, string.format("%d",lastLagFr))
  20. end
  21.  
  22. local eHP={}            -- enemy HP
  23. local eHPDisp={}        -- enemy HP Display
  24. local itemDrop={}       -- item Drop (prize pack manipulation)
  25. local eX = {}           -- enemy's X position
  26. local eY = {}           -- enemy's Y position
  27. 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
  28. 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
  29.  
  30. -- reads RAM
  31. function ramRead()
  32.     rupee = memory.readword(0x7EF360)       -- rupee   
  33.     numBomb = memory.readbyte(0x7EF343)     -- number of bombs for after YBA with spin attack
  34.     numArrows = memory.readbyte(0x7EF377)   -- number of arrows for after YBA with spin attack
  35.     x = memory.readbyte(0x7E0022)           -- Link's X position
  36.     superX = memory.readbyte(0x7E0023)
  37.     X = memory.readword(0x7E0022)
  38.     y = memory.readbyte(0x7E0020)           -- Link's Y position
  39.     superY = memory.readbyte(0x7E0021)
  40.     Y = memory.readword(0x7E0020)
  41.     pos = string.format("(%2x,%2x)",x,y)    -- means Link's position, (X, Y). I think HEXed value is more useful.
  42.     cameraX = memory.readbyte(0x7E011E)     -- camera's X
  43.     CX = memory.readword(0x7E011E)
  44.     cameraY = memory.readbyte(0x7E0122)     -- camera's Y
  45.     CY = memory.readword(0x7E0122)
  46.     hitX = (x-cameraX) % 256                -- top-left X position of Link's hitbox
  47.     hitY = (y-cameraY) % 256                -- top-left Y position of Link's hitbox
  48.     gui.box(hitX, hitY, hitX+16, hitY+24)   -- displaying Link's hitbox
  49.    
  50.     armedEG = memory.readbyte(0x7E047A)
  51.     waterWalk = memory.readbyte(0x7E005B)
  52.    
  53.     -- assigns enemy's HP, X and Y position, and top-left X and Y position of enemy's hitbox
  54.     -- In Arrghus fight, there are 14 enemies.
  55.     for i=0,13 do
  56.         eHP[i] = memory.readbyte(0x7E0E50+i)
  57.         eHPDisp[i]=string.format("%3d",eHP[i])
  58.         eX[i] = memory.readbyte(0x7E0D10+i)
  59.         eY[i] = memory.readbyte(0x7E0D00+i)
  60.         relEneX[i] = (eX[i] - cameraX) % 256
  61.         relEneY[i] = (eY[i] - cameraY) % 256
  62.     end
  63.     HP=memory.readbyte(0x7EF36D)                        -- Link's HP
  64.     string.format("%3d",HP)
  65.     MP=memory.readbyte(0x7EF36E)                        -- Link's MP
  66.     string.format("%3d",MP)
  67.     xSpeed=memory.readbytesigned(0x7E0031)              -- Link's X speed
  68.     ySpeed=memory.readbytesigned(0x7E0030)              -- Link's Y speed
  69.     posSpeed = string.format(" %4d,%4d ",xSpeed,ySpeed) -- means Link's (X speed, Y speed)
  70.    
  71.     peg=memory.readbyte(0x7E0374)                       -- 0=pegasus boots dash; 29=spin dash
  72.     bomb=memory.readbyte(0x7E03A0)                      -- timer for exploding a bomb
  73.     spinAttack=memory.readbyte(0x7E0079)                -- charging time for spin attack
  74.     rng=memory.readword(0x7E0FA0)                       -- RNG
  75.     grab=memory.readbyte(0x7E0DFF)                      -- timer for grabbing
  76.      
  77.     --[[    -- assigns prize pack manipulation, but this code does not display for the lack of gui.text. should use 'RAM Watch.'
  78.     for i=0,6 do
  79.         itemDrop[i]=memory.readbyte(0x7E0FC7+i)
  80.     end
  81.     -- Quards, Rupees, Magic, Bombs, Arrows, Skeleton, Big
  82.     --]]
  83.    
  84.     --[[
  85.     layer=memory.readbyte(0x7E0476)         -- Link's current Layer
  86.     0x7E00A0                                -- Link's current room for EG. HEXed value should be used on 'RAM Watch.'
  87.     -]]
  88.    
  89.     p=string.format("peg %2d",peg)
  90.     s=string.format("spn %2x",spinAttack)
  91.     b=string.format("bom %2d",bomb)
  92.     r=string.format("rng %4x",rng)
  93.     g=string.format("grb %2d",grab)
  94.    
  95.     status = memory.readbyte(0x7E004D)      -- Link's current status. 0=able to be inputted.
  96.     recoil = memory.readbyte(0x7E0046)      -- Link's current recoiling status. 0=able to be inputted.
  97.     push = memory.readbyte(0x7E0371) - 13   -- state of pushing a block. 0=begin to move the block.
  98.     ledge = memory.readbyte(0x7E0375)       -- Link's current ledge off status. 0=begin to ledge off. used when you don't have pegasus boots.
  99.     motion = memory.readbyte(0x7E0354)      -- Link's current motion (slashing, using staff, arrow, etc). 0=able to be inputted.
  100.    
  101.     EG = memory.readbyte(0x7E00A0)  -- Dungeon Room ID. useful for EG.
  102.     layer=memory.readbyte(0x7E0476)         -- Link's current Layer
  103.    
  104.     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.
  105.     gui.text(0,30,string.format("EG %02X",EG))  -- displaying EG ID
  106.     gui.text(0,37,string.format("lyr%2d",layer))    -- displaying Link's current layer
  107.    
  108.     X2 = math.floor(bit.rshift(bit.band(X,0xFF00),8)/2)
  109.     Y2 = math.floor(bit.rshift(bit.band(Y,0xFF00),8)/2)
  110.     CX2 = math.floor(bit.rshift(bit.band(CX,0xFF00),8)/2)
  111.     CY2 = math.floor(bit.rshift(bit.band(CY,0xFF00),8)/2)
  112.     gui.text(0,52,string.format("p  %01X%01X",Y2,X2))
  113.     gui.text(0,59,string.format("c  %01X%01X",CY2,CX2))
  114.    
  115.     dungeonID = memory.readbyte(0x7E010E)
  116.     gui.text(0,44,string.format("ID %X",dungeonID))
  117.    
  118.     gui.text(0,72,string.format("amdEG %d",armedEG))
  119.     gui.text(0,79,string.format("WWlk %d",waterWalk))
  120.    
  121.     direction = memory.readbyte(0x7E002F)
  122.    
  123.     -- useful after YBA with spinattack in Swamp
  124.     Direc = ""
  125.     if direction == 0 then
  126.         Direc = "UP"
  127.     elseif direction == 2 then
  128.         Direc = "DOWN"
  129.     elseif direction == 4 then
  130.         Direc = "LEFT"
  131.     elseif direction == 6 then
  132.         Direc = "RIGHT"
  133.     end
  134.    
  135.     gui.text(234,108,Direc)
  136.    
  137. end
  138.  
  139. -- auto scroll text messages. when msgWait is not 0, you have to scroll them manually.
  140. function autoMsg()
  141.     windowBox = memory.readword(0x7E0010)   -- This may be bad name. It should be GameMode.
  142.     msg = memory.readbyte(0x7E1CE9) - 1
  143.     msgWait = memory.readbyte(0x7E1CE0)     -- It seems used in opening
  144.     gui.text(40, 0, string.format("%d %d %X", msg, msgWait, windowBox))
  145.     if windowBox == 0x20E or windowBox == 0x219 then    -- 0x219: Triforce Room
  146.     ---[[
  147.         if msg == 0 then
  148.             joypad.set(1, {A=1})
  149.         end
  150.     --]]
  151.     --[[    -- should be used at opening
  152.     if (msgWait > 0) then
  153.         print("message: "..movie.framecount()-1)
  154.         emu.pause()
  155.     end
  156.     ]]
  157.     --[[
  158.         if (msgWait > 0) then
  159.         joypad.set(1, {A=1})
  160.         -- emu.pause()
  161.         end
  162.     --]]
  163.     end
  164.     --[[    -- This is used at the top of the Pyramid after Agahnim 1.
  165.     if windowBox == 0x715 then
  166.         if msg == -1 then
  167.             joypad.set(1, {A=1})
  168.         end
  169.     end
  170.     --]]
  171. end
  172.  
  173. -- the next function is auto-displaying the last frame of no input available
  174. lastGameMode = 0
  175. lastStatus = 0
  176. lastRecoil = 0
  177. lastMotion = 0
  178. lastGameModeValue = 0
  179. function chkNoInput()
  180.     gameMode = bit.band(windowBox,0xFF00)
  181.    
  182.     if gameMode > 0 then
  183.         lastGameMode = movie.framecount()
  184.     end
  185.     if status > 0 then
  186.         lastStatus = movie.framecount()
  187.     end
  188.     if recoil > 0 then
  189.         lastRecoil = movie.framecount()
  190.     end
  191.     if motion > 0 then
  192.         lastMotion = movie.framecount()-1
  193.     end
  194.    
  195.     gui.text(80,0,string.format("%d",lastGameMode))
  196.     gui.text(204,7,string.format("%d",lastStatus))
  197.     gui.text(128,7,string.format("%d",lastMotion))
  198.     -- gui.text(210,7,string.format("%d",lastRecoil))
  199.    
  200.     if lastGameModeValue > 0 and gameMode == 0 then
  201.         print("end   "..movie.framecount()-1)
  202.     end
  203.     if lastGameModeValue == 0 and gameMode > 0 then
  204.         print("begin "..movie.framecount()-1)
  205.     end
  206.     lastGameModeValue = gameMode
  207. end
  208.  
  209. -- displays Link's position and velocity
  210. function position()
  211.     gui.text(212,184,string.format("(%04x,%04x)",X,Y))
  212.     gui.text(212,176,posSpeed)
  213.     gui.text(192,194,string.format("ovr (6-e7,4-e3)\nin  (6-ea,12-e3)\nEG  (8-ea,4-db)"))
  214.     gui.text(164,184,string.format("(%04x,%04x)",CX,CY))
  215.    
  216. end
  217.  
  218. -- displays enemie's HP and a hitbox
  219. -- In Arrghus fight, there are 14 enemies.
  220. function eHPF()
  221.     for j=0,13 do
  222.         if (eHP[j] ~= 0) and (eHP[j] < 250) then
  223.             gui.text(240,0+(j)*8,eHPDisp[j])
  224.             gui.box(relEneX[j], relEneY[j], relEneX[j]+16, relEneY[j]+24)
  225.            
  226.             -- this meant to target enemies with arrows or stuffs.
  227.             --[[
  228.             gui.line(relEneX[j]+8, 0, relEneX[j]+8, 225)
  229.             gui.line(0, relEneY[j]+12, 255, relEneY[j]+12)         
  230.             --]]
  231.             --[[
  232.             gui.line(relEneX[j], 0, relEneX[j], 225)
  233.             gui.line(0, relEneY[j], 255, relEneY[j])
  234.             gui.line(relEneX[j]+16, 0, relEneX[j]+16, 225)
  235.             gui.line(0, relEneY[j]+24, 255, relEneY[j]+24)
  236.             --]]
  237.            
  238.         end
  239.     end
  240. end
  241.  
  242. -- displays Link's HP and MP
  243. function HPDisp()
  244.     gui.text(166,14,HP)
  245.     gui.text(24,60,MP)
  246. end
  247.  
  248. -- displays Link's various states
  249. function state()
  250.     gui.text(220,128,p)     -- 0=pegasus boots dash; 29=spin dash
  251.     gui.text(220,136,s)     -- charging time for spin attack
  252.     gui.text(220,144,b)     -- timer for exploding a bomb
  253.     gui.text(220,152,g)     -- timer for grabbing
  254.     gui.text(220,164,r)     -- RNG
  255. end
  256.  
  257. lastGrab = 0
  258. grabCount = 0
  259. function grabTimer()
  260.     if (grab > 0 and grab ~= 30 and grab ~= 1) and (lastGrab == 0 or lastGrab == 30) then
  261.         grabCount = movie.framecount() + 17
  262.     end
  263.     gui.text(220,118,grabCount.."+4 A")
  264.     lastGrab = grab
  265. end
  266.  
  267.  
  268. -- displays the number of rupees, bombs and arrows for after YBA with spin attack
  269. function RupeeBombArrow()
  270.     gui.text(80,16,rupee)
  271.     gui.text(108,16,numBomb)
  272.     gui.text(128,16,numArrows)
  273. end
  274.  
  275. -- floating glitch without Macro (to deal with odd/even problem)
  276. function oddA()
  277.     if movie.framecount() % 2 == 0 then
  278.         joypad.set(1,{A=1})
  279.     end
  280. end
  281. -- same above
  282. function evenA()
  283.     if movie.framecount() % 2 == 1 then
  284.         joypad.set(1,{A=1})
  285.     end
  286. end
  287.  
  288. -- poke sword
  289. function pokeSword()
  290.     joypad.set(1,{B=1})
  291. end
  292.  
  293. function playbackStopsAtLast()
  294.     if movie.readonly() then
  295.         if movie.framecount()+1 == movie.length() then
  296.             emu.pause()
  297.         end
  298.     end
  299. end
  300.  
  301. function AnyHitBox(Xul,Yul,Xdr,Ydr) -- ul=upleft, dr=downright
  302.     Xul = (Xul - cameraX) % 256
  303.     Yul = (Yul - cameraY) % 256
  304.     Xdr = (Xdr - cameraX) % 256
  305.     Ydr = (Ydr - cameraY) % 256
  306.     gui.box(Xul,Yul,Xdr,Ydr)
  307. end
  308.  
  309.  
  310. -- for chest game, digging game, Agahnim manipulation or something. repeats input with one frame delay
  311. function try()
  312.     -- emu.speedmode("turbo")
  313.     local state = savestate.create()
  314.     savestate.save(state)
  315.     emu.frameadvance()
  316.     savestate.load(state)
  317.     local try1=0
  318.     for i=1,200 do
  319.         savestate.load(state)
  320.         joypad.set(1,{B=1})
  321.         emu.frameadvance()
  322.         savestate.save(state)
  323.         joypad.set(1,{B=1})
  324.         emu.frameadvance()
  325.         ---[[
  326.         for j=1,500 do
  327.             -- joypad.set(1,{A=1})
  328.             -- joypad.set(1,{Y=1})
  329.             -- joypad.set(1,{B=1})
  330.  
  331.             gui.text(16,52,try1)
  332.             emu.frameadvance()
  333.         end
  334.         --]]
  335.         try1=try1+1
  336.         print(try1)
  337.     end
  338. end
  339.  
  340. while true do
  341.     lastLag()               -- for rough indication of the next input frame
  342.     ramRead()               -- reads RAM
  343.     autoMsg()               -- auto scroll text messages. when msgWait is not 0, you have to scroll them manually.
  344.     RupeeBombArrow()        -- displays the number of rupees, bombs and arrows for after YBA with spin attack
  345.     position()              -- displays Link's position and velocity
  346.     eHPF()                  -- displays enemie's HP and a hitbox
  347.     HPDisp()                -- displays Link's HP and MP
  348.     -- toFrame(100000)      -- for fastforwarding to the frame
  349.     state()                 -- displays Link's various states
  350.     chkNoInput()            -- check you cannot input
  351.     grabTimer()             -- estimate when you can begin moving after grab something.
  352.     -- the next function is auto-displaying the last frame of no input available.
  353.     -- try()                -- for chest game and digging game or something. repeats input with one frame delay
  354.    
  355.     -- oddA()               -- floating glitch without Macro (to deal with odd/even problem)
  356.     -- evenA()              -- same above
  357.     -- pokeSword()          -- poke sword
  358.    
  359.     playbackStopsAtLast()
  360.    
  361.     -- AnyHitBox(0x5c,0x48,0x6c,0x58)  
  362.     -- emu.pause()
  363.    
  364.     emu.frameadvance()
  365. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement