Skip to content

Commit

Permalink
Fix network protocol error thing
Browse files Browse the repository at this point in the history
Fixes #492, fixes #493, fixes #495
  • Loading branch information
Aizistral committed Nov 8, 2024
1 parent cb05b3c commit 0f36233
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,22 @@ private String onAddRecentChat(String message) {
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/components/ChatComponent;"
+ "logChatMessage(Lnet/minecraft/client/GuiMessage;)V", ordinal = 0, shift = Shift.BEFORE))
private GuiMessage modifyGUIMessage(GuiMessage msg) {
if (!NCRConfig.getEncryption().isEnabledAndValid())
return msg;
else if (this.minecraft.level == null) {
NCRCore.LOGGER.warn("Chat message cannot be decrypted since level didn't load in yet!");
return msg;
}

if (NCRConfig.getCommon().enableDebugLog()) {
NCRCore.LOGGER.info("Adding chat message, structure: " +
Component.Serializer.toJson(msg.content(), RegistryAccess.EMPTY));
}

assert minecraft.level != null;
var decrypted = EncryptionUtil.tryDecrypt(minecraft.level.registryAccess(), msg.content());
var decrypted = EncryptionUtil.tryDecrypt(this.minecraft.level.registryAccess(), msg.content());

decrypted.ifPresentOrElse(component -> {
this.lastMessageOriginal = EncryptionUtil.recreate(minecraft.level.registryAccess(), msg.content());
this.lastMessageOriginal = EncryptionUtil.recreate(this.minecraft.level.registryAccess(), msg.content());
this.lastMessageEncrypted = true;
}, () -> this.lastMessageEncrypted = false);

Expand Down

0 comments on commit 0f36233

Please sign in to comment.