Skip to content

Commit

Permalink
Add 15w31b client support
Browse files Browse the repository at this point in the history
  • Loading branch information
lowercasebtw committed Oct 16, 2024
1 parent 5441c10 commit d729d18
Show file tree
Hide file tree
Showing 9 changed files with 231 additions and 8 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
# ViaSnapshot

### ⚠️ WARNING: This is experimental and is not safe to use on public servers. Use at your own risk!
**Allows you to join servers from snapshots, using ViaProxy. Currently only supports 15w31a.**

**Allows you to join servers from snapshots, using ViaProxy.**

Supported Versions:

- 15w31a
- 15w31b

Known Issues:

- Item Drops are stone
- Entity metadata is missing
- Item interaction in newer versions is broken
Expand All @@ -11,6 +19,7 @@ Known Issues:
- And more, possibly on purpose as some packets were disabled

## Installation and Usage

1. Download the latest version from [GitHub Actions](https://github.com/ViaVersionAddons/ViaSnapshot/actions).
2. Put the jar file into the plugins folder of ViaProxy
3. Run ViaProxy. You should now be able to connect from a snapshot client to ViaProxy.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
import com.viaversion.viaversion.protocol.RedirectProtocolVersion;

public class SnapshotProtocolVersion {
public static final ProtocolVersion v15w31a = registerSnapshot(49, "15w31a (Client Only)", ProtocolVersion.v1_8);
public static final ProtocolVersion v15w31a = registerSnapshot1_8(49, "15w31a (Client Only)");
public static final ProtocolVersion v15w31b = registerSnapshot1_8(50, "15w31b (Client Only)");

private static ProtocolVersion registerSnapshot(final int version, final String name, final ProtocolVersion origin) {
final ProtocolVersion protocolVersion = new RedirectProtocolVersion(version, name, origin);
private static ProtocolVersion registerSnapshot1_8(final int version, final String name) {
final ProtocolVersion protocolVersion = new RedirectProtocolVersion(version, name, ProtocolVersion.v1_8);
ProtocolVersion.register(protocolVersion);
return protocolVersion;
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/btw/lowercase/viasnapshot/ViaSnapshot.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package btw.lowercase.viasnapshot;

import btw.lowercase.viasnapshot.protocol.v15w31ato1_8.Protocol15w31a_To1_8;
import btw.lowercase.viasnapshot.protocol.v15w31bto15w31a.Protocol15w31b_To15w31a;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.protocol.ProtocolManager;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
Expand All @@ -16,13 +17,13 @@ public void onEnable() {
}

@EventHandler
public void onInitializeEvent(ProtocolTranslatorInitEvent event) {
private void onInitializeEvent(ProtocolTranslatorInitEvent event) {
event.registerPlatform(() -> {
// Adds this to the VV dump
Via.getManager().getSubPlatforms().add(String.format("git-ViaSnapshot-%s", getVersion()));

final ProtocolManager protocolManager = Via.getManager().getProtocolManager();
protocolManager.registerProtocol(new Protocol15w31a_To1_8(), SnapshotProtocolVersion.v15w31a, ProtocolVersion.v1_8);
protocolManager.registerProtocol(new Protocol15w31b_To15w31a(), SnapshotProtocolVersion.v15w31b, SnapshotProtocolVersion.v15w31a);
return null;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public enum ClientboundPackets15w31a implements ClientboundPacketType {
RESOURCE_PACK,
UPDATE_ENTITY_NBT;

private ClientboundPackets15w31a() {
ClientboundPackets15w31a() {
}

public int getId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public enum ServerboundPackets15w31a implements ServerboundPacketType {
TELEPORT_TO_ENTITY,
RESOURCE_PACK;

private ServerboundPackets15w31a() {
ServerboundPackets15w31a() {
}

public int getId() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package btw.lowercase.viasnapshot.protocol.v15w31bto15w31a;

import btw.lowercase.viasnapshot.protocol.v15w31ato1_8.packet.ClientboundPackets15w31a;
import btw.lowercase.viasnapshot.protocol.v15w31ato1_8.packet.ServerboundPackets15w31a;
import btw.lowercase.viasnapshot.protocol.v15w31bto15w31a.packet.ClientboundPackets15w31b;
import btw.lowercase.viasnapshot.protocol.v15w31bto15w31a.packet.ServerboundPackets15w31b;
import btw.lowercase.viasnapshot.protocol.v15w31bto15w31a.rewriter.PacketRewriter15w31b;
import com.viaversion.viaversion.api.protocol.AbstractProtocol;

public class Protocol15w31b_To15w31a extends AbstractProtocol<ClientboundPackets15w31a, ClientboundPackets15w31b, ServerboundPackets15w31a, ServerboundPackets15w31b> {
public Protocol15w31b_To15w31a() {
super(ClientboundPackets15w31a.class, ClientboundPackets15w31b.class, ServerboundPackets15w31a.class, ServerboundPackets15w31b.class);
}

@Override
protected void registerPackets() {
PacketRewriter15w31b.register(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package btw.lowercase.viasnapshot.protocol.v15w31bto15w31a.packet;

import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;

public enum ClientboundPackets15w31b implements ClientboundPacketType {
KEEP_ALIVE,
LOGIN,
CHAT,
SET_TIME,
SET_EQUIPPED_ITEM,
SET_DEFAULT_SPAWN_POSITION,
SET_HEALTH,
RESPAWN,
PLAYER_POSITION,
SET_CARRIED_ITEM,
PLAYER_SLEEP,
ANIMATE,
ADD_PLAYER,
TAKE_ITEM_ENTITY,
ADD_ENTITY,
ADD_MOB,
ADD_PAINTING,
ADD_EXPERIENCE_ORB,
SET_ENTITY_MOTION,
REMOVE_ENTITIES,
MOVE_ENTITY,
MOVE_ENTITY_POS,
MOVE_ENTITY_ROT,
MOVE_ENTITY_POS_ROT,
TELEPORT_ENTITY,
ROTATE_HEAD,
ENTITY_EVENT,
SET_ENTITY_LINK,
SET_ENTITY_DATA,
UPDATE_MOB_EFFECT,
REMOVE_MOB_EFFECT,
SET_EXPERIENCE,
UPDATE_ATTRIBUTES,
LEVEL_CHUNK,
CHUNK_BLOCKS_UPDATE,
BLOCK_UPDATE,
BLOCK_EVENT,
BLOCK_DESTRUCTION,
MAP_BULK_CHUNK,
EXPLODE,
LEVEL_EVENT,
CUSTOM_SOUND,
LEVEL_PARTICLES,
GAME_EVENT,
ADD_GLOBAL_ENTITY,
OPEN_SCREEN,
CONTAINER_CLOSE,
CONTAINER_SET_SLOT,
CONTAINER_SET_CONTENT,
CONTAINER_SET_DATA,
CONTAINER_ACK,
UPDATE_SIGN,
MAP_ITEM_DATA,
BLOCK_ENTITY_DATA,
OPEN_SIGN_EDITOR,
AWARD_STATS,
PLAYER_INFO,
PLAYER_ABILITIES,
COMMAND_SUGGESTIONS,
SET_OBJECTIVE,
SET_SCORE,
SET_DISPLAY_OBJECTIVE,
SET_PLAYER_TEAM,
CUSTOM_PAYLOAD,
DISCONNECT,
CHANGE_DIFFICULTY,
PLAYER_COMBAT,
SET_CAMERA,
SET_BORDER,
SET_TITLES,
SET_COMPRESSION,
TAB_LIST,
RESOURCE_PACK,
BOSS_BAR;

ClientboundPackets15w31b() {
}

public int getId() {
return this.ordinal();
}

public String getName() {
return this.name();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package btw.lowercase.viasnapshot.protocol.v15w31bto15w31a.packet;

import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;

public enum ServerboundPackets15w31b implements ServerboundPacketType {
KEEP_ALIVE,
CHAT,
INTERACT,
MOVE_PLAYER_STATUS_ONLY,
MOVE_PLAYER_POS,
MOVE_PLAYER_ROT,
MOVE_PLAYER_POS_ROT,
PLAYER_ACTION,
USE_ITEM,
USE_ITEM_ON,
SET_CARRIED_ITEM,
SWING,
PLAYER_COMMAND,
PLAYER_INPUT,
CONTAINER_CLOSE,
CONTAINER_CLICK,
CONTAINER_ACK,
SET_CREATIVE_MODE_SLOT,
CONTAINER_BUTTON_CLICK,
SIGN_UPDATE,
PLAYER_ABILITIES,
COMMAND_SUGGESTION,
CLIENT_INFORMATION,
CLIENT_COMMAND,
CUSTOM_PAYLOAD,
TELEPORT_TO_ENTITY,
RESOURCE_PACK;

ServerboundPackets15w31b() {
}

public int getId() {
return this.ordinal();
}

public String getName() {
return this.name();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package btw.lowercase.viasnapshot.protocol.v15w31bto15w31a.rewriter;

import btw.lowercase.viasnapshot.protocol.v15w31ato1_8.packet.ClientboundPackets15w31a;
import btw.lowercase.viasnapshot.protocol.v15w31bto15w31a.Protocol15w31b_To15w31a;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.protocols.v1_8to1_9.Protocol1_8To1_9;

// https://wiki.vg/index.php?title=Pre-release_protocol&direction=prev&oldid=6751
public class PacketRewriter15w31b {
public static void register(final Protocol15w31b_To15w31a protocol) {
// Player List Item
protocol.registerClientbound(ClientboundPackets15w31a.PLAYER_INFO, new PacketHandlers() {
public void register() {
map(Types.VAR_INT); // Action
map(Types.VAR_INT); // Count
handler((wrapper) -> {
final int action = wrapper.get(Types.VAR_INT, 0);
final int count = wrapper.get(Types.VAR_INT, 1);
for (int i = 0; i < count; ++i) {
wrapper.passthrough(Types.UUID); // UUID
if (action != 0) {
if (action != 1 && action != 2) {
// Update Display Name
if (action == 3) {
String displayName = wrapper.read(Types.OPTIONAL_STRING);
wrapper.write(Types.OPTIONAL_COMPONENT, displayName != null ? Protocol1_8To1_9.STRING_TO_JSON.transform(wrapper, displayName) : null);
}
} else {
// ?
wrapper.passthrough(Types.VAR_INT);
}
} else {
// Add Player
wrapper.passthrough(Types.STRING); // Name

final int properties = wrapper.passthrough(Types.VAR_INT); // Number of properties
for (int j = 0; j < properties; ++j) {
wrapper.passthrough(Types.STRING);
wrapper.passthrough(Types.STRING);
wrapper.passthrough(Types.OPTIONAL_STRING);
}

wrapper.passthrough(Types.VAR_INT);
wrapper.passthrough(Types.VAR_INT);

String displayName = wrapper.read(Types.OPTIONAL_STRING);
wrapper.write(Types.OPTIONAL_COMPONENT, displayName != null ? Protocol1_8To1_9.STRING_TO_JSON.transform(wrapper, displayName) : null);
}
}
});
}
});


protocol.cancelClientbound(ClientboundPackets15w31a.UPDATE_ENTITY_NBT); // TODO: now bossbar
}
}

0 comments on commit d729d18

Please sign in to comment.