From 6cfbaf91de667d110a58c695aa8d0c0ab4b36bc1 Mon Sep 17 00:00:00 2001 From: Lassebq Date: Sun, 6 Aug 2023 20:02:48 +0300 Subject: [PATCH] Address #2 --- .gitignore | 2 + MultiMC.md | 566 +----------------- build.gradle | 47 +- .../org/mcphackers/launchwrapper/Launch.java | 41 ++ .../launchwrapper/LaunchConfig.java | 43 +- .../loader/LaunchClassLoader.java | 24 +- .../launchwrapper/protocol/SkinRequests.java | 7 +- .../launchwrapper/tweak/LegacyTweak.java | 9 +- .../launchwrapper/util/ClassNodeSource.java | 4 + .../org/mcphackers/launchwrapper/util/OS.java | 28 + 10 files changed, 215 insertions(+), 556 deletions(-) create mode 100644 src/main/java/org/mcphackers/launchwrapper/util/OS.java diff --git a/.gitignore b/.gitignore index a7e41e1..a628d9b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ .project .settings/ +.vscode/ + # netbeans nbproject diff --git a/MultiMC.md b/MultiMC.md index db25047..c120964 100644 --- a/MultiMC.md +++ b/MultiMC.md @@ -1,182 +1,17 @@ -# How to use in MultiMC -- Make a new instance in MultiMC with the wanted version of Minecraft. -- Click `Edit Instance` - it should open the `Version` page of the instance. -- Select the `Minecraft` component and click `Customize` - `Edit`. If you have not configured an external Text Editor in MultiMC Settings, this will attempt to open your system JSON editor. -- If the opened JSON has the `legacyLaunch` trait (for Minecraft versions 1.5.2 and older), then add the `noapplet` trait after it as well. -- For Minecraft versions 1.5.2 and older, set up an empty `assetIndex` instead of the vanilla pre-1.6: -```json -"assetIndex": { - "id": "empty", - "sha1": "62ea787c1f800c091b98678b050453a5ae59d7bc", - "size": 14, - "totalSize": 0, - "url": "https://mcphackers.github.io/assets/empty.json" -} -``` -- If the opened JSON does not have a `libraries` array object (right after the `formatVersion` object), then add one. Add LaunchWrapper and its dependencies to the libraries to get an array like this: -```json -"libraries": [ - { - "downloads": { - "artifact": { - "sha1": "120f6fdeb2602fa2d979ad0bdcd3c443a48148a6", - "size": 107614, - "url": "https://mcphackers.github.io/libraries/org/mcphackers/launchwrapper/1.0/launchwrapper-1.0.jar" - } - }, - "name": "org.mcphackers:launchwrapper:1.0" - }, - { - "downloads": { - "artifact": { - "sha1": "d96c99a30f5e1a19b0e609dbb19a44d8518ac01e", - "size": 52660, - "url": "https://repo.maven.apache.org/maven2/org/ow2/asm/asm-tree/9.2/asm-tree-9.2.jar" - } - }, - "name": "org.ow2.asm:asm-tree:9.2" - }, - { - "downloads": { - "artifact": { - "sha1": "81a03f76019c67362299c40e0ba13405f5467bff", - "size": 122004, - "url": "https://repo.maven.apache.org/maven2/org/ow2/asm/asm/9.2/asm-9.2.jar" - } - }, - "name": "org.ow2.asm:asm:9.2" - }, - { - "downloads": { - "artifact": { - "sha1": "d2c95f0a83b1b2b28131d46abfe8e68f7dc07ede", - "size": 65667, - "url": "https://mcphackers.github.io/libraries/org/json/json/20230311/json-20230311.jar" - } - }, - "name": "org.json:json:20230311" - }, - { - "downloads": { - "artifact": { - "sha1": "6fcff0b8d6173ac275f3728a9e5a987cfca88762", - "size": 79599, - "url": "https://mcphackers.github.io/libraries/org/mcphackers/rdi/rdi/1.0/rdi-1.0.jar" - } - }, - "name": "org.mcphackers.rdi:rdi:1.0" - } -] -``` -- If the opened JSON does not have a `mainClass` string object (right before the `mainJar` object), then add one. Set or change the `mainClass` value to `org.mcphackers.launchwrapper.Launch`. -- If the opened JSON does not have a `minecraftArguments` string object (right after the `mainJar` object), then add one. Set or change the `minecraftArguments` value to something like `--username ${auth_player_name} --session ${auth_session} --gameDir ${game_directory} --assetsDir ${game_assets}` (you can see examples below or in [BetterJSONs](https://mcphackers.github.io/BetterJSONs/)). +# JSON patches for MultiMC instances +This allows changing the Minecraft version in the instance without re-editing the component, and easier interoperability with other MultiMC features. More information about JSON patches can be found [on the MultiMC wiki page about them](https://github.com/MultiMC/Launcher/wiki/JSON-Patches). Here is a [MultiMC instance](https://github.com/MCPHackers/LaunchWrapper/files/11588554/LaunchWrapperMCP-MultiMC.zip) demonstrating this. -## Examples -*Base your JSON on [BetterJSONs](https://mcphackers.github.io/BetterJSONs/)* +Instructions: +- Create a new MultiMC instance. +- Click "Edit Instance". +- Click "Add Empty". Enter "LaunchWrapper" for the name, and "org.mcphackers.launchwrapper" for the UUID. +- Select the new component labeled "LaunchWrapper", and click "Edit". +- Replace the contents of the file with something like this: -### c0.30_01c -```json + ```json { "+traits": [ - "legacyLaunch", - "noapplet", - "no-texturepacks" - ], - "appletClass": "com.mojang.minecraft.MinecraftApplet", - "assetIndex": { - "id": "empty", - "sha1": "62ea787c1f800c091b98678b050453a5ae59d7bc", - "size": 14, - "totalSize": 0, - "url": "https://mcphackers.github.io/assets/empty.json" - }, - "formatVersion": 1, - "libraries": [ - { - "downloads": { - "artifact": { - "sha1": "120f6fdeb2602fa2d979ad0bdcd3c443a48148a6", - "size": 107614, - "url": "https://mcphackers.github.io/libraries/org/mcphackers/launchwrapper/1.0/launchwrapper-1.0.jar" - } - }, - "name": "org.mcphackers:launchwrapper:1.0" - }, - { - "downloads": { - "artifact": { - "sha1": "d96c99a30f5e1a19b0e609dbb19a44d8518ac01e", - "size": 52660, - "url": "https://repo.maven.apache.org/maven2/org/ow2/asm/asm-tree/9.2/asm-tree-9.2.jar" - } - }, - "name": "org.ow2.asm:asm-tree:9.2" - }, - { - "downloads": { - "artifact": { - "sha1": "81a03f76019c67362299c40e0ba13405f5467bff", - "size": 122004, - "url": "https://repo.maven.apache.org/maven2/org/ow2/asm/asm/9.2/asm-9.2.jar" - } - }, - "name": "org.ow2.asm:asm:9.2" - }, - { - "downloads": { - "artifact": { - "sha1": "d2c95f0a83b1b2b28131d46abfe8e68f7dc07ede", - "size": 65667, - "url": "https://mcphackers.github.io/libraries/org/json/json/20230311/json-20230311.jar" - } - }, - "name": "org.json:json:20230311" - }, - { - "downloads": { - "artifact": { - "sha1": "855b05d238b72b03197e6702a765f344a32b8291", - "size": 79599, - "url": "https://mcphackers.github.io/libraries/org/mcphackers/rdi/rdi/1.0/rdi-1.0.jar" - } - }, - "name": "org.mcphackers.rdi:rdi:1.0" - } - ], - "mainClass": "org.mcphackers.launchwrapper.Launch", - "mainJar": { - "downloads": { - "artifact": { - "sha1": "54622801f5ef1bcc1549a842c5b04cb5d5583005", - "size": 297776, - "url": "https://launcher.mojang.com/v1/objects/54622801f5ef1bcc1549a842c5b04cb5d5583005/client.jar" - } - }, - "name": "com.mojang:minecraft:c0.30_01c:client" - }, - "minecraftArguments": "--username ${auth_player_name} --sessionid ${auth_session} --gameDir ${game_directory} --assetsDir ${game_assets} --resourcesProxyPort 11701 --skinProxy pre-b1.9-pre4", - "name": "Minecraft", - "releaseTime": "2009-12-22T00:00:00+02:00", - "requires": [ - { - "suggests": "2.9.4", - "uid": "org.lwjgl" - } - ], - "type": "old_alpha", - "uid": "net.minecraft", - "version": "c0.30_01c" -} - -``` - -### a1.1.2_01 -```json -{ - "+traits": [ - "legacyLaunch", - "noapplet", - "no-texturepacks" + "noapplet" ], "assetIndex": { "id": "empty", @@ -185,387 +20,44 @@ "totalSize": 0, "url": "https://mcphackers.github.io/assets/empty.json" }, - "formatVersion": 1, "libraries": [ { - "downloads": { - "artifact": { - "sha1": "120f6fdeb2602fa2d979ad0bdcd3c443a48148a6", - "size": 107614, - "url": "https://mcphackers.github.io/libraries/org/mcphackers/launchwrapper/1.0/launchwrapper-1.0.jar" - } - }, - "name": "org.mcphackers:launchwrapper:1.0" + "name": "org.mcphackers:launchwrapper:1.0", + "url": "https://mcphackers.github.io/libraries/" }, { - "downloads": { - "artifact": { - "sha1": "d96c99a30f5e1a19b0e609dbb19a44d8518ac01e", - "size": 52660, - "url": "https://repo.maven.apache.org/maven2/org/ow2/asm/asm-tree/9.2/asm-tree-9.2.jar" - } - }, - "name": "org.ow2.asm:asm-tree:9.2" + "name": "org.ow2.asm:asm:9.2", + "url": "https://repo1.maven.org/maven2/" }, { - "downloads": { - "artifact": { - "sha1": "81a03f76019c67362299c40e0ba13405f5467bff", - "size": 122004, - "url": "https://repo.maven.apache.org/maven2/org/ow2/asm/asm/9.2/asm-9.2.jar" - } - }, - "name": "org.ow2.asm:asm:9.2" + "name": "org.ow2.asm:asm-tree:9.2", + "url": "https://repo1.maven.org/maven2/" }, { - "downloads": { - "artifact": { - "sha1": "d2c95f0a83b1b2b28131d46abfe8e68f7dc07ede", - "size": 65667, - "url": "https://mcphackers.github.io/libraries/org/json/json/20230311/json-20230311.jar" - } - }, - "name": "org.json:json:20230311" + "name": "org.json:json:20230311", + "url": "https://mcphackers.github.io/libraries/" }, { - "downloads": { - "artifact": { - "sha1": "855b05d238b72b03197e6702a765f344a32b8291", - "size": 79599, - "url": "https://mcphackers.github.io/libraries/org/mcphackers/rdi/rdi/1.0/rdi-1.0.jar" - } - }, - "name": "org.mcphackers.rdi:rdi:1.0" + "name": "org.mcphackers.rdi:rdi:1.0", + "url": "https://mcphackers.github.io/libraries/" } ], "mainClass": "org.mcphackers.launchwrapper.Launch", - "mainJar": { - "downloads": { - "artifact": { - "sha1": "daa4b9f192d2c260837d3b98c39432324da28e86", - "size": 897164, - "url": "https://launcher.mojang.com/v1/objects/daa4b9f192d2c260837d3b98c39432324da28e86/client.jar" - } - }, - "name": "com.mojang:minecraft:a1.1.2_01:client" - }, - "minecraftArguments": "--username ${auth_player_name} --session ${auth_session} --gameDir ${game_directory} --assetsDir ${game_assets} --resourcesProxyPort 11702 --skinProxy pre-b1.9-pre4", - "name": "Minecraft", - "releaseTime": "2010-09-23T00:00:00+02:00", + "minecraftArguments": "--username ${auth_player_name} --session ${auth_session} --gameDir ${game_directory} --assetsDir ${game_assets}", "requires": [ { - "suggests": "2.9.4", - "uid": "org.lwjgl" + "uid": "net.minecraft" } ], - "type": "old_alpha", - "uid": "net.minecraft", - "version": "a1.1.2_01" -} - -``` - -### b1.7.3 -```json -{ - "+traits": [ - "legacyLaunch", - "noapplet", - "texturepacks" - ], - "assetIndex": { - "id": "empty", - "sha1": "62ea787c1f800c091b98678b050453a5ae59d7bc", - "size": 14, - "totalSize": 0, - "url": "https://mcphackers.github.io/assets/empty.json" - }, "formatVersion": 1, - "libraries": [ - { - "downloads": { - "artifact": { - "sha1": "120f6fdeb2602fa2d979ad0bdcd3c443a48148a6", - "size": 107614, - "url": "https://mcphackers.github.io/libraries/org/mcphackers/launchwrapper/1.0/launchwrapper-1.0.jar" - } - }, - "name": "org.mcphackers:launchwrapper:1.0" - }, - { - "downloads": { - "artifact": { - "sha1": "d96c99a30f5e1a19b0e609dbb19a44d8518ac01e", - "size": 52660, - "url": "https://repo.maven.apache.org/maven2/org/ow2/asm/asm-tree/9.2/asm-tree-9.2.jar" - } - }, - "name": "org.ow2.asm:asm-tree:9.2" - }, - { - "downloads": { - "artifact": { - "sha1": "81a03f76019c67362299c40e0ba13405f5467bff", - "size": 122004, - "url": "https://repo.maven.apache.org/maven2/org/ow2/asm/asm/9.2/asm-9.2.jar" - } - }, - "name": "org.ow2.asm:asm:9.2" - }, - { - "downloads": { - "artifact": { - "sha1": "d2c95f0a83b1b2b28131d46abfe8e68f7dc07ede", - "size": 65667, - "url": "https://mcphackers.github.io/libraries/org/json/json/20230311/json-20230311.jar" - } - }, - "name": "org.json:json:20230311" - }, - { - "downloads": { - "artifact": { - "sha1": "855b05d238b72b03197e6702a765f344a32b8291", - "size": 79599, - "url": "https://mcphackers.github.io/libraries/org/mcphackers/rdi/rdi/1.0/rdi-1.0.jar" - } - }, - "name": "org.mcphackers.rdi:rdi:1.0" - } - ], - "mainClass": "org.mcphackers.launchwrapper.Launch", - "mainJar": { - "downloads": { - "artifact": { - "sha1": "43db9b498cb67058d2e12d394e6507722e71bb45", - "size": 1465375, - "url": "https://launcher.mojang.com/v1/objects/43db9b498cb67058d2e12d394e6507722e71bb45/client.jar" - } - }, - "name": "com.mojang:minecraft:b1.7.3:client" - }, - "minecraftArguments": "--username ${auth_player_name} --session ${auth_session} --gameDir ${game_directory} --assetsDir ${game_assets} --resourcesProxyPort 11705 --skinProxy pre-b1.9-pre4", - "name": "Minecraft", - "releaseTime": "2011-07-08T00:00:00+02:00", - "requires": [ - { - "suggests": "2.9.4", - "uid": "org.lwjgl" - } - ], - "type": "old_beta", - "uid": "net.minecraft", - "version": "b1.7.3" + "name": "LaunchWrapper", + "uid": "org.mcphackers.launchwrapper", + "version": "1.0.0" } - ``` -### 1.6.4 -```json -{ - "assetIndex": { - "id": "legacy", - "sha1": "770572e819335b6c0a053f8378ad88eda189fc14", - "size": 109634, - "totalSize": 153475165, - "url": "https://launchermeta.mojang.com/v1/packages/770572e819335b6c0a053f8378ad88eda189fc14/legacy.json" - }, - "formatVersion": 1, - "libraries": [ - { - "downloads": { - "artifact": { - "sha1": "6065cc95c661255349c1d0756657be17c29a4fd3", - "size": 61311, - "url": "https://libraries.minecraft.net/net/sf/jopt-simple/jopt-simple/4.5/jopt-simple-4.5.jar" - } - }, - "name": "net.sf.jopt-simple:jopt-simple:4.5" - }, - { - "downloads": { - "artifact": { - "sha1": "4e61cd854bbd3d9765bd7c46fc9008d654b29281", - "size": 102767, - "url": "https://mcphackers.github.io/libraries/com/paulscode/codecjorbis/20230120/codecjorbis-20230120.jar" - } - }, - "name": "com.paulscode:codecjorbis:20230120" - }, - { - "downloads": { - "artifact": { - "sha1": "12f031cfe88fef5c1dd36c563c0a3a69bd7261da", - "size": 5618, - "url": "https://libraries.minecraft.net/com/paulscode/codecwav/20101023/codecwav-20101023.jar" - } - }, - "name": "com.paulscode:codecwav:20101023" - }, - { - "downloads": { - "artifact": { - "sha1": "5c5e304366f75f9eaa2e8cca546a1fb6109348b3", - "size": 21679, - "url": "https://libraries.minecraft.net/com/paulscode/libraryjavasound/20101123/libraryjavasound-20101123.jar" - } - }, - "name": "com.paulscode:libraryjavasound:20101123" - }, - { - "downloads": { - "artifact": { - "sha1": "73e80d0794c39665aec3f62eee88ca91676674ef", - "size": 18981, - "url": "https://libraries.minecraft.net/com/paulscode/librarylwjglopenal/20100824/librarylwjglopenal-20100824.jar" - } - }, - "name": "com.paulscode:librarylwjglopenal:20100824" - }, - { - "downloads": { - "artifact": { - "sha1": "419c05fe9be71f792b2d76cfc9b67f1ed0fec7f6", - "size": 65020, - "url": "https://libraries.minecraft.net/com/paulscode/soundsystem/20120107/soundsystem-20120107.jar" - } - }, - "name": "com.paulscode:soundsystem:20120107" - }, - { - "downloads": { - "artifact": { - "sha1": "751761ce15a3e3aaf3fc75b9f013ff8f7b88a585", - "size": 74953, - "url": "https://libraries.minecraft.net/argo/argo/2.25_fixed/argo-2.25_fixed.jar" - } - }, - "name": "argo:argo:2.25_fixed" - }, - { - "downloads": { - "artifact": { - "sha1": "b6f5d9926b0afbde9f4dbe3db88c5247be7794bb", - "size": 1997327, - "url": "https://libraries.minecraft.net/org/bouncycastle/bcprov-jdk15on/1.47/bcprov-jdk15on-1.47.jar" - } - }, - "name": "org.bouncycastle:bcprov-jdk15on:1.47" - }, - { - "downloads": { - "artifact": { - "sha1": "67b7be4ee7ba48e4828a42d6d5069761186d4a53", - "size": 2189111, - "url": "https://libraries.minecraft.net/com/google/guava/guava/14.0/guava-14.0.jar" - } - }, - "name": "com.google.guava:guava:14.0" - }, - { - "downloads": { - "artifact": { - "sha1": "905075e6c80f206bbe6cf1e809d2caa69f420c76", - "size": 315805, - "url": "https://libraries.minecraft.net/org/apache/commons/commons-lang3/3.1/commons-lang3-3.1.jar" - } - }, - "name": "org.apache.commons:commons-lang3:3.1" - }, - { - "downloads": { - "artifact": { - "sha1": "b1b6ea3b7e4aa4f492509a4952029cd8e48019ad", - "size": 185140, - "url": "https://libraries.minecraft.net/commons-io/commons-io/2.4/commons-io-2.4.jar" - } - }, - "name": "commons-io:commons-io:2.4" - }, - { - "downloads": { - "artifact": { - "sha1": "1f96456ca233dec780aa224bff076d8e8bca3908", - "size": 189285, - "url": "https://libraries.minecraft.net/com/google/code/gson/gson/2.2.2/gson-2.2.2.jar" - } - }, - "name": "com.google.code.gson:gson:2.2.2" - }, - { - "downloads": { - "artifact": { - "sha1": "120f6fdeb2602fa2d979ad0bdcd3c443a48148a6", - "size": 107614, - "url": "https://mcphackers.github.io/libraries/org/mcphackers/launchwrapper/1.0/launchwrapper-1.0.jar" - } - }, - "name": "org.mcphackers:launchwrapper:1.0" - }, - { - "downloads": { - "artifact": { - "sha1": "d96c99a30f5e1a19b0e609dbb19a44d8518ac01e", - "size": 52660, - "url": "https://repo.maven.apache.org/maven2/org/ow2/asm/asm-tree/9.2/asm-tree-9.2.jar" - } - }, - "name": "org.ow2.asm:asm-tree:9.2" - }, - { - "downloads": { - "artifact": { - "sha1": "81a03f76019c67362299c40e0ba13405f5467bff", - "size": 122004, - "url": "https://repo.maven.apache.org/maven2/org/ow2/asm/asm/9.2/asm-9.2.jar" - } - }, - "name": "org.ow2.asm:asm:9.2" - }, - { - "downloads": { - "artifact": { - "sha1": "d2c95f0a83b1b2b28131d46abfe8e68f7dc07ede", - "size": 65667, - "url": "https://mcphackers.github.io/libraries/org/json/json/20230311/json-20230311.jar" - } - }, - "name": "org.json:json:20230311" - }, - { - "downloads": { - "artifact": { - "sha1": "855b05d238b72b03197e6702a765f344a32b8291", - "size": 79599, - "url": "https://mcphackers.github.io/libraries/org/mcphackers/rdi/rdi/1.0/rdi-1.0.jar" - } - }, - "name": "org.mcphackers.rdi:rdi:1.0" - } - ], - "mainClass": "org.mcphackers.launchwrapper.Launch", - "mainJar": { - "downloads": { - "artifact": { - "sha1": "1703704407101cf72bd88e68579e3696ce733ecd", - "size": 4745096, - "url": "https://launcher.mojang.com/v1/objects/1703704407101cf72bd88e68579e3696ce733ecd/client.jar" - } - }, - "name": "com.mojang:minecraft:1.6.4:client" - }, - "minecraftArguments": "--username ${auth_player_name} --session ${auth_session} --version ${version_name} --gameDir ${game_directory} --assetsDir ${game_assets} --skinProxy pre-1.8", - "name": "Minecraft", - "releaseTime": "2013-09-19T15:52:37+00:00", - "requires": [ - { - "suggests": "2.9.4", - "uid": "org.lwjgl" - } - ], - "type": "release", - "uid": "net.minecraft", - "version": "1.6.4" -} + The existing version-specific information about creating a MultiMC instance should apply here (`minecraftArguments` should be customised as needed, `assetIndex` and `noapplet` can be removed for Minecraft 1.6 and onwards etc). The main difference between this and the existing instructions is that the format of the `libraries` array is different for JSON patches (`url` is treated like a maven repo). -``` +- Save and close the document. + +This should produce an instance similar to the attached one. I also edited mmc-pack.json to set `dependencyOnly` to be true on the LaunchWrapper patch, which prevents disabling it (optional). diff --git a/build.gradle b/build.gradle index 0bb6fa2..43ad06f 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,13 @@ -apply plugin: 'java' -apply plugin: 'eclipse' +plugins { + id 'java' + id 'eclipse' + id 'maven-publish' +} repositories { + flatDir { + dirs "libs" + } maven { url "https://mcphackers.github.io/libraries/" } @@ -13,24 +19,51 @@ repositories { group = 'org.mcphackers' archivesBaseName = 'launchwrapper' -version = '1.0' +version = '1.0-SNAPSHOT' sourceCompatibility = 1.5 dependencies { implementation 'org.mcphackers.rdi:rdi:1.0' - implementation 'org.lwjgl.lwjgl:lwjgl:2.9.4' - implementation 'org.lwjgl.lwjgl:lwjgl_util:2.9.4' implementation 'org.ow2.asm:asm:9.3' implementation 'org.ow2.asm:asm-tree:9.3' implementation 'org.json:json:20230311' + // implementation name: 'discord-rpc-1.6.2' } task sourcesJar(type: Jar) { - classifier = 'sources' + archiveClassifier = 'sources' from sourceSets.main.allSource } artifacts { archives jar archives sourcesJar -} \ No newline at end of file +} + +publishing { + publications { + mavenJava(MavenPublication) { + artifactId = archivesBaseName + + artifact jar + artifact sourcesJar + } + } + + repositories { + mavenLocal() + + def ENV = System.getenv() + if (ENV.MAVEN_URL) { + maven { + url ENV.MAVEN_URL + if (ENV.MAVEN_USERNAME) { + credentials { + username ENV.MAVEN_USERNAME + password ENV.MAVEN_PASSWORD + } + } + } + } + } +} diff --git a/src/main/java/org/mcphackers/launchwrapper/Launch.java b/src/main/java/org/mcphackers/launchwrapper/Launch.java index fc2eacc..dda7f70 100644 --- a/src/main/java/org/mcphackers/launchwrapper/Launch.java +++ b/src/main/java/org/mcphackers/launchwrapper/Launch.java @@ -1,5 +1,7 @@ package org.mcphackers.launchwrapper; +import java.io.File; + import org.mcphackers.launchwrapper.loader.LaunchClassLoader; import org.mcphackers.launchwrapper.tweak.Tweak; @@ -34,18 +36,57 @@ public class Launch { } public void launch() { + Launch.CLASS_LOADER.setDebugOutput(new File(config.gameDir.get(), "debug")); Tweak mainTweak = Tweak.get(CLASS_LOADER, config); if(mainTweak == null) { System.err.println("Could not find launch target"); return; } if(mainTweak.transform()) { + if(config.discordRPC.get()) { + setupDiscordRPC(); + } mainTweak.getLaunchTarget().launch(CLASS_LOADER); } else { System.err.println("Tweak could not be applied"); } } + protected void setupDiscordRPC() { + // String applicationId = "356875570916753438"; + // DiscordEventHandlers handlers = new DiscordEventHandlersAdapter() {}; + // DiscordRPC.discordInitialize(applicationId, handlers, true); + // DiscordRichPresence presence = new DiscordRichPresence(); + // if(config.version.get() != null) { + // presence.state = "Version: " + config.version.get(); + // } + // if(config.username.get() != null) { + // presence.details = "Username: " + config.username.get(); + // } + // presence.startTimestamp = System.currentTimeMillis() / 1000; + // presence.largeImageKey = "https://cdn.discordapp.com/app-icons/356875570916753438/166fbad351ecdd02d11a3b464748f66b.png?size=256"; + // DiscordRPC.discordUpdatePresence(presence); + // final Thread thread = + // new Thread("Discord RPC") { + // public void run() { + // while(true) { + // DiscordRPC.discordRunCallbacks(); + // try { + // Thread.sleep(2000); + // } catch (InterruptedException e) { + // } + // } + // } + // }; + // Runtime.getRuntime().addShutdownHook(new Thread() { + // public void run() { + // DiscordRPC.discordShutdown(); + // thread.interrupt(); + // } + // }); + // thread.start(); + } + public static Launch getInstance() { return INSTANCE; } diff --git a/src/main/java/org/mcphackers/launchwrapper/LaunchConfig.java b/src/main/java/org/mcphackers/launchwrapper/LaunchConfig.java index b2359b0..25e4615 100644 --- a/src/main/java/org/mcphackers/launchwrapper/LaunchConfig.java +++ b/src/main/java/org/mcphackers/launchwrapper/LaunchConfig.java @@ -10,8 +10,10 @@ import java.util.Locale; import java.util.Map; import org.mcphackers.launchwrapper.protocol.SkinType; +import org.mcphackers.launchwrapper.util.OS; public class LaunchConfig { + private static final File defaultGameDir = getDefaultGameDir(); private Map> parameters = new HashMap>(); public LaunchParameterSwitch demo = new LaunchParameterSwitch("demo", false); @@ -19,8 +21,8 @@ public class LaunchConfig { public LaunchParameterSwitch checkGlErrors = new LaunchParameterSwitch("checkGlErrors", false); public LaunchParameterString server = new LaunchParameterString("server"); public LaunchParameterNumber port = new LaunchParameterNumber("port", 25565); - public LaunchParameterFile gameDir = new LaunchParameterFile("gameDir"); - public LaunchParameterFile workDir = new LaunchParameterFile("workDir"); + public LaunchParameterFile gameDir = new LaunchParameterFile("gameDir", defaultGameDir); + public LaunchParameterFile workDir = new LaunchParameterFile("workDir", defaultGameDir); public LaunchParameterFile assetsDir = new LaunchParameterFile("assetsDir"); public LaunchParameterFile resourcePackDir = new LaunchParameterFile("resourcePackDir"); public LaunchParameterString proxyHost = new LaunchParameterString("proxyHost"); @@ -58,6 +60,43 @@ public class LaunchConfig { public LaunchParameterString title = new LaunchParameterString("title", null, true); public LaunchParameterSwitch oneSixFlag = new LaunchParameterSwitch("oneSixFlag", false, true); public LaunchParameterString tweakClass = new LaunchParameterString("tweakClass", null, true); + public LaunchParameterSwitch discordRPC = new LaunchParameterSwitch("discordRPC", false, true); + + private static File getDefaultGameDir() { + String game = "minecraft"; + String homeDir = System.getProperty("user.home", "."); + File gameDir; + switch(OS.getOs()) { + case LINUX: + case SOLARIS: + String dataHome = System.getProperty("XDG_DATA_HOME"); + if(dataHome != null) { + gameDir = new File(dataHome, "." + game + '/'); + } else { + gameDir = new File(homeDir, ".local/share/" + game + '/'); + } + break; + case WINDOWS: + String appdata = System.getenv("APPDATA"); + if(appdata != null) { + gameDir = new File(appdata, "." + game + '/'); + } else { + gameDir = new File(homeDir, '.' + game + '/'); + } + break; + case OSX: + gameDir = new File(homeDir, "Library/Application Support/" + game); + break; + default: + gameDir = new File(homeDir, game + '/'); + } + + if(!gameDir.exists() && !gameDir.mkdirs()) { + throw new RuntimeException("The working directory could not be created: " + gameDir); + } else { + return gameDir; + } + } public LaunchConfig() { } diff --git a/src/main/java/org/mcphackers/launchwrapper/loader/LaunchClassLoader.java b/src/main/java/org/mcphackers/launchwrapper/loader/LaunchClassLoader.java index 75f4860..f7117c4 100644 --- a/src/main/java/org/mcphackers/launchwrapper/loader/LaunchClassLoader.java +++ b/src/main/java/org/mcphackers/launchwrapper/loader/LaunchClassLoader.java @@ -53,7 +53,7 @@ public class LaunchClassLoader extends URLClassLoader implements ClassNodeSource addURL(url); } } - + public void setDebugOutput(File directory) { debugOutput = directory; } @@ -62,15 +62,19 @@ public class LaunchClassLoader extends URLClassLoader implements ClassNodeSource super.addURL(url); } - public URL getResource(String name) { - URL url = super.getResource(name); + public URL findResource(String name) { + URL url = super.findResource(name); if(url != null) { return url; } return parent.getResource(name); } - public Enumeration getResources(String name) throws IOException { + public URL getResource(String name) { + return super.getResource(name); + } + + public Enumeration findResources(String name) throws IOException { return parent.getResources(name); } @@ -117,7 +121,7 @@ public class LaunchClassLoader extends URLClassLoader implements ClassNodeSource path = path.substring("file:".length()); int i = path.lastIndexOf('!'); if(i != -1) { - path.substring(0, i); + path = path.substring(0, i); } } try { @@ -260,7 +264,7 @@ public class LaunchClassLoader extends URLClassLoader implements ClassNodeSource public void setLoaderTweak(ClassLoaderTweak classLoaderTweak) { tweak = classLoaderTweak; } - + private Class defineClass(String name, byte[] classData) { int i = name.lastIndexOf('.'); if (i != -1) { @@ -299,4 +303,12 @@ public class LaunchClassLoader extends URLClassLoader implements ClassNodeSource return INSTANCE = new LaunchClassLoader(getSystemClassLoader()); } + public URL getLocation(String className) { + try { + return loadClass(className).getProtectionDomain().getCodeSource().getLocation(); + } catch (Exception e) { + return null; + } + } + } diff --git a/src/main/java/org/mcphackers/launchwrapper/protocol/SkinRequests.java b/src/main/java/org/mcphackers/launchwrapper/protocol/SkinRequests.java index 4666cc6..0c0db30 100644 --- a/src/main/java/org/mcphackers/launchwrapper/protocol/SkinRequests.java +++ b/src/main/java/org/mcphackers/launchwrapper/protocol/SkinRequests.java @@ -3,6 +3,7 @@ package org.mcphackers.launchwrapper.protocol; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.InputStream; +import java.net.HttpURLConnection; import java.net.URL; import java.util.HashMap; @@ -36,7 +37,11 @@ public class SkinRequests { public static JSONObject requestUUIDfromName(String name) { try { URL profileURL = new URL("https://api.mojang.com/users/profiles/minecraft/" + name); - InputStream connStream = profileURL.openConnection().getInputStream(); + HttpURLConnection connection = (HttpURLConnection)profileURL.openConnection(); + if(connection.getResponseCode() == 404) { + return null; + } + InputStream connStream = connection.getInputStream(); JSONObject uuidJson = new JSONObject(new String(Util.readStream(connStream), "UTF-8")); return uuidJson; diff --git a/src/main/java/org/mcphackers/launchwrapper/tweak/LegacyTweak.java b/src/main/java/org/mcphackers/launchwrapper/tweak/LegacyTweak.java index 65af4f2..c3acb40 100644 --- a/src/main/java/org/mcphackers/launchwrapper/tweak/LegacyTweak.java +++ b/src/main/java/org/mcphackers/launchwrapper/tweak/LegacyTweak.java @@ -404,7 +404,7 @@ public class LegacyTweak extends Tweak { } private void displayPatch(MethodNode init, boolean supportsResizing) { - boolean foundTitle = false; // TODO + boolean foundTitle = false; this.classic = isClassic(); String canvasName = null; @@ -526,7 +526,6 @@ public class LegacyTweak extends Tweak { foundTitle = true; String value = (String) ldc.cst; if(launch.title.get() != null) { - // TODO replace title even if there isn't a setTitle call tweakInfo("Replaced title"); ldc.cst = launch.title.get(); } else if(value.startsWith("Minecraft Minecraft")) { @@ -553,6 +552,10 @@ public class LegacyTweak extends Tweak { insn = nextInsn(insn); } + if(!foundTitle && launch.title.get() != null) { + //TODO + } + if(afterLabel != null && iLabel != null && oLabel != null @@ -1258,7 +1261,7 @@ public class LegacyTweak extends Tweak { return node; } - private boolean patchAppletInit() { + protected boolean patchAppletInit() { if(minecraftApplet == null) { return false; } diff --git a/src/main/java/org/mcphackers/launchwrapper/util/ClassNodeSource.java b/src/main/java/org/mcphackers/launchwrapper/util/ClassNodeSource.java index 357e27d..d97518a 100644 --- a/src/main/java/org/mcphackers/launchwrapper/util/ClassNodeSource.java +++ b/src/main/java/org/mcphackers/launchwrapper/util/ClassNodeSource.java @@ -1,5 +1,7 @@ package org.mcphackers.launchwrapper.util; +import java.net.URL; + import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.FieldNode; import org.objectweb.asm.tree.MethodNode; @@ -13,5 +15,7 @@ public interface ClassNodeSource { MethodNode getMethod(String owner, String name, String desc); void overrideClass(ClassNode node); + + URL getLocation(String className); } diff --git a/src/main/java/org/mcphackers/launchwrapper/util/OS.java b/src/main/java/org/mcphackers/launchwrapper/util/OS.java new file mode 100644 index 0000000..1e45d51 --- /dev/null +++ b/src/main/java/org/mcphackers/launchwrapper/util/OS.java @@ -0,0 +1,28 @@ +package org.mcphackers.launchwrapper.util; + +public enum OS { + LINUX, + SOLARIS, + WINDOWS, + OSX, + UNKNOWN; + + public static OS os; + + + public static OS getOs() { + if(os != null) { + return os; + } + String s = System.getProperty("os.name").toLowerCase(); + os + = s.contains("win") ? OS.WINDOWS + : s.contains("mac") ? OS.OSX + : s.contains("solaris") ? OS.SOLARIS + : s.contains("sunos") ? OS.SOLARIS + : s.contains("linux") ? OS.LINUX + : s.contains("unix") ? OS.LINUX + : OS.UNKNOWN; + return os; + } +} \ No newline at end of file