Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/Assets/Lua/SNES/Megaman X2.lua
2 views
1
--Author Pasky13
2
3
---------------
4
----GLOBALS----
5
---------------
6
local pbase = 0x9D8
7
local px = pbase +0x5
8
local py = pbase +0x8
9
local cx = 0x1E5D
10
local cy = 0x1E60
11
local xm
12
local ym
13
14
---------------
15
----TOGGLES----
16
---------------
17
local draw_megaman = true
18
local draw_enemies = true
19
local draw_hpvalues = true
20
local draw_projectiles = true
21
22
memory.usememorydomain("CARTROM")
23
24
local function megaman()
25
26
local camx = mainmemory.read_u16_le(cx)
27
local camy = mainmemory.read_u16_le(cy)
28
local x = mainmemory.read_u16_le(px) - camx
29
local y = mainmemory.read_u16_le(py) - camy
30
local facing = mainmemory.read_u8(pbase + 0x11)
31
local boxpointer = mainmemory.read_u16_le(pbase + 0x20) + 0x28000
32
local xoff = memory.read_s8(boxpointer + 0)
33
local yoff = memory.read_s8(boxpointer + 1)
34
local xrad = memory.read_u8(boxpointer + 2)
35
local yrad = memory.read_u8(boxpointer + 3)
36
37
if facing > 0x45 then
38
xoff = xoff * -1
39
end
40
41
gui.drawBox(x + xoff +xrad,y + yoff + yrad, x + xoff - xrad, y + yoff - yrad,0xFF0000FF,0x400000FF)
42
end
43
44
local function enemies()
45
46
local x
47
local xoff
48
local xrad
49
local y
50
local yoff
51
local yrad
52
local camx = mainmemory.read_u16_le(cx)
53
local camy = mainmemory.read_u16_le(cy)
54
local base
55
local boxpointer
56
local facing
57
local fill
58
local outl
59
local start = 0xD18
60
local oend = 31
61
62
for i = 0, oend,1 do
63
64
base = start + (i * 0x40)
65
66
if i == 0 then
67
base = start
68
end
69
70
if mainmemory.read_u8(base) ~= 0 and mainmemory.read_u8(base + 0x27) ~= 128 then
71
72
if i > 14 and i < 25 then
73
if draw_projectiles == true then
74
fill = 0x40FFFFFF
75
outl = 0xFFFFFFFF
76
else
77
fill = 0x00000000
78
outl = 0x00000000
79
end
80
else
81
fill = 0x40FF0000
82
outl = 0xFFFF0000
83
end
84
85
if i > 24 then
86
fill = 0x40FFFF00
87
outl = 0xFFFFFF00
88
end
89
90
facing = mainmemory.read_u8(base + 0x11)
91
x = mainmemory.read_u16_le(base + 5) - camx
92
y = mainmemory.read_u16_le(base + 8) - camy
93
boxpointer = mainmemory.read_u16_le(base +0x20) + 0x28000
94
xoff = memory.read_s8(boxpointer + 0)
95
yoff = memory.read_s8(boxpointer + 1)
96
xrad = memory.read_u8(boxpointer + 2)
97
yrad = memory.read_u8(boxpointer + 3)
98
99
if facing > 0x45 then
100
xoff = xoff * -1
101
end
102
103
104
--gui.text(x,y,string.format("%X",base)) -- Debug
105
gui.drawBox(x + xoff +xrad,y + yoff + yrad, x + xoff - xrad, y + yoff - yrad,outl, fill)
106
107
if draw_hpvalues == true and mainmemory.read_u8(base+0x27) > 0 and mainmemory.read_u8(base+0x27) ~= 128 then
108
if i < 15 or i > 20 then
109
gui.text((x-5) * xm,(y-5) * ym,"HP: " .. mainmemory.read_u8(base+0x27))
110
end
111
end
112
end
113
end
114
end
115
116
local function scaler()
117
xm = client.screenwidth() / 256
118
ym = client.screenheight() / 224
119
end
120
121
while true do
122
scaler()
123
if draw_megaman == true then
124
megaman()
125
end
126
if draw_enemies == true then
127
enemies()
128
end
129
emu.frameadvance()
130
end
131