Experimental fix for game version ^1.99.5.2
parent
e030456063
commit
8b01bb6642
24
build.js
24
build.js
|
@ -1,5 +1,6 @@
|
|||
import beautifier from 'js-beautify';
|
||||
const { js: beautify } = beautifier;
|
||||
import UglifyJS from 'uglify-js';
|
||||
import fs from 'fs';
|
||||
|
||||
if (!fs.existsSync("./build")) fs.mkdirSync("./build");
|
||||
|
@ -9,6 +10,22 @@ fs.cpSync("./src/fx_core.js", "./build/fx_core.js");
|
|||
fs.writeFileSync("./build/index.html", fs.readFileSync("./build/index.html").toString().replace(/buildTimestamp/g, Date.now()));
|
||||
let script = fs.readFileSync('./game/latest.js', { encoding: 'utf8' }).replace("\n", "").trim();
|
||||
|
||||
const exposeVarsToGlobalScope = true;
|
||||
// need to first remove the iife wrapper so the top-level functions aren't inlined
|
||||
if (exposeVarsToGlobalScope && script.startsWith("\"use strict\"; (function () {") && script.endsWith("})();"))
|
||||
script = script.slice("\"use strict\"; (function () {".length, -"})();".length);
|
||||
if (exposeVarsToGlobalScope && script.startsWith("(function () {") && script.endsWith("})();"))
|
||||
script = script.slice("(function () {".length, -"})();".length);
|
||||
|
||||
// for versions ^1.99.5.2
|
||||
const minificationResult = UglifyJS.minify(script, {
|
||||
"compress": { "arrows": false },
|
||||
"mangle": false
|
||||
});
|
||||
if (minificationResult.error) console.log(minificationResult.error);
|
||||
if (minificationResult.warnings) console.log(minificationResult.warnings);
|
||||
script = minificationResult.code;
|
||||
|
||||
const replaceOne = (expression, replaceValue) => {
|
||||
const result = matchOne(expression);
|
||||
// this (below) works correctly because expression.lastIndex gets reset above in matchOne when there is no match
|
||||
|
@ -104,13 +121,6 @@ applyPatches({ replace, replaceOne, replaceRawCode, dictionary, matchOne, matchR
|
|||
|
||||
console.log("Formatting code...");
|
||||
|
||||
const exposeVarsToGlobalScope = true;
|
||||
|
||||
if (exposeVarsToGlobalScope && script.startsWith("\"use strict\"; (function () {") && script.endsWith("})();"))
|
||||
script = script.slice("\"use strict\"; (function () {".length, -"})();".length);
|
||||
if (exposeVarsToGlobalScope && script.startsWith("(function () {") && script.endsWith("})();"))
|
||||
script = script.slice("(function () {".length, -"})();".length);
|
||||
|
||||
script = beautify(script, {
|
||||
"indent_size": "1",
|
||||
"indent_char": "\t",
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
"version": "0.5.3",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"js-beautify": "^1.14.11"
|
||||
"js-beautify": "^1.14.11",
|
||||
"uglify-js": "^3.19.2"
|
||||
}
|
||||
},
|
||||
"node_modules/@isaacs/cliui": {
|
||||
|
@ -463,6 +464,17 @@
|
|||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/uglify-js": {
|
||||
"version": "3.19.2",
|
||||
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.19.2.tgz",
|
||||
"integrity": "sha512-S8KA6DDI47nQXJSi2ctQ629YzwOVs+bQML6DAtvy0wgNdpi+0ySpQK0g2pxBq2xfF2z3YCscu7NNA8nXT9PlIQ==",
|
||||
"bin": {
|
||||
"uglifyjs": "bin/uglifyjs"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/which": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
|
||||
|
@ -878,6 +890,11 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"uglify-js": {
|
||||
"version": "3.19.2",
|
||||
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.19.2.tgz",
|
||||
"integrity": "sha512-S8KA6DDI47nQXJSi2ctQ629YzwOVs+bQML6DAtvy0wgNdpi+0ySpQK0g2pxBq2xfF2z3YCscu7NNA8nXT9PlIQ=="
|
||||
},
|
||||
"which": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
},
|
||||
"homepage": "https://github.com/fxclient/FXclient#readme",
|
||||
"dependencies": {
|
||||
"js-beautify": "^1.14.11"
|
||||
"js-beautify": "^1.14.11",
|
||||
"uglify-js": "^3.19.2"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue