示例#1
0
        /// <summary>
        /// Called by Phoenix.Initialize().
        /// </summary>
        /// <param name="param">Client directory.</param>
        internal static void Load(object param)
        {
            string dir = param.ToString();

            try {
                Trace.WriteLine("Loading ultima data files started..", "MulLib");

                tiledata = TileData.Load(Path.Combine(dir, "tiledata.mul"));
                hues     = Hues.Load(Path.Combine(dir, "hues.mul"));
                radarCol = RadarCol.Load(Path.Combine(dir, "radarcol.mul"));
                skills   = Skills.Load(Path.Combine(dir, "skills.idx"), Path.Combine(dir, "skills.mul"));
                art      = Art.Load(Path.Combine(dir, "artidx.mul"), Path.Combine(dir, "art.mul"), MulFileAccessMode.ReadOnly);
                multi    = Multi.Load(Path.Combine(dir, "multi.idx"), Path.Combine(dir, "multi.mul"), MulFileAccessMode.ReadOnly);

                Trace.WriteLine("Loading ultima data files finished.", "MulLib");
            }
            catch (Exception e) {
                string msg = String.Format("Unable to load ultima data files. Program will be terminated. Exception:\r\n{0}", e);
                Trace.WriteLine(msg, "MulLib");
                MessageBox.Show(msg, "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Core.Terminate();
            }

            try {
                SyncEvent.Invoke(Loaded, null, EventArgs.Empty);
            }
            catch (Exception e) {
                Trace.WriteLine("Unhandled exception in DataFiles.Loaded event. Exception:\r\n" + e.ToString(), "MulLib");
            }
        }
示例#2
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            string path = Path.Combine(tbFolder.Text, "_new");

            int minid = 0x5780; int minid2 = 0x49FC; int minid3 = 0x4AB9;
            int maxid = 0x992C; int maxid2 = 0x4A8D; int maxid3 = 0x4AF4;
            //int newid = 0xA000;
            int newid = 0x8000;
            int count = 0;

            int[] idmat = new int[0xFFFF];
            for (int id = 0; id < idmat.Length; ++id)
            {
                idmat[id] = -1;
            }

            Ultima.Files.SetMulPath(tbFolder.Text);
            for (int id = 0; id < idmat.Length; ++id)
            {
                if ((id >= minid && id <= maxid) || (id >= minid2 && id <= maxid2) || (id >= minid3 && id <= maxid3))
                {
                    if (Art.IsValidStatic(id))
                    {
                        idmat[id] = newid + count;
                        ++count;
                    }
                }
            }

            string fpath1 = Path.Combine(Path.Combine(Ultima.Files.RootDir, "_old"), "VirtualTiles.xml");
            string fpath2 = Path.Combine(path, "VirtualTiles.xml");

            using (StreamReader sr = new StreamReader(new FileStream(fpath1, FileMode.Open, FileAccess.Read, FileShare.Read))) {
                using (StreamWriter sw = new StreamWriter(new FileStream(fpath2, FileMode.Create, FileAccess.ReadWrite, FileShare.Read))) {
                    String line;
                    // Read and display lines from the file until the end of
                    // the file is reached.
                    bool galeon = false;
                    while ((line = sr.ReadLine()) != null)
                    {
                        var st = line.Trim().Split(new char[] { '\"', '<', ' ', '/', '>' }, StringSplitOptions.RemoveEmptyEntries);
                        var si = st.Length - 1;

                        /*
                         * if (si > 2 && st[0] == "Unused") {
                         *  galeon = (st[si] == "галеон");
                         * }
                         *
                         * if (galeon && st.Length > 0 && st[si].Length == 6 && st[si][0] == '0' && st[si][1] == 'x') {
                         *  var se = Int32.Parse(st[si].Substring(2), NumberStyles.HexNumber);
                         *
                         *  idmat[se] = newid + count;
                         ++count;
                         *  line = line.Replace(st[si], String.Format("0x{0:X4}", idmat[se]));
                         * }
                         */
                        if (st.Length > 0 && st[si].Length == 6 && st[si][0] == '0' && st[si][1] == 'x')
                        {
                            var se = Int32.Parse(st[si].Substring(2), NumberStyles.HexNumber);
                            if (idmat[se] >= 0)
                            {
                                line = line.Replace(st[si], String.Format("0x{0:X4}", idmat[se]));
                            }
                        }
                        sw.WriteLine(line);
                    }
                    sr.Close(); sw.Close();
                }
            }

            fpath1 = Path.Combine(Path.Combine(Ultima.Files.RootDir, "_old"), "TilesGroup.xml");
            fpath2 = Path.Combine(path, "TilesGroup.xml");
            using (StreamReader sr = new StreamReader(new FileStream(fpath1, FileMode.Open, FileAccess.Read, FileShare.Read))) {
                using (StreamWriter sw = new StreamWriter(new FileStream(fpath2, FileMode.Create, FileAccess.ReadWrite, FileShare.Read))) {
                    String line;
                    // Read and display lines from the file until the end of
                    // the file is reached.
                    bool galeon = false;
                    while ((line = sr.ReadLine()) != null)
                    {
                        var st = line.Trim().Split(new char[] { '\"', '<', ' ', '/', '>' }, StringSplitOptions.RemoveEmptyEntries);
                        var si = st.Length - 1;
                        if (st.Length > 0 && st[si].Length == 6 && st[si][0] == '0' && st[si][1] == 'x')
                        {
                            var se = Int32.Parse(st[si].Substring(2), NumberStyles.HexNumber);
                            if (idmat[se] >= 0)
                            {
                                line = line.Replace(st[si], String.Format("0x{0:X4}", idmat[se]));
                            }
                        }
                        sw.WriteLine(line);
                    }
                    sr.Close(); sw.Close();
                }
            }

            int ccc = 0;

            for (int id = idmat.Length - 1; id >= 0; --id)
            {
                if (idmat[id] >= 0)
                {
                    Art.ReplaceStatic(idmat[id], Art.GetStatic(id));
                    Art.RemoveStatic(id);

                    var tdtemp = TileData.ItemTable[idmat[id]];
                    TileData.ItemTable[idmat[id]] = TileData.ItemTable[id];
                    TileData.ItemTable[id]        = tdtemp;

                    var rctemp = RadarCol.GetItemColor(idmat[id]);
                    RadarCol.SetItemColor(idmat[id], RadarCol.GetItemColor(id));
                    RadarCol.SetItemColor(id, rctemp);

                    // Cliloc
                }
                else if (idmat[id] == -55)
                {
                    ++ccc;
                }
            }

            MoveMultis(Ultima.Files.RootDir, path, idmat);
            MoveStatic(Ultima.Files.RootDir, path, 0, idmat);
            MoveStatic(Ultima.Files.RootDir, path, 1, idmat);

            /*
             * for (int multi = 0; multi < 0x2000; ++multi) {
             *  var comp = Multis.GetComponents(multi);
             *  if (comp == MultiComponentList.Empty) continue;
             *  for (int tid = 0; tid < comp.SortedTiles.Length; ++tid) {
             *      var tile = comp.SortedTiles[tid];
             *      if (idmat[tile.m_ItemID] >= 0)
             *          tile.m_ItemID = (ushort)idmat[tile.m_ItemID];
             *  }
             *  //Multis.Add(multi, comp);
             * }
             *
             * for (int x = 0; x < Map.Dangeon.Width; ++x)
             *  for (int y = 0; y < Map.Dangeon.Height; ++y) {
             *      var tiles = Map.Dangeon.Tiles.GetStaticTiles(x, y, false);
             *      for (int tid = 0; tid < tiles.Length; ++tid)
             *          if (idmat[tiles[tid].ID] > 0)
             *              tiles[tid].ID = (ushort)idmat[tiles[tid].ID];
             *  }
             *
             * for (int x = 0; x < Map.Sosaria.Width; ++x)
             *  for (int y = 0; y < Map.Sosaria.Height; ++y) {
             *      var tiles = Map.Sosaria.Tiles.GetStaticTiles(x, y, false);
             *      for (int tid = 0; tid < tiles.Length; ++tid)
             *          if (idmat[tiles[tid].ID] > 0)
             *              tiles[tid].ID = (ushort)idmat[tiles[tid].ID];
             *  }
             */

            // Saving data....
            Art.Save(path);
            TileData.SaveTileData(Path.Combine(path, "tiledata.mul"));
            RadarCol.Save(Path.Combine(path, "radarcol.mul"));
//            Multis.Save(path);
            MessageBox.Show("Done");
        }