protected override void Initialize()
        {
            RegisterReplaceHandler <Motion>(filePath =>
            {
                var configuration = ConfigurationList.Instance.CurrentConfiguration;
                var motion        = new Motion();
                {
                    motion.Load(filePath, configuration?.BoneDatabase?.Skeletons?[0]);
                }
                return(motion);
            });
            RegisterExportHandler <Motion>(filePath =>
            {
                var configuration = ConfigurationList.Instance.CurrentConfiguration;
                {
                    Data.Save(filePath, configuration?.BoneDatabase?.Skeletons?[0]);
                }
            });
            RegisterExportHandler <MotionSet>(filePath =>
            {
                using (var motionSet = new MotionSet())
                {
                    motionSet.Motions.Add(Data);

                    var configuration = ConfigurationList.Instance.CurrentConfiguration;
                    {
                        motionSet.Save(filePath,
                                       configuration?.BoneDatabase?.Skeletons?[0], configuration?.MotionDatabase);
                    }
                }
            });
        }
Example #2
0
        protected override void Initialize()
        {
            RegisterReplaceHandler <Motion>(filePath =>
            {
                var configuration = ConfigurationList.Instance.CurrentConfiguration;
                var motion        = new Motion();
                {
                    motion.Load(filePath, configuration?.BoneDatabase?.Skeletons?[0]);
                }
                return(motion);
            });
            RegisterExportHandler <Motion>(filePath =>
            {
                var configuration = ConfigurationList.Instance.CurrentConfiguration;
                {
                    Data.Save(filePath, configuration?.BoneDatabase?.Skeletons?[0]);
                }
            });
            RegisterExportHandler <MotionSet>(filePath =>
            {
                using (var motionSet = new MotionSet())
                {
                    motionSet.Motions.Add(Data);

                    var configuration = ConfigurationList.Instance.CurrentConfiguration;
                    {
                        motionSet.Save(filePath,
                                       configuration?.BoneDatabase?.Skeletons?[0], configuration?.MotionDatabase);
                    }
                }
            });
            RegisterCustomHandler("Copy bone names to clipboard",
                                  () => Clipboard.SetText(string.Join("\n", Data.BoneInfos.Select(x => x.Name))));
        }
Example #3
0
        public void GetValidMotionSetIndex(
            int animId,
            bool isBattle,
            bool hasWeapon,
            int expectedMsetId)
        {
            var fakeBar = GenerateFakeBar(new bool[]
            {
                // A000
                ANIM,
                DUMMY,
                ANIM,
                DUMMY,
                // A001
                ANIM,
                DUMMY,
                ANIM,
                ANIM,
                // A002
                ANIM,
                DUMMY,
                ANIM,
                ANIM,
                // A003
                DUMMY,
                DUMMY,
                ANIM,
                DUMMY,
                // A004
                DUMMY,
                DUMMY,
                ANIM,
                DUMMY,
                // A005
                DUMMY,
                DUMMY,
                DUMMY,
                DUMMY,
            });

            var actualMsetId = MotionSet.GetMotionSetIndex(
                fakeBar, (MotionSet.MotionName)animId, isBattle, hasWeapon);

            Assert.Equal(expectedMsetId, actualMsetId);
        }
Example #4
0
        public void GetAbsoluteMotionSetIndex(
            bool isBattle,
            bool hasWeapon,
            int expectedMsetId)
        {
            var fakeBar = GenerateFakeBar(new bool[]
            {
                ANIM,
                ANIM,
                ANIM,
                ANIM,
            });

            var actualMsetId = MotionSet.GetMotionSetIndex(
                fakeBar, MotionSet.MotionName.IDLE, isBattle, hasWeapon);

            Assert.Equal(expectedMsetId, actualMsetId);
        }
