-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
655 lines (612 loc) · 31.3 KB
/
index.html
File metadata and controls
655 lines (612 loc) · 31.3 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
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Romhack a SM rando</title>
<meta property="og:type" content="website">
<meta property="og:url" content="https://strotlog.github.io/romhackizer/">
<meta property="og:title" content="Romhackizer">
<meta property="og:description" content="Copy the 100 item locations from a Super Metroid randomizer seed, into a romhack of SM">
<link rel="icon" type="image/png" href="favicon.ico">
<!--<meta property="og:image" content="">-->
<script>
// utilities
function stringifyInHex(key, value) {
if (typeof value === 'number') {
return '0x' + value.toString(16)
} else {
return value
}
}
function readUint16LE(bytearr, address) {
return bytearr[address] + 256*bytearr[address+1]
}
function applyPatch(modifications) {
modifications.forEach((modification) => {
if (modification.hasOwnProperty('description')) { // 1st modif in a bunch usually has a description
console.log('applying js patch: ' + modification.description)
}
for (i = 0; i < modification.bytes.length; i++) {
loadedroms['romhack'].allbytes[modification.address + i] = modification.bytes[i]
}
})
}
function checkForPatch(modifications) {
rets = modifications.map((modification) => {
for (i = 0; i < modification.bytes.length; i++) {
if (loadedroms['romhack'].allbytes[modification.address + i] !== modification.bytes[i]) {
return false
}
}
return true // this modification found
})
if (rets.includes(false)) {
return false
}
return true // all modifications found
}
function checkForFreespaceConflict(modifications) {
rets = modifications.map((modification) => {
if (modification.type !== 'freespace') {
return false
}
for (i = modification.address; i < modification.bytes.length; i++) {
if (loadedroms['romhack'].allbytes[i] !== 0xff) {
// current copy of the romhack rom has code where freespace was expected
if (checkForPatch([modification])) {
// no problem, the romhack rom already has exactly this patch
// (as is the case when we process multiple seeds in one session
return false
} else {
// not 0xff and not the exact same patch => a conflict
console.log('patch beginning at 0x' + modification.address.toString(16) + ' length 0n' + modification.allbytes.length + ' which is intended for free space, conflicts with data found in the romhack rom')
return true
}
}
}
return false
})
if (rets.includes(true)) {
return true
}
return false // all modifications had no conflict
}
function checkForOverlappingPatches(modifications) {
// turn each patch into 2 markers: one for where it begins, one for where it ends. then sort all the markers together and check for double-begins
ordered = modifications.map((modification) => [{address: modification.address, type: 'begin', length: modification.bytes.length },
{address: modification.address + modification.bytes.length, type: 'end', length: modification.bytes.length}]
).flat().sort((a, b) => {
if (a.address < b.address) { return -1 }
if (a.address > b.address) { return 1 }
// consider 'end' as less than 'begin', because if one patch ends where another begins that's ok ('end' points to the first byte not modified by a given patch)
if (a.type === 'end' && b.type === 'begin') { return -1 }
if (a.type === 'begin' && b.type === 'end' ) { return 1 }
return 0
})
begunpatches = 0
for (i = 0; i < ordered.length; i++) {
if (ordered[i].type === 'begin') {
begunpatches++
} else {
begunpatches--
}
if (begunpatches > 1) {
console.log('patch beginning at 0x' + ordered[i].address.toString(16) + ' overlaps with an earlier patch! all patches examined: ' + JSON.stringify(modifications, stringifyInHex))
console.log('the overlapping patch ought to be the one at 0x' + ordered[i-1].address.toString(16) + ' (\'' + ordered[i-1].type + '\'), having length ' + ordered[i-1].length)
return true // overlap!
}
}
return false
}
function assembleUnambiguousInstructions(modifications) {
ret = modifications.map(function (modification) {
modification.bytes = modification.bytes.map(function (byteOrOpcode) {
if (typeof byteOrOpcode !== 'string') {
return byteOrOpcode
}
if (byteOrOpcode.toUpperCase() in unambiguousInstructionMapping) {
return unambiguousInstructionMapping[byteOrOpcode.toUpperCase()]
}
console.log('patch beginning at 0x' + modification.address.toString(16) + ' contains the opcode \'' + byteOrOpcode + '\', which does not exist OR is ambiguous (context-dependent opcodes like LDA are not supported yet)')
return 'error'
});
if (modification.bytes.includes('error')) {
return 'error'
}
return modification
});
if (ret.includes('error')) {
return []
}
return ret
}
unambiguousInstructionMapping = {
'INY': 0xC8, 'INX': 0xE8, 'DEY': 0x88, 'DEX': 0xCA, 'BPL': 0x10, 'BMI': 0x30, 'BVC': 0x50, 'BVS': 0x70,
'BRA': 0x80, 'BRL': 0x82, 'BCC': 0x90, 'BCS': 0xB0, 'BNE': 0xD0, 'BEQ': 0xF0, 'JSL': 0x22, 'RTS': 0x60,
'RTL': 0x6B, 'CLC': 0x18, 'SEC': 0x38, 'CLI': 0x58, 'SEI': 0x78, 'CLV': 0xB8, 'CLD': 0xD8, 'SED': 0xF8,
'TCS': 0x1B, 'TSC': 0x3B, 'TCD': 0x5B, 'TDC': 0x7B, 'TXA': 0x8A, 'TYA': 0x98, 'TXS': 0x9A, 'TXY': 0x9B,
'TAY': 0xA8, 'TAX': 0xAA, 'TSX': 0xBA, 'TYX': 0xBB, 'MVP': 0x44, 'MVN': 0x54, 'PER': 0x62, 'PEI': 0xD4,
'PEA': 0xF4, 'PHP': 0x08, 'PHD': 0x0B, 'PHA': 0x48, 'PHK': 0x4B, 'PHY': 0x5A, 'PHB': 0x8B, 'PHX': 0xDA,
'PLP': 0x28, 'PLD': 0x2B, 'PLA': 0x68, 'PLY': 0x7A, 'PLB': 0xAB, 'PLX': 0xFA, 'NOP': 0xEA, 'REP': 0xC2,
'SEP': 0xE2, 'XBA': 0xEB, 'XCE': 0xFB, 'BRK': 0x00, 'COP': 0x02, 'RTI': 0x40, 'WAI': 0xCB, 'STP': 0xDB,
}
function snesAddrStringFromRomOffset(romoffset) {
within = romoffset % 0x8000
bank = (romoffset - within) / 0x8000 + 0x80
return bank.toString(16) + ":" + (within + 0x8000).toString(16)
}
function romOffsetFromSnesAddrString(snesAddrString) {
if (snesAddrString[0] == "$") {
snesAddrString = snesAddrString.substring(1)
}
[bank, highwithin] = snesAddrString.split(":")
bank = parseInt("0x" + bank)
highwithin = parseInt("0x" + highwithin)
return (bank - 0x80)*0x8000 + (highwithin - 0x8000)
}
loadedroms = {}
async function addRomFiles(purpose, filesarr) {
if (filesarr.length === 0) {
return
}
if (filesarr.length > 1) {
console.log('Received ' + filesarr.length + ' files at once, ignoring (expected 1)')
return
}
let fr = new FileReader()
// ".onload" is basically the ".then" of readAsArrayBuffer() which we're about to call
fr.onload = function(event) {
loadedroms[purpose] = {
filename: filesarr[0].name,
allbytes: new Uint8Array(event.target.result),
}
updateState()
}
fr.readAsArrayBuffer(filesarr[0])
}
let g_completed = false
async function updateState() {
if ('rando' in loadedroms) {
document.getElementById('spanIdRandoRomFilename').textContent = loadedroms['rando'].filename
}
if ('vanilla' in loadedroms) {
document.getElementById('spanIdVanillaRomFilename').textContent = loadedroms['vanilla'].filename
}
if ('romhackIps' in loadedroms) {
document.getElementById('spanIdRomhackIpsFilename').textContent = loadedroms['romhackIps'].filename
}
if ('rando' in loadedroms && 'vanilla' in loadedroms && 'romhackIps' in loadedroms) {
document.getElementById('aIdDownloadLink').textContent = '' // remove link (if any previous one was shown)
document.getElementById('divIdRotationNote').style.visibility = 'hidden' // more reset
document.getElementById('divIdOtherRotationNote').style.visibility = 'hidden'
document.getElementById('divIdZfactorNote').style.visibility = 'hidden'
// determine romhack. a checksum would be nice, but length works in a pinch
let hackname
if (loadedroms['romhackIps'].allbytes.length == 550480) {
hackname = 'rotation'
} else if (loadedroms['romhackIps'].allbytes.length == 1079276) {
hackname = 'otherRotation'
} else if (loadedroms['romhackIps'].allbytes.length == 20345) {
hackname = 'unhundo'
} else if (loadedroms['romhackIps'].allbytes.length == 917097) {
hackname = 'zfactor'
} else {
console.log('Unexpected IPS length: ' + loadedroms['romhackIps'].allbytes.length + ' bytes. Expected 917097 (zfactor) or 550480 (rotation) or 1079276 (otherRotation) or 20345 (unhundo)')
return
}
console.log('Detected hack \'' + hackname + '\' based on ips')
if (loadedroms['vanilla'].allbytes.length < 2*1024*1024) {
console.log('Vanilla SM ROM provided is only ' + loadedroms['vanilla'].allbytes.length + ' bytes, expected ' + 3*1024*1024 + ' (3MB)')
return
}
// *** the split between apsm functionality and single player (smc/sfc) functionality is here:
if (loadedroms['rando'].filename.endsWith('.apsm')) {
if (g_completed) {
console.log('Please reload the page before doing Archipelago') // because we need that romhack data to be pristine to read the bsdiff correctly
return
}
g_completed = true
archipelagoRidiculum(hackname)
} else {
if (loadedroms['rando'].allbytes.length < 2*1024*1024) {
console.log('Rando ROM provided is only ' + loadedroms['rando'].allbytes.length + ' bytes, expected ' + 3*1024*1024 + ' or more')
return
}
// do original functionality: move items from rando rom to romhack and patch the romhack
// first we have to create an in-browser-memory copy of the romhack rom
let romhackSize
if (hackname == 'rotation') {
romhackSize = 3*1024*1024 + 2*0x8000
} else if (hackname == 'otherRotation') {
romhackSize = 4*1024*1024
} else if (hackname == 'unhundo') {
romhackSize = 3*1024*1024
} else if (hackname == 'zfactor') {
romhackSize = 3*1024*1024 + 5*0x8000
}
loadedroms['romhack'] = {filename: 'Super Metroid ' + hackname + '.sfc', // not really used
allbytes: new Uint8Array(romhackSize),
}
for (let i = 0; i < loadedroms['vanilla'].allbytes.length; i++) {
// copy vanilla to a new ROM
loadedroms['romhack'].allbytes[i] = loadedroms['vanilla'].allbytes[i]
}
for (let i = 3*1024*1024; i < loadedroms['romhack'].allbytes.length; i++) {
// extend ROM to correct romhack size
loadedroms['romhack'].allbytes[i] = 0xff
}
// create romhack
romhackmod = readips(loadedroms['romhackIps'].allbytes, 'romhack ips')
if (romhackmod.length == 0) { // invalid ips, error in console
return
}
applyPatch(romhackmod)
// everything looks good, do main functionality
g_completed = true
if (hackname == 'rotation') {
let patches = romhacks.rotation.patchmain({hasRoms: true, loadedroms: loadedroms})
if (checkForOverlappingPatches(patches)) {
return
}
if (checkForFreespaceConflict(patches)) {
return
}
patches = assembleUnambiguousInstructions(patches)
if (patches.length === 0) {
return
}
applyPatch(patches)
} else if (hackname == 'otherRotation') {
let patches = romhacks.otherRotation.patchmain({hasRoms: true, loadedroms: loadedroms})
if (checkForOverlappingPatches(patches)) {
return
}
if (checkForFreespaceConflict(patches)) {
return
}
patches = assembleUnambiguousInstructions(patches)
if (patches.length === 0) {
return
}
applyPatch(patches)
} else if (hackname == 'unhundo') {
let patches = romhacks.unhundo.patchmain({hasRoms: true, loadedroms: loadedroms})
patches.push(...romhacks.unhundo.singlePlayerExtrasWithRoms(loadedroms))
if (checkForOverlappingPatches(patches)) {
return
}
if (checkForFreespaceConflict(patches)) {
return
}
patches = assembleUnambiguousInstructions(patches)
if (patches.length === 0) {
return
}
applyPatch(patches)
} else if (hackname == 'zfactor') {
let patches = romhacks.zfactor.patchmain({hasRoms: true, loadedroms: loadedroms})
if (checkForOverlappingPatches(patches)) {
return
}
if (checkForFreespaceConflict(patches)) {
return
}
patches = assembleUnambiguousInstructions(patches)
if (patches.length === 0) {
return
}
applyPatch(patches)
}
let prettyHackname
if (hackname == 'otherRotation') {
prettyHackname = hackname
} else {
prettyHackname = hackname[0].toUpperCase() + hackname.slice(1)
}
updateDownload(prettyHackname + ' romhackized ' + loadedroms['rando'].filename,
loadedroms['romhack'].allbytes,
'Download Modified SM: ' + prettyHackname)
}
}
}
function updateDownload(filename, bytes, linktext) {
let blob = new Blob([bytes], {type: 'application/octet-stream'})
document.getElementById('aIdDownloadLink').href = URL.createObjectURL(blob)
document.getElementById('aIdDownloadLink').download = filename
document.getElementById('aIdDownloadLink').textContent = linktext
}
function archipelagoRidiculum(hackname) {
loadedroms['apsm'] = loadedroms['rando'] // not really a ROM in any case
requirejs.config({
appDir: ".",
baseUrl: '.',
paths: {
'compressjs' : ["https://cdn.jsdelivr.net/npm/compressjs@1.0.3"],
'js-yaml' : ["https://cdn.jsdelivr.net/npm/js-yaml@4.1.0/dist"],
},
});
// kick off a little chain of getting requirements and running a callback
requirejs(['compressjs/main.min' /* requirejs will expands 'compressjs' before slash to become the URL directory we specified in 'paths', and will append '.js' to the end */,
'js-yaml/js-yaml.min',
'archipelago' /* ie, ./archipelago.js which must be written in a requirejs module-y way */,
], function(compressjs, jsyaml, archipelago) {
// kick off the rest of the work (cannot await it here since requirejs doesn't allow async/promises)
archipelagoRidiculum_continued(hackname, compressjs, jsyaml, archipelago)
})
}
var g_archi // for debugging
async function archipelagoRidiculum_continued(hackname, compressjs, jsyaml, archipelago) {
console.log('loaded requirements')
let cjs = compressjs
let jsy = jsyaml
let archi = archipelago
g_archi = archipelago
// 1) (we'll start from a clean bsdiff that says 'copy everything from vanilla')
// 2) (already have the romhack IPS)
// 3) fetch multiworld basepatch
let hacknameBuild = hackname
if (hackname == 'otherRotation') {
hacknameBuild = 'rotation' // rotation multiworld basepatch works with otherRotation romhack
}
if (hackname == 'unhundo') {
hacknameBuild = 'rotation' // rotation multiworld basepatch works with unhundo romhack
}
let basepatch_ips = await fetchFileAndGetBytes("https://github.com/strotlog/SMBasepatch/main/build/romhacks/" + hacknameBuild + "/multiworld-basepatch.ips")
console.log('fetched basepatch ips')
let basepatch = readips(basepatch_ips, 'multiworld basepatch ips')
if (basepatch.length == 0) {
console.log('failed to process multiworld basepatch')
return -1
}
// 4) fetch and apply other ips patches that may be needed (externalpatches)
let externalpatches = []
if (hackname == 'zfactor') {
// fixes from z-factor rando by galamoz!
let galapatch1_ips = await fetchFileAndGetBytes("https://github.com/Galamoz/Z-Factor-ItemRandomizer/master/Patches/Level%20Patch.IPS")
let galapatch1 = readips(galapatch1_ips, "Level Patch.IPS")
let galapatch2_ips = await fetchFileAndGetBytes("https://github.com/Galamoz/Z-Factor-ItemRandomizer/master/Patches/Zebes%20Awakens%20Patch.IPS")
let galapatch2 = readips(galapatch2_ips, "Zebes Awakens Patch.IPS")
if (galapatch1.length == 0 || galapatch2.length == 0) {
console.log("failed to process zfactor-specific IPSes, check that the links are alive?")
}
externalpatches.push(...galapatch1)
externalpatches.push(...galapatch2)
}
// 5) gather javascript-based patches from romhackizer's single player mode (localpatches)
let localpatches = []
if (hackname == 'rotation') {
localpatches = romhacks.rotation.patchmain({hasRoms: false})
if (checkForOverlappingPatches(localpatches)) {
return -1
}
localpatches = assembleUnambiguousInstructions(localpatches)
if (localpatches.length === 0) {
return -1
}
} else if (hackname == 'otherRotation') {
localpatches = romhacks.otherRotation.patchmain({hasRoms: false})
if (checkForOverlappingPatches(localpatches)) {
return -1
}
localpatches = assembleUnambiguousInstructions(localpatches)
if (localpatches.length === 0) {
return -1
}
} else if (hackname == 'unhundo') {
localpatches = romhacks.unhundo.patchmain({hasRoms: false})
if (checkForOverlappingPatches(localpatches)) {
return -1
}
localpatches = assembleUnambiguousInstructions(localpatches)
if (localpatches.length === 0) {
return -1
}
} else if (hackname == 'zfactor') {
localpatches = romhacks.zfactor.patchmain({hasRoms: false})
if (checkForOverlappingPatches(localpatches)) {
return -1
}
localpatches = assembleUnambiguousInstructions(localpatches)
if (localpatches.length === 0) {
return -1
}
}
// see if basepatch overlaps with our local patches that are specific to randoing this romhack
let combinedpatches = []
combinedpatches.push(...basepatch)
combinedpatches.push(...localpatches)
if (checkForOverlappingPatches(combinedpatches)) {
return -1
}
let romhackmod = readips(loadedroms['romhackIps'].allbytes, 'romhack ips')
if (romhackmod.length == 0) {
console.log('failed to process romhack ips')
return -1
}
// patch order is:
// 1) start a fresh bsdiff patch based on vanilla
// order of 2-5 is specified by the way we call the next function call here
// {
// 2) add romhack (now it's the romhack)
// 3) add AP basepatch tailored to the addresses available in this specific romhack
// 4) add any external patches
// 5) add localpatches
// }
// 6) write 'generic archipelago item' to 100 item plm populations
// 7) copy seed-specific data from apsm over top of some of the AP basepatch
let finished_apsm = archi.archipelagomagic(loadedroms['apsm'].allbytes,
[romhackmod, basepatch, externalpatches, localpatches], /* note, putting the romhack first is important, since we overwrite some of its stuff! */
loadedroms['vanilla'].allbytes,
romhacks.offsetsInRomOf100ItemPlms,
hackname,
(hackname == 'otherRotation' ? romhacks.otherRotation.sm_to_otherRotation_remapping : (
hackname == 'unhundo' ? romhacks.unhundo.sm_to_unhundo_remapping : null)),
(hackname == 'zfactor' ? {fromAp: romhacks.zfactor.sm_to_zf_mapping,
leaveAsRegularItem: romhacks.zfactor.zf_unmodified_except_sram_bit}
: null))
// special bsdiff is generated with all the above changes to vanilla.
// present it to the user
let arraybuffer = new ArrayBuffer(finished_apsm.buffer, finished_apsm.byteOffset, finished_apsm.byteLength)
let verb
if (hackname == 'rotation') {
verb = 'Rotated'
} else if (hackname == 'otherRotation') {
verb = 'otherRotated'
} else if (hackname == 'unhundo') {
verb = 'Unhundoed'
} else if (hackname == 'zfactor') {
verb = 'Zfactored'
}
updateDownload(verb + ' ' + loadedroms['apsm'].filename,
finished_apsm,
'Download ' + verb + ' AP Multiworld World (beta)')
if (hackname == 'rotation') {
document.getElementById('divIdRotationNote').style.visibility = 'visible'
} else if (hackname == 'otherRotation') {
document.getElementById('divIdOtherRotationNote').style.visibility = 'visible'
} else if (hackname == 'unhundo') {
document.getElementById('divIdUnhundoNote').style.visibility = 'visible'
} else if (hackname == 'zfactor') {
document.getElementById('divIdZfactorNote').style.visibility = 'visible'
}
return 0
}
async function fetchFileAndGetBytes(url) {
let response = await fetch(url)
let file_blob = await response.blob()
let file_arraybuffer = await file_blob.arrayBuffer()
let file_bytearray = new Uint8Array(file_arraybuffer)
return file_bytearray
}
function readips(binary, description) {
let ret = []
let i = 5
while (i < binary.length-3) {
let address = binary[i] * 65536 + binary[i+1] * 256 + binary[i+2]
let length = binary[i+3] * 256 + binary[i+4]
if (length == 0) {
let rlelength = binary[i+5] * 256 + binary[i+6]
let rlebyte = binary[i+7]
let bytearr = new Uint8Array(rlelength)
for (j = 0; j < rlelength; j++) {
bytearr[j] = rlebyte
}
ret.push({address: address, type: 'overwrite',
bytes: bytearr})
i += 8
} else {
ret.push({address: address, type: 'overwrite',
bytes: binary.slice(i+5, i+5+length)})
i += 5 + length
}
}
if (i != binary.length - 3) {
console.log('ips failed to parse! i=' + i + ', length=' + binary.length)
return []
}
ret[0]['description'] = description // applies only to one tiny byte sequence, just to keep some boundaries and reduce verbosity
return ret
}
document.addEventListener('DOMContentLoaded', function (event) {
// check upon loading, before we have any ROMs, for a query string
httpQuery = new URLSearchParams(window.location.search)
// support simply exporting an IPS of our current rotation patches at ?getRotationIps. note, after someone applies this IPS, the ROM will still have to be loaded with rando items
if (httpQuery.has('getips') /* let's deprecate getIps */ || httpQuery.has('getRotationIps')) {
let patches = romhacks.rotation.patchmain({hasRoms: false})
if (checkForOverlappingPatches(patches)) {
return -1
}
patches = assembleUnambiguousInstructions(patches)
if (patches.length === 0) {
return -1
}
// convert our 'modification' patch format to IPS
ipsbytes = []
ipsbytes.push(...Array.from('PATCH').map((c) => c.charCodeAt(0)))
for (modification of patches) {
// address: 24-bit big endian
ipsbytes.push(...[(modification.address & 0xff0000) >> 16,
(modification.address & 0x00ff00) >> 8,
(modification.address & 0x0000ff)])
// length: 16-bit big endian
ipsbytes.push(...[(modification.bytes.length & 0xff00) >> 8,
(modification.bytes.length & 0x00ff)])
// bytes
ipsbytes.push(...modification.bytes)
}
ipsbytes.push(...Array.from('EOF').map((c) => c.charCodeAt(0)))
ipsbytearray = new Uint8Array(ipsbytes)
console.log(ipsbytearray[0])
let filename = 'romhackizer-rotation-patches' + (new Date()).toISOString().split('T')[0] + '.ips'
updateDownload(filename, ipsbytearray, 'Download patch IPS (no items)')
}
})
</script>
</head>
<body ondrop="event.preventDefault()"
ondragover="event.preventDefault()">
<p>Romhackizer: Welcome to a Web tool that allows you to move the items in various romhacks.</p>
<p>This is not exactly a randomizer. Instead, it copies the locations of all the items from a <strong><a href="https://varia.run/">VARIA Randomizer</a></strong> ROM seed that you provide. (VARIA itself may include a rotation randomizer soon.) (Other randomizers should be fine.)</p>
<p>This:</p>
<ul>
<li>For SM: Rotation, applies <dfn title="1. TBD; 2. vanilla bug patch(es); 3. can always reach Taco tank room & BT's door; 4. BT wakes; 5. balanced suits; 6. screw attack menuing; 7. speed echoes in heated room; 8. spring change in bounce crash fix; 9. escape-climb softlock fix; 10. down-facing gadora crash fix; 11. max ammo equip screen; 12. suit pickup restores position; 13. faster intro; 14. metal pirates crash fix" style="font-style: normal; text-decoration: underline; text-decoration-style: dotted">several code patches</dfn>. Check console log. For otherRotation and Unhundo, a limited subset is applied. For Z-Factor Archipelago, a limited subset is applied, plus Galamoz's ZF Rando patches are fetched and applied, with Gala's generous permission. Beyond these changes, it is exactly like the romhack except the items are moved. Be careful and save!</li>
<li><strong>Does not ensure the seed is completable.</strong></li>
<li>Does not prevent most softlocks.</li>
<li>Will not show errors plainly yet - check your browser's console if a download link doesn't appear.</li>
<li>Will not actually upload or store anything - it's all in your browser. (This means links generated are very temporary and local to this tab.)</li>
</ul>
<p>by strotlog 2022-2023</p>
<div id='divIdRandoRomArea' style='border: 1px; border-style: dotted' ondrop="event.preventDefault(); addRomFiles('rando', event.dataTransfer.files)">
<p><h3 style="display: inline">
Rando ROM
</h3><div style="color:#666666"> or Archipelago .apsm (beta)</div></p>
<input type='file' id='inputIdRandoRom' style='display:none' onchange="addRomFiles('rando', this.files)" accept=".sfc,.smc,.apsm" />
<input type='button' id='inputIdRandoRomButton' value='Browse' onclick="document.getElementById('inputIdRandoRom').click()"/>
<span id='spanIdRandoRomFilename'>(No file)</span>
</div>
<div id='divIdVanillaRomArea' style='border: 1px; border-style: dotted' ondrop="event.preventDefault(); addRomFiles('vanilla', event.dataTransfer.files)">
<h3>
Vanilla Super Metroid ROM (unheadered)
</h3>
<input type='file' id='inputIdVanillaRom' style='display:none' onchange="addRomFiles('vanilla', this.files)" accept=".sfc,.smc" />
<input type='button' id='inputIdVanillaRomButton' value='Browse' onclick="document.getElementById('inputIdVanillaRom').click()"/>
<span id='spanIdVanillaRomFilename'>(No file)</span>
</div>
<div id='romhackIpsArea' style='border: 1px; border-style: dotted' ondrop="event.preventDefault(); addRomFiles('romhackIps', event.dataTransfer.files)">
<p><h3 style="display:inline">
Romhack IPS
</h3><div style="color:#333333"> Upload one of:</div></p><ul>
<li><strong><a href="https://metroidconstruction.com/hack.php?id=350">Super Metroid: Rotation</a></strong> (Beta 11) by SMILEuser96 or</li>
<li><strong><a href="https://metroidconstruction.com/hack.php?id=28">Super Metroid: Z-Factor</a></strong> (1.3) by Metaquarius or</li>
<li><strong><a href="https://metroidconstruction.com/hack.php?id=714">Super Metroid: otherRotation</a></strong> (1.0.1) by BuggMann</li>
<li><strong><a href="https://metroidconstruction.com/hack.php?id=665">Unhundred %</a></strong> (0.5) ('Unhundo') by ClockwiseUK</li>
</ul><input type='file' id='inputIdRomhackIps' style='display:none' onchange="addRomFiles('romhackIps', this.files)" accept=".ips" />
<input type='button' id='inputIdRomhackIpsButton' value='Browse' onclick="document.getElementById('inputIdRomhackIps').click()"/>
<span id='spanIdRomhackIpsFilename'>(No file)</span>
</div>
<div>
<h3>
<a href='#' download='' id='aIdDownloadLink'></a>
</h3>
</div>
<div id='divIdRotationNote' style='visibility: hidden; font-size: 16px'>
Enjoy Rotation romhack by SMILEuser96.
</div>
<div id='divIdOtherRotationNote' style='visibility: hidden; font-size: 16px'>
Enjoy otherRotation romhack by BuggMann.
</div>
<div id='divIdUnhundoNote' style='visibility: hidden; font-size: 16px'>
Enjoy Unhundo romhack by ClockwiseUK.
</div>
<div id='divIdZfactorNote' style='visibility: hidden; font-size: 16px'>
<!-- note, external patches patching doesn't happen for plain sfc patching (which is completely synchronous). so to keep us honest, these messages don't show except in the AP code path. -->
Enjoy Z-Factor romhack by Metaquarius. External patches: fetched and applied Z-Factor rando patches by Galamoz.
</div>
</body>
<!-- include our scripts directly, except archipelago.js (which uses dependencies, see below) -->
<script src="generalpatches.js" ></script>
<script src="romfeatures.js" ></script>
<script src="romhacks.js" ></script>
<!-- requirejs is very, well, required, for the archipelago code path. -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js"></script>
</html>