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

Commit a61f5db

Browse files
committed
Introduce SimpleTweaker
1 parent 8bafeba commit a61f5db

File tree

11 files changed

+41
-448
lines changed

11 files changed

+41
-448
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ repositories {
8484

8585
dependencies {
8686
compile "com.github.ZeroMemes:Alpine:${project.alpineVersion}"
87+
compile "com.github.ImpactDevelopment:SimpleTweaker:${project.simpleTweakerVersion}"
8788
compile "net.jodah:typetools:${project.typetoolsVersion}"
8889
compile("org.spongepowered:mixin:${project.mixinVersion}") {
8990
// Mixin includes a lot of dependencies that are too up-to-date

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ mixinVersion = 0.7.11-SNAPSHOT
3232
alpineVersion = 1.8
3333
typetoolsVersion = 0.5.0
3434
featherVersion = 1.0
35+
simpleTweakerVersion = 1.0
3536

3637
# Testing dependency versions
3738
junitVersion = 4.12

src/main/java/clientapi/config/ClientConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
package clientapi.config;
1818

1919
import clientapi.Client;
20-
import clientapi.load.transform.ITransformer;
2120
import com.google.gson.annotations.SerializedName;
21+
import io.github.impactdevelopment.simpletweaker.transform.ITransformer;
2222

2323
/**
2424
* Representation of the {@code client.json} format.

src/main/java/clientapi/load/ClientTransformer.java

Lines changed: 0 additions & 130 deletions
This file was deleted.

src/main/java/clientapi/load/ClientTweaker.java

Lines changed: 25 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
import clientapi.ClientAPI;
2020
import clientapi.config.ClientConfiguration;
2121
import clientapi.config.JsonConfiguration;
22-
import clientapi.load.argument.Argument;
23-
import clientapi.load.argument.Arguments;
24-
import net.minecraft.launchwrapper.ITweaker;
22+
import clientapi.load.transform.impl.ValueAccessorTransformer;
23+
import io.github.impactdevelopment.simpletweaker.SimpleTweaker;
24+
import io.github.impactdevelopment.simpletweaker.transform.SimpleTransformer;
2525
import net.minecraft.launchwrapper.Launch;
2626
import net.minecraft.launchwrapper.LaunchClassLoader;
2727
import org.apache.logging.log4j.Level;
@@ -30,9 +30,7 @@
3030
import org.spongepowered.asm.mixin.Mixins;
3131
import org.spongepowered.tools.obfuscation.mcp.ObfuscationServiceMCP;
3232

33-
import java.io.File;
3433
import java.io.InputStream;
35-
import java.util.ArrayList;
3634
import java.util.List;
3735

3836
/**
@@ -41,34 +39,19 @@
4139
* @author Brady
4240
* @since 1/20/2017
4341
*/
44-
public final class ClientTweaker implements ITweaker {
45-
46-
/**
47-
* The raw game launch arguments that are provided in {@link ClientTweaker#acceptOptions(List, File, File, String)}
48-
*/
49-
private List<String> args;
50-
51-
@Override
52-
public void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) {
53-
(this.args = new ArrayList<>()).addAll(args);
54-
addArg("gameDir", gameDir);
55-
addArg("assetsDir", assetsDir);
56-
addArg("version", profile);
57-
}
42+
public final class ClientTweaker extends SimpleTweaker {
5843

5944
@Override
6045
public void injectIntoClassLoader(LaunchClassLoader classLoader) {
46+
super.injectIntoClassLoader(classLoader);
47+
6148
ClientAPI.LOGGER.log(Level.INFO, "Injecting into ClassLoader");
6249

6350
this.setupMixin();
6451

6552
ClientConfiguration config = findClientConfig();
6653

67-
// Load bytecode transformers
68-
classLoader.registerTransformer(ClientTransformer.class.getName());
69-
ClientTransformer.getInstance().registerAll(config.getTransformers());
70-
71-
ClientAPI.LOGGER.log(Level.INFO, "Registered Bytecode Transformes");
54+
this.setupTransformers(config);
7255

7356
// Load mixin configs
7457
loadMixinConfig("mixins.capi.json");
@@ -85,38 +68,39 @@ public final String getLaunchTarget() {
8568
return "net.minecraft.client.main.Main";
8669
}
8770

88-
@Override
8971
@SuppressWarnings("unchecked")
90-
public final String[] getLaunchArguments() {
91-
// Parse the arguments that we are able to pass to the game
92-
List<Argument> parsed = Arguments.parse(this.args);
93-
94-
// Parse the arguments that are already being passed to the game
95-
List<Argument> existing = Arguments.parse((List<String>) Launch.blackboard.get("ArgumentList"));
96-
97-
// Remove any arguments that conflict with existing ones
98-
parsed.removeIf(argument -> existing.stream().anyMatch(a -> a.conflicts(argument)));
99-
100-
// Join back the filtered arguments and pass those to the game
101-
return Arguments.join(parsed).toArray(new String[0]);
102-
}
103-
10472
private void setupMixin() {
10573
MixinBootstrap.init();
10674
ClientAPI.LOGGER.log(Level.INFO, "Initialized Mixin bootstrap");
10775

76+
// Find all of the other tweakers that are being loaded
77+
List<String> tweakClasses = (List<String>) Launch.blackboard.get("TweakClasses");
78+
79+
// Default to NOTCH obfuscation context
10880
String obfuscation = ObfuscationServiceMCP.NOTCH;
10981

110-
// If there are any transformers that have "fml" in their class name, then use the searge obfuscation context
111-
if (Launch.classLoader.getTransformers().stream().anyMatch(t -> t.getClass().getName().contains("fml"))) {
82+
// If there are any tweak classes that contain "FMLTweaker", then set the obfuscation context to SEARGE
83+
if (tweakClasses.stream().anyMatch(s -> s.contains("FMLTweaker"))) {
11284
obfuscation = ObfuscationServiceMCP.SEARGE;
85+
ClientAPI.LOGGER.log(Level.INFO, "Discovered FML! Switching to SEARGE mappings.");
11386
}
11487

11588
MixinEnvironment.getDefaultEnvironment().setSide(MixinEnvironment.Side.CLIENT);
11689
MixinEnvironment.getDefaultEnvironment().setObfuscationContext(obfuscation);
11790
ClientAPI.LOGGER.log(Level.INFO, "Setup Mixin Environment");
11891
}
11992

93+
private void setupTransformers(ClientConfiguration config) {
94+
SimpleTransformer transformer = SimpleTransformer.getInstance();
95+
96+
if (!Boolean.valueOf(System.getProperty("clientapi.load.devMode", "false")))
97+
transformer.registerAll(new ValueAccessorTransformer());
98+
99+
transformer.registerAll(config.getTransformers());
100+
101+
ClientAPI.LOGGER.log(Level.INFO, "Registered Bytecode Transformes");
102+
}
103+
120104
private ClientConfiguration findClientConfig() {
121105
InputStream stream;
122106
if ((stream = this.getClass().getResourceAsStream("/client.json")) == null)
@@ -132,16 +116,4 @@ private void loadMixinConfig(String config) {
132116

133117
Mixins.addConfiguration(config);
134118
}
135-
136-
private void addArg(String label, File file) {
137-
if (file != null)
138-
addArg(label, file.getAbsolutePath());
139-
}
140-
141-
private void addArg(String label, String value) {
142-
if (!args.contains("--" + label) && value != null) {
143-
this.args.add("--" + label);
144-
this.args.add(value);
145-
}
146-
}
147119
}

src/main/java/clientapi/load/argument/Argument.java

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)