Merge branch 'master' of github.com:UnknownShadow200/ClassicalSharp

This commit is contained in:
UnknownShadow200 2016-04-28 09:35:48 +10:00
commit c2658dfced
3 changed files with 17 additions and 7 deletions

View File

@ -17,8 +17,11 @@ namespace ClassicalSharp.Map {
World map;
public byte[] Load( Stream stream, Game game, out int width, out int height, out int length ) {
using( GZipStream wrapper = new GZipStream( stream, CompressionMode.Decompress ) ) {
reader = new BinaryReader( wrapper );
GZipHeaderReader gsHeader = new GZipHeaderReader();
while( !gsHeader.ReadHeader( stream ) ) { }
using( DeflateStream gs = new DeflateStream( stream, CompressionMode.Decompress ) ) {
reader = new BinaryReader( gs );
if( reader.ReadByte() != (byte)NbtTagType.Compound )
throw new InvalidDataException( "Nbt file must start with Tag_Compound" );
this.game = game;

View File

@ -5,6 +5,7 @@ using System.IO.Compression;
using System.Net;
using System.Text;
using ClassicalSharp.Entities;
using ClassicalSharp.Net;
using OpenTK;
namespace ClassicalSharp.Map {
@ -25,8 +26,10 @@ namespace ClassicalSharp.Map {
length = 0;
LocalPlayer p = game.LocalPlayer;
p.Spawn = Vector3.Zero;
GZipHeaderReader gsHeader = new GZipHeaderReader();
while( !gsHeader.ReadHeader( stream ) ) { }
using( GZipStream gs = new GZipStream( stream, CompressionMode.Decompress ) ) {
using( DeflateStream gs = new DeflateStream( stream, CompressionMode.Decompress ) ) {
reader = new BinaryReader( gs );
ClassDescription obj = ReadData();
for( int i = 0; i < obj.Fields.Length; i++ ) {

View File

@ -5,6 +5,7 @@ using System.IO;
using System.IO.Compression;
using System.Text;
using ClassicalSharp.Entities;
using ClassicalSharp.Net;
namespace ClassicalSharp.Map {
@ -13,7 +14,10 @@ namespace ClassicalSharp.Map {
const int Version = 1874;
public byte[] Load( Stream stream, Game game, out int width, out int height, out int length ) {
using( GZipStream gs = new GZipStream( stream, CompressionMode.Decompress ) ) {
GZipHeaderReader gsHeader = new GZipHeaderReader();
while( !gsHeader.ReadHeader( stream ) ) { }
using( DeflateStream gs = new DeflateStream( stream, CompressionMode.Decompress ) ) {
BinaryReader reader = new BinaryReader( gs );
ushort header = reader.ReadUInt16();
@ -40,15 +44,15 @@ namespace ClassicalSharp.Map {
}
}
void ReadCustomBlocks( GZipStream gs, int width, int height, int length, byte[] blocks ) {
void ReadCustomBlocks( Stream s, int width, int height, int length, byte[] blocks ) {
byte[] chunk = new byte[16 * 16 * 16];
for( int y = 0; y < height; y += 16 )
for( int z = 0; z < length; z += 16 )
for( int x = 0; x < width; x += 16 )
{
if( gs.ReadByte() != 1 ) continue;
gs.Read( chunk, 0, chunk.Length );
if( s.ReadByte() != 1 ) continue;
s.Read( chunk, 0, chunk.Length );
int baseIndex = (y * length + z) * width + x;
for( int i = 0; i < chunk.Length; i++ ) {