Exemplo n.º 1
0
        public static void Extract(DbContextOptions options)
        {
            var wz = new Wz_Structure();

            wz.Load(@"C:\Nexon\MapleStory\String.wz");
            using (var db = new MapleStoryDbContext(options)) {
                var eqp = wz.WzNode.Nodes["Eqp.img"].GetNodeWzImage();
                if (!eqp.TryExtract())
                {
                    throw new Exception();
                }
                foreach (var dir in eqp.Node.Nodes.SelectMany(x => x.Nodes))
                {
                    foreach (var item in dir.Nodes)
                    {
                        var eq = db.Equipments.SingleOrDefault(x => x.EquipmentId == int.Parse(item.Text));
                        if (eq != null)
                        {
                            eq.EquipmentName = (string)item.Nodes["name"]?.Value;
                        }
                    }
                }
                db.SaveChanges();
            }
        }
Exemplo n.º 2
0
        public static void Extract(DbContextOptions options)
        {
            var wz = new Wz_Structure();

            wz.Load(@"C:\Nexon\MapleStory\Character.wz");
            var character = Directory.CreateDirectory("Character");

            Directory.SetCurrentDirectory(character.FullName);

            using (var db = new MapleStoryDbContext(options)) {
                foreach (var img in wz.WzNode.Nodes.Where(x => x.Value is Wz_Image).OrderBy(x => x.Text).Select(x => x.GetNodeWzImage()))
                {
                    var eq = CreateEquipment(img, false);
                    if (eq != null)
                    {
                        db.Equipments.Add(eq);
                    }
                }
                db.SaveChanges();

                var list = new[] {
                    "Accessory",
                    "Cap",
                    "Cape",
                    "Coat",
                    "Face",
                    "Glove",
                    "Hair",
                    "Longcoat",
                    "Pants",
                    "Ring",
                    "Shield",
                    "Shoes",
                    "Weapon"
                };
                foreach (var dir in wz.WzNode.Nodes.Where(x => !(x.Value is Wz_Image) && list.Contains(x.Text)).OrderBy(x => x.Text))
                {
                    Log(dir);
                    var fullpathes          = new List <string>();
                    var referenceFullpathes = new List <string>();
                    foreach (var img in dir.Nodes.OrderBy(x => x.Text).Select(x => x.GetNodeWzImage()))
                    {
                        var eq = CreateEquipment(img, dir.Text == "Hair");
                        if (eq != null)
                        {
                            db.Equipments.Add(eq);
                            referenceFullpathes.AddRange(eq.Frames.SelectMany(fr => fr.FrameImages.Select(fi => fi.ImageLogicalPath)));
                            fullpathes.AddRange(eq.Frames.SelectMany(fr => fr.FrameImages.Select(fi => fi.Image?.ImageLogicalPath)));
                        }
                    }
                    foreach (var i in referenceFullpathes.Except(fullpathes))
                    {
                        Console.WriteLine(i);
                    }
                    db.SaveChanges();
                }
            }
        }
Exemplo n.º 3
0
        public WzLoader(ILogger <WzLoader> logger)
        {
            this.logger  = logger;
            wz_Structure = new Wz_Structure();
            wz_Structure.Load(FILEPATH);

            BaseNode      = wz_Structure.WzNode;
            CharacterNode = BaseNode.SearchNode("Character");
            CharacterNode.Nodes.SortByImgID();
            StringNode = BaseNode.SearchNode("String");
            this.logger.LogInformation($"已加载Wz,baseNode={BaseNode.Text},character={CharacterNode.Text},string={StringNode.Text}");
        }
        protected MapRenderInvokerBase(string mapleStoryPath, Encoding encoding, bool disableImgCheck = false)
        {
            // Static settings for Wz_Structure :(
            Wz_Structure.DefaultAutoDetectExtFiles = true;
            Wz_Structure.DefaultEncoding           = encoding;
            Wz_Structure.DefaultImgCheckDisabled   = disableImgCheck;
            // Then our constructor
            string baseWzPath = Path.Combine(mapleStoryPath, MapleStoryPathHelper.MapleStoryBaseWzName);

            if (!File.Exists(baseWzPath))
            {
                throw new ArgumentException($"Cannot find {MapleStoryPathHelper.MapleStoryBaseWzName} in given directory {mapleStoryPath}.");
            }
            _wzStructure = new Wz_Structure();
            _wzStructure.Load(baseWzPath);
        }
Exemplo n.º 5
0
        public static void Extract(DbContextOptions options)
        {
            var wz = new Wz_Structure();

            wz.Load(@"C:\Nexon\MapleStory\Base.wz");
            using (var db = new MapleStoryDbContext(options)) {
                var zmap = wz.WzNode.Nodes["zmap.img"].GetNodeWzImage();
                if (!zmap.TryExtract())
                {
                    throw new Exception();
                }
                foreach (var(value, index) in zmap.Node.Nodes.Reverse().Select((value, index) => (value, index)))
                {
                    db.Zmaps.Add(new Zmap()
                    {
                        Name  = value.Text,
                        Index = index
                    });
                }

                var smap = wz.WzNode.Nodes["smap.img"].GetNodeWzImage();
                if (!smap.TryExtract())
                {
                    throw new Exception();
                }

                foreach (var(value, index) in smap.Node.Nodes.Reverse().Select((value, index) => (value, index)))
                {
                    db.Smaps.Add(new Smap()
                    {
                        Key   = value.Text,
                        Value = value.GetValue <string>(),
                        Index = index
                    });
                }
                db.SaveChanges();
            }
        }
Exemplo n.º 6
0
        private void patcher_PatchingStateChanged(object sender, PatchingEventArgs e)
        {
            switch (e.State)
            {
            case PatchingState.PatchStart:
                AppendStateText("Starting Update: " + e.Part.FileName + "\r\n");
                break;

            case PatchingState.VerifyOldChecksumBegin:
                AppendStateText("  Checking old file checksum...");
                break;

            case PatchingState.VerifyOldChecksumEnd:
                AppendStateText("  Complete\r\n");
                break;

            case PatchingState.VerifyNewChecksumBegin:
                AppendStateText("  Checking new file checksum...");
                break;

            case PatchingState.VerifyNewChecksumEnd:
                AppendStateText("  Complete\r\n");
                break;

            case PatchingState.TempFileCreated:
                AppendStateText("  Creating temporary files...\r\n");
                progressBarX1.Maximum = e.Part.NewFileLength;
                break;

            case PatchingState.TempFileBuildProcessChanged:
                progressBarX1.Value = (int)e.CurrentFileLength;
                progressBarX1.Text  = string.Format("{0:N0}/{1:N0}", e.CurrentFileLength, e.Part.NewFileLength);
                break;

            case PatchingState.TempFileClosed:
                AppendStateText("  Closing temporary files...\r\n");
                progressBarX1.Value   = 0;
                progressBarX1.Maximum = 0;
                progressBarX1.Text    = string.Empty;

                if (!string.IsNullOrEmpty(this.compareFolder) &&
                    e.Part.Type == 1 &&
                    Path.GetExtension(e.Part.FileName).Equals(".wz", StringComparison.OrdinalIgnoreCase) &&
                    !Path.GetFileName(e.Part.FileName).Equals("list.wz", StringComparison.OrdinalIgnoreCase))
                {
                    Wz_Structure wznew = new Wz_Structure();
                    Wz_Structure wzold = new Wz_Structure();
                    try
                    {
                        AppendStateText("  (comparer)Comparing files...\r\n");
                        EasyComparer comparer = new EasyComparer();
                        comparer.OutputPng               = chkOutputPng.Checked;
                        comparer.OutputAddedImg          = chkOutputAddedImg.Checked;
                        comparer.OutputRemovedImg        = chkOutputRemovedImg.Checked;
                        comparer.Comparer.PngComparison  = (WzPngComparison)cmbComparePng.SelectedItem;
                        comparer.Comparer.ResolvePngLink = chkResolvePngLink.Checked;
                        wznew.Load(e.Part.TempFilePath, false);
                        wzold.Load(e.Part.OldFilePath, false);
                        comparer.EasyCompareWzFiles(wznew.wz_files[0], wzold.wz_files[0], this.compareFolder);
                    }
                    catch (Exception ex)
                    {
                        txtPatchState.AppendText(ex.ToString());
                    }
                    finally
                    {
                        wznew.Clear();
                        wzold.Clear();
                        GC.Collect();
                    }
                }

                if (this.deadPatch && e.Part.Type == 1)
                {
                    ((WzPatcher)sender).SafeMove(e.Part.TempFilePath, e.Part.OldFilePath);
                    AppendStateText("  (deadpatch)Applying files...\r\n");
                }
                break;
            }
        }
