Created
January 18, 2023 01:43
-
-
Save pikapower9080/5749e7ec73d30e84c74257088bfa0597 to your computer and use it in GitHub Desktop.
Undertale Randomizer (MAC)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Note: this node.js script will only work on mac with the steam version of the game, sorry about that. | |
MAKE A BACKUP BEFORE RUNNING | |
To make a backup: Copy the files in your undertale resources folder to a new folder somewhere safe | |
To find your resources folder: | |
- Open Finder | |
- Press Command + G | |
- Paste ~/Library/Application Support/Steam/steamapps/common/Undertale/UNDERTALE.app/Contents/Resources | |
*/ | |
const fs = require('fs') | |
const path = require('path') | |
const resources = path.resolve(process.env.HOME, "Library", "Application Support", "Steam", "steamapps", "common", "Undertale", "UNDERTALE.app", "Contents", "Resources") | |
const files = fs.readdirSync(resources) | |
let music = [] | |
files.forEach((file) => { | |
if (file.startsWith("mus_") || file.startsWith("TMP-mus_")) { | |
music.push(file.replace("TMP-", "")) | |
} | |
}) | |
let shuffled = music | |
.map(value => ({ value, sort: Math.random() })) | |
.sort((a, b) => a.sort - b.sort) | |
.map(({ value }) => value) | |
// Prevent naming conflicts | |
for (let index = 0; index < music.length; index++) { | |
const file = music[index]; | |
if (!file.startsWith("TMP-")) { | |
try { | |
fs.renameSync(`${resources}/${file}`, `${resources}/TMP-${file}`) | |
} catch(e) {console.error(e)} | |
} | |
} | |
// Actually randomize it | |
for (let masterIndex = 0; masterIndex < music.length; masterIndex++) { | |
fs.renameSync(`${resources}/TMP-${music[masterIndex]}`, `${resources}/${shuffled[masterIndex]}`) | |
} | |
console.log("All done!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment