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 args, File gameDir, File assetsDir, String version) { boolean isRelaunch = false; // is this invocation from a relaunch? String uuid = null; ArrayList argsCopy = new ArrayList<>(args); for (int i = 0; i < argsCopy.size(); i++) { if (argsCopy.get(i).equals("--accessToken")) { if (argsCopy.get(i + 1).equals("")) { isRelaunch = true; continue; } argsCopy.set(i + 1, ""); } 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]; } }