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

Commit 4ab18fa

Browse files
committed
Support all environments in one tweaker
1 parent 844d10e commit 4ab18fa

6 files changed

Lines changed: 184 additions & 64 deletions

File tree

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
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;
2224
import net.minecraft.launchwrapper.ITweaker;
25+
import net.minecraft.launchwrapper.Launch;
2326
import net.minecraft.launchwrapper.LaunchClassLoader;
2427
import org.apache.logging.log4j.Level;
2528
import org.spongepowered.asm.launch.MixinBootstrap;
@@ -43,7 +46,7 @@ public class ClientTweaker implements ITweaker {
4346
/**
4447
* The Game Launch Arguments
4548
*/
46-
List<String> args;
49+
private List<String> args;
4750

4851
@Override
4952
public void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) {
@@ -61,7 +64,14 @@ public void injectIntoClassLoader(LaunchClassLoader classLoader) {
6164
ClientAPI.LOGGER.log(Level.INFO, "Initialized Mixin bootstrap");
6265

6366
MixinEnvironment.getDefaultEnvironment().setSide(MixinEnvironment.Side.CLIENT);
64-
MixinEnvironment.getDefaultEnvironment().setObfuscationContext(ObfuscationServiceMCP.NOTCH);
67+
68+
String obfuscation = ObfuscationServiceMCP.NOTCH;
69+
if (Launch.classLoader.getTransformers().stream().noneMatch(t -> t.getClass().getName().contains("fml"))) {
70+
obfuscation = ObfuscationServiceMCP.SEARGE;
71+
}
72+
73+
MixinEnvironment.getDefaultEnvironment().setObfuscationContext(obfuscation);
74+
6575
ClientAPI.LOGGER.log(Level.INFO, "Setup Mixin Environment");
6676

6777
ClientConfiguration config = findClientConfig();
@@ -88,8 +98,19 @@ public final String getLaunchTarget() {
8898
}
8999

90100
@Override
101+
@SuppressWarnings("unchecked")
91102
public final String[] getLaunchArguments() {
92-
return this.args.toArray(new String[0]);
103+
// Parse the arguments that we are able to pass to the game
104+
List<Argument> parsed = Arguments.parse(this.args);
105+
106+
// Parse the arguments that are already being passed to the game
107+
List<Argument> existing = Arguments.parse((List<String>) Launch.blackboard.get("ArgumentList"));
108+
109+
// Remove any arguments that match already existing ones
110+
parsed.removeIf(argument -> existing.stream().anyMatch(a -> a.matches(argument)));
111+
112+
// Join back the filtered arguments and pass those to the game
113+
return Arguments.join(parsed).toArray(new String[0]);
93114
}
94115

95116
private ClientConfiguration findClientConfig() {

src/main/java/clientapi/load/ClientTweakerForge.java

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

src/main/java/clientapi/load/ClientTweakerOptifine.java renamed to src/main/java/clientapi/load/argument/Argument.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,17 @@
1414
* limitations under the License.
1515
*/
1616

17-
package clientapi.load;
17+
package clientapi.load.argument;
1818

19-
import java.io.File;
20-
import java.util.ArrayList;
2119
import java.util.List;
2220

2321
/**
24-
* Implementation of ClientTweaker that leaves the argument list alone
25-
* so that optifine's tweaker does not cause any conflictions.
26-
*
2722
* @author Brady
28-
* @since 2/21/2018
23+
* @since 10/9/2018
2924
*/
30-
public final class ClientTweakerOptifine extends ClientTweaker {
25+
public interface Argument {
26+
27+
void addToList(List<String> arguments);
3128

32-
@Override
33-
public final void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) {
34-
this.args = new ArrayList<>();
35-
}
29+
boolean matches(Argument argument);
3630
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright 2018 ImpactDevelopment
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package clientapi.load.argument;
18+
19+
import java.util.ArrayList;
20+
import java.util.List;
21+
22+
/**
23+
* @author Brady
24+
* @since 10/9/2018
25+
*/
26+
public final class Arguments {
27+
28+
public static List<Argument> parse(List<String> args) {
29+
List<Argument> argsOut = new ArrayList<>();
30+
31+
String classifier = null;
32+
33+
for (String arg : args) {
34+
if (arg.startsWith("-")) {
35+
if (classifier != null) {
36+
argsOut.add(new ClassifiedArgument(classifier, ""));
37+
classifier = null;
38+
} else if (arg.contains("=")) {
39+
argsOut.add(new ClassifiedArgument(arg.substring(0, arg.indexOf('=')), arg.substring(arg.indexOf('=') + 1)));
40+
} else {
41+
classifier = arg;
42+
}
43+
} else {
44+
if (classifier != null) {
45+
argsOut.add(new ClassifiedArgument(classifier, arg));
46+
classifier = null;
47+
} else {
48+
argsOut.add(new SingularArgument(arg));
49+
}
50+
}
51+
}
52+
53+
return argsOut;
54+
}
55+
56+
public static List<String> join(List<Argument> args) {
57+
List<String> argsOut = new ArrayList<>();
58+
args.forEach(argument -> argument.addToList(argsOut));
59+
return argsOut;
60+
}
61+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2018 ImpactDevelopment
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package clientapi.load.argument;
18+
19+
import java.util.List;
20+
21+
/**
22+
* @author Brady
23+
* @since 10/9/2018
24+
*/
25+
public final class ClassifiedArgument implements Argument {
26+
27+
private final String classifier;
28+
private final String value;
29+
30+
public ClassifiedArgument(String classifier, String value) {
31+
this.classifier = classifier;
32+
this.value = value;
33+
}
34+
35+
@Override
36+
public final void addToList(List<String> arguments) {
37+
arguments.add(classifier);
38+
arguments.add(value);
39+
}
40+
41+
@Override
42+
public final boolean matches(Argument argument) {
43+
if (!(argument instanceof ClassifiedArgument))
44+
return false;
45+
46+
return ((ClassifiedArgument) argument).classifier.equals(this.classifier);
47+
}
48+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2018 ImpactDevelopment
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package clientapi.load.argument;
18+
19+
import java.util.List;
20+
21+
/**
22+
* @author Brady
23+
* @since 10/9/2018
24+
*/
25+
public final class SingularArgument implements Argument {
26+
27+
private final String value;
28+
29+
public SingularArgument(String value) {
30+
this.value = value;
31+
}
32+
33+
@Override
34+
public final void addToList(List<String> arguments) {
35+
arguments.add(this.value);
36+
}
37+
38+
@Override
39+
public final boolean matches(Argument argument) {
40+
if (!(argument instanceof SingularArgument))
41+
return false;
42+
43+
return ((SingularArgument) argument).value.equals(this.value);
44+
}
45+
}

0 commit comments

Comments
 (0)