-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.js
103 lines (92 loc) · 3.28 KB
/
code.js
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
let ARM9_BIN_PATH = null;
let ARM_VALUES = [];
const ARM_OFFSETS = {
"Rain Slot": 0x082B80,
"Snow Slot": 0x082B78,
"Flashing Camera Slot": 0x08BBC0
};
function openFile() {
const fileInput = document.getElementById('fileInput');
fileInput.click();
}
function readBinaryFile(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => resolve(new Uint8Array(reader.result));
reader.onerror = reject;
reader.readAsArrayBuffer(file);
});
}
async function saveFile() {
if (ARM9_BIN_PATH) {
try {
const uint8Array = new Uint8Array(ARM_VALUES);
const blob = new Blob([uint8Array], { type: 'application/octet-stream' });
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = ARM9_BIN_PATH;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
} catch (error) {
console.error('Error saving file:', error);
}
} else {
console.error('No file is opened to save.');
}
}
function openHelp() {
const helpMessage = `
This program allows you to edit the course specific slot IDs in the arm9.bin file of Mario Kart DS.\n\n
1. To get started, click the open button and select the arm9.bin file you want to edit.\n\n
2. Once the file is opened, click on a slot in the list to change its course ID.\n\n
3. After making changes, click the save button to save the modified file.\n\n
Documentation: Southport\n
Code by Landon & Emma`;
alert(helpMessage);
}
function openRepository() {
const repositoryUrl = 'https://github.com/LandonAndEmma/MKDS-ARM9-Slots-Swapper';
window.open(repositoryUrl, '_blank');
}
function onListboxSelect() {
const selectedTrack = trackList.options[trackList.selectedIndex].text;
if (selectedTrack) {
openPopup();
}
}
function refreshListbox() {
const trackList = document.getElementById('trackList');
trackList.innerHTML = '';
for (const [track, offset] of Object.entries(ARM_OFFSETS)) {
const option = document.createElement('option');
option.text = track;
trackList.add(option);
}
}
async function openPopup() {
const selectedTrack = trackList.options[trackList.selectedIndex].text;
const offset = ARM_OFFSETS[selectedTrack];
const newSeqValue = prompt(`Enter new course value for ${selectedTrack}:`, ARM_VALUES[offset]);
if (newSeqValue !== null) {
const intValue = parseInt(newSeqValue);
if (!isNaN(intValue) && intValue > 0 && intValue < 55) {
ARM_VALUES[offset] = intValue;
refreshListbox();
alert(`SEQ value for ${selectedTrack} changed to ${intValue}`);
} else {
alert('Invalid course value. Value must be between 1 and 54.');
}
}
}
document.getElementById('fileInput').addEventListener('change', async (event) => {
const file = event.target.files[0];
if (file) {
ARM9_BIN_PATH = file.name;
const fileContent = await readBinaryFile(file);
ARM_VALUES = Array.from(fileContent);
refreshListbox();
}
});