Advertisement
Guest User

Untitled

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