Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/Assets/Lua/SNES/Rockman and Forte.lua
2 views
1
-- Author Pasky13
2
3
local pbase = 0xC00
4
local ppbase = 0xCC0
5
6
local ebase = 0x19C0
7
local epbase = 0xEC0
8
9
local xm
10
local ym
11
12
memory.usememorydomain("CARTROM")
13
14
function findbit(p)
15
return 2 ^ (p - 1)
16
end
17
18
function hasbit(x, p)
19
return x % (p + p) >= p
20
end
21
22
local function hex(val)
23
val = string.format("%X",val)
24
return val
25
end
26
27
local function camera()
28
cx = mainmemory.read_u16_le(0xD9)
29
cy = mainmemory.read_u16_le(0xDB)
30
end
31
32
33
local function drawbox(p,x,y,base,player,fill,outl)
34
local box = {0,0,0,0} --xoff/yoff/xrad/yrad
35
36
box[1] = memory.read_s8(p)
37
box[2] = memory.read_s8(p + 1)
38
box[3] = memory.read_u8(p + 2)
39
box[4] = memory.read_u8(p + 3)
40
41
if player == false then
42
if hasbit(mainmemory.read_u8(base+0x14),findbit(7)) then -- megaman facing right
43
box[1] = box[1] * - 1
44
end
45
else
46
if hasbit(mainmemory.read_u8(base+0x4A),findbit(3)) then -- enemy facing left
47
box[1] = box[1] * - 1
48
end
49
end
50
51
gui.drawBox(x+box[1]+box[3],y+box[2]+box[4],x+box[1]-box[3],y+box[2]-box[4],outl, fill)
52
return box
53
end
54
55
local function proj_vuln(base,x,y,xoff,yoff,xrad,yrad)
56
local offset = memory.read_u8(0x87D0 +(mainmemory.read_u8(base + 0x31) * 2))
57
local property = memory.read_s8(0x87D0 + offset)
58
if property <= 0 then
59
gui.drawLine(x + xoff + xrad,y + yoff,x + xoff - xrad, y + yoff,0xFFFFFFFF)
60
gui.drawLine(x + xoff,y + yoff + yrad, x + xoff,y + yoff - yrad,0xFFFFFFFF)
61
end
62
--gui.text(x-40,y-20,hex(offset) .. " " .. hex(base))
63
end
64
65
local function player()
66
local x = mainmemory.read_u16_le(pbase + 5) - cx
67
local y = mainmemory.read_u16_le(pbase + 8) - cy
68
local pointer = mainmemory.read_u16_le(pbase + 0x24)
69
local hp = mainmemory.read_s8(pbase + 0x2F)
70
drawbox(pointer,x,y,pbase,true,0x400000FF,0xFF0000FF)
71
gui.text((x-4) * xm,y * ym,"HP:" .. hp)
72
end
73
74
75
76
local function player_projectiles()
77
local x
78
local y
79
local base
80
local pointer
81
local active
82
local anim
83
84
for i = 0,7,1 do
85
base = ppbase + (i * 0x40)
86
active = mainmemory.read_u8(base)
87
anim = mainmemory.read_u8(base + 1)
88
if active ~= 0 and anim > 1 then
89
x = mainmemory.read_u16_le(base + 5) - cx
90
y = mainmemory.read_u16_le(base + 8) - cy
91
pointer = mainmemory.read_u16_le(base + 0x24)
92
drawbox(pointer,x,y,base,false,0x40FFFFFF,0xFFFFFFFF)
93
end
94
end
95
96
end
97
98
local function enemy_projectiles()
99
local x
100
local y
101
local base
102
local pointer
103
local active
104
local anim
105
for i = 0,7,1 do
106
base = epbase + (i * 0x40)
107
active = mainmemory.read_u8(base)
108
anim = mainmemory.read_u8(base + 1)
109
if active ~= 0 and anim > 1 then
110
x = mainmemory.read_u16_le(base + 5) - cx
111
y = mainmemory.read_u16_le(base + 8) - cy
112
pointer = mainmemory.read_u16_le(base + 0x24)
113
drawbox(pointer,x,y,base,false,0x4000FF00,0xFF00FF00)
114
end
115
end
116
117
end
118
119
local function objects()
120
local x
121
local y
122
local hp
123
local base
124
local pointer
125
local active
126
local anim
127
local box
128
for i = 0,15,1 do
129
base = ebase + (i * 0x40)
130
active = mainmemory.read_u8(base)
131
anim = mainmemory.read_u8(base + 1)
132
if active ~= 0 and anim > 1 then
133
x = mainmemory.read_u16_le(base + 5) - cx
134
y = mainmemory.read_u16_le(base + 8) - cy
135
pointer = mainmemory.read_u16_le(base + 0x24)
136
hp = mainmemory.read_s8(base + 0x2F)
137
if hp > 0 then
138
gui.text((x-8) * xm,(y-8) * ym,"HP: " .. hp)
139
end
140
box = drawbox(pointer,x,y,base,false,0x40FF0000,0xFFFF0000)
141
proj_vuln(base,x,y,box[1],box[2],box[3],box[4])
142
end
143
end
144
end
145
146
-- local function unknown() -- Hitstun animations?
147
-- local x
148
-- local y
149
-- local base = 0x15C0
150
151
-- for i = 0,8,1 do
152
-- base = 0x15C0 + (i * 0x20)
153
-- if mainmemory.read_u16_le(base) ~= 0 then
154
-- x = mainmemory.read_u16_le(base + 5) - cx
155
-- y = mainmemory.read_u16_le(base + 8) - cy
156
-- gui.text(x,y,"UK:" .. i)
157
-- end
158
-- end
159
160
-- for i = 0,15,1 do
161
-- base = 0x16C0 + (i * 0x30)
162
-- if mainmemory.read_u16_le(base) ~= 0 then
163
-- x = mainmemory.read_u16_le(base + 5) - cx
164
-- y = mainmemory.read_u16_le(base + 8) - cy
165
-- gui.text(x,y,"UK2:" .. i)
166
-- end
167
-- end
168
-- end
169
170
local function scaler()
171
xm = client.screenwidth() / 256
172
ym = client.screenheight() / 224
173
end
174
175
while true do
176
scaler()
177
camera()
178
enemy_projectiles()
179
player_projectiles()
180
objects()
181
player()
182
emu.frameadvance()
183
end
184