Advertisement
Guest User

Untitled

a guest
Oct 30th, 2017
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.66 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.  
  3. -- for fastforwarding to the frame
  4. function toFrame(frame)
  5.     if movie.framecount() -1 > frame then
  6.         emu.pause()
  7.     end
  8. end
  9.  
  10. -- for rough indication of the next input frame
  11. lastLagFr = 0
  12. function lastLag()
  13.     if emu.lagged() then
  14.         lastLagFr = movie.framecount() - 2
  15.     end
  16.     gui.text(0, 0, string.format("%d",lastLagFr))
  17. end
  18.  
  19. local eHP={}            -- enemy HP
  20. local eHPDisp={}        -- enemy HP Display
  21. local itemDrop={}       -- item Drop (prize pack manipulation)
  22. local eX = {}           -- enemy's X position
  23. local eY = {}           -- enemy's Y position
  24. 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
  25. 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
  26.  
  27. -- reads RAM
  28. function ramRead()
  29.     rupee = memory.readword(0x7EF360)       -- rupee   
  30.     numBomb = memory.readbyte(0x7EF343)     -- number of bombs for after YBA with spin attack
  31.     numArrows = memory.readbyte(0x7EF377)   -- number of arrows for after YBA with spin attack
  32.     x = memory.readbyte(0x7E0022)           -- Link's X position
  33.     y = memory.readbyte(0x7E0020)           -- Link's Y position
  34.     pos = string.format("(%2x,%2x)",x,y)    -- means Link's position, (X, Y). I think HEXed value is more useful.
  35.     cameraX = memory.readbyte(0x7E011E)     -- camera's X
  36.     cameraY = memory.readbyte(0x7E0122)     -- camera's Y
  37.     hitX = (x-cameraX) % 256                -- top-left X position of Link's hitbox
  38.     hitY = (y-cameraY) % 256                -- top-left Y position of Link's hitbox
  39.     gui.box(hitX, hitY, hitX+16, hitY+24)   -- displaying Link's hitbox
  40.    
  41.     -- assigns enemy's HP, X and Y position, and top-left X and Y position of enemy's hitbox
  42.     for i=0,8 do
  43.         eHP[i] = memory.readbyte(0x7E0E50+i)
  44.         eHPDisp[i]=string.format("%3d",eHP[i])
  45.         eX[i] = memory.readbyte(0x7E0D10+i)
  46.         eY[i] = memory.readbyte(0x7E0D00+i)
  47.         relEneX[i] = (eX[i] - cameraX) % 256
  48.         relEneY[i] = (eY[i] - cameraY) % 256
  49.     end
  50.     HP=memory.readbyte(0x7EF36D)                        -- Link's HP
  51.     string.format("%3d",HP)
  52.     MP=memory.readbyte(0x7EF36E)                        -- Link's MP
  53.     string.format("%3d",MP)
  54.     xSpeed=memory.readbytesigned(0x7E0031)              -- Link's X speed
  55.     ySpeed=memory.readbytesigned(0x7E0030)              -- Link's Y speed
  56.     posSpeed = string.format(" %2d,%2d ",xSpeed,ySpeed) -- means Link's (X speed, Y speed)
  57.    
  58.     peg=memory.readbyte(0x7E0374)                       -- 0=pegasus boots dash; 29=spin dash
  59.     bomb=memory.readbyte(0x7E03A0)                      -- timer for exploding a bomb
  60.     spinAttack=memory.readbyte(0x7E0079)                -- charging time for spin attack
  61.     rng=memory.readword(0x7E0FA0)                       -- RNG
  62.     grab=memory.readbyte(0x7E0DFF)                      -- timer for grabbing
  63.      
  64.     --[[    -- assigns prize pack manipulation, but this code does not display for the lack of gui.text. should use 'RAM Watch.'
  65.     for i=0,6 do
  66.         itemDrop[i]=memory.readbyte(0x7E0FC7+i)
  67.     end
  68.     -- Quards, Rupees, Magic, Bombs, Arrows, Skeleton, Big
  69.     --]]
  70.    
  71.     --[[
  72.     layer=memory.readbyte(0x7E0476)         -- Link's current Layer
  73.     0x7E00A0                                -- Link's current room for EG. HEXed value should be used on 'RAM Watch.'
  74.     -]]
  75.    
  76.     p=string.format("peg %2d",peg)
  77.     s=string.format("spn %2x",spinAttack)
  78.     b=string.format("bom %2d",bomb)
  79.     r=string.format("rng %4x",rng)
  80.     g=string.format("grb %2d",grab)
  81.    
  82.     status = memory.readbyte(0x7E004D)      -- Link's current status. 0=able to be inputted.
  83.     recoil = memory.readbyte(0x7E0046)      -- Link's current recoiling status. 0=able to be inputted.
  84.     push = memory.readbyte(0x7E0371) - 13   -- state of pushing a block. 0=begin to move the block.
  85.     ledge = memory.readbyte(0x7E0375)       -- Link's current ledge off status. 0=begin to ledge off. used when you don't have pegasus boots.
  86.     motion = memory.readbyte(0x7E0354)      -- Link's current motion (slashing, using staff, arrow, etc). 0=able to be inputted.
  87.    
  88.     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.
  89. end
  90.  
  91. -- auto scroll text messages. when msgWait is not 0, you have to scroll them manually.
  92. function autoMsg()
  93.     windowBox = memory.readword(0x7E0010)
  94.     msg = memory.readbyte(0x7E1CE9) - 1
  95.     msgWait = memory.readbyte(0x7E1CE0)
  96.     gui.text(40, 0, string.format("%d %d %X", msg, msgWait, windowBox))
  97.     if windowBox == 0x20E then
  98.         if msg == 0 then
  99.             joypad.set(1, {A=1})
  100.         end
  101.     --[[
  102.         if (msgWait > 0) then
  103.         joypad.set(1, {A=1})
  104.         -- emu.pause()
  105.         end
  106.     --]]
  107.     end
  108. end
  109.  
  110. -- the next function is auto-displaying the last frame of no input available
  111. lastGameMode = 0
  112. lastStatus = 0
  113. lastRecoil = 0
  114. lastMotion = 0
  115. function chkNoInput()
  116.     gameMode = bit.band(windowBox,0xFF00)
  117.    
  118.     if gameMode > 0 then
  119.         lastGameMode = movie.framecount()+1
  120.     end
  121.     if status > 0 then
  122.         lastStatus = movie.framecount()+1
  123.     end
  124.     if recoil > 0 then
  125.         lastRecoil = movie.framecount()+1
  126.     end
  127.     if motion > 0 then
  128.         lastMotion = movie.framecount()
  129.     end
  130.    
  131.     gui.text(80,0,string.format("%d",lastGameMode))
  132.     gui.text(204,7,string.format("%d",lastStatus))
  133.     gui.text(128,7,string.format("%d",lastMotion))
  134.     -- gui.text(210,7,string.format("%d",lastRecoil))
  135. end
  136.  
  137. -- displays Link's position and |velocity|
  138. function position()
  139.     gui.text(228,208,pos)
  140.     gui.text(228,200,posSpeed)
  141. end
  142.  
  143. -- displays enemie's HP and a hitbox
  144. function eHPF()
  145.     for j=0,8 do
  146.         if (eHP[j] ~= 0) and (eHP[j] < 250) then
  147.             gui.text(240,0+(j)*8,eHPDisp[j])
  148.             gui.box(relEneX[j], relEneY[j], relEneX[j]+16, relEneY[j]+24)
  149.            
  150.             -- this meant to target enemies with arrows or stuffs.
  151.             --[[
  152.             gui.line(relEneX[j]+8, 0, relEneX[j]+8, 225)
  153.             gui.line(0, relEneY[j]+12, 255, relEneY[j]+12)         
  154.             --]]
  155.             --[[
  156.             gui.line(relEneX[j], 0, relEneX[j], 225)
  157.             gui.line(0, relEneY[j], 255, relEneY[j])
  158.             gui.line(relEneX[j]+16, 0, relEneX[j]+16, 225)
  159.             gui.line(0, relEneY[j]+24, 255, relEneY[j]+24)
  160.             --]]
  161.            
  162.         end
  163.     end
  164. end
  165.  
  166. -- displays Link's HP and MP
  167. function HPDisp()
  168.     gui.text(166,14,HP)
  169.     gui.text(22,60,MP)
  170. end
  171.  
  172. -- displays Link's various states
  173. function state()
  174.     gui.text(220,152,p)     -- 0=pegasus boots dash; 29=spin dash
  175.     gui.text(220,160,s)     -- charging time for spin attack
  176.     gui.text(220,168,b)     -- timer for exploding a bomb
  177.     gui.text(220,176,g)     -- timer for grabbing
  178.     gui.text(220,188,r)     -- RNG
  179. end
  180.  
  181. -- displays the number of rupees, bombs and arrows for after YBA with spin attack
  182. function RupeeBombArrow()
  183.     gui.text(80,16,rupee)
  184.     gui.text(108,16,numBomb)
  185.     gui.text(128,16,numArrows)
  186. end
  187.  
  188. -- for chest game and digging game or something. repeats input with one frame delay
  189. function try()
  190.     emu.speedmode("turbo")
  191.     local state = savestate.create()
  192.     savestate.save(state)
  193.     local try1=0
  194.     for i=1,1000 do
  195.         savestate.load(state)
  196.         emu.frameadvance()
  197.         savestate.save(state)
  198.         for j=1,500 do
  199.             -- joypad.set(1,{A=1})
  200.             joypad.set(1,{Y=1})
  201.  
  202.             gui.text(16,52,try1)
  203.             emu.frameadvance()
  204.         end
  205.         try1=try1+1
  206.     end
  207. end
  208.  
  209. while true do
  210.     lastLag()               -- for rough indication of the next input frame
  211.     ramRead()               -- reads RAM
  212.     autoMsg()               -- auto scroll text messages. when msgWait is not 0, you have to scroll them manually.
  213.     RupeeBombArrow()        -- displays the number of rupees, bombs and arrows for after YBA with spin attack
  214.     position()              -- displays Link's position and |velocity|
  215.     eHPF()                  -- displays enemie's HP and a hitbox
  216.     HPDisp()                -- displays Link's HP and MP
  217.     -- toFrame(205000)      -- for fastforwarding to the frame
  218.     state()                 -- displays Link's various states
  219.     chkNoInput()            -- the next function is auto-displaying the last frame of no input available.
  220.     -- try()                -- for chest game and digging game or something. repeats input with one frame delay
  221.    
  222.     emu.frameadvance()
  223. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement