Ejemplo n.º 1
1
 private void WriteStatic(BinaryWriter bw, HuedTile stat)
 {
     bw.Write((ushort)stat.ID);
     bw.Write((ushort)0);
     bw.Write((sbyte)stat.Z);
     bw.Write((ushort)stat.Hue);
 }
Ejemplo n.º 2
0
        public HuedTile[][][] GetStaticBlock(int x, int y, bool patch)
        {
            if (x < 0 || y < 0 || x >= BlockWidth || y >= BlockHeight)
            {
                return(EmptyStaticBlock);
            }

            if (m_StaticTiles[x] == null)
            {
                m_StaticTiles[x] = new HuedTile[BlockHeight][][][];
            }

            HuedTile[][][] tiles = m_StaticTiles[x][y];

            if (tiles == null)
            {
                tiles = m_StaticTiles[x][y] = ReadStaticBlock(x, y);
            }

            if ((Map.UseDiff) && (patch))
            {
                if (Patch.StaticBlocksCount > 0)
                {
                    if (Patch.StaticBlocks[x] != null)
                    {
                        if (Patch.StaticBlocks[x][y] != null)
                        {
                            tiles = Patch.StaticBlocks[x][y];
                        }
                    }
                }
            }

            return(tiles);
        }
Ejemplo n.º 3
0
        public TileMatrix(int fileIndex, int mapID, int width, int height)
        {
            m_Width       = width;
            m_Height      = height;
            m_BlockWidth  = width >> 3;
            m_BlockHeight = height >> 3;

            if (fileIndex != 0x7F)
            {
                string mapPath = Client.GetFilePath("map{0}.mul", fileIndex);

                if (mapPath != null && File.Exists(mapPath))
                {
                    m_Map = new FileStream(mapPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                }

                string indexPath = Client.GetFilePath("staidx{0}.mul", fileIndex);

                if (indexPath != null && File.Exists(indexPath))
                {
                    m_Index       = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                    m_IndexReader = new BinaryReader(m_Index);
                }

                string staticsPath = Client.GetFilePath("statics{0}.mul", fileIndex);

                if (staticsPath != null && File.Exists(staticsPath))
                {
                    m_Statics = new FileStream(staticsPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                }
            }

            m_EmptyStaticBlock = new HuedTile[8][][];

            for (int i = 0; i < 8; ++i)
            {
                m_EmptyStaticBlock[i] = new HuedTile[8][];

                for (int j = 0; j < 8; ++j)
                {
                    m_EmptyStaticBlock[i][j] = new HuedTile[0];
                }
            }

            m_InvalidLandBlock = new Tile[196];

            m_LandTiles   = new Tile[m_BlockWidth][][];
            m_StaticTiles = new HuedTile[m_BlockWidth][][][][];

            m_Patch = new TileMatrixPatch(this, mapID);

            /*for ( int i = 0; i < m_BlockWidth; ++i )
             * {
             *      m_LandTiles[i] = new Tile[m_BlockHeight][];
             *      m_StaticTiles[i] = new Tile[m_BlockHeight][][][];
             * }*/
        }
Ejemplo n.º 4
0
        public HuedTile[] ToArray()
        {
            HuedTile[] tiles = new HuedTile[Count];

            if (m_Tiles.Count > 0)
                m_Tiles.CopyTo(tiles);
            m_Tiles.Clear();

            return tiles;
        }
 public HuedTile[] ToArray()
 {
     HuedTile[] mTiles = new HuedTile[this.m_Count];
     for (int i = 0; i < this.m_Count; i++)
     {
         mTiles[i] = this.m_Tiles[i];
     }
     this.m_Count = 0;
     return mTiles;
 }
Ejemplo n.º 6
0
 public HuedTile[] ToArray()
 {
     HuedTile[] mTiles = new HuedTile[this.m_Count];
     for (int i = 0; i < this.m_Count; i++)
     {
         mTiles[i] = this.m_Tiles[i];
     }
     this.m_Count = 0;
     return(mTiles);
 }
Ejemplo n.º 7
0
		public HuedTile[] ToArray()
		{
			HuedTile[] tiles = new HuedTile[m_Count];

			for ( int i = 0; i < m_Count; ++i )
				tiles[i] = m_Tiles[i];

			m_Count = 0;

			return tiles;
		}
Ejemplo n.º 8
0
        public TileMatrixPatch(TileMatrix matrix, int index, string path)
        {
            BlockWidth = matrix.BlockWidth;
            BlockHeight = matrix.BlockWidth;

            LandBlocksCount = StaticBlocksCount = 0;
            string mapDataPath, mapIndexPath;
            if (path == null)
            {
                mapDataPath = Files.GetFilePath("mapdif{0}.mul", index);
                mapIndexPath = Files.GetFilePath("mapdifl{0}.mul", index);
            }
            else
            {
                mapDataPath = Path.Combine(path, String.Format("mapdif{0}.mul", index));
                if (!File.Exists(mapDataPath))
                    mapDataPath = null;
                mapIndexPath = Path.Combine(path, String.Format("mapdifl{0}.mul", index));
                if (!File.Exists(mapIndexPath))
                    mapIndexPath = null;
            }

            if (mapDataPath != null && mapIndexPath != null)
            {
                LandBlocks = new Tile[matrix.BlockWidth][][];
                LandBlocksCount = PatchLand(matrix, mapDataPath, mapIndexPath);
            }

            string staDataPath, staIndexPath, staLookupPath;
            if (path == null)
            {
                staDataPath = Files.GetFilePath("stadif{0}.mul", index);
                staIndexPath = Files.GetFilePath("stadifl{0}.mul", index);
                staLookupPath = Files.GetFilePath("stadifi{0}.mul", index);
            }
            else
            {
                staDataPath = Path.Combine(path, String.Format("stadif{0}.mul", index));
                if (!File.Exists(staDataPath))
                    staDataPath = null;
                staIndexPath = Path.Combine(path, String.Format("stadifl{0}.mul", index));
                if (!File.Exists(staIndexPath))
                    staIndexPath = null;
                staLookupPath = Path.Combine(path, String.Format("stadifi{0}.mul", index));
                if (!File.Exists(staLookupPath))
                    staLookupPath = null;
            }

            if (staDataPath != null && staIndexPath != null && staLookupPath != null)
            {
                StaticBlocks = new HuedTile[matrix.BlockWidth][][][][];
                StaticBlocksCount = PatchStatics(matrix, staDataPath, staIndexPath, staLookupPath);
            }
        }
Ejemplo n.º 9
0
        public HuedTile[] ToArray()
        {
            var tiles = new HuedTile[Count];

            if (m_Tiles.Count > 0)
            {
                m_Tiles.CopyTo(tiles);
            }
            m_Tiles.Clear();

            return(tiles);
        }
Ejemplo n.º 10
0
        public HuedTile[] ToArray()
        {
            HuedTile[] tiles = new HuedTile[m_Count];

            for (int i = 0; i < m_Count; ++i)
            {
                tiles[i] = m_Tiles[i];
            }

            m_Count = 0;

            return(tiles);
        }
Ejemplo n.º 11
0
        public void SetStaticBlock(int x, int y, HuedTile[][][] value)
        {
            if (x < 0 || y < 0 || x >= m_BlockWidth || y >= m_BlockHeight)
            {
                return;
            }

            if (m_StaticTiles[x] == null)
            {
                m_StaticTiles[x] = new HuedTile[m_BlockHeight][][][];
            }

            m_StaticTiles[x][y] = value;
        }
Ejemplo n.º 12
0
        private unsafe HuedTile[][][] ReadStaticBlock(int x, int y)
        {
            this.m_IndexReader.BaseStream.Seek((long)((x * this.m_BlockHeight + y) * 12), SeekOrigin.Begin);
            int num  = this.m_IndexReader.ReadInt32();
            int num1 = this.m_IndexReader.ReadInt32();

            if (num < 0 || num1 <= 0)
            {
                return(this.m_EmptyStaticBlock);
            }
            int num2 = num1 / 7;

            this.m_Statics.Seek((long)num, SeekOrigin.Begin);
            fixed(StaticTile *staticTilePointer = &(new StaticTile[num2])[0])
            {
                TileMatrix._lread(this.m_Statics.Handle, staticTilePointer, num1);
                if (TileMatrix.m_Lists == null)
                {
                    TileMatrix.m_Lists = new HuedTileList[8][];
                    for (int i = 0; i < 8; i++)
                    {
                        TileMatrix.m_Lists[i] = new HuedTileList[8];
                        for (int j = 0; j < 8; j++)
                        {
                            TileMatrix.m_Lists[i][j] = new HuedTileList();
                        }
                    }
                }
                HuedTileList[][] mLists             = TileMatrix.m_Lists;
                StaticTile *     staticTilePointer1 = staticTilePointer;
                StaticTile *     staticTilePointer2 = staticTilePointer + num2 * sizeof(StaticTile);

                while (staticTilePointer1 < staticTilePointer2)
                {
                    mLists[(*staticTilePointer1).m_X & 7][(*staticTilePointer1).m_Y & 7].Add((short)(((*staticTilePointer1).m_ID & 16383) + 16384), (*staticTilePointer1).m_Hue, (*staticTilePointer1).m_Z);
                    staticTilePointer1 = staticTilePointer1 + sizeof(StaticTile);
                }
                HuedTile[][][] array = new HuedTile[8][][];
                for (int k = 0; k < 8; k++)
                {
                    array[k] = new HuedTile[8][];
                    for (int l = 0; l < 8; l++)
                    {
                        array[k][l] = mLists[k][l].ToArray();
                    }
                }
                return(array);
            }
        }
Ejemplo n.º 13
0
        public HuedTile[][][] GetStaticBlock(int x, int y)
        {
            if (x < 0 || y < 0 || x >= m_BlockWidth || y >= m_BlockHeight || m_Statics == null || m_Index == null)
            {
                return(m_EmptyStaticBlock);
            }

            if (m_StaticTiles[x] == null)
            {
                m_StaticTiles[x] = new HuedTile[m_BlockHeight][][][];
            }

            HuedTile[][][] tiles = m_StaticTiles[x][y] ?? (m_StaticTiles[x][y] = ReadStaticBlock(x, y));

            return(tiles);
        }
Ejemplo n.º 14
0
        private unsafe HuedTile[][][] ReadStaticBlock(int x, int y)
        {
            this.m_IndexReader.BaseStream.Seek((long)((x * this.m_BlockHeight + y) * 12), SeekOrigin.Begin);
            int num    = this.m_IndexReader.ReadInt32();
            int wBytes = this.m_IndexReader.ReadInt32();

            if (num < 0 || wBytes <= 0)
            {
                return(this.m_EmptyStaticBlock);
            }
            int length = wBytes / 7;

            this.m_Statics.Seek((long)num, SeekOrigin.Begin);
            fixed(StaticTile *staticTilePtr1 = &new StaticTile[length][0])
            {
                TileMatrix._lread(this.m_Statics.Handle, (void *)staticTilePtr1, wBytes);
                if (TileMatrix.m_Lists == null)
                {
                    TileMatrix.m_Lists = new HuedTileList[8][];
                    for (int index1 = 0; index1 < 8; ++index1)
                    {
                        TileMatrix.m_Lists[index1] = new HuedTileList[8];
                        for (int index2 = 0; index2 < 8; ++index2)
                        {
                            TileMatrix.m_Lists[index1][index2] = new HuedTileList();
                        }
                    }
                }
                HuedTileList[][] huedTileListArray = TileMatrix.m_Lists;
                StaticTile *     staticTilePtr2    = staticTilePtr1;

                for (StaticTile *staticTilePtr3 = staticTilePtr1 + length; staticTilePtr2 < staticTilePtr3; ++staticTilePtr2)
                {
                    huedTileListArray[(int)staticTilePtr2->m_X & 7][(int)staticTilePtr2->m_Y & 7].Add((short)(((int)staticTilePtr2->m_ID & 16383) + 16384), staticTilePtr2->m_Hue, staticTilePtr2->m_Z);
                }
                HuedTile[][][] huedTileArray = new HuedTile[8][][];
                for (int index1 = 0; index1 < 8; ++index1)
                {
                    huedTileArray[index1] = new HuedTile[8][];
                    for (int index2 = 0; index2 < 8; ++index2)
                    {
                        huedTileArray[index1][index2] = huedTileListArray[index1][index2].ToArray();
                    }
                }
                return(huedTileArray);
            }
        }
Ejemplo n.º 15
0
 public void RemoveStaticBlock(int blockx, int blocky)
 {
     if (m_RemovedStaticBlock == null)
     {
         m_RemovedStaticBlock = new bool[BlockWidth][];
     }
     if (m_RemovedStaticBlock[blockx] == null)
     {
         m_RemovedStaticBlock[blockx] = new bool[BlockHeight];
     }
     m_RemovedStaticBlock[blockx][blocky] = true;
     if (m_StaticTiles[blockx] == null)
     {
         m_StaticTiles[blockx] = new HuedTile[BlockHeight][][][];
     }
     m_StaticTiles[blockx][blocky] = EmptyStaticBlock;
 }
Ejemplo n.º 16
0
        //manual input dir selection FIX
        public TileMatrix(string inpath, int fileIndex, int mapID, int width, int height)
        {
            m_Width       = width;
            m_Height      = height;
            m_BlockWidth  = width >> 3;
            m_BlockHeight = height >> 3;

            if (fileIndex != 0x7F)
            {
                string mapPath = inpath + "map" + mapID + ".mul";
                m_Map = new FileStream(mapPath, FileMode.Open, FileAccess.Read, FileShare.Read);

                string indexPath = inpath + "staidx" + mapID + ".mul";
                m_Index       = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                m_IndexReader = new BinaryReader(m_Index);

                string staticsPath = inpath + "statics" + mapID + ".mul";
                m_Statics = new FileStream(staticsPath, FileMode.Open, FileAccess.Read, FileShare.Read);
            }

            m_EmptyStaticBlock = new HuedTile[8][][];

            for (int i = 0; i < 8; ++i)
            {
                m_EmptyStaticBlock[i] = new HuedTile[8][];

                for (int j = 0; j < 8; ++j)
                {
                    m_EmptyStaticBlock[i][j] = new HuedTile[0];
                }
            }

            m_InvalidLandBlock = new Tile[196];

            //m_LandTiles = new Tile[m_BlockWidth][][];
            //m_StaticTiles = new HuedTile[m_BlockWidth][][][][];

            //m_Patch = new TileMatrixPatch( this, mapID );

            /*for ( int i = 0; i < m_BlockWidth; ++i )
             *          {
             *                  m_LandTiles[i] = new Tile[m_BlockHeight][];
             *                  m_StaticTiles[i] = new Tile[m_BlockHeight][][][];
             *          }*/
        }
Ejemplo n.º 17
0
            public int Compare(object x, object y)
            {
                HuedTile a = (HuedTile)x;
                HuedTile b = (HuedTile)y;

                if (a.Z > b.Z)
                {
                    return(-1);
                }
                else if (a.Z == b.Z)
                {
                    return(0);
                }
                else
                {
                    return(1);
                }
            }
Ejemplo n.º 18
0
        public void RemoveStaticBlock(int blockX, int blockY)
        {
            if (_removedStaticBlock == null)
            {
                _removedStaticBlock = new bool[BlockWidth][];
            }

            if (_removedStaticBlock[blockX] == null)
            {
                _removedStaticBlock[blockX] = new bool[BlockHeight];
            }

            _removedStaticBlock[blockX][blockY] = true;
            if (_staticTiles[blockX] == null)
            {
                _staticTiles[blockX] = new HuedTile[BlockHeight][][][];
            }

            _staticTiles[blockX][blockY] = EmptyStaticBlock;
        }
Ejemplo n.º 19
0
        // Nolok: To prevent race conditions when doing the conversion in parallel mode, i need to pre-load the map.
        //  This because UltimaSDK loads the map block only when you are accessing a tile located into it.
        public void PreLoadMap(byte task_mapstatics, ProgressBarValDelegate ProgressSetMax, ProgressBarValDelegate ProgressSetVal, LogDelegate SendLog)
        {
            m_LandTiles   = null;
            m_StaticTiles = null;
            m_LandTiles   = new Tile[m_BlockWidth][][];
            m_StaticTiles = new HuedTile[m_BlockWidth][][][][];

            ProgressSetMax(400);
            int prog = 0, progMax = (m_BlockWidth * m_BlockHeight);
            int progVal = 0, progValOld = 0;

            for (int blockX = 0; blockX < m_BlockWidth; blockX++)
            {
                //if (m_LandTiles[blockX] == null)
                m_LandTiles[blockX] = new Tile[m_BlockHeight][];
                if (task_mapstatics == 0) // && (m_StaticTiles[blocksX] == null)
                {
                    m_StaticTiles[blockX] = new HuedTile[m_BlockHeight][][][];
                }

                for (int blockY = 0; blockY < m_BlockHeight; blockY++)
                {
                    //if (m_LandTiles[blockX][blockY] == null)
                    m_LandTiles[blockX][blockY] = ReadLandBlock(blockX, blockY);
                    if (task_mapstatics == 0) // && (m_StaticTiles[blockX][blockY] == null)
                    {
                        m_StaticTiles[blockX][blockY] = ReadStaticBlock(blockX, blockY);
                    }

                    SendLog(string.Format("\nReading 8x8 block {0} (blockX {1}, blockY {2}). Ingame coords X[{3}-{4}] Y[{5}-{6}]",
                                          prog, blockX, blockY, blockX * 64, (blockX * 64) + 63, blockY * 64, (blockY * 64) + 63));
                    prog++;
                    progVal = (prog * 400) / progMax;
                    if (progVal > progValOld)
                    {
                        ProgressSetVal(progVal);
                    }
                    progValOld = progVal;
                }
            }
        }
Ejemplo n.º 20
0
        public HuedTile[][][] GetStaticBlock(int x, int y, bool patch = true)
        {
            if (x < 0 || y < 0 || x >= BlockWidth || y >= BlockHeight)
            {
                return(EmptyStaticBlock);
            }

            if (_staticTiles[x] == null)
            {
                _staticTiles[x] = new HuedTile[BlockHeight][][][];
            }

            HuedTile[][][] tiles = _staticTiles[x][y] ?? (_staticTiles[x][y] = ReadStaticBlock(x, y));

            if (Map.UseDiff && patch && Patch.StaticBlocksCount > 0 && Patch.StaticBlocks[x]?[y] != null)
            {
                tiles = Patch.StaticBlocks[x][y];
            }

            return(tiles);
        }
Ejemplo n.º 21
0
        public TileMatrix( int fileIndex, int mapID, int width, int height )
        {
            m_Width = width;
            m_Height = height;
            m_BlockWidth = width >> 3;
            m_BlockHeight = height >> 3;

            if ( fileIndex != 0x7F )
            {
                string mapPath = Client.GetFilePath( "map{0}.mul", fileIndex );

                if ( mapPath != null && File.Exists( mapPath ) )
                    m_Map = new FileStream( mapPath, FileMode.Open, FileAccess.Read, FileShare.Read );

                string indexPath = Client.GetFilePath( "staidx{0}.mul", fileIndex );

                if ( indexPath != null && File.Exists( indexPath ) )
                {
                    m_Index = new FileStream( indexPath, FileMode.Open, FileAccess.Read, FileShare.Read );
                    m_IndexReader = new BinaryReader( m_Index );
                }

                string staticsPath = Client.GetFilePath( "statics{0}.mul", fileIndex );

                if ( staticsPath != null && File.Exists( staticsPath ) )
                    m_Statics = new FileStream( staticsPath, FileMode.Open, FileAccess.Read, FileShare.Read );
            }

            m_EmptyStaticBlock = new HuedTile[8][][];

            for ( int i = 0; i < 8; ++i )
            {
                m_EmptyStaticBlock[i] = new HuedTile[8][];

                for ( int j = 0; j < 8; ++j )
                {
                    m_EmptyStaticBlock[i][j] = new HuedTile[0];
                }
            }

            m_InvalidLandBlock = new Tile[196];

            m_LandTiles = new Tile[m_BlockWidth][][];
            m_StaticTiles = new HuedTile[m_BlockWidth][][][][];

            m_Patch = new TileMatrixPatch( this, mapID );

            /*for ( int i = 0; i < m_BlockWidth; ++i )
            {
                m_LandTiles[i] = new Tile[m_BlockHeight][];
                m_StaticTiles[i] = new Tile[m_BlockHeight][][][];
            }*/
        }
Ejemplo n.º 22
0
        public TileMatrix(int fileIndex, int mapID, int width, int height, string path)
        {
            Width       = width;
            Height      = height;
            BlockWidth  = width >> 3;
            BlockHeight = height >> 3;

            if (path == null)
            {
                mapPath = Files.GetFilePath("map{0}.mul", fileIndex);
                if (String.IsNullOrEmpty(mapPath) || !File.Exists(mapPath))
                {
                    mapPath = Files.GetFilePath("map{0}LegacyMUL.uop", fileIndex);
                }

                if (mapPath != null && mapPath.EndsWith(".uop"))
                {
                    IsUOPFormat = true;
                }
            }
            else
            {
                mapPath = Path.Combine(path, String.Format("map{0}.mul", fileIndex));
                if (!File.Exists(mapPath))
                {
                    mapPath = Path.Combine(path, String.Format("map{0}LegacyMUL.uop", fileIndex));
                }
                if (!File.Exists(mapPath))
                {
                    mapPath = null;
                }
                else if (mapPath != null && mapPath.EndsWith(".uop"))
                {
                    IsUOPFormat = true;
                }
            }

            if (path == null)
            {
                indexPath = Files.GetFilePath("staidx{0}.mul", fileIndex);
            }
            else
            {
                indexPath = Path.Combine(path, String.Format("staidx{0}.mul", fileIndex));
                if (!File.Exists(indexPath))
                {
                    indexPath = null;
                }
            }

            if (path == null)
            {
                staticsPath = Files.GetFilePath("statics{0}.mul", fileIndex);
            }
            else
            {
                staticsPath = Path.Combine(path, String.Format("statics{0}.mul", fileIndex));
                if (!File.Exists(staticsPath))
                {
                    staticsPath = null;
                }
            }

            EmptyStaticBlock = new HuedTile[8][][];

            for (int i = 0; i < 8; ++i)
            {
                EmptyStaticBlock[i] = new HuedTile[8][];

                for (int j = 0; j < 8; ++j)
                {
                    EmptyStaticBlock[i][j] = new HuedTile[0];
                }
            }

            InvalidLandBlock = new Tile[196];

            m_LandTiles   = new Tile[BlockWidth][][];
            m_StaticTiles = new HuedTile[BlockWidth][][][][];

            Patch = new TileMatrixPatch(this, mapID, path);
        }
Ejemplo n.º 23
0
        public HuedTile[][][] GetStaticBlock( int x, int y )
        {
            if ( x < 0 || y < 0 || x >= m_BlockWidth || y >= m_BlockHeight || m_Statics == null || m_Index == null )
                return m_EmptyStaticBlock;

            if ( m_StaticTiles[x] == null )
                m_StaticTiles[x] = new HuedTile[m_BlockHeight][][][];

            HuedTile[][][] tiles = m_StaticTiles[x][y];

            if ( tiles == null )
                tiles = m_StaticTiles[x][y] = ReadStaticBlock( x, y );

            return tiles;
        }
 private unsafe HuedTile[][][] ReadStaticBlock(int x, int y)
 {
     this.m_IndexReader.BaseStream.Seek((long)((x * this.m_BlockHeight + y) * 12), SeekOrigin.Begin);
     int num = this.m_IndexReader.ReadInt32();
     int num1 = this.m_IndexReader.ReadInt32();
     if (num < 0 || num1 <= 0)
     {
         return this.m_EmptyStaticBlock;
     }
     int num2 = num1 / 7;
     this.m_Statics.Seek((long)num, SeekOrigin.Begin);
     fixed (StaticTile* staticTilePointer = &(new StaticTile[num2])[0])
     {
         TileMatrix._lread(this.m_Statics.Handle, staticTilePointer, num1);
         if (TileMatrix.m_Lists == null)
         {
             TileMatrix.m_Lists = new HuedTileList[8][];
             for (int i = 0; i < 8; i++)
             {
                 TileMatrix.m_Lists[i] = new HuedTileList[8];
                 for (int j = 0; j < 8; j++)
                 {
                     TileMatrix.m_Lists[i][j] = new HuedTileList();
                 }
             }
         }
         HuedTileList[][] mLists = TileMatrix.m_Lists;
         StaticTile* staticTilePointer1 = staticTilePointer;
         StaticTile* staticTilePointer2 = staticTilePointer + num2 * sizeof(StaticTile);
         while (staticTilePointer1 < staticTilePointer2)
         {
             mLists[(*staticTilePointer1).m_X & 7][(*staticTilePointer1).m_Y & 7].Add((short)(((*staticTilePointer1).m_ID & 16383) + 16384), (*staticTilePointer1).m_Hue, (*staticTilePointer1).m_Z);
             staticTilePointer1 = staticTilePointer1 + sizeof(StaticTile);
         }
         HuedTile[][][] array = new HuedTile[8][][];
         for (int k = 0; k < 8; k++)
         {
             array[k] = new HuedTile[8][];
             for (int l = 0; l < 8; l++)
             {
                 array[k][l] = mLists[k][l].ToArray();
             }
         }
         return array;
     }
 }
Ejemplo n.º 25
0
		public void SetStaticBlock(int x, int y, HuedTile[][][] value)
		{
			if (x < 0 || y < 0 || x >= BlockWidth || y >= BlockHeight)
			{
				return;
			}

			if (m_StaticTiles[x] == null)
			{
				m_StaticTiles[x] = new HuedTile[BlockHeight][][][];
			}

			m_StaticTiles[x][y] = value;
		}
Ejemplo n.º 26
0
        private unsafe int PatchStatics(TileMatrix matrix, string dataPath, string indexPath, string lookupPath)
        {
            int num;

            using (FileStream fileStream = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                using (FileStream fileStream1 = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    using (FileStream fileStream2 = new FileStream(lookupPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        BinaryReader     binaryReader  = new BinaryReader(fileStream1);
                        BinaryReader     binaryReader1 = new BinaryReader(fileStream2);
                        int              length        = (int)(binaryReader.BaseStream.Length / (long)4);
                        HuedTileList[][] huedTileList  = new HuedTileList[8][];
                        for (int i = 0; i < 8; i++)
                        {
                            huedTileList[i] = new HuedTileList[8];
                            for (int j = 0; j < 8; j++)
                            {
                                huedTileList[i][j] = new HuedTileList();
                            }
                        }
                        for (int k = 0; k < length; k++)
                        {
                            int num1         = binaryReader.ReadInt32();
                            int blockHeight  = num1 / matrix.BlockHeight;
                            int blockHeight1 = num1 % matrix.BlockHeight;
                            int num2         = binaryReader1.ReadInt32();
                            int num3         = binaryReader1.ReadInt32();
                            binaryReader1.ReadInt32();
                            if (num2 < 0 || num3 <= 0)
                            {
                                matrix.SetStaticBlock(blockHeight, blockHeight1, matrix.EmptyStaticBlock);
                            }
                            else
                            {
                                fileStream.Seek((long)num2, SeekOrigin.Begin);
                                int          num4            = num3 / 7;
                                StaticTile[] staticTileArray = new StaticTile[num4];
                                try
                                {
                                    fixed(StaticTile *staticTilePointer = &staticTileArray[0])
                                    {
                                        TileMatrixPatch._lread(fileStream.Handle, staticTilePointer, num3);
                                        StaticTile *staticTilePointer1 = staticTilePointer;
                                        StaticTile *staticTilePointer2 = staticTilePointer + num4 * sizeof(StaticTile);

                                        while (staticTilePointer1 < staticTilePointer2)
                                        {
                                            huedTileList[(*staticTilePointer1).m_X & 7][(*staticTilePointer1).m_Y & 7].Add((short)(((*staticTilePointer1).m_ID & 16383) + 16384), (*staticTilePointer1).m_Hue, (*staticTilePointer1).m_Z);
                                            staticTilePointer1 = staticTilePointer1 + sizeof(StaticTile);
                                        }
                                        HuedTile[][][] array = new HuedTile[8][][];
                                        for (int l = 0; l < 8; l++)
                                        {
                                            array[l] = new HuedTile[8][];
                                            for (int m = 0; m < 8; m++)
                                            {
                                                array[l][m] = huedTileList[l][m].ToArray();
                                            }
                                        }
                                        matrix.SetStaticBlock(blockHeight, blockHeight1, array);
                                    }
                                }
                                finally
                                {
                                    staticTilePointer = null;
                                }
                            }
                        }
                        num = length;
                    }
                }
            }
            return(num);
        }
Ejemplo n.º 27
0
        public TileMatrix(int fileIndex, int mapID, int width, int height, string path)
        {
            Width = width;
            Height = height;
            BlockWidth = width >> 3;
            BlockHeight = height >> 3;

            if (path == null)
                mapPath = Files.GetFilePath("map{0}.mul", fileIndex);
            else
            {
                mapPath = Path.Combine(path, String.Format("map{0}.mul", fileIndex));
                if (!File.Exists(mapPath))
                    mapPath = null;
            }

            if (path == null)
                indexPath = Files.GetFilePath("staidx{0}.mul", fileIndex);
            else
            {
                indexPath = Path.Combine(path, String.Format("staidx{0}.mul", fileIndex));
                if (!File.Exists(indexPath))
                    indexPath = null;
            }

            if (path == null)
                staticsPath = Files.GetFilePath("statics{0}.mul", fileIndex);
            else
            {
                staticsPath = Path.Combine(path, String.Format("statics{0}.mul", fileIndex));
                if (!File.Exists(staticsPath))
                    staticsPath = null;
            }

            EmptyStaticBlock = new HuedTile[8][][];

            for (int i = 0; i < 8; ++i)
            {
                EmptyStaticBlock[i] = new HuedTile[8][];

                for (int j = 0; j < 8; ++j)
                {
                    EmptyStaticBlock[i][j] = new HuedTile[0];
                }
            }

            InvalidLandBlock = new Tile[196];

            m_LandTiles = new Tile[BlockWidth][][];
            m_StaticTiles = new HuedTile[BlockWidth][][][][];

            Patch = new TileMatrixPatch(this, mapID, path);
        }
Ejemplo n.º 28
0
        private unsafe int PatchStatics(TileMatrix matrix, string dataPath, string indexPath, string lookupPath)
        {
            using (FileStream fileStream1 = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                using (FileStream fileStream2 = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    using (FileStream fileStream3 = new FileStream(lookupPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        BinaryReader     binaryReader1     = new BinaryReader((Stream)fileStream2);
                        BinaryReader     binaryReader2     = new BinaryReader((Stream)fileStream3);
                        int              num1              = (int)(binaryReader1.BaseStream.Length / 4L);
                        HuedTileList[][] huedTileListArray = new HuedTileList[8][];
                        for (int index1 = 0; index1 < 8; ++index1)
                        {
                            huedTileListArray[index1] = new HuedTileList[8];
                            for (int index2 = 0; index2 < 8; ++index2)
                            {
                                huedTileListArray[index1][index2] = new HuedTileList();
                            }
                        }
                        for (int index1 = 0; index1 < num1; ++index1)
                        {
                            int num2   = binaryReader1.ReadInt32();
                            int x      = num2 / matrix.BlockHeight;
                            int y      = num2 % matrix.BlockHeight;
                            int num3   = binaryReader2.ReadInt32();
                            int wBytes = binaryReader2.ReadInt32();
                            binaryReader2.ReadInt32();
                            if (num3 < 0 || wBytes <= 0)
                            {
                                matrix.SetStaticBlock(x, y, matrix.EmptyStaticBlock);
                            }
                            else
                            {
                                fileStream1.Seek((long)num3, SeekOrigin.Begin);
                                int          length          = wBytes / 7;
                                StaticTile[] staticTileArray = new StaticTile[length];
                                fixed(StaticTile *staticTilePtr1 = &staticTileArray[0])
                                {
                                    TileMatrixPatch._lread(fileStream1.Handle, (void *)staticTilePtr1, wBytes);
                                    StaticTile *staticTilePtr2 = staticTilePtr1;

                                    for (StaticTile *staticTilePtr3 = staticTilePtr1 + length; staticTilePtr2 < staticTilePtr3; ++staticTilePtr2)
                                    {
                                        huedTileListArray[(int)staticTilePtr2->m_X & 7][(int)staticTilePtr2->m_Y & 7].Add((short)(((int)staticTilePtr2->m_ID & 16383) + 16384), staticTilePtr2->m_Hue, staticTilePtr2->m_Z);
                                    }
                                    HuedTile[][][] huedTileArray = new HuedTile[8][][];
                                    for (int index2 = 0; index2 < 8; ++index2)
                                    {
                                        huedTileArray[index2] = new HuedTile[8][];
                                        for (int index3 = 0; index3 < 8; ++index3)
                                        {
                                            huedTileArray[index2][index3] = huedTileListArray[index2][index3].ToArray();
                                        }
                                    }
                                    matrix.SetStaticBlock(x, y, huedTileArray);
                                }
                            }
                        }
                        return(num1);
                    }
                }
            }
        }
Ejemplo n.º 29
0
        private unsafe HuedTile[][][] ReadStaticBlock(int x, int y)
        {
            if (!StaticIndexInit)
            {
                InitStatics();
            }

            if (_statics?.CanRead != true || !_statics.CanSeek)
            {
                _statics = _staticsPath == null
                    ? null
                    : new FileStream(_staticsPath, FileMode.Open, FileAccess.Read, FileShare.Read);
            }

            if (_statics == null)
            {
                return(EmptyStaticBlock);
            }

            int lookup = _staticIndex[(x * BlockHeight) + y].Lookup;
            int length = _staticIndex[(x * BlockHeight) + y].Length;

            if (lookup < 0 || length <= 0)
            {
                return(EmptyStaticBlock);
            }

            int count = length / 7;

            _statics.Seek(lookup, SeekOrigin.Begin);

            if (_buffer == null || _buffer.Length < length)
            {
                _buffer = new byte[length];
            }

            GCHandle gc = GCHandle.Alloc(_buffer, GCHandleType.Pinned);

            try
            {
                _statics.Read(_buffer, 0, length);

                if (_lists == null)
                {
                    _lists = new HuedTileList[8][];

                    for (int i = 0; i < 8; ++i)
                    {
                        _lists[i] = new HuedTileList[8];

                        for (int j = 0; j < 8; ++j)
                        {
                            _lists[i][j] = new HuedTileList();
                        }
                    }
                }

                HuedTileList[][] lists = _lists;

                for (int i = 0; i < count; ++i)
                {
                    var ptr = new IntPtr((long)gc.AddrOfPinnedObject() + (i * sizeof(StaticTile)));
                    var cur = (StaticTile)Marshal.PtrToStructure(ptr, typeof(StaticTile));
                    lists[cur.X & 0x7][cur.Y & 0x7].Add(Art.GetLegalItemID(cur.Id), cur.Hue, cur.Z);
                }

                var tiles = new HuedTile[8][][];

                for (int i = 0; i < 8; ++i)
                {
                    tiles[i] = new HuedTile[8][];

                    for (int j = 0; j < 8; ++j)
                    {
                        tiles[i][j] = lists[i][j].ToArray();
                    }
                }

                return(tiles);
            }
            finally
            {
                gc.Free();
            }
        }
Ejemplo n.º 30
0
        public void SetStaticBlock( int x, int y, HuedTile[][][] value )
        {
            if ( x < 0 || y < 0 || x >= m_BlockWidth || y >= m_BlockHeight )
                return;

            if ( m_StaticTiles[x] == null )
                m_StaticTiles[x] = new HuedTile[m_BlockHeight][][][];

            m_StaticTiles[x][y] = value;
        }
Ejemplo n.º 31
0
		public TileMatrix(int fileIndex, int mapID, int width, int height, string path)
		{
			Width = width;
			Height = height;
			BlockWidth = width >> 3;
			BlockHeight = height >> 3;

			if (path == null)
			{
				mapPath = Files.GetFilePath("map{0}.mul", fileIndex);

				if (String.IsNullOrEmpty(mapPath) || !File.Exists(mapPath))
				{
					mapPath = Files.GetFilePath("map{0}LegacyMUL.uop", fileIndex);
				}

				if (mapPath != null && mapPath.EndsWith(".uop"))
				{
					IsUOPFormat = true;
				}
			}
			else
			{
				mapPath = Path.Combine(path, String.Format("map{0}.mul", fileIndex));

				if (!File.Exists(mapPath))
				{
					mapPath = Path.Combine(path, String.Format("map{0}LegacyMUL.uop", fileIndex));
				}

				if (!File.Exists(mapPath))
				{
					mapPath = null;
				}
				else if (mapPath != null && mapPath.EndsWith(".uop"))
				{
					IsUOPFormat = true;
				}
			}

			if (path == null)
			{
				indexPath = Files.GetFilePath("staidx{0}.mul", fileIndex);
			}
			else
			{
				indexPath = Path.Combine(path, String.Format("staidx{0}.mul", fileIndex));
				if (!File.Exists(indexPath))
				{
					indexPath = null;
				}
			}

			if (path == null)
			{
				staticsPath = Files.GetFilePath("statics{0}.mul", fileIndex);
			}
			else
			{
				staticsPath = Path.Combine(path, String.Format("statics{0}.mul", fileIndex));
				if (!File.Exists(staticsPath))
				{
					staticsPath = null;
				}
			}

			EmptyStaticBlock = new HuedTile[8][][];

			for (int i = 0; i < 8; ++i)
			{
				EmptyStaticBlock[i] = new HuedTile[8][];

				for (int j = 0; j < 8; ++j)
				{
					EmptyStaticBlock[i][j] = new HuedTile[0];
				}
			}

			InvalidLandBlock = new Tile[196];

			m_LandTiles = new Tile[BlockWidth][][];
			m_StaticTiles = new HuedTile[BlockWidth][][][][];

			Patch = new TileMatrixPatch(this, mapID, path);
		}
Ejemplo n.º 32
0
        /// <summary>
        /// Generate in memmory new Facet from map & statics mul files		
        /// </summary>
        /// <param name="map">source map for generating facet</param>
        /// <param name="algorithm">type of algorithm which will be used for converting map to facet</param>
        public unsafe Facet(Map map, FacetGenAlgorithm algorithm)
        {
            if (map == null)
                throw new ArgumentNullException();

            m_Width = map.Width;
            m_Height = map.Height;
            m_FileIndex = map.FileIndex;
            m_FileName = Files.GetFilePath(String.Format("facet{0:D2}.mul", FileIndex));

            #region FacetGenAlgorithm.UltimaMap
            if (algorithm == FacetGenAlgorithm.UltimaMap)
            {
                Bitmap bmp = map.GetImage(0, 0, Width, Height, true);
                m_Bitmap = bmp.Clone(new Rectangle(0, 0, Width, Height), PixelFormat.Format16bppRgb555);
                bmp.Dispose();
                return;
            }
            #endregion FacetGenAlgorithm.UltimaMap

            m_Bitmap = new Bitmap(Width, Height, PixelFormat.Format16bppRgb555);
            BitmapData data = m_Bitmap.LockBits(new Rectangle(0, 0, Width, Height), ImageLockMode.WriteOnly, PixelFormat.Format16bppRgb555);
            ushort* cur = (ushort*)data.Scan0;
            int stride = data.Stride >> 1;

            switch (algorithm)
            {
                #region FacetGenAlgorithm.Simple
                case FacetGenAlgorithm.Simple:
                    {
                        TileMatrix matrix = new TileMatrix(FileIndex, FileIndex, Width, Height, null);
                        int blocklength = Width >> 3;
                        Tile[][] land = new Tile[blocklength][];
                        HuedTile[][][][] item = new HuedTile[blocklength][][][];
                        HuedTileComparer comparator = new HuedTileComparer();

                        for (int h = 0; h < (Height >> 3); ++h)
                        {
                            for (int b = 0; b < blocklength; ++b)
                            {
                                land[b] = matrix.GetLandBlock(b, h);
                                item[b] = matrix.GetStaticBlock(b, h);
                            }

                            for (int y = 0; y < 8; ++y)
                            {
                                int i = -1;
                                for (int b = 0; b < blocklength; ++b)
                                {
                                    for (int x = 0; x < 8; ++x)
                                    {
                                        Tile landtile = land[b][(y << 3) + x];
                                        HuedTile[] itemtile = item[b][x][y];
                                        if (itemtile == null || itemtile.Length == 0)
                                        {
                                            if (Array.BinarySearch(nodrawland, landtile.ID) < 0)
                                                cur[++i] = (ushort)RadarCol.Colors[landtile.ID];
                                            else
                                                cur[++i] = 0x0000;
                                            continue;
                                        }

                                        Array.Sort(itemtile, comparator);

                                        cur[++i] = itemtile[0].Z < landtile.Z
                                                 ? (ushort)RadarCol.Colors[landtile.ID]
                                                 : (ushort)RadarCol.Colors[0x4000 + itemtile[0].ID];

                                        if (cur[i] == 0x0421 || cur[i] == 0x0000)
                                            if (Array.BinarySearch(nodrawland, landtile.ID) < 0)
                                                cur[++i] = (ushort)RadarCol.Colors[landtile.ID];
                                            else
                                                cur[++i] = 0x0000;
                                    }
                                }
                                cur += stride;
                            }
                        }
                        break;
                    }
                #endregion FacetGenAlgorithm.Simple

                #region FacetGenAlgorithm.AltMask
                case FacetGenAlgorithm.AltMask:
                    {
                        TileMatrix matrix = new TileMatrix(FileIndex, FileIndex, Width, Height, null);
                        int blocklength = Width >> 3;
                        Tile[][] land = new Tile[blocklength][];
                        HuedTile[][][][] item = new HuedTile[blocklength][][][];
                        HuedTileComparer comparator = new HuedTileComparer();

                        for (int h = 0; h < (Height >> 3); ++h)
                        {
                            for (int b = 0; b < blocklength; ++b)
                            {
                                land[b] = matrix.GetLandBlock(b, h);
                                item[b] = matrix.GetStaticBlock(b, h);
                            }

                            matrix.Dispose();

                            for (int y = 0; y < 8; ++y)
                            {
                                int i = -1;
                                for (int b = 0; b < blocklength; ++b)
                                {
                                    for (int x = 0; x < 8; ++x)
                                    {
                                        Tile landtile = land[b][(y << 3) + x];
                                        HuedTile[] itemtile = item[b][x][y];
                                        bool drawland = false;

                                        if (itemtile == null || itemtile.Length == 0)
                                        {
                                            if (Array.BinarySearch(nodrawland, landtile.ID) >= 0)
                                                cur[++i] = 0x0000;
                                            else
                                            {
                                                cur[++i] = (ushort)RadarCol.Colors[landtile.ID];
                                                drawland = true;
                                            }
                                        }
                                        else
                                        {
                                            Array.Sort(itemtile, comparator);

                                            ushort landcolor = (ushort)RadarCol.Colors[landtile.ID];
                                            ushort itemcolor = 0x0000;
                                            int iu = 0;
                                            for (int u = 0; u < itemtile.Length; ++u)
                                            {
                                                iu = u;
                                                if (Array.BinarySearch(nodrawitem, itemtile[u].ID) >= 0)
                                                    continue;
                                                itemcolor = (ushort)RadarCol.Colors[0x4000 + itemtile[u].ID];
                                                if (itemcolor == 0x0000 || itemcolor == 0x0421)
                                                    if ((u + 1 < itemtile.Length) && (itemtile[u].Z >= landtile.Z))
                                                        continue;
                                                    else
                                                    {
                                                        itemcolor = 0x0000;
                                                        break;
                                                    }
                                                break;
                                            }

                                            if (itemcolor == 0x0000 || itemtile[iu].Z < landtile.Z)
                                            {
                                                if (Array.BinarySearch(nodrawland, landtile.ID) >= 0)
                                                    cur[++i] = 0x0000;
                                                else
                                                {
                                                    cur[++i] = landcolor;
                                                    drawland = true;
                                                }
                                            }
                                            else
                                                cur[++i] = itemcolor;
                                        }

                                        if (drawland && ((TileData.LandTable[landtile.ID].Flags & TileFlag.Wet) == 0))
                                        {
                                            short inc = (short)(0 - (landtile.Z / 20));

                                            short maskR = (short)(((cur[i] & 0x7C00) >> 10) + inc);
                                            maskR = Math.Min(Math.Max((short)0x00, maskR), (short)0x1F);
                                            short maskG = (short)(((cur[i] & 0x03E0) >> 5) + inc);
                                            maskG = Math.Min(Math.Max((short)0x00, maskG), (short)0x1F);
                                            short maskB = (short)(((cur[i] & 0x001F) >> 0) + inc);
                                            maskB = Math.Min(Math.Max((short)0x00, maskB), (short)0x1F);

                                            cur[i] = (ushort)((maskR << 10) | (maskG << 5) | (maskB << 0));
                                        }
                                        else
                                        {
                                            ushort maskR = (ushort)((cur[i] & 0x7C00) >> 10);
                                            if (maskR > 0)
                                                --maskR;
                                            ushort maskG = (ushort)((cur[i] & 0x03E0) >> 5);
                                            if (maskG > 0)
                                                --maskG;
                                            ushort maskB = (ushort)((cur[i] & 0x001F) >> 0);
                                            if (maskB > 0)
                                                --maskB;
                                            cur[i] = (ushort)((maskR << 10) | (maskG << 5) | (maskB << 0));
                                        }
                                    }
                                }
                                cur += stride;
                            }
                        }
                        break;
                    }
                #endregion FacetGenAlgorithm.AltMask

                #region FacetGenAlgorithm.AltMaskNoise
                case FacetGenAlgorithm.AltMaskNoise:
                    {
                        Random random = new Random();
                        TileMatrix matrix = new TileMatrix(FileIndex, FileIndex, Width, Height, null);
                        int blocklength = Width >> 3;
                        Tile[][] land = new Tile[blocklength][];
                        HuedTile[][][][] item = new HuedTile[blocklength][][][];
                        HuedTileComparer comparator = new HuedTileComparer();

                        for (int h = 0; h < (Height >> 3); ++h)
                        {
                            for (int b = 0; b < blocklength; ++b)
                            {
                                land[b] = matrix.ReadLandBlock(b, h);
                                item[b] = matrix.ReadStaticBlock(b, h);
                            }

                            for (int y = 0; y < 8; ++y)
                            {
                                int i = -1;
                                for (int b = 0; b < blocklength; ++b)
                                {
                                    for (int x = 0; x < 8; ++x)
                                    {
                                        Tile landtile = land[b][(y << 3) + x];
                                        HuedTile[] itemtile = item[b][x][y];
                                        bool drawland = false;

                                        if (itemtile == null || itemtile.Length == 0)
                                        {
                                            if (Array.BinarySearch(nodrawland, landtile.ID) >= 0)
                                                cur[++i] = 0x0000;
                                            else
                                            {
                                                cur[++i] = (ushort)RadarCol.Colors[landtile.ID];
                                                drawland = true;
                                            }
                                        }
                                        else
                                        {
                                            Array.Sort(itemtile, comparator);

                                            ushort landcolor = (ushort)RadarCol.Colors[landtile.ID];
                                            ushort itemcolor = 0x0000;
                                            int iu = 0;
                                            for (int u = 0; u < itemtile.Length; ++u)
                                            {
                                                iu = u;
                                                if (Array.BinarySearch(nodrawitem, itemtile[u].ID) >= 0)
                                                    continue;
                                                itemcolor = (ushort)RadarCol.Colors[0x4000 + itemtile[u].ID];
                                                if (itemcolor == 0x0000 || itemcolor == 0x0421 )
                                                    if ((u + 1 < itemtile.Length) && (itemtile[u].Z >= landtile.Z))
                                                        continue;
                                                    else
                                                    {
                                                        itemcolor = 0x0000;
                                                        break;
                                                    }
                                                break;
                                            }

                                            if (itemcolor == 0x0000 || itemtile[iu].Z < landtile.Z)
                                            {
                                                if (Array.BinarySearch(nodrawland, landtile.ID) >= 0)
                                                    cur[++i] = 0x0000;
                                                else
                                                {
                                                    cur[++i] = landcolor;
                                                    drawland = true;
                                                }
                                            }
                                            else
                                                cur[++i] = itemcolor;
                                        }

                                        if (drawland && ((TileData.LandTable[landtile.ID].Flags & TileFlag.Wet) == 0))
                                        {
                                            short inc = (short)(0 - (landtile.Z / 25));

                                            short maskR = (short)(((cur[i] & 0x7C00) >> 10) + inc);
                                            short maskG = (short)(((cur[i] & 0x03E0) >> 5) + inc);
                                            short maskB = (short)(((cur[i] & 0x001F) >> 0) + inc);

                                            inc = (short)(random.Next(-1, 2));
                                            maskR += inc;
                                            inc = (short)(random.Next(-1, 2));
                                            maskG += inc;
                                            inc = (short)(random.Next(-1, 2));
                                            maskB += inc;

                                            maskR = Math.Min(Math.Max((short)0x00, maskR), (short)0x1F);
                                            maskG = Math.Min(Math.Max((short)0x00, maskG), (short)0x1F);
                                            maskB = Math.Min(Math.Max((short)0x00, maskB), (short)0x1F);

                                            cur[i] = (ushort)((maskR << 10) | (maskG << 5) | (maskB << 0));
                                        }
                                        else
                                        {
                                            ushort maskR = (ushort)((cur[i] & 0x7C00) >> 10);
                                            if (maskR > 0)
                                                --maskR;
                                            ushort maskG = (ushort)((cur[i] & 0x03E0) >> 5);
                                            if (maskG > 0)
                                                --maskG;
                                            ushort maskB = (ushort)((cur[i] & 0x001F) >> 0);
                                            if (maskB > 0)
                                                --maskB;
                                            cur[i] = (ushort)((maskR << 10) | (maskG << 5) | (maskB << 0));
                                        }
                                    }
                                }
                                cur += stride;
                            }

                        }
                        break;
                    }
                #endregion FacetGenAlgorithm.AltMaskNoise

                #region FacetGenAlgorithm.Improved
                case FacetGenAlgorithm.Improved:
                    {
                        Random random = new Random();
                        TileMatrix matrix = new TileMatrix(FileIndex, FileIndex, Width, Height, null);
                        int blocklength = Width >> 3;
                        Tile[][] land = new Tile[blocklength][];
                        HuedTile[][][][] item = new HuedTile[blocklength][][][];
                        HuedTileComparer comparator = new HuedTileComparer();

                        for (int h = 0; h < (Height >> 3); ++h)
                        {
                            for (int b = 0; b < blocklength; ++b)
                            {
                                land[b] = matrix.GetLandBlock(b, h);
                                item[b] = matrix.GetStaticBlock(b, h);
                            }

                            for (int y = 0; y < 8; ++y)
                            {
                                int i = -1;
                                for (int b = 0; b < blocklength; ++b)
                                {
                                    for (int x = 0; x < 8; ++x)
                                    {
                                        Tile landtile = land[b][(y << 3) + x];
                                        HuedTile[] itemtile = item[b][x][y];
                                        bool drawland = false;

                                        if (itemtile == null || itemtile.Length == 0)
                                        {
                                            cur[++i] = (ushort)RadarCol.Colors[landtile.ID];
                                            drawland = true;
                                        }
                                        else
                                        {
                                            Array.Sort(itemtile, comparator);

                                            ushort landcolor = (ushort)RadarCol.Colors[landtile.ID];
                                            ushort itemcolor = 0x0000;
                                            int iu = 0;
                                            for (int u = 0; u < itemtile.Length; ++u)
                                            {
                                                iu = u;
                                                itemcolor = (ushort)RadarCol.Colors[0x4000 + itemtile[u].ID];
                                                if (itemcolor == 0x0000 || itemcolor == 0x0421)
                                                    if ((u + 1 < itemtile.Length) && (itemtile[u].Z >= landtile.Z))
                                                        continue;
                                                    else
                                                    {
                                                        itemcolor = 0x0000;
                                                        break;
                                                    }
                                                break;
                                            }

                                            if (itemcolor == 0x0000 || itemtile[iu].Z < landtile.Z)
                                            {
                                                cur[++i] = landcolor;
                                                drawland = true;
                                            }
                                            else
                                                cur[++i] = itemcolor;
                                        }

                                        if (drawland)
                                        {
                                            short inc = (short)(0 - (landtile.Z / 20));
                                            //
                                            inc *= 3;
                                            if (inc == 0)
                                                switch (random.Next(0, 2))
                                                {
                                                    case 0: inc = -1; break;
                                                    case 1: inc = 1; break;
                                                }
                                            short dir = (short)((inc >= 0) ? 1 : -1);

                                            short maskR = (short)((cur[i] & 0x7C00) >> 10);
                                            short maskG = (short)((cur[i] & 0x03E0) >> 5);
                                            short maskB = (short)((cur[i] & 0x001F) >> 0);

                                            for (short rand = 0; rand < dir * inc; ++rand)
                                                switch (random.Next(0, 3))
                                                {
                                                    case 0: maskR += dir; break;
                                                    case 1: maskG += dir; break;
                                                    case 2: maskB += dir; break;
                                                }

                                            maskR = Math.Min(Math.Max((short)0x00, maskR), (short)0x1F);
                                            maskG = Math.Min(Math.Max((short)0x00, maskG), (short)0x1F);
                                            maskB = Math.Min(Math.Max((short)0x00, maskB), (short)0x1F);
                                            /*
                                            short maskR = (short)(((cur[i] & 0x7C00) >> 10) + inc);
                                            maskR = Math.Min(Math.Max((short)0x00, maskR), (short)0x1F);
                                            short maskG = (short)(((cur[i] & 0x03E0) >> 5) + inc);
                                            maskG = Math.Min(Math.Max((short)0x00, maskG), (short)0x1F);
                                            short maskB = (short)(((cur[i] & 0x001F) >> 0) + inc);
                                            maskB = Math.Min(Math.Max((short)0x00, maskB), (short)0x1F);
                                            */
                                            cur[i] = (ushort)((maskR << 10) | (maskG << 5) | (maskB << 0));
                                        }
                                        else
                                        {
                                            ushort maskR = (ushort)((cur[i] & 0x7C00) >> 10);
                                            if (maskR > 0)
                                                --maskR;
                                            ushort maskG = (ushort)((cur[i] & 0x03E0) >> 5);
                                            if (maskG > 0)
                                                --maskG;
                                            ushort maskB = (ushort)((cur[i] & 0x001F) >> 0);
                                            if (maskB > 0)
                                                --maskB;
                                            cur[i] = (ushort)((maskR << 10) | (maskG << 5) | (maskB << 0));
                                        }
                                    }
                                }
                                cur += stride;
                            }
                        }
                        break;
                    }
                #endregion FacetGenAlgorithm.Improved
            }

            m_Bitmap.UnlockBits(data);
        }
Ejemplo n.º 33
0
        private unsafe int PatchStatics(TileMatrix matrix, string dataPath, string indexPath, string lookupPath)
        {
            using (FileStream fsData = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                using (FileStream fsIndex = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    using (FileStream fsLookup = new FileStream(lookupPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        BinaryReader indexReader  = new BinaryReader(fsIndex);
                        BinaryReader lookupReader = new BinaryReader(fsLookup);

                        int count = (int)(indexReader.BaseStream.Length / 4);

                        HuedTileList[][] lists = new HuedTileList[8][];

                        for (int x = 0; x < 8; ++x)
                        {
                            lists[x] = new HuedTileList[8];

                            for (int y = 0; y < 8; ++y)
                            {
                                lists[x][y] = new HuedTileList();
                            }
                        }

                        for (int i = 0; i < count; ++i)
                        {
                            int blockID = indexReader.ReadInt32();
                            int blockX  = blockID / matrix.BlockHeight;
                            int blockY  = blockID % matrix.BlockHeight;

                            int offset = lookupReader.ReadInt32();
                            int length = lookupReader.ReadInt32();
                            lookupReader.ReadInt32();                             // Extra

                            if (offset < 0 || length <= 0)
                            {
                                matrix.SetStaticBlock(blockX, blockY, matrix.EmptyStaticBlock);
                                continue;
                            }

                            fsData.Seek(offset, SeekOrigin.Begin);

                            int tileCount = length / 7;

                            StaticTile[] staTiles = new StaticTile[tileCount];

                            fixed(StaticTile *pTiles = staTiles)
                            {
                                _lread(fsData.Handle, pTiles, length);

                                StaticTile *pCur = pTiles, pEnd = pTiles + tileCount;

                                while (pCur < pEnd)
                                {
                                    lists[pCur->m_X & 0x7][pCur->m_Y & 0x7].Add((short)((pCur->m_ID & 0x3FFF) + 0x4000), pCur->m_Hue, pCur->m_Z);
                                    ++pCur;
                                }

                                HuedTile[][][] tiles = new HuedTile[8][][];

                                for (int x = 0; x < 8; ++x)
                                {
                                    tiles[x] = new HuedTile[8][];

                                    for (int y = 0; y < 8; ++y)
                                    {
                                        tiles[x][y] = lists[x][y].ToArray();
                                    }
                                }

                                matrix.SetStaticBlock(blockX, blockY, tiles);
                            }
                        }

                        return(count);
                    }
                }
            }
        }
Ejemplo n.º 34
0
        public TileMatrix(int fileIndex, int mapID, int width, int height, string path)
        {
            Width       = width;
            Height      = height;
            BlockWidth  = width >> 3;
            BlockHeight = height >> 3;


            if (path == null)
            {
                mapPath = Files.GetFilePath("map{0}.mul", fileIndex);

                if (String.IsNullOrEmpty(mapPath) || !File.Exists(mapPath))
                {
                    mapPath = Files.GetFilePath("map{0}LegacyMUL.uop", fileIndex);
                }

                if (mapPath != null && mapPath.EndsWith(".uop"))
                {
                    IsUOPFormat = true;
                }

                // For shards that use Fel and Tram before the split
                if (String.IsNullOrEmpty(mapPath) || (!File.Exists(mapPath) && fileIndex == 1))
                {
                    fileIndex = 0;
                    mapPath   = Files.GetFilePath("map{0}.mul", fileIndex);
                }
            }
            else
            {
                mapPath = Path.Combine(path, String.Format("map{0}.mul", fileIndex));

                if (!File.Exists(mapPath))
                {
                    mapPath = Path.Combine(path, String.Format("map{0}LegacyMUL.uop", fileIndex));
                }

                if (!File.Exists(mapPath))
                {
                    mapPath = null;
                }
                else if (mapPath != null && mapPath.EndsWith(".uop"))
                {
                    IsUOPFormat = true;
                }
            }

            if (mapPath != null && fileIndex == 0)
            {
                FileInfo fi = new FileInfo(mapPath);
                if (fi.Length < 89915392)
                {
                    // Old map size.
                    Width = 6144;
                }
            }

            if (path == null)
            {
                indexPath = Files.GetFilePath("staidx{0}.mul", fileIndex);
            }
            else
            {
                indexPath = Path.Combine(path, String.Format("staidx{0}.mul", fileIndex));
                if (!File.Exists(indexPath))
                {
                    indexPath = null;
                }
            }

            if (path == null)
            {
                staticsPath = Files.GetFilePath("statics{0}.mul", fileIndex);
            }
            else
            {
                staticsPath = Path.Combine(path, String.Format("statics{0}.mul", fileIndex));
                if (!File.Exists(staticsPath))
                {
                    staticsPath = null;
                }
            }

            EmptyStaticBlock = new HuedTile[8][][];

            for (int i = 0; i < 8; ++i)
            {
                EmptyStaticBlock[i] = new HuedTile[8][];

                for (int j = 0; j < 8; ++j)
                {
                    EmptyStaticBlock[i][j] = new HuedTile[0];
                }
            }

            InvalidLandBlock = new Tile[196];

            m_LandTiles   = new Tile[BlockWidth][][];
            m_StaticTiles = new HuedTile[BlockWidth][][][][];

            Patch = new TileMatrixPatch(this, mapID, path);
        }
 private unsafe int PatchStatics(TileMatrix matrix, string dataPath, string indexPath, string lookupPath)
 {
     using (FileStream fileStream1 = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read))
       {
     using (FileStream fileStream2 = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.Read))
     {
       using (FileStream fileStream3 = new FileStream(lookupPath, FileMode.Open, FileAccess.Read, FileShare.Read))
       {
     BinaryReader binaryReader1 = new BinaryReader((Stream) fileStream2);
     BinaryReader binaryReader2 = new BinaryReader((Stream) fileStream3);
     int num1 = (int) (binaryReader1.BaseStream.Length / 4L);
     HuedTileList[][] huedTileListArray = new HuedTileList[8][];
     for (int index1 = 0; index1 < 8; ++index1)
     {
       huedTileListArray[index1] = new HuedTileList[8];
       for (int index2 = 0; index2 < 8; ++index2)
         huedTileListArray[index1][index2] = new HuedTileList();
     }
     for (int index1 = 0; index1 < num1; ++index1)
     {
       int num2 = binaryReader1.ReadInt32();
       int x = num2 / matrix.BlockHeight;
       int y = num2 % matrix.BlockHeight;
       int num3 = binaryReader2.ReadInt32();
       int wBytes = binaryReader2.ReadInt32();
       binaryReader2.ReadInt32();
       if (num3 < 0 || wBytes <= 0)
       {
         matrix.SetStaticBlock(x, y, matrix.EmptyStaticBlock);
       }
       else
       {
         fileStream1.Seek((long) num3, SeekOrigin.Begin);
         int length = wBytes / 7;
         StaticTile[] staticTileArray = new StaticTile[length];
         fixed (StaticTile* staticTilePtr1 = &staticTileArray[0])
         {
           TileMatrixPatch._lread(fileStream1.Handle, (void*) staticTilePtr1, wBytes);
           StaticTile* staticTilePtr2 = staticTilePtr1;
           for (StaticTile* staticTilePtr3 = staticTilePtr1 + length; staticTilePtr2 < staticTilePtr3; ++staticTilePtr2)
             huedTileListArray[(int) staticTilePtr2->m_X & 7][(int) staticTilePtr2->m_Y & 7].Add((short) (((int) staticTilePtr2->m_ID & 16383) + 16384), staticTilePtr2->m_Hue, staticTilePtr2->m_Z);
           HuedTile[][][] huedTileArray = new HuedTile[8][][];
           for (int index2 = 0; index2 < 8; ++index2)
           {
             huedTileArray[index2] = new HuedTile[8][];
             for (int index3 = 0; index3 < 8; ++index3)
               huedTileArray[index2][index3] = huedTileListArray[index2][index3].ToArray();
           }
           matrix.SetStaticBlock(x, y, huedTileArray);
         }
       }
     }
     return num1;
       }
     }
       }
 }
Ejemplo n.º 36
0
        private unsafe HuedTile[][][] ReadStaticBlock(int x, int y)
        {
            try
            {
                if (!StaticIndexInit)
                {
                    InitStatics();
                }
                if (m_Statics == null || !m_Statics.CanRead || !m_Statics.CanSeek)
                {
                    if (staticsPath == null)
                    {
                        m_Statics = null;
                    }
                    else
                    {
                        m_Statics = new FileStream(staticsPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                    }
                }

                if (m_Statics == null)
                {
                    return(EmptyStaticBlock);
                }

                int lookup = m_StaticIndex[(x * BlockHeight) + y].lookup;
                int length = m_StaticIndex[(x * BlockHeight) + y].length;

                if (lookup < 0 || length <= 0)
                {
                    return(EmptyStaticBlock);
                }
                else
                {
                    int count = length / 7;

                    m_Statics.Seek(lookup, SeekOrigin.Begin);

                    if (m_Buffer == null || m_Buffer.Length < length)
                    {
                        m_Buffer = new byte[length];
                    }

                    GCHandle gc = GCHandle.Alloc(m_Buffer, GCHandleType.Pinned);
                    try
                    {
                        m_Statics.Read(m_Buffer, 0, length);

                        if (m_Lists == null)
                        {
                            m_Lists = new HuedTileList[8][];

                            for (int i = 0; i < 8; ++i)
                            {
                                m_Lists[i] = new HuedTileList[8];

                                for (int j = 0; j < 8; ++j)
                                {
                                    m_Lists[i][j] = new HuedTileList();
                                }
                            }
                        }

                        HuedTileList[][] lists = m_Lists;

                        for (int i = 0; i < count; ++i)
                        {
                            IntPtr     ptr = new IntPtr((long)gc.AddrOfPinnedObject() + i * sizeof(StaticTile));
                            StaticTile cur = (StaticTile)Marshal.PtrToStructure(ptr, typeof(StaticTile));
                            lists[cur.m_X & 0x7][cur.m_Y & 0x7].Add(Art.GetLegalItemID(cur.m_ID), cur.m_Hue, cur.m_Z);
                        }

                        HuedTile[][][] tiles = new HuedTile[8][][];

                        for (int i = 0; i < 8; ++i)
                        {
                            tiles[i] = new HuedTile[8][];

                            for (int j = 0; j < 8; ++j)
                            {
                                tiles[i][j] = lists[i][j].ToArray();
                            }
                        }

                        return(tiles);
                    }
                    finally
                    {
                        gc.Free();
                    }
                }
            }
            finally
            {
                //if (m_Statics != null)
                //    m_Statics.Close();
            }
        }
Ejemplo n.º 37
0
        private unsafe HuedTile[][][] ReadStaticBlock( int x, int y )
        {
            m_IndexReader.BaseStream.Seek( ((x * m_BlockHeight) + y) * 12, SeekOrigin.Begin );

            int lookup = m_IndexReader.ReadInt32();
            int length = m_IndexReader.ReadInt32();

            if ( lookup < 0 || length <= 0 )
            {
                return m_EmptyStaticBlock;
            }
            else
            {
                int count = length / 7;

                m_Statics.Seek( lookup, SeekOrigin.Begin );

                StaticTile[] staTiles = new StaticTile[count];

                fixed ( StaticTile *pTiles = staTiles )
                {
                    _lread(m_Statics.Handle, pTiles, length);

                    if ( m_Lists == null )
                    {
                        m_Lists = new HuedTileList[8][];

                        for ( int i = 0; i < 8; ++i )
                        {
                            m_Lists[i] = new HuedTileList[8];

                            for ( int j = 0; j < 8; ++j )
                                m_Lists[i][j] = new HuedTileList();
                        }
                    }

                    HuedTileList[][] lists = m_Lists;

                    StaticTile *pCur = pTiles, pEnd = pTiles + count;

                    while ( pCur < pEnd )
                    {
                        lists[pCur->m_X & 0x7][pCur->m_Y & 0x7].Add( (short)((pCur->m_ID & 0x3FFF) + 0x4000), pCur->m_Hue, pCur->m_Z );
                        ++pCur;
                    }

                    HuedTile[][][] tiles = new HuedTile[8][][];

                    for ( int i = 0; i < 8; ++i )
                    {
                        tiles[i] = new HuedTile[8][];

                        for ( int j = 0; j < 8; ++j )
                            tiles[i][j] = lists[i][j].ToArray();
                    }

                    return tiles;
                }
            }
        }
Ejemplo n.º 38
0
        private unsafe int PatchStatics(TileMatrix matrix, string dataPath, string indexPath, string lookupPath)
        {
            using (FileStream fsData = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read),
                              fsIndex = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.Read),
                              fsLookup = new FileStream(lookupPath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                using (BinaryReader indexReader = new BinaryReader(fsIndex),
                                    lookupReader = new BinaryReader(fsLookup))
                {
                    int count = Math.Min((int)(indexReader.BaseStream.Length / 4),
                                        (int)(lookupReader.BaseStream.Length / 12));

                    HuedTileList[][] lists = new HuedTileList[8][];

                    for (int x = 0; x < 8; ++x)
                    {
                        lists[x] = new HuedTileList[8];

                        for (int y = 0; y < 8; ++y)
                            lists[x][y] = new HuedTileList();
                    }

                    for (int i = 0; i < count; ++i)
                    {
                        int blockID = indexReader.ReadInt32();
                        int blockX = blockID / matrix.BlockHeight;
                        int blockY = blockID % matrix.BlockHeight;

                        int offset = lookupReader.ReadInt32();
                        int length = lookupReader.ReadInt32();
                        lookupReader.ReadInt32(); // Extra

                        if (offset < 0 || length <= 0)
                        {
                            if (StaticBlocks[blockX] == null)
                                StaticBlocks[blockX] = new HuedTile[matrix.BlockHeight][][][];

                            StaticBlocks[blockX][blockY] = TileMatrix.EmptyStaticBlock;
                            continue;
                        }

                        fsData.Seek(offset, SeekOrigin.Begin);

                        int tileCount = length / 7;

                        if (m_TileBuffer.Length < tileCount)
                            m_TileBuffer = new StaticTile[tileCount];

                        StaticTile[] staTiles = m_TileBuffer;

                        GCHandle gc = GCHandle.Alloc(staTiles, GCHandleType.Pinned);
                        try
                        {
                            if (m_Buffer == null || m_Buffer.Length < length)
                                m_Buffer = new byte[length];

                            fsData.Read(m_Buffer, 0, length);

                            Marshal.Copy(m_Buffer, 0, gc.AddrOfPinnedObject(), length);

                            for (int j = 0; j < tileCount; ++j)
                            {
                                StaticTile cur = staTiles[j];
                                lists[cur.m_X & 0x7][cur.m_Y & 0x7].Add(Art.GetLegalItemID(cur.m_ID), cur.m_Hue, cur.m_Z);
                            }

                            HuedTile[][][] tiles = new HuedTile[8][][];

                            for (int x = 0; x < 8; ++x)
                            {
                                tiles[x] = new HuedTile[8][];

                                for (int y = 0; y < 8; ++y)
                                    tiles[x][y] = lists[x][y].ToArray();
                            }

                            if (StaticBlocks[blockX] == null)
                                StaticBlocks[blockX] = new HuedTile[matrix.BlockHeight][][][];

                            StaticBlocks[blockX][blockY] = tiles;
                        }
                        finally
                        {
                            gc.Free();
                        }
                    }

                    return count;
                }
            }
        }
Ejemplo n.º 39
0
        private unsafe int PatchStatics( TileMatrix matrix, string dataPath, string indexPath, string lookupPath )
        {
            using ( FileStream fsData = new FileStream( dataPath, FileMode.Open, FileAccess.Read, FileShare.Read ) )
            {
                using ( FileStream fsIndex = new FileStream( indexPath, FileMode.Open, FileAccess.Read, FileShare.Read ) )
                {
                    using ( FileStream fsLookup = new FileStream( lookupPath, FileMode.Open, FileAccess.Read, FileShare.Read ) )
                    {
                        BinaryReader indexReader = new BinaryReader( fsIndex );
                        BinaryReader lookupReader = new BinaryReader( fsLookup );

                        int count = (int)(indexReader.BaseStream.Length / 4);

                        HuedTileList[][] lists = new HuedTileList[8][];

                        for ( int x = 0; x < 8; ++x )
                        {
                            lists[x] = new HuedTileList[8];

                            for ( int y = 0; y < 8; ++y )
                                lists[x][y] = new HuedTileList();
                        }

                        for ( int i = 0; i < count; ++i )
                        {
                            int blockID = indexReader.ReadInt32();
                            int blockX = blockID / matrix.BlockHeight;
                            int blockY = blockID % matrix.BlockHeight;

                            int offset = lookupReader.ReadInt32();
                            int length = lookupReader.ReadInt32();
                            lookupReader.ReadInt32(); // Extra

                            if ( offset < 0 || length <= 0 )
                            {
                                matrix.SetStaticBlock( blockX, blockY, matrix.EmptyStaticBlock );
                                continue;
                            }

                            fsData.Seek( offset, SeekOrigin.Begin );

                            int tileCount = length / 7;

                            StaticTile[] staTiles = new StaticTile[tileCount];

                            fixed ( StaticTile *pTiles = staTiles )
                            {
                                _lread(fsData.SafeFileHandle, pTiles, length);

                                StaticTile *pCur = pTiles, pEnd = pTiles + tileCount;

                                while ( pCur < pEnd )
                                {
                                    lists[pCur->m_X & 0x7][pCur->m_Y & 0x7].Add( (short)((pCur->m_ID & 0x3FFF) + 0x4000), pCur->m_Hue, pCur->m_Z );
                                    ++pCur;
                                }

                                HuedTile[][][] tiles = new HuedTile[8][][];

                                for ( int x = 0; x < 8; ++x )
                                {
                                    tiles[x] = new HuedTile[8][];

                                    for ( int y = 0; y < 8; ++y )
                                        tiles[x][y] = lists[x][y].ToArray();
                                }

                                matrix.SetStaticBlock( blockX, blockY, tiles );
                            }
                        }

                        return count;
                    }
                }
            }
        }
Ejemplo n.º 40
0
		public HuedTile[][][] GetStaticBlock(int x, int y, bool patch)
		{
			if (x < 0 || y < 0 || x >= BlockWidth || y >= BlockHeight)
			{
				return EmptyStaticBlock;
			}

			if (m_StaticTiles[x] == null)
			{
				m_StaticTiles[x] = new HuedTile[BlockHeight][][][];
			}

			HuedTile[][][] tiles = m_StaticTiles[x][y];

			if (tiles == null)
			{
				tiles = m_StaticTiles[x][y] = ReadStaticBlock(x, y);
			}

			if ((Map.UseDiff) && (patch))
			{
				if (Patch.StaticBlocksCount > 0)
				{
					if (Patch.StaticBlocks[x] != null)
					{
						if (Patch.StaticBlocks[x][y] != null)
						{
							tiles = Patch.StaticBlocks[x][y];
						}
					}
				}
			}
			return tiles;
		}
Ejemplo n.º 41
0
        /// <summary>
        /// Generate in memmory new Facet from map & statics mul files
        /// </summary>
        /// <param name="map">source map for generating facet</param>
        /// <param name="algorithm">type of algorithm which will be used for converting map to facet</param>
        public unsafe Facet(Map map, FacetGenAlgorithm algorithm)
        {
            if (map == null)
            {
                throw new ArgumentNullException();
            }

            m_Width     = map.Width;
            m_Height    = map.Height;
            m_FileIndex = map.FileIndex;
            m_FileName  = Files.GetFilePath(String.Format("facet{0:D2}.mul", FileIndex));

            #region FacetGenAlgorithm.UltimaMap
            if (algorithm == FacetGenAlgorithm.UltimaMap)
            {
                Bitmap bmp = map.GetImage(0, 0, Width, Height, true);
                m_Bitmap = bmp.Clone(new Rectangle(0, 0, Width, Height), PixelFormat.Format16bppRgb555);
                bmp.Dispose();
                return;
            }
            #endregion FacetGenAlgorithm.UltimaMap

            m_Bitmap = new Bitmap(Width, Height, PixelFormat.Format16bppRgb555);
            BitmapData data   = m_Bitmap.LockBits(new Rectangle(0, 0, Width, Height), ImageLockMode.WriteOnly, PixelFormat.Format16bppRgb555);
            ushort *   cur    = (ushort *)data.Scan0;
            int        stride = data.Stride >> 1;

            switch (algorithm)
            {
                #region FacetGenAlgorithm.Simple
            case FacetGenAlgorithm.Simple:
            {
                TileMatrix       matrix      = new TileMatrix(FileIndex, FileIndex, Width, Height, null);
                int              blocklength = Width >> 3;
                Tile[][]         land        = new Tile[blocklength][];
                HuedTile[][][][] item        = new HuedTile[blocklength][][][];
                HuedTileComparer comparator  = new HuedTileComparer();

                for (int h = 0; h < (Height >> 3); ++h)
                {
                    for (int b = 0; b < blocklength; ++b)
                    {
                        land[b] = matrix.GetLandBlock(b, h);
                        item[b] = matrix.GetStaticBlock(b, h);
                    }

                    for (int y = 0; y < 8; ++y)
                    {
                        int i = -1;
                        for (int b = 0; b < blocklength; ++b)
                        {
                            for (int x = 0; x < 8; ++x)
                            {
                                Tile       landtile = land[b][(y << 3) + x];
                                HuedTile[] itemtile = item[b][x][y];
                                if (itemtile == null || itemtile.Length == 0)
                                {
                                    if (Array.BinarySearch(nodrawland, landtile.ID) < 0)
                                    {
                                        cur[++i] = (ushort)RadarCol.Colors[landtile.ID];
                                    }
                                    else
                                    {
                                        cur[++i] = 0x0000;
                                    }
                                    continue;
                                }

                                Array.Sort(itemtile, comparator);

                                cur[++i] = itemtile[0].Z < landtile.Z
                                                 ? (ushort)RadarCol.Colors[landtile.ID]
                                                 : (ushort)RadarCol.Colors[0x4000 + itemtile[0].ID];

                                if (cur[i] == 0x0421 || cur[i] == 0x0000)
                                {
                                    if (Array.BinarySearch(nodrawland, landtile.ID) < 0)
                                    {
                                        cur[++i] = (ushort)RadarCol.Colors[landtile.ID];
                                    }
                                    else
                                    {
                                        cur[++i] = 0x0000;
                                    }
                                }
                            }
                        }
                        cur += stride;
                    }
                }
                break;
            }
                #endregion FacetGenAlgorithm.Simple

                #region FacetGenAlgorithm.AltMask
            case FacetGenAlgorithm.AltMask:
            {
                TileMatrix       matrix      = new TileMatrix(FileIndex, FileIndex, Width, Height, null);
                int              blocklength = Width >> 3;
                Tile[][]         land        = new Tile[blocklength][];
                HuedTile[][][][] item        = new HuedTile[blocklength][][][];
                HuedTileComparer comparator  = new HuedTileComparer();

                for (int h = 0; h < (Height >> 3); ++h)
                {
                    for (int b = 0; b < blocklength; ++b)
                    {
                        land[b] = matrix.GetLandBlock(b, h);
                        item[b] = matrix.GetStaticBlock(b, h);
                    }

                    matrix.Dispose();

                    for (int y = 0; y < 8; ++y)
                    {
                        int i = -1;
                        for (int b = 0; b < blocklength; ++b)
                        {
                            for (int x = 0; x < 8; ++x)
                            {
                                Tile       landtile = land[b][(y << 3) + x];
                                HuedTile[] itemtile = item[b][x][y];
                                bool       drawland = false;

                                if (itemtile == null || itemtile.Length == 0)
                                {
                                    if (Array.BinarySearch(nodrawland, landtile.ID) >= 0)
                                    {
                                        cur[++i] = 0x0000;
                                    }
                                    else
                                    {
                                        cur[++i] = (ushort)RadarCol.Colors[landtile.ID];
                                        drawland = true;
                                    }
                                }
                                else
                                {
                                    Array.Sort(itemtile, comparator);

                                    ushort landcolor = (ushort)RadarCol.Colors[landtile.ID];
                                    ushort itemcolor = 0x0000;
                                    int    iu        = 0;
                                    for (int u = 0; u < itemtile.Length; ++u)
                                    {
                                        iu = u;
                                        if (Array.BinarySearch(nodrawitem, itemtile[u].ID) >= 0)
                                        {
                                            continue;
                                        }
                                        itemcolor = (ushort)RadarCol.Colors[0x4000 + itemtile[u].ID];
                                        if (itemcolor == 0x0000 || itemcolor == 0x0421)
                                        {
                                            if ((u + 1 < itemtile.Length) && (itemtile[u].Z >= landtile.Z))
                                            {
                                                continue;
                                            }
                                            else
                                            {
                                                itemcolor = 0x0000;
                                                break;
                                            }
                                        }
                                        break;
                                    }

                                    if (itemcolor == 0x0000 || itemtile[iu].Z < landtile.Z)
                                    {
                                        if (Array.BinarySearch(nodrawland, landtile.ID) >= 0)
                                        {
                                            cur[++i] = 0x0000;
                                        }
                                        else
                                        {
                                            cur[++i] = landcolor;
                                            drawland = true;
                                        }
                                    }
                                    else
                                    {
                                        cur[++i] = itemcolor;
                                    }
                                }

                                if (drawland && ((TileData.LandTable[landtile.ID].Flags & TileFlag.Wet) == 0))
                                {
                                    short inc = (short)(0 - (landtile.Z / 20));

                                    short maskR = (short)(((cur[i] & 0x7C00) >> 10) + inc);
                                    maskR = Math.Min(Math.Max((short)0x00, maskR), (short)0x1F);
                                    short maskG = (short)(((cur[i] & 0x03E0) >> 5) + inc);
                                    maskG = Math.Min(Math.Max((short)0x00, maskG), (short)0x1F);
                                    short maskB = (short)(((cur[i] & 0x001F) >> 0) + inc);
                                    maskB = Math.Min(Math.Max((short)0x00, maskB), (short)0x1F);

                                    cur[i] = (ushort)((maskR << 10) | (maskG << 5) | (maskB << 0));
                                }
                                else
                                {
                                    ushort maskR = (ushort)((cur[i] & 0x7C00) >> 10);
                                    if (maskR > 0)
                                    {
                                        --maskR;
                                    }
                                    ushort maskG = (ushort)((cur[i] & 0x03E0) >> 5);
                                    if (maskG > 0)
                                    {
                                        --maskG;
                                    }
                                    ushort maskB = (ushort)((cur[i] & 0x001F) >> 0);
                                    if (maskB > 0)
                                    {
                                        --maskB;
                                    }
                                    cur[i] = (ushort)((maskR << 10) | (maskG << 5) | (maskB << 0));
                                }
                            }
                        }
                        cur += stride;
                    }
                }
                break;
            }
                #endregion FacetGenAlgorithm.AltMask

                #region FacetGenAlgorithm.AltMaskNoise
            case FacetGenAlgorithm.AltMaskNoise:
            {
                Random           random      = new Random();
                TileMatrix       matrix      = new TileMatrix(FileIndex, FileIndex, Width, Height, null);
                int              blocklength = Width >> 3;
                Tile[][]         land        = new Tile[blocklength][];
                HuedTile[][][][] item        = new HuedTile[blocklength][][][];
                HuedTileComparer comparator  = new HuedTileComparer();

                for (int h = 0; h < (Height >> 3); ++h)
                {
                    for (int b = 0; b < blocklength; ++b)
                    {
                        land[b] = matrix.ReadLandBlock(b, h);
                        item[b] = matrix.ReadStaticBlock(b, h);
                    }

                    for (int y = 0; y < 8; ++y)
                    {
                        int i = -1;
                        for (int b = 0; b < blocklength; ++b)
                        {
                            for (int x = 0; x < 8; ++x)
                            {
                                Tile       landtile = land[b][(y << 3) + x];
                                HuedTile[] itemtile = item[b][x][y];
                                bool       drawland = false;

                                if (itemtile == null || itemtile.Length == 0)
                                {
                                    if (Array.BinarySearch(nodrawland, landtile.ID) >= 0)
                                    {
                                        cur[++i] = 0x0000;
                                    }
                                    else
                                    {
                                        cur[++i] = (ushort)RadarCol.Colors[landtile.ID];
                                        drawland = true;
                                    }
                                }
                                else
                                {
                                    Array.Sort(itemtile, comparator);

                                    ushort landcolor = (ushort)RadarCol.Colors[landtile.ID];
                                    ushort itemcolor = 0x0000;
                                    int    iu        = 0;
                                    for (int u = 0; u < itemtile.Length; ++u)
                                    {
                                        iu = u;
                                        if (Array.BinarySearch(nodrawitem, itemtile[u].ID) >= 0)
                                        {
                                            continue;
                                        }
                                        itemcolor = (ushort)RadarCol.Colors[0x4000 + itemtile[u].ID];
                                        if (itemcolor == 0x0000 || itemcolor == 0x0421)
                                        {
                                            if ((u + 1 < itemtile.Length) && (itemtile[u].Z >= landtile.Z))
                                            {
                                                continue;
                                            }
                                            else
                                            {
                                                itemcolor = 0x0000;
                                                break;
                                            }
                                        }
                                        break;
                                    }

                                    if (itemcolor == 0x0000 || itemtile[iu].Z < landtile.Z)
                                    {
                                        if (Array.BinarySearch(nodrawland, landtile.ID) >= 0)
                                        {
                                            cur[++i] = 0x0000;
                                        }
                                        else
                                        {
                                            cur[++i] = landcolor;
                                            drawland = true;
                                        }
                                    }
                                    else
                                    {
                                        cur[++i] = itemcolor;
                                    }
                                }

                                if (drawland && ((TileData.LandTable[landtile.ID].Flags & TileFlag.Wet) == 0))
                                {
                                    short inc = (short)(0 - (landtile.Z / 25));

                                    short maskR = (short)(((cur[i] & 0x7C00) >> 10) + inc);
                                    short maskG = (short)(((cur[i] & 0x03E0) >> 5) + inc);
                                    short maskB = (short)(((cur[i] & 0x001F) >> 0) + inc);

                                    inc    = (short)(random.Next(-1, 2));
                                    maskR += inc;
                                    inc    = (short)(random.Next(-1, 2));
                                    maskG += inc;
                                    inc    = (short)(random.Next(-1, 2));
                                    maskB += inc;

                                    maskR = Math.Min(Math.Max((short)0x00, maskR), (short)0x1F);
                                    maskG = Math.Min(Math.Max((short)0x00, maskG), (short)0x1F);
                                    maskB = Math.Min(Math.Max((short)0x00, maskB), (short)0x1F);

                                    cur[i] = (ushort)((maskR << 10) | (maskG << 5) | (maskB << 0));
                                }
                                else
                                {
                                    ushort maskR = (ushort)((cur[i] & 0x7C00) >> 10);
                                    if (maskR > 0)
                                    {
                                        --maskR;
                                    }
                                    ushort maskG = (ushort)((cur[i] & 0x03E0) >> 5);
                                    if (maskG > 0)
                                    {
                                        --maskG;
                                    }
                                    ushort maskB = (ushort)((cur[i] & 0x001F) >> 0);
                                    if (maskB > 0)
                                    {
                                        --maskB;
                                    }
                                    cur[i] = (ushort)((maskR << 10) | (maskG << 5) | (maskB << 0));
                                }
                            }
                        }
                        cur += stride;
                    }
                }
                break;
            }
                #endregion FacetGenAlgorithm.AltMaskNoise

                #region FacetGenAlgorithm.Improved
            case FacetGenAlgorithm.Improved:
            {
                Random           random      = new Random();
                TileMatrix       matrix      = new TileMatrix(FileIndex, FileIndex, Width, Height, null);
                int              blocklength = Width >> 3;
                Tile[][]         land        = new Tile[blocklength][];
                HuedTile[][][][] item        = new HuedTile[blocklength][][][];
                HuedTileComparer comparator  = new HuedTileComparer();

                for (int h = 0; h < (Height >> 3); ++h)
                {
                    for (int b = 0; b < blocklength; ++b)
                    {
                        land[b] = matrix.GetLandBlock(b, h);
                        item[b] = matrix.GetStaticBlock(b, h);
                    }

                    for (int y = 0; y < 8; ++y)
                    {
                        int i = -1;
                        for (int b = 0; b < blocklength; ++b)
                        {
                            for (int x = 0; x < 8; ++x)
                            {
                                Tile       landtile = land[b][(y << 3) + x];
                                HuedTile[] itemtile = item[b][x][y];
                                bool       drawland = false;

                                if (itemtile == null || itemtile.Length == 0)
                                {
                                    cur[++i] = (ushort)RadarCol.Colors[landtile.ID];
                                    drawland = true;
                                }
                                else
                                {
                                    Array.Sort(itemtile, comparator);

                                    ushort landcolor = (ushort)RadarCol.Colors[landtile.ID];
                                    ushort itemcolor = 0x0000;
                                    int    iu        = 0;
                                    for (int u = 0; u < itemtile.Length; ++u)
                                    {
                                        iu        = u;
                                        itemcolor = (ushort)RadarCol.Colors[0x4000 + itemtile[u].ID];
                                        if (itemcolor == 0x0000 || itemcolor == 0x0421)
                                        {
                                            if ((u + 1 < itemtile.Length) && (itemtile[u].Z >= landtile.Z))
                                            {
                                                continue;
                                            }
                                            else
                                            {
                                                itemcolor = 0x0000;
                                                break;
                                            }
                                        }
                                        break;
                                    }

                                    if (itemcolor == 0x0000 || itemtile[iu].Z < landtile.Z)
                                    {
                                        cur[++i] = landcolor;
                                        drawland = true;
                                    }
                                    else
                                    {
                                        cur[++i] = itemcolor;
                                    }
                                }

                                if (drawland)
                                {
                                    short inc = (short)(0 - (landtile.Z / 20));
                                    //
                                    inc *= 3;
                                    if (inc == 0)
                                    {
                                        switch (random.Next(0, 2))
                                        {
                                        case 0: inc = -1; break;

                                        case 1: inc = 1; break;
                                        }
                                    }
                                    short dir = (short)((inc >= 0) ? 1 : -1);

                                    short maskR = (short)((cur[i] & 0x7C00) >> 10);
                                    short maskG = (short)((cur[i] & 0x03E0) >> 5);
                                    short maskB = (short)((cur[i] & 0x001F) >> 0);

                                    for (short rand = 0; rand < dir * inc; ++rand)
                                    {
                                        switch (random.Next(0, 3))
                                        {
                                        case 0: maskR += dir; break;

                                        case 1: maskG += dir; break;

                                        case 2: maskB += dir; break;
                                        }
                                    }

                                    maskR = Math.Min(Math.Max((short)0x00, maskR), (short)0x1F);
                                    maskG = Math.Min(Math.Max((short)0x00, maskG), (short)0x1F);
                                    maskB = Math.Min(Math.Max((short)0x00, maskB), (short)0x1F);

                                    /*
                                     * short maskR = (short)(((cur[i] & 0x7C00) >> 10) + inc);
                                     * maskR = Math.Min(Math.Max((short)0x00, maskR), (short)0x1F);
                                     * short maskG = (short)(((cur[i] & 0x03E0) >> 5) + inc);
                                     * maskG = Math.Min(Math.Max((short)0x00, maskG), (short)0x1F);
                                     * short maskB = (short)(((cur[i] & 0x001F) >> 0) + inc);
                                     * maskB = Math.Min(Math.Max((short)0x00, maskB), (short)0x1F);
                                     */
                                    cur[i] = (ushort)((maskR << 10) | (maskG << 5) | (maskB << 0));
                                }
                                else
                                {
                                    ushort maskR = (ushort)((cur[i] & 0x7C00) >> 10);
                                    if (maskR > 0)
                                    {
                                        --maskR;
                                    }
                                    ushort maskG = (ushort)((cur[i] & 0x03E0) >> 5);
                                    if (maskG > 0)
                                    {
                                        --maskG;
                                    }
                                    ushort maskB = (ushort)((cur[i] & 0x001F) >> 0);
                                    if (maskB > 0)
                                    {
                                        --maskB;
                                    }
                                    cur[i] = (ushort)((maskR << 10) | (maskG << 5) | (maskB << 0));
                                }
                            }
                        }
                        cur += stride;
                    }
                }
                break;
            }
                #endregion FacetGenAlgorithm.Improved
            }

            m_Bitmap.UnlockBits(data);
        }
Ejemplo n.º 42
0
        private unsafe HuedTile[][][] ReadStaticBlock(int x, int y)
        {
            m_IndexReader.BaseStream.Seek(((x * m_BlockHeight) + y) * 12, SeekOrigin.Begin);

            int lookup = m_IndexReader.ReadInt32();
            int length = m_IndexReader.ReadInt32();

            if (lookup < 0 || length <= 0)
            {
                return(m_EmptyStaticBlock);
            }
            else
            {
                int count = length / 7;

                m_Statics.Seek(lookup, SeekOrigin.Begin);

                StaticTile[] staTiles = new StaticTile[count];

                fixed(StaticTile *pTiles = staTiles)
                {
                    _lread(m_Statics.Handle, pTiles, length);

                    if (m_Lists == null)
                    {
                        m_Lists = new HuedTileList[8][];

                        for (int i = 0; i < 8; ++i)
                        {
                            m_Lists[i] = new HuedTileList[8];

                            for (int j = 0; j < 8; ++j)
                            {
                                m_Lists[i][j] = new HuedTileList();
                            }
                        }
                    }

                    HuedTileList[][] lists = m_Lists;

                    StaticTile *pCur = pTiles, pEnd = pTiles + count;

                    while (pCur < pEnd)
                    {
                        lists[pCur->m_X & 0x7][pCur->m_Y & 0x7].Add((short)((pCur->m_ID & 0x3FFF) + 0x4000), pCur->m_Hue, pCur->m_Z);
                        ++pCur;
                    }

                    HuedTile[][][] tiles = new HuedTile[8][][];

                    for (int i = 0; i < 8; ++i)
                    {
                        tiles[i] = new HuedTile[8][];

                        for (int j = 0; j < 8; ++j)
                        {
                            tiles[i][j] = lists[i][j].ToArray();
                        }
                    }

                    return(tiles);
                }
            }
        }
Ejemplo n.º 43
0
		private unsafe HuedTile[][][] ReadStaticBlock(int x, int y)
		{
			try
			{
				if (!StaticIndexInit)
				{
					InitStatics();
				}
				if (m_Statics == null || !m_Statics.CanRead || !m_Statics.CanSeek)
				{
					if (staticsPath == null)
					{
						m_Statics = null;
					}
					else
					{
						m_Statics = new FileStream(staticsPath, FileMode.Open, FileAccess.Read, FileShare.Read);
					}
				}
				if (m_Statics == null)
				{
					return EmptyStaticBlock;
				}

				int lookup = m_StaticIndex[(x * BlockHeight) + y].lookup;
				int length = m_StaticIndex[(x * BlockHeight) + y].length;

				if (lookup < 0 || length <= 0)
				{
					return EmptyStaticBlock;
				}
				else
				{
					int count = length / 7;

					m_Statics.Seek(lookup, SeekOrigin.Begin);

					if (m_Buffer == null || m_Buffer.Length < length)
					{
						m_Buffer = new byte[length];
					}

					GCHandle gc = GCHandle.Alloc(m_Buffer, GCHandleType.Pinned);
					try
					{
						m_Statics.Read(m_Buffer, 0, length);

						if (m_Lists == null)
						{
							m_Lists = new HuedTileList[8][];

							for (int i = 0; i < 8; ++i)
							{
								m_Lists[i] = new HuedTileList[8];

								for (int j = 0; j < 8; ++j)
								{
									m_Lists[i][j] = new HuedTileList();
								}
							}
						}

						HuedTileList[][] lists = m_Lists;

						for (int i = 0; i < count; ++i)
						{
							var ptr = new IntPtr((long)gc.AddrOfPinnedObject() + i * sizeof(StaticTile));
							var cur = (StaticTile)Marshal.PtrToStructure(ptr, typeof(StaticTile));
							lists[cur.m_X & 0x7][cur.m_Y & 0x7].Add(Art.GetLegalItemID(cur.m_ID), cur.m_Hue, cur.m_Z);
						}

						var tiles = new HuedTile[8][][];

						for (int i = 0; i < 8; ++i)
						{
							tiles[i] = new HuedTile[8][];

							for (int j = 0; j < 8; ++j)
							{
								tiles[i][j] = lists[i][j].ToArray();
							}
						}

						return tiles;
					}
					finally
					{
						gc.Free();
					}
				}
			}
			finally
			{
				//if (m_Statics != null)
				//    m_Statics.Close();
			}
		}
Ejemplo n.º 44
0
        private int PatchStatics(TileMatrix matrix, string dataPath, string indexPath, string lookupPath)
        {
            using (
                FileStream fsData = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read),
                fsIndex = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.Read),
                fsLookup = new FileStream(lookupPath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                using (BinaryReader indexReader = new BinaryReader(fsIndex), lookupReader = new BinaryReader(fsLookup))
                {
                    int count = Math.Min((int)(indexReader.BaseStream.Length / 4), (int)(lookupReader.BaseStream.Length / 12));

                    var lists = new HuedTileList[8][];

                    for (int x = 0; x < 8; ++x)
                    {
                        lists[x] = new HuedTileList[8];

                        for (int y = 0; y < 8; ++y)
                        {
                            lists[x][y] = new HuedTileList();
                        }
                    }

                    for (int i = 0; i < count; ++i)
                    {
                        int blockID = indexReader.ReadInt32();
                        int blockX  = blockID / matrix.BlockHeight;
                        int blockY  = blockID % matrix.BlockHeight;

                        int offset = lookupReader.ReadInt32();
                        int length = lookupReader.ReadInt32();
                        lookupReader.ReadInt32(); // Extra

                        if (offset < 0 || length <= 0)
                        {
                            if (StaticBlocks[blockX] == null)
                            {
                                StaticBlocks[blockX] = new HuedTile[matrix.BlockHeight][][][];
                            }

                            StaticBlocks[blockX][blockY] = TileMatrix.EmptyStaticBlock;
                            continue;
                        }

                        fsData.Seek(offset, SeekOrigin.Begin);

                        int tileCount = length / 7;

                        if (m_TileBuffer.Length < tileCount)
                        {
                            m_TileBuffer = new StaticTile[tileCount];
                        }

                        StaticTile[] staTiles = m_TileBuffer;

                        GCHandle gc = GCHandle.Alloc(staTiles, GCHandleType.Pinned);
                        try
                        {
                            if (m_Buffer == null || m_Buffer.Length < length)
                            {
                                m_Buffer = new byte[length];
                            }

                            fsData.Read(m_Buffer, 0, length);

                            Marshal.Copy(m_Buffer, 0, gc.AddrOfPinnedObject(), length);

                            for (int j = 0; j < tileCount; ++j)
                            {
                                StaticTile cur = staTiles[j];
                                lists[cur.m_X & 0x7][cur.m_Y & 0x7].Add(Art.GetLegalItemID(cur.m_ID), cur.m_Hue, cur.m_Z);
                            }

                            var tiles = new HuedTile[8][][];

                            for (int x = 0; x < 8; ++x)
                            {
                                tiles[x] = new HuedTile[8][];

                                for (int y = 0; y < 8; ++y)
                                {
                                    tiles[x][y] = lists[x][y].ToArray();
                                }
                            }

                            if (StaticBlocks[blockX] == null)
                            {
                                StaticBlocks[blockX] = new HuedTile[matrix.BlockHeight][][][];
                            }

                            StaticBlocks[blockX][blockY] = tiles;
                        }
                        finally
                        {
                            gc.Free();
                        }
                    }

                    return(count);
                }
            }
        }
Ejemplo n.º 45
0
		public void RemoveStaticBlock(int blockx, int blocky)
		{
			if (m_RemovedStaticBlock == null)
			{
				m_RemovedStaticBlock = new bool[BlockWidth][];
			}
			if (m_RemovedStaticBlock[blockx] == null)
			{
				m_RemovedStaticBlock[blockx] = new bool[BlockHeight];
			}
			m_RemovedStaticBlock[blockx][blocky] = true;
			if (m_StaticTiles[blockx] == null)
			{
				m_StaticTiles[blockx] = new HuedTile[BlockHeight][][][];
			}
			m_StaticTiles[blockx][blocky] = EmptyStaticBlock;
		}