Advertisement
feos

NinjaGaidenHUD

Apr 9th, 2014
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.06 KB | None | 0 0
  1. lastxposAbs = 0
  2. RyuRow = 0
  3. curves = {}
  4.  
  5. function NGRAMview()
  6.     xpos      = memory.readbyte(0x86)+memory.readbyte(0x85)/256
  7.     yspdsub   = memory.readbyte(0x87)/0x37
  8.     yspd      = memory.readbytesigned(0x89)+yspdsub/5
  9.     yspda     = yspd/5
  10.     yspdasub  = yspd%5
  11.     ypos      = memory.readbyte(0x8A)
  12.     scrnpos   = memory.readbyte(0xA3)
  13.     scrnsub   = memory.readbyte(0xA2)
  14.     scrnHi    = memory.readbytesigned(0x52)
  15.     xposAbs   = scrnpos+xpos+scrnsub/256+scrnHi*256
  16.     xspd      = xposAbs-lastxposAbs
  17.     rngb      = memory.readbyte(0xBF)
  18.     bosshp    = memory.readbyte(0x497)
  19.     abosshp   = memory.readbyte(0x496)
  20.     inv       = memory.readbyte(0x95)
  21.     interrupt = AND(memory.readbyte(0x4C),0x40)
  22.     collision = tobitstring(memory.readbyte(0x8c))
  23.     tmrsub    = memory.readbyte(0x62)
  24.     tmr       = memory.readbyte(0x63)
  25. --  yposQ     = AND(ypos,0x10)
  26. --  rnga      = memory.readbyte(0xB5)
  27. --  shifted   = bit.rshift(rngb,1)
  28. --  anded     = bit.band(rngb,1)
  29.     ViewBG(1)
  30.     PredictBird()  
  31.     for i = 0, 7 do
  32.         id      = memory.readbyte(0x400+i)
  33.         time    = memory.readbyte(0x408+i)
  34.         action  = memory.readbyte(0x410+i)
  35.         mov     = memory.readbyte(0x438+i)
  36.         xsubspd = memory.readbyte(0x448+i)/0x10
  37.         xspeed  = memory.readbytesigned(0x450+i)
  38.         xsub    = memory.readbyte(0x458+i)
  39.         x       = memory.readbyte(0x460+i)
  40.         ysubspd = memory.readbyte(0x468+i)
  41.         yspeed  = memory.readbyte(0x470+i)
  42.         ysub    = memory.readbyte(0x478+i)
  43.         y       = memory.readbyte(0x480+i)
  44.         BGcoll  = memory.readbyte(0x488+i)
  45.         hp      = memory.readbyte(0x490+i)
  46.         state   = memory.readbyte(0x498+i)
  47.         if (state ~= 0) then
  48.             if (BGcoll ~= 0) then color5 = "red" else color5 = "white" end
  49.             gui.text(x,y,string.format("%d",i))
  50.             if (id == 0) then gui.text(x+6,y,string.format(":%X",action),color5) end
  51.             if (time > 0) then gui.text(x,y,string.format("\n%d",time),color) end  
  52.         end
  53.         if (interrupt > 0) then color = "red" else color = "white" end
  54.         if  (id == 18) or ((id == 11) and (state ~= 0)) then
  55.             gui.text(x,y,string.format("%d.%d",xspeed,xsubspd))
  56.         end
  57.         gui.text(i*32+3,1,string.format("%d: %X\n%02X.%02X\n%02X.%02X",
  58.             i,id,x,xsub,y,ysub),"#ffccaaff","black")
  59.     end
  60.     gui.box(0,25,64,40,"#000000ff")
  61.     gui.text(xpos-8,ypos-18,string.format("%.1f",xspd))
  62.     gui.text(73, 41,string.format("%3d:%2d",tmr,tmrsub),"#ffccaaff","black")
  63.     gui.text(128,25,string.format("S: %.1f",scrnpos+scrnsub/256+scrnHi*256),"#44ffffff","#000000ff")
  64.     gui.text(0,  25,string.format("X: %.1f\nY: %3d\ndY: %.1f \nBG: %s",xposAbs,ypos,yspd,collision),"#44ffffff","#000000ff")
  65.     gui.text(212,25,"Interrupt",color,"#000000ff")
  66.     if (inv > 0) then gui.text(242,33,string.format("%02d",inv),"#ffccaaff","black") end
  67.     if (bosshp > 0) then
  68.         if (bosshp > 16) then bosshp = abosshp end
  69.         gui.text(242,41,string.format("%02d",abosshp),"#ffccaaff","black")
  70.     end
  71.     lastxposAbs = xposAbs
  72.     Spawns()
  73. end
  74.  
  75. function Spawns()
  76.     -- feos, 2014
  77.     -- uncovers which spawns will occur per frame
  78.     local SubCur= memory.readbyte(0x50)/25.6
  79.     local PosCur= AND(memory.readbyte(0x51),0xF)
  80.     local BlCur = memory.readbyte(0x4E)
  81.     local Blptr = memory.readword(0x96)
  82.     local Yptr  = memory.readword(0x98)
  83.     local IDptr = memory.readword(0x9A)
  84.     local Count = memory.readbyte(0xB4)
  85.     local Iterator = memory.readbyte(0xB5)-8
  86.     local IteratorLast = memory.readbyte(0xB5)-1
  87.     while (Iterator < 0) do Iterator = Count+Iterator end
  88.     if (IteratorLast < 0) then IteratorLast = Count+IteratorLast end   
  89.     local Interrupt = AND(memory.readbyte(0x4C),0x40)
  90.     if (memory.readbyte(0x1FC) == 0x87)
  91.     or (memory.readbyte(0x1F3) == 0xD8) then
  92.         for i = 0,Count-1 do
  93.             local color1 = "white"
  94.             local block = memory.readbyte(Blptr+i)
  95.             local ypos  = memory.readbyte(Yptr +i)
  96.             local id    = memory.readbyte(IDptr+i)
  97.             local x = i*16%256+1
  98.             local y = 57+math.floor(i/16)*30
  99.             if (block == BlCur) then gui.box(x-1,y-1,x+12,y+23,"#00ff0088") end
  100.             if (i+1 >= Iterator) and (i+1 < Iterator+8)
  101.             or (i+1 < Iterator+8-Count) then color1 = "#ffccaaff" end
  102.             if (Interrupt > 0) then color2 = "red" else color2 = "#44ffffff" end
  103.             gui.text(x,y,string.format("%X\n%X\n%X",block,ypos,id),color1)
  104.             gui.text(108,41,string.format("Block: %X.%02d.%d\nIterator: %02d-%02d/%d",
  105.                 BlCur,PosCur,SubCur,Iterator,IteratorLast,Count),color2,"#000000ff")
  106.         end
  107.     end
  108. end
  109.  
  110. function GetCell(X,Y)
  111.     local temp = memory.readbyte(0xE7CC+SHIFT(X,4))+memory.readbyte(0x5F)
  112.     if (temp >= 0xC0) then temp = temp-0xC0 end
  113.     Y = Y-0x40
  114.     if (Y < 0) then Y = 0 end
  115.     temp = SHIFT(Y,5)+temp
  116.     return temp
  117. end
  118.  
  119. function DrawBG(arg,offset,x,y)
  120.     local color2 = "#00ff00ff"
  121.     local b = 16
  122.     local function box(color,text)
  123.         gui.box(x,y+offset,x+b,y+offset+b,color)
  124.         if (text == 1) then
  125.             gui.text(x+1,y+offset+1,string.format("%d",arg))
  126.         end
  127.     end
  128.     local function line(up,down,left,right)
  129.         if (up    == 1) then gui.line(x  ,y+offset  ,x+b,y+offset  ,color2) end
  130.         if (down  == 1) then gui.line(x  ,y+offset+b,x+b,y+offset  ,color2) end
  131.         if (left  == 1) then gui.line(x  ,y+offset  ,x  ,y+offset+b,color2) end
  132.         if (right == 1) then gui.line(x+b,y+offset  ,x+b,y+offset+b,color2) end
  133.     end
  134.     if (arg ~= 0) then
  135.         if     (arg == 1) then line(0,0,0,1) -- right wall
  136.         elseif (arg == 2) then line(0,0,1,0) -- left wall
  137.         elseif (arg == 3) then line(0,0,1,1) -- two-sided wall
  138.         elseif (arg == 4) then line(1,0,0,1) -- right corner
  139.         elseif (arg == 5) then line(1,0,1,0) -- left corner
  140.         elseif (arg == 6) then line(1,0,1,1) -- two-sided corner
  141.         elseif (arg == 7) then line(1,0,0,0) -- floor
  142.         elseif (arg == 8) then box("#ff000066",0) -- ejecting block
  143.         elseif (arg == 9) then box("#00ff0000",0) -- ladder
  144.         elseif (arg >= 12) and (arg <= 15)
  145.         then box("#ffffff66",0) -- exits
  146.         else box("#0000ff66",1)
  147.         end
  148.     end
  149. end
  150.  
  151. function ViewBG(style)
  152.     -- feos, 2014
  153.     -- style: 0=none, 1=new, 2=old, 3=both
  154.     local base = 0x300
  155.     local RyuX = memory.readbyte(0x86)
  156.     local RyuY = memory.readbyte(0x8A)
  157.     local RyuYspeed = memory.readbytesigned(0x89)
  158.     local RyuXspeed = memory.readbytesigned(0xAD)+memory.readbyte(0xAC)/256
  159.     if (AND(memory.readbyte(0x84),4) == 0) then RyuYspeed = 0 end
  160.     local RyuCell = GetCell(RyuX, RyuY+RyuYspeed)
  161.     local RyuRow = math.floor(RyuCell/6)
  162.     local Screen = memory.readwordsigned(0x51)
  163.     if (AND(style,1) == 1)
  164.     and (memory.readbyte(0x1FC) == 0x87)
  165.     or  (memory.readbyte(0x1F3) == 0xD8) then
  166.         for tRow = RyuRow-14, RyuRow+14 do
  167.             for tLine = 0,5 do
  168.                 local address = base+((tRow*6+tLine)%0xC0)
  169.                 local hi = SHIFT(memory.readbyte(address),  4)
  170.                 local lo =   AND(memory.readbyte(address),0xF)
  171.                 local x = (tRow-RyuRow)*16+RyuX-RyuX%0x10-Screen%0x10
  172.                 local y = tLine*32+64
  173.                 DrawBG(hi, 0,x,y)
  174.                 DrawBG(lo,16,x,y)
  175.             end
  176.         end
  177.         gui.box(xpos-9,ypos+RyuYspeed-1,xpos+5,ypos+RyuYspeed-5,"#0000ff66")
  178.     end
  179.     if (AND(style,2) == 2) then
  180.         for cell = 0,191 do
  181.             local hi = SHIFT(memory.readbyte(base+cell),  4)
  182.             local lo =   AND(memory.readbyte(base+cell),0xF)
  183.             local bX = math.floor(cell/6)
  184.             local bY = cell%6
  185.             local rX = (RyuRow%32)*6-1
  186.             local rY = math.floor(RyuY/16)*8-32
  187.             if (hi == 0) then hi = " " else hi = string.format("%X",hi) end
  188.             if (lo == 0) then lo = " " else lo = string.format("%X",lo) end
  189.             gui.text(bX*6,bY*16+9,hi.."\n"..lo)
  190.             gui.box(rX,rY,rX+6,rY+8,"#00ff0000")
  191.         end
  192.     end
  193. end
  194.  
  195. function PredictBird()
  196.     -- feos, 2014
  197.     -- draws birds trajectories
  198.     -- color marks direction
  199.     for slot = 0,7 do
  200.         if (memory.readbyte(0x400+slot) ~= 11) or (memory.readbyte(0x498+slot) == 0) then
  201.             curves.slot = nil
  202.         else
  203.             if (curves.slot == nil) then curves.slot = {} end
  204.             local ryuY      = memory.readbyte(0x8A)
  205.             local ryuX      = memory.readbyte(0x86)
  206.             local birdY     = memory.readbyte(0x480+slot)
  207.             local birdX     = memory.readbyte(0x460+slot)      +memory.readbyte(0x458+slot)/256
  208.             local birdSpeed = memory.readbytesigned(0x450+slot)+memory.readbyte(0x448+slot)/256
  209.             local newY = 0
  210.             local newX = 0
  211.             local newSpeed = 0
  212.             while (#curves.slot <= 200) do
  213.                 if (#curves.slot == 0) then
  214.                     if (birdY > ryuY)
  215.                     then newY = birdY-1
  216.                     else newY = birdY+1
  217.                     end
  218.                     if (birdX > ryuX)
  219.                     then newSpeed = birdSpeed-16/256
  220.                     else newSpeed = birdSpeed+16/256
  221.                     end
  222.                     newX = birdX+newSpeed
  223.                 else
  224.                     local index = #curves.slot
  225.                     local tempY = curves.slot[index].oldY
  226.                     local tempX = curves.slot[index].oldX
  227.                     local tempSpeed = curves.slot[index].oldSpeed
  228.                     if (tempY > ryuY)
  229.                     then newY = tempY-1
  230.                     else newY = tempY+1
  231.                     end
  232.                     if (tempX > ryuX)
  233.                     then newSpeed = tempSpeed-16/256
  234.                     else newSpeed = tempSpeed+16/256
  235.                     end
  236.                     newX = tempX + newSpeed
  237.                 end            
  238.                 table.insert(curves.slot,{oldY = newY,oldX = newX,oldSpeed = newSpeed})
  239.             end
  240.             if (#curves.slot == 200) then table.remove(curves.slot,1) end          
  241.             for index = 1,#curves.slot do
  242.                 local color = nil
  243.                 if (curves.slot[index].oldSpeed < 0) then color = "#008800" else color = "#0000ff" end
  244.                 gui.box(curves.slot[index].oldX-1, curves.slot[index].oldY-1,
  245.                         curves.slot[index].oldX+1, curves.slot[index].oldY+1, color)
  246.             end
  247.             for index = 1,#curves.slot do
  248.                 gui.pixel(curves.slot[index].oldX,curves.slot[index].oldY,"white")
  249.             end
  250.         end
  251.     end
  252. end
  253.  
  254. emu.registerafter(NGRAMview)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement