Advertisement
Guest User

Rockman & Forte (Bizhawk)

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