2020-06-28 06:33:20 +09:00
|
|
|
<template>
|
2021-06-11 07:48:15 +09:00
|
|
|
<div>
|
|
|
|
<ButtonComponent
|
|
|
|
label="Download"
|
|
|
|
:onClick="onClick"
|
|
|
|
:disabled="(!codes || codes.length === 0) && !stageLoaderCode"
|
2022-01-17 03:17:07 +09:00
|
|
|
/>
|
2021-06-11 07:48:15 +09:00
|
|
|
</div>
|
2020-06-28 06:33:20 +09:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-06-30 05:30:29 +09:00
|
|
|
// Data
|
|
|
|
import gameVersions from '../data/gameVersions.json';
|
|
|
|
|
2020-07-10 12:21:13 +09:00
|
|
|
// Util
|
2022-04-23 23:29:38 +09:00
|
|
|
import { translate, translateCode } from '../i18n/localeHelper';
|
2020-07-10 12:21:13 +09:00
|
|
|
|
2022-04-08 12:48:37 +09:00
|
|
|
// customizable code
|
|
|
|
import codegens from './codes/codegen.js';
|
|
|
|
|
2023-02-11 16:59:34 +09:00
|
|
|
export const lskeyLDC = '@/lastDLCodes';
|
|
|
|
|
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
|
|
|
},
|
2021-06-11 07:48:15 +09:00
|
|
|
data() {
|
2022-01-17 03:17:07 +09:00
|
|
|
return {};
|
2021-06-11 07:48:15 +09:00
|
|
|
},
|
2020-06-28 06:33:20 +09:00
|
|
|
methods: {
|
|
|
|
onClick() {
|
2022-12-17 21:35:18 +09:00
|
|
|
if ((!this.codes || !this.codes.length) && !this.stageLoaderCode) {
|
2020-06-28 06:33:20 +09:00
|
|
|
return;
|
|
|
|
}
|
2023-10-16 16:47:26 +09:00
|
|
|
|
|
|
|
const codeList = this.codes.map((c) => ({
|
|
|
|
...c,
|
|
|
|
// for recording previous downloaded code
|
|
|
|
titleEN: c.title.find(o => o.lang === 'en-US').content,
|
|
|
|
// for generated txt, ini
|
|
|
|
title: translateCode(c, this.$lang).title,
|
|
|
|
}));
|
|
|
|
|
|
|
|
// add dependencies information to title
|
|
|
|
const id2code = Object.fromEntries(codeList.map(c => [c.id, c]));
|
|
|
|
const depBys = {};
|
|
|
|
/* depends on */
|
|
|
|
for (const c of codeList) {
|
|
|
|
if (c.dependencies.length) {
|
|
|
|
c.dependencies.forEach(id => {
|
|
|
|
depBys[id] ??= [];
|
|
|
|
depBys[id].push(c.title);
|
|
|
|
});
|
|
|
|
const depList = c.dependencies.map(id => id2code[id].title).join(', ');
|
|
|
|
c.title += ` **(REQUIRES: ${depList})**`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* used by */
|
|
|
|
for (const [id, depBy] of Object.entries(depBys)) {
|
|
|
|
id2code[id].title += ` (Used by: ${depBy.join(', ')})`;
|
|
|
|
}
|
|
|
|
|
|
|
|
// save downloaded code list
|
|
|
|
try {
|
|
|
|
const codeTitles = codeList.map(c => c.titleEN);
|
|
|
|
localStorage.setItem(lskeyLDC, JSON.stringify(codeTitles));
|
|
|
|
} catch {}
|
2020-06-28 10:45:44 +09:00
|
|
|
|
|
|
|
if (this.stageLoaderCode)
|
2023-01-04 06:09:04 +09:00
|
|
|
codeList.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
|
|
|
|
2020-07-01 13:14:05 +09:00
|
|
|
try {
|
2020-07-01 13:19:15 +09:00
|
|
|
window._paq.push([
|
2020-07-01 13:14:05 +09:00
|
|
|
'trackEvent',
|
|
|
|
'GCT Generator',
|
|
|
|
'Code Download',
|
|
|
|
JSON.stringify({
|
|
|
|
gameVersion: this.versionIdentifier,
|
|
|
|
format: this.format,
|
2022-12-17 21:35:18 +09:00
|
|
|
codes: codeList.map((code) => ({
|
2020-07-01 13:14:05 +09:00
|
|
|
title: code.title,
|
|
|
|
version: code.version,
|
|
|
|
})),
|
|
|
|
}),
|
|
|
|
]);
|
|
|
|
} catch {}
|
|
|
|
|
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
|
|
|
|
2022-04-08 12:48:37 +09:00
|
|
|
// apply customizable codes
|
2022-12-17 21:35:18 +09:00
|
|
|
for (const code of codeList) {
|
2022-04-08 12:48:37 +09:00
|
|
|
const codegen = codegens[code.id];
|
|
|
|
if (codegen) {
|
2022-12-17 08:54:58 +09:00
|
|
|
code.source = codegen(this.versionIdentifier, code.source);
|
2022-04-08 12:48:37 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// generate file
|
2022-12-17 21:35:18 +09:00
|
|
|
const codeSize = codeList.reduce((a, e) => a + e.source.length, 0) / 2 + 16; // 8(00D0)+8(F000)
|
|
|
|
// console.log(codeSize, codeList);
|
2020-06-28 06:33:20 +09:00
|
|
|
switch (this.format) {
|
2020-06-29 00:35:18 +09:00
|
|
|
case 'gct':
|
2022-04-23 23:29:38 +09:00
|
|
|
this.alertGCTCodeSize(codeSize);
|
2022-12-17 21:35:18 +09:00
|
|
|
this.generateGCT(codeList, fileName);
|
2020-06-28 06:33:20 +09:00
|
|
|
break;
|
2020-06-29 00:35:18 +09:00
|
|
|
case 'dolphin':
|
2022-04-23 23:29:38 +09:00
|
|
|
this.alertDolphinCodeSize(codeSize);
|
2022-12-17 21:35:18 +09:00
|
|
|
this.generateDolphinINI(codeList, fileName);
|
2020-06-28 06:33:20 +09:00
|
|
|
break;
|
2020-06-29 00:35:18 +09:00
|
|
|
case 'gcm':
|
2022-04-23 23:29:38 +09:00
|
|
|
this.alertDolphinCodeSize(codeSize);
|
2022-12-17 21:35:18 +09:00
|
|
|
this.generateCheatManagerTXT(codeList, fileName);
|
2020-06-28 06:33:20 +09:00
|
|
|
break;
|
|
|
|
}
|
2020-06-28 10:45:44 +09:00
|
|
|
},
|
2022-04-23 23:29:38 +09:00
|
|
|
alertGCTCodeSize(size) {
|
|
|
|
if (size > 5000) {
|
|
|
|
alert(translate('generatorconfig.alert.gct', this.$lang).replaceAll('{size}', size));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
alertDolphinCodeSize(size) {
|
2022-12-17 08:54:58 +09:00
|
|
|
if (size > 3272) {
|
|
|
|
// 0x3000-0x2338
|
2022-04-23 23:29:38 +09:00
|
|
|
// excluding header+footer
|
2022-12-17 08:54:58 +09:00
|
|
|
alert(
|
|
|
|
translate('generatorconfig.alert.dolphin', this.$lang).replaceAll('{size}', size - 16),
|
|
|
|
);
|
2022-04-23 23:29:38 +09:00
|
|
|
}
|
|
|
|
},
|
2020-07-03 10:53:48 +09:00
|
|
|
generateGCT(codes, version) {
|
|
|
|
let code = '00D0C0DE00D0C0DE';
|
|
|
|
codes.forEach((c) => (code += c.source));
|
2021-01-15 08:39:49 +09:00
|
|
|
code += 'F000000000000000';
|
2020-07-03 10:53:48 +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`);
|
|
|
|
},
|
|
|
|
generateDolphinINI(codes, version) {
|
|
|
|
let data = 'Paste the following on top of your games .ini file:\r\n[Gecko]';
|
|
|
|
|
|
|
|
codes.forEach((code) => {
|
2023-10-16 16:47:26 +09:00
|
|
|
data += `\r\n$${code.title} (${code.date}) [${code.author}]\r\n`;
|
2020-07-03 10:53:48 +09:00
|
|
|
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) => {
|
2020-07-10 12:21:13 +09:00
|
|
|
const codeTitle =
|
|
|
|
typeof code.title === 'string' ? code.title : translateCode(code, this.$lang).title;
|
|
|
|
|
2023-10-16 16:47:26 +09:00
|
|
|
data += `\r\n\r\n${code.title} (${code.date}) [${code.author}]\r\n`;
|
2020-07-03 10:53:48 +09:00
|
|
|
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>
|