aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gq/malwarefight/nosession/tweaks
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/gq/malwarefight/nosession/tweaks')
-rw-r--r--src/main/java/gq/malwarefight/nosession/tweaks/cleanup/CleanupTweaker.java83
-rw-r--r--src/main/java/gq/malwarefight/nosession/tweaks/cleanup/package-info.java5
-rw-r--r--src/main/java/gq/malwarefight/nosession/tweaks/initial/InitialTweaker.java97
-rw-r--r--src/main/java/gq/malwarefight/nosession/tweaks/initial/package-info.java5
4 files changed, 190 insertions, 0 deletions
diff --git a/src/main/java/gq/malwarefight/nosession/tweaks/cleanup/CleanupTweaker.java b/src/main/java/gq/malwarefight/nosession/tweaks/cleanup/CleanupTweaker.java
new file mode 100644
index 0000000..a0d458b
--- /dev/null
+++ b/src/main/java/gq/malwarefight/nosession/tweaks/cleanup/CleanupTweaker.java
@@ -0,0 +1,83 @@
+package gq.malwarefight.nosession.tweaks.cleanup;
+
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import net.minecraft.launchwrapper.ITweaker;
+import net.minecraft.launchwrapper.Launch;
+import net.minecraft.launchwrapper.LaunchClassLoader;
+import net.minecraftforge.fml.common.asm.ASMTransformerWrapper;
+
+import java.io.File;
+import java.lang.reflect.*;
+import java.net.URL;
+import java.net.URLStreamHandler;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import gq.malwarefight.nosession.utils.Utils;
+
+public class CleanupTweaker implements ITweaker {
+ /**
+ * Cached to avoid expensive reflection operations
+ */
+ public Method makeWrapper;
+
+ public CleanupTweaker() throws NoSuchMethodException {
+ makeWrapper = ASMTransformerWrapper.class.getDeclaredMethod("makeWrapper", String.class);
+ makeWrapper.setAccessible(true);
+ }
+ @Override
+ @SuppressWarnings("unchecked")
+ public void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) {
+ // add the FMLTweaker
+ ArrayList<String> tweakerList = (ArrayList<String>) Launch.blackboard.get("TweakClasses");
+ tweakerList.add("net.minecraftforge.fml.common.launcher.FMLTweaker");
+ // reset ASMTransformerWrapper
+ Class<ASMTransformerWrapper> cls = ASMTransformerWrapper.class;
+ try {
+ Utils.setStaticValue(cls, "wrapperModMap", new HashMap<String, String>());
+ Utils.setStaticValue(cls, "wrapperParentMap", new HashMap<String, String>());
+ //noinspection UnstableApiUsage
+ Utils.setStaticValue(cls, "wrapperCache", CacheBuilder.newBuilder().maximumSize(30L).weakValues().build(new CacheLoader<String, byte[]>() {
+ public byte[] load(String file) throws Exception {
+ return (byte[]) makeWrapper.invoke(null, file);
+ }
+ }));
+ Utils.setStaticValue(cls, "asmGenRoot", new URL("asmgen", null, -1, "/", getAsmGenHandler()));
+ Utils.setStaticValue(cls, "injected", false);
+ } catch (Exception e) {
+ System.err.println("NoSession: Fixing ASMTransformerWrapper failed. Things may break.");
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void injectIntoClassLoader(LaunchClassLoader classLoader) {}
+
+ @Override
+ public String getLaunchTarget() {
+ return "net.minecraft.client.main.Main";
+ }
+
+ @Override
+ public String[] getLaunchArguments() {
+ return new String[0];
+ }
+
+
+
+ @SuppressWarnings("unchecked")
+ private URLStreamHandler getAsmGenHandler() throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
+ Class<ASMTransformerWrapper> cls = ASMTransformerWrapper.class;
+ for (Class<?> candidate: cls.getDeclaredClasses()) {
+ if (candidate.getSimpleName().equals("ASMGenHandler")) {
+ Method pgdc = Class.class.getDeclaredMethod("privateGetDeclaredConstructors", boolean.class);
+ pgdc.setAccessible(true);
+ Constructor<? extends URLStreamHandler> constructor = ((Constructor<? extends URLStreamHandler>[]) pgdc.invoke(candidate, false))[0];
+ constructor.setAccessible(true);
+ return constructor.newInstance();
+ }
+ }
+ throw new RuntimeException("NoSession: unable to get the ASMGenHandler");
+ }
+}
diff --git a/src/main/java/gq/malwarefight/nosession/tweaks/cleanup/package-info.java b/src/main/java/gq/malwarefight/nosession/tweaks/cleanup/package-info.java
new file mode 100644
index 0000000..c2a48ea
--- /dev/null
+++ b/src/main/java/gq/malwarefight/nosession/tweaks/cleanup/package-info.java
@@ -0,0 +1,5 @@
+/**
+ * Due to the launchwrapper using a launchclassloader exclusion on every tweaker's package, we separate the two tweakers
+ * so that the loader exclusion doesn't affect anything else
+ */
+package gq.malwarefight.nosession.tweaks.cleanup; \ No newline at end of file
diff --git a/src/main/java/gq/malwarefight/nosession/tweaks/initial/InitialTweaker.java b/src/main/java/gq/malwarefight/nosession/tweaks/initial/InitialTweaker.java
new file mode 100644
index 0000000..0baee07
--- /dev/null
+++ b/src/main/java/gq/malwarefight/nosession/tweaks/initial/InitialTweaker.java
@@ -0,0 +1,97 @@
+package gq.malwarefight.nosession.tweaks.initial;
+
+import gq.malwarefight.nosession.utils.Utils;
+import java.io.File;
+import java.net.Socket;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+import net.minecraft.launchwrapper.ITweaker;
+import net.minecraft.launchwrapper.LaunchClassLoader;
+import org.spongepowered.asm.launch.MixinBootstrap;
+import org.spongepowered.asm.mixin.MixinEnvironment;
+import org.spongepowered.asm.mixin.Mixins;
+
+public class InitialTweaker implements ITweaker {
+
+ public InitialTweaker() {
+ System.gc(); // try to garbage collect the earlier launch data
+ }
+
+ /**
+ * This handles the launch arguments passed towards minecraft
+ * @param args The launch arguments
+ * @param gameDir The game directory (ie: .minecraft)
+ * @param assetsDir The assets directory
+ * @param version The game version
+ */
+ @Override
+ public final void acceptOptions(List<String> args, File gameDir, File assetsDir, String version) {
+ boolean isRelaunch = false; // is this invocation from a relaunch?
+ String uuid = null;
+ ArrayList<String> argsCopy = new ArrayList<>(args);
+ for (int i = 0; i < argsCopy.size(); i++) {
+ if (argsCopy.get(i).equals("--accessToken")) {
+ if (argsCopy.get(i + 1).equals("<noSessionAccessToken>")) {
+ isRelaunch = true;
+ }
+ try {
+ Utils.setToken(args.get(i + 1));
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ argsCopy.set(i + 1, "<noSessionAccessToken>");
+ } else if (argsCopy.get(i).equals("--uuid")) {
+ uuid = argsCopy.get(i + 1);
+ }
+ }
+ if (isRelaunch) {
+ String finalUUID = uuid;
+ if (finalUUID == null) {
+ return; // if we don't have a uuid, quit
+ }
+ Runtime.getRuntime().addShutdownHook(
+ new Thread(() -> {
+ try {
+ Socket socket = Utils.getProperSocket(UUID.fromString(Utils.normalizeUUID(finalUUID)));
+ socket.getOutputStream().write("fullquit\n".getBytes(StandardCharsets.UTF_8));
+ socket.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ })
+ );
+ return; // don't do anything, the change has already been made
+ }
+ throw new RuntimeException("It should be impossible to get here! Report this bug to https://github.com/thefightagainstmalware/NoSession");
+ }
+
+ /**
+ * Inject into the MC class loader
+ * @param classLoader The class loader
+ */
+ @Override
+ public final void injectIntoClassLoader(LaunchClassLoader classLoader) {
+ MixinBootstrap.init();
+ MixinEnvironment environment = MixinEnvironment.getDefaultEnvironment();
+ Mixins.addConfiguration("mixins.nosession.json");
+ // Check if the obfuscation context is null
+ if (environment.getObfuscationContext() == null) {
+ environment.setObfuscationContext("notch");
+ }
+ // This is a client side, client :)
+ environment.setSide(MixinEnvironment.Side.CLIENT);
+ }
+
+ @Override
+ public String getLaunchTarget() {
+ return MixinBootstrap.getPlatform().getLaunchTarget();
+ }
+
+ @Override
+ public String[] getLaunchArguments() {
+ return new String[0];
+ }
+
+}
diff --git a/src/main/java/gq/malwarefight/nosession/tweaks/initial/package-info.java b/src/main/java/gq/malwarefight/nosession/tweaks/initial/package-info.java
new file mode 100644
index 0000000..443e379
--- /dev/null
+++ b/src/main/java/gq/malwarefight/nosession/tweaks/initial/package-info.java
@@ -0,0 +1,5 @@
+/**
+ * Due to the launchwrapper using a launchclassloader exclusion on every tweaker's package, we separate the two tweakers
+ * so that the loader exclusion doesn't affect anything else
+ */
+package gq.malwarefight.nosession.tweaks.initial; \ No newline at end of file