-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsm.lua
More file actions
551 lines (536 loc) · 11 KB
/
sm.lua
File metadata and controls
551 lines (536 loc) · 11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
-- first run through
first=true
-- width and height of icons
xoffset=254
xmax=256+142
w=16
h=16
require("cfg")
function snes2pc(addr)
a = addr >> 1
a = a & 0x3F8000
a = a | (addr & 0x7FFF)
return a
end
function rom_readbyte(addr)
if goodcore then
return memory.readbyte(addr)
end
return memory.readbyte(snes2pc(addr))
end
function rom_read_u16(addr)
if goodcore then
return memory.read_u16_le(addr)
end
return memory.read_u16_le(snes2pc(addr))
end
function rom_read_u32(addr)
if goodcore then
return memory.read_u32_le(addr)
end
return memory.read_u32_le(snes2pc(addr))
end
function mem(addr)
str = ""
c = rom_readbyte(addr)
i = 1
-- 0 terminated strings
while c ~= 0 do
str = str .. string.char(c)
c = rom_readbyte(addr+i)
i = i + 1
end
return str
end
function mem0(addr)
str = ""
c = rom_readbyte(addr)
i = 1
-- 0 terminated strings
font = {}
font[64] = "-"
font[65] = "'"
font[66] = "."
while c ~= 0 do
if c == 1 then
str = str .. " "
elseif c < 28 then
str = str .. string.char(c+63)
elseif c > 53 and c < 64 then
str = str .. string.char(c-6)
else
str = str .. font[c]
end
c = rom_readbyte(addr+i)
i = i + 1
end
return str
end
function bigletter(addr)
str = ""
c = rom_readbyte(addr)
i = 2
b = 0
-- length of all big letter strings
lastc = c
while i < 0x40 do
if c < 0x0040 then
c = c -0x0020
str = str .. string.char(c+65)
elseif c == 127 then
-- we only care about the last part of the string
if lastc ==c then
str = ""
end
else
c = c -0x0030
str = str .. string.char(c+65)
end
lastc = c
c = rom_read_u16(addr+i)
i = i + 2
end
return string.upper(str)
end
function drawequip(x,y, scale)
draw(x, y, "equip", scale)
end
function draw(x,y,img, scale)
sc = (scale == nil and 1) or scale
if win ~= 0 then
forms.drawImage(win,img ..".png",xoffset+x*w,y*h,w*sc,h*sc)
else
gui.drawImage(img ..".png",xoffset+x*w,y*h,w*sc,h*sc)
end
end
function text(x,y,str,clr,size)
sz = (size == nil and 10) or size
if win ~= 0 then
forms.drawString(win,xoffset+x*w,y*h,str,clr,nil,sz)
else
gui.drawString(xoffset+x*w,y*h,str,clr,nil,sz)
end
end
function textright(x, y, str, clr, size)
sz = (size == nil and 10) or size
if win ~= 0 then
forms.drawString(win,xmax-x*w,y*h,str,clr,nil,sz,nil,nil,"right")
else
gui.drawString(xmax-x*w,y*h,str,clr,nil,sz,nil, nil, "right")
end
end
function rect(x,y,color, size)
sz = (size == nil and 10) or size
if win ~= 0 then
forms.drawRectangle(win, xoffset+x*w, y*h+2, sz, sz,color, "black")
else
gui.drawRectangle(xoffset+x*w, y*h+2, sz, sz,color, "black")
end
end
--items 09A4-collected 09A2-equiped, walljump enabled dfff05
function items()
val=mainmemory.read_u16_le(0x09A4)
eq=mainmemory.read_u16_le(0x09A2)
for i, item in pairs(itemenum) do
drawEq(val,eq,i,item)
end
extras=rom_readbyte(0xdfff05)
if extras&1~=0 then
i=0x400
drawEq(val,eq,i,walljump)
end
if extras&2~=0 then
--split boosters
bl=0x40
sl=0x80
both = bl+sl
if val&both==both then
-- do I draw reg booster here??? idk
drawEq(val,eq,both,speed)
return
end
drawEq(val,eq,sl,spark)
drawEq(val,eq,bl,blue)
else
sp = 0x2000
drawEq(val,eq,sp,speed)
end
end
--beams 09A8, hyperbeam 0A76
function beams()
val=mainmemory.read_u16_le(0x0A76)
if val==0x8000 then
draw(cfg[hyper][1], cfg[hyper][2], hyper, cfg[hyper][3])
end
val=mainmemory.read_u16_le(0x09A8)
eq=mainmemory.read_u16_le(0x09A6)
for i,beam in pairs(beamenum) do
drawEq(val,eq,i,beam)
end
end
function drawEq(val,eq,f,name)
x = cfg[name][1]
y = cfg[name][2]
sc = cfg[name][3]
if (val&f)==f then
draw(x, y, name, sc)
if (eq&f)~=f then
drawequip(x, y, sc)
end
else
draw(x, y, "b" .. name, sc)
end
end
-- flag loc 8FEBC0, flag 8FEBC8 indexed
function bossesdead()
bn = 0
if #objflags == 0 then
return bn
end
for i = 1, #objflags do
val=mainmemory.read_u16_le(objflags[i][2])
f= objflags[i][3]
if val&f~=0 then
bn = bn+1
end
end
return bn
end
bossset =0
bossrefresh = 0
function boss()
-- objectives
if noobj or #objflags == 0 or bossesdead() == #objflags then
motherbrain()
else
if #objflags > 4 and bossrefresh > 5 then
bossset = bossset +4
if bossset > #objflags then
bossset = 0
end
bossrefresh = 0
end
for i = 1, 4 do
seti = i+bossset
if seti <= #objflags then
val=mainmemory.read_u16_le(objflags[seti][2])
f= objflags[seti][3]
b = "boss"..i
x = cfg[b][1]
y = cfg[b][2]
sc = cfg[b][3]
if val&f~=0 then
--text(x,y,i, "white")
draw(x, y, objflags[seti][1], sc)
drawequip(x, y, sc)
else
--text(x,y,i+1, "white", 56)
draw(x, y, objflags[seti][1], sc)
end
end
end
end
bossrefresh = bossrefresh +1
end
function motherbrain()
mb2 = mainmemory.readbyte(mb[2])
if mb2&mb[3] ~= 0 then
val = mainmemory.readbyte(animals[2])
if reqanimals and val&animals[3]==0 then
anim = animals[1]
x = cfg[anim][1]
y = cfg[anim][2]
sc = cfg[anim][3]
draw(x,y,anim, sc)
else
x = cfg["ship"][1]
y = cfg["ship"][2]
sc = cfg["ship"][3]
draw(x,y,"ship", sc)
end
else
m = mb[1]
x = cfg[m][1]
y = cfg[m][2]
sc = cfg[m][3]
draw(x,y,m,sc)
end
end
--map D908, loc 1F5B
pauseloc=-1
function map(r)
text(0,r, "MAPS:", "yellow")
memory.usememorydomain("CARTRAM")
mapflags=rom_readbyte(0x2600)
setmem()
loc = mainmemory.readbyte(0x1F5B)+3
gs=mainmemory.readbyte(0x0998)
-- pausing: track current position move map icon. could read 0x1F62 instead of storing pause loc
if gs==0xF then
if pauseloc == -1 then
pauseloc = loc
end
rect(pauseloc,r,"orange")
else
pauseloc =-1
end
rect(loc, r,"white")
flag = 1
for i = 1,#mapenum do
if mapflags&flag ~= 0 then
val=mainmemory.readbyte(0xD908+i-1)
if val ~= 0 then
text(i+2, r,mapenum[i][1], mapenum[i][2])
else
text(i+2, r,mapenum[i][1], "white")
end
end
flag = flag * 2
end
end
function room()
r=mainmemory.read_u16_le(0x079b)
r=r+11
state = rom_read_u16(0x8F0000+r)
while (state ~= 0xE5E6) do
r=r+1
state = rom_read_u16(0x8F0000+r)
end
r = r+2
-- r is now E5E6 room state addr
xtra = rom_read_u16(0x8F0000+r+16);
room_name_addr = rom_read_u16(0xb80000+xtra+9)
return mem0(0xE30000+room_name_addr+1)
end
--general gameplay flags
function flags()
for i = 1,#flagenum do
val=mainmemory.read_u16_le(flagenum[i][2])
f=flagenum[i][3]
flag = flagenum[i][1]
x = cfg[flag][1]
y = cfg[flag][2]
sc = cfg[flag][3]
draw(x, y, flag, sc)
if val&f==0 then
drawequip(x, y)
end
end
end
function timer()
msecperframe = 100 / 60.09881186
memory.usememorydomain("CARTRAM")
frames = rom_read_u32(0x1E10)
setmem()
tmsecs = frames * msecperframe
secs = tmsecs / 100
msecs = tmsecs % 100
mins = secs / 60
secs = secs % 60
hours = mins / 60
mins = mins % 60
time = string.format("%02d:%02d:%02d:%02d",math.floor(hours),
math.floor(mins),math.floor(secs),math.floor(msecs))
return time
end
beamenum = {}
--c 1-3 r1-2
beamenum[0x1000]="charge"
beamenum[4]="spazer"
beamenum[8]="plasma"
beamenum[2]="ice"
beamenum[1]="wave"
hyper="hyper"
itemenum = {}
--c 4-8, r1-2
itemenum[1]="varia"
itemenum[0x20]="gravity"
itemenum[4]="morph"
itemenum[0x1000]="bombs"
itemenum[2]="spring"
itemenum[0x4000]="grapple"
itemenum[0x100]="hijump"
itemenum[0x200]="space"
itemenum[8]="screw"
itemenum[0x8000]="xray"
speed="speed"
blue="blue"
spark="spark"
walljump="walljump"
-- icon, mem loc for flag, flag
flagenum = {
{"zebes", 0xD820, 1},
{"tube", 0xd821, 8},
{"shak", 0xd821, 0x20},
}
bossenum = {
{"pitroom",0xD823, 2},
{"bombtorizo",0xD828, 4},
{"sporespawn",0xD829, 2},
{"babykraidroom",0xD823, 4},
{"kraid",0xD829, 1},
{"crocomire",0xD82A, 2},
{"phantoon",0xD82B, 1},
{"bowlingstatue",0xD823, 1},
{"botwoon",0xD82C, 2},
{"draygon",0xD82C, 1},
{"plasmaroom",0xD823, 8},
{"goldentorizo",0xD82A, 4},
{"metalpiratesroom",0xD823, 0x10},
{"acidchozostatue",0xD821, 0x10},
{"ridley",0xD82A, 1},
{"metroidroom",0xD822, 1},
{"metroidroom",0xD822, 2},
{"metroidroom",0xD822, 4},
{"metroidroom",0xD822, 8},
}
mb={"motherbrain2",0xD82D, 1}
animals={"animals",0xD821, 0x80}
-- maps & color
mapenum = {
{"C","purple"},
{"B","green"},
{"N","red"},
{"W","orange"},
{"M","blue"},
{"T","brown"},
}
frames = 0
hash = ""
diff = ""
objflags = {}
noobj = false;
reqanimals = false
function setup()
if hash == mem(0xdffef0) then
return
end
hash = mem(0xdffef0)
if(hash:match("%W")) then
return
end
diff = bigletter(0xceb240 + (224 - 128) * 0x40)
if diff == "VERYHARD" then
diff = "VHARD"
elseif diff == "CUSTOM" then
diff = "CUST"
elseif diff == "EXTREME" then
diff = "XTRM"
elseif diff == "INSANE" then
diff = "INSN"
end
prog = bigletter(0xceb240 + (226 - 128) * 0x40)
if prog == "TECHNICAL" then
prog = "TECH"
elseif prog == "CHALLENGE" then
prog = "CHAL"
elseif prog == "DESOLATE" then
prog = "DESO"
elseif prog == "CUSTOM" then
prog = "CUST"
end
qol = bigletter(0xceb240 + (228 - 128) * 0x40)
if qol == "DEFAULT" then
qol = "DEF"
elseif qol == "CUSTOM" then
qol = "CUST"
end
nophantoon = true
reqanimals= rom_read_u32(0xa1f000)==0xffff
val=rom_read_u16(0x83AAD2)
if val==0xECA0 then
noobj = true
else
i=0
m = rom_read_u16(0x8FEBC0+i*2)
f = rom_read_u16(0x8FEBE8+i*2)
while m ~= 0xFFFF do
for j, boss in pairs(bossenum) do
if boss[2] == m and boss[3] == f then
objflags[i+1] = boss
end
if m == 0xD82B and f == 1 then
--nophantoon = false
end
end
i=i+1
m = rom_read_u16(0x8FEBC0+i*2)
f = rom_read_u16(0x8FEBE8+i*2)
end
end
if nophantoon then
flagenum[#flagenum+1] = {"atomic", 0xD82B, 1}
end
diff = diff .. " " .. prog .. " " .. qol
end
goodcore = true
function done()
if win ~= 0 then
forms.destroy(win)
end
event.unregisterbyname("done")
end
win = 0
function setmem()
if goodcore == false then
memory.usememorydomain("CARTROM")
return
end
memory.usememorydomain("System Bus")
end
while true do
if emu.getsystemid() ~= "SNES" then
goto continue
end
if frames ~= 30 then
goto continue
end
if first then
goodcore = memory.usememorydomain("System Bus")
if goodcore == false then
memory.usememorydomain("CARTROM")
end
first = false
if hash == "" or hash:match("%W") then
setup()
if hash:match("%W") or hash == "" then
client.SetGameExtraPadding(0,0,0,0)
goto continue
end
end
getconfig()
if cfg["window"] then
if win == 0 then
form = forms.newform(142,224)
win = forms.pictureBox(form, nil, nil, 142, 224)
client.SetGameExtraPadding(0,0,0,0)
end
xoffset = 0
xmax = 142
else
client.SetGameExtraPadding(0,0,142,0)
end
event.onexit(done, "done")
end
pressed = input.get()
if (pressed["Number1"]) then
console.log("1")
end
forms.clear(win, "black")
map(cfg["maprow"])
items()
beams()
flags()
totobj = ((noobj or #objflags) == 0 and 0) or #objflags
ob = bossesdead() .. "/" .. totobj
textright(0,cfg["seedrow"],hash,"white")
textright(0,cfg["diffrow"],ob .. " "..diff,"white")
room_name = room()
boss()
textright(0,cfg["roomrow"],room_name,"white")
forms.refresh(win)
frames = 0
::continue::
frames = frames + 1
emu.frameadvance()
end