Skip to content

Commit

Permalink
Fix signed message check on PandaSpigot
Browse files Browse the repository at this point in the history
  • Loading branch information
Rothes committed Feb 14, 2024
1 parent 5c95489 commit 72fd444
Showing 1 changed file with 61 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,78 +55,80 @@ public class PlayerChatHelper {
version = Version.V19_4;
}

try {
messageBodyClass = MinecraftReflection.getMinecraftClass("network.chat.SignedMessageBody");
} catch (Throwable ignored) {}

try {
// 1.19.1+
playerChatMessageClass = MinecraftReflection.getMinecraftClass("network.chat.PlayerChatMessage");
for (Field declaredField : playerChatMessageClass.getDeclaredFields()) {
if (declaredField.getType() == Optional.class) {
declaredField.setAccessible(true);
playerChatMessageComponentField = declaredField;
break;
if (version != Version.V8_0_TO_V18_2) {
try {
messageBodyClass = MinecraftReflection.getMinecraftClass("network.chat.SignedMessageBody");
} catch (Throwable ignored) {}

try {
// 1.19.1+
playerChatMessageClass = MinecraftReflection.getMinecraftClass("network.chat.PlayerChatMessage");
for (Field declaredField : playerChatMessageClass.getDeclaredFields()) {
if (declaredField.getType() == Optional.class) {
declaredField.setAccessible(true);
playerChatMessageComponentField = declaredField;
break;
}
}
}

Class<?> chatMessageTypeClass = MinecraftReflection.getMinecraftClass("network.chat.ChatMessageType");

for (Field field : PacketType.Play.Server.CHAT.getPacketClass().getDeclaredFields()) {
Class<?> declaringClass = field.getType().getDeclaringClass();
if (declaringClass == chatMessageTypeClass) {
chatMessageTypeSubClass = field.getType();
setupNameFields(chatMessageTypeSubClass);
} else if (messageBodyClass != null && declaringClass == messageBodyClass) {
// 1.19.3 only
messageBodySubClass = field.getType();
for (Field declaredField : messageBodySubClass.getDeclaredFields()) {
if (declaredField.getType() == String.class) {
messageStringField = declaredField;
messageStringField.setAccessible(true);
break;
Class<?> chatMessageTypeClass = MinecraftReflection.getMinecraftClass("network.chat.ChatMessageType");

for (Field field : PacketType.Play.Server.CHAT.getPacketClass().getDeclaredFields()) {
Class<?> declaringClass = field.getType().getDeclaringClass();
if (declaringClass == chatMessageTypeClass) {
chatMessageTypeSubClass = field.getType();
setupNameFields(chatMessageTypeSubClass);
} else if (messageBodyClass != null && declaringClass == messageBodyClass) {
// 1.19.3 only
messageBodySubClass = field.getType();
for (Field declaredField : messageBodySubClass.getDeclaredFields()) {
if (declaredField.getType() == String.class) {
messageStringField = declaredField;
messageStringField.setAccessible(true);
break;
}
}
}

} else if (field.getType() == playerChatMessageClass) {
chatMessageField = field;
chatMessageField.setAccessible(true);

for (Field declaredField : playerChatMessageClass.getDeclaredFields()) {
if (declaredField.getType() == messageBodyClass) {
messageBodyField = declaredField;
messageBodyField.setAccessible(true);

Class<?> messageContentClass = MinecraftReflection.getMinecraftClass("network.chat.ChatMessageContent");
for (Field messageContentClassDeclaredField : messageBodyClass.getDeclaredFields()) {
if (messageContentClassDeclaredField.getType() == messageContentClass) {
messageContentField = messageContentClassDeclaredField;
messageContentField.setAccessible(true);

for (Field contentClassDeclaredField : messageContentClass.getDeclaredFields()) {
if (contentClassDeclaredField.getType() == String.class) {
stringField = contentClassDeclaredField;
stringField.setAccessible(true);
} else if (contentClassDeclaredField.getType() == MinecraftReflection.getIChatBaseComponentClass()) {
componentField = contentClassDeclaredField;
componentField.setAccessible(true);
} else if (field.getType() == playerChatMessageClass) {
chatMessageField = field;
chatMessageField.setAccessible(true);

for (Field declaredField : playerChatMessageClass.getDeclaredFields()) {
if (declaredField.getType() == messageBodyClass) {
messageBodyField = declaredField;
messageBodyField.setAccessible(true);

Class<?> messageContentClass = MinecraftReflection.getMinecraftClass("network.chat.ChatMessageContent");
for (Field messageContentClassDeclaredField : messageBodyClass.getDeclaredFields()) {
if (messageContentClassDeclaredField.getType() == messageContentClass) {
messageContentField = messageContentClassDeclaredField;
messageContentField.setAccessible(true);

for (Field contentClassDeclaredField : messageContentClass.getDeclaredFields()) {
if (contentClassDeclaredField.getType() == String.class) {
stringField = contentClassDeclaredField;
stringField.setAccessible(true);
} else if (contentClassDeclaredField.getType() == MinecraftReflection.getIChatBaseComponentClass()) {
componentField = contentClassDeclaredField;
componentField.setAccessible(true);
}
}
}
}
}
}
}

}
}
}

if (chatMessageTypeSubClass == null) {
// Not 1.19.1+, it's 1.19
chatSenderClass = MinecraftReflection.getMinecraftClass("network.chat.ChatSender");
setupNameFields(chatSenderClass);
if (chatMessageTypeSubClass == null) {
// Not 1.19.1+, it's 1.19
chatSenderClass = MinecraftReflection.getMinecraftClass("network.chat.ChatSender");
setupNameFields(chatSenderClass);
}
} catch (Throwable t) {
ProtocolStringReplacer.warn("Unable to init PlayerChatHelper. PlayerChat packet handle may not work.", t);
}
} catch (Throwable t) {
ProtocolStringReplacer.warn("Unable to init PlayerChatHelper. PlayerChat packet handle may not work.", t);
}
}

Expand Down

0 comments on commit 72fd444

Please sign in to comment.