Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/Assets/Lua/SNES/Contra 3.lua
2 views
1
----------------------------------------------
2
-----Contra III hitbox viewer script SNES-----
3
----------------------------------------------
4
--Player Colors:
5
--Gold = Invuln
6
--Blue = Vulnerable
7
8
--Enemy colors:
9
--Red = Can be touched and hit with projectiles
10
--Green = Can be hit with projectiles but has no collision
11
--Yellow = Can touch you, cannot be hit with player projectiles
12
--White Axis in middle of box = Box is invulnerable
13
14
local xm
15
local ym
16
17
function findbit(p)
18
return 2 ^ (p - 1)
19
end
20
21
function hasbit(x, p)
22
return x % (p + p) >= p
23
end
24
25
local function check_offscreen(pos,val)
26
27
if val ~= 0 then
28
if val == 1 then
29
pos = 255 + pos
30
elseif val == 255 then
31
pos = 0 -(255 - pos)
32
end
33
end
34
35
return pos
36
37
end
38
39
local function draw_invuln(x,y,xrad,yrad)
40
gui.drawLine(x + (xrad / 2), y, x + (xrad / 2), y + yrad,0xFFFFFFFF)
41
gui.drawLine(x, y + (yrad / 2), x + xrad, y + (yrad / 2),0xFFFFFFFF)
42
end
43
44
local function Player()
45
local pbase = 0x200
46
47
for i = 0,1,1 do
48
pbase = pbase + (i * 0x40)
49
local x = mainmemory.read_u8(pbase + 6)
50
local y = mainmemory.read_u8(pbase + 0x10)
51
local x2 = mainmemory.read_u8(pbase + 0x28)
52
local y2 = mainmemory.read_u8(pbase + 0x2A)
53
local x_offscreen = mainmemory.read_u8(pbase + 0x7)
54
local y_offscreen = mainmemory.read_u8(pbase + 0x11)
55
local x2_offscreen = mainmemory.read_u8(pbase + 0x29)
56
local y2_offscreen = mainmemory.read_u8(pbase + 0x2B)
57
local active = mainmemory.read_u8(pbase + 0x16)
58
59
-- Checks if the box went off screen and adjusts
60
x = check_offscreen(x,x_offscreen)
61
x2 = check_offscreen(x2,x2_offscreen)
62
y = check_offscreen(y,y_offscreen)
63
y2 = check_offscreen(y2,y2_offscreen)
64
65
if active > 0 then
66
if hasbit(active,findbit(2)) == true or mainmemory.read_u16_le(0x1F88 + (i * 0x40)) > 0 then
67
gui.drawBox(x,y,x2,y2,0xFFFDD017,0x35FDD017)
68
else
69
gui.drawBox(x,y,x2,y2,0xFF0000FF,0x350000FF)
70
end
71
end
72
end
73
74
75
76
end
77
78
local function Enemies()
79
local start = 0x280
80
local base = 0
81
local oend = 32
82
local x
83
local x_offscreen
84
local y
85
local y_offscreen
86
local xrad
87
local yrad
88
local active
89
local touch
90
local projectile
91
local invuln
92
local hp
93
94
for i = 0,oend,1 do
95
base = start + (i * 0x40)
96
97
active = mainmemory.read_u8(base + 0x16)
98
hp = mainmemory.read_s16_le(base + 6)
99
if active > 0 then
100
101
touch = hasbit(active,findbit(4))
102
projectile = hasbit(active,findbit(5))
103
invuln = hasbit(active,findbit(6))
104
x = mainmemory.read_u8(base + 0xa)
105
x_offscreen = mainmemory.read_u8(base + 0xb)
106
y = mainmemory.read_u8(base + 0xe)
107
y_offscreen = mainmemory.read_u8(base + 0xf)
108
xrad = mainmemory.read_s16_le(base+0x28)
109
yrad = mainmemory.read_s16_le(base+0x2A)
110
111
-- Checks if the box went off screen and adjusts
112
113
x = check_offscreen(x,x_offscreen)
114
y = check_offscreen(y,y_offscreen)
115
116
if projectile and touch then
117
gui.drawBox(x,y,x+ xrad,y+yrad,0xFFFF0000,0x35FF0000)
118
elseif projectile then
119
gui.drawBox(x,y,x + xrad,y+yrad,0xFF00FF00,0x3500FF00)
120
elseif touch then
121
gui.drawBox(x,y,x + xrad,y + yrad,0xFFFFFF00,0x35FFFF00)
122
end
123
if hp > 0 and invuln == false then
124
gui.text((x-5) * xm,(y-5) * ym,"HP: " .. hp)
125
end
126
if invuln then
127
draw_invuln(x,y,xrad,yrad)
128
end
129
130
end
131
end
132
133
end
134
135
local function scaler()
136
xm = client.screenwidth() / 256
137
ym = client.screenheight() / 224
138
end
139
140
while true do
141
scaler()
142
local stage = mainmemory.read_u8(0x7E0086)
143
if stage ~= 2 and stage ~= 5 then
144
Player()
145
Enemies()
146
end
147
emu.frameadvance()
148
end
149