Advertisement
Guest User

Snes9x Lua Y's III

a guest
Aug 28th, 2013
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.57 KB | None | 0 0
  1. -- Y's III (SNES) Collision box viewer
  2. -- Snes9x 1.43-rr/1.51-rr
  3. -- Author: Pasky
  4.  
  5. local camx
  6. local camy
  7.  
  8. function findbit(p)
  9.     return 2 ^ (p - 1)
  10. end
  11.  
  12. function hasbit(x, p)
  13.     return x % (p + p) >= p
  14. end
  15.  
  16. local function hex(val)
  17.     val = string.format("%X",val)
  18.     if string.len(val) == 1 then
  19.         val = "0" .. val
  20.     end
  21.     return val
  22. end
  23.  
  24. local function camera()
  25.     camx = memory.readword(0x12D8)
  26.     camy = memory.readword(0x12E0)
  27. end
  28.  
  29. local function player()
  30.     local x = memory.readbyte(0x1274)
  31.     local y = memory.readbyte(0x1276)
  32.     local x1 = x
  33.     local y1 = y
  34.     local x2 = 0
  35.     local y2 = 0
  36.     if memory.readbyte(0x1273) == 3 then
  37.         x1 = x1 - 4
  38.         x2= x1 + 0x18
  39.         y1= y1 + 0x12
  40.         y2= y1 + 0x10
  41.     else
  42.         x2 = x1 + 0x10
  43.         y1 = y1 + 0x08
  44.         y2 = y1 + 0x18
  45.     end
  46.  
  47.     gui.box(x1,y1,x2,y2,"#0000FF30","#0000FFFF")
  48.     -- cheat
  49.     -- memory.writebyte(0x1294,0x90) -- infinite hp
  50.     -- memory.writeword(0x1299,0x400) -- experience
  51.    
  52.     -- Attacking
  53.     if memory.readbyte(0x1283) ~= 0 then
  54.         local offset1 = bit.band(memory.readbyte(0x1287),0x3)
  55.         offset1 = offset1 + memory.readbyte(0x1278) + memory.readbyte(0x127A) - 0x10
  56.         offset1 = bit.lshift(offset1,1)
  57.         local offset2 = bit.band(memory.readbyte(0x127C),0x40)
  58.         offset2 = bit.rshift(offset2,6)
  59.         offset2 = bit.bor(offset2,offset1)
  60.         offset2 = bit.lshift(offset2,2)
  61.         local ax1 = bit.band(x + memory.readbyte(0x17A4BE + offset2),0xFF)
  62.         local ay1 = bit.band(y + memory.readbyte(0x17A4BF + offset2),0xFF)
  63.         local ax2 = bit.band(x + memory.readbyte(0x17A4BC + offset2),0xFF)
  64.         local ay2 = bit.band(y + memory.readbyte(0x17A4BD + offset2),0xFF)
  65.         gui.box(ax1,ay1,ax2,ay2)
  66.     end
  67. end
  68.  
  69. local function enemies()
  70.     local start = 0x17FB - 0x22
  71.     for i =0,15,1 do
  72.         local base = start + (i * 0x22)
  73.         local x = memory.readword(base) - camx
  74.         local y = memory.readword(base + 2) - camy
  75.         local facing = memory.readbyte(base + 0xf)
  76.         local offset = memory.readbyte(base + 0xD) * 2
  77.         local pointer = memory.readword(0x179a25 + offset)
  78.         local hp = memory.readbyte(base + 0x8)
  79.         local active = memory.readbyte(base + 0x1D)
  80.        
  81.         if active ~= 0 then
  82.             if bit.band(facing,0x40) ~= 0 then
  83.                 -- left
  84.                 pointer = pointer + 4
  85.             else
  86.                 -- right
  87.             end
  88.             local x1 = x + memory.readbyte(0x179A26 + pointer)
  89.             local y1 = y + memory.readbyte(0x179A27 + pointer)
  90.             local x2 = x + memory.readbyte(0x179A28 + pointer)
  91.             local y2 = y + memory.readbyte(0x179A29 + pointer)
  92.            
  93.             gui.text(x,y,"HP: " .. hp)
  94.             gui.box(x1,y1,x2,y2,"#0xFF000030","#FF0000FF")
  95.             end
  96.     end
  97. end
  98.  
  99. while true do
  100.     camera()
  101.     player()
  102.     enemies()
  103.     emu.frameadvance()
  104. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement