-
Notifications
You must be signed in to change notification settings - Fork 28
/
bps_maker.html
191 lines (179 loc) · 7.12 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
<html>
<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;
}
.upload_box {
padding: 20px;
}
.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) {
console.log(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="upload_box vanilla_upload">
<label for="input-file-rom_1" class="select-title">Vanilla ROM</label>
<input type="file" id="input-file-rom" class="form-control" accept=".z64,.n64,.v64"/>
</div>
<div class="upload_box rando_upload hide">
<label for="rando_rom" class="select-title">Rando ROM</label>
<input type="file" id="rando_rom" class="form-control" accept=".z64"/>
</div>
<div class="upload_box bps_download hide">
<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>
var target_rom;
document.getElementById("rando_rom").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));
document.getElementsByClassName("bps_download")[0].classList.remove("hide");
};
fr.readAsArrayBuffer(document.getElementById("rando_rom").files[0]);
})
function clearProgress() {
document.getElementsByClassName("rando_upload")[0].classList.add("hide");
document.getElementsByClassName("bps_download")[0].classList.add("hide");
}
document.getElementById("input-file-rom").addEventListener("change", function() {
clearProgress();
})
document.getElementById("save_bps").addEventListener("click", ()=>{buildBPS()})
// Await is-valid
const targetNode = document.getElementById("input-file-rom");
const config = {
attributes: true
}
const callback = mutations => {
mutations.forEach(mutation => {
if (mutation.type === "attributes") {
if (targetNode.classList.contains("is-valid")) {
document.getElementsByClassName("rando_upload")[0].classList.remove("hide");
if (target_rom) {
document.getElementsByClassName("bps_download")[0].classList.remove("hide");
}
} else {
clearProgress();
}
}
});
}
const observer = new MutationObserver(callback);
observer.observe(targetNode, 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 = document.getElementById("rando_rom").value;
const extensions = [".z64",".v64",".n64"];
const directory_delimiters = ["/","\\"]
extensions.forEach(ext => {
original_name = original_name.split(ext)[0];
})
directory_delimiters.forEach(delim => {
const delim_array = original_name.split(delim)
original_name = delim_array[delim_array.length - 1];
})
downloadBlob(newPatchFile._u8array,`${original_name}.bps`,"application/octet-stream")
};
}
</script>
</html>