Skip to content

Commit

Permalink
More work on 1.20.4 port
Browse files Browse the repository at this point in the history
  • Loading branch information
kyrptonaught committed Dec 18, 2023
1 parent f7ce57a commit efe47d9
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 78 deletions.
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ dependencies {
modImplementation include('xyz.nucleoid:fantasy:0.5.0-lem-v1-1.20.4') { exclude group: "net.fabricmc.fabric-api" }

//Luck Perms
//modImplementation('maven.modrinth:luckperms:v5.4.111-fabric') { exclude group: "net.fabricmc.fabric-api" }
//modImplementation('me.lucko:fabric-permissions-api:0.3-SNAPSHOT') { exclude group: "net.fabricmc.fabric-api" }
//compileOnly 'net.luckperms:api:5.4'
modImplementation('maven.modrinth:luckperms:v5.4.113-fabric') { exclude group: "net.fabricmc.fabric-api" }
modImplementation('me.lucko:fabric-permissions-api:0.3-SNAPSHOT') { exclude group: "net.fabricmc.fabric-api" }
compileOnly 'net.luckperms:api:5.4'
modImplementation "com.moandjiezana.toml:toml4j:0.7.2"

//Fabric Proxy Lite
Expand All @@ -52,10 +52,10 @@ dependencies {
//modImplementation("org.geysermc.floodgate:floodgate-fabric:2.2.2-SNAPSHOT")

//carpet
//modImplementation('carpet:fabric-carpet:1.20.3-1.4.128+v231205') { exclude group: "net.fabricmc.fabric-api" }
modImplementation('carpet:fabric-carpet:1.20.3-1.4.128+v231205') { exclude group: "net.fabricmc.fabric-api" }

//NoChatReports
modImplementation('maven.modrinth:no-chat-reports:Fabric-1.20.3-v2.4.0') { exclude group: "net.fabricmc.fabric-api" }
modImplementation('maven.modrinth:no-chat-reports:Fabric-1.20.4-v2.5.0') { exclude group: "net.fabricmc.fabric-api" }

//NOTA
//modImplementation include("ru.pinkgoosik:nota:0.2.0-lem-v1-1.20.1")
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ org.gradle.jvmargs=-Xmx2G

# Fabric Properties
minecraft_version=1.20.4
yarn_mappings=1.20.4+build.1
loader_version=0.15.1
yarn_mappings=1.20.4+build.3
loader_version=0.15.3

#Fabric api
fabric_version=0.91.2+1.20.4
fabric_version=0.91.3+1.20.4

# Mod Properties
mod_version=1.0.7b1-1.20.4
mod_version=1.0.7b2-1.20.4
maven_group=net.kyrptonaught
archives_base_name=ServerUtils

Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package net.kyrptonaught.serverutils.mixin.personatus;

import net.minecraft.server.MinecraftServer;
import com.mojang.authlib.GameProfile;
import me.lucko.luckperms.fabric.listeners.FabricConnectionListener;
import me.lucko.luckperms.fabric.mixin.ServerLoginNetworkHandlerAccessor;
import net.kyrptonaught.serverutils.personatus.PersonatusProfile;
import net.minecraft.server.network.ServerPlayerEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import java.util.UUID;

@Pseudo
//@Mixin(FabricConnectionListener.class)
@Mixin(MinecraftServer.class)
@Mixin(FabricConnectionListener.class)
public class FixLuckPermsMixin {

/*
@Redirect(method = "onPreLogin", at = @At(value = "INVOKE", target = "Lme/lucko/luckperms/fabric/mixin/ServerLoginNetworkHandlerAccessor;getGameProfile()Lcom/mojang/authlib/GameProfile;"))
public GameProfile spoofRealPermsPre(ServerLoginNetworkHandlerAccessor instance) {
return ((PersonatusProfile) instance.getGameProfile()).getRealProfile();
Expand All @@ -20,6 +26,4 @@ public GameProfile spoofRealPermsPre(ServerLoginNetworkHandlerAccessor instance)
public UUID spoofRealPerms(ServerPlayerEntity instance) {
return ((PersonatusProfile) instance.getGameProfile()).getRealProfile().getId();
}
*/
}
Original file line number Diff line number Diff line change
@@ -1,83 +1,48 @@
package net.kyrptonaught.serverutils.mixin.personatus;

import com.mojang.authlib.GameProfile;
import com.mojang.authlib.yggdrasil.ProfileResult;
import com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService;
import com.mojang.util.UndashedUuid;
import net.fabricmc.fabric.mixin.networking.accessor.ServerLoginNetworkHandlerAccessor;
import net.kyrptonaught.serverutils.personatus.PersonatusModule;
import net.minecraft.network.packet.c2s.login.LoginHelloC2SPacket;
import net.minecraft.server.MinecraftServer;
import net.kyrptonaught.serverutils.personatus.PersonatusProfile;
import net.minecraft.server.network.ServerLoginNetworkHandler;
import org.objectweb.asm.Opcodes;
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 org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(ServerLoginNetworkHandler.class)
public class ServerLoginNetworkHandlerMixin {
import java.util.UUID;

@Shadow
GameProfile profile;

@Final
@Shadow
MinecraftServer server;

private boolean profileChecked = false;
@Mixin(targets = "net.minecraft.server.network.ServerLoginNetworkHandler$1")
public abstract class ServerLoginNetworkHandlerMixin {


@Inject(method = "onHello", at = @At(value = "FIELD", target = "Lnet/minecraft/server/network/ServerLoginNetworkHandler;profileName:Ljava/lang/String;", opcode = Opcodes.PUTFIELD, shift = At.Shift.AFTER))
public void requestSpoof(LoginHelloC2SPacket packet, CallbackInfo ci) {
if (!PersonatusModule.isEnabled()) {
profileChecked = true;
}

/*
new Thread(() -> {
if (server.getSessionService() instanceof YggdrasilMinecraftSessionService sessionService) {
String responseName = PersonatusModule.URLGetValue(false, "kvs/get/personatus/" + profile.getName(), "value");
@Shadow
@Final
ServerLoginNetworkHandler field_14176;

@Redirect(method = "run", at = @At(value = "INVOKE", target = "Lcom/mojang/authlib/yggdrasil/ProfileResult;profile()Lcom/mojang/authlib/GameProfile;"))
public GameProfile requestSpoof(ProfileResult instance) {
if (PersonatusModule.isEnabled()) {
GameProfile oldProfile = instance.profile();
if (((ServerLoginNetworkHandlerAccessor)field_14176).getServer().getSessionService() instanceof YggdrasilMinecraftSessionService sessionService) {
String responseName = PersonatusModule.URLGetValue(false, "kvs/get/personatus/" + oldProfile.getName(), "value");
if (responseName != null) {
String responseUUID = PersonatusModule.URLGetValue(true, "https://api.mojang.com/users/profiles/minecraft/" + responseName, "id");
if (responseUUID != null) {
UUID uuid = UUIDTypeAdapter.fromString(responseUUID);
GameProfile spoofed = sessionService.fillProfileProperties(new GameProfile(uuid, responseName), true);
UUID uuid = UndashedUuid.fromString(responseUUID);
GameProfile spoofed = sessionService.fetchProfile(uuid, true).profile();

((PersonatusProfile) spoofed).setRealProfile(profile);
profile = spoofed;
((PersonatusProfile) spoofed).setRealProfile(oldProfile);
return spoofed;
}
}
}
profileChecked = true;
}).start();
*/
}

@Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerLoginNetworkHandler;sendSuccessPacket(Lcom/mojang/authlib/GameProfile;)V"), cancellable = true)
public void delayAcceptUntilCheck(CallbackInfo ci) {
if (!PersonatusModule.isEnabled()) return;
if (!profileChecked)
ci.cancel();
}

/*
@Inject(method = "getVerifiedPublicKey", at = @At("HEAD"), cancellable = true)
private static void noKey4u(PlayerPublicKey.PublicKeyData publicKeyData, UUID playerUuid, SignatureVerifier servicesSignatureVerifier, boolean shouldThrowOnMissingKey, CallbackInfoReturnable<PlayerPublicKey> cir) {
cir.setReturnValue(null);
}
@Dynamic("Fabric Proxy Mixin")
@Inject(method = "setRealUUID", at = @At("HEAD"), cancellable = true, require = 0)
public void stopThatFabricProxyItsverysilly(UUID uuid, CallbackInfo ci) {
if (PersonatusModule.isEnabled())
ci.cancel();
}
}

@Dynamic("Fabric Proxy Mixin")
@Inject(method = "setProfile", at = @At("HEAD"), cancellable = true, require = 0)
public void stopThatFabricProxyItsverysilly2(GameProfile profile, CallbackInfo ci) {
if (PersonatusModule.isEnabled())
ci.cancel();
return instance.profile();
}
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.network.ClientConnection;
import net.minecraft.network.PacketCallbacks;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.s2c.play.ChatMessageS2CPacket;
import net.minecraft.network.packet.s2c.play.PlayerListS2CPacket;
import net.minecraft.network.packet.s2c.play.TeamS2CPacket;
import net.minecraft.server.network.ServerCommonNetworkHandler;
Expand Down Expand Up @@ -47,7 +48,6 @@ public void spoofPacket(Packet<?> packet, @Nullable PacketCallbacks callbacks, C

connection.send(teamPacket);
ci.cancel();

} else if (packet instanceof PlayerListS2CPacket) {
PlayerListS2CPacket listPacket = PacketCopier.copyPlayerList((PlayerListS2CPacket) packet);
List<PlayerListS2CPacket.Entry> entries = listPacket.getEntries();
Expand All @@ -61,7 +61,13 @@ public void spoofPacket(Packet<?> packet, @Nullable PacketCallbacks callbacks, C

connection.send(listPacket);
ci.cancel();
} else if (packet instanceof ChatMessageS2CPacket chatPacket) {
if (chatPacket.sender().equals(spoofProfile.getSpoofProfile().getId())) {
connection.send(PacketCopier.copyChatPacket(chatPacket, spoofProfile.getRealProfile().getId()));
ci.cancel();
}
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import io.netty.buffer.Unpooled;
import net.kyrptonaught.serverutils.mixin.personatus.PlayerListS2CPacketAccessor;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.packet.s2c.play.ChatMessageS2CPacket;
import net.minecraft.network.packet.s2c.play.PlayerListS2CPacket;
import net.minecraft.network.packet.s2c.play.TeamS2CPacket;

import java.util.ArrayList;
import java.util.Collections;
import java.util.UUID;

public class PacketCopier {

Expand All @@ -23,4 +25,8 @@ public static TeamS2CPacket copyTeamPacket(TeamS2CPacket oldTeamPacket) {
oldTeamPacket.write(buf);
return new TeamS2CPacket(buf);
}

public static ChatMessageS2CPacket copyChatPacket(ChatMessageS2CPacket oldChatPacket, UUID newUUID) {
return new ChatMessageS2CPacket(newUUID, oldChatPacket.index(), oldChatPacket.signature(), oldChatPacket.body(), oldChatPacket.unsignedContent(), oldChatPacket.filterMask(), oldChatPacket.serializedParameters());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -92,7 +93,7 @@ public boolean execute(String packname, Collection<ServerPlayerEntity> players)
}

//todo UUIDs
ResourcePackSendS2CPacket resourcePackSendS2CPacket = new ResourcePackSendS2CPacket(UUID.randomUUID(), rpOption.url, rpOption.hash, rpOption.required, rpOption.hasPrompt ? Text.literal(rpOption.message) : null);
ResourcePackSendS2CPacket resourcePackSendS2CPacket = new ResourcePackSendS2CPacket(UUID.nameUUIDFromBytes(rpOption.packname.getBytes(StandardCharsets.UTF_8)), rpOption.url, rpOption.hash, rpOption.required, rpOption.hasPrompt ? Text.literal(rpOption.message) : null);
player.networkHandler.sendPacket(resourcePackSendS2CPacket);
});
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"schemaVersion": 1,
"id": "serverutils",
"version": "1.0.7b1-1.20.4",
"version": "1.0.7b2-1.20.4",
"name": "Server Utils",
"description": "A group of utilities for servers",
"authors": [
Expand Down

0 comments on commit efe47d9

Please sign in to comment.