gctGenerator/site/.vuepress/components/DownloadButton.vue

129 lines
3.4 KiB
Vue
Raw Normal View History

2020-06-28 06:33:20 +09:00
<template>
2020-06-28 10:45:44 +09:00
<ButtonComponent
label="Download"
:onClick="onClick"
:disabled="(!codes || codes.length === 0) && !stageLoaderCode"
/>
2020-06-28 06:33:20 +09:00
</template>
<script>
2020-06-30 05:30:29 +09:00
// Components
2020-06-29 00:35:18 +09:00
import ButtonComponent from './ButtonComponent';
2020-06-28 06:33:20 +09:00
2020-06-30 05:30:29 +09:00
// Data
import gameVersions from '../data/gameVersions.json';
2020-06-28 06:33:20 +09:00
export default {
props: {
codes: { type: Array },
2020-06-28 10:45:44 +09:00
stageLoaderCode: { type: String },
2020-06-28 06:33:20 +09:00
format: { type: String },
2020-06-28 10:45:44 +09:00
versionIdentifier: { type: String },
2020-06-28 06:33:20 +09:00
},
methods: {
onClick() {
2020-06-28 10:45:44 +09:00
if (!(this.codes || this.codes.length === 0) && !this.stageLoaderCode) {
2020-06-28 06:33:20 +09:00
return;
}
2020-06-28 10:45:44 +09:00
const c = [...(this.codes ?? [])];
if (this.stageLoaderCode)
c.push({
2020-06-29 00:35:18 +09:00
title: 'Stage List Loader',
author: 'Noki Doki',
date: '-',
version: '',
2020-06-28 10:45:44 +09:00
source: this.stageLoaderCode,
});
2020-06-28 06:33:20 +09:00
try {
2020-07-01 13:19:15 +09:00
window._paq.push([
'trackEvent',
'GCT Generator',
'Code Download',
JSON.stringify({
gameVersion: this.versionIdentifier,
format: this.format,
2020-07-01 14:26:48 +09:00
codes: c.map((code) => ({
title: code.title,
version: code.version,
})),
}),
]);
} catch {}
2020-06-28 06:33:20 +09:00
console.log(`Preparing download for ${this.format}`);
2020-07-01 14:26:48 +09:00
const fileName = gameVersions.find((v) => v.identifier === this.versionIdentifier).version;
2020-06-30 05:30:29 +09:00
2020-06-28 06:33:20 +09:00
switch (this.format) {
2020-06-29 00:35:18 +09:00
case 'gct':
2020-07-03 10:53:48 +09:00
this.generateGCT(c, fileName);
2020-06-28 06:33:20 +09:00
break;
2020-06-29 00:35:18 +09:00
case 'dolphin':
2020-07-03 10:53:48 +09:00
this.generateDolphinINI(c, fileName);
2020-06-28 06:33:20 +09:00
break;
2020-06-29 00:35:18 +09:00
case 'gcm':
2020-07-03 10:53:48 +09:00
this.generateCheatManagerTXT(c, fileName);
2020-06-28 06:33:20 +09:00
break;
}
2020-06-28 10:45:44 +09:00
},
2020-07-03 10:53:48 +09:00
generateGCT(codes, version) {
let code = '00D0C0DE00D0C0DE';
codes.forEach((c) => (code += c.source));
code += 'FF00000000000000';
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`);
},
generateDolphinINI(codes, version) {
let data = 'Paste the following on top of your games .ini file:\r\n[Gecko]';
codes.forEach((code) => {
data += `\r\n$${code.title} (${code.date}) [${code.author}]\r\n`;
data += code.source
.match(/.{8}/g)
.join(' ')
.replace(/(.{17})./g, '$1\r\n');
});
this.downloadFile(data, `${version}.txt`);
},
generateCheatManagerTXT(codes, version) {
let data = `${version}\r\nSuper Mario Sunshine`;
codes.forEach((code) => {
data += `\r\n\r\n${code.title} (${code.date}) [${code.author}]\r\n`;
data += code.source
.match(/.{8}/g)
.join(' ')
.replace(/(.{17})./g, '$1\r\n');
});
this.downloadFile(data, `${version}.txt`);
},
downloadFile(data, filename) {
var file = new Blob([data], {
type: 'application/octet-stream',
});
if (window.navigator.msSaveOrOpenBlob) window.navigator.msSaveOrOpenBlob(file, filename);
else {
var a = document.createElement('a'),
url = window.URL.createObjectURL(file);
a.href = url;
a.download = filename;
a.click();
setTimeout(function () {
window.URL.revokeObjectURL(url);
}, 500);
}
},
2020-06-28 10:45:44 +09:00
},
2020-06-28 06:33:20 +09:00
};
</script>