diff --git a/Substrate/SubstrateCS/Assemblies/Ionic.Zlib.dll b/Substrate/SubstrateCS/Assemblies/Ionic.Zlib.dll index 7c29e8c..23bbfdf 100644 Binary files a/Substrate/SubstrateCS/Assemblies/Ionic.Zlib.dll and b/Substrate/SubstrateCS/Assemblies/Ionic.Zlib.dll differ diff --git a/Substrate/SubstrateCS/Source/ChunkRef.cs b/Substrate/SubstrateCS/Source/ChunkRef.cs index a041a8d..de6e361 100644 --- a/Substrate/SubstrateCS/Source/ChunkRef.cs +++ b/Substrate/SubstrateCS/Source/ChunkRef.cs @@ -214,17 +214,17 @@ namespace Substrate public int XDim { - get { return _chunk.XDim; } + get { return 16; } } public int YDim { - get { return _chunk.YDim; } + get { return 128; } } public int ZDim { - get { return _chunk.ZDim; } + get { return 16; } } #endregion diff --git a/Substrate/SubstrateCS/Source/Level.cs b/Substrate/SubstrateCS/Source/Level.cs index 4c58b43..4f70246 100644 --- a/Substrate/SubstrateCS/Source/Level.cs +++ b/Substrate/SubstrateCS/Source/Level.cs @@ -10,22 +10,7 @@ namespace Substrate public class Level : INBTObject, ICopyable { - public static NBTCompoundNode LevelSchema = new NBTCompoundNode() - { - new NBTCompoundNode("Data") - { - new NBTScalerNode("Time", NBT_Type.TAG_LONG), - new NBTScalerNode("LastPlayed", NBT_Type.TAG_LONG), - new NBTCompoundNode("Player", Player.PlayerSchema), - new NBTScalerNode("SpawnX", NBT_Type.TAG_INT), - new NBTScalerNode("SpawnY", NBT_Type.TAG_INT), - new NBTScalerNode("SpawnZ", NBT_Type.TAG_INT), - new NBTScalerNode("SizeOnDisk", NBT_Type.TAG_LONG), - new NBTScalerNode("RandomSeed", NBT_Type.TAG_LONG), - new NBTScalerNode("Version", NBT_Type.TAG_INT, NBTOptions.OPTIONAL), - new NBTScalerNode("LevelName", NBT_Type.TAG_STRING, NBTOptions.OPTIONAL), - }, - }; + public static NBTCompoundNode LevelSchema; private World _world; @@ -103,6 +88,23 @@ namespace Substrate public Level (World world) { _world = world; + + LevelSchema = new NBTCompoundNode() + { + new NBTCompoundNode("Data") + { + new NBTScalerNode("Time", NBT_Type.TAG_LONG), + new NBTScalerNode("LastPlayed", NBT_Type.TAG_LONG), + new NBTCompoundNode("Player", Player.PlayerSchema, NBTOptions.OPTIONAL), + new NBTScalerNode("SpawnX", NBT_Type.TAG_INT), + new NBTScalerNode("SpawnY", NBT_Type.TAG_INT), + new NBTScalerNode("SpawnZ", NBT_Type.TAG_INT), + new NBTScalerNode("SizeOnDisk", NBT_Type.TAG_LONG), + new NBTScalerNode("RandomSeed", NBT_Type.TAG_LONG), + new NBTScalerNode("version", NBT_Type.TAG_INT, NBTOptions.OPTIONAL), + new NBTScalerNode("LevelName", NBT_Type.TAG_STRING, NBTOptions.OPTIONAL), + }, + }; } public Level (Level p) @@ -157,7 +159,9 @@ namespace Substrate _time = ctree["Time"].ToNBTLong(); _lastPlayed = ctree["LastPlayed"].ToNBTLong(); - _player = new Player().LoadTree(ctree["Player"]); + if (ctree.ContainsKey("Player")) { + _player = new Player().LoadTree(ctree["Player"]); + } _spawnX = ctree["SpawnX"].ToNBTInt(); _spawnY = ctree["SpawnY"].ToNBTInt(); @@ -166,8 +170,8 @@ namespace Substrate _sizeOnDisk = ctree["SizeOnDisk"].ToNBTLong(); _randomSeed = ctree["RandomSeed"].ToNBTLong(); - if (ctree.ContainsKey("Version")) { - _version = ctree["Version"].ToNBTInt(); + if (ctree.ContainsKey("version")) { + _version = ctree["version"].ToNBTInt(); } if (ctree.ContainsKey("LevelName")) { @@ -191,7 +195,11 @@ namespace Substrate NBT_Compound data = new NBT_Compound(); data["Time"] = new NBT_Long(_time); data["LastPlayed"] = new NBT_Long(_lastPlayed); - data["Player"] = _player.BuildTree(); + + if (_player != null) { + data["Player"] = _player.BuildTree(); + } + data["SpawnX"] = new NBT_Int(_spawnX); data["SpawnY"] = new NBT_Int(_spawnY); data["SpawnZ"] = new NBT_Int(_spawnZ); @@ -199,7 +207,7 @@ namespace Substrate data["RandomSeed"] = new NBT_Long(_randomSeed); if (_version != null) { - data["Version"] = new NBT_Int(_version ?? 0); + data["version"] = new NBT_Int(_version ?? 0); } if (_name != null) { diff --git a/Substrate/SubstrateCS/Source/NBT/JSONSerializer.cs b/Substrate/SubstrateCS/Source/NBT/JSONSerializer.cs index ce3e1de..f1f7b45 100644 --- a/Substrate/SubstrateCS/Source/NBT/JSONSerializer.cs +++ b/Substrate/SubstrateCS/Source/NBT/JSONSerializer.cs @@ -4,7 +4,7 @@ using System.Text; namespace Substrate.NBT { - class JSONSerializer + public class JSONSerializer { public static string Serialize (NBT_Value tag) { diff --git a/Substrate/SubstrateCS/Source/NBT/NBTSchema.cs b/Substrate/SubstrateCS/Source/NBT/NBTSchema.cs index 5f0903a..a627ca2 100644 --- a/Substrate/SubstrateCS/Source/NBT/NBTSchema.cs +++ b/Substrate/SubstrateCS/Source/NBT/NBTSchema.cs @@ -354,6 +354,8 @@ namespace Substrate.NBT public NBTCompoundNode (string name, NBTSchemaNode subschema) : base(name) { + _subnodes = new List(); + NBTCompoundNode schema = subschema as NBTCompoundNode; if (schema == null) { return; @@ -368,6 +370,8 @@ namespace Substrate.NBT public NBTCompoundNode (string name, NBTSchemaNode subschema, NBTOptions options) : base(name, options) { + _subnodes = new List(); + NBTCompoundNode schema = subschema as NBTCompoundNode; if (schema == null) { return; diff --git a/Substrate/SubstrateCS/Source/Region.cs b/Substrate/SubstrateCS/Source/Region.cs index f3e6a8b..3a14891 100644 --- a/Substrate/SubstrateCS/Source/Region.cs +++ b/Substrate/SubstrateCS/Source/Region.cs @@ -143,7 +143,10 @@ namespace Substrate return null; } - return new NBT_Tree(nbtstr); + NBT_Tree tree = new NBT_Tree(nbtstr); + + nbtstr.Close(); + return tree; } public bool SaveChunkTree (int lcx, int lcz, NBT_Tree tree) diff --git a/Substrate/SubstrateCS/Source/RegionFile.cs b/Substrate/SubstrateCS/Source/RegionFile.cs index 4b81735..24d7d76 100644 --- a/Substrate/SubstrateCS/Source/RegionFile.cs +++ b/Substrate/SubstrateCS/Source/RegionFile.cs @@ -237,14 +237,24 @@ namespace Substrate byte[] data = new byte[length - 1]; file.Read(data, 0, data.Length); Stream ret = new GZipStream(new MemoryStream(data), CompressionMode.Decompress); - // Debug("READ", x, z, " = found"); + return ret; - } else if (version == VERSION_DEFLATE) { + } + else if (version == VERSION_DEFLATE) { byte[] data = new byte[length - 1]; file.Read(data, 0, data.Length); + Stream ret = new ZlibStream(new MemoryStream(data), CompressionMode.Decompress, true); - // Debug("READ", x, z, " = found"); return ret; + + /*MemoryStream sinkZ = new MemoryStream(); + ZlibStream zOut = new ZlibStream(sinkZ, CompressionMode.Decompress, true); + zOut.Write(data, 0, data.Length); + zOut.Flush(); + zOut.Close(); + + sinkZ.Seek(0, SeekOrigin.Begin); + return sinkZ;*/ } Debugln("READ", x, z, "unknown version " + version); diff --git a/Substrate/SubstrateCS/Source/World.cs b/Substrate/SubstrateCS/Source/World.cs index 6400d0a..d77bc6b 100644 --- a/Substrate/SubstrateCS/Source/World.cs +++ b/Substrate/SubstrateCS/Source/World.cs @@ -61,7 +61,10 @@ namespace Substrate return false; } - _level = new Level(this).LoadTreeSafe(new NBT_Tree(nbtstr).Root); + NBT_Tree tree = new NBT_Tree(nbtstr); + + _level = new Level(this); + _level = _level.LoadTreeSafe(tree.Root); return _level != null; } diff --git a/Substrate/SubstrateCS/Substrate.csproj b/Substrate/SubstrateCS/Substrate.csproj index f9358d5..deef722 100644 --- a/Substrate/SubstrateCS/Substrate.csproj +++ b/Substrate/SubstrateCS/Substrate.csproj @@ -54,13 +54,12 @@ - + False Assemblies\Ionic.Zlib.dll - diff --git a/Substrate/SubstrateCS/Substrate.sln b/Substrate/SubstrateCS/Substrate.sln index 5c12077..73b0b82 100644 --- a/Substrate/SubstrateCS/Substrate.sln +++ b/Substrate/SubstrateCS/Substrate.sln @@ -3,6 +3,10 @@ Microsoft Visual Studio Solution File, Format Version 10.00 # Visual C# Express 2008 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Substrate", "Substrate.csproj", "{AFE30E14-3F2F-4461-9F7D-147AB4DCA4C3}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NBToolkit", "..\..\NBToolkit\NBToolkit.csproj", "{68207314-C080-4823-97F1-A6623145AA00}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ionic.Zlib", "..\..\Ionic.Zlib\Ionic.Zlib.csproj", "{5A137E43-7E7B-4696-8BFC-844CACAB144B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -13,6 +17,14 @@ Global {AFE30E14-3F2F-4461-9F7D-147AB4DCA4C3}.Debug|Any CPU.Build.0 = Debug|Any CPU {AFE30E14-3F2F-4461-9F7D-147AB4DCA4C3}.Release|Any CPU.ActiveCfg = Release|Any CPU {AFE30E14-3F2F-4461-9F7D-147AB4DCA4C3}.Release|Any CPU.Build.0 = Release|Any CPU + {68207314-C080-4823-97F1-A6623145AA00}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {68207314-C080-4823-97F1-A6623145AA00}.Debug|Any CPU.Build.0 = Debug|Any CPU + {68207314-C080-4823-97F1-A6623145AA00}.Release|Any CPU.ActiveCfg = Release|Any CPU + {68207314-C080-4823-97F1-A6623145AA00}.Release|Any CPU.Build.0 = Release|Any CPU + {5A137E43-7E7B-4696-8BFC-844CACAB144B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5A137E43-7E7B-4696-8BFC-844CACAB144B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5A137E43-7E7B-4696-8BFC-844CACAB144B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5A137E43-7E7B-4696-8BFC-844CACAB144B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE