diff --git a/GraphicsAPI/OpenGLApi.cs b/GraphicsAPI/OpenGLApi.cs index 9c3da6de0..72e124494 100644 --- a/GraphicsAPI/OpenGLApi.cs +++ b/GraphicsAPI/OpenGLApi.cs @@ -89,9 +89,9 @@ namespace ClassicalSharp.GraphicsAPI { set { ToggleCap( EnableCap.Fog, value ); } } - public override void SetFogColour( FastColour col ) { - float[] colRGBA = { col.R / 255f, col.G / 255f, col.B / 255f, col.A / 255f }; - GL.Fog( FogParameter.FogColor, colRGBA ); + public unsafe override void SetFogColour( FastColour col ) { + Vector4 colRGBA = new Vector4( col.R / 255f, col.G / 255f, col.B / 255f, col.A / 255f ); + GL.Fog( FogParameter.FogColor, &colRGBA.X ); } public override void SetFogDensity( float value ) { diff --git a/Network/FastNetReader.cs b/Network/FastNetReader.cs index aa3c9015e..33e3690e6 100644 --- a/Network/FastNetReader.cs +++ b/Network/FastNetReader.cs @@ -62,18 +62,20 @@ namespace ClassicalSharp { /// Reads a string, then converts control characters into the /// unicode values of their equivalent code page 437 graphical representations. public string ReadTextString() { - byte[] data = ReadBytes( 64 ); - return GetTextString( data ).TrimEnd( '\0', ' ' ); // servers can use either null or spaces for padding. + string value = GetTextString( buffer ).TrimEnd( '\0', ' ' ); // servers can use either null or spaces for padding. + Remove( 64 ); + return value; } public string ReadString() { - byte[] data = ReadBytes( 64 ); - return GetAsciiString( data ).TrimEnd( '\0', ' ' ); + string value = GetAsciiString( buffer ).TrimEnd( '\0', ' ' ); + Remove( 64 ); + return value; } + static char[] characters = new char[64]; static string GetAsciiString( byte[] data ) { - char[] characters = new char[data.Length]; - for( int i = 0; i < data.Length; i++ ) { + for( int i = 0; i < 64; i++ ) { byte code = data[i]; characters[i] = code >= 0x80 ? '?' : (char)code; } @@ -82,8 +84,7 @@ namespace ClassicalSharp { static string GetTextString( byte[] data ) { // code page 437 indices --> actual unicode characters - char[] characters = new char[data.Length]; - for( int i = 0; i < data.Length; i++ ) { + for( int i = 0; i < 64; i++ ) { byte code = data[i]; if( code < 0x20 ) { // general control characters characters[i] = controlCharReplacements[code]; diff --git a/Network/FixedBufferStream.cs b/Network/FixedBufferStream.cs index 716dd3aa4..cf294b3f1 100644 --- a/Network/FixedBufferStream.cs +++ b/Network/FixedBufferStream.cs @@ -5,7 +5,7 @@ namespace ClassicalSharp { internal class FixedBufferStream : Stream { - private byte[] _buffer; + public byte[] _buffer; private int _position; private int _length; diff --git a/Network/NetworkProcessor.cs b/Network/NetworkProcessor.cs index 2a77c9ac8..6c135eecc 100644 --- a/Network/NetworkProcessor.cs +++ b/Network/NetworkProcessor.cs @@ -329,14 +329,12 @@ namespace ClassicalSharp { case PacketId.LevelDataChunk: { int usedLength = reader.ReadInt16(); - byte[] data = reader.ReadBytes( 1024 ); - byte progress = reader.ReadUInt8(); - Window.RaiseMapLoading( progress ); - gzippedMap.Position = 0; gzippedMap.SetLength( usedLength ); - gzippedMap.Write( data, 0, usedLength ); + Buffer.BlockCopy( reader.buffer, 0, gzippedMap._buffer, 0, usedLength ); + reader.Remove( 1024 ); gzippedMap.Position = 0; + if( mapSizeIndex < 4 ) { mapSizeIndex += gzipStream.Read( mapSize, 0, 4 - mapSizeIndex ); } @@ -348,6 +346,9 @@ namespace ClassicalSharp { } mapIndex += gzipStream.Read( map, mapIndex, map.Length - mapIndex ); } + + byte progress = reader.ReadUInt8(); + Window.RaiseMapLoading( progress ); } break; case PacketId.LevelFinalise: