From 27abe81af027ab571e766261245e5f30ba0b10b7 Mon Sep 17 00:00:00 2001 From: mark Date: Thu, 14 Oct 2010 09:27:13 +0000 Subject: [PATCH] try to autodetect tiledata format --- Scripts/Misc/MapDefinitions.cs | 1 - Server/TileData.cs | 74 +++++++++++++++++++++------------- 2 files changed, 46 insertions(+), 29 deletions(-) diff --git a/Scripts/Misc/MapDefinitions.cs b/Scripts/Misc/MapDefinitions.cs index b93164bb1..37ca928f6 100644 --- a/Scripts/Misc/MapDefinitions.cs +++ b/Scripts/Misc/MapDefinitions.cs @@ -39,7 +39,6 @@ namespace Server.Misc TileMatrixPatch.Enabled = false; // OSI Client Patch 6.0.0.0 - TileData.PostHSFormat = true; // OSI Client Patch 7.0.9.0 MultiData.PostHSFormat = true; // OSI Client Patch 7.0.9.0 } diff --git a/Server/TileData.cs b/Server/TileData.cs index 2b8499fd1..2ac6d094c 100644 --- a/Server/TileData.cs +++ b/Server/TileData.cs @@ -160,7 +160,7 @@ namespace Server } [Flags] - public enum TileFlag + public enum TileFlag : long { None = 0x00000000, Background = 0x00000001, @@ -170,7 +170,7 @@ namespace Server Wall = 0x00000010, Damaging = 0x00000020, Impassable = 0x00000040, - Wet = 0x00000080, + Wet = 0x00000080, Unknown1 = 0x00000100, Surface = 0x00000200, Bridge = 0x00000400, @@ -183,7 +183,7 @@ namespace Server Foliage = 0x00020000, PartialHue = 0x00040000, Unknown2 = 0x00080000, - Map = 0x00100000, + Map = 0x00100000, Container = 0x00200000, Wearable = 0x00400000, LightSource = 0x00800000, @@ -194,18 +194,11 @@ namespace Server Roof = 0x10000000, Door = 0x20000000, StairBack = 0x40000000, - StairRight = unchecked( (int)0x80000000 ) + StairRight = 0x80000000 } public class TileData { - public static bool PostHSFormat { - get { return _PostHSFormat; } - set { _PostHSFormat = value; } - } - - private static bool _PostHSFormat = false; - private static LandData[] m_LandData; private static ItemData[] m_ItemData; @@ -248,7 +241,7 @@ namespace Server { BinaryReader bin = new BinaryReader( fs ); - if ( _PostHSFormat ) { + if ( fs.Length == 3188736 ) { // 7.0.9.0 m_LandData = new LandData[0x4000]; for ( int i = 0; i < 0x4000; ++i ) @@ -302,27 +295,52 @@ namespace Server m_LandData[i] = new LandData( ReadNameString( bin ), flags ); } - m_ItemData = new ItemData[0x4000]; + if ( fs.Length == 1644544 ) { // 7.0.0.0 + m_ItemData = new ItemData[0x8000]; - for ( int i = 0; i < 0x4000; ++i ) - { - if ( (i & 0x1F) == 0 ) + for ( int i = 0; i < 0x8000; ++i ) { - bin.ReadInt32(); // header + if ( (i & 0x1F) == 0 ) + { + bin.ReadInt32(); // header + } + + TileFlag flags = (TileFlag)bin.ReadInt32(); + int weight = bin.ReadByte(); + int quality = bin.ReadByte(); + bin.ReadInt16(); + bin.ReadByte(); + int quantity = bin.ReadByte(); + bin.ReadInt32(); + bin.ReadByte(); + int value = bin.ReadByte(); + int height = bin.ReadByte(); + + m_ItemData[i] = new ItemData( ReadNameString( bin ), flags, weight, quality, quantity, value, height ); } + } else { + m_ItemData = new ItemData[0x4000]; - TileFlag flags = (TileFlag)bin.ReadInt32(); - int weight = bin.ReadByte(); - int quality = bin.ReadByte(); - bin.ReadInt16(); - bin.ReadByte(); - int quantity = bin.ReadByte(); - bin.ReadInt32(); - bin.ReadByte(); - int value = bin.ReadByte(); - int height = bin.ReadByte(); + for ( int i = 0; i < 0x4000; ++i ) + { + if ( (i & 0x1F) == 0 ) + { + bin.ReadInt32(); // header + } - m_ItemData[i] = new ItemData( ReadNameString( bin ), flags, weight, quality, quantity, value, height ); + TileFlag flags = (TileFlag)bin.ReadInt32(); + int weight = bin.ReadByte(); + int quality = bin.ReadByte(); + bin.ReadInt16(); + bin.ReadByte(); + int quantity = bin.ReadByte(); + bin.ReadInt32(); + bin.ReadByte(); + int value = bin.ReadByte(); + int height = bin.ReadByte(); + + m_ItemData[i] = new ItemData( ReadNameString( bin ), flags, weight, quality, quantity, value, height ); + } } } }