Advertisement
Guest User

Rockman & Forte (Snes9X)

a guest
Oct 13th, 2012
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.34 KB | None | 0 0
  1. local pbase = 0xC00
  2. local ppbase = 0xCC0
  3.  
  4. local ebase = 0x19C0
  5. local epbase = 0xEC0
  6.  
  7. function findbit(p)
  8.     return 2 ^ (p - 1)
  9. end
  10.  
  11. function hasbit(x, p)
  12.     return x % (p + p) >= p
  13. end
  14.  
  15. local function hex(val)
  16.     val = string.format("%X",val)
  17.     return val
  18. end
  19.  
  20. local function camera()
  21.     cx = memory.readword(0xD9)
  22.     cy = memory.readword(0xDB)
  23. end
  24.  
  25.  
  26. local function drawbox(p,x,y,base,player,color)
  27.     local box = {0,0,0,0} --xoff/yoff/xrad/yrad
  28.    
  29.     box[1] = memory.readbytesigned(p + 0x800000)
  30.     box[2] = memory.readbytesigned(p + 0x800001)
  31.     box[3] = memory.readbyte(p + 0x800002)
  32.     box[4] = memory.readbyte(p + 0x800003)
  33.    
  34.     if player == false then
  35.         if hasbit(memory.readbyte(base+0x14),findbit(7)) then -- megaman facing right
  36.             box[1] = box[1] * - 1
  37.         end
  38.     else
  39.         if hasbit(memory.readbyte(base+0x4A),findbit(3)) then -- enemy facing left
  40.             box[1] = box[1] * - 1
  41.         end
  42.     end
  43.    
  44.     gui.box(x+box[1]+box[3],y+box[2]+box[4],x+box[1]-box[3],y+box[2]-box[4],color .. "40",color .. "FF")
  45.     return box
  46. end
  47.  
  48. local function proj_vuln(base,x,y,xoff,yoff,xrad,yrad)
  49.     local offset = memory.readbyte(0x8087D0 +(memory.readbyte(base + 0x31) * 2))
  50.     local property = memory.readbytesigned(0x8087D0 + offset)
  51.     if property <= 0 then
  52.         gui.line(x + xoff + xrad,y + yoff,x + xoff - xrad, y + yoff)
  53.         gui.line(x + xoff,y + yoff + yrad, x + xoff,y + yoff - yrad)
  54.     end
  55.     --gui.text(x-40,y-20,hex(offset) .. "   " .. hex(base))
  56. end
  57.  
  58. local function player()
  59.     local x = memory.readword(pbase + 5) - cx
  60.     local y = memory.readword(pbase + 8) - cy
  61.     local pointer = memory.readword(pbase + 0x24)
  62.     local hp = memory.readbytesigned(pbase + 0x2F)
  63.     drawbox(pointer,x,y,pbase,true,"#0000FF")
  64.     gui.text(x-4,y,"HP:" .. hp)
  65. end
  66.  
  67.  
  68.  
  69. local function player_projectiles()
  70.     local x
  71.     local y
  72.     local base
  73.     local pointer
  74.     local active
  75.     local anim
  76.    
  77.     for i = 0,7,1 do
  78.         base = ppbase + (i * 0x40)
  79.         active = memory.readbyte(base)
  80.         anim = memory.readbyte(base + 1)
  81.         if active ~= 0 and anim > 1 then
  82.             x = memory.readword(base + 5) - cx
  83.             y = memory.readword(base + 8) - cy
  84.             pointer = memory.readword(base + 0x24)
  85.             drawbox(pointer,x,y,base,false,"#FFFFFF")
  86.         end
  87.     end
  88.    
  89. end
  90.  
  91. local function enemy_projectiles()
  92.     local x
  93.     local y
  94.     local base
  95.     local pointer
  96.     local active
  97.     local anim
  98.     for i = 0,7,1 do
  99.         base = epbase + (i * 0x40)
  100.         active = memory.readbyte(base)
  101.         anim = memory.readbyte(base + 1)
  102.         if active ~= 0 and anim > 1 then
  103.             x = memory.readword(base + 5) - cx
  104.             y = memory.readword(base + 8) - cy
  105.             pointer = memory.readword(base + 0x24)
  106.             drawbox(pointer,x,y,base,false,"#00FF00")
  107.         end
  108.     end
  109.    
  110. end
  111.  
  112. local function objects()
  113.     local x
  114.     local y
  115.     local hp
  116.     local base
  117.     local pointer
  118.     local active
  119.     local anim
  120.     local box
  121.     for i = 0,15,1 do
  122.         base = ebase + (i * 0x40)
  123.         active = memory.readbyte(base)
  124.         anim = memory.readbyte(base + 1)
  125.         if active ~= 0 and anim > 1 then
  126.             x = memory.readword(base + 5) - cx
  127.             y = memory.readword(base + 8) - cy
  128.             pointer = memory.readword(base + 0x24)
  129.             hp = memory.readbytesigned(base + 0x2F)
  130.             if hp > 0 then
  131.                 gui.text(x-8,y-8,"HP: " .. hp)
  132.             end
  133.             box = drawbox(pointer,x,y,base,false,"#FF0000")
  134.             proj_vuln(base,x,y,box[1],box[2],box[3],box[4])
  135.         end
  136.     end
  137. end
  138. emu.registerafter(function()
  139.     camera()
  140.     enemy_projectiles()
  141.     player_projectiles()
  142.     objects()
  143.     player()
  144. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement