Guest User

Devil Island - Hitboxes and Watches v1.3

a guest
Nov 4th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.05 KB | None | 0 0
  1. --Hitboxes and Watches v1.3 for GBC Devil Island (Emo Dao) by ThunderAxe31
  2.  
  3. local R2ub= memory.read_u16_be
  4. local R2ul= memory.read_u16_le
  5. local R1u= memory.read_u8
  6.  
  7. local white = 0xFFFFFFFF
  8. local black = 0xFF000000
  9.  
  10. local player_x = R1u(0xD001)
  11. local actions  = R1u(0xD008)
  12.  
  13. local combined_x_old = -1
  14. local combined_x_lagcount = 0
  15. local framecount_old = -1
  16.  
  17. local function draw_watches()
  18.     local combined_x = player_x + R2ul(0xC122) --add level x
  19.    
  20.     --count x lag
  21.     local framecount = emu.framecount()
  22.     if framecount_old ~= (framecount-1) then --if a state has been loaded, reset values
  23.         combined_x_lagcount = 0
  24.         combined_x_old = -1
  25.     end
  26.     if (combined_x_old > -1) and (combined_x_old == combined_x) then --checks if the x value is unchanged
  27.         combined_x_lagcount = combined_x_lagcount + 1 --updates the movement lag count
  28.         if combined_x_lagcount > 9999 then --reset counter
  29.             combined_x_lagcount = 0
  30.         end
  31.     end
  32.     combined_x_old = combined_x --updates the x value
  33.     framecount_old = framecount --updates the frame count
  34.    
  35.     --exp stuff
  36.     local exp_amount = R2ub(0xCFF8)
  37.     local exp_next = 0
  38.     local attack = 0
  39.     if exp_amount < 3072 then
  40.         attack = 1
  41.         exp_next =  3072 - exp_amount
  42.     elseif exp_amount <  6144 then
  43.         attack = 2
  44.         exp_next =  6144 - exp_amount
  45.     elseif exp_amount <  8192 then
  46.         attack = 3
  47.         exp_next =  8192 - exp_amount
  48.     elseif exp_amount < 10240 then
  49.         attack = 4
  50.         exp_next = 10240 - exp_amount
  51.     elseif exp_amount < 12288 then
  52.         attack = 5
  53.         exp_next = 12288 - exp_amount
  54.     elseif exp_amount < 14336 then
  55.         attack = 6
  56.         exp_next = 14336 - exp_amount
  57.     elseif exp_amount < 16384 then
  58.         attack = 7
  59.         exp_next = 16384 - exp_amount
  60.     else
  61.         attack = 8
  62.         exp_next = 0
  63.     end
  64.    
  65.     --display watches
  66.     if bit.band(actions, 128) ~= 128 then --if menu is open, don't display.
  67.         gui.pixelText(0, 0, "X_POS:     EXP:      ATK: \nX_LAG:     NEXT:     HP:",  white, black)
  68.         gui.pixelText(24, 0, string.format("%4s", combined_x), white, black) --current X position in level
  69.         gui.pixelText(24, 7, string.format("%4s", combined_x_lagcount), white, black) --current movement X lag counted
  70.         gui.pixelText(60, 0, string.format("%5s", exp_amount), white, black) --experience total
  71.         gui.pixelText(64, 7, string.format("%4s", exp_next), white, black) --experience left for next level
  72.         gui.pixelText(100,0, attack, white, black) --attack level
  73.         gui.pixelText(96, 7, string.format("%2s", R1u(0xCFF5)),  white, black) --player HP
  74.         gui.pixelText(108, 0, "$:" .. R2ul(0xCFF6), white, black) --money
  75.     end
  76. end
  77.  
  78. local function fix_negative(value) --wrap negative coordinates correctly
  79.     if (value>212) then
  80.         return value-256
  81.     end
  82.     return value
  83. end
  84.  
  85. local function enemy_hitboxes()
  86.     for i = 0, 3 do --yes, there are just 4 object slots
  87.         local addr = 0xC200+i*0x20 --data chunks for objects are 32 bytes long
  88.         if R1u(addr) ~= 0 then --enemy hitboxes
  89.             gui.drawRectangle(fix_negative(R1u(addr+0x01))+R1u(addr+0x12)-8, fix_negative(R1u(addr+0x02))+R1u(addr+0x14)-16, R1u(addr+0x13)-1, R1u(addr+0x15)-1)
  90.             local obj_type = R1u(addr+0x16)
  91.             local label = ""
  92.             if obj_type==0 then --if enemy, show HP
  93.                 if R1u(addr+0x0F)~=255 then
  94.                     label = R1u(addr+0x07)
  95.                 end
  96.             elseif obj_type==1 then --if money, show how much
  97.                 label = "$"..R1u(addr+0x17)
  98.             elseif obj_type==2 then --if health, display a simple hospital cross
  99.                 label = "+"
  100.             elseif obj_type==3 then --if pass
  101.                 label = "PASS"
  102.             elseif obj_type==4 then --if whip piece
  103.                 label = "WHIP\nPIECE"
  104.             else --if unknown, just in case
  105.                 label = "?"
  106.             end
  107.             gui.pixelText(fix_negative(R1u(addr+0x01))-7, fix_negative(R1u(addr+0x02))-15, label, white, black)
  108.         end
  109.     end
  110.    
  111.     --since there is currently no better solution, we're simply gonna splat these bosses HP on the screen upper left...
  112.     local head_hp = R1u(0xC1B3)
  113.     local core_hp = R1u(0xC1B4)
  114.     local boss_hp = R1u(0xC1A5)
  115.     if head_hp > 0 then
  116.         gui.pixelText(0, 14, "HEAD HP: " .. head_hp, white, black)
  117.     end
  118.     if core_hp > 0 then
  119.         gui.pixelText(0, 21, "CORE HP: " .. core_hp, white, black)
  120.     end
  121.     if boss_hp > 0 then
  122.         gui.pixelText(0, 28, "BOSS HP: " .. boss_hp, white, black) --using a different Y cooradinate, just in case
  123.     end --and no, all other bosses use the regular enemy object structure. this would explain why only these three have an invicibility timer.
  124. end
  125.  
  126. local function player_hitboxes()
  127.     local player_y = R1u(0xD000)
  128.     local whip_x = player_x + 8
  129.     local whip_y = player_y - 8
  130.     local player_height = 32
  131.     local whip_height   = 32
  132.        
  133.     if bit.band(actions, 4) == 4 then --if crouched
  134.         player_y = player_y + 8
  135.         player_height = 24
  136.         whip_y = whip_y + 8
  137.         whip_height = 40
  138.     end
  139.    
  140.     gui.drawRectangle(player_x, player_y, 16, player_height) --player hitbox
  141.    
  142.     if bit.band(actions, 2) == 2 then --if attacking
  143.         if R1u(0xD005) == 2 then --if facing left
  144.             whip_x = whip_x -16
  145.         end
  146.         gui.drawRectangle(whip_x, whip_y, 16, whip_height) --whip hitbox
  147.     end
  148. end
  149.  
  150. while true do
  151.     player_x = R1u(0xD001)
  152.     actions  = R1u(0xD008)
  153.    
  154.     draw_watches()
  155.     enemy_hitboxes()
  156.     player_hitboxes()
  157.    
  158.     emu.frameadvance()
  159. end
Add Comment
Please, Sign In to add comment