Advertisement
Guest User

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

a guest
Oct 6th, 2012
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.75 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 xm
  21. local ym
  22.  
  23. local function hex(val)
  24.     val = string.format("%X",val)
  25.     return val
  26. end
  27.  
  28. function findbit(p)
  29.     return 2 ^ (p - 1)
  30. end
  31.  
  32. function hasbit(x, p)
  33.     return x % (p + p) >= p
  34. end
  35.  
  36. memory.usememorydomain("PRG ROM")
  37.  
  38. local function formatstring(adr)
  39.     local str
  40.     if string.len(string.format("%X",mainmemory.read_u8(adr+1))) == 1 then
  41.         str = "0" .. string.format("%X", mainmemory.read_u8(adr+1))
  42.     else
  43.         str = string.format("%X", mainmemory.read_u8(adr+1))
  44.     end
  45.     if adr == pt then
  46.         str = str .. ":"
  47.     end
  48.     if string.len(string.format("%X",mainmemory.read_u8(adr))) == 1 then
  49.         str = str .. "0" .. string.format("%X",mainmemory.read_u8(adr))
  50.     else
  51.         str = str .. string.format("%X", mainmemory.read_u8(adr))
  52.     end
  53.     return str
  54. end
  55.  
  56. local function buildbox(i)
  57.     local offset1 = mainmemory.read_u8(0x3B4 + i) * 2
  58.     local pointer1 = memory.read_u8(0x4AC0 + offset1) + (memory.read_u8(0x4AC1 + offset1) * 0x100)
  59.     local offset2 = mainmemory.read_u8(0x3FC + i)
  60.        
  61.     if offset2 > 0 then
  62.         offset2 = offset2 - 1
  63.     end
  64.    
  65.     local offset3 = memory.read_u8(pointer1 + offset2 - 0x4000)
  66.     local offset3 = ((offset3 * 2) + offset3) % 0x100
  67.     local box = { memory.read_s8(0x4B7E + offset3), memory.read_u8(0x4B7F + offset3),memory.read_u8(0x4B80 + offset3) } -- yoff/yrad/xrad
  68.    
  69.     return box
  70. end
  71.  
  72. local function player()
  73.     local x = mainmemory.read_u8(px)
  74.     local y = mainmemory.read_u8(py)
  75.  
  76.     gui.drawBox(x - 6,y + 3 - 0x0A,x + 6,y + 3 + 0x0A,0xFF0000FF,0x400000FF)
  77.    
  78.     -- Whip
  79.     if mainmemory.read_u8(0x445) == 3 then
  80.         local wxoff = 0x16
  81.         local wyoff = -4
  82.         local wxrad
  83.         local wyrad = 4
  84.         local woff = mainmemory.read_u8(0x434)
  85.         if mainmemory.read_u8(0x420) == 0 then
  86.             wxoff = wxoff * -1
  87.         end
  88.         wxrad = memory.read_u8(0x4BDD + woff)
  89.         gui.drawBox(x+wxoff-wxrad,y+wyoff-wyrad,x+wxoff+wxrad,y+wyoff+wyrad,0xFFFFFFFF,0x40FFFFFF)
  90.     end
  91.    
  92. end
  93.  
  94. local function objects()
  95.     local x
  96.     local y
  97.     local l
  98.     local box
  99.     local active
  100.     local fill
  101.     local outl
  102.     local isoob
  103.     local etype
  104.     for i = 2,19,1 do
  105.         active = mainmemory.read_u8(0x3D8 + i)
  106.         isoob = mainmemory.read_u8(oob + i)
  107.         etype = mainmemory.read_u8(0x3B4 + i)
  108.        
  109.         if etype > 0 and etype ~= 0x43 and etype ~= 0x1E and etype ~= 0x2A then
  110.             box = buildbox(i)
  111.             x = mainmemory.read_u8(ex + i)
  112.             y = mainmemory.read_u8(ey + i)
  113.             l = mainmemory.read_u8(el + i)
  114.             if hasbit(active,findbit(1)) and not hasbit(active,findbit(8)) then  -- Enemy
  115.                
  116.                 if bit.rshift(bit.band(isoob,0xF0),4) ~= 8 and bit.rshift(bit.band(isoob,0xF0),4) ~= 4 then  -- If not offscreen
  117.                     if show_elife == true then
  118.                         gui.text((x-8) * xm,(y-28) * ym,"HP: " .. l)
  119.                     end
  120.                 end
  121.                 fill = 0x40FF0000
  122.                 outl = 0xFFFF0000
  123.             elseif hasbit(active,findbit(8)) and hasbit(active,findbit(1)) then -- Hidden enemy, no active box
  124.                 outl = 0x40FF0000
  125.                 fill = 0x00FF0000
  126.                
  127.                 if bit.rshift(bit.band(isoob,0xF0),4) ~= 8 and bit.rshift(bit.band(isoob,0xF0),4) ~= 4 then  -- If not offscreen
  128.                     if show_elife == true then
  129.                         gui.text((x-8) * xm,(y-28) * ym,"HP: " .. l)
  130.                     end
  131.                 end
  132.             elseif hasbit(active,findbit(8)) and hasbit(active,findbit(2)) then  -- Simon's projectiles
  133.                 outl = 0xFF00FFFF
  134.                 fill = 0x4000FFFF
  135.             elseif not hasbit(active,findbit(8)) and hasbit(active,(2)) then -- Enemy projectile
  136.                 outl = 0xFFFFFF00
  137.                 fill = 0x40FFFF00
  138.             elseif hasbit(active,findbit(8)) and not hasbit(active,findbit(2)) then  -- Inactive box
  139.                 outl = 0
  140.                 fill = 0
  141.             elseif hasbit(active,findbit(7)) then -- NPC
  142.                 outl = 0xFFFF00FF
  143.                 fill = 0x40FF00FF
  144.             elseif hasbit(active,findbit(3)) then -- Item pickups
  145.                 outl = 0xFFFFA500
  146.                 fill = 0x40FFA500
  147.             end
  148.             if bit.rshift(bit.band(isoob,0xF0),4) ~= 8 and bit.rshift(bit.band(isoob,0xF0),4) ~= 4 then  -- If not offscreen
  149.                 gui.drawBox(x - box[3],y+box[1]+box[2],x+box[3],y+box[1]-box[2],outl,fill)
  150.             end
  151.  
  152.         end
  153.        
  154.     end
  155.    
  156. end
  157.  
  158. local function HUD()
  159.     local l = mainmemory.read_u8(pl)
  160.     local h = 0
  161.     local e = 0
  162.     local t = 0
  163.    
  164.     -- Hearts
  165.     h = formatstring(ph)
  166.     -- Experience
  167.     e = formatstring(pe)
  168.     -- Time
  169.     t = formatstring(pt)
  170.    
  171.     gui.text(14 * xm, 9 * ym, l)
  172.     gui.text((256 - 40) * xm, 9 * ym,"H: " .. h)
  173.     gui.text((256 - 40) * xm, 17 * ym,"E: " .. e)
  174.     gui.text((256 - 85) * xm, 9 * ym, "T: " .. t)
  175. end
  176.  
  177. local function scaler()
  178.     xm = client.screenwidth() / 256
  179.     ym = client.screenheight() / 224
  180. end
  181.  
  182. while true do
  183.     scaler()
  184.     if show_hud == true then
  185.         HUD()
  186.     end
  187.     player()
  188.     objects()
  189.     emu.frameadvance()
  190. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement