// Dumps every script in a .rbxlx (with its full instance path) into a folder, // so place scripts can be compared with src/. // usage: node tools/dump-place-scripts.js place.rbxlx outDir 'use strict'; const fs = require('fs'); const path = require('path'); const [,, inP, outDir] = process.argv; const text = fs.readFileSync(inP, 'latin1'); const NAME_RE = /([^<]*)<\/string>/; const TOKEN_RE = /|<\/Item>/g; const stack = []; const seen = new Map(); let m; fs.mkdirSync(outDir, { recursive: true }); while ((m = TOKEN_RE.exec(text))) { if (m[0] === '') { stack.pop(); continue; } const cls = m[1]; const ps = text.indexOf('', m.index); const pe = text.indexOf('', ps); const props = text.slice(ps, pe); const nm = NAME_RE.exec(props.replace(//g, '')); const name = nm ? Buffer.from(nm[1], 'latin1').toString('utf8') : '(' + cls + ')'; stack.push(name); if (cls === 'Script' || cls === 'LocalScript' || cls === 'ModuleScript') { const sm = /<\/ProtectedString>/.exec(props) || /([\s\S]*?)<\/ProtectedString>/.exec(props); const src = sm ? Buffer.from(sm[1], 'latin1').toString('utf8') : ''; let rel = stack.join('__').replace(/[\\/:*?"<>|]/g, '_') + '.' + cls + '.lua'; const n = (seen.get(rel) || 0) + 1; seen.set(rel, n); if (n > 1) rel = rel.replace(/\.lua$/, '.dup' + n + '.lua'); fs.writeFileSync(path.join(outDir, rel), src); } TOKEN_RE.lastIndex = pe; } console.log('dumped', [...seen.values()].reduce((a, b) => a + b, 0), 'scripts to', outDir);