commit d662a553234fc3074822faca333e2a1c15a89bb1 Author: Reece Date: Sun Sep 26 04:53:12 2021 +0100 Initial Commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5d118b3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +package-lock.json +node_modules +data +node.exe +node +project \ No newline at end of file diff --git a/ConstructFullMaven.js b/ConstructFullMaven.js new file mode 100644 index 0000000..18b47b5 --- /dev/null +++ b/ConstructFullMaven.js @@ -0,0 +1,173 @@ +let version = require("./config.json").version + +let manifest = require("./data/" + version + ".json") +let fs = require("fs") + +var xml = "" + +let XMLStart = +` + + 4.0.0 + + sx.reece + Minecraft + ` + version + ` + + + 16 + 16 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.3 + + 16 + 16 + true + + -Xpkginfo:always + + + + + + + + + snapshot-repository + Maven2 Snapshot Repository + https://oss.sonatype.org/content/repositories/snapshots + + true + daily + + + + + maven2-repo + http://central.maven.org/maven2 + + + + mojang-repo + https://libraries.minecraft.net + + + + ss + http://maven.icm.edu.pl/artifactory/repo/ + + + +` + +function GetKey(key, obj) +{ + return key.split('.').reduce(function(a, b) + { + return a && a[b]; + }, obj); +} + +xml += XMLStart + +xml += " \r\n" + +//xml += ` +// +// sx.reece +// mcerrors +// 1.0 +// system +// ` + process.cwd() + "\\MinecraftErrors.jar" + ` +// +//` + +let os = require("os") +let osname = os.type() === "Windows_NT" ? "windows" : "linux" +let arch = os.arch() === "ia32" || os.arch() === "x64" || os.arch() === "x86" ? "x86" : "arm64" +let added = {} +manifest.libraries.forEach((library) => +{ + if (library.rules) + { + var allow = false + for (rule of library.rules) + { + let testRule = function() + { + let testPair = function(value, expected) + { + let actual = GetKey(value, rule) + + if (!actual) + { + return false + } + + return actual != expected + } + + + return false + } + + let retState = testRule("os.name", osname) || testRule("os.arch", arch) + + if (retState || Object.keys(rule).length == 1) + { + if (rule.action == "allow") + { + allow = true + } + else if (rule.action == "disallow") + { + allow = false + } + } + } + + if (!allow) + { + return + } + } + + let parts = library.name.split(":") + if (GetKey("downloads.artifact.url", library) && !added[library.name]) + { + added[library.name] = "a" + xml += " \r\n" + xml += " " + parts[0] + "\r\n" + xml += " " + parts[1] + "\r\n" + xml += " " + parts[2] + "\r\n" + xml += " \r\n" + } + + let forceNatives = GetKey("natives." + osname, library) + let natives = GetKey("downloads.classifiers.natives-" + osname, library) + if (forceNatives) + { + xml += " \r\n" + xml += " " + parts[0] + "\r\n" + xml += " " + parts[1] + "\r\n" + xml += " " + parts[2] + "\r\n" + xml += " natives-" + osname + "\r\n" + xml += " \r\n" + console.log(natives) + + } +}) +xml += " \r\n" + +xml += "\r\n" + + +fs.writeFileSync("./data/tmp/minecraft-maven.xml", xml) \ No newline at end of file diff --git a/ConstructProjectMaven.js b/ConstructProjectMaven.js new file mode 100644 index 0000000..1f80cb5 --- /dev/null +++ b/ConstructProjectMaven.js @@ -0,0 +1,212 @@ +// mvn bash:run +// mvn install + + +let config = require("./config.json") + +let version = config.version +let devNamespace = config.devNamespace +let proj = config.proj +let projVer = config.projVer + +let manifest = require("./data/" + version + ".json") +let fs = require("fs") +let os = require("os") +let osname = os.type() === "Windows_NT" ? "windows" : "linux" +let arch = os.arch() === "ia32" || os.arch() === "x64" || os.arch() === "x86" ? "x86" : "arm64" + +var xml = "" +let added = {} + + +function GetKey(key, obj) +{ + return key.split('.').reduce(function(a, b) + { + return a && a[b]; + }, obj); +} + +let nodeJsCmd = "" +let nodeJsCmdSanitized = nodeJsCmd + + +let XMLStart = +` + + 4.0.0 + + ${devNamespace} + ${proj} + ${projVer} + + + 16 + 16 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.3 + + 16 + 16 + true + + -Xpkginfo:always + + + + + org.codehaus.mojo + exec-maven-plugin + 3.0.0 + + + test + compile + + exec + + + + + node + ` + process.cwd() + ` + + ./UpdateJar.js + + + + + + + + + snapshot-repository + Maven2 Snapshot Repository + https://oss.sonatype.org/content/repositories/snapshots + + true + daily + + + + maven2-repo + http://central.maven.org/maven2 + + + mojang-repo + https://libraries.minecraft.net + + + ss + http://maven.icm.edu.pl/artifactory/repo/ + + + central-repo + https://repo1.maven.org/maven2/ + + +` + +xml += XMLStart +xml += " " + +xml += ` + + net.minecraft + mojangClient + 1.0 + system + ` + process.cwd() + `\\data\\${version}-Dummy.jar` + ` + + + org.codehaus.mojo + exec-maven-plugin + 3.0.0 + +` + +manifest.libraries.forEach((library) => +{ + if (library.rules) + { + var allow = false + for (rule of library.rules) + { + let testRule = function() + { + let testPair = function(value, expected) + { + let actual = GetKey(value, rule) + + if (!actual) + { + return false + } + + return actual != expected + } + + + return false + } + + let retState = testRule("os.name", osname) || testRule("os.arch", arch) + + if (retState || Object.keys(rule).length == 1) + { + if (rule.action == "allow") + { + allow = true + } + else if (rule.action == "disallow") + { + allow = false + } + } + } + + if (!allow) + { + return + } + } + + let parts = library.name.split(":") + if (GetKey("downloads.artifact.url", library) && !added[library.name]) + { + added[library.name] = "a" + xml += " \r\n" + xml += " " + parts[0] + "\r\n" + xml += " " + parts[1] + "\r\n" + xml += " " + parts[2] + "\r\n" + xml += " \r\n" + } + + let forceNatives = GetKey("natives." + osname, library) + let natives = GetKey("downloads.classifiers.natives-" + osname, library) + if (forceNatives) + { + xml += " \r\n" + xml += " " + parts[0] + "\r\n" + xml += " " + parts[1] + "\r\n" + xml += " " + parts[2] + "\r\n" + xml += " natives-" + osname + "\r\n" + xml += " \r\n" + console.log(natives) + + } +}) +xml += " \r\n" + +xml += "\r\n" + + +fs.writeFileSync("./project/pom.xml", xml) \ No newline at end of file diff --git a/CreateDir.js b/CreateDir.js new file mode 100644 index 0000000..2aafbc1 --- /dev/null +++ b/CreateDir.js @@ -0,0 +1,14 @@ +let fs = require("fs") + +function tryAdd(path) { + try { + fs.mkdirSync(path) + } catch (e) {} +} + +tryAdd("project") +tryAdd("project/src") +tryAdd("project/src/main") +tryAdd("project/src/resources") +tryAdd("data") +tryAdd("data/tmp") \ No newline at end of file diff --git a/DecompileMinecraft.js b/DecompileMinecraft.js new file mode 100644 index 0000000..f52b73b --- /dev/null +++ b/DecompileMinecraft.js @@ -0,0 +1,29 @@ +let ver = require("./config.json").version +let fs = require("fs") +let modBuilding = `./data/tmp/mc_decompiled_${ver}` +let unzip = require("unzipper") + +function mkdir(path) { + try { + fs.mkdirSync(path) + } catch (e) {} +} + +function unlink(path) { + try { + fs.unlinkSync(path) + return true + } catch (e) {} +} + +async function re() { + mkdir(modBuilding) + + await require("./Exec.js").exec(`java -Xmx4G -Xms1G -jar lib\\FernFlower.jar -hes=1 -hdc=1 -dgs=1 -ren=0 -lit=0 -nns=0 -asc=1 -rbr=1 ./data/${ver}-Mapped.jar ${modBuilding}`) + + let sources = `${modBuilding}/${ver}-Mapped.jar` + await fs.createReadStream(sources).pipe(unzip.Extract({ path: modBuilding })).promise() + unlink(sources) +} + +re() \ No newline at end of file diff --git a/Exec.js b/Exec.js new file mode 100644 index 0000000..fd3d896 --- /dev/null +++ b/Exec.js @@ -0,0 +1,20 @@ +function exec(cmd){ + return new Promise((resolve) => { + var process = require("child_process").exec(cmd, (error, stdout, stderr) => { + if (error) { + console.log(`error: ${error.message}`); + return; + } + if (stderr) { + console.log(`stderr: ${stderr}`); + return; + } + console.log(`stdout: ${stdout}`); + }); + process.on('close', (code) => { + resolve() + }); + }); +} + +module.exports = {exec: exec} \ No newline at end of file diff --git a/ExportMod.bat b/ExportMod.bat new file mode 100644 index 0000000..594e01b --- /dev/null +++ b/ExportMod.bat @@ -0,0 +1,4 @@ +@echo off +cd project +mvn package +node ./RemapMod.js \ No newline at end of file diff --git a/FirstRun.bat b/FirstRun.bat new file mode 100644 index 0000000..15cfacd --- /dev/null +++ b/FirstRun.bat @@ -0,0 +1,5 @@ +@echo off +node .\CreateDir.js +node .\PullMinecraftVersion.js +node .\MapMinecraft.js +node .\ConstructProjectMaven.js diff --git a/MapMinecraft.js b/MapMinecraft.js new file mode 100644 index 0000000..abf57c1 --- /dev/null +++ b/MapMinecraft.js @@ -0,0 +1,2 @@ +let ver = require("./config.json").version +require("./Exec.js").exec(`java -jar lib\\SpecialSource.jar -srg-in=.\\data\\${ver}.txt --in-jar=.\\data\\${ver}.jar -o=.\\data\\${ver}-Mapped.jar`) \ No newline at end of file diff --git a/PullMinecraftVersion.js b/PullMinecraftVersion.js new file mode 100644 index 0000000..5c78a71 --- /dev/null +++ b/PullMinecraftVersion.js @@ -0,0 +1,46 @@ +let fs = require("fs") +let config = require("./config.json") +let http = require('https'); +let archiver = require('archiver') + +var download = function(url, dest, cb) { + var file = fs.createWriteStream(dest); + http.get(url, function(response) { + response.pipe(file); + file.on('finish', function() { + file.close(cb); + }); + }); +} + +async function downloadAsync(url, path) { + let p = new Promise((resolve, reject) => { + download(url, path, resolve) + }); + await p +} + +function reformatJsonFile(path) { + fs.writeFileSync(path, JSON.stringify(JSON.parse(fs.readFileSync(path)), 0, 4)) +} + +async function downloadAll() { + await downloadAsync(`https://launchermeta.mojang.com/mc/game/version_manifest.json`, `./data/versions.json`) + const versions = require("./data/versions.json") + reformatJsonFile("./data/versions.json") + const version = versions.versions.find((item) => { return item.id == config.version}) + let path = `./data/${config.version}.json` + await downloadAsync(version.url, path) + reformatJsonFile(path) + let game = JSON.parse(fs.readFileSync(path)) + await downloadAsync(game.downloads.client.url, `./data/${config.version}.jar`) + await downloadAsync(game.downloads.client_mappings.url, `./data/${config.version}.txt`) + const output = fs.createWriteStream(`./data/${config.version}-Dummy.jar`) + const archive = archiver('zip', { + zlib: { level: 9 } + }) + archive.finalize() +} + +downloadAll() + diff --git a/RemapMod.js b/RemapMod.js new file mode 100644 index 0000000..e69de29 diff --git a/UpdateJar.js b/UpdateJar.js new file mode 100644 index 0000000..ee2c1ac --- /dev/null +++ b/UpdateJar.js @@ -0,0 +1,78 @@ +let fs = require("fs") +let config = require("./config.json") +let unzip = require("unzipper") +let zipper = require('zip-local'); + +let projPath = "./project/src/main/java" +let gameSrc = `./data/tmp/game_building_${config.version}` + +console.log("Processing support library") + +const readAllFolder = (dirMain) => { + let paths = [] + const readDirMain = fs.readdirSync(dirMain); + + readDirMain.forEach((dirNext) => { + if (fs.lstatSync(dirMain + "/" + dirNext).isDirectory()) + { + paths = paths.concat(readAllFolder(dirMain + "/" + dirNext)); + } + else + { + paths.push(dirMain + "/" + dirNext) + } + }); + + return paths + +}; + +let patchFiles = readAllFolder(projPath).map((path) => path.substr(projPath.length + 1)) + +function mkdir(path) { + try { + fs.mkdirSync(path) + } catch (e) {} +} + +function unlink(path) { + try { + fs.unlinkSync(path) + return true + } catch (e) {} +} + +let modBuilding = `./data/tmp/mod_building_${config.version}` +let hash = `./data/tmp/lastHash_${config.version}.txt` + +mkdir("./data/tmp") +mkdir(gameSrc) +mkdir(modBuilding) + + +var lastHash = "" +try { + lastHash = fs.readFileSync(hash) +} catch (e){} + +let curHash = JSON.stringify(patchFiles) +if (curHash == lastHash) return; + +async function re() { + console.log("Unzipping") + await fs.createReadStream(`./data/${config.version}-Mapped.jar`).pipe(unzip.Extract({ path: gameSrc })).promise() + + console.log("Deleting original classes") + patchFiles.forEach((path) => {unlink(gameSrc + '/' + path.substr(0, path.lastIndexOf(".")) + ".class") }) + + + console.log("Deleting meta-inf") + fs.rmdirSync(gameSrc + "/META-INF", { recursive: true }); + + console.log("Rezipping") + zipper.sync.zip(gameSrc).compress().save(`./data/${config.version}-Dummy.jar`); + + fs.writeFileSync(hash, curHash) +} + +re() \ No newline at end of file diff --git a/config.json b/config.json new file mode 100644 index 0000000..92adbc0 --- /dev/null +++ b/config.json @@ -0,0 +1,6 @@ +{ + "version": "21w38a", + "devNamespace": "sx.reece", + "proj": "altren", + "projVer": "0.0.1" +} \ No newline at end of file diff --git a/lib/SpecialSource.jar b/lib/SpecialSource.jar new file mode 100644 index 0000000..7ffba8d Binary files /dev/null and b/lib/SpecialSource.jar differ diff --git a/lib/fernflower.jar b/lib/fernflower.jar new file mode 100644 index 0000000..d4e56c3 Binary files /dev/null and b/lib/fernflower.jar differ diff --git a/package.json b/package.json new file mode 100644 index 0000000..fc71d08 --- /dev/null +++ b/package.json @@ -0,0 +1,8 @@ +{ + "dependencies": + { + "zip-local": "latest", + "archiver": "latest", + "unzipper": "latest" + } +} \ No newline at end of file