-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathbps_maker.html
254 lines (234 loc) · 9.86 KB
/
bps_maker.html
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
<html data-bs-theme="dark">
<head>
<title>DK64 Randomizer - BPS Maker</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="./static/styles/gui.css">
<link rel="stylesheet" href="./static/styles/styles.css">
<style>
.center_block {
text-align: center;
width: 480px;
margin-left: auto;
margin-right: auto;
color: white;
background-color: rgba(0,0,0,0.8);
padding: 20px;
position:absolute;
top:50%;
left:50%;
transform: translate(-50%,-50%);
}
.hide {
display: none;
}
#vanilla_upload input, #rando_upload input {
cursor: pointer;
}
.error {
background-color: rgba(255, 97, 97, 0.8);
border: 2px solid rgba(255, 49, 49, 0.8);
border-radius: 5px;
padding: 10px;
text-align: left;
}
@media screen and (width <= 768px) {
.center_block {
width:90%;
}
}
@media screen and (width >= 2560px) {
.center_block {
width:960px;
font-size: xx-large;
}
.center_block h1 {
font-size: 1.5em;
}
input[type=file] {
font-size: 0.75em;
}
}
</style>
<script type="text/javascript" src="./static/js/rompatcher/crc.js" defer></script>
<script type="text/javascript" src="./static/js/rompatcher/formats/bps.js" defer></script>
<script type="text/javascript" src="./static/js/rompatcher/MarcFile.js" defer></script>
<script src="./static/js/rompatcher/RomPatcher.js"></script>
<script>
window.onerror = function (error) {
let targ = document.getElementById("error_box");
targ.classList.remove("hide");
targ.innerText = error.toString();
};
</script>
</head>
<body>
<div class="center_block">
<h1>DK64 Randomizer BPS Maker</h1>
<p>This tool generates a BPS patch that the devs of DK64 Randomizer may need in order to bug test your ROM.</p>
<div class="form-floating user-select-none" id="vanilla_upload" title="Upload Vanilla ROM">
<input type="file" id="input-file-rom" class="form-control" accept=".z64,.n64,.v64" hidden/>
<input type="text" id="vanilla_rom_text" class="form-control" readonly value="No Vanilla ROM Chosen"/>
<label for="input-file-rom">Vanilla ROM</label>
</div>
<div class="form-floating user-select-none mt-4 hide" id="rando_upload" title="Upload Randomizer ROM">
<input type="file" id="rando_rom" class="form-control" accept=".z64" hidden/>
<input type="text" id="rando_rom_text" class="form-control" readonly value="No Rando ROM Chosen"/>
<label for="rando_rom">Rando ROM</label>
</div>
<div class="hide p-2 mt-4" id="bps_download">
<button class="btn btn-secondary" id="save_bps">
Save BPS
</button>
</div>
<div class="error hide" id="error_box">
ERROR TEXT
</div>
</div>
</body>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
<script>
var target_rom;
const vanilla_rom_input = document.getElementById("input-file-rom");
const vanilla_rom_box = document.getElementById("vanilla_upload");
const rando_rom_input = document.getElementById("rando_rom");
const rando_rom_box = document.getElementById("rando_upload");
const bps_download_box = document.getElementById("bps_download");
const dropboxes = [
{
"box": vanilla_rom_box,
"input": vanilla_rom_input,
},
{
"box": rando_rom_box,
"input": rando_rom_input,
}
]
dropboxes.forEach(data => {
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
data["box"].addEventListener(eventName, event => event.preventDefault());
});
data["box"].addEventListener('dragenter', (event) => data["box"].classList.add('hover'));
data["box"].addEventListener('dragleave', (event) => data["box"].classList.remove('hover'));
data["box"].addEventListener('drop', event => {
data["box"].classList.remove('hover');
const files = event.dataTransfer.files;
if (files.length > 0) {
const dataTransfer = new DataTransfer();
for (let i = 0; i < files.length; i++) {
dataTransfer.items.add(files[i]);
}
data["input"].files = dataTransfer.files;
// Manually trigger the change event
const event = new Event('change', { bubbles: true });
data["input"].dispatchEvent(event);
}
});
})
rando_rom_input.addEventListener("change", function() {
var fr = new FileReader();
fr.onload = function() {
var data = fr.result;
setup_data = fr.result;
target_rom = new MarcFile(new Uint8Array(data));
bps_download_box.classList.remove("hide");
};
fr.readAsArrayBuffer(rando_rom_input.files[0]);
let path = rando_rom_input.value;
path = last(path.split("/"));
path = last(path.split("\\"));
document.getElementById("rando_rom_text").value = path;
})
function clearProgress() {
rando_rom_box.classList.add("hide");
bps_download_box.classList.add("hide");
document.getElementById("error_box").classList.add("hide");
}
function last(arr) {
return arr[arr.length - 1];
}
vanilla_rom_box.addEventListener("click", (e) => {
vanilla_rom_input.click();
})
rando_rom_box.addEventListener("click", (e) => {
rando_rom_input.click();
})
vanilla_rom_input.addEventListener("change", function() {
clearProgress();
let path = vanilla_rom_input.value;
path = last(path.split("/"));
path = last(path.split("\\"));
document.getElementById("vanilla_rom_text").value = path;
})
document.getElementById("save_bps").addEventListener("click", ()=>{buildBPS()})
// Await is-valid
const config = {
attributes: true
}
const callback = mutations => {
mutations.forEach((mutation, index) => {
if (mutation.type === "attributes") {
if (vanilla_rom_input.classList.contains("is-valid")) {
rando_rom_box.classList.remove("hide");
if (target_rom) {
bps_download_box.classList.remove("hide");
}
} else {
clearProgress();
throw new Error("This is not a vanilla US DK64 ROM.")
}
}
});
}
const observer = new MutationObserver(callback);
observer.observe(vanilla_rom_input, config);
// Download file
var downloadBlob, downloadURL;
downloadBlob = function(data, fileName, mimeType) {
var blob, url;
blob = new Blob([data], {
type: mimeType
});
url = window.URL.createObjectURL(blob);
downloadURL(url, fileName);
setTimeout(function() {
return window.URL.revokeObjectURL(url);
}, 1000);
};
downloadURL = function(data, fileName) {
var a;
a = document.createElement('a');
a.href = data;
a.download = fileName;
document.body.appendChild(a);
a.style = 'display: none';
a.click();
a.remove();
};
function buildBPS() {
webWorkerCreate=new Worker("./static/js/rompatcher/worker_create.js");
webWorkerCreate.postMessage(
{
sourceFileU8Array:romFile._u8array,
modifiedFileU8Array:target_rom._u8array,
modifiedFileName:target_rom.fileName
},[
romFile._u8array.buffer,
target_rom._u8array.buffer
]
);
webWorkerCreate.onmessage = event => { // listen for events from the worker
var newPatchFile=new MarcFile(event.data.patchFileU8Array);
let original_name = rando_rom_input.value;
const extensions = [".z64",".v64",".n64"];
const directory_delimiters = ["/","\\"]
extensions.forEach(ext => {
original_name = original_name.split(ext)[0];
})
directory_delimiters.forEach(delim => {
original_name = last(original_name.split(delim));
})
downloadBlob(newPatchFile._u8array,`${original_name}.bps`,"application/octet-stream")
};
}
</script>
</html>