Exemplo n.º 1
0
 public FastMap(UInt16 _x, UInt16 _y, UInt16 _z)
 {
     //Init
     sizeX = _x;
     sizeY = _y;
     sizeZ = _z;
     tiles = new FastMapBlock[_x, _y, _z];
     //Fill
     EnumerateAllBlocks((ref FastMapBlock block, int x, int y, int z) =>
     {
         block = new FastMapBlock(0);
     });
 }
Exemplo n.º 2
0
        public static FastMap LoadMap(byte[] data)
        {
            //Open stream
            MemoryStream ms = new MemoryStream(data);
            //Open meta and header
            UInt16 contentTableLocation = UInt16FromStream(ref ms);
            UInt16 mapX = UInt16FromStream(ref ms);
            UInt16 mapY = UInt16FromStream(ref ms);
            UInt16 mapZ = UInt16FromStream(ref ms);
            UInt16 rev  = UInt16FromStream(ref ms);
            //Create map
            FastMap m = new FastMap(mapX, mapY, mapZ, rev);

            //Now jump to the table location.
            ms.Position = contentTableLocation;
            //Now, read in the table.
            byte[] table = new byte[((int)mapX * (int)mapY * (int)mapZ) * 8];
            ms.Read(table, 0, table.Length);
            //Now, fill in all the blocks
            m.EnumerateAllBlocks((ref FastMapBlock block, int x, int y, int z) =>
            {
                //Write the entry in the table at position.
                int pos = ((m.sizeX * m.sizeY) * z) + (m.sizeX * y) + x;
                pos    *= 8;
                //Create block
                FastMapBlock b = new FastMapBlock();
                //Jump to this position
                UInt16 id        = UInt16FromBytes(new byte[] { table[pos], table[pos + 1] });
                byte[] flagsByte = new byte[] { table[pos + 2], table[pos + 3] };
                BitArray bc      = new BitArray(flagsByte);
                b.id             = id;
                b.flags          = new bool[] { bc[1], bc[2], bc[3], bc[4], bc[5], bc[6], bc[7], bc[8], bc[9], bc[10], bc[11], bc[12], bc[13], bc[14], bc[15] }; //Skip the 0th bool becasue that isn't shown to the user
                //If the additional data flag, bc[0], is true, get the data it is pointing to.
                if (bc[0])
                {
                    lock (ms)
                    {
                        //Jump to the location offered by the pointer.
                        long pointer = UInt32FromBytes(new byte[] { table[pos + 4], table[pos + 5], table[pos + 6], table[pos + 7] });
                        pointer     += contentTableLocation;
                        pointer     += table.Length;
                        //Jump
                        ms.Position = pointer;
                        //Read in length
                        byte[] buf = new byte[2];
                        ms.Read(buf, 0, 2);
                        if (!BitConverter.IsLittleEndian)
                        {
                            Array.Reverse(buf);
                        }
                        UInt32 len = BitConverter.ToUInt16(buf, 0);
                        //Now, read in content
                        b.data = new byte[len];
                        ms.Read(b.data, 0, (int)len);
                    }
                }
                else
                {
                    //No data. Set it to null
                    b.data = null;
                }
                //Set block
                block = b;
            });
            //Return
            ms.Close();
            return(m);
        }