Skip to content
Permalink
Browse files

Use unsigned instead of signed shorts, to support maps over 32767 in …

…axis size.
  • Loading branch information...
UnknownShadow200 committed May 20, 2017
1 parent 6959649 commit 702ef1b777d77c613dad96a626463eac61feae4e
@@ -73,9 +73,9 @@ public sealed class MapD3 : IMapImporter, IMapExporter {
int formatVersion = bs.ReadInt32();

// Read in the map dimesions
int width = bs.ReadInt16();
int length = bs.ReadInt16();
int height = bs.ReadInt16();
int width = bs.ReadUInt16();
int length = bs.ReadUInt16();
int height = bs.ReadUInt16();

Map map = new Map( null, width, length, height, false );

@@ -74,9 +74,9 @@ public sealed class MapFCMv2 : IMapImporter {
}

// Read in the map dimesions
int width = reader.ReadInt16();
int length = reader.ReadInt16();
int height = reader.ReadInt16();
int width = reader.ReadUInt16();
int length = reader.ReadUInt16();
int height = reader.ReadUInt16();

// ReSharper disable UseObjectOrCollectionInitializer
Map map = new Map( null, width, length, height, false );
@@ -162,9 +162,9 @@ public sealed class MapFCMv3 : IMapImporter, IMapExporter {
}

// read dimensions
int width = reader.ReadInt16();
int height = reader.ReadInt16();
int length = reader.ReadInt16();
int width = reader.ReadUInt16();
int height = reader.ReadUInt16();
int length = reader.ReadUInt16();

// ReSharper disable UseObjectOrCollectionInitializer
Map map = new Map( null, width, length, height, false );
@@ -83,9 +83,9 @@ public sealed class MapJTE : IMapImporter, IMapExporter {
};

// Read in the map dimesions
int width = IPAddress.NetworkToHostOrder( bs.ReadInt16() );
int length = IPAddress.NetworkToHostOrder( bs.ReadInt16() );
int height = IPAddress.NetworkToHostOrder( bs.ReadInt16() );
int width = (ushort)IPAddress.NetworkToHostOrder( bs.ReadInt16() );
int length = (ushort)IPAddress.NetworkToHostOrder( bs.ReadInt16() );
int height = (ushort)IPAddress.NetworkToHostOrder( bs.ReadInt16() );

return new Map( null, width, length, height, false ) { Spawn = spawn };
}
@@ -74,9 +74,9 @@ public class MapMCSharp : IMapImporter, IMapExporter {
}

// Read in the map dimesions
int width = bs.ReadInt16();
int length = bs.ReadInt16();
int height = bs.ReadInt16();
int width = bs.ReadUInt16();
int length = bs.ReadUInt16();
int height = bs.ReadUInt16();

// ReSharper disable UseObjectOrCollectionInitializer
Map map = new Map( null, width, length, height, false );
@@ -79,9 +79,9 @@ public sealed class MapMinerCPP : IMapImporter, IMapExporter {
// Read in the map dimesions
// Saved in big endian for who-knows-what reason.
// XYZ(?)
int width = IPAddress.NetworkToHostOrder( bs.ReadInt16() );
int height = IPAddress.NetworkToHostOrder( bs.ReadInt16() );
int length = IPAddress.NetworkToHostOrder( bs.ReadInt16() );
int width = (ushort)IPAddress.NetworkToHostOrder( bs.ReadInt16() );
int height = (ushort)IPAddress.NetworkToHostOrder( bs.ReadInt16() );
int length = (ushort)IPAddress.NetworkToHostOrder( bs.ReadInt16() );

// ReSharper disable UseObjectOrCollectionInitializer
Map map = new Map( null, width, length, height, false );
@@ -114,13 +114,13 @@ public partial struct Packet {
packet.Bytes[1] = (byte)variable;
if (color != null) {
System.Drawing.Color col = System.Drawing.ColorTranslator.FromHtml("#" + color.ToUpper());
WriteI16((short) col.R, packet.Bytes, 2);
WriteI16((short) col.G, packet.Bytes, 4);
WriteI16((short) col.B, packet.Bytes, 6);
WriteI16(col.R, packet.Bytes, 2);
WriteI16(col.G, packet.Bytes, 4);
WriteI16(col.B, packet.Bytes, 6);
} else {
WriteI16((short)-1, packet.Bytes, 2);
WriteI16((short)-1, packet.Bytes, 4);
WriteI16((short)-1, packet.Bytes, 6);
WriteI16(-1, packet.Bytes, 2);
WriteI16(-1, packet.Bytes, 4);
WriteI16(-1, packet.Bytes, 6);
}
return packet;
}
@@ -143,9 +143,9 @@ public partial struct Packet {
WriteI16((short)(bounds.YMax + 1), packet.Bytes, 76);

CustomColor c = Color.ParseHex(color);
WriteI16((short)c.R, packet.Bytes, 78);
WriteI16((short)c.G, packet.Bytes, 80);
WriteI16((short)c.B, packet.Bytes, 82);
WriteI16(c.R, packet.Bytes, 78);
WriteI16(c.G, packet.Bytes, 80);
WriteI16(c.B, packet.Bytes, 82);
WriteI16(opacity, packet.Bytes, 84);
return packet;
}
@@ -66,9 +66,9 @@ public partial struct Packet {
public static Packet MakeSetBlock( Vector3I coords, Block type ) {
Packet packet = new Packet( OpCode.SetBlockServer );
//Logger.Log(LogType.Debug, "Send: MakeSetBlock({0})({1})", coords, type);
WriteI16( (short)coords.X, packet.Bytes, 1 );
WriteI16( (short)coords.Z, packet.Bytes, 3 );
WriteI16( (short)coords.Y, packet.Bytes, 5 );
WriteU16( (ushort)coords.X, packet.Bytes, 1 );
WriteU16( (ushort)coords.Z, packet.Bytes, 3 );
WriteU16( (ushort)coords.Y, packet.Bytes, 5 );
packet.Bytes[7] = (byte)type;
return packet;
}
@@ -235,6 +235,11 @@ public partial struct Packet {
arr[offset] = (byte)((number & 0xff00) >> 8);
arr[offset + 1] = (byte)( number & 0x00ff);
}

internal static void WriteU16( ushort number, [NotNull] byte[] arr, int offset ) {
arr[offset] = (byte)((number & 0xff00) >> 8);
arr[offset + 1] = (byte)( number & 0x00ff);
}

internal static void WriteI32( int number, [NotNull] byte[] arr, int offset ) {
arr[offset] = (byte)((number & 0xff000000) >> 24);
@@ -292,16 +297,16 @@ public partial struct Packet {
}

public struct SetBlockData {
public short X, Y, Z;
public ushort X, Y, Z;
public byte Block;

public SetBlockData(int x, int y, int z, byte block) {
X = (short)x; Y = (short)y; Z = (short)z;
X = (ushort)x; Y = (ushort)y; Z = (ushort)z;
Block = block;
}

public SetBlockData(Vector3I p, byte block) {
X = (short)p.X; Y = (short)p.Y; Z = (short)p.Z;
X = (ushort)p.X; Y = (ushort)p.Y; Z = (ushort)p.Z;
Block = block;
}
}
@@ -18,7 +18,12 @@ public OpCode ReadOpCode()
public override short ReadInt16() {
return IPAddress.NetworkToHostOrder( base.ReadInt16() );
}



public override ushort ReadUInt16() {
return (ushort)IPAddress.NetworkToHostOrder( base.ReadInt16() );
}


public override int ReadInt32()
{
@@ -19,7 +19,12 @@ public PacketWriter( [NotNull] Stream stream )
public override void Write( short data ) {
base.Write( IPAddress.HostToNetworkOrder( data ) );
}


public override void Write( ushort data ) {
base.Write( IPAddress.HostToNetworkOrder( (short)data ) );
}


public override void Write( string str ) {
if( str == null ) throw new ArgumentNullException( "str" );
@@ -204,9 +204,9 @@ public sealed partial class Player {
CheckBlock(ref blockUpdate.Block);

if (!useBulk) {
Packet.WriteI16(blockUpdate.X, blockPacket, 1);
Packet.WriteI16(blockUpdate.Z, blockPacket, 3);
Packet.WriteI16(blockUpdate.Y, blockPacket, 5);
Packet.WriteU16(blockUpdate.X, blockPacket, 1);
Packet.WriteU16(blockUpdate.Z, blockPacket, 3);
Packet.WriteU16(blockUpdate.Y, blockPacket, 5);
blockPacket[7] = blockUpdate.Block;
writer.Write( blockPacket );
BytesSent += blockPacket.Length;
@@ -488,9 +488,9 @@ public sealed partial class Player {
Server.UpdateTabList(true);
}
ResetIdleTimer();
short x = reader.ReadInt16();
short z = reader.ReadInt16();
short y = reader.ReadInt16();
ushort x = reader.ReadUInt16();
ushort z = reader.ReadUInt16();
ushort y = reader.ReadUInt16();
ClickAction action = ( reader.ReadByte() == 1 ) ? ClickAction.Build : ClickAction.Delete;
byte type = reader.ReadByte();

@@ -1113,9 +1113,9 @@ bool LoginSequence()

// Done sending over level copy
writer.Write(OpCode.MapEnd);
writer.Write((short)map.Width);
writer.Write((short)map.Height);
writer.Write((short)map.Length);
writer.Write((ushort)map.Width);
writer.Write((ushort)map.Height);
writer.Write((ushort)map.Length);
BytesSent += 7;

SendJoinCpeExtensions();
@@ -9,12 +9,12 @@ public struct BlockUpdate {
/// <summary> Player who initiated the block change. Can be null. </summary>
[CanBeNull] public readonly Player Origin;

public readonly short X, Y, Z;
public readonly ushort X, Y, Z;

/// <summary> Type of block to set at the given coordinates. </summary>
public readonly Block BlockType;

public BlockUpdate( Player origin, short x, short y, short z, Block blockType ) {
public BlockUpdate( Player origin, ushort x, ushort y, ushort z, Block blockType ) {
Origin = origin;
X = x;
Y = y;
@@ -24,9 +24,9 @@ public struct BlockUpdate {

public BlockUpdate( Player origin, Vector3I coord, Block blockType ) {
Origin = origin;
X = (short)coord.X;
Y = (short)coord.Y;
Z = (short)coord.Z;
X = (ushort)coord.X;
Y = (ushort)coord.Y;
Z = (ushort)coord.Z;
BlockType = blockType;
}
}

0 comments on commit 702ef1b

Please sign in to comment.
You can’t perform that action at this time.