Exemplo n.º 1
0
        private unsafe int PatchLand(TileMatrix tileMatrix, string dataPath, string indexPath)
        {
            using (FileStream fsData = FileManager.GetFile(dataPath))
            {
                using (FileStream fsIndex = FileManager.GetFile(indexPath))
                {
                    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 / tileMatrix.BlockHeight;
                        int y = blockID % tileMatrix.BlockHeight;

                        fsData.Seek(4, SeekOrigin.Current);

                        Tile[] tiles = new Tile[64];

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

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

                    indexReader.Close();

                    return count;
                }
            }
        }
Exemplo n.º 2
0
        public static void OnLoad()
        {
            Console.WriteLine("Loading Ultima Live map changes");

            if (!Directory.Exists(UltimaLiveSettings.UltimaLiveMapChangesSavePath))
            {
                Directory.CreateDirectory(UltimaLiveSettings.UltimaLiveMapChangesSavePath);
            }

            string[]      filePaths    = Directory.GetFiles(UltimaLiveSettings.UltimaLiveMapChangesSavePath, "*.live");
            List <string> staticsPaths = new List <string>();
            List <string> landPaths    = new List <string>();

            foreach (string s in filePaths)
            {
                if (s.Contains("map"))
                {
                    landPaths.Add(s);
                }
                else if (s.Contains("statics"))
                {
                    staticsPaths.Add(s);
                }
            }

            landPaths.Sort();

            //read map blocks and apply them in order
            foreach (string s in landPaths)
            {
                BinaryReader reader = new BinaryReader(File.Open(Path.Combine(Core.BaseDirectory, s), FileMode.Open));
                try
                {
                    reader.BaseStream.Seek(0, SeekOrigin.Begin);
                    int MapNumber = reader.ReadUInt16();

                    while (reader.BaseStream.Position < reader.BaseStream.Length)
                    {
                        int        x          = (int)reader.ReadInt16();
                        int        y          = (int)reader.ReadInt16();
                        LandTile[] blocktiles = new LandTile[64];

                        for (int j = 0; j < 64; j++)
                        {
                            short    id = reader.ReadInt16();
                            sbyte    z  = reader.ReadSByte();
                            LandTile lt = new LandTile(id, z);
                            blocktiles[j] = lt;
                        }

                        List <int> associated;
                        MapRegistry.MapAssociations.TryGetValue(MapNumber, out associated);
                        foreach (int integer in associated)
                        {
                            Map        map = Map.Maps[integer];
                            TileMatrix tm  = map.Tiles;
                            tm.SetLandBlock(x, y, blocktiles);
                        }
                    }
                }
                catch
                {
                    Console.WriteLine("An error occured reading land changes at " + reader.BaseStream.Position);
                }
                finally
                {
                    reader.Close();
                }
            }


            staticsPaths.Sort();
            //read statics blocks and apply them in order
            foreach (string s in staticsPaths)
            {
                FileInfo     mapFile = new FileInfo(Path.Combine(Core.BaseDirectory, s));
                BinaryReader reader  = new BinaryReader(File.Open(Path.Combine(Core.BaseDirectory, s), FileMode.Open));
                try
                {
                    reader.BaseStream.Seek(0, SeekOrigin.Begin);
                    int MapNumber = reader.ReadUInt16();

                    while (reader.BaseStream.Position < reader.BaseStream.Length)
                    {
                        int blockX      = (int)reader.ReadInt16();
                        int blockY      = (int)reader.ReadInt16();
                        int staticCount = reader.ReadInt32();

                        Dictionary <Point2D, List <StaticTile> > blockStatics = new Dictionary <Point2D, List <StaticTile> >();

                        for (int staticIndex = 0; staticIndex < staticCount; staticIndex++)
                        {
                            UInt16     id  = reader.ReadUInt16();
                            byte       x   = reader.ReadByte();
                            byte       y   = reader.ReadByte();
                            sbyte      z   = reader.ReadSByte();
                            Int16      hue = reader.ReadInt16();
                            StaticTile st  = new StaticTile(id, x, y, z, hue);

                            Point2D p = new Point2D(x, y);
                            if (!(blockStatics.ContainsKey(p)))
                            {
                                blockStatics.Add(p, new List <StaticTile>());
                            }
                            blockStatics[p].Add(st);
                        }

                        StaticTile[][][] newblockOfTiles = new StaticTile[8][][];

                        for (int i = 0; i < 8; i++)
                        {
                            newblockOfTiles[i] = new StaticTile[8][];
                            for (int j = 0; j < 8; j++)
                            {
                                Point2D p      = new Point2D(i, j);
                                int     length = 0;
                                if (blockStatics.ContainsKey(p))
                                {
                                    length = blockStatics[p].Count;
                                }
                                newblockOfTiles[i][j] = new StaticTile[length];
                                for (int k = 0; k < length; k++)
                                {
                                    if (blockStatics.ContainsKey(p))
                                    {
                                        newblockOfTiles[i][j][k] = blockStatics[p][k];
                                    }
                                }
                            }
                        }

                        List <int> associated;
                        MapRegistry.MapAssociations.TryGetValue(MapNumber, out associated);
                        foreach (int integer in associated)
                        {
                            Map        map = Map.Maps[integer];
                            TileMatrix tm  = map.Tiles;
                            tm.SetStaticBlock(blockX, blockY, newblockOfTiles);
                        }
                    }
                }
                catch
                {
                    Console.WriteLine("An error occured reading land changes.");
                }
                finally
                {
                    reader.Close();
                }
            }
        }