コード例 #1
0
ファイル: TileMatrixPatch.cs プロジェクト: ViWinfii/UltimaXNA
        private unsafe int PatchStatics(TileMatrix tileMatrix, string dataPath, string indexPath, string lookupPath)
        {
            using (FileStream fsData = FileManager.GetFile(dataPath))
            {
                using (FileStream fsIndex = FileManager.GetFile(indexPath))
                {
                    using (FileStream fsLookup = FileManager.GetFile(lookupPath))
                    {
                        BinaryReader indexReader  = new BinaryReader(fsIndex);
                        BinaryReader lookupReader = new BinaryReader(fsLookup);

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

                        StaticTileList[][] lists = new StaticTileList[8][];

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

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

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

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

                            if (offset < 0 || length <= 0)
                            {
                                tileMatrix.SetStaticBlock(blockX, blockY, tileMatrix.EmptyStaticsBlock);

                                continue;
                            }

                            fsData.Seek(offset, SeekOrigin.Begin);

                            int tileCount = length / 7;

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

                            StaticTile[] staticTiles = m_TileBuffer;

                            fixed(StaticTile *pStaticTiles = staticTiles)
                            {
                                SharedMethods.Read(fsData.SafeFileHandle, pStaticTiles, length);

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

                                while (pCur < pEnd)
                                {
                                    lists[pCur->X & 0x07][pCur->Y & 0x07].Add((short)((pCur->ID & 0x3FFF) + 0x4000), pCur->Z);

                                    pCur = pCur + 1;
                                }

                                StaticTile[][][] tiles = new StaticTile[8][][];

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

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

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

                        indexReader.Close();
                        lookupReader.Close();

                        return(count);
                    }
                }
            }
        }
コード例 #2
0
        public StaticTile[] GetStatics(int width, int height)
        {
            List <StaticTile> statics = new List <StaticTile>();

            // Custom Houses are sent in 'planes' of four different types. We determine which type we're looking at the index and the size.
            int sizeFloor = ((width - 1) * (height - 1));
            int sizeWalls = (width * height);
            // There is no z data for most planes, so we have to determine their z by their relative position to preceeding planes of the same type.
            int numTilesInLastPlane = 0;
            int zIndex = 0;

            for (int plane = 0; plane < m_planeCount; plane++)
            {
                int numTiles = m_planes[plane].ItemData.Length >> 1;

                if ((plane == m_planeCount - 1) &&
                    (numTiles != sizeFloor) &&
                    (numTiles != sizeWalls))
                {
                    numTiles = m_planes[plane].ItemData.Length / 5;
                    int index = 0;
                    for (int j = 0; j < numTiles; j++)
                    {
                        StaticTile s = new StaticTile();
                        s.ID = (short)((m_planes[plane].ItemData[index++] << 8) + m_planes[plane].ItemData[index++]);
                        int x = (sbyte)m_planes[plane].ItemData[index++];
                        int y = (sbyte)m_planes[plane].ItemData[index++];
                        int z = (sbyte)m_planes[plane].ItemData[index++];
                        s.X = (byte)((width >> 1) + x - 1);
                        s.Y = (byte)((height >> 1) + y);
                        s.Z = (sbyte)z;
                        statics.Add(s);
                    }
                }
                else
                {
                    int iWidth = width, iHeight = height;
                    int iX = 0, iY = 0;

                    int x = 0, y = 0, z = 0;

                    if (plane == 0)
                    {
                        zIndex   = 0;
                        iWidth  += 1;
                        iHeight += 1;
                    }
                    else if (numTiles == sizeFloor)
                    {
                        if (numTilesInLastPlane != sizeFloor)
                        {
                            zIndex = 1;
                        }
                        else
                        {
                            zIndex++;
                        }
                        iWidth  -= 1;
                        iHeight -= 1;
                        iX       = 1;
                        iY       = 1;
                    }
                    else if (numTiles == sizeWalls)
                    {
                        if (numTilesInLastPlane != sizeWalls)
                        {
                            zIndex = 1;
                        }
                        else
                        {
                            zIndex++;
                        }
                    }



                    switch (zIndex)
                    {
                    case 0: z = 0; break;

                    case 1: z = 7; break;

                    case 2: z = 27; break;

                    case 3: z = 47; break;

                    case 4: z = 67; break;

                    default: continue;
                    }

                    int index = 0;
                    for (int j = 0; j < numTiles; j++)
                    {
                        StaticTile s = new StaticTile();
                        s.ID = (short)((m_planes[plane].ItemData[index++] << 8) + m_planes[plane].ItemData[index++]);
                        s.X  = (byte)(x + iX);
                        s.Y  = (byte)(y + iY);
                        s.Z  = (sbyte)z;
                        y++;
                        if (y >= iHeight)
                        {
                            y = 0;
                            x++;
                        }
                        statics.Add(s);
                    }
                    numTilesInLastPlane = numTiles;
                }
            }
            return(statics.ToArray());
        }