コード例 #1
0
        public WorldMap Unpack()
        {
            BufferOffset = 0;
            WorldMap map = new WorldMap();

            int    len  = ReadUInt16();
            ushort code = ReadUInt16();

            if (code != Constants.WorldCodeHeader)
            {
                return(null);
            }

            int Version = ReadUInt16();

            if (Version != MapVersion)
            {
                return(null);
            }

            UInt32 uncompressedSize = ReadUInt32();
            UInt32 compressedSize   = ReadUInt32();

            UInt16 zlibFlags = ReadUInt16(); // deflate doesnt need these

            try
            {
                MemoryStream  ms  = new MemoryStream(Buffer, BufferOffset, (int)compressedSize);
                DeflateStream dfs = new DeflateStream(ms, CompressionMode.Decompress);

                byte[] uncompressedData = new byte[uncompressedSize];
                dfs.Read(uncompressedData, 0, (int)uncompressedSize);
                dfs.Close();
                ms.Close();

                Buffer       = uncompressedData;
                BufferOffset = 0;

                // start parsin that sweet sweet world data
                map.AddObjects(UnpackDynamicColors());
                map.AddObjects(UnpackTextureMatricies());
                map.AddObjects(UnpackMaterials());
                map.AddObjects(UnpackPhysicsDrivers());
                map.AddObjects(UnpackTransforms());
                map.AddObjects(UnpackObstacles());
                map.AddObjects(UnpackLinks());
                map.AddObject(UnpackWaterLevel());
                map.AddObjects(UnpackWorldWeapons());
                map.AddObjects(UnpackZones());
            }
            catch (Exception /*ex*/)
            {
            }

            map.CacheRuntimeObjects();
            return(map);
        }