Advertisement
Guest User

Castlevania Collision box viewer (FCEUX)

a guest
Oct 7th, 2012
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.55 KB | None | 0 0
  1. local px = 0x38C
  2. local py = 0x354
  3. local pl = 0x45
  4.  
  5. local ex = 0x38C
  6. local ey = 0x354
  7.  
  8. local function hex(val)
  9.     val = string.format("%X",val)
  10.     return val
  11. end
  12.  
  13. local function whip()
  14.     local box = {0,0,0} -- xoff/yoff/xrad/yrad
  15.     local wtype = memory.readbyte(0x70)
  16.     local pos = bit.band(memory.readbyte(0x434),0x7F)  -- Simons acting positon (jumping/crouching, etc...)
  17.     box[1] = rom.readbytesigned(0x1E46D + wtype)  
  18.     wtype = wtype * 2
  19.     box[2] = rom.readbytesigned(0x1E470 + pos)
  20.     box[3] = rom.readbyte(0x1E474 + wtype)
  21.     box[4] = rom.readbyte(0x1E475 + wtype)
  22.    
  23.     if memory.readbyte(0x450) == 1 then  -- Simon is facing left
  24.         box[1] = box[1] * -1
  25.         box[3] = box[3] * -1
  26.     end
  27.     return box
  28. end
  29.  
  30. local function player()
  31.     local x = memory.readbyte(px)
  32.     local y = memory.readbyte(py)
  33.     local box
  34.     gui.box(x+4,y+memory.readbyte(0x5F),x-4,y-memory.readbyte(0x5F),"#0000FF40","#0000FFFF")
  35.    
  36.     if memory.readbyte(0x568) == 0x11 then -- Whip is active
  37.         box = whip()
  38.         gui.box(x+box[1]+box[3],y+box[2]+box[4],x+box[1]-box[3],y+box[2]-box[4],"#FFFFFF40","#FFFFFFFF")
  39.     end
  40.    
  41. end
  42.  
  43. local function buildbox(i)
  44.     local box = {0,0}  -- xrad/yrad
  45.     local offset = memory.readbyte(0x434 + i)
  46.     local dracform
  47.     if offset == 0x1D then
  48.         dracform = memory.readbyte(0x7A)
  49.         if dracform == 1 then  -- Dracula's 2nd form
  50.             offset = 0x30 * 2
  51.         else  -- Dracula's 2nd form
  52.             offset = offset * 2
  53.         end
  54.     else
  55.         offset = offset * 2
  56.     end
  57.  
  58.     box = { rom.readbyte(0x1E47A + offset),rom.readbyte(0x1E47B + offset) }
  59.    
  60.     return box
  61. end
  62.  
  63. local function getcolor(x)
  64.     local color = {0,0} -- Fill/Outline
  65.     if x >= 0x28 and x < 0x30 then
  66.         color = {"#FFA50040","#FFA500F0"}
  67.     elseif x >= 0x30 and x <= 0x35 then
  68.         return color
  69.     elseif x == 0x17 then -- Simon subweapon
  70.         color = {"#00FFFF40","#00FFFFFF"}
  71.     elseif x == 0x1D then -- Dracula invuln box
  72.         color = {"#FF000040","#FFFFFFFF"}
  73.     else
  74.         color = {"#FF000040","#FF0000FF"}
  75.     end
  76.     return color
  77. end
  78.  
  79. local function objects()
  80.     local x
  81.     local y            
  82.     local active
  83.     local box
  84.     local etype
  85.     local c
  86.     local oob
  87.    
  88.     for i = 4,20,1 do
  89.         oob = memory.readbyte(0x300 + i)
  90.         if oob == 0 or oob == 0x80 then
  91.             box = buildbox(i)
  92.             etype = memory.readbyte(0x434 + i)
  93.             c = getcolor(etype)
  94.             x = memory.readbyte(ex + i)
  95.             y = memory.readbyte(ey + i)
  96.             gui.box(x+box[1],y+box[2],x-box[1],y-box[2],c[1],c[2])
  97.             if etype == 0x1D then -- Dracula's invuln box
  98.                 gui.line(x+box[1],y,x-box[1],y)
  99.                 gui.line(x,y+box[2],x,y-box[2])
  100.             end
  101.         end
  102.     end
  103. end
  104.  
  105.  
  106. emu.registerafter(function()
  107.     player()
  108.     objects()
  109. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement