some code style

This commit is contained in:
creeper123123321 2022-11-05 19:40:49 -03:00
parent 683a7128b7
commit 396695aea7
7 changed files with 40 additions and 38 deletions

View File

@ -18,18 +18,19 @@ import java.util.stream.Collectors;
@Mixin(ArgumentSignatureDataMap.class)
public class ArgumentSignatureDataMapMixin {
@Inject(method = "sign", at = @At("HEAD"), cancellable = true)
private static void injectSign(DecoratableArgumentList<?> arguments, ArgumentSignatureDataMap.ArgumentSigner signer, CallbackInfoReturnable<ArgumentSignatureDataMap> cir) {
if (ProtocolPatcher1_19_0.shouldFixKeys) {
final List<ArgumentSignatureDataMap.Entry> list = ArgumentSignatureDataMap.toNameValuePairs(arguments).stream().map(entry -> {
final MessageMetadata metadata = MessageSigner1_19_0.get();
final MessageSignatureData messageSignatureData = MessageSigner1_19_0.sign((Signer) signer, Text.literal(entry.getFirst()), metadata.sender(), metadata.timestamp(), metadata.salt());
if (!ProtocolPatcher1_19_0.shouldPatchKeys) return;
final List<ArgumentSignatureDataMap.Entry> list = ArgumentSignatureDataMap.toNameValuePairs(arguments)
.stream().map(entry -> {
final MessageMetadata metadata = MessageSigner1_19_0.pollLastMetadata();
final MessageSignatureData messageSignatureData = MessageSigner1_19_0.sign((Signer) signer,
Text.literal(entry.getFirst()), metadata.sender(), metadata.timestamp(), metadata.salt());
return new ArgumentSignatureDataMap.Entry(entry.getFirst(), messageSignatureData);
}).collect(Collectors.toList());
cir.setReturnValue(new ArgumentSignatureDataMap(list));
}
}
}

View File

@ -19,22 +19,24 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(ClientPlayerEntity.class)
public class ClientPlayerEntityMixin {
@Shadow
@Final
protected MinecraftClient client;
@Inject(method = "signChatMessage", at = @At("HEAD"), cancellable = true)
public void injectSignChatMessage(MessageMetadata metadata, DecoratedContents content, LastSeenMessageList lastSeenMessages, CallbackInfoReturnable<MessageSignatureData> cir) {
if (ProtocolPatcher1_19_0.shouldFixKeys) {
if (!ProtocolPatcher1_19_0.shouldPatchKeys) return;
try {
final Signer signer = this.client.getProfileKeys().getSigner();
if (signer != null)
cir.setReturnValue(MessageSigner1_19_0.sign(signer, content.decorated(), metadata.sender(), metadata.timestamp(), metadata.salt()));
} catch (Exception ignored) {}
cir.cancel();
if (signer != null) {
cir.setReturnValue(MessageSigner1_19_0.sign(signer, content.decorated(), metadata.sender(),
metadata.timestamp(), metadata.salt()));
}
} catch (Exception ignored) {
}
cir.cancel();
}
@Inject(method = "signArguments", at = @At(value = "HEAD"))

View File

@ -22,30 +22,35 @@ import java.util.UUID;
@Mixin(PlayerPublicKey.PublicKeyData.class)
public class PlayerPublicKeyChPublicKeyDataMixin implements IPublicKeyData {
@Shadow @Final private Instant expiresAt;
@Shadow
@Final
private Instant expiresAt;
@Shadow @Final
@Shadow
@Final
PublicKey key;
@Unique
private byte[] _1_19_0Key;
private byte[] key1_19_0;
@Redirect(method = { "write", "verifyKey" }, at = @At(value = "FIELD", target = "Lnet/minecraft/network/encryption/PlayerPublicKey$PublicKeyData;keySignature:[B"))
@Redirect(method = {"write", "verifyKey"}, at = @At(value = "FIELD", target = "Lnet/minecraft/network/encryption/PlayerPublicKey$PublicKeyData;keySignature:[B"))
public byte[] replaceKeys(PlayerPublicKey.PublicKeyData instance) {
if (this._1_19_0Key != null && ProtocolPatcher1_19_0.shouldFixKeys)
return this._1_19_0Key;
if (this.key1_19_0 != null && ProtocolPatcher1_19_0.shouldPatchKeys) {
return this.key1_19_0;
}
return instance.keySignature();
}
@Inject(method = "toSerializedString", at = @At(value = "HEAD"), cancellable = true)
public void injectToSerializedString(UUID playerUuid, CallbackInfoReturnable<byte[]> cir) {
if (ProtocolPatcher1_19_0.shouldFixKeys)
if (ProtocolPatcher1_19_0.shouldPatchKeys) {
cir.setReturnValue((this.expiresAt.toEpochMilli() + NetworkEncryptionUtils.encodeRsaPublicKey(this.key)).getBytes(StandardCharsets.UTF_8));
}
}
@Override
public void set1_19_0Key(ByteBuffer byteBuffer) {
this._1_19_0Key = byteBuffer.array();
this.key1_19_0 = byteBuffer.array();
}
}

View File

@ -11,7 +11,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(ProfileKeys.class)
public class ProfileKeysMixin {
@Inject(method = "decodeKeyPairResponse", at = @At("RETURN"))
private static void trackLegacyKey(KeyPairResponse keyPairResponse, CallbackInfoReturnable<PlayerPublicKey.PublicKeyData> cir) {
((IPublicKeyData) (Object) cir.getReturnValue()).set1_19_0Key(keyPairResponse.getLegacyPublicKeySignature());

View File

@ -31,7 +31,7 @@ public class FabricVersionProvider extends AbstractFabricVersionProvider {
@Override
public void onFinallySetVersion(int realClientsideVersion) {
ProtocolPatcher1_19_0.shouldFixKeys = realClientsideVersion <= ProtocolVersion.v1_19.getVersion();
ProtocolPatcher1_19_0.shouldPatchKeys = realClientsideVersion <= ProtocolVersion.v1_19.getVersion();
}
@Override

View File

@ -9,18 +9,13 @@ import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.*;
public class MessageSigner1_19_0 {
public static final Deque<MessageMetadata> TRACKED_METADATA_LIST = new ArrayDeque<>();
public static final List<MessageMetadata> TRACKED_METADATA_LIST = new ArrayList<>();
public static MessageMetadata get() {
MessageMetadata i = TRACKED_METADATA_LIST.get(TRACKED_METADATA_LIST.size() - 1);
TRACKED_METADATA_LIST.remove(i);
return i;
public static MessageMetadata pollLastMetadata() {
return TRACKED_METADATA_LIST.pollLast();
}
public static void track(final MessageMetadata metadata) {

View File

@ -11,7 +11,7 @@ import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.Protocol1_19_1To
// This class modifies the 1.19.1 -> 1.19.0 transformers so that they simply pass through the original Minecraft key.
public class ProtocolPatcher1_19_0 {
public static boolean shouldFixKeys = false;
public static boolean shouldPatchKeys = false;
public static void patch() {
final Protocol1_19_1To1_19 protocol1_19_1To1_19 = Via.getManager().getProtocolManager().getProtocol(Protocol1_19_1To1_19.class);