Esempio n. 1
0
        private unsafe int PatchLand( TileMatrix matrix, string dataPath, string indexPath )
        {
            using ( FileStream fsData = new FileStream( dataPath, FileMode.Open, FileAccess.Read, FileShare.Read ) )
            {
                using ( FileStream fsIndex = new FileStream( indexPath, FileMode.Open, FileAccess.Read, FileShare.Read ) )
                {
                    BinaryReader indexReader = new BinaryReader( fsIndex );

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

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

                        fsData.Seek( 4, SeekOrigin.Current );

                        Tile[] tiles = new Tile[64];

                        fixed ( Tile *pTiles = tiles )
                        {
                            _lread(fsData.SafeFileHandle, pTiles, 192);
                        }

                        matrix.SetLandBlock( x, y, tiles );
                    }

                    return count;
                }
            }
        }
Esempio n. 2
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);
            }
        }
 public TileMatrixPatch(TileMatrix matrix, int index)
 {
     string filePath1 = Client.GetFilePath("mapdiff{0}.mul", (object) index);
       string filePath2 = Client.GetFilePath("mapdiffl{0}.mul", (object) index);
       if (filePath1 != null && filePath2 != null)
     this.m_LandBlocks = this.PatchLand(matrix, filePath1, filePath2);
       string filePath3 = Client.GetFilePath("stadiff{0}.mul", (object) index);
       string filePath4 = Client.GetFilePath("stadiffl{0}.mul", (object) index);
       string filePath5 = Client.GetFilePath("stadiffi{0}.mul", (object) index);
       if (filePath3 == null || filePath4 == null || filePath5 == null)
     return;
       this.m_StaticBlocks = this.PatchStatics(matrix, filePath3, filePath4, filePath5);
 }
Esempio n. 4
0
        public TileMatrixPatch( TileMatrix matrix, int index )
        {
            string mapDataPath = Client.GetFilePath( "mapdiff{0}.mul", index );
            string mapIndexPath = Client.GetFilePath( "mapdiffl{0}.mul", index );

            if ( mapDataPath != null && mapIndexPath != null )
                m_LandBlocks = PatchLand( matrix, mapDataPath, mapIndexPath );

            string staDataPath = Client.GetFilePath( "stadiff{0}.mul", index );
            string staIndexPath = Client.GetFilePath( "stadiffl{0}.mul", index );
            string staLookupPath = Client.GetFilePath( "stadiffi{0}.mul", index );

            if ( staDataPath != null && staIndexPath != null && staLookupPath != null )
                m_StaticBlocks = PatchStatics( matrix, staDataPath, staIndexPath, staLookupPath );
        }
 private unsafe int PatchLand(TileMatrix matrix, string dataPath, string indexPath)
 {
     using (FileStream fileStream1 = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read))
       {
     using (FileStream fileStream2 = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.Read))
     {
       BinaryReader binaryReader = new BinaryReader((Stream) fileStream2);
       int num1 = (int) (binaryReader.BaseStream.Length / 4L);
       for (int index = 0; index < num1; ++index)
       {
     int num2 = binaryReader.ReadInt32();
     int x = num2 / matrix.BlockHeight;
     int y = num2 % matrix.BlockHeight;
     fileStream1.Seek(4L, SeekOrigin.Current);
     Tile[] tileArray = new Tile[64];
     fixed (Tile* tilePtr = &tileArray[0])
       TileMatrixPatch._lread(fileStream1.Handle, (void*) tilePtr, 192);
     matrix.SetLandBlock(x, y, tileArray);
       }
       return num1;
     }
       }
 }
Esempio n. 6
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;
                }
            }
        }
Esempio n. 7
0
        private unsafe int PatchLand(TileMatrix matrix, string dataPath, string indexPath)
        {
            using (FileStream fsData = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read),
                              fsIndex = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                using (BinaryReader indexReader = new BinaryReader(fsIndex))
                {
                    int count = (int)(indexReader.BaseStream.Length / 4);

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

                        fsData.Seek(4, SeekOrigin.Current);

                        Tile[] tiles = new Tile[64];

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

                            fsData.Read(m_Buffer, 0, 192);

                            Marshal.Copy(m_Buffer, 0, gc.AddrOfPinnedObject(), 192);
                        }
                        finally
                        {
                            gc.Free();
                        }
                        if (LandBlocks[x] == null)
                            LandBlocks[x] = new Tile[matrix.BlockHeight][];
                        LandBlocks[x][y] = tiles;
                    }
                    return count;
                }
            }
        }
Esempio n. 8
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);
        }
Esempio n. 9
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;
                    }
                }
            }
        }
Esempio n. 10
0
        public void TargetGround(int X, int Y, int Z, int ID)
        {
            //ID should be 00
            // get ground type from x/y
            //if ((int)uonet.player.Facet <= 1) need a check to set right map size for tokuno/malas.
            // This will only work in britannia
                Ultima.TileMatrix tm = new TileMatrix(0, 0, 6144, 4096);
                HuedTile[] htile = tm.GetStaticTiles(X, Y);
                int mytileid2 = (htile[0].ID & 0x3FFF);

            uonet.Send(uonet.ClickTargetPacket(ID, X, Y, Z, mytileid2, CursorTarget.SelectXYZ));

            uonet.UOClient.TargCurs = 0;
        }
Esempio n. 11
0
        private void button3_Click(object sender, EventArgs e)
        {
            Ultima.Tile mytile = new Ultima.Tile();

            //mytile = tm.GetLandTile(2563, 489);
            int mytileid = (mytile.ID & 0x3FFF);
               // uonet.display(""+mytileid);

            Ultima.Tile mytile2 = new Ultima.Tile();
            Ultima.TileMatrix tm = new TileMatrix(0, 0, 6144, 4096);
            HuedTile[] htile = tm.GetStaticTiles(2563, 489);
            int mytileid2 = (htile[0].ID & 0x3FFF); // need a check, exception if ID is 0
            //uonet.display("" + htile[0].ID + "___" + htile[1].ID);

            //mytile2 =

            mytile = tm.GetLandTile(273, 1216);
            //txtOutput.Text = txtOutput.Text + StringList.Table[1076267];
            //txtOutput.Text = txtOutput.Text +
        }
 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;
       }
     }
       }
 }
Esempio n. 13
0
        private void button3_Click(object sender, EventArgs e)
        {
            string newPath = Application.ExecutablePath.Substring(0, Application.ExecutablePath.LastIndexOf('\\'));
            newPath += @"\Created\";

            if (!Directory.Exists(newPath))
                Directory.CreateDirectory(newPath);
            TileMatrix tm = new TileMatrix(0, 0, 6144, 4096);
            TransTable tt = new TransTable();
            for (int BlockX = 0; BlockX < 96; BlockX++)
            {
                for (int BlockY = 0; BlockY < 64; BlockY++)
                {
                    int BlockID = BlockX * 64 + BlockY + 1;
                    int firstID = BlockID / 100;
                    int secondID = BlockID - firstID * 100;
                    BlockID--;
                    String filename = newPath+"facet0_" + firstID + "_" + secondID + ".dat";
                    BinaryWriter bw = new BinaryWriter(File.Create(filename));
                    Tile t;
                    HuedTile[] ht;
                    bool overlap = false;
                    for (int X = BlockX * 64; X < (BlockX + 1) * 64; X++)
                    {
                        for (int Y = BlockY * 64; Y < (BlockY + 1) * 64; Y++)
                        {
                            t = tm.GetLandTile(X, Y);
                            if (!overlap)
                                bw.Write((byte)0);
                            else
                                overlap = false;
                            if (bw.BaseStream.Position == 1)
                                bw.Write((UInt16)BlockID);
                            else
                                bw.Write((UInt16)0);
                            bw.Write((SByte)t.Z);
                            bw.Write((UInt16)tt[t.ID]);
                            bw.Write(UopParser.Flip((UInt16)t.ID));
                            AddDelimiters(bw, BlockX, BlockY, X, Y);
                            ht = tm.GetStaticTiles(X, Y);
                            if (ht!=null)
                            {
                                for (int i = 0; i < ht.Length; i++)
                                {
                                    if (!overlap)
                                        bw.Write((byte)0);
                                    else
                                        overlap = false;
                                    bw.Write((byte)0);
                                    if (i == 0)
                                        bw.Write((byte)ht.Length);
                                    else
                                        bw.Write((byte)0);
                                    bw.Write((UInt16)ht[i].ID);
                                    bw.Write((UInt16)0);
                                    bw.Write((sbyte)ht[i].Z);
                                    bw.Write((UInt16)ht[i].Hue);
                                    overlap = true;
                                }
                            }                            
                        }
                    }
                    bw.Write(new byte[] { 0, 0, 0 });
                    bw.Close();
                }
            }

        }
Esempio n. 14
0
        private int PatchStatics(TileMatrix matrix, string dataPath, string indexPath, string lookupPath)
        {
            using (var fsData = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                using (var fsIndex = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                    using (var 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 (_tileBuffer.Length < tileCount)
                                {
                                    _tileBuffer = new StaticTile[tileCount];
                                }

                                StaticTile[] staTiles = _tileBuffer;

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

                                    fsData.Read(_buffer, 0, length);

                                    Marshal.Copy(_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);
                        }
        }
Esempio n. 15
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, $"mapdif{index}.mul");
                if (!File.Exists(mapDataPath))
                {
                    mapDataPath = null;
                }

                mapIndexPath = Path.Combine(path, $"mapdifl{index}.mul");
                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, $"stadif{index}.mul");
                if (!File.Exists(staDataPath))
                {
                    staDataPath = null;
                }

                staIndexPath = Path.Combine(path, $"stadifl{index}.mul");
                if (!File.Exists(staIndexPath))
                {
                    staIndexPath = null;
                }

                staLookupPath = Path.Combine(path, $"stadifi{index}.mul");
                if (!File.Exists(staLookupPath))
                {
                    staLookupPath = null;
                }
            }

            if (staDataPath == null || staIndexPath == null || staLookupPath == null)
            {
                return;
            }

            StaticBlocks      = new HuedTile[matrix.BlockWidth][][][][];
            StaticBlocksCount = PatchStatics(matrix, staDataPath, staIndexPath, staLookupPath);
        }