Exemplo n.º 7
0
        private void patcher_PatchingStateChanged(object sender, PatchingEventArgs e)
        {
            switch (e.State)
            {
            case PatchingState.PatchStart:
                AppendStateText("开始更新" + e.Part.FileName + "\r\n");
                break;

            case PatchingState.VerifyOldChecksumBegin:
                AppendStateText("  检查旧文件checksum...");
                break;

            case PatchingState.VerifyOldChecksumEnd:
                AppendStateText("  结束\r\n");
                break;

            case PatchingState.VerifyNewChecksumBegin:
                AppendStateText("  检查新文件checksum...");
                break;

            case PatchingState.VerifyNewChecksumEnd:
                AppendStateText("  结束\r\n");
                break;

            case PatchingState.TempFileCreated:
                AppendStateText("  创建临时文件...\r\n");
                progressBarX1.Maximum = e.Part.NewFileLength;
                break;

            case PatchingState.TempFileBuildProcessChanged:
                progressBarX1.Value = (int)e.CurrentFileLength;
                progressBarX1.Text  = string.Format("{0:N0}/{1:N0}", e.CurrentFileLength, e.Part.NewFileLength);
                break;

            case PatchingState.TempFileClosed:
                AppendStateText("  关闭临时文件...\r\n");
                progressBarX1.Value   = 0;
                progressBarX1.Maximum = 0;
                progressBarX1.Text    = string.Empty;

                if (!string.IsNullOrEmpty(this.compareFolder) &&
                    e.Part.Type == 1 &&
                    Path.GetExtension(e.Part.FileName).Equals(".wz", StringComparison.OrdinalIgnoreCase) &&
                    !Path.GetFileName(e.Part.FileName).Equals("list.wz", StringComparison.OrdinalIgnoreCase))
                {
                    Wz_Structure wznew = new Wz_Structure();
                    Wz_Structure wzold = new Wz_Structure();
                    try
                    {
                        AppendStateText("  (comparer)正在对比文件...\r\n");
                        EasyComparer comparer = new EasyComparer();
                        comparer.OutputPng               = chkOutputPng.Checked;
                        comparer.OutputAddedImg          = chkOutputAddedImg.Checked;
                        comparer.OutputRemovedImg        = chkOutputRemovedImg.Checked;
                        comparer.Comparer.PngComparison  = (WzPngComparison)cmbComparePng.SelectedItem;
                        comparer.Comparer.ResolvePngLink = chkResolvePngLink.Checked;
                        wznew.Load(e.Part.TempFilePath, false);
                        wzold.Load(e.Part.OldFilePath, false);
                        comparer.EasyCompareWzFiles(wznew.wz_files[0], wzold.wz_files[0], this.compareFolder);
                    }
                    catch (Exception ex)
                    {
                        txtPatchState.AppendText(ex.ToString());
                    }
                    finally
                    {
                        wznew.Clear();
                        wzold.Clear();
                        GC.Collect();
                    }
                }

                if (this.deadPatch && e.Part.Type == 1 && sender is WzPatcher patcher)
                {
                    if (patcher.IsKMST1125Format.Value)
                    {
                        // TODO: we should build the file dependency tree to make sure all old files could be overridden safely.
                        AppendStateText("  (deadpatch)延迟应用文件...\r\n");
                    }
                    else
                    {
                        patcher.SafeMove(e.Part.TempFilePath, e.Part.OldFilePath);
                        AppendStateText("  (deadpatch)正在应用文件...\r\n");
                    }
                }
                break;

            case PatchingState.PrepareVerifyOldChecksumBegin:
                AppendStateText($"预检查旧文件checksum: {e.Part.FileName}");
                break;

            case PatchingState.PrepareVerifyOldChecksumEnd:
                AppendStateText(" 结束\r\n");
                break;

            case PatchingState.ApplyFile:
                AppendStateText($"应用文件: {e.Part.FileName}\r\n");
                break;
            }
        }
        public static void Extract(DbContextOptions options)
        {
            var regex = new Regex(@"(^begin|^end)(\d*)$");
            var wz    = new Wz_Structure();

            wz.Load(@"C:\Nexon\MapleStory\Item.wz");
            using (var db = new MapleStoryDbContext(options)) {
                var eqp = wz.WzNode.Nodes["ThothSearchOption.img"].GetNodeWzImage();
                if (!eqp.TryExtract())
                {
                    throw new Exception();
                }
                db.ItemCategories.AddRange(new[] {
                    new ItemCategory {
                        ItemCategory1          = "Character",
                        ItemCategory2          = "Body",
                        ItemCategoryName       = "肌",
                        ItemCategoryRangeBegin = 2000,
                        ItemCategoryRangeEnd   = 2099
                    },
                    new ItemCategory {
                        ItemCategory1          = "Character",
                        ItemCategory2          = "Head",
                        ItemCategoryName       = "肌(顔)",
                        ItemCategoryRangeBegin = 12000,
                        ItemCategoryRangeEnd   = 12099
                    },
                    new ItemCategory {
                        ItemCategory1          = "Character",
                        ItemCategory2          = "Hair",
                        ItemCategoryName       = "髪",
                        ItemCategoryRangeBegin = 30000,
                        ItemCategoryRangeEnd   = 49999
                    },
                    new ItemCategory {
                        ItemCategory1          = "Character",
                        ItemCategory2          = "Face",
                        ItemCategoryName       = "顔",
                        ItemCategoryRangeBegin = 20000,
                        ItemCategoryRangeEnd   = 29999
                    },
                });

                foreach (var category1 in eqp.Node.Nodes["ItemDetailCategory"].Nodes)
                {
                    foreach (var category2 in category1.Nodes)
                    {
                        var ranges =
                            category2
                            .Nodes
                            .Where(x => regex.IsMatch(x.Text))
                            .GroupBy(x => regex.Replace(x.Text, "$2"))
                            .Select(x => {
                            int?begin = null;
                            int?end   = null;
                            foreach (var attr in x)
                            {
                                if (attr.Text.StartsWith("begin"))
                                {
                                    begin = GetValue <int>(attr.Value);
                                }
                                if (attr.Text.StartsWith("end"))
                                {
                                    end = GetValue <int>(attr.Value);
                                }
                            }
                            return(begin, end);
                        });
                        foreach (var(begin, end) in ranges)
                        {
                            var category = new ItemCategory {
                                ItemCategory1          = category1.Text,
                                ItemCategory2          = category2.Text,
                                ItemCategoryName       = GetValue <string>(category2.Nodes["string"].Value),
                                ItemCategoryRangeBegin = (int)begin,
                                ItemCategoryRangeEnd   = (int)end
                            };

                            db.ItemCategories.Add(category);
                        }
                    }
                }
                db.SaveChanges();
            }
        }