3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-24 15:20:15 +01:00

1.13-pre4 + ProtocolPipeline changes

Dieser Commit ist enthalten in:
creeper123123321 2018-06-27 09:39:38 -03:00
Ursprung 6f98e35dec
Commit df2d9ba3d8
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 0AC57D54786721D1
15 geänderte Dateien mit 320 neuen und 18 gelöschten Zeilen

Datei anzeigen

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>1.4.0-1.13-pre3</version>
<version>1.4.0-1.13-pre4</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Datei anzeigen

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>1.4.0-1.13-pre3</version>
<version>1.4.0-1.13-pre4</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Datei anzeigen

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>1.4.0-1.13-pre3</version>
<version>1.4.0-1.13-pre4</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Datei anzeigen

@ -48,7 +48,7 @@ public class ProtocolPipeline extends Protocol {
/**
* Add a protocol to the current pipeline
* This will call the .init method.
* This will call the Protocol#init method.
*
* @param protocol The protocol to add to the end
*/
@ -56,6 +56,9 @@ public class ProtocolPipeline extends Protocol {
if (protocolList != null) {
protocolList.add(protocol);
protocol.init(userConnection);
// Move BaseProtocol to end, so the login packets can be modified by other protocols
protocolList.remove(ProtocolRegistry.BASE_PROTOCOL);
protocolList.add(ProtocolRegistry.BASE_PROTOCOL);
} else {
throw new NullPointerException("Tried to add protocol to early");
}
@ -71,6 +74,7 @@ public class ProtocolPipeline extends Protocol {
// Apply protocols
packetWrapper.apply(direction, state, 0, protocols);
int transformedId = packetWrapper.getId();
super.transform(direction, state, packetWrapper);
@ -78,19 +82,33 @@ public class ProtocolPipeline extends Protocol {
// Debug packet
String packet = "UNKNOWN";
int serverProtocol = userConnection.get(ProtocolInfo.class).getServerProtocolVersion();
int clientProtocol = userConnection.get(ProtocolInfo.class).getProtocolVersion();
// For 1.8/1.9 server version, eventually we'll probably get an API for this...
if (ProtocolRegistry.SERVER_PROTOCOL >= ProtocolVersion.v1_8.getId() &&
ProtocolRegistry.SERVER_PROTOCOL <= ProtocolVersion.v1_9_3.getId()) {
if (serverProtocol >= ProtocolVersion.v1_8.getId() &&
serverProtocol <= ProtocolVersion.v1_9_3.getId()
|| clientProtocol >= ProtocolVersion.v1_8.getId() &&
clientProtocol <= ProtocolVersion.v1_9_3.getId()) {
PacketType type;
if (ProtocolRegistry.SERVER_PROTOCOL <= ProtocolVersion.v1_8.getId()) {
if (serverProtocol <= ProtocolVersion.v1_8.getId()) {
if (direction == Direction.INCOMING) {
type = PacketType.findNewPacket(state, direction, originalID);
} else {
type = PacketType.findOldPacket(state, direction, originalID);
}
} else {
} else if (serverProtocol <= ProtocolVersion.v1_9_3.getId()) {
type = PacketType.findNewPacket(state, direction, originalID);
} else if (clientProtocol <= ProtocolVersion.v1_8.getId()) {
if (direction == Direction.INCOMING) {
type = PacketType.findNewPacket(state, direction, transformedId);
} else {
type = PacketType.findOldPacket(state, direction, transformedId);
}
} else {
type = PacketType.findNewPacket(state, direction, transformedId);
}
if (type != null) {
// Filter :) This would be not hard coded too, sorry :(
@ -108,7 +126,7 @@ public class ProtocolPipeline extends Protocol {
packet = type.name();
}
}
String name = packet + "[" + userConnection.get(ProtocolInfo.class).getProtocolVersion() + "]";
String name = packet + "[" + clientProtocol + "]";
ViaPlatform platform = Via.getPlatform();
String actualUsername = packetWrapper.user().get(ProtocolInfo.class).getUsername();

Datei anzeigen

@ -62,7 +62,7 @@ public class ProtocolVersion {
register(v1_12 = new ProtocolVersion(335, "1.12"));
register(v1_12_1 = new ProtocolVersion(338, "1.12.1"));
register(v1_12_2 = new ProtocolVersion(340, "1.12.2"));
register(v1_13 = new ProtocolVersion(385, "1.13-pre3"));
register(v1_13 = new ProtocolVersion(386, "1.13-pre4"));
register(unknown = new ProtocolVersion(-1, "UNKNOWN"));
}

Datei anzeigen

@ -53,6 +53,8 @@ public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
/* Variable Types */
public static final Type<Integer> VAR_INT = new VarIntType();
public static final Type<Integer[]> VAR_INT_ARRAY = new ArrayType<>(Type.VAR_INT);
public static final Type<Long> VAR_LONG = new VarLongType();
public static final Type<Long[]> VAR_LONG_ARRAY = new ArrayType<>(Type.VAR_LONG);
/* Special Types */
public static final Type<Void> NOTHING = new VoidType(); // This is purely used for remapping.
/* MC Types */

Datei anzeigen

@ -0,0 +1,65 @@
package us.myles.ViaVersion.api.type.types;
import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.TypeConverter;
public class VarLongType extends Type<Long> implements TypeConverter<Long> {
public VarLongType() {
super("VarLong", Long.class);
}
@Override
public void write(ByteBuf buffer, Long object) {
int part;
while (true) {
part = (int) (object & 0x7F);
object >>>= 7;
if (object != 0) {
part |= 0x80;
}
buffer.writeByte(part);
if (object == 0) {
break;
}
}
}
@Override
public Long read(ByteBuf buffer) {
long out = 0;
int bytes = 0;
byte in;
while (true) {
in = buffer.readByte();
out |= (in & 0x7F) << (bytes++ * 7);
if (bytes > 10) { // 10 is maxBytes
throw new RuntimeException("VarLong too big");
}
if ((in & 0x80) != 0x80) {
break;
}
}
return out;
}
@Override
public Long from(Object o) {
if (o instanceof Number) {
return ((Number) o).longValue();
}
if (o instanceof Boolean) {
return ((Boolean) o) ? 1L : 0L;
}
return (Long) o;
}
}

Datei anzeigen

@ -179,6 +179,7 @@ public class BaseProtocol extends Protocol {
}
// Choose the pipe
int protocol = Via.getManager().getProviders().get(VersionProvider.class).getServerProtocol(wrapper.user());
info.setServerProtocolVersion(protocol);
List<Pair<Integer, Protocol>> protocols = null;
// Only allow newer clients or (1.9.2 on 1.9.4 server if the server supports it)
@ -216,7 +217,7 @@ public class BaseProtocol extends Protocol {
handler(new PacketHandler() {
@Override
public void handle(final PacketWrapper wrapper) throws Exception {
int protocol = wrapper.user().get(ProtocolInfo.class).getProtocolVersion();
int protocol = wrapper.user().get(ProtocolInfo.class).getServerProtocolVersion();
if (protocol < ProtocolVersion.v1_13.getId())
handleLoginStart(wrapper);
}
@ -232,7 +233,7 @@ public class BaseProtocol extends Protocol {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int protocol = wrapper.user().get(ProtocolInfo.class).getProtocolVersion();
int protocol = wrapper.user().get(ProtocolInfo.class).getServerProtocolVersion();
if (protocol >= ProtocolVersion.v1_13.getId())
handleLoginStart(wrapper);
}

Datei anzeigen

@ -14,6 +14,7 @@ import java.util.UUID;
public class ProtocolInfo extends StoredObject {
private State state = State.HANDSHAKE;
private int protocolVersion = -1;
private int serverProtocolVersion = -1;
private String username;
private UUID uuid;
private ProtocolPipeline pipeline;

Datei anzeigen

@ -5,6 +5,7 @@ import net.md_5.bungee.chat.ComponentSerializer;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.entities.Entity1_13Types;
import us.myles.ViaVersion.api.minecraft.Position;
import us.myles.ViaVersion.api.platform.providers.ViaProviders;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketHandler;
@ -463,8 +464,34 @@ public class ProtocolSnapshotTo1_12_2 extends Protocol {
}
});
// New 0x0A - Edit book
registerIncoming(State.PLAY, 0x0b, 0x0c);
registerIncoming(State.PLAY, 0x0A, 0x0B);
registerIncoming(State.PLAY, 0x0c, 0x0d);
registerIncoming(State.PLAY, 0x0d, 0x0e);
registerIncoming(State.PLAY, 0x0e, 0x0f);
registerIncoming(State.PLAY, 0x0f, 0x10);
registerIncoming(State.PLAY, 0x10, 0x11);
registerIncoming(State.PLAY, 0x11, 0x12);
// New 0x13 - Pick Item
registerIncoming(State.PLAY, -1, 0x13, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int slot = wrapper.read(Type.VAR_INT);
wrapper.clearPacket();
wrapper.setId(0x09); // Plugin Message
wrapper.write(Type.STRING, "MC|PickItem");
wrapper.write(Type.VAR_INT, slot);
}
});
}
});
// Craft recipe request
registerIncoming(State.PLAY, 0x12, 0x12, new PacketRemapper() {
registerIncoming(State.PLAY, 0x12, 0x14, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@ -477,6 +504,193 @@ public class ProtocolSnapshotTo1_12_2 extends Protocol {
}
});
registerIncoming(State.PLAY, 0x13, 0x15);
registerIncoming(State.PLAY, 0x14, 0x16);
registerIncoming(State.PLAY, 0x15, 0x17);
registerIncoming(State.PLAY, 0x16, 0x18);
registerIncoming(State.PLAY, 0x17, 0x19);
// New 0x1A - Name Item
registerIncoming(State.PLAY, -1, 0x1A, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
String name = wrapper.read(Type.STRING);
wrapper.clearPacket();
wrapper.setId(0x09); // Plugin Message
wrapper.write(Type.STRING, "MC|ItemName");
wrapper.write(Type.STRING, name);
}
});
}
});
registerIncoming(State.PLAY, 0x18, 0x1B);
registerIncoming(State.PLAY, 0x19, 0x1C);
// New 0x1D - Select Trade
registerIncoming(State.PLAY, -1, 0x1D, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int slot = wrapper.read(Type.INT);
wrapper.clearPacket();
wrapper.setId(0x09); // Plugin Message
wrapper.write(Type.STRING, "MC|TrSel");
wrapper.write(Type.VAR_INT, slot);
}
});
}
});
// New 0x1E - Set Beacon Effect
registerIncoming(State.PLAY, -1, 0x1E, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int potion = wrapper.read(Type.INT);
wrapper.clearPacket();
wrapper.setId(0x09); // Plugin Message
wrapper.write(Type.STRING, "MC|Beacon");
wrapper.write(Type.VAR_INT, potion);
}
});
}
});
registerIncoming(State.PLAY, 0x1A, 0x1F);
// New 0x20 - Update Command Block
registerIncoming(State.PLAY, -1, 0x20, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Position position = wrapper.read(Type.POSITION);
String command = wrapper.read(Type.STRING);
int mode = wrapper.read(Type.VAR_INT);
byte flags = wrapper.read(Type.BYTE);
String stringMode = mode == 0 ? "SEQUENCE"
: mode == 1 ? "AUTO"
: "REDSTONE";
wrapper.clearPacket();
wrapper.setId(0x09); // Plugin Message
wrapper.write(Type.STRING, "MC|AutoCmd");
wrapper.write(Type.INT, position.getX().intValue());
wrapper.write(Type.INT, position.getY().intValue());
wrapper.write(Type.INT, position.getZ().intValue());
wrapper.write(Type.STRING, command);
wrapper.write(Type.BOOLEAN, (flags & 0x1) != 0); // Track output
wrapper.write(Type.STRING, stringMode);
wrapper.write(Type.BOOLEAN, (flags & 0x2) != 0); // Is conditional
wrapper.write(Type.BOOLEAN, (flags & 0x4) != 0); // Automatic
}
});
}
});
// New 0x21 - Update Command Block Minecart
registerIncoming(State.PLAY, -1, 0x21, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int entityId = wrapper.read(Type.INT);
String command = wrapper.read(Type.STRING);
boolean trackOutput = wrapper.read(Type.BOOLEAN);
wrapper.clearPacket();
wrapper.setId(0x09); // Plugin Message
wrapper.write(Type.STRING, "MC|AdvCmd");
wrapper.write(Type.VAR_INT, entityId);
wrapper.write(Type.STRING, command);
wrapper.write(Type.BOOLEAN, trackOutput);
}
});
}
});
// 0x1B -> 0x22 in InventoryPackets
// New 0x23 - Update Structure Block
registerIncoming(State.PLAY, -1, 0x23, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Position pos = wrapper.read(Type.POSITION);
int action = wrapper.read(Type.VAR_INT);
int mode = wrapper.read(Type.VAR_INT);
String name = wrapper.read(Type.STRING);
byte offsetX = wrapper.read(Type.BYTE);
byte offsetY = wrapper.read(Type.BYTE);
byte offsetZ = wrapper.read(Type.BYTE);
byte sizeX = wrapper.read(Type.BYTE);
byte sizeY = wrapper.read(Type.BYTE);
byte sizeZ = wrapper.read(Type.BYTE);
int mirror = wrapper.read(Type.VAR_INT);
int rotation = wrapper.read(Type.VAR_INT);
String metadata = wrapper.read(Type.STRING);
float integrity = wrapper.read(Type.FLOAT);
long seed = wrapper.read(Type.VAR_LONG);
byte flags = wrapper.read(Type.BYTE);
String stringMode = mode == 0 ? "SAVE"
: mode == 1 ? "LOAD"
: mode == 2 ? "CORNER"
: "DATA";
String stringMirror = mirror == 0 ? "NONE"
: mirror == 1 ? "LEFT_RIGHT"
: "FRONT_BACK";
String stringRotation = mirror == 0 ? "NONE"
: mirror == 1 ? "CLOCKWISE_90"
: mirror == 2 ? "CLOCKWISE_180"
: "COUNTERCLOCKWISE_90";
wrapper.clearPacket();
wrapper.setId(0x09); // Plugin Message
wrapper.write(Type.STRING, "MC|Struct");
wrapper.write(Type.INT, pos.getX().intValue());
wrapper.write(Type.INT, pos.getY().intValue());
wrapper.write(Type.INT, pos.getZ().intValue());
wrapper.write(Type.BYTE, (byte) (action + 1));
wrapper.write(Type.STRING, stringMode);
wrapper.write(Type.STRING, name);
wrapper.write(Type.INT, (int) offsetX);
wrapper.write(Type.INT, (int) offsetY);
wrapper.write(Type.INT, (int) offsetZ);
wrapper.write(Type.INT, (int) sizeX);
wrapper.write(Type.INT, (int) sizeY);
wrapper.write(Type.INT, (int) sizeZ);
wrapper.write(Type.STRING, stringMirror);
wrapper.write(Type.STRING, stringRotation);
wrapper.write(Type.STRING, metadata);
wrapper.write(Type.BOOLEAN, (flags & 0x1) != 0); // Ignore Entities
wrapper.write(Type.BOOLEAN, (flags & 0x2) != 0); // Show air
wrapper.write(Type.BOOLEAN, (flags & 0x4) != 0); // Show bounding box
wrapper.write(Type.FLOAT, integrity);
wrapper.write(Type.VAR_LONG, seed);
}
});
}
});
registerIncoming(State.PLAY, 0x1C, 0x24);
registerIncoming(State.PLAY, 0x1D, 0x25);
registerIncoming(State.PLAY, 0x1E, 0x26);
registerIncoming(State.PLAY, 0x1F, 0x27);
// Recipe Book Data
registerIncoming(State.PLAY, 0x17, 0x17, new PacketRemapper() {
@Override

Datei anzeigen

@ -136,6 +136,7 @@ public class InventoryPackets {
} else {
wrapper.cancel(); // TODO REGISTER channel removed?
}
// TODO message channel to new packets rewriting
wrapper.set(Type.STRING, 0, channel);
}
});
@ -188,7 +189,7 @@ public class InventoryPackets {
);
// Creative Inventory Action
protocol.registerIncoming(State.PLAY, 0x1B, 0x1B, new PacketRemapper() {
protocol.registerIncoming(State.PLAY, 0x1B, 0x22, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.SHORT); // 0 - Slot

Datei anzeigen

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>1.4.0-1.13-pre3</version>
<version>1.4.0-1.13-pre4</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<name>viaversion-jar</name>

Datei anzeigen

@ -6,7 +6,7 @@
<groupId>us.myles</groupId>
<artifactId>viaversion-parent</artifactId>
<version>1.4.0-1.13-pre3</version>
<version>1.4.0-1.13-pre4</version>
<packaging>pom</packaging>
<name>viaversion-parent</name>

Datei anzeigen

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>1.4.0-1.13-pre3</version>
<version>1.4.0-1.13-pre4</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Datei anzeigen

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>1.4.0-1.13-pre3</version>
<version>1.4.0-1.13-pre4</version>
</parent>
<modelVersion>4.0.0</modelVersion>