52 lines
1.6 KiB
Java
52 lines
1.6 KiB
Java
|
package site.hackery.unknit.mixin;
|
||
|
|
||
|
|
||
|
import net.minecraft.client.main.Main;
|
||
|
import net.minecraft.client.util.Session;
|
||
|
import org.spongepowered.asm.mixin.Mixin;
|
||
|
import org.spongepowered.asm.mixin.injection.At;
|
||
|
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||
|
import site.hackery.unknit.auth.GameAuthenticationFlow;
|
||
|
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.Arrays;
|
||
|
import java.util.List;
|
||
|
|
||
|
@Mixin(Main.class)
|
||
|
public abstract class MixinMinecraftMain {
|
||
|
private static void replace(List<String> arguments, String tag, String value) {
|
||
|
int index = arguments.indexOf(tag);
|
||
|
if (index != -1) {
|
||
|
arguments.set(index + 1, value);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private static void replaceVersion(List<String> arguments) {
|
||
|
replace(arguments, "--version", "1.18.1");
|
||
|
replace(arguments, "--versionType", "release");
|
||
|
}
|
||
|
|
||
|
private static void replaceSession(List<String> arguments, Session session) {
|
||
|
replace(arguments, "--accessToken", session.getAccessToken());
|
||
|
|
||
|
arguments.add("--username");
|
||
|
arguments.add(session.getUsername());
|
||
|
|
||
|
arguments.add("--uuid");
|
||
|
arguments.add(session.getUuid());
|
||
|
}
|
||
|
|
||
|
@ModifyVariable(method = "main", at = @At("HEAD"), argsOnly = true, remap = false)
|
||
|
private static String[] setArgs(String[] args) {
|
||
|
List<String> arguments = new ArrayList<>(Arrays.asList(args));
|
||
|
replaceVersion(arguments);
|
||
|
|
||
|
Session session = GameAuthenticationFlow.createSessionFromEnvironment();
|
||
|
if (session != null) {
|
||
|
replaceSession(arguments, session);
|
||
|
}
|
||
|
|
||
|
return arguments.toArray(new String[0]);
|
||
|
}
|
||
|
}
|