Fix Reflections

Dieser Commit ist enthalten in:
Chaoscaot 2022-09-24 01:08:14 +02:00
Ursprung 95ffafafe9
Commit 97ed2addd3
2 geänderte Dateien mit 11 neuen und 17 gelöschten Zeilen

Datei anzeigen

@ -31,6 +31,10 @@ dependencies {
}
modCompileOnlyApi "com.terraformersmc:modmenu:4.0.6"
compileOnly project(":common")
// Used to Override 'private final'
implementation 'org.jooq:joor:0.9.14'
include 'org.jooq:joor:0.9.14'
}
processResources {

Datei anzeigen

@ -1,13 +1,12 @@
package de.chaoscaot.altauth.mixin.client;
import com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService;
import com.mojang.authlib.yggdrasil.YggdrasilEnvironment;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.ConnectScreen;
import net.minecraft.client.network.ClientLoginNetworkHandler;
import net.minecraft.network.packet.s2c.login.LoginHelloS2CPacket;
import net.minecraft.text.Text;
import org.joor.Reflect;
import org.slf4j.Logger;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
@ -16,7 +15,6 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.lang.reflect.Field;
import java.net.URL;
@Environment(EnvType.CLIENT)
@ -24,28 +22,20 @@ import java.net.URL;
public class LoginRequestMixin {
@Shadow @Final private static Logger LOGGER;
private static final Class<YggdrasilMinecraftSessionService> YGGDRASIL_MINECRAFT_SESSION_SERVICE_CLASS = YggdrasilMinecraftSessionService.class;
private static final Field YGGDRASIL_MINECRAFT_SESSION_SERVICE_JOIN_URL;
static {
try {
YGGDRASIL_MINECRAFT_SESSION_SERVICE_JOIN_URL = YGGDRASIL_MINECRAFT_SESSION_SERVICE_CLASS.getDeclaredField("joinUrl");
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
}
}
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/network/packet/s2c/login/LoginHelloS2CPacket;getServerId()Ljava/lang/String;"), method = "onHello")
public void onHello(LoginHelloS2CPacket packet, CallbackInfo ci) {
try {
if(packet.getServerId().contains(".")) {
LOGGER.info("AltauthClient: LoginRequestMixin: Server is running on a custom: {}", packet.getServerId());
YGGDRASIL_MINECRAFT_SESSION_SERVICE_JOIN_URL.set(MinecraftClient.getInstance().getSessionService(), new URL("https://" + packet.getServerId() + "/session/minecraft/join"));
URL url = new URL("https://" + packet.getServerId() + "/session/minecraft/join");
Reflect.on(MinecraftClient.getInstance().getSessionService()).set("joinUrl", url);
} else {
LOGGER.info("AltauthClient: LoginRequestMixin: Server is running on mojang");
YGGDRASIL_MINECRAFT_SESSION_SERVICE_JOIN_URL.set(MinecraftClient.getInstance().getSessionService(), new URL("https://sessionserver.mojang.com/session/minecraft/join"));
URL url = new URL(YggdrasilEnvironment.PROD.getEnvironment().getSessionHost() + "/session/minecraft/join");
Reflect.on(MinecraftClient.getInstance().getSessionService()).set("joinUrl", url);
}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}