78 lines
2.9 KiB
Java
78 lines
2.9 KiB
Java
package site.hackery.unknit;
|
|
|
|
|
|
import com.mojang.authlib.*;
|
|
import com.mojang.authlib.exceptions.*;
|
|
import com.mojang.authlib.yggdrasil.*;
|
|
import com.mojang.util.*;
|
|
import net.minecraft.client.main.*;
|
|
import net.minecraft.client.util.*;
|
|
import org.spongepowered.asm.mixin.*;
|
|
import org.spongepowered.asm.mixin.injection.*;
|
|
|
|
import java.io.*;
|
|
import java.net.*;
|
|
import java.nio.file.*;
|
|
import java.util.*;
|
|
|
|
@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);
|
|
}
|
|
}
|
|
|
|
@ModifyVariable(method = "main", at = @At("HEAD"), argsOnly = true)
|
|
private static String[] setArgs(String[] args) {
|
|
List<String> arguments = new ArrayList<>(Arrays.asList(args));
|
|
replace(arguments, "--version", "1.18.1");
|
|
replace(arguments, "--versionType", "release");
|
|
|
|
try {
|
|
String authFile = System.getenv("LOGIN_FILE");
|
|
authFile = authFile == null ? "lastlogin.txt" : authFile;
|
|
|
|
List<String> loginDetails = Files.readAllLines(Paths.get(authFile));
|
|
if (loginDetails.size() >= 2) {
|
|
Session session = getAuthenticatedSession(loginDetails.get(0), loginDetails.get(1));
|
|
replace(arguments, "--accessToken", session.getAccessToken());
|
|
|
|
arguments.add("--username");
|
|
arguments.add(session.getUsername());
|
|
|
|
arguments.add("--uuid");
|
|
arguments.add(session.getUuid());
|
|
}
|
|
} catch (AuthenticationException | IOException ignored) {
|
|
}
|
|
|
|
return arguments.toArray(new String[0]);
|
|
}
|
|
|
|
private static Session getAuthenticatedSession(String username, String password) throws AuthenticationException {
|
|
YggdrasilUserAuthentication yggdrasilUserAuthentication = constructUserAuthentication(username, password);
|
|
yggdrasilUserAuthentication.logIn();
|
|
|
|
GameProfile selectedProfile = yggdrasilUserAuthentication.getSelectedProfile();
|
|
|
|
return new Session(
|
|
selectedProfile.getName(),
|
|
UUIDTypeAdapter.fromUUID(selectedProfile.getId()),
|
|
yggdrasilUserAuthentication.getAuthenticatedToken(),
|
|
Optional.empty(),
|
|
Optional.empty(),
|
|
Session.AccountType.LEGACY // Why legacy?
|
|
);
|
|
}
|
|
|
|
private static YggdrasilUserAuthentication constructUserAuthentication(String username, String password) {
|
|
YggdrasilUserAuthentication yggdrasilUserAuthentication = (YggdrasilUserAuthentication) new YggdrasilAuthenticationService(Proxy.NO_PROXY, "my epic client token").createUserAuthentication(Agent.MINECRAFT);
|
|
yggdrasilUserAuthentication.setUsername(username);
|
|
yggdrasilUserAuthentication.setPassword(password);
|
|
|
|
return yggdrasilUserAuthentication;
|
|
}
|
|
}
|