gctGenerator/site/.vuepress/components/scripts/codeFormatter.js

62 lines
1.6 KiB
JavaScript
Raw Normal View History

2020-06-28 06:33:20 +09:00
export default class CodeFormatter {
static generateGCT(codes, version) {
2020-06-29 00:35:18 +09:00
let code = '00D0C0DE00D0C0DE';
2020-07-01 14:26:48 +09:00
codes.forEach((c) => (code += c.source));
2020-06-29 00:35:18 +09:00
code += 'FF00000000000000';
2020-06-28 06:33:20 +09:00
let rawData = new Uint8Array(code.length / 2);
for (let x = 0; x < rawData.length; x++) {
rawData[x] = parseInt(code.substr(x * 2, 2), 16);
}
this.downloadFile(rawData, `${version}.gct`);
}
static generateDolphinINI(codes, version) {
2020-06-29 00:35:18 +09:00
let data = 'Paste the following on top of your games .ini file:\r\n[Gecko]';
2020-06-28 06:33:20 +09:00
2020-07-01 14:26:48 +09:00
codes.forEach((code) => {
data += `\r\n$${code.title} (${code.date}) [${code.author}]\r\n`;
2020-06-28 06:33:20 +09:00
data += code.source
.match(/.{8}/g)
2020-06-29 00:35:18 +09:00
.join(' ')
.replace(/(.{17})./g, '$1\r\n');
2020-06-28 06:33:20 +09:00
});
this.downloadFile(data, `${version}.txt`);
}
static generateCheatManagerTXT(codes, version) {
let data = `${version}\r\nSuper Mario Sunshine`;
2020-07-01 14:26:48 +09:00
codes.forEach((code) => {
data += `\r\n\r\n${code.title} (${code.date}) [${code.author}]\r\n`;
2020-06-28 06:33:20 +09:00
data += code.source
.match(/.{8}/g)
2020-06-29 00:35:18 +09:00
.join(' ')
.replace(/(.{17})./g, '$1\r\n');
2020-06-28 06:33:20 +09:00
});
this.downloadFile(data, `${version}.txt`);
}
static downloadFile(data, filename) {
var file = new Blob([data], {
2020-06-29 00:35:18 +09:00
type: 'application/octet-stream',
2020-06-28 06:33:20 +09:00
});
2020-06-29 00:35:18 +09:00
if (window.navigator.msSaveOrOpenBlob) window.navigator.msSaveOrOpenBlob(file, filename);
2020-06-28 06:33:20 +09:00
else {
2020-06-29 00:35:18 +09:00
var a = document.createElement('a'),
2020-06-28 06:33:20 +09:00
url = window.URL.createObjectURL(file);
a.href = url;
a.download = filename;
a.click();
2020-07-01 14:26:48 +09:00
setTimeout(function () {
2020-06-28 06:33:20 +09:00
window.URL.revokeObjectURL(url);
}, 500);
}
}
}