mirror of
https://github.com/ViaVersion/ViaFabric.git
synced 2024-11-16 10:45:15 +01:00
some code style
This commit is contained in:
parent
683a7128b7
commit
396695aea7
@ -18,18 +18,19 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
@Mixin(ArgumentSignatureDataMap.class)
|
@Mixin(ArgumentSignatureDataMap.class)
|
||||||
public class ArgumentSignatureDataMapMixin {
|
public class ArgumentSignatureDataMapMixin {
|
||||||
|
|
||||||
@Inject(method = "sign", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "sign", at = @At("HEAD"), cancellable = true)
|
||||||
private static void injectSign(DecoratableArgumentList<?> arguments, ArgumentSignatureDataMap.ArgumentSigner signer, CallbackInfoReturnable<ArgumentSignatureDataMap> cir) {
|
private static void injectSign(DecoratableArgumentList<?> arguments, ArgumentSignatureDataMap.ArgumentSigner signer, CallbackInfoReturnable<ArgumentSignatureDataMap> cir) {
|
||||||
if (ProtocolPatcher1_19_0.shouldFixKeys) {
|
if (!ProtocolPatcher1_19_0.shouldPatchKeys) return;
|
||||||
final List<ArgumentSignatureDataMap.Entry> list = ArgumentSignatureDataMap.toNameValuePairs(arguments).stream().map(entry -> {
|
|
||||||
final MessageMetadata metadata = MessageSigner1_19_0.get();
|
final List<ArgumentSignatureDataMap.Entry> list = ArgumentSignatureDataMap.toNameValuePairs(arguments)
|
||||||
final MessageSignatureData messageSignatureData = MessageSigner1_19_0.sign((Signer) signer, Text.literal(entry.getFirst()), metadata.sender(), metadata.timestamp(), metadata.salt());
|
.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);
|
return new ArgumentSignatureDataMap.Entry(entry.getFirst(), messageSignatureData);
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
|
|
||||||
cir.setReturnValue(new ArgumentSignatureDataMap(list));
|
cir.setReturnValue(new ArgumentSignatureDataMap(list));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -19,22 +19,24 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|||||||
|
|
||||||
@Mixin(ClientPlayerEntity.class)
|
@Mixin(ClientPlayerEntity.class)
|
||||||
public class ClientPlayerEntityMixin {
|
public class ClientPlayerEntityMixin {
|
||||||
|
|
||||||
@Shadow
|
@Shadow
|
||||||
@Final
|
@Final
|
||||||
protected MinecraftClient client;
|
protected MinecraftClient client;
|
||||||
|
|
||||||
@Inject(method = "signChatMessage", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "signChatMessage", at = @At("HEAD"), cancellable = true)
|
||||||
public void injectSignChatMessage(MessageMetadata metadata, DecoratedContents content, LastSeenMessageList lastSeenMessages, CallbackInfoReturnable<MessageSignatureData> cir) {
|
public void injectSignChatMessage(MessageMetadata metadata, DecoratedContents content, LastSeenMessageList lastSeenMessages, CallbackInfoReturnable<MessageSignatureData> cir) {
|
||||||
if (ProtocolPatcher1_19_0.shouldFixKeys) {
|
if (!ProtocolPatcher1_19_0.shouldPatchKeys) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final Signer signer = this.client.getProfileKeys().getSigner();
|
final Signer signer = this.client.getProfileKeys().getSigner();
|
||||||
|
|
||||||
if (signer != null)
|
if (signer != null) {
|
||||||
cir.setReturnValue(MessageSigner1_19_0.sign(signer, content.decorated(), metadata.sender(), metadata.timestamp(), metadata.salt()));
|
cir.setReturnValue(MessageSigner1_19_0.sign(signer, content.decorated(), metadata.sender(),
|
||||||
} catch (Exception ignored) {}
|
metadata.timestamp(), metadata.salt()));
|
||||||
cir.cancel();
|
|
||||||
}
|
}
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
cir.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "signArguments", at = @At(value = "HEAD"))
|
@Inject(method = "signArguments", at = @At(value = "HEAD"))
|
||||||
|
@ -22,30 +22,35 @@ import java.util.UUID;
|
|||||||
@Mixin(PlayerPublicKey.PublicKeyData.class)
|
@Mixin(PlayerPublicKey.PublicKeyData.class)
|
||||||
public class PlayerPublicKeyChPublicKeyDataMixin implements IPublicKeyData {
|
public class PlayerPublicKeyChPublicKeyDataMixin implements IPublicKeyData {
|
||||||
|
|
||||||
@Shadow @Final private Instant expiresAt;
|
@Shadow
|
||||||
|
@Final
|
||||||
|
private Instant expiresAt;
|
||||||
|
|
||||||
@Shadow @Final
|
@Shadow
|
||||||
|
@Final
|
||||||
PublicKey key;
|
PublicKey key;
|
||||||
|
|
||||||
@Unique
|
@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) {
|
public byte[] replaceKeys(PlayerPublicKey.PublicKeyData instance) {
|
||||||
if (this._1_19_0Key != null && ProtocolPatcher1_19_0.shouldFixKeys)
|
if (this.key1_19_0 != null && ProtocolPatcher1_19_0.shouldPatchKeys) {
|
||||||
return this._1_19_0Key;
|
return this.key1_19_0;
|
||||||
|
}
|
||||||
|
|
||||||
return instance.keySignature();
|
return instance.keySignature();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "toSerializedString", at = @At(value = "HEAD"), cancellable = true)
|
@Inject(method = "toSerializedString", at = @At(value = "HEAD"), cancellable = true)
|
||||||
public void injectToSerializedString(UUID playerUuid, CallbackInfoReturnable<byte[]> cir) {
|
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));
|
cir.setReturnValue((this.expiresAt.toEpochMilli() + NetworkEncryptionUtils.encodeRsaPublicKey(this.key)).getBytes(StandardCharsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void set1_19_0Key(ByteBuffer byteBuffer) {
|
public void set1_19_0Key(ByteBuffer byteBuffer) {
|
||||||
this._1_19_0Key = byteBuffer.array();
|
this.key1_19_0 = byteBuffer.array();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|||||||
|
|
||||||
@Mixin(ProfileKeys.class)
|
@Mixin(ProfileKeys.class)
|
||||||
public class ProfileKeysMixin {
|
public class ProfileKeysMixin {
|
||||||
|
|
||||||
@Inject(method = "decodeKeyPairResponse", at = @At("RETURN"))
|
@Inject(method = "decodeKeyPairResponse", at = @At("RETURN"))
|
||||||
private static void trackLegacyKey(KeyPairResponse keyPairResponse, CallbackInfoReturnable<PlayerPublicKey.PublicKeyData> cir) {
|
private static void trackLegacyKey(KeyPairResponse keyPairResponse, CallbackInfoReturnable<PlayerPublicKey.PublicKeyData> cir) {
|
||||||
((IPublicKeyData) (Object) cir.getReturnValue()).set1_19_0Key(keyPairResponse.getLegacyPublicKeySignature());
|
((IPublicKeyData) (Object) cir.getReturnValue()).set1_19_0Key(keyPairResponse.getLegacyPublicKeySignature());
|
||||||
|
@ -31,7 +31,7 @@ public class FabricVersionProvider extends AbstractFabricVersionProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFinallySetVersion(int realClientsideVersion) {
|
public void onFinallySetVersion(int realClientsideVersion) {
|
||||||
ProtocolPatcher1_19_0.shouldFixKeys = realClientsideVersion <= ProtocolVersion.v1_19.getVersion();
|
ProtocolPatcher1_19_0.shouldPatchKeys = realClientsideVersion <= ProtocolVersion.v1_19.getVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -9,18 +9,13 @@ import java.nio.ByteBuffer;
|
|||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class MessageSigner1_19_0 {
|
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 pollLastMetadata() {
|
||||||
|
return TRACKED_METADATA_LIST.pollLast();
|
||||||
public static MessageMetadata get() {
|
|
||||||
MessageMetadata i = TRACKED_METADATA_LIST.get(TRACKED_METADATA_LIST.size() - 1);
|
|
||||||
TRACKED_METADATA_LIST.remove(i);
|
|
||||||
return i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void track(final MessageMetadata metadata) {
|
public static void track(final MessageMetadata metadata) {
|
||||||
|
@ -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.
|
// 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 class ProtocolPatcher1_19_0 {
|
||||||
|
|
||||||
public static boolean shouldFixKeys = false;
|
public static boolean shouldPatchKeys = false;
|
||||||
|
|
||||||
public static void patch() {
|
public static void patch() {
|
||||||
final Protocol1_19_1To1_19 protocol1_19_1To1_19 = Via.getManager().getProtocolManager().getProtocol(Protocol1_19_1To1_19.class);
|
final Protocol1_19_1To1_19 protocol1_19_1To1_19 = Via.getManager().getProtocolManager().getProtocol(Protocol1_19_1To1_19.class);
|
||||||
|
Loading…
Reference in New Issue
Block a user