Example #5
0
        private void doRobConvert()
        {
            string ac_path   = "";
            string ft_path   = "";
            string fs_path   = "";
            string ct_path   = "";
            bool   ask_user  = false;
            bool   skip_robs = false;

            if (File.Exists("config.txt"))
            {
                StreamReader sr = new StreamReader("config.txt");
                while (sr.Peek() > -1)
                {
                    var line  = sr.ReadLine();
                    var lines = line.Split('=');
                    if (lines[0] == "AC")
                    {
                        ac_path = lines[1];
                    }
                    if (lines[0] == "FT")
                    {
                        ft_path = lines[1];
                    }
                    if (lines[0] == "FS")
                    {
                        fs_path = lines[1];
                    }
                    if (lines[0] == "CT")
                    {
                        ct_path = lines[1];
                    }
                    if (lines[0] == "I_HAVE_CHANGED_THIS")
                    {
                        if (lines[1] == "TRUE")
                        {
                            ask_user = true;
                        }
                    }
                    if (lines[0] == "SKIP_ROBS")
                    {
                        if (lines[1] == "TRUE")
                        {
                            skip_robs = true;
                        }
                    }
                }
                sr.Close();
            }
            if ((ask_user) && (!skip_robs))
            {
                Logs.WriteLine("Rob Retarget Start");
                string[] filespl = System.IO.Directory.GetFiles(ft_path + @"\rob\", "*.farc", SearchOption.AllDirectories);
                string[] filesfs = { };
                string[] filesct = { };
                if (fs_path != "")
                {
                    filesfs = System.IO.Directory.GetFiles(fs_path + @"\rob\", "*.farc", SearchOption.AllDirectories);
                }
                if (ct_path != "")
                {
                    filesct = System.IO.Directory.GetFiles(ct_path + @"\rob\", "*.farc", SearchOption.AllDirectories);
                }
                string[] files = filespl.Concat(filesfs).ToArray().Concat(filesct).ToArray();


                var BoneDatabaseFT   = new BoneDatabase();
                var BoneDatabaseAC   = new BoneDatabase();
                var MotionDatabaseFT = new MotionDatabase();
                var MotionDatabaseAC = new MotionDatabase();

                BoneDatabaseFT.Load(ft_path + "\\bone_data.bin");
                BoneDatabaseAC.Load(ac_path + "\\bone_data.bin");

                using (var farcArchive = BinaryFile.Load <FarcArchive>(ac_path + "\\rob\\mot_db.farc"))
                    using (var entryStream = farcArchive.Open(farcArchive.Entries.First(), EntryStreamMode.MemoryStream))
                        MotionDatabaseAC.Load(entryStream);

                using (var farcArchive = BinaryFile.Load <FarcArchive>(ft_path + "\\rob\\mot_db.farc"))
                    using (var entryStream = farcArchive.Open(farcArchive.Entries.First(), EntryStreamMode.MemoryStream))
                        MotionDatabaseFT.Load(entryStream);

                var SkeletonEntryAC = BoneDatabaseAC.Skeletons[0];
                var SkeletonEntryFT = BoneDatabaseFT.Skeletons[0];

                foreach (var filePath in files)
                {
                    var motionset = new MotionSet();
                    if (!File.Exists(ac_path + "\\rob\\" + Path.GetFileName(filePath)))
                    {
                        if (!filePath.Contains("db"))
                        {
                            Logs.WriteLine("Processing " + Path.GetFileNameWithoutExtension(filePath));

                            string farcpath = filePath;

                            using (var farcArchive = BinaryFile.Load <FarcArchive>(farcpath))
                                using (var entryStream = farcArchive.Open(farcArchive.Entries.First(), EntryStreamMode.MemoryStream))
                                    motionset.Load(entryStream, SkeletonEntryFT, MotionDatabaseFT);
                            {
                                motionset.Save("temp", SkeletonEntryAC, MotionDatabaseAC);
                                //motionset.Dispose();


                                FarcArchive newfarc = new FarcArchive();
                                newfarc.Add(Path.GetFileNameWithoutExtension(filePath) + ".bin", "temp");
                                newfarc.Save(ac_path + "\\rob\\" + Path.GetFileName(filePath));
                            }
                        }
                    }
                }
            }
        }
Example #6
0
        public static void Convert(string path, string acpath, string mot_db, divamodgen divamods)
        {
            if (Directory.Exists(path + "temp"))
            {
                Directory.Delete(path + "temp", true);
            }
            if (Directory.Exists(path + "temp2"))
            {
                Directory.Delete(path + "temp2", true);
            }
            if (Directory.Exists(acpath + "\\rom\\rob_temp"))
            {
                Directory.Delete(acpath + "\\rom\\rob_temp", true);
            }

            Directory.CreateDirectory(path + "temp");
            Directory.CreateDirectory(path + "temp2");
            Directory.CreateDirectory(acpath + "\\rom\\rob_temp");

            MotionDatabase acmot  = new MotionDatabase();
            BoneDatabase   acbone = new BoneDatabase();

            acbone.Load(acpath + "\\rom\\bone_data.bin");
            var skeletonEntry = acbone.Skeletons[0];

            using (var farcArchive = BinaryFile.Load <FarcArchive>(mot_db))
                using (var entryStream = farcArchive.Open(farcArchive.Entries.First(), EntryStreamMode.MemoryStream))
                    acmot.Load(entryStream);

            foreach (string file in Directory.EnumerateFiles(path, "mot_pv*.farc", SearchOption.TopDirectoryOnly))
            {
                Tools.Extract(file, path + "temp\\");
                //Console.WriteLine("Extracted " + Path.GetFileName(file));
            }

            var maxid  = acmot.MotionSets.Max(c => c.Id);
            var maxid2 = -1;

            foreach (var i in acmot.MotionSets)
            {
                if (i.Id > maxid2)
                {
                    maxid2 = i.Id;
                }
            }

            foreach (string file in Directory.EnumerateFiles(path + "temp", "*p1_00.mot", SearchOption.AllDirectories))
            {
                Directory.CreateDirectory(path + "temp2\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3));
                var       moti   = CombineBone(path, file, path + "temp2\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + "\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + "_p1.mot");
                MotionSet motion = new MotionSet();
                if (File.Exists(acpath + "\\rom\\rob_temp\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + "\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + ".bin"))
                {
                    motion.Load(acpath + "\\rom\\rob_temp\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + "\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + ".bin");
                }
                motion.Motions.Add(moti);
                if (!Directory.Exists(acpath + "\\rom\\rob_temp\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3)))
                {
                    Directory.CreateDirectory(acpath + "\\rom\\rob_temp\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3));
                }
                motion.Save(acpath + "\\rom\\rob_temp\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + "\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + ".bin", skeletonEntry, acmot);

                maxid++;
                maxid2++;

                var check = acmot.MotionSets.Where(c => c.Name == "PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3)).FirstOrDefault();
                if (check == null)
                {
                    var motset = new MotionSetEntry();
                    motset.Name = "PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3);
                    motset.Id   = maxid + 1;
                    acmot.MotionSets.Add(motset);
                    check = acmot.MotionSets.Where(c => c.Name == "PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3)).First();
                }

                var motentry = new MotionEntry();
                motentry.Id   = maxid2 + 1;
                motentry.Name = "PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + "_P1";
                check.Motions.Add(motentry);

                int pvid = int.Parse(Path.GetFileNameWithoutExtension(file).Substring(2, 3));

                var check2 = divamods.Divamods.Where(c => c.pvid == pvid).FirstOrDefault();
                if (check2 == null)
                {
                    divamods.Divamods.Add(new pdaconversion.divamods(pvid));
                    Logs.WriteLine("Motion: Created new PV at id " + (pvid));
                    check2 = divamods.Divamods.Where(c => c.pvid == pvid).First();
                }

                Console.WriteLine("Converted " + Path.GetFileName(file));
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }

            foreach (string file in Directory.EnumerateFiles(path + "temp", "*p2_00.mot", SearchOption.AllDirectories))
            {
                Directory.CreateDirectory(path + "temp2\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3));
                var       moti   = CombineBone(path, file, path + "temp2\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + "\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + "_p2.mot");
                MotionSet motion = new MotionSet();
                if (File.Exists(acpath + "\\rom\\rob_temp\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + "\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + ".bin"))
                {
                    motion.Load(acpath + "\\rom\\rob_temp\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + "\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + ".bin");
                }
                motion.Motions.Add(moti);
                if (!Directory.Exists(acpath + "\\rom\\rob_temp\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3)))
                {
                    Directory.CreateDirectory(acpath + "\\rom\\rob_temp\\" + Path.GetFileNameWithoutExtension(file).Substring(2, 3));
                }
                motion.Save(acpath + "\\rom\\rob_temp\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + "\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + ".bin", skeletonEntry, acmot);
                Console.WriteLine("Converted " + Path.GetFileName(file));

                maxid++;
                maxid2++;

                var check = acmot.MotionSets.Where(c => c.Name == "PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3)).FirstOrDefault();
                if (check == null)
                {
                    var motset = new MotionSetEntry();
                    motset.Name = "PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3);
                    motset.Id   = maxid;
                    acmot.MotionSets.Add(motset);
                    check = acmot.MotionSets.Where(c => c.Name == "PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3)).First();
                }

                var motentry = new MotionEntry();
                motentry.Id   = maxid2;
                motentry.Name = "PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + "_P2";
                check.Motions.Add(motentry);

                int pvid = int.Parse(Path.GetFileNameWithoutExtension(file).Substring(2, 3));

                var check2 = divamods.Divamods.Where(c => c.pvid == pvid).FirstOrDefault();
                if (check2 == null)
                {
                    divamods.Divamods.Add(new pdaconversion.divamods(pvid));
                    Logs.WriteLine("Motion: Created new PV at id " + (pvid));
                    check2 = divamods.Divamods.Where(c => c.pvid == pvid).First();
                    //check2.duet = true;
                }

                check2.duet = true;
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }

            foreach (string file in Directory.EnumerateFiles(path + "temp", "*p3_00.mot", SearchOption.AllDirectories))
            {
                Directory.CreateDirectory(path + "temp2\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3));
                var       moti   = CombineBone(path, file, path + "temp2\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + "\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + "_p3.mot");
                MotionSet motion = new MotionSet();
                if (File.Exists(acpath + "\\rom\\rob_temp\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + "\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + ".bin"))
                {
                    motion.Load(acpath + "\\rom\\rob_temp\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + "\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + ".bin");
                }
                motion.Motions.Add(moti);
                if (!Directory.Exists(acpath + "\\rom\\rob_temp\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3)))
                {
                    Directory.CreateDirectory(acpath + "\\rom\\rob_temp\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3));
                }
                motion.Save(acpath + "\\rom\\rob_temp\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + "\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + ".bin", skeletonEntry, acmot);
                Console.WriteLine("Converted " + Path.GetFileName(file));

                maxid++;
                maxid2++;

                var check = acmot.MotionSets.Where(c => c.Name == "PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3)).FirstOrDefault();
                if (check == null)
                {
                    var motset = new MotionSetEntry();
                    motset.Name = "PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3);
                    motset.Id   = maxid;
                    acmot.MotionSets.Add(motset);
                    check = acmot.MotionSets.Where(c => c.Name == "PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3)).First();
                }

                var motentry = new MotionEntry();
                motentry.Id   = maxid2;
                motentry.Name = "PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + "_P3";
                check.Motions.Add(motentry);
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }

            Directory.CreateDirectory(acpath + "\\rom\\rob_temp\\mot_db");
            acmot.Save(acpath + "\\rom\\rob_temp\\mot_db\\mot_db.bin");

            Console.WriteLine("Packing farcs...");
            Tools.MassPackFolders(acpath + "\\rom\\rob_temp", acpath + "\\rom\\rob\\");
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }