Skip to content
This repository was archived by the owner on Oct 29, 2019. It is now read-only.

Commit fb12f54

Browse files
committed
Patching launchwrapperTM
1 parent e3b3b1e commit fb12f54

File tree

3 files changed

+60
-5
lines changed

3 files changed

+60
-5
lines changed

pom.xml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>cc.hyperium.installer</groupId>
88
<artifactId>Installer</artifactId>
9-
<version>1.2</version>
9+
<version>1.3</version>
1010

1111
<properties>
1212
<kotlin.version>1.2.50</kotlin.version>
@@ -129,6 +129,18 @@
129129
<artifactId>guava</artifactId>
130130
<version>17.0</version>
131131
</dependency>
132+
<dependency>
133+
<groupId>com.github.Cubxity</groupId>
134+
<artifactId>LaunchWrapperPatcher</artifactId>
135+
<version>81f509b36c</version>
136+
</dependency>
132137
</dependencies>
133138

139+
<repositories>
140+
<repository>
141+
<id>jitpack.io</id>
142+
<url>https://jitpack.io</url>
143+
</repository>
144+
</repositories>
145+
134146
</project>

src/main/java/cc/hyperium/installer/api/Installer.java

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.google.common.io.Files;
1515
import com.google.gson.JsonArray;
1616
import com.google.gson.JsonPrimitive;
17+
import me.cubxity.asm.LaunchWrapperPatcher;
1718
import org.apache.commons.io.FileUtils;
1819

1920
import java.io.File;
@@ -32,7 +33,7 @@
3233
* Created by Cubxity on 06/07/2018
3334
*/
3435
public class Installer {
35-
public static final int API_VERSION = 1;
36+
public static final int API_VERSION = 2;
3637

3738
private final InstallerConfig config;
3839

@@ -257,6 +258,34 @@ public void install() {
257258
return;
258259
}
259260

261+
File launchWrapper = new File(libraries, "net" + sep + "minecraft" + sep + "launchwrapper" + sep + "1.7" + sep + "launchwrapper-1.7.jar");
262+
launchWrapper.getParentFile().mkdirs();
263+
if (!launchWrapper.exists()) {
264+
phrase = Phrase.DOWNLOAD_LAUNCHER;
265+
try {
266+
DownloadTask dl = new DownloadTask("https://libraries.minecraft.net/net/minecraft/launchwrapper/1.7/launchwrapper-1.7.jar", launchWrapper.getParentFile().getAbsolutePath());
267+
dl.addPropertyChangeListener(evt -> {
268+
if (evt.getNewValue() instanceof Integer)
269+
callback.accept(new StatusCallback(Phrase.DOWNLOAD_COMPONENTS, "Downloading LaunchWrapper (" + evt.getNewValue() + "%)", null));
270+
});
271+
dl.execute();
272+
dl.get();
273+
} catch (Exception ex) {
274+
callback.accept(new ErrorCallback(ex, phrase, "Failed to download LaunchWrapper, " + ex.getMessage()));
275+
return;
276+
}
277+
}
278+
279+
File customLaunchWrapper = new File(launchWrapper.getParentFile().getParentFile(), "Hyperium" + sep + "launchwrapper-Hyperium.jar");
280+
customLaunchWrapper.getParentFile().mkdir();
281+
phrase = Phrase.PATCH_LAUNCHER;
282+
try {
283+
LaunchWrapperPatcher.patch(launchWrapper, "cc/hyperium/utils/CrashHandler", "handle", "(Ljava/lang/Exception;)V", customLaunchWrapper);
284+
} catch (Exception ex) {
285+
callback.accept(new ErrorCallback(ex, phrase, "Failed to patch LaunchWrapper: " + ex.getMessage()));
286+
return;
287+
}
288+
260289
phrase = Phrase.CREATE_PROFILE;
261290
callback.accept(new StatusCallback(phrase, "Creating profile", null));
262291
if (mmc) {
@@ -350,7 +379,8 @@ public void install() {
350379
);
351380
libs.add(
352381
new JsonHolder()
353-
.put("name", "net.minecraft:launchwrapper:1.7")
382+
.put("name", "net.minecraft:launchwrapper:Hyperium")
383+
.put("MMC-hint", "local")
354384
.getObject()
355385
);
356386
if (of)
@@ -397,7 +427,7 @@ public void install() {
397427
lib.put("name", config.getVersion().getName().equals("LOCAL") ? "cc.hyperium:Hyperium:LOCAL" : config.getVersion().getArtifactId());
398428
JsonArray libs = json.optJSONArray("libraries");
399429
libs.add(lib.getObject());
400-
libs.add(new JsonHolder().put("name", "net.minecraft:launchwrapper:1.7").getObject());
430+
libs.add(new JsonHolder().put("name", "net.minecraft:launchwrapper:Hyperium").getObject());
401431
if (of)
402432
libs.add(new JsonHolder().put("name", "optifine:OptiFine:1.8.9_HD_U_I7").getObject());
403433
json.put("libraries", libs);

src/main/java/cc/hyperium/installer/api/callbacks/Phrase.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,25 @@ public enum Phrase {
4545
*/
4646
PATCH_OPTIFINE,
4747

48+
/**
49+
* @since 1.3
50+
*
51+
* When it's downloading launchwrapper
52+
*/
53+
DOWNLOAD_LAUNCHER,
54+
55+
/**
56+
* @since 1.3
57+
*
58+
* When it's patching launchwrapper
59+
*/
60+
PATCH_LAUNCHER,
61+
4862
/**
4963
* When it's creating launcher profile
5064
*/
5165
CREATE_PROFILE,
5266

53-
5467
/**
5568
* When installation has finished
5669
*/

0 commit comments

Comments
 (0)