Exemple #1
0
        public void TestMethod3()
        {
            var dir = @"D:\avatar_new\image";

            foreach (var prof in pairs.Keys)
            {
                foreach (var part in part_array)
                {
                    var file = $@"{dir}\{prof}\{part}";

                    var path = $"d:/avatar_ex/image/{prof}/{part}";
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    var list = NpkCoder.Load(file);

                    foreach (var img in list)
                    {
                        var tables = img.Tables;
                        var match  = Regex.Match(img.Name, "\\d+");
                        if (match.Success)
                        {
                            var code = int.Parse(match.Value);
                            for (var i = 0; i < tables.Count; i++)
                            {
                                img.TableIndex = i;
                                var image = img[pairs[prof]];
                                ImageToJson(path, prof, part, img.Name, Avatars.CompleteCode(code + i), image);
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
        public static void GetWeapons()
        {
            var professions = new List <Profession>();
            var builder     = new LSBuilder();

            builder.ReadJson(Resources.profession).GetValue(ref professions);
            var gamePath = "D:\\地下城与勇士";

            var regex = new Regex("\\d+");

            foreach (var prof in professions)
            {
                foreach (var type in prof.Weapon)
                {
                    var file = $"{gamePath}\\{NpkCoder.IMAGE_DIR}\\{Avatars.GetWeaponFile(prof.Name, type)}.NPK";
                    if (!File.Exists(file))
                    {
                        continue;
                    }
                    var list = NpkCoder.LoadAll(file, Avatars.MatchWeapon);
                    var path = $"d:\\avatar\\new_image\\{prof.Name}\\{type}";
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    foreach (var img in list)
                    {
                        var image = img[prof.Frame];
                        var match = regex.Match(img.Name);
                        ImageToJson(path, prof.Name, type, img.Name, match.Value, image);
                    }
                }
            }
        }
        public void GetWeapon()
        {
            var prof_list = GetProfession();

            foreach (var prof in prof_list)
            {
                var dir = $"{SAVE_DIR}/image/{prof.Name}/weapon";
                if (Directory.Exists(dir))
                {
                    Directory.Delete(dir, true);
                }
                Directory.CreateDirectory(dir);

                foreach (var part in prof.WeaponNames)
                {
                    var file =
                        $"{GAME_DIR}/ImagePacks2/sprite_character_{prof}{(prof.Name.EndsWith("_at") ? "" : "_")}equipment_weapon_{ part }.NPK";
                    var list = NpkCoder.Load(file);
                    list = list.Where(item => {
                        var name = item.Name;
                        if (name.Contains("(tn)") || name.Contains("_mask"))
                        {
                            return(false);
                        }
                        var regex = new Regex("\\d+");
                        var match = regex.Match(name);
                        return(match.Success);
                    }).ToList();
                    NpkCoder.Save($"{dir}/{part}.NPK", list);
                }
            }
        }
Exemple #4
0
        public void Do(params object[] args)
        {
            array = args as Album[];
            if (array == null)
            {
                return;
            }
            counts = new int[array.Length];
            var i = 0;

            NpkCoder.Compare(GamePath, (a1, a2) => {
                counts[i] = a1.List.Count - a2.List.Count;
                if (counts[i] > 0)
                {
                    var source = a1.List.GetRange(a2.List.Count, counts[i]); //获得源文件比当前文件多的贴图集合
                    source.ForEach(e => {
                        e.Load();
                        e.Parent = a2;
                    });
                    a2.List.AddRange(source); //加入到当前文件中,不修改原贴图。
                }

                i++;
            }, array);
        }
Exemple #5
0
        public void Do(params object[] args)
        {
            currents = args as Album[];
            if (currents == null)
            {
                return;
            }
            olds = new Album[currents.Length];
            var i   = 0;
            var dir = NpkCoder.IMAGE_DIR;

            if (currents.Length > 0)
            {
                if (Regex.IsMatch(currents[0].Path, "^sounds/.*\\.ogg$"))
                {
                    dir = NpkCoder.SOUND_DIR;
                }
            }

            NpkCoder.Compare(GamePath, dir, (a1, a2) => {
                var old = new Album();
                old.Replace(a2); //保存旧文件
                a2.Replace(a1);  //替换为源文件
                olds[i++] = old;
            }, currents);
        }
Exemple #6
0
        public static List <Album> FindByCode(string path, string code, bool mask, bool ban)
        {
            var regex  = new Regex("\\d+");
            var index  = int.Parse(code) % 100;
            var match1 = regex.Match(code);

            if (!match1.Success)
            {
                return(new List <Album>());
            }
            var code1 = int.Parse(match1.Value);

            var stream = File.OpenRead(path);
            var list   = NpkCoder.ReadInfo(stream);

            list = FindByCode(list, code, mask, ban);
            list = new List <Album>(list.Where(al => {
                stream.Seek(al.Offset, SeekOrigin.Begin);
                NpkCoder.ReadImg(stream, al, stream.Length);
                var code0 = int.Parse(regex.Match(al.Name).Value);
                if (code0 == code1 || ((code0 == code1 / 100 * 100) && (index < al.Tables.Count)))
                {
                    al.TableIndex = index;
                    al.Name       = regex.Replace(al.Name, code, 1);
                    return(true);
                }
                return(false);
            }));
            stream.Close();
            return(list);
        }
Exemple #7
0
        private void loadNpkHeader(string dir)
        {
            if (!System.IO.Directory.Exists(dir))
            {
                return;
            }
            var files = System.IO.Directory.GetFiles(dir, "*.npk");

            for (int i = 0; i < files.Length; i++)
            {
                var albums = NpkCoder.Load(true, files[i]);
                for (int a = 0; a < albums.Count; a++)
                {
                    var npk = new NpkData
                    {
                        filePath = files[i],
                        index    = a,
                        album    = albums[a]
                    };

                    var path = albums[a].Path.Substring("sprite/".Length);
                    allNpkData[path] = npk;
                }
            }
            Debug.Log("load npk header : " + dir + " " + allNpkData.Count);
        }
Exemple #8
0
        public static Album[] SplitFile(this Album file)
        {
            var arr   = new Album[Math.Max(1, file.Tables.Count)];
            var regex = new Regex("\\d+");
            var name  = file.Name;
            var match = regex.Match(name);

            if (!match.Success)
            {
                arr[0] = file;
                return(arr);
            }
            var code = int.Parse(match.Value);

            file.Adjust();
            var data = file.Data;

            for (var i = 0; i < arr.Length; i++)
            {
                arr[i]      = new Album();
                arr[i].Path = regex.Replace(file.Path, CompleteCode(code + i), 1);
                NpkCoder.ReadImg(data, arr[i], data.LongLength);
                arr[i].Tables.Clear();
                if (file.Tables.Count > 0)
                {
                    arr[i].Tables.Add(file.Tables[i]);
                }
            }
            return(arr);
        }
        public void Test01()
        {
            var prof_list = GetProfession();

            foreach (var prof in prof_list)
            {
                var dir = $"{SAVE_DIR}/image/{prof}";
                if (Directory.Exists(dir))
                {
                    Directory.Delete(dir, true);
                }
                Directory.CreateDirectory(dir);
                foreach (var part in part_array)
                {
                    var file =
                        $"{GAME_DIR}/ImagePacks2/sprite_character_{prof}{(prof.Name.EndsWith("_at") ? "" : "_")}equipment_avatar_{part}.NPK";
                    var avatars = GetAvatar(prof.Name, part);
                    var list    = NpkCoder.Load(file);
                    var arr     = new List <Album>();
                    list = list.Where(item => {
                        var name = item.Name;
                        if (name.Contains("(tn)") || name.Contains("_mask"))
                        {
                            return(false);
                        }
                        var regex = new Regex("\\d+");
                        var match = regex.Match(name);
                        if (match.Success)
                        {
                            var codeStr = match.Value;
                            var code    = int.Parse(codeStr);
                            var rs      = false;
                            for (var i = 0; i < item.Tables.Count; i++)
                            {
                                rs = rs || !avatars.Contains((code + i).ToString());
                            }
                            return(rs);
                        }
                        return(false);
                    }).ToList();
                    var target = $"{dir}/{part}/";
                    if (!Directory.Exists(target))
                    {
                        Directory.CreateDirectory(target);
                    }
                    NpkCoder.SaveToDirectory($"{dir}/{part}", list);
                }
            }
        }
Exemple #10
0
 public void Action(params Album[] array)
 {
     NpkCoder.Compare(GamePath, (a1, a2) => {
         var count = a1.List.Count - a2.List.Count;
         if (count <= 0)
         {
             return;
         }
         var source = a1.List.GetRange(a2.List.Count, count);
         source.ForEach(e => {
             e.Load();
             e.Parent = a2;
         });
         a2.List.AddRange(source);
     }, array);
 }
Exemple #11
0
        public void TestSaveImg()
        {
            var list = NpkCoder.Load(@"D:\地下城与勇士\ImagePacks2\sprite_character_swordman_equipment_avatar_coat.NPK");

            Assert.IsTrue(list.Count > 0);
            var img = list[0];

            Assert.IsNotNull(img);
            var target = @"d:\test\v6\01.img";

            img.Save(target);
            Assert.IsTrue(File.Exists(target));
            list = NpkCoder.Load(target);
            Assert.IsTrue(list.Count > 0);
            img = list[0];
            Assert.IsNotNull(img);
        }
Exemple #12
0
        public void TestSaveImage()
        {
            var list = NpkCoder.Load(@"D:\test\v6\01.img");

            Assert.IsTrue(list.Count > 0);
            var img = list[0];

            Assert.IsNotNull(img);
            var dir = @"D:\test\v6\image\";

            if (Directory.Exists(dir))
            {
                Directory.Delete(dir, true);
                Directory.CreateDirectory(dir);
            }
            img.List.ForEach(e => e.Picture.Save(dir + e.Index + ".png"));
            Assert.IsTrue(Directory.GetFiles(dir, "*.png").Length == img.Count);
        }
Exemple #13
0
    void _openFile(string path)
    {
        path   = path.Replace("res://", GameManager.Instance.PrjPath);
        albums = NpkCoder.Load(path);
        albums.Count.ToString().log();

        albumList.Clear();
        for (int i = 0; i < albums.Count; i++)
        {
            albumList.AddItem(albums[i].Name);
        }

        selectAlbum = 0;
        if (albums.Count > 0)
        {
            setImage(0);
        }
        GC.Collect();
    }
Exemple #14
0
        public void GetWeapon()
        {
            var dir = "d:/avatar/new";

            foreach (var prof in pairs.Keys)
            {
                foreach (var typed in Directory.GetDirectories($"{dir}/{prof.Replace("_at", "")}/weapon"))
                {
                    var type = typed.GetSuffix();
                    var file =
                        $"{GAME_PATH}/sprite_character_{prof}{(prof.EndsWith("_at") ? "" : "_")}equipment_weapon_{GetType(prof, type)}.npk";
                    var list = NpkCoder.Load(file);
                    var ps   = $"{dir}/{prof}/weapon/{type}";
                    if (!Directory.Exists(ps))
                    {
                        continue;
                    }
                    var images = Directory.GetFiles(ps);

                    var path = $"d:/avatar/new_image/{prof}/weapon/{type}";
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    for (var i = 0; i < images.Length; i++)
                    {
                        var regex = new Regex("\\d+");
                        var match = regex.Match(images[i]);
                        //  if (match.Success) {
                        //     var code = match.Value;
                        //     var arr = list.Where(item => MatchCode(item.Name, code)).ToList();
                        //     var rs = FindImg(arr, int.Parse(code), type);
                        //     if (rs.Count() > 0) {
                        //         var img = rs.ElementAt(0);
                        //         var builder = new LSBuilder();
                        //         var image = img[pairs[prof]];
                        //         ImageToJson(path, prof, type, img.Name, match.Value, image);
                        //     }
                        // }
                    }
                }
            }
        }
Exemple #15
0
        public void TestMethod1()
        {
            var dir = @"D:\avatar_ex\icon";

            foreach (var prof in pairs.Keys)
            {
                foreach (var part in part_array)
                {
                    var file =
                        $"{GAME_PATH}/sprite_character_{prof}{(prof.EndsWith("_at") ? "" : "_")}equipment_avatar_{part}.NPK";
                    var list = NpkCoder.Load(file);
                    var ps   = $"{dir}/{prof}/{part}";
                    if (!Directory.Exists(ps))
                    {
                        continue;
                    }
                    var images = Directory.GetFiles(ps);

                    var path = $"d:/avatar_ex/image/{prof}/{part}";
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    for (var i = 0; i < images.Length; i++)
                    {
                        var regex = new Regex("\\d+");
                        var match = regex.Match(images[i]);
                        if (match.Success)
                        {
                            var code = match.Value;
                            var arr  = Avatars.FindByCode(list, code);
                            var rs   = FindImg(arr, int.Parse(code), part.Equals("skin") ? "body" : part);
                            foreach (var img in rs)
                            {
                                var image = img[pairs[prof]];
                                ImageToJson(path, prof, part, img.Name, match.Value, image);
                            }
                        }
                    }
                }
            }
        }
Exemple #16
0
        public void Test()
        {
            foreach (var f in Directory.GetFiles(@"D:\地下城与勇士\ImagePacks2"))
            {
                var list = NpkCoder.Load(f);
                foreach (var e in list)
                {
                    if (e.Version == ImgVersion.Ver5)
                    {
                        var handler = e.Handler as FifthHandler;
                        foreach (var a in handler.List)
                        {
                            var image = a.Pictrue;
                        }
                    }

                    GC.Collect();
                }
            }
        }
Exemple #17
0
        public void Action(params Album[] array)
        {
            switch (_type)
            {
            case SaveToDir:
                NpkCoder.SaveToDirectory(_path, array);
                break;

            case SaveToImg:
                if (array.Length > 0)
                {
                    array[0].Save(_path);
                }
                break;

            case SaveToNpk:
                NpkCoder.Save(_path, new List <Album>(array));
                break;
            }
        }
Exemple #18
0
        public void GetCategory()
        {
            var list    = LoadFileLst($"{GamePath}\\auto.lst");
            var builder = new LSBuilder();
            var rs      = new List <EntryInfo>();

            foreach (var f in list)
            {
                var file   = $"{GamePath}\\{f}";
                var stream = File.OpenRead(file);
                var infos  = NpkCoder.ReadInfo(stream);
                var array  = infos.ConvertAll(e => new EntryInfo()
                {
                    path   = e.Path,
                    length = e.Length
                });
                rs.AddRange(array);
                stream.Close();
            }
            builder.WriteObject(rs, "D:\\entries.json");
        }
Exemple #19
0
        public void GetImage(string source, string target, string prof)
        {
            foreach (var part in part_array)
            {
                var file =
                    $"{GAME_PATH}/sprite_character_{prof}{(prof.EndsWith("_at") ? "" : "_")}equipment_avatar_{part}.NPK";
                var list = NpkCoder.Load(file);
                var ps   = $"{source}/icon/{prof}/{part}";
                if (!Directory.Exists(ps))
                {
                    continue;
                }
                var images = Directory.GetFiles(ps);

                var path = $"{target}/image/{prof}/{part}";
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                for (var i = 0; i < images.Length; i++)
                {
                    var regex = new Regex("\\d+");
                    var match = regex.Match(images[i].GetSuffix());
                    if (match.Success)
                    {
                        var code = match.Value;
                        //    var arr = list.Where(item => NpkCoder.MatchCode(item.Name, code)).ToList();
                        //      var rs = FindImg(arr, int.Parse(code), part.Equals("skin") ? "body" : part);
                        //      foreach (var img in rs) {
                        //          var builder = new LSBuilder();
                        //          var image = img[pairs[prof]];
                        //          ImageToJson(path, prof, part, img.Name, match.Value, image);
                    }
                    //  }
                }
            }
        }
Exemple #20
0
        public void GetWeapon()
        {
            var dir       = @"D:\avatar_new\image";
            var prof_list = GetProfession();

            foreach (var prof in prof_list)
            {
                foreach (var part in prof.WeaponNames)
                {
                    var file = $"{dir}/{prof}/weapon/{part}.NPK";

                    var path = $"d:/avatar_ex/image/{prof}/weapon/{part}";
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    var list = NpkCoder.Load(file);

                    foreach (var img in list)
                    {
                        var tables = img.Tables;
                        var match  = Regex.Match(img.Name, "\\d+");
                        if (match.Success)
                        {
                            var code = int.Parse(match.Value);
                            for (var i = 0; i < tables.Count; i++)
                            {
                                img.TableIndex = i;
                                var image = img[pairs[prof.Name]];
                                ImageToJson(path, prof.Name, part, img.Name, Avatars.CompleteCode(code + i), image);
                            }
                        }
                    }
                }
            }
        }
Exemple #21
0
        public static void GetAvatars()
        {
            var professions = new List <Profession>();
            var builder     = new LSBuilder();

            builder.ReadJson(Resources.profession).GetValue(ref professions);
            var gamePath = "D:\\地下城与勇士";
            var parts    = new string[] { "hair", "cap", "face", "neck", "coat", "skin", "belt", "pants", "shoes" };

            var regex = new Regex("\\d+");

            foreach (var prof in professions)
            {
                foreach (var part in parts)
                {
                    var file = $"{gamePath}\\{NpkCoder.IMAGE_DIR}\\{Avatars.GetAvatarFile(prof.Name, part)}.NPK";
                    if (!File.Exists(file))
                    {
                        continue;
                    }
                    var array = GetAvatar(prof.Name, part);
                    var list  = NpkCoder.LoadAll(file, e => MatchAvatar(e, array));
                    var path  = $"d:\\avatar\\new_image\\{prof.Name}\\{part}";
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    foreach (var img in list)
                    {
                        var image = img[prof.Frame];
                        var match = regex.Match(img.Name);
                        ImageToJson(path, prof.Name, part, img.Name, match.Value, image);
                    }
                }
            }
        }
Exemple #22
0
 public void Action(params Album[] array)
 {
     NpkCoder.Compare(GamePath, (a1, a2) => a1.Replace(a2), array);
 }
Exemple #23
0
 public List <Album> Decode(string filename)
 {
     return(NpkCoder.Load(filename));
 }