3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-20 06:50:08 +01:00

22w17a (and a lot of dread)

Dieser Commit ist enthalten in:
Nassim Jahnke 2022-04-27 21:06:34 +02:00
Ursprung 8df48bc378
Commit 0e66228a96
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
8 geänderte Dateien mit 240 neuen und 67 gelöschten Zeilen

Datei anzeigen

@ -58,6 +58,15 @@ public interface UserConnection {
*/ */
boolean has(Class<? extends StorableObject> objectClass); boolean has(Class<? extends StorableObject> objectClass);
/**
* Removes and returns an object from the storage.
*
* @param objectClass class of the object to get
* @param <T> type of the class you want to get
* @return removed storable object if present
*/
@Nullable <T extends StorableObject> T remove(Class<T> objectClass);
/** /**
* Put an object into the stored objects based on class. * Put an object into the stored objects based on class.
* *

Datei anzeigen

@ -80,7 +80,7 @@ public class ProtocolVersion {
public static final ProtocolVersion v1_17_1 = register(756, "1.17.1"); public static final ProtocolVersion v1_17_1 = register(756, "1.17.1");
public static final ProtocolVersion v1_18 = register(757, "1.18/1.18.1", new VersionRange("1.18", 0, 1)); public static final ProtocolVersion v1_18 = register(757, "1.18/1.18.1", new VersionRange("1.18", 0, 1));
public static final ProtocolVersion v1_18_2 = register(758, "1.18.2"); public static final ProtocolVersion v1_18_2 = register(758, "1.18.2");
public static final ProtocolVersion v1_19 = register(759, 81, "1.19"); public static final ProtocolVersion v1_19 = register(759, 82, "1.19");
public static final ProtocolVersion unknown = register(-1, "UNKNOWN"); public static final ProtocolVersion unknown = register(-1, "UNKNOWN");
public static ProtocolVersion register(int version, String name) { public static ProtocolVersion register(int version, String name) {

Datei anzeigen

@ -93,6 +93,11 @@ public class UserConnectionImpl implements UserConnection {
return storedObjects.containsKey(objectClass); return storedObjects.containsKey(objectClass);
} }
@Override
public <T extends StorableObject> @Nullable T remove(Class<T> objectClass) {
return (T) storedObjects.remove(objectClass);
}
@Override @Override
public void put(StorableObject object) { public void put(StorableObject object) {
storedObjects.put(object.getClass(), object); storedObjects.put(object.getClass(), object);

Datei anzeigen

@ -33,7 +33,6 @@ public enum ClientboundPackets1_19 implements ClientboundPacketType {
BLOCK_CHANGE, // 0x09 BLOCK_CHANGE, // 0x09
BOSSBAR, // 0x0A BOSSBAR, // 0x0A
SERVER_DIFFICULTY, // 0x0B SERVER_DIFFICULTY, // 0x0B
CHAT_MESSAGE, // 0x0C
CLEAR_TITLES, // 0x0D CLEAR_TITLES, // 0x0D
TAB_COMPLETE, // 0x0E TAB_COMPLETE, // 0x0E
DECLARE_COMMANDS, // 0x0F DECLARE_COMMANDS, // 0x0F
@ -69,6 +68,7 @@ public enum ClientboundPackets1_19 implements ClientboundPacketType {
PING, // 0x2D PING, // 0x2D
CRAFT_RECIPE_RESPONSE, // 0x2E CRAFT_RECIPE_RESPONSE, // 0x2E
PLAYER_ABILITIES, // 0x2F PLAYER_ABILITIES, // 0x2F
PLAYER_CHAT,
COMBAT_END, // 0x30 COMBAT_END, // 0x30
COMBAT_ENTER, // 0x31 COMBAT_ENTER, // 0x31
COMBAT_KILL, // 0x32 COMBAT_KILL, // 0x32
@ -113,6 +113,7 @@ public enum ClientboundPackets1_19 implements ClientboundPacketType {
ENTITY_SOUND, // 0x59 ENTITY_SOUND, // 0x59
SOUND, // 0x5A SOUND, // 0x5A
STOP_SOUND, // 0x5B STOP_SOUND, // 0x5B
SYSTEM_CHAT,
TAB_LIST, // 0x5C TAB_LIST, // 0x5C
NBT_QUERY, // 0x5D NBT_QUERY, // 0x5D
COLLECT_ITEM, // 0x5E COLLECT_ITEM, // 0x5E

Datei anzeigen

@ -17,12 +17,14 @@
*/ */
package com.viaversion.viaversion.protocols.protocol1_19to1_18_2; package com.viaversion.viaversion.protocols.protocol1_19to1_18_2;
import com.google.gson.JsonObject;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.MappingData; import com.viaversion.viaversion.api.data.MappingData;
import com.viaversion.viaversion.api.data.MappingDataBase; import com.viaversion.viaversion.api.data.MappingDataBase;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_19Types; import com.viaversion.viaversion.api.minecraft.entities.Entity1_19Types;
import com.viaversion.viaversion.api.protocol.AbstractProtocol; import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper; import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
import com.viaversion.viaversion.api.rewriter.EntityRewriter; import com.viaversion.viaversion.api.rewriter.EntityRewriter;
import com.viaversion.viaversion.api.rewriter.ItemRewriter; import com.viaversion.viaversion.api.rewriter.ItemRewriter;
@ -30,19 +32,43 @@ import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.minecraft.ParticleType; import com.viaversion.viaversion.api.type.types.minecraft.ParticleType;
import com.viaversion.viaversion.api.type.types.version.Types1_19; import com.viaversion.viaversion.api.type.types.version.Types1_19;
import com.viaversion.viaversion.data.entity.EntityTrackerBase; import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets;
import com.viaversion.viaversion.protocols.base.ServerboundLoginPackets;
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ServerboundPackets1_17; import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ServerboundPackets1_17;
import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.ClientboundPackets1_18; import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.ClientboundPackets1_18;
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.packets.EntityPackets; import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.packets.EntityPackets;
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.packets.InventoryPackets; import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.packets.InventoryPackets;
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.packets.WorldPackets; import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.packets.WorldPackets;
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.storage.NonceStorage;
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.storage.SequenceStorage; import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.storage.SequenceStorage;
import com.viaversion.viaversion.rewriter.CommandRewriter; import com.viaversion.viaversion.rewriter.CommandRewriter;
import com.viaversion.viaversion.rewriter.SoundRewriter; import com.viaversion.viaversion.rewriter.SoundRewriter;
import com.viaversion.viaversion.rewriter.TagRewriter; import com.viaversion.viaversion.rewriter.TagRewriter;
import javax.crypto.Cipher;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.PublicKey;
import java.security.spec.EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
public final class Protocol1_19To1_18_2 extends AbstractProtocol<ClientboundPackets1_18, ClientboundPackets1_19, ServerboundPackets1_17, ServerboundPackets1_17> { public final class Protocol1_19To1_18_2 extends AbstractProtocol<ClientboundPackets1_18, ClientboundPackets1_19, ServerboundPackets1_17, ServerboundPackets1_17> {
public static final MappingData MAPPINGS = new MappingDataBase("1.18", "1.19", true); public static final MappingData MAPPINGS = new MappingDataBase("1.18", "1.19", true);
private static final JsonObject EMPTY_COMPONENT = new JsonObject();
private static final KeyFactory RSA_FACTORY;
static {
try {
RSA_FACTORY = KeyFactory.getInstance("RSA");
} catch (final NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
EMPTY_COMPONENT.addProperty("text", "");
}
private static final byte[] EMPTY_BYTES = new byte[0];
private final EntityPackets entityRewriter = new EntityPackets(this); private final EntityPackets entityRewriter = new EntityPackets(this);
private final InventoryPackets itemRewriter = new InventoryPackets(this); private final InventoryPackets itemRewriter = new InventoryPackets(this);
@ -140,6 +166,93 @@ public final class Protocol1_19To1_18_2 extends AbstractProtocol<ClientboundPack
}); });
} }
}); });
// Make every message a system message, including player ones; we don't want to analyze and remove player names from the original component
registerClientbound(ClientboundPackets1_18.CHAT_MESSAGE, ClientboundPackets1_19.SYSTEM_CHAT, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.COMPONENT); // Message
map(Type.BYTE); // Type
read(Type.UUID); // Sender
}
});
registerServerbound(ServerboundPackets1_17.CHAT_MESSAGE, new PacketRemapper() {
@Override
public void registerMap() {
read(Type.LONG); // Timestamp
map(Type.STRING); // Message
read(Type.LONG); // Salt
read(Type.BYTE_ARRAY_PRIMITIVE); // Signature
}
});
// Login changes
registerClientbound(State.LOGIN, ClientboundLoginPackets.GAME_PROFILE.getId(), ClientboundLoginPackets.GAME_PROFILE.getId(), new PacketRemapper() {
@Override
public void registerMap() {
map(Type.UUID_INT_ARRAY, Type.UUID); // UUID
map(Type.STRING); // Name
handler(wrapper -> {
// No properties
wrapper.write(Type.VAR_INT, 0);
});
}
});
registerClientbound(State.LOGIN, ClientboundLoginPackets.HELLO.getId(), ClientboundLoginPackets.HELLO.getId(), new PacketRemapper() {
@Override
public void registerMap() {
map(Type.STRING); // Server id
map(Type.BYTE_ARRAY_PRIMITIVE); // Public key
map(Type.BYTE_ARRAY_PRIMITIVE); // Nonce
handler(wrapper -> {
final byte[] pubKey = wrapper.get(Type.BYTE_ARRAY_PRIMITIVE, 0);
final byte[] nonce = wrapper.get(Type.BYTE_ARRAY_PRIMITIVE, 1);
final EncodedKeySpec keySpec = new X509EncodedKeySpec(pubKey);
final PublicKey key = RSA_FACTORY.generatePublic(keySpec);
final Cipher cipher = Cipher.getInstance(key.getAlgorithm());
cipher.init(Cipher.ENCRYPT_MODE, key);
wrapper.user().put(new NonceStorage(cipher.doFinal(nonce)));
});
}
});
registerServerbound(State.LOGIN, ServerboundLoginPackets.HELLO.getId(), ServerboundLoginPackets.HELLO.getId(), new PacketRemapper() {
@Override
public void registerMap() {
map(Type.STRING); // Name
handler(wrapper -> {
// Read the public key
if (wrapper.read(Type.BOOLEAN)) {
wrapper.read(Type.NBT);
}
});
}
});
registerServerbound(State.LOGIN, ServerboundLoginPackets.ENCRYPTION_KEY.getId(), ServerboundLoginPackets.ENCRYPTION_KEY.getId(), new PacketRemapper() {
@Override
public void registerMap() {
map(Type.BYTE_ARRAY_PRIMITIVE); // Keys
handler(wrapper -> {
if (wrapper.read(Type.BOOLEAN)) {
// Nonce, just pass it through
wrapper.passthrough(Type.BYTE_ARRAY_PRIMITIVE);
} else {
// 🧂
final NonceStorage nonceStorage = wrapper.user().remove(NonceStorage.class);
if (nonceStorage == null) {
throw new IllegalArgumentException("Server sent nonce is missing");
}
wrapper.read(Type.LONG); // Salt
wrapper.read(Type.BYTE_ARRAY_PRIMITIVE); // Signature
wrapper.write(Type.BYTE_ARRAY_PRIMITIVE, nonceStorage.nonce());
}
});
}
});
} }
@Override @Override

Datei anzeigen

@ -0,0 +1,33 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2022 ViaVersion 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 com.viaversion.viaversion.protocols.protocol1_19to1_18_2.storage;
import com.viaversion.viaversion.api.connection.StorableObject;
public final class NonceStorage implements StorableObject {
private final byte[] nonce;
public NonceStorage(final byte[] nonce) {
this.nonce = nonce;
}
public byte[] nonce() {
return nonce;
}
}

Datei anzeigen

@ -23472,70 +23472,71 @@
"1084": "minecraft:mojang_banner_pattern", "1084": "minecraft:mojang_banner_pattern",
"1085": "minecraft:globe_banner_pattern", "1085": "minecraft:globe_banner_pattern",
"1086": "minecraft:piglin_banner_pattern", "1086": "minecraft:piglin_banner_pattern",
"1087": "minecraft:composter", "1087": "minecraft:goat_horn",
"1088": "minecraft:barrel", "1088": "minecraft:composter",
"1089": "minecraft:smoker", "1089": "minecraft:barrel",
"1090": "minecraft:blast_furnace", "1090": "minecraft:smoker",
"1091": "minecraft:cartography_table", "1091": "minecraft:blast_furnace",
"1092": "minecraft:fletching_table", "1092": "minecraft:cartography_table",
"1093": "minecraft:grindstone", "1093": "minecraft:fletching_table",
"1094": "minecraft:smithing_table", "1094": "minecraft:grindstone",
"1095": "minecraft:stonecutter", "1095": "minecraft:smithing_table",
"1096": "minecraft:bell", "1096": "minecraft:stonecutter",
"1097": "minecraft:lantern", "1097": "minecraft:bell",
"1098": "minecraft:soul_lantern", "1098": "minecraft:lantern",
"1099": "minecraft:sweet_berries", "1099": "minecraft:soul_lantern",
"1100": "minecraft:glow_berries", "1100": "minecraft:sweet_berries",
"1101": "minecraft:campfire", "1101": "minecraft:glow_berries",
"1102": "minecraft:soul_campfire", "1102": "minecraft:campfire",
"1103": "minecraft:shroomlight", "1103": "minecraft:soul_campfire",
"1104": "minecraft:honeycomb", "1104": "minecraft:shroomlight",
"1105": "minecraft:bee_nest", "1105": "minecraft:honeycomb",
"1106": "minecraft:beehive", "1106": "minecraft:bee_nest",
"1107": "minecraft:honey_bottle", "1107": "minecraft:beehive",
"1108": "minecraft:honeycomb_block", "1108": "minecraft:honey_bottle",
"1109": "minecraft:lodestone", "1109": "minecraft:honeycomb_block",
"1110": "minecraft:crying_obsidian", "1110": "minecraft:lodestone",
"1111": "minecraft:blackstone", "1111": "minecraft:crying_obsidian",
"1112": "minecraft:blackstone_slab", "1112": "minecraft:blackstone",
"1113": "minecraft:blackstone_stairs", "1113": "minecraft:blackstone_slab",
"1114": "minecraft:gilded_blackstone", "1114": "minecraft:blackstone_stairs",
"1115": "minecraft:polished_blackstone", "1115": "minecraft:gilded_blackstone",
"1116": "minecraft:polished_blackstone_slab", "1116": "minecraft:polished_blackstone",
"1117": "minecraft:polished_blackstone_stairs", "1117": "minecraft:polished_blackstone_slab",
"1118": "minecraft:chiseled_polished_blackstone", "1118": "minecraft:polished_blackstone_stairs",
"1119": "minecraft:polished_blackstone_bricks", "1119": "minecraft:chiseled_polished_blackstone",
"1120": "minecraft:polished_blackstone_brick_slab", "1120": "minecraft:polished_blackstone_bricks",
"1121": "minecraft:polished_blackstone_brick_stairs", "1121": "minecraft:polished_blackstone_brick_slab",
"1122": "minecraft:cracked_polished_blackstone_bricks", "1122": "minecraft:polished_blackstone_brick_stairs",
"1123": "minecraft:respawn_anchor", "1123": "minecraft:cracked_polished_blackstone_bricks",
"1124": "minecraft:candle", "1124": "minecraft:respawn_anchor",
"1125": "minecraft:white_candle", "1125": "minecraft:candle",
"1126": "minecraft:orange_candle", "1126": "minecraft:white_candle",
"1127": "minecraft:magenta_candle", "1127": "minecraft:orange_candle",
"1128": "minecraft:light_blue_candle", "1128": "minecraft:magenta_candle",
"1129": "minecraft:yellow_candle", "1129": "minecraft:light_blue_candle",
"1130": "minecraft:lime_candle", "1130": "minecraft:yellow_candle",
"1131": "minecraft:pink_candle", "1131": "minecraft:lime_candle",
"1132": "minecraft:gray_candle", "1132": "minecraft:pink_candle",
"1133": "minecraft:light_gray_candle", "1133": "minecraft:gray_candle",
"1134": "minecraft:cyan_candle", "1134": "minecraft:light_gray_candle",
"1135": "minecraft:purple_candle", "1135": "minecraft:cyan_candle",
"1136": "minecraft:blue_candle", "1136": "minecraft:purple_candle",
"1137": "minecraft:brown_candle", "1137": "minecraft:blue_candle",
"1138": "minecraft:green_candle", "1138": "minecraft:brown_candle",
"1139": "minecraft:red_candle", "1139": "minecraft:green_candle",
"1140": "minecraft:black_candle", "1140": "minecraft:red_candle",
"1141": "minecraft:small_amethyst_bud", "1141": "minecraft:black_candle",
"1142": "minecraft:medium_amethyst_bud", "1142": "minecraft:small_amethyst_bud",
"1143": "minecraft:large_amethyst_bud", "1143": "minecraft:medium_amethyst_bud",
"1144": "minecraft:amethyst_cluster", "1144": "minecraft:large_amethyst_bud",
"1145": "minecraft:pointed_dripstone", "1145": "minecraft:amethyst_cluster",
"1146": "minecraft:ochre_froglight", "1146": "minecraft:pointed_dripstone",
"1147": "minecraft:verdant_froglight", "1147": "minecraft:ochre_froglight",
"1148": "minecraft:pearlescent_froglight", "1148": "minecraft:verdant_froglight",
"1149": "minecraft:frogspawn", "1149": "minecraft:pearlescent_froglight",
"1150": "minecraft:echo_shard" "1150": "minecraft:frogspawn",
"1151": "minecraft:echo_shard"
}, },
"sounds": [ "sounds": [
"entity.allay.ambient_with_item", "entity.allay.ambient_with_item",
@ -24008,6 +24009,8 @@
"entity.goat.milk", "entity.goat.milk",
"entity.goat.prepare_ram", "entity.goat.prepare_ram",
"entity.goat.ram_impact", "entity.goat.ram_impact",
"entity.goat.horn_break",
"item.goat_horn.play",
"entity.goat.screaming.ambient", "entity.goat.screaming.ambient",
"entity.goat.screaming.death", "entity.goat.screaming.death",
"entity.goat.screaming.eat", "entity.goat.screaming.eat",
@ -24016,6 +24019,7 @@
"entity.goat.screaming.milk", "entity.goat.screaming.milk",
"entity.goat.screaming.prepare_ram", "entity.goat.screaming.prepare_ram",
"entity.goat.screaming.ram_impact", "entity.goat.screaming.ram_impact",
"entity.goat.screaming.horn_break",
"entity.goat.step", "entity.goat.step",
"block.grass.break", "block.grass.break",
"block.grass.fall", "block.grass.fall",
@ -24059,6 +24063,14 @@
"block.honey_block.step", "block.honey_block.step",
"item.honeycomb.wax_on", "item.honeycomb.wax_on",
"item.honey_bottle.drink", "item.honey_bottle.drink",
"item.goat_horn.sound.0",
"item.goat_horn.sound.1",
"item.goat_horn.sound.2",
"item.goat_horn.sound.3",
"item.goat_horn.sound.4",
"item.goat_horn.sound.5",
"item.goat_horn.sound.6",
"item.goat_horn.sound.7",
"entity.horse.ambient", "entity.horse.ambient",
"entity.horse.angry", "entity.horse.angry",
"entity.horse.armor", "entity.horse.armor",

Datei anzeigen

@ -1,5 +1,5 @@
# Project properties - we put these here so they can be modified without causing a recompile of the build scripts # Project properties - we put these here so they can be modified without causing a recompile of the build scripts
projectVersion=4.3.0-22w16b-SNAPSHOT projectVersion=4.3.0-22w17a-SNAPSHOT
# Gradle properties # Gradle properties
org.gradle.daemon=true org.gradle.daemon=true