From 95ffafafe9053438b23f6a08e45f64b647062ba3 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 23 Sep 2022 21:02:46 +0200 Subject: [PATCH 1/2] Got Fabric in the Repo :D --- build.gradle | 22 ++++++-- bukkit/build.gradle | 3 -- bungee/build.gradle | 3 -- common/build.gradle | 3 -- fabric/build.gradle | 43 +++++++++++++++ fabric/src/alt-auth.mixins.json | 15 ++++++ fabric/src/de/chaoscaot/altauth/AltAuth.java | 18 +++++++ .../de/chaoscaot/altauth/AltAuthClient.java | 10 ++++ .../de/chaoscaot/altauth/AltAuthServer.java | 10 ++++ .../config/client/AltAuthClientConfig.java | 43 +++++++++++++++ .../config/server/AltAuthServerConfig.java | 44 ++++++++++++++++ .../altauth/gui/ApproveServerScreen.java | 22 ++++++++ .../mixin/client/LoginRequestMixin.java | 52 +++++++++++++++++++ .../altauth/mixin/server/ServerIdMixin.java | 20 +++++++ fabric/src/fabric.mod.json | 29 +++++++++++ gradle.properties | 8 +++ settings.gradle | 11 ++++ 17 files changed, 343 insertions(+), 13 deletions(-) create mode 100644 fabric/build.gradle create mode 100644 fabric/src/alt-auth.mixins.json create mode 100644 fabric/src/de/chaoscaot/altauth/AltAuth.java create mode 100644 fabric/src/de/chaoscaot/altauth/AltAuthClient.java create mode 100644 fabric/src/de/chaoscaot/altauth/AltAuthServer.java create mode 100644 fabric/src/de/chaoscaot/altauth/config/client/AltAuthClientConfig.java create mode 100644 fabric/src/de/chaoscaot/altauth/config/server/AltAuthServerConfig.java create mode 100644 fabric/src/de/chaoscaot/altauth/gui/ApproveServerScreen.java create mode 100644 fabric/src/de/chaoscaot/altauth/mixin/client/LoginRequestMixin.java create mode 100644 fabric/src/de/chaoscaot/altauth/mixin/server/ServerIdMixin.java create mode 100644 fabric/src/fabric.mod.json create mode 100644 gradle.properties diff --git a/build.gradle b/build.gradle index 4b3ad46..cf720d1 100644 --- a/build.gradle +++ b/build.gradle @@ -12,10 +12,11 @@ plugins { id 'application' id 'com.github.johnrengelman.shadow' version '5.0.0' + id 'fabric-loom' version '1.0-SNAPSHOT' apply false } group 'de.lixfel' -version '' +version project.version ext { buildName = 'AltAuth' @@ -26,9 +27,6 @@ ext { compileJava.options.encoding = 'UTF-8' -sourceCompatibility = 1.8 -targetCompatibility = 1.8 - mainClassName = '' allprojects { @@ -39,11 +37,27 @@ allprojects { maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } maven { url = uri('https://steamwar.de/maven') } + + maven { url 'https://maven.fabricmc.net/' } + maven { url "https://maven.shedaniel.me/" } + maven { url "https://maven.terraformersmc.com/releases/" } + } + + configurations { + compileClasspath + } +} + +subprojects { + tasks.withType(JavaCompile) { + options.encoding = 'UTF-8' + options.release = 8 } } dependencies { implementation project(":bukkit") implementation project(":bungee") + implementation project(":fabric") implementation project(":common") } diff --git a/bukkit/build.gradle b/bukkit/build.gradle index 90f1a2c..78be4fc 100644 --- a/bukkit/build.gradle +++ b/bukkit/build.gradle @@ -10,9 +10,6 @@ version '' compileJava.options.encoding = 'UTF-8' -sourceCompatibility = 1.8 -targetCompatibility = 1.8 - sourceSets { main { java { diff --git a/bungee/build.gradle b/bungee/build.gradle index b223f51..ea9bb97 100644 --- a/bungee/build.gradle +++ b/bungee/build.gradle @@ -10,9 +10,6 @@ version '' compileJava.options.encoding = 'UTF-8' -sourceCompatibility = 1.8 -targetCompatibility = 1.8 - sourceSets { main { java { diff --git a/common/build.gradle b/common/build.gradle index c0c5b66..0498bfe 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -10,9 +10,6 @@ version '' compileJava.options.encoding = 'UTF-8' -sourceCompatibility = 1.8 -targetCompatibility = 1.8 - sourceSets { main { java { diff --git a/fabric/build.gradle b/fabric/build.gradle new file mode 100644 index 0000000..4223ef8 --- /dev/null +++ b/fabric/build.gradle @@ -0,0 +1,43 @@ +plugins { + id 'fabric-loom' +} + +tasks.withType(JavaCompile) { + options.release = 17 +} + +version = project.version +group = 'de.chaoscaot' + +sourceSets { + main { + java { + srcDirs = ['src/'] + } + resources { + srcDirs = ['src/'] + exclude '**/*.java' + } + } +} + +dependencies { + // To change the versions see the gradle.properties file + minecraft "com.mojang:minecraft:${project.minecraft_version}" + mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" + modCompileOnly "net.fabricmc:fabric-loader:${project.loader_version}" + modCompileOnlyApi ("me.shedaniel.cloth:cloth-config-fabric:8.2.88") { + exclude(group: "net.fabricmc.fabric-api") + } + modCompileOnlyApi "com.terraformersmc:modmenu:4.0.6" + compileOnly project(":common") +} + +processResources { + inputs.property "version", project.version + filteringCharset "UTF-8" + + filesMatching("fabric.mod.json") { + expand "version": project.version + } +} diff --git a/fabric/src/alt-auth.mixins.json b/fabric/src/alt-auth.mixins.json new file mode 100644 index 0000000..5c7a44e --- /dev/null +++ b/fabric/src/alt-auth.mixins.json @@ -0,0 +1,15 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "de.chaoscaot.altauth.mixin", + "compatibilityLevel": "JAVA_17", + "client": [ + "client.LoginRequestMixin" + ], + "server": [ + "server.ServerIdMixin" + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/fabric/src/de/chaoscaot/altauth/AltAuth.java b/fabric/src/de/chaoscaot/altauth/AltAuth.java new file mode 100644 index 0000000..a80a691 --- /dev/null +++ b/fabric/src/de/chaoscaot/altauth/AltAuth.java @@ -0,0 +1,18 @@ +package de.chaoscaot.altauth; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import net.fabricmc.api.ModInitializer; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +public class AltAuth implements ModInitializer { + + public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); + public static final Logger LOGGER = LogManager.getLogger(); + + @Override + public void onInitialize() { + + } +} diff --git a/fabric/src/de/chaoscaot/altauth/AltAuthClient.java b/fabric/src/de/chaoscaot/altauth/AltAuthClient.java new file mode 100644 index 0000000..42c9326 --- /dev/null +++ b/fabric/src/de/chaoscaot/altauth/AltAuthClient.java @@ -0,0 +1,10 @@ +package de.chaoscaot.altauth; + +import net.fabricmc.api.ClientModInitializer; + +public class AltAuthClient implements ClientModInitializer { + @Override + public void onInitializeClient() { + + } +} diff --git a/fabric/src/de/chaoscaot/altauth/AltAuthServer.java b/fabric/src/de/chaoscaot/altauth/AltAuthServer.java new file mode 100644 index 0000000..42f4f09 --- /dev/null +++ b/fabric/src/de/chaoscaot/altauth/AltAuthServer.java @@ -0,0 +1,10 @@ +package de.chaoscaot.altauth; + +import net.fabricmc.api.DedicatedServerModInitializer; + +public class AltAuthServer implements DedicatedServerModInitializer { + @Override + public void onInitializeServer() { + + } +} diff --git a/fabric/src/de/chaoscaot/altauth/config/client/AltAuthClientConfig.java b/fabric/src/de/chaoscaot/altauth/config/client/AltAuthClientConfig.java new file mode 100644 index 0000000..931cc35 --- /dev/null +++ b/fabric/src/de/chaoscaot/altauth/config/client/AltAuthClientConfig.java @@ -0,0 +1,43 @@ +package de.chaoscaot.altauth.config.client; + +import de.chaoscaot.altauth.AltAuth; +import net.fabricmc.loader.api.FabricLoader; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.ArrayList; +import java.util.List; + +public class AltAuthClientConfig { + + private static final String CONFIG_FILE_NAME = "altauth.client.json"; + + public static AltAuthClientConfig INSTANCE; + + static { + if(!new File(FabricLoader.getInstance().getConfigDir().toFile(), CONFIG_FILE_NAME).exists()) { + INSTANCE = new AltAuthClientConfig(); + } else { + try { + INSTANCE = AltAuth.GSON.fromJson(Files.readString(FabricLoader.getInstance().getConfigDir().resolve(CONFIG_FILE_NAME)), AltAuthClientConfig.class); + } catch (IOException e) { + AltAuth.LOGGER.error("AltauthClient: AltAuthClientConfig: Error while loading config", e); + AltAuth.LOGGER.info("Reset Config..."); + INSTANCE = new AltAuthClientConfig(); + INSTANCE.save(); + } + } + } + + public boolean enabled = true; + public List allowedServers = new ArrayList<>(); + + public void save() { + try { + Files.writeString(FabricLoader.getInstance().getConfigDir().resolve(CONFIG_FILE_NAME), AltAuth.GSON.toJson(this)); + } catch (IOException e) { + AltAuth.LOGGER.error("AltauthClient: AltAuthClientConfig: Error while saving config", e); + } + } +} diff --git a/fabric/src/de/chaoscaot/altauth/config/server/AltAuthServerConfig.java b/fabric/src/de/chaoscaot/altauth/config/server/AltAuthServerConfig.java new file mode 100644 index 0000000..3236a21 --- /dev/null +++ b/fabric/src/de/chaoscaot/altauth/config/server/AltAuthServerConfig.java @@ -0,0 +1,44 @@ +package de.chaoscaot.altauth.config.server; + +import de.chaoscaot.altauth.AltAuth; +import net.fabricmc.loader.api.FabricLoader; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; + +public class AltAuthServerConfig { + + private static final String CONFIG_FILE_NAME = "altauth.json"; + + public static AltAuthServerConfig INSTANCE; + + static { + if(!new File(FabricLoader.getInstance().getConfigDir().toFile(), CONFIG_FILE_NAME).exists()) { + INSTANCE = new AltAuthServerConfig(); + } else { + try { + INSTANCE = AltAuth.GSON.fromJson(Files.readString(FabricLoader.getInstance().getConfigDir().resolve(CONFIG_FILE_NAME)), AltAuthServerConfig.class); + if(INSTANCE.serverUrl.length() > 20) { + AltAuth.LOGGER.error("AltauthServer: AltAuthServerConfig: ServerUrl is too long. Max length is 20 characters"); + INSTANCE.serverUrl = ""; + } + } catch (IOException e) { + AltAuth.LOGGER.error("AltauthServer: AltAuthServerConfig: Error while loading config", e); + AltAuth.LOGGER.info("Reset Config..."); + INSTANCE = new AltAuthServerConfig(); + INSTANCE.save(); + } + } + } + + public String serverUrl = "EnterNameHere"; + + public void save() { + try { + Files.writeString(FabricLoader.getInstance().getConfigDir().resolve(CONFIG_FILE_NAME), AltAuth.GSON.toJson(this)); + } catch (IOException e) { + AltAuth.LOGGER.error("AltauthServer: AltAuthServerConfig: Error while saving config", e); + } + } +} diff --git a/fabric/src/de/chaoscaot/altauth/gui/ApproveServerScreen.java b/fabric/src/de/chaoscaot/altauth/gui/ApproveServerScreen.java new file mode 100644 index 0000000..80e1492 --- /dev/null +++ b/fabric/src/de/chaoscaot/altauth/gui/ApproveServerScreen.java @@ -0,0 +1,22 @@ +package de.chaoscaot.altauth.gui; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.gui.screen.WarningScreen; +import net.minecraft.text.Text; + +@Environment(EnvType.CLIENT) +public class ApproveServerScreen extends WarningScreen { + private static final Text TITLE = Text.of("Approve Server"); + private static final Text MESSAGE = Text.of("Do you want to approve this server?"); + private static final Text NARRATOR_MESSAGE = Text.of("Do you want to approve this server?"); + + public ApproveServerScreen(String serverAddress) { + super(TITLE, MESSAGE, NARRATOR_MESSAGE); + } + + @Override + protected void initButtons(int yOffset) { + + } +} diff --git a/fabric/src/de/chaoscaot/altauth/mixin/client/LoginRequestMixin.java b/fabric/src/de/chaoscaot/altauth/mixin/client/LoginRequestMixin.java new file mode 100644 index 0000000..299b73a --- /dev/null +++ b/fabric/src/de/chaoscaot/altauth/mixin/client/LoginRequestMixin.java @@ -0,0 +1,52 @@ +package de.chaoscaot.altauth.mixin.client; + +import com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService; +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.slf4j.Logger; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +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) +@Mixin(ClientLoginNetworkHandler.class) +public class LoginRequestMixin { + @Shadow @Final private static Logger LOGGER; + + private static final Class 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")); + } 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")); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + } +} diff --git a/fabric/src/de/chaoscaot/altauth/mixin/server/ServerIdMixin.java b/fabric/src/de/chaoscaot/altauth/mixin/server/ServerIdMixin.java new file mode 100644 index 0000000..99c0afb --- /dev/null +++ b/fabric/src/de/chaoscaot/altauth/mixin/server/ServerIdMixin.java @@ -0,0 +1,20 @@ +package de.chaoscaot.altauth.mixin.server; + +import de.chaoscaot.altauth.config.server.AltAuthServerConfig; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.network.PacketByteBuf; +import net.minecraft.network.packet.s2c.login.LoginHelloS2CPacket; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Environment(EnvType.SERVER) +@Mixin(LoginHelloS2CPacket.class) +public class ServerIdMixin { + + @Redirect(method = "write", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/PacketByteBuf;writeString(Ljava/lang/String;)Lnet/minecraft/network/PacketByteBuf;")) + public PacketByteBuf writeString(PacketByteBuf packetByteBuf, String string) { + return packetByteBuf.writeString(AltAuthServerConfig.INSTANCE.serverUrl); + } +} diff --git a/fabric/src/fabric.mod.json b/fabric/src/fabric.mod.json new file mode 100644 index 0000000..8c45d1f --- /dev/null +++ b/fabric/src/fabric.mod.json @@ -0,0 +1,29 @@ +{ + "schemaVersion": 1, + "id": "alt-auth-client", + "version": "${version}", + "name": "AltAuth", + "description": "Use AltAuth", + "authors": [], + "contact": {}, + "license": "MIT", + "environment": "*", + "entrypoints": { + "main": [ + "de.chaoscaot.altauth.AltAuth" + ], + "client": [ + "de.chaoscaot.altauth.AltAuthClient" + ], + "server": [ + "de.chaoscaot.altauth.AltAuthServer" + ] + }, + "mixins": [ + "alt-auth.mixins.json" + ], + "depends": { + "fabricloader": ">=0.13.3", + "minecraft": ">=1.18.2" + } +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..ec2a6b9 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,8 @@ +org.gradle.jvmargs=-Xmx1G + +minecraft_version=1.19.2 +yarn_mappings=1.19.2+build.4 +loader_version=0.14.9 + +version=1.0.0 + diff --git a/settings.gradle b/settings.gradle index ab3c409..90f72bd 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,7 +1,18 @@ // SPDX-License-Identifier: MIT +pluginManagement { + repositories { + maven { + name = 'Fabric' + url = 'https://maven.fabricmc.net/' + } + gradlePluginPortal() + } +} + rootProject.name = 'AltAuth' include 'bukkit' include 'bungee' include 'common' +include 'fabric' From 97ed2addd315fa781045723bd0225507493edece Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 24 Sep 2022 01:08:14 +0200 Subject: [PATCH 2/2] Fix Reflections --- fabric/build.gradle | 4 ++++ .../mixin/client/LoginRequestMixin.java | 24 ++++++------------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/fabric/build.gradle b/fabric/build.gradle index 4223ef8..f8b1765 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -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 { diff --git a/fabric/src/de/chaoscaot/altauth/mixin/client/LoginRequestMixin.java b/fabric/src/de/chaoscaot/altauth/mixin/client/LoginRequestMixin.java index 299b73a..2181032 100644 --- a/fabric/src/de/chaoscaot/altauth/mixin/client/LoginRequestMixin.java +++ b/fabric/src/de/chaoscaot/altauth/mixin/client/LoginRequestMixin.java @@ -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 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); } }