Initial Commit

This commit is contained in:
Reece Wilson 2021-09-26 04:53:12 +01:00
commit d662a55323
16 changed files with 603 additions and 0 deletions

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
package-lock.json
node_modules
data
node.exe
node
project

173
ConstructFullMaven.js Normal file
View File

@ -0,0 +1,173 @@
let version = require("./config.json").version
let manifest = require("./data/" + version + ".json")
let fs = require("fs")
var xml = ""
let XMLStart =
`<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>sx.reece</groupId>
<artifactId>Minecraft</artifactId>
<version>` + version + `</version>
<properties>
<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>16</source>
<target>16</target>
<fork>true</fork>
<compilerArgs>
<arg>-Xpkginfo:always</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>snapshot-repository</id>
<name>Maven2 Snapshot Repository</name>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
</snapshots>
</repository>
<repository>
<id>maven2-repo</id>
<url>http://central.maven.org/maven2</url>
</repository>
<repository>
<id>mojang-repo</id>
<url>https://libraries.minecraft.net</url>
</repository>
<repository>
<id>ss</id>
<url>http://maven.icm.edu.pl/artifactory/repo/</url>
</repository>
</repositories>
`
function GetKey(key, obj)
{
return key.split('.').reduce(function(a, b)
{
return a && a[b];
}, obj);
}
xml += XMLStart
xml += " <dependencies>\r\n"
//xml += `
// <dependency>
// <groupId>sx.reece</groupId>
// <artifactId>mcerrors</artifactId>
// <version>1.0</version>
// <scope>system</scope>
// <systemPath>` + process.cwd() + "\\MinecraftErrors.jar" + `</systemPath>
// </dependency>
//`
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 += " <dependency>\r\n"
xml += " <groupId>" + parts[0] + "</groupId>\r\n"
xml += " <artifactId>" + parts[1] + "</artifactId>\r\n"
xml += " <version>" + parts[2] + "</version>\r\n"
xml += " </dependency>\r\n"
}
let forceNatives = GetKey("natives." + osname, library)
let natives = GetKey("downloads.classifiers.natives-" + osname, library)
if (forceNatives)
{
xml += " <dependency>\r\n"
xml += " <groupId>" + parts[0] + "</groupId>\r\n"
xml += " <artifactId>" + parts[1] + "</artifactId>\r\n"
xml += " <version>" + parts[2] + "</version>\r\n"
xml += " <classifier>natives-" + osname + "</classifier>\r\n"
xml += " </dependency>\r\n"
console.log(natives)
}
})
xml += " </dependencies>\r\n"
xml += "</project>\r\n"
fs.writeFileSync("./data/tmp/minecraft-maven.xml", xml)

212
ConstructProjectMaven.js Normal file
View File

@ -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 =
`<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>${devNamespace}</groupId>
<artifactId>${proj}</artifactId>
<version>${projVer}</version>
<properties>
<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>16</source>
<target>16</target>
<fork>true</fork>
<compilerArgs>
<arg>-Xpkginfo:always</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>test</id>
<phase>compile</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>node</executable>
<workingDirectory>` + process.cwd() + `</workingDirectory>
<arguments>
<argument>./UpdateJar.js</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>snapshot-repository</id>
<name>Maven2 Snapshot Repository</name>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
</snapshots>
</repository>
<repository>
<id>maven2-repo</id>
<url>http://central.maven.org/maven2</url>
</repository>
<repository>
<id>mojang-repo</id>
<url>https://libraries.minecraft.net</url>
</repository>
<repository>
<id>ss</id>
<url>http://maven.icm.edu.pl/artifactory/repo/</url>
</repository>
<repository>
<id>central-repo</id>
<url>https://repo1.maven.org/maven2/</url>
</repository>
</repositories>
`
xml += XMLStart
xml += " <dependencies>"
xml += `
<dependency>
<groupId>net.minecraft</groupId>
<artifactId>mojangClient</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>` + process.cwd() + `\\data\\${version}-Dummy.jar` + `</systemPath>
</dependency>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
</dependency>
`
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 += " <dependency>\r\n"
xml += " <groupId>" + parts[0] + "</groupId>\r\n"
xml += " <artifactId>" + parts[1] + "</artifactId>\r\n"
xml += " <version>" + parts[2] + "</version>\r\n"
xml += " </dependency>\r\n"
}
let forceNatives = GetKey("natives." + osname, library)
let natives = GetKey("downloads.classifiers.natives-" + osname, library)
if (forceNatives)
{
xml += " <dependency>\r\n"
xml += " <groupId>" + parts[0] + "</groupId>\r\n"
xml += " <artifactId>" + parts[1] + "</artifactId>\r\n"
xml += " <version>" + parts[2] + "</version>\r\n"
xml += " <classifier>natives-" + osname + "</classifier>\r\n"
xml += " </dependency>\r\n"
console.log(natives)
}
})
xml += " </dependencies>\r\n"
xml += "</project>\r\n"
fs.writeFileSync("./project/pom.xml", xml)

14
CreateDir.js Normal file
View File

@ -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")

29
DecompileMinecraft.js Normal file
View File

@ -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()

20
Exec.js Normal file
View File

@ -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}

4
ExportMod.bat Normal file
View File

@ -0,0 +1,4 @@
@echo off
cd project
mvn package
node ./RemapMod.js

5
FirstRun.bat Normal file
View File

@ -0,0 +1,5 @@
@echo off
node .\CreateDir.js
node .\PullMinecraftVersion.js
node .\MapMinecraft.js
node .\ConstructProjectMaven.js

2
MapMinecraft.js Normal file
View File

@ -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`)

46
PullMinecraftVersion.js Normal file
View File

@ -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()

0
RemapMod.js Normal file
View File

78
UpdateJar.js Normal file
View File

@ -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()

6
config.json Normal file
View File

@ -0,0 +1,6 @@
{
"version": "21w38a",
"devNamespace": "sx.reece",
"proj": "altren",
"projVer": "0.0.1"
}

BIN
lib/SpecialSource.jar Normal file

Binary file not shown.

BIN
lib/fernflower.jar Normal file

Binary file not shown.

8
package.json Normal file
View File

@ -0,0 +1,8 @@
{
"dependencies":
{
"zip-local": "latest",
"archiver": "latest",
"unzipper": "latest"
}
}