Advertisement
Guest User

Castlevania II simon's quest collision box viewer (FCEUX)

a guest
Oct 6th, 2012
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.47 KB | None | 0 0
  1. --Toggles
  2. local show_hud = true
  3. local show_elife = true -- enemy life
  4.  
  5. -- Player
  6. local px = 0x348
  7. local py = 0x324
  8. local pl = 0x80
  9. local ph = 0x48
  10. local pe = 0x46
  11. local pt = 0x85
  12.  
  13. -- Enemy
  14. local el = 0x4C2
  15. local ex = 0x348
  16. local ey = 0x324
  17. local oob = 0x3C6
  18. local point = 0x3FC
  19.  
  20. local function hex(val)
  21.     val = string.format("%X",val)
  22.     return val
  23. end
  24.  
  25. function findbit(p)
  26.     return 2 ^ (p - 1)
  27. end
  28.  
  29. function hasbit(x, p)
  30.     return x % (p + p) >= p
  31. end
  32.  
  33. local function formatstring(adr)
  34.     local str
  35.     if string.len(string.format("%X",memory.readbyte(adr+1))) == 1 then
  36.         str = "0" .. string.format("%X", memory.readbyte(adr+1))
  37.     else
  38.         str = string.format("%X", memory.readbyte(adr+1))
  39.     end
  40.     if adr == pt then
  41.         str = str .. ":"
  42.     end
  43.     if string.len(string.format("%X",memory.readbyte(adr))) == 1 then
  44.         str = str .. "0" .. string.format("%X",memory.readbyte(adr))
  45.     else
  46.         str = str .. string.format("%X", memory.readbyte(adr))
  47.     end
  48.     return str
  49. end
  50.  
  51. local function buildbox(i)
  52.     local offset1 = memory.readbyte(0x3B4 + i) * 2
  53.     local pointer1 = rom.readbyte(0x4AD0 + offset1) + (rom.readbyte(0x4AD1 + offset1) * 0x100)
  54.     local offset2 = memory.readbyte(0x3FC + i)
  55.    
  56.     if offset2 > 0 then
  57.         offset2 = offset2 - 1
  58.     end
  59.    
  60.     local offset3 = rom.readbyte(pointer1 + offset2 - 0x3FF0)
  61.     local offset3 = ((offset3 * 2) + offset3) % 0x100
  62.     local box = { rom.readbytesigned(0x4B8E + offset3), rom.readbyte(0x4B8F + offset3),rom.readbyte(0x4B90 + offset3) } -- yoff/yrad/xrad
  63.    
  64.     return box
  65. end
  66.  
  67. local function player()
  68.     local x = memory.readbyte(px)
  69.     local y = memory.readbyte(py)
  70.  
  71.     gui.box(x - 6,y + 3 - 0x0A,x + 6,y + 3 + 0x0A,"#0000FF40","#0000FFFF")
  72.    
  73.     -- Whip
  74.     if memory.readbyte(0x445) == 3 then
  75.         local wxoff = 0x16
  76.         local wyoff = -4
  77.         local wxrad
  78.         local wyrad = 4
  79.         local woff = memory.readbyte(0x434)
  80.         if memory.readbyte(0x420) == 0 then
  81.             wxoff = wxoff * -1
  82.         end
  83.         wxrad = rom.readbyte(0x4BED + woff)
  84.         gui.box(x+wxoff-wxrad,y+wyoff-wyrad,x+wxoff+wxrad,y+wyoff+wyrad,"#FFFFFF40","#FFFFFFFF")
  85.        
  86.     end
  87. end
  88.  
  89. local function objects()
  90.     local x
  91.     local y
  92.     local l
  93.     local box
  94.     local active
  95.     local fill
  96.     local outl
  97.     local isoob
  98.     local etype
  99.     for i = 2,19,1 do
  100.         active = memory.readbyte(0x3D8 + i)
  101.         isoob = memory.readbyte(oob + i)
  102.         etype = memory.readbyte(0x3B4 +i)
  103.         if etype > 0 and etype ~= 0x43 and etype ~= 0x1E and etype ~= 0x2A then
  104.             box = buildbox(i)
  105.             x = memory.readbyte(ex + i)
  106.             y = memory.readbyte(ey + i)
  107.             l = memory.readbyte(el + i)
  108.             if hasbit(active,findbit(1)) and not hasbit(active,findbit(8)) then  -- Enemy
  109.                
  110.                 if bit.rshift(bit.band(isoob,0xF0),4) ~= 8 and bit.rshift(bit.band(isoob,0xF0),4) ~= 4 then  -- If not offscreen
  111.                     if show_elife == true then
  112.                         gui.text(x-8,y-28,"HP: " .. l)
  113.                     end
  114.                 end
  115.                 fill = "#FF000040"
  116.                 outl = "#FF0000FF"
  117.             elseif hasbit(active,findbit(8)) and hasbit(active,findbit(1)) then -- Hidden enemy, no active box
  118.                 outl = "#FF000040"
  119.                 fill = "#FF000000"
  120.                
  121.                 if bit.rshift(bit.band(isoob,0xF0),4) ~= 8 and bit.rshift(bit.band(isoob,0xF0),4) ~= 4 then  -- If not offscreen
  122.                     if show_elife == true then
  123.                         gui.text(x-8,y-28,"HP: " .. l)
  124.                     end
  125.                 end
  126.             elseif hasbit(active,findbit(8)) and hasbit(active,findbit(2)) then  -- Simon's projectiles
  127.                 outl = "#00FFFFFF"
  128.                 fill = "#00FFFF40"
  129.             elseif not hasbit(active,findbit(8)) and hasbit(active,(2)) then -- Enemy projectile
  130.                 outl = "#FFFF00FF"
  131.                 fill = "#FFFF0040"
  132.             elseif hasbit(active,findbit(8)) and not hasbit(active,findbit(2)) then  -- Inactive box
  133.                 outl = 0
  134.                 fill = 0
  135.             elseif hasbit(active,findbit(7)) then -- NPC
  136.                 outl = "#FF00FFFF"
  137.                 fill = "#FF00FF40"
  138.             elseif hasbit(active,findbit(3)) then -- Item pickups
  139.                 outl = "#FFA500FF"
  140.                 fill = "#FFA50040"         
  141.             end
  142.             if bit.rshift(bit.band(isoob,0xF0),4) ~= 8 and bit.rshift(bit.band(isoob,0xF0),4) ~= 4 then  -- If not offscreen
  143.                 gui.box(x - box[3],y+box[1]+box[2],x+box[3],y+box[1]-box[2],fill,outl)
  144.             end
  145.  
  146.         end
  147.        
  148.     end
  149.    
  150. end
  151.  
  152.  
  153. local function HUD()
  154.     local l = memory.readbyte(pl)
  155.     local h = 0
  156.     local e = 0
  157.     local t = 0
  158.    
  159.     -- Hearts
  160.     h = formatstring(ph)
  161.     -- Experience
  162.     e = formatstring(pe)
  163.     -- Time
  164.     t = formatstring(pt)
  165.    
  166.     gui.text(14, 9, l)
  167.     gui.text(256 - 40, 09,"H: " .. h)
  168.     gui.text(256 - 40, 17,"E: " .. e)
  169.     gui.text(256 - 85, 09, "T: " .. t)
  170. end
  171.  
  172. emu.registerafter(function()
  173.     if show_hud == true then
  174.         HUD()
  175.     end
  176.     player()
  177.     objects()
  178.     -- emu.frameadvance()
  179. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement