mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
attempt crash fix
This commit is contained in:
parent
94bf222009
commit
c050ae240b
9 changed files with 3711 additions and 32 deletions
|
@ -29,8 +29,10 @@ import com.nukkitx.protocol.bedrock.BedrockPong;
|
|||
import com.nukkitx.protocol.bedrock.BedrockServerEventHandler;
|
||||
import com.nukkitx.protocol.bedrock.BedrockServerSession;
|
||||
import com.nukkitx.protocol.bedrock.v361.Bedrock_v361;
|
||||
import org.geysermc.api.Geyser;
|
||||
import org.geysermc.connector.GeyserConnector;
|
||||
import org.geysermc.connector.configuration.GeyserConfiguration;
|
||||
import org.geysermc.connector.console.GeyserLogger;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
@ -51,7 +53,7 @@ public class ConnectorServerEventHandler implements BedrockServerEventHandler {
|
|||
|
||||
@Override
|
||||
public BedrockPong onQuery(InetSocketAddress inetSocketAddress) {
|
||||
System.out.println(inetSocketAddress + " has pinged you!");
|
||||
GeyserLogger.DEFAULT.info(inetSocketAddress + " has pinged you!");
|
||||
GeyserConfiguration config = connector.getConfig();
|
||||
BedrockPong pong = new BedrockPong();
|
||||
pong.setEdition("MCPE");
|
||||
|
@ -63,6 +65,7 @@ public class ConnectorServerEventHandler implements BedrockServerEventHandler {
|
|||
pong.setNintendoLimited(false);
|
||||
pong.setProtocolVersion(GeyserConnector.BEDROCK_PACKET_CODEC.getProtocolVersion());
|
||||
pong.setVersion("1.12.0");
|
||||
pong.setIpv4Port(19132);
|
||||
|
||||
return pong;
|
||||
}
|
||||
|
@ -71,7 +74,7 @@ public class ConnectorServerEventHandler implements BedrockServerEventHandler {
|
|||
public void onSessionCreation(BedrockServerSession bedrockServerSession) {
|
||||
bedrockServerSession.setLogging(true);
|
||||
bedrockServerSession.setPacketHandler(new UpstreamPacketHandler(connector, new GeyserSession(connector, bedrockServerSession)));
|
||||
bedrockServerSession.addDisconnectHandler((x) -> System.out.println("Bedrock user with ip: " + bedrockServerSession.getAddress().getAddress() + " has disconected for reason " + x));
|
||||
bedrockServerSession.addDisconnectHandler((x) -> GeyserLogger.DEFAULT.warning("Bedrock user with ip: " + bedrockServerSession.getAddress().getAddress() + " has disconected for reason " + x));
|
||||
bedrockServerSession.setPacketCodec(Bedrock_v361.V361_CODEC);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,43 +1,57 @@
|
|||
package org.geysermc.connector.network.translators;
|
||||
|
||||
import com.flowpowered.math.vector.Vector2f;
|
||||
import com.flowpowered.math.vector.Vector2i;
|
||||
import com.flowpowered.math.vector.Vector3f;
|
||||
import com.flowpowered.math.vector.Vector3i;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerAbilitiesPacket;
|
||||
import com.nukkitx.nbt.NbtUtils;
|
||||
import com.nukkitx.nbt.stream.NBTOutputStream;
|
||||
import com.nukkitx.nbt.tag.CompoundTag;
|
||||
import com.nukkitx.network.VarInts;
|
||||
import com.nukkitx.protocol.bedrock.data.GamePublishSetting;
|
||||
import com.nukkitx.protocol.bedrock.data.GameRule;
|
||||
import com.nukkitx.protocol.bedrock.packet.*;
|
||||
import com.nukkitx.protocol.bedrock.v340.serializer.FullChunkDataSerializer_v340;
|
||||
import com.nukkitx.protocol.bedrock.v340.serializer.ResourcePackChunkDataSerializer_v340;
|
||||
import com.nukkitx.protocol.bedrock.v340.serializer.SetSpawnPositionSerializer_v340;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import org.geysermc.connector.console.GeyserLogger;
|
||||
import org.geysermc.connector.utils.PositionSerializer;
|
||||
import org.geysermc.connector.utils.Toolbox;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class TranslatorsInit {
|
||||
public static void start() {
|
||||
addLoginPackets();
|
||||
}
|
||||
|
||||
private static void addLoginPackets() {
|
||||
Registry.add(ServerJoinGamePacket.class, (x, y) -> {
|
||||
Registry.add(ServerJoinGamePacket.class, (packet, session) -> {
|
||||
for(byte b : Toolbox.EMPTY_CHUNK) {
|
||||
GeyserLogger.DEFAULT.warning("" + b);
|
||||
}
|
||||
AdventureSettingsPacket bedrockPacket = new AdventureSettingsPacket();
|
||||
|
||||
bedrockPacket.setUniqueEntityId(x.getEntityId());
|
||||
bedrockPacket.setUniqueEntityId(packet.getEntityId());
|
||||
|
||||
y.getUpstream().sendPacketImmediately(bedrockPacket);
|
||||
|
||||
System.out.println(y.getUpstream().isClosed());
|
||||
session.getUpstream().sendPacketImmediately(bedrockPacket);
|
||||
|
||||
StartGamePacket startGamePacket = new StartGamePacket();
|
||||
startGamePacket.setUniqueEntityId(x.getEntityId());
|
||||
startGamePacket.setRuntimeEntityId(x.getEntityId());
|
||||
startGamePacket.setPlayerGamemode(x.getGameMode().ordinal());
|
||||
startGamePacket.setUniqueEntityId(packet.getEntityId());
|
||||
startGamePacket.setRuntimeEntityId(packet.getEntityId());
|
||||
startGamePacket.setPlayerGamemode(packet.getGameMode().ordinal());
|
||||
startGamePacket.setPlayerPosition(new Vector3f(0, 0, 0));
|
||||
startGamePacket.setRotation(new Vector2f(1, 1));
|
||||
|
||||
startGamePacket.setSeed(1111);
|
||||
startGamePacket.setDimensionId(0);
|
||||
startGamePacket.setGeneratorId(0);
|
||||
startGamePacket.setLevelGamemode(x.getGameMode().ordinal());
|
||||
startGamePacket.setLevelGamemode(packet.getGameMode().ordinal());
|
||||
startGamePacket.setDifficulty(1);
|
||||
startGamePacket.setDefaultSpawn(new Vector3i(0, 0, 0));
|
||||
startGamePacket.setAcheivementsDisabled(true);
|
||||
|
@ -72,44 +86,56 @@ public class TranslatorsInit {
|
|||
startGamePacket.setEnchantmentSeed(1);
|
||||
startGamePacket.setMultiplayerCorrelationId("");
|
||||
startGamePacket.setCachedPalette(Toolbox.CACHED_PALLETE);
|
||||
startGamePacket.setItemEntries(Toolbox.ITEMS);
|
||||
|
||||
y.getUpstream().sendPacketImmediately(startGamePacket);
|
||||
|
||||
System.out.println(y.getUpstream().isClosed());
|
||||
session.getUpstream().sendPacketImmediately(startGamePacket);
|
||||
|
||||
Vector3f pos = new Vector3f(0, 0, 0);
|
||||
|
||||
int chunkX = pos.getFloorX() >> 4;
|
||||
|
||||
int chunkZ = pos.getFloorX() >> 4;
|
||||
int chunkZ = pos.getFloorZ() >> 4;
|
||||
|
||||
for (int x1 = -3; x1 < 3; x1++) {
|
||||
for (int x = -3; x < 3; x++) {
|
||||
|
||||
for (int z = -3; z < 3; z++) {
|
||||
|
||||
LevelChunkPacket data = new LevelChunkPacket();
|
||||
|
||||
data.setChunkX(chunkX + x1);
|
||||
|
||||
data.setChunkX(chunkX + x);
|
||||
data.setChunkZ(chunkZ + z);
|
||||
|
||||
data.setData(new byte[0]);
|
||||
data.setData(Toolbox.EMPTY_CHUNK);
|
||||
|
||||
y.getUpstream().sendPacketImmediately(data);
|
||||
|
||||
System.out.println(y.getUpstream().isClosed());
|
||||
session.getUpstream().sendPacketImmediately(data);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
PlayStatusPacket packet = new PlayStatusPacket();
|
||||
PlayStatusPacket packet1 = new PlayStatusPacket();
|
||||
|
||||
packet.setStatus(PlayStatusPacket.Status.PLAYER_SPAWN);
|
||||
packet1.setStatus(PlayStatusPacket.Status.PLAYER_SPAWN);
|
||||
|
||||
y.getUpstream().sendPacket(packet);
|
||||
|
||||
System.out.println(y.getUpstream().isClosed());
|
||||
session.getUpstream().sendPacket(packet1);
|
||||
});
|
||||
}
|
||||
|
||||
private static byte[] empty(byte[] b, Vector2i pos) {
|
||||
ByteBuf by = Unpooled.buffer();
|
||||
|
||||
PositionSerializer.writePEChunkCoord(by, pos);
|
||||
|
||||
return by.array();
|
||||
}
|
||||
|
||||
private static class CanWriteToBB extends ByteArrayOutputStream {
|
||||
|
||||
CanWriteToBB() {
|
||||
super(8192);
|
||||
}
|
||||
|
||||
void writeTo(ByteBuf buf) {
|
||||
buf.writeBytes(super.buf, 0, super.count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,272 @@
|
|||
package org.geysermc.connector.utils;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import java.util.function.ToIntFunction;
|
||||
|
||||
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
|
||||
|
||||
public class ArraySerializer {
|
||||
|
||||
|
||||
|
||||
public static ByteBuf readShortByteArraySlice(ByteBuf from, int limit) {
|
||||
|
||||
int length = from.readShort();
|
||||
|
||||
MiscSerializer.checkLimit(length, limit);
|
||||
|
||||
return from.readSlice(length);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
public static <T> T[] readShortTArray(ByteBuf from, Class<T> tclass, Function<ByteBuf, T> elementReader) {
|
||||
|
||||
T[] array = (T[]) Array.newInstance(tclass, from.readShort());
|
||||
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
|
||||
array[i] = elementReader.apply(from);
|
||||
|
||||
}
|
||||
|
||||
return array;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static byte[] readVarIntByteArray(ByteBuf from) {
|
||||
|
||||
return MiscSerializer.readBytes(from, VarNumberSerializer.readVarInt(from));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static ByteBuf readVarIntByteArraySlice(ByteBuf from, int limit) {
|
||||
|
||||
int length = VarNumberSerializer.readVarInt(from);
|
||||
|
||||
MiscSerializer.checkLimit(length, limit);
|
||||
|
||||
return from.readSlice(length);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static ByteBuf readVarIntByteArraySlice(ByteBuf from) {
|
||||
|
||||
return from.readSlice(VarNumberSerializer.readVarInt(from));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
public static <T> T[] readVarIntTArray(ByteBuf from, Class<T> tclass, Function<ByteBuf, T> elementReader) {
|
||||
|
||||
T[] array = (T[]) Array.newInstance(tclass, VarNumberSerializer.readVarInt(from));
|
||||
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
|
||||
array[i] = elementReader.apply(from);
|
||||
|
||||
}
|
||||
|
||||
return array;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static int[] readVarIntVarIntArray(ByteBuf from) {
|
||||
|
||||
int[] array = new int[VarNumberSerializer.readVarInt(from)];
|
||||
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
|
||||
array[i] = VarNumberSerializer.readVarInt(from);
|
||||
|
||||
}
|
||||
|
||||
return array;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static void writeShortByteArray(ByteBuf to, ByteBuf data) {
|
||||
|
||||
to.writeShort(data.readableBytes());
|
||||
|
||||
to.writeBytes(data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void writeShortByteArray(ByteBuf to, byte[] data) {
|
||||
|
||||
to.writeShort(data.length);
|
||||
|
||||
to.writeBytes(data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void writeShortByteArray(ByteBuf to, Consumer<ByteBuf> dataWriter) {
|
||||
|
||||
MiscSerializer.writeLengthPrefixedBytes(to, (lTo, length) -> lTo.writeShort(length), dataWriter);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static <T> void writeShortTArray(ByteBuf to, T[] array, BiConsumer<ByteBuf, T> elementWriter) {
|
||||
|
||||
to.writeShort(array.length);
|
||||
|
||||
for (T element : array) {
|
||||
|
||||
elementWriter.accept(to, element);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static void writeVarIntByteArray(ByteBuf to, ByteBuf data) {
|
||||
|
||||
VarNumberSerializer.writeVarInt(to, data.readableBytes());
|
||||
|
||||
to.writeBytes(data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void writeVarIntByteArray(ByteBuf to, byte[] data) {
|
||||
|
||||
VarNumberSerializer.writeVarInt(to, data.length);
|
||||
|
||||
to.writeBytes(data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void writeVarIntByteArray(ByteBuf to, Consumer<ByteBuf> dataWriter) {
|
||||
|
||||
MiscSerializer.writeLengthPrefixedBytes(to, VarNumberSerializer::writeFixedSizeVarInt, dataWriter);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void writeVarIntTArray(ByteBuf to, ToIntFunction<ByteBuf> arrayWriter) {
|
||||
|
||||
MiscSerializer.writeSizePrefixedData(to, VarNumberSerializer::writeFixedSizeVarInt, arrayWriter);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static <T> void writeVarIntTArray(ByteBuf to, T[] array, BiConsumer<ByteBuf, T> elementWriter) {
|
||||
|
||||
VarNumberSerializer.writeVarInt(to, array.length);
|
||||
|
||||
for (T element : array) {
|
||||
|
||||
elementWriter.accept(to, element);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static <T> void writeVarIntTArray(ByteBuf to, List<T> array, BiConsumer<ByteBuf, T> elementWriter) {
|
||||
|
||||
VarNumberSerializer.writeVarInt(to, array.size());
|
||||
|
||||
for (T element : array) {
|
||||
|
||||
elementWriter.accept(to, element);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static void writeVarIntVarIntArray(ByteBuf to, int[] array) {
|
||||
|
||||
VarNumberSerializer.writeVarInt(to, array.length);
|
||||
|
||||
for (int element : array) {
|
||||
|
||||
VarNumberSerializer.writeVarInt(to, element);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void writeSVarIntSVarIntArray(ByteBuf to, int[] array) {
|
||||
|
||||
VarNumberSerializer.writeSVarInt(to, array.length);
|
||||
|
||||
for (int element : array) {
|
||||
|
||||
VarNumberSerializer.writeSVarInt(to, element);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void writeVarIntLongArray(ByteBuf to, long[] array) {
|
||||
|
||||
VarNumberSerializer.writeVarInt(to, array.length);
|
||||
|
||||
for (long element : array) {
|
||||
|
||||
to.writeLong(element);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,159 @@
|
|||
package org.geysermc.connector.utils;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import java.util.function.ObjIntConsumer;
|
||||
|
||||
import java.util.function.ToIntFunction;
|
||||
|
||||
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import io.netty.handler.codec.DecoderException;
|
||||
|
||||
|
||||
public class MiscSerializer {
|
||||
|
||||
|
||||
public static void writeVarIntEnum(ByteBuf to, Enum<?> e) {
|
||||
|
||||
VarNumberSerializer.writeVarInt(to, e.ordinal());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void writeByteEnum(ByteBuf to, Enum<?> e) {
|
||||
|
||||
to.writeByte(e.ordinal());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static UUID readUUID(ByteBuf from) {
|
||||
|
||||
return new UUID(from.readLong(), from.readLong());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void writeUUID(ByteBuf to, UUID uuid) {
|
||||
|
||||
to.writeLong(uuid.getMostSignificantBits());
|
||||
|
||||
to.writeLong(uuid.getLeastSignificantBits());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void writePEUUID(ByteBuf to, UUID uuid) {
|
||||
|
||||
to.writeLongLE(uuid.getMostSignificantBits());
|
||||
|
||||
to.writeLongLE(uuid.getLeastSignificantBits());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static byte[] readAllBytes(ByteBuf buf) {
|
||||
|
||||
return MiscSerializer.readBytes(buf, buf.readableBytes());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static ByteBuf readAllBytesSlice(ByteBuf from) {
|
||||
|
||||
return from.readSlice(from.readableBytes());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static ByteBuf readAllBytesSlice(ByteBuf buf, int limit) {
|
||||
|
||||
checkLimit(buf.readableBytes(), limit);
|
||||
|
||||
return readAllBytesSlice(buf);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static byte[] readBytes(ByteBuf buf, int length) {
|
||||
|
||||
byte[] result = new byte[length];
|
||||
|
||||
buf.readBytes(result);
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected static void checkLimit(int length, int limit) {
|
||||
|
||||
if (length > limit) {
|
||||
|
||||
throw new DecoderException(MessageFormat.format("Size {0} is bigger than allowed {1}", length, limit));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void writeLengthPrefixedBytes(ByteBuf to, ObjIntConsumer<ByteBuf> lengthWriter, Consumer<ByteBuf> dataWriter) {
|
||||
|
||||
int lengthWriterIndex = to.writerIndex();
|
||||
|
||||
lengthWriter.accept(to, 0);
|
||||
|
||||
int writerIndexDataStart = to.writerIndex();
|
||||
|
||||
dataWriter.accept(to);
|
||||
|
||||
int writerIndexDataEnd = to.writerIndex();
|
||||
|
||||
to.writerIndex(lengthWriterIndex);
|
||||
|
||||
lengthWriter.accept(to, writerIndexDataEnd - writerIndexDataStart);
|
||||
|
||||
to.writerIndex(writerIndexDataEnd);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void writeSizePrefixedData(ByteBuf to, ObjIntConsumer<ByteBuf> sizeWriter, ToIntFunction<ByteBuf> dataWriter) {
|
||||
|
||||
int sizeWriterIndex = to.writerIndex();
|
||||
|
||||
sizeWriter.accept(to, 0);
|
||||
|
||||
int size = dataWriter.applyAsInt(to);
|
||||
|
||||
int writerIndexDataEnd = to.writerIndex();
|
||||
|
||||
to.writerIndex(sizeWriterIndex);
|
||||
|
||||
sizeWriter.accept(to, size);
|
||||
|
||||
to.writerIndex(writerIndexDataEnd);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package org.geysermc.connector.utils;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class PSPEStuff {
|
||||
|
||||
public static final int FLAG_RUNTIME = 1;
|
||||
|
||||
public static final int GLOBAL_PALETTE_BITS_PER_BLOCK = 14;
|
||||
|
||||
public static final int SECTION_COUNT_BLOCKS = 16;
|
||||
|
||||
public static final int SECTION_COUNT_LIGHT = 18;
|
||||
|
||||
public static final int BLOCKS_IN_SECTION = 16 * 16 * 16;
|
||||
|
||||
public static final int LIGHT_DATA_LENGTH = BLOCKS_IN_SECTION / 2;
|
||||
|
||||
public static final int EMPTY_SUBCHUNK_BYTES = BLOCKS_IN_SECTION / 8;
|
||||
|
||||
public static final int SUBCHUNK_VERSION = 8;
|
||||
|
||||
public static void writeEmpty(ByteBuf to) {
|
||||
|
||||
to.writeByte(storageHeader(1));
|
||||
|
||||
to.writeZero(EMPTY_SUBCHUNK_BYTES);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected static final int storageHeader(int bitsPerBlock) {
|
||||
|
||||
return (bitsPerBlock << 1) | FLAG_RUNTIME;
|
||||
|
||||
}
|
||||
|
||||
public static void writeEmptySubChunk(ByteBuf out) {
|
||||
|
||||
out.writeByte(SUBCHUNK_VERSION);
|
||||
|
||||
out.writeByte(1); //only blockstate storage
|
||||
|
||||
writeEmpty(out);
|
||||
|
||||
VarNumberSerializer.writeSVarInt(out, 1); //Palette size
|
||||
|
||||
VarNumberSerializer.writeSVarInt(out, 0); //Palette: Air
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,191 @@
|
|||
package org.geysermc.connector.utils;
|
||||
|
||||
import com.flowpowered.math.vector.Vector2d;
|
||||
import com.flowpowered.math.vector.Vector2i;
|
||||
import com.flowpowered.math.vector.Vector3d;
|
||||
import com.flowpowered.math.vector.Vector3i;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import protocolsupport.protocol.types.Position;
|
||||
|
||||
public class PositionSerializer {
|
||||
|
||||
|
||||
|
||||
public static void skipPosition(ByteBuf from) {
|
||||
|
||||
from.skipBytes(Long.BYTES);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static Vector3d readPosition(ByteBuf from) {
|
||||
|
||||
long l = from.readLong();
|
||||
|
||||
return new Vector3d(
|
||||
|
||||
(int) (l >> 38), (int) (l & 0xFFF), (int) ((l << 26) >> 38)
|
||||
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void readPEPosition(ByteBuf from) {
|
||||
|
||||
VarNumberSerializer.readSVarInt(from);
|
||||
|
||||
VarNumberSerializer.readVarInt(from);
|
||||
|
||||
VarNumberSerializer.readSVarInt(from);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static Vector3d readLegacyPositionI(ByteBuf from) {
|
||||
|
||||
return new Vector3d(from.readInt(), from.readInt(), from.readInt());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void writePosition(ByteBuf to, Vector3i position) {
|
||||
|
||||
to.writeLong(((position.getX() & 0x3FFFFFFL) << 38) | ((position.getZ() & 0x3FFFFFFL) << 12) | (position.getY() & 0xFFFL));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void writeLegacyPositionL(ByteBuf to, Position position) {
|
||||
|
||||
to.writeLong(((position.getX() & 0x3FFFFFFL) << 38) | ((position.getY() & 0xFFFL) << 26) | (position.getZ() & 0x3FFFFFFL));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void writePEPosition(ByteBuf to, Position position) {
|
||||
|
||||
VarNumberSerializer.writeSVarInt(to, position.getX());
|
||||
|
||||
VarNumberSerializer.writeVarInt(to, position.getY());
|
||||
|
||||
VarNumberSerializer.writeSVarInt(to, position.getZ());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void writeLegacyPositionB(ByteBuf to, Position position) {
|
||||
|
||||
to.writeInt(position.getX());
|
||||
|
||||
to.writeByte(position.getY());
|
||||
|
||||
to.writeInt(position.getZ());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void writeLegacyPositionS(ByteBuf to, Position position) {
|
||||
|
||||
to.writeInt(position.getX());
|
||||
|
||||
to.writeShort(position.getY());
|
||||
|
||||
to.writeInt(position.getZ());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void writeLegacyPositionI(ByteBuf to, Position position) {
|
||||
|
||||
to.writeInt(position.getX());
|
||||
|
||||
to.writeInt(position.getY());
|
||||
|
||||
to.writeInt(position.getZ());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static Vector2i readIntChunkCoord(ByteBuf from) {
|
||||
|
||||
return new Vector2i(from.readInt(), from.readInt());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static Vector2i readVarIntChunkCoord(ByteBuf from) {
|
||||
|
||||
return new Vector2i(VarNumberSerializer.readVarInt(from), VarNumberSerializer.readVarInt(from));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void writeIntChunkCoord(ByteBuf to, Vector2i chunk) {
|
||||
|
||||
to.writeInt(chunk.getX());
|
||||
|
||||
to.writeInt(chunk.getY());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static Vector2i readPEChunkCoord(ByteBuf from) {
|
||||
|
||||
return new Vector2i(VarNumberSerializer.readSVarInt(from), VarNumberSerializer.readSVarInt(from));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void writePEChunkCoord(ByteBuf to, Vector2i chunk) {
|
||||
|
||||
VarNumberSerializer.writeSVarInt(to, chunk.getX());
|
||||
|
||||
VarNumberSerializer.writeSVarInt(to, chunk.getY());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static int readLocalCoord(ByteBuf from) {
|
||||
|
||||
return from.readUnsignedShort();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void writeLocalCoord(ByteBuf to, int coord) {
|
||||
|
||||
to.writeShort(coord);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void writeVarIntChunkCoord(ByteBuf to, Vector2i chunk) {
|
||||
|
||||
VarNumberSerializer.writeVarInt(to, chunk.getX());
|
||||
|
||||
VarNumberSerializer.writeVarInt(to, chunk.getY());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -4,15 +4,14 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
|||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.type.CollectionType;
|
||||
import com.nukkitx.network.VarInts;
|
||||
import com.nukkitx.protocol.bedrock.packet.StartGamePacket;
|
||||
import com.nukkitx.protocol.bedrock.v361.BedrockUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
public class Toolbox {
|
||||
static {
|
||||
|
@ -40,8 +39,50 @@ public class Toolbox {
|
|||
|
||||
CACHED_PALLETE = b;
|
||||
|
||||
|
||||
|
||||
|
||||
InputStream stream2 = Toolbox.class.getClassLoader().getResourceAsStream("items.json");
|
||||
if (stream2 == null) {
|
||||
throw new AssertionError("Items Table not found");
|
||||
}
|
||||
|
||||
ObjectMapper mapper2 = new ObjectMapper();
|
||||
|
||||
ArrayList<HashMap> s = new ArrayList<>();
|
||||
try {
|
||||
s = mapper2.readValue(stream2, ArrayList.class);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
ArrayList<StartGamePacket.ItemEntry> l = new ArrayList<>();
|
||||
|
||||
for(HashMap e : s) {
|
||||
l.add(new StartGamePacket.ItemEntry((String) e.get("name"), ((Integer) e.get("id")).shortValue()));
|
||||
}
|
||||
|
||||
ITEMS = l;
|
||||
|
||||
ByteBuf serializer;
|
||||
|
||||
serializer = Unpooled.buffer();
|
||||
serializer.writeShortLE(1);
|
||||
ArraySerializer.writeVarIntByteArray(serializer, (chunkdata) -> {
|
||||
PSPEStuff.writeEmptySubChunk(chunkdata);
|
||||
chunkdata.writeZero(512);
|
||||
chunkdata.writeZero(256);
|
||||
chunkdata.writeByte(0);
|
||||
});
|
||||
|
||||
EMPTY_CHUNK = MiscSerializer.readAllBytes(serializer);
|
||||
|
||||
}
|
||||
|
||||
public static final Collection<StartGamePacket.ItemEntry> ITEMS;
|
||||
|
||||
public static final ByteBuf CACHED_PALLETE;
|
||||
|
||||
public static final byte[] EMPTY_CHUNK;
|
||||
|
||||
}
|
|
@ -0,0 +1,177 @@
|
|||
package org.geysermc.connector.utils;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import io.netty.handler.codec.DecoderException;
|
||||
|
||||
|
||||
|
||||
public class VarNumberSerializer {
|
||||
|
||||
|
||||
|
||||
public static final int MAX_LENGTH = 5;
|
||||
|
||||
|
||||
|
||||
public static void writeFixedSizeVarInt(ByteBuf to, int i) {
|
||||
|
||||
int writerIndex = to.writerIndex();
|
||||
|
||||
while ((i & 0xFFFFFF80) != 0x0) {
|
||||
|
||||
to.writeByte(i | 0x80);
|
||||
|
||||
i >>>= 7;
|
||||
|
||||
}
|
||||
|
||||
int paddingBytes = MAX_LENGTH - (to.writerIndex() - writerIndex) - 1;
|
||||
|
||||
if (paddingBytes == 0) {
|
||||
|
||||
to.writeByte(i);
|
||||
|
||||
} else {
|
||||
|
||||
to.writeByte(i | 0x80);
|
||||
|
||||
while (--paddingBytes > 0) {
|
||||
|
||||
to.writeByte(0x80);
|
||||
|
||||
}
|
||||
|
||||
to.writeByte(0);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static int readVarInt(ByteBuf from) {
|
||||
|
||||
int value = 0;
|
||||
|
||||
int length = 0;
|
||||
|
||||
byte part;
|
||||
|
||||
do {
|
||||
|
||||
part = from.readByte();
|
||||
|
||||
value |= (part & 0x7F) << (length++ * 7);
|
||||
|
||||
if (length > MAX_LENGTH) {
|
||||
|
||||
throw new DecoderException("VarInt too big");
|
||||
|
||||
}
|
||||
|
||||
} while (part < 0);
|
||||
|
||||
return value;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void writeVarInt(ByteBuf to, int i) {
|
||||
|
||||
while ((i & 0xFFFFFF80) != 0x0) {
|
||||
|
||||
to.writeByte(i | 0x80);
|
||||
|
||||
i >>>= 7;
|
||||
|
||||
}
|
||||
|
||||
to.writeByte(i);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static int readSVarInt(ByteBuf from) {
|
||||
|
||||
int varint = readVarInt(from);
|
||||
|
||||
return (varint >> 1) ^ -(varint & 1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void writeSVarInt(ByteBuf to, int varint) {
|
||||
|
||||
writeVarInt(to, (varint << 1) ^ (varint >> 31));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static long readVarLong(ByteBuf from) {
|
||||
|
||||
long varlong = 0L;
|
||||
|
||||
int length = 0;
|
||||
|
||||
byte part;
|
||||
|
||||
do {
|
||||
|
||||
part = from.readByte();
|
||||
|
||||
varlong |= (part & 0x7F) << (length++ * 7);
|
||||
|
||||
if (length > 10) {
|
||||
|
||||
throw new RuntimeException("VarLong too big");
|
||||
|
||||
}
|
||||
|
||||
} while ((part & 0x80) == 0x80);
|
||||
|
||||
return varlong;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void writeVarLong(ByteBuf to, long varlong) {
|
||||
|
||||
while ((varlong & 0xFFFFFFFFFFFFFF80L) != 0x0L) {
|
||||
|
||||
to.writeByte((int) (varlong & 0x7FL) | 0x80);
|
||||
|
||||
varlong >>>= 7;
|
||||
|
||||
}
|
||||
|
||||
to.writeByte((int) varlong);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static long readSVarLong(ByteBuf from) {
|
||||
|
||||
long varlong = readVarLong(from);
|
||||
|
||||
return (varlong >> 1) ^ -(varlong & 1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void writeSVarLong(ByteBuf to, long varlong) {
|
||||
|
||||
writeVarLong(to, (varlong << 1) ^ (varlong >> 63));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
2758
connector/src/main/resources/items.json
Normal file
2758
connector/src/main/resources/items.json
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue