Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add frankenfirm soundhax to troubleshooting #2357

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/get-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
noneSelected: System model is required.
invalidVersion: This doesn't seem to be a valid system version.
head: [
['script', {src: '/assets/js/common.js'}],
['script', {src: '/assets/js/selecting.js'}]
]
---
Expand Down
8 changes: 8 additions & 0 deletions docs/installing-boot9strap-(soundhax).md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
---
head: [
['script', {src: '/assets/js/common.js'}],
['script', {src: '/assets/js/soundhax-link.js'}],
['script', {src: '/assets/js/link-common.js'}],
]
---

# Installing boot9strap (Soundhax)

::: details Technical Details (optional)
Expand Down
8 changes: 8 additions & 0 deletions docs/installing-boot9strap-(super-skaterhax).md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
---
head: [
['script', {src: '/assets/js/common.js'}],
['script', {src: '/assets/js/skater-link.js'}],
['script', {src: '/assets/js/link-common.js'}],
]
---

# Installing boot9strap (super-skaterhax)

::: details Technical Details (optional)
Expand Down
66 changes: 66 additions & 0 deletions docs/public/assets/js/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
Copyright (C) 2024 Nintendo Homebrew

SPDX-License-Identifier: MIT
*/

(() => {

// probably not really needed?
function c(key, value) {
Object.defineProperty(window, key, { value, writable: false, enumerable: true, configurable: false });
}

if (!window.COMMON_LOADED) {
c("COMMON_LOADED", true);

// Possible max minor for each major, major as key
const major_minor_map = {
0: -1, // invalidate all 0.x
1: 1,
2: 2,
3: 1,
4: 5,
5: 1,
6: 4,
7: 2,
8: 1,
9: 9,
10: 7,
11: 17
}

// Validate version
// CHN/TWN doesn't have new model
// KOR/CHN/TWN doesn't have 11.17 currently
c("validate_version", (major, minor, native, region, model) => {
if (model == DEVICE_N3DS && ["C", "T"].includes(region)) {
return false;
}

if (major == 11 && minor == 17 && ["K", "C", "T"].includes(region)) {
return false;
}

const minor_max = major_minor_map[major];
if (!isNaN(minor_max) && minor > minor_max) {
return false;
}

return true;
});

c("DEVICE_N3DS", 1);
c("DEVICE_O3DS", 0);

c("FILENAME_REGION_MAP", {
"U": "usa",
"E": "eur",
"J": "jpn",
"K": "kor",
"C": "cnh",
"T": "twn",
});
}

})();
38 changes: 38 additions & 0 deletions docs/public/assets/js/link-common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
Copyright (C) 2024 DannyAAM

SPDX-License-Identifier: MIT
*/

(() => {

const selectedVersion = sessionStorage.getItem("selected_version");
if (selectedVersion && window.MATCH && window.generateLink) {
function replaceLink() {
const {major, minor, nver, region, model} = JSON.parse(selectedVersion);
if (!validate_version(major, minor, nver, region, model)) {
return;
}

const links = document.querySelectorAll(`a[href*="${MATCH}"]`);
for(const link of links) {
const newLink = generateLink(major, minor, nver, region, model, link.href);
if (newLink) {
link.setAttribute("href", newLink);
}
}
}

if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", replaceLink);
} else {
replaceLink();
}

if (!window.autoLinkAddedCustomEvent) {
window.autoLinkAddedCustomEvent = true;
document.addEventListener("customEventReplaceLink", replaceLink);
}
}

})();
48 changes: 11 additions & 37 deletions docs/public/assets/js/selecting.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,11 @@
SPDX-License-Identifier: MIT
*/

const DEVICE_N3DS = 1;
const DEVICE_O3DS = 0;

// Possible max minor for each major, major as key
const major_minor_map = {
0: -1, // invalidate all 0.x
1: 1,
2: 2,
3: 1,
4: 5,
5: 1,
6: 4,
7: 2,
8: 1,
9: 9,
10: 7,
11: 17
}

// Validate version
// CHN/TWN doesn't have new model
// KOR/CHN/TWN doesn't have 11.17 currently
function validate_version(major, minor, native, region, model) {
if (model == DEVICE_N3DS && ["C", "T"].includes(region)) {
return false;
}
// required as vitepress don't always fully reload page
// without putting script in its own scope will have const redefine issue
(() => {

if (major == 11 && minor == 17 && ["K", "C", "T"].includes(region)) {
return false;
}

const minor_max = major_minor_map[major];
if (!isNaN(minor_max) && minor > minor_max) {
return false;
}

return true;
}
// validate_version moved to common.js

// Soundhax
// 1.0-11.3
Expand Down Expand Up @@ -208,6 +175,9 @@ function redirect() {
return;
}

// Store selected version for some later pages
sessionStorage.setItem("selected_version", JSON.stringify({major, minor, nver, region, model}));

const redirected = [
can_soundhax,
can_ssloth,
Expand All @@ -221,3 +191,7 @@ function redirect() {
document.getElementById("result_methodUnavailable").style.display = "block";
return false;
}

window.redirect = redirect;

})();
43 changes: 43 additions & 0 deletions docs/public/assets/js/skater-link.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
Copyright (C) 2024 DannyAAM

SPDX-License-Identifier: MIT
*/

(() => {

const BASE = "https://hacksguidewiki.sfo3.digitaloceanspaces.com/hacksguidewiki/Super-skaterhax";

window.MATCH = "skater.nintendohomebrew.com";

window.generateLink = (major, minor, nver, region, model, link) => {
const fileRegion = FILENAME_REGION_MAP[region];

if (model != DEVICE_N3DS || major < 11) {
return null;
}

let fileVersion;
switch (region) {
case "U":
if (minor == 17) {
fileVersion = "v11.17";
} else {
fileVersion = "pre17";
}
break;
case "K":
if (minor == 17) {
return null;
} else {
fileVersion = "pre17";
}
break;
default:
fileVersion = "all";
break;
}
return `${BASE}-${fileRegion}-${fileVersion}.zip`;
}

})();
145 changes: 145 additions & 0 deletions docs/public/assets/js/soundhax-frankenfirm-link.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/*
Copyright (C) 2024 DannyAAM

SPDX-License-Identifier: MIT
*/

(() => {

const BASE = "https://github.com/danny8376/soundhax/raw/frankenfirmware/soundhax";

window.MATCH = "soundhax.saru.moe/frankenfirm";

// adopt from https://github.com/danny8376/soundhax/blob/2a2c2499ad45d9216ae4c9d157dfb90dfd3b6bd4/docs/js/frankenfirm.js#L82-L237
window.generateLink = (major, minor, nver, region, model, link) => {
console.log("MATCH")
const fileRegion = FILENAME_REGION_MAP[region];
const errorIndex = link.lastIndexOf("?");
if (errorIndex == -1) {
return null;
}
const error = link.slice(errorIndex + 1);
console.log(error);

if (model == DEVICE_N3DS || ["K", "C", "T"].includes(region)) {
return null;
}

switch (parseInt(nver)) {
case 0:
case 1:
case 2:
case 3:
console.log("nver 0-3")
if (major < 2 || (major == 2 && minor <= 1)) {
switch (error) {
case "unplayable":
// very unlikely to have v1027 sound app in this case?
return `${BASE}-${fileRegion}-o3ds-pre2.1.m4a`;
case "crash":
return null; // WTF
default:
return null;
}
} else if (major < 5) {
switch (error) {
case "unplayable":
return `${BASE}-${fileRegion}-o3ds-pre2.1.m4a`;
case "crash":
return `${BASE}-${fileRegion}-o3ds-v2.1and2.2.m4a`;
default:
return null;
}
} else if (major < 11 || (major == 11 && minor <= 3)) {
switch (error) {
case "unplayable":
return `${BASE}-${fileRegion}-o3ds-pre2.1-post5franken.m4a`;
case "crash":
return `${BASE}-${fileRegion}-o3ds-v2.1and2.2-post5franken.m4a`;
default:
return null;
}
} else if ((major == 11 && minor > 3) || major > 11) {
return null;
}
case 4:
console.log("nver 4")
if (major < 2 || (major == 2 && minor < 1)) {
return null; // WTF
} else if (major == 2 && minor == 1) {
switch (error) {
case "unplayable":
return `${BASE}-${fileRegion}-o3ds-v2.1and2.2.m4a`;
case "crash":
return null; // WTF
default:
return null;
}
} else if (major < 5) {
switch (error) {
case "unplayable":
return null;
case "crash":
return `${BASE}-${fileRegion}-o3ds-v2.1and2.2.m4a`;
default:
return null;
}
} else if (major < 11 || (major == 11 && minor <= 3)) {
switch (error) {
case "unplayable":
return null;
case "crash":
return `${BASE}-${fileRegion}-o3ds-v2.1and2.2-post5franken.m4a`;
default:
return null;
}
} else if ((major == 11 && minor > 3) || major > 11) {
return null;
}
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
console.log("nver 5-10");
if (major < 5) {
switch (error) {
case "unplayable":
case "crash":
return null;
default:
return null;
}
} else if (major < 11 || (major == 11 && minor <= 3)) {
switch (error) {
case "unplayable":
case "crash":
return null;
default:
return null;
}
} else if ((major == 11 && minor > 3) || major > 11) {
return null;
}
default:
if (nver < 37) {
console.log("nver 11-36");
switch (error) {
case "unplayable":
case "crash":
return null;
default:
return `${BASE}-${fileRegion}-o3ds-post5.0.m4a`;
}
} else {
console.log("nver 37+");
return null;
}
}
}

// workaround for link-common.js won't get loaded again if jump from other also loaded page
document.dispatchEvent(new Event("customEventReplaceLink"));

})();
Loading