Skip to content

Commit 702ef1b

Browse files
Use unsigned instead of signed shorts, to support maps over 32767 in axis size.
1 parent 6959649 commit 702ef1b

File tree

12 files changed

+63
-48
lines changed

12 files changed

+63
-48
lines changed

fCraft/MapConversion/MapD3.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ static Map LoadHeaderInternal( GZipStream gs ) {
7373
int formatVersion = bs.ReadInt32();
7474

7575
// Read in the map dimesions
76-
int width = bs.ReadInt16();
77-
int length = bs.ReadInt16();
78-
int height = bs.ReadInt16();
76+
int width = bs.ReadUInt16();
77+
int length = bs.ReadUInt16();
78+
int height = bs.ReadUInt16();
7979

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

fCraft/MapConversion/MapFCMv2.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ static Map LoadHeaderInternal( [NotNull] Stream stream ) {
7474
}
7575

7676
// Read in the map dimesions
77-
int width = reader.ReadInt16();
78-
int length = reader.ReadInt16();
79-
int height = reader.ReadInt16();
77+
int width = reader.ReadUInt16();
78+
int length = reader.ReadUInt16();
79+
int height = reader.ReadUInt16();
8080

8181
// ReSharper disable UseObjectOrCollectionInitializer
8282
Map map = new Map( null, width, length, height, false );

fCraft/MapConversion/MapFCMv3.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ static Map LoadHeaderInternal( [NotNull] BinaryReader reader ) {
162162
}
163163

164164
// read dimensions
165-
int width = reader.ReadInt16();
166-
int height = reader.ReadInt16();
167-
int length = reader.ReadInt16();
165+
int width = reader.ReadUInt16();
166+
int height = reader.ReadUInt16();
167+
int length = reader.ReadUInt16();
168168

169169
// ReSharper disable UseObjectOrCollectionInitializer
170170
Map map = new Map( null, width, length, height, false );

fCraft/MapConversion/MapJTE.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ static Map LoadHeaderInternal( [NotNull] Stream stream ) {
8383
};
8484

8585
// Read in the map dimesions
86-
int width = IPAddress.NetworkToHostOrder( bs.ReadInt16() );
87-
int length = IPAddress.NetworkToHostOrder( bs.ReadInt16() );
88-
int height = IPAddress.NetworkToHostOrder( bs.ReadInt16() );
86+
int width = (ushort)IPAddress.NetworkToHostOrder( bs.ReadInt16() );
87+
int length = (ushort)IPAddress.NetworkToHostOrder( bs.ReadInt16() );
88+
int height = (ushort)IPAddress.NetworkToHostOrder( bs.ReadInt16() );
8989

9090
return new Map( null, width, length, height, false ) { Spawn = spawn };
9191
}

fCraft/MapConversion/MapMCSharp.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ protected static Map LoadHeaderInternal( [NotNull] Stream stream ) {
7474
}
7575

7676
// Read in the map dimesions
77-
int width = bs.ReadInt16();
78-
int length = bs.ReadInt16();
79-
int height = bs.ReadInt16();
77+
int width = bs.ReadUInt16();
78+
int length = bs.ReadUInt16();
79+
int height = bs.ReadUInt16();
8080

8181
// ReSharper disable UseObjectOrCollectionInitializer
8282
Map map = new Map( null, width, length, height, false );

fCraft/MapConversion/MapMinerCPP.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ static Map LoadHeaderInternal( [NotNull] Stream stream ) {
7979
// Read in the map dimesions
8080
// Saved in big endian for who-knows-what reason.
8181
// XYZ(?)
82-
int width = IPAddress.NetworkToHostOrder( bs.ReadInt16() );
83-
int height = IPAddress.NetworkToHostOrder( bs.ReadInt16() );
84-
int length = IPAddress.NetworkToHostOrder( bs.ReadInt16() );
82+
int width = (ushort)IPAddress.NetworkToHostOrder( bs.ReadInt16() );
83+
int height = (ushort)IPAddress.NetworkToHostOrder( bs.ReadInt16() );
84+
int length = (ushort)IPAddress.NetworkToHostOrder( bs.ReadInt16() );
8585

8686
// ReSharper disable UseObjectOrCollectionInitializer
8787
Map map = new Map( null, width, length, height, false );

fCraft/Network/Packet.CPE.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,13 @@ public static Packet MakeEnvSetColor(Byte variable, string color) {
114114
packet.Bytes[1] = (byte)variable;
115115
if (color != null) {
116116
System.Drawing.Color col = System.Drawing.ColorTranslator.FromHtml("#" + color.ToUpper());
117-
WriteI16((short) col.R, packet.Bytes, 2);
118-
WriteI16((short) col.G, packet.Bytes, 4);
119-
WriteI16((short) col.B, packet.Bytes, 6);
117+
WriteI16(col.R, packet.Bytes, 2);
118+
WriteI16(col.G, packet.Bytes, 4);
119+
WriteI16(col.B, packet.Bytes, 6);
120120
} else {
121-
WriteI16((short)-1, packet.Bytes, 2);
122-
WriteI16((short)-1, packet.Bytes, 4);
123-
WriteI16((short)-1, packet.Bytes, 6);
121+
WriteI16(-1, packet.Bytes, 2);
122+
WriteI16(-1, packet.Bytes, 4);
123+
WriteI16(-1, packet.Bytes, 6);
124124
}
125125
return packet;
126126
}
@@ -143,9 +143,9 @@ public static Packet MakeMakeSelection(byte selectionId, [NotNull] string label,
143143
WriteI16((short)(bounds.YMax + 1), packet.Bytes, 76);
144144

145145
CustomColor c = Color.ParseHex(color);
146-
WriteI16((short)c.R, packet.Bytes, 78);
147-
WriteI16((short)c.G, packet.Bytes, 80);
148-
WriteI16((short)c.B, packet.Bytes, 82);
146+
WriteI16(c.R, packet.Bytes, 78);
147+
WriteI16(c.G, packet.Bytes, 80);
148+
WriteI16(c.B, packet.Bytes, 82);
149149
WriteI16(opacity, packet.Bytes, 84);
150150
return packet;
151151
}

fCraft/Network/Packet.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ public static Packet MakeHandshake( [NotNull] Player player, [NotNull] string se
6666
public static Packet MakeSetBlock( Vector3I coords, Block type ) {
6767
Packet packet = new Packet( OpCode.SetBlockServer );
6868
//Logger.Log(LogType.Debug, "Send: MakeSetBlock({0})({1})", coords, type);
69-
WriteI16( (short)coords.X, packet.Bytes, 1 );
70-
WriteI16( (short)coords.Z, packet.Bytes, 3 );
71-
WriteI16( (short)coords.Y, packet.Bytes, 5 );
69+
WriteU16( (ushort)coords.X, packet.Bytes, 1 );
70+
WriteU16( (ushort)coords.Z, packet.Bytes, 3 );
71+
WriteU16( (ushort)coords.Y, packet.Bytes, 5 );
7272
packet.Bytes[7] = (byte)type;
7373
return packet;
7474
}
@@ -235,6 +235,11 @@ internal static void WriteI16( short number, [NotNull] byte[] arr, int offset )
235235
arr[offset] = (byte)((number & 0xff00) >> 8);
236236
arr[offset + 1] = (byte)( number & 0x00ff);
237237
}
238+
239+
internal static void WriteU16( ushort number, [NotNull] byte[] arr, int offset ) {
240+
arr[offset] = (byte)((number & 0xff00) >> 8);
241+
arr[offset + 1] = (byte)( number & 0x00ff);
242+
}
238243

239244
internal static void WriteI32( int number, [NotNull] byte[] arr, int offset ) {
240245
arr[offset] = (byte)((number & 0xff000000) >> 24);
@@ -292,16 +297,16 @@ internal static void WriteI32( int number, [NotNull] byte[] arr, int offset ) {
292297
}
293298

294299
public struct SetBlockData {
295-
public short X, Y, Z;
300+
public ushort X, Y, Z;
296301
public byte Block;
297302

298303
public SetBlockData(int x, int y, int z, byte block) {
299-
X = (short)x; Y = (short)y; Z = (short)z;
304+
X = (ushort)x; Y = (ushort)y; Z = (ushort)z;
300305
Block = block;
301306
}
302307

303308
public SetBlockData(Vector3I p, byte block) {
304-
X = (short)p.X; Y = (short)p.Y; Z = (short)p.Z;
309+
X = (ushort)p.X; Y = (ushort)p.Y; Z = (ushort)p.Z;
305310
Block = block;
306311
}
307312
}

fCraft/Network/PacketReader.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ public OpCode ReadOpCode()
1818
public override short ReadInt16() {
1919
return IPAddress.NetworkToHostOrder( base.ReadInt16() );
2020
}
21-
21+
22+
23+
public override ushort ReadUInt16() {
24+
return (ushort)IPAddress.NetworkToHostOrder( base.ReadInt16() );
25+
}
26+
2227

2328
public override int ReadInt32()
2429
{

fCraft/Network/PacketWriter.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ public void Write( OpCode opcode ) {
1919
public override void Write( short data ) {
2020
base.Write( IPAddress.HostToNetworkOrder( data ) );
2121
}
22+
2223

24+
public override void Write( ushort data ) {
25+
base.Write( IPAddress.HostToNetworkOrder( (short)data ) );
26+
}
27+
2328

2429
public override void Write( string str ) {
2530
if( str == null ) throw new ArgumentNullException( "str" );

0 commit comments

Comments
 (0)