Skip to content

Instantly share code, notes, and snippets.

@ToxicAven
Last active August 4, 2022 05:53
Show Gist options
  • Save ToxicAven/3aef7b9bcffc3c0ed03af51a7f79641d to your computer and use it in GitHub Desktop.
Save ToxicAven/3aef7b9bcffc3c0ed03af51a7f79641d to your computer and use it in GitHub Desktop.
Minecraft Hashed Assets Remapper
/**
* ToxicAven's Assets Remapper
* @author ToxicAven
* With proofreading by tycrek
* @version 1.1.0
*
* Remaps Minecraft's stupid hashed assets so you can decipher
* what the texture parser is actually trying to accomplish
*
* To use this script, simply place it in the .minecraft/assets folder
* of your Minecraft installation, and run `node assetsRemapper.mjs`.
* MultiMC users should run `node assetsRemapper.mjs` from the MultiMC assets folder.
*/
import { readFileSync } from 'fs';
import { mkdir, copyFile } from 'fs/promises';
import { join } from 'path';
const scriptVersion = "1.1.0";
let deobfAssetsDir = 'extracted';
let versionNumber = '1.19';
const mappingsFile = join(process.cwd(), 'indexes', `${versionNumber}.json`);
const mappingJson = JSON.parse(readFileSync(mappingsFile));
const mapObjects = mappingJson.objects;
let processingCount = 0;
function main() {
const keys = Object.keys(mapObjects);
console.log(`ToxicAven's Assets Remapper ${scriptVersion}`);
console.log(`Remapping ${keys.length} assets for version ${versionNumber}...`);
mkdir(join(process.cwd(), deobfAssetsDir), { recursive: true });
keys.forEach(async (key) => {
const fileHash = mapObjects[key].hash;
const sortingChars = fileHash.substring(0, 2);
const extractedPath = join(process.cwd(), deobfAssetsDir, key.substring(0, key.lastIndexOf('/')));
const fileName = key.substring(key.lastIndexOf('/') + 1);
const objectPath = join(process.cwd(), 'objects', sortingChars, fileHash);
mkdir(extractedPath, { recursive: true }).then(() => {
copyFile(objectPath, join(extractedPath, fileName)).then(() => {
processingCount++;
process.stdout.write(`\rConverting obfuscated files... (File ${processingCount}/${keys.length})`);
if (processingCount == keys.length) console.log(`\nDone remapping assets for version ${versionNumber}!`);
});
});
});
};
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment