Fixed chat signature injection

This commit is contained in:
RaphiMC 2023-10-20 21:13:24 +02:00
parent d986ea0875
commit e3651490c5
No known key found for this signature in database
GPG Key ID: 0F6BB0657A03AC94
2 changed files with 48 additions and 19 deletions

View File

@ -0,0 +1,48 @@
/*
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
* Copyright (C) 2023 RK_01/RaphiMC and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.raphimc.viaproxy.injection.transformer;
import com.viaversion.viabackwards.protocol.protocol1_19_1to1_19_3.Protocol1_19_1To1_19_3;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ServerboundPackets1_19_3;
import net.lenni0451.classtransform.InjectionCallback;
import net.lenni0451.classtransform.annotations.CTarget;
import net.lenni0451.classtransform.annotations.CTransformer;
import net.lenni0451.classtransform.annotations.injection.CInject;
import net.raphimc.viaproxy.protocolhack.viaproxy.signature.storage.ChatSession1_19_3;
@CTransformer(name = "com.viaversion.viabackwards.protocol.protocol1_19_1to1_19_3.Protocol1_19_1To1_19_3$1")
public abstract class Protocol1_19_1To1_19_3$1Transformer extends PacketHandlers {
@CInject(method = "register", target = @CTarget("RETURN"))
private void allowSignatures(InjectionCallback ic) {
handler(wrapper -> {
final ChatSession1_19_3 chatSession = wrapper.user().get(ChatSession1_19_3.class);
if (chatSession != null) {
final PacketWrapper chatSessionUpdate = wrapper.create(ServerboundPackets1_19_3.CHAT_SESSION_UPDATE);
chatSessionUpdate.write(Type.UUID, chatSession.getSessionId());
chatSessionUpdate.write(Type.PROFILE_KEY, chatSession.getProfileKey());
chatSessionUpdate.sendToServer(Protocol1_19_1To1_19_3.class);
}
});
}
}

View File

@ -20,12 +20,9 @@ package net.raphimc.viaproxy.injection.transformer;
import com.viaversion.viabackwards.api.BackwardsProtocol; import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viabackwards.protocol.protocol1_19_1to1_19_3.Protocol1_19_1To1_19_3; import com.viaversion.viabackwards.protocol.protocol1_19_1to1_19_3.Protocol1_19_1To1_19_3;
import com.viaversion.viaversion.api.minecraft.PlayerMessageSignature; import com.viaversion.viaversion.api.minecraft.PlayerMessageSignature;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.BitSetType; import com.viaversion.viaversion.api.type.types.BitSetType;
import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets;
import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.ClientboundPackets1_19_1; import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.ClientboundPackets1_19_1;
import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.ServerboundPackets1_19_1; import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.ServerboundPackets1_19_1;
import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ClientboundPackets1_19_3; import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ClientboundPackets1_19_3;
@ -44,22 +41,6 @@ public abstract class Protocol1_19_1To1_19_3Transformer extends BackwardsProtoco
@CInject(method = "registerPackets", target = @CTarget("RETURN")) @CInject(method = "registerPackets", target = @CTarget("RETURN"))
private void allowSignatures(InjectionCallback ic) { private void allowSignatures(InjectionCallback ic) {
this.registerClientbound(State.LOGIN, ClientboundLoginPackets.GAME_PROFILE.getId(), ClientboundLoginPackets.GAME_PROFILE.getId(), new PacketHandlers() {
@Override
public void register() {
handler(wrapper -> {
final ChatSession1_19_3 chatSession = wrapper.user().get(ChatSession1_19_3.class);
if (chatSession != null) {
final PacketWrapper chatSessionUpdate = wrapper.create(ServerboundPackets1_19_3.CHAT_SESSION_UPDATE);
chatSessionUpdate.write(Type.UUID, chatSession.getSessionId());
chatSessionUpdate.write(Type.PROFILE_KEY, chatSession.getProfileKey());
chatSessionUpdate.sendToServer(Protocol1_19_1To1_19_3.class);
}
});
}
}, true);
this.registerServerbound(ServerboundPackets1_19_1.CHAT_MESSAGE, ServerboundPackets1_19_3.CHAT_MESSAGE, new PacketHandlers() { this.registerServerbound(ServerboundPackets1_19_1.CHAT_MESSAGE, ServerboundPackets1_19_3.CHAT_MESSAGE, new PacketHandlers() {
@Override @Override
public void register() { public void register() {