protected override void Initialize() { RegisterImportHandler <Motion>(filePath => { var configuration = ConfigurationList.Instance.CurrentConfiguration; var motion = new Motion(); { motion.Load(filePath, configuration?.BoneDatabase?.Skeletons?[0]); } Data.Motions.Add(motion); }); RegisterImportHandler <MotionSet>(filePath => { var configuration = ConfigurationList.Instance.CurrentConfiguration; var motionSet = new MotionSet(); { motionSet.Load(filePath, configuration?.BoneDatabase?.Skeletons?[0], configuration?.MotionDatabase); } Data.Motions.AddRange(motionSet.Motions); }); RegisterReplaceHandler <MotionSet>(filePath => { var configuration = ConfigurationList.Instance.CurrentConfiguration; var motionSet = new MotionSet(); { motionSet.Load(filePath, configuration?.BoneDatabase?.Skeletons?[0], configuration?.MotionDatabase); } return(motionSet); }); RegisterReplaceHandler <Motion>(filePath => { var configuration = ConfigurationList.Instance.CurrentConfiguration; var motion = new Motion(); var motionSet = new MotionSet(); { motion.Load(filePath, configuration?.BoneDatabase?.Skeletons?[0]); motionSet.Motions.Add(motion); } return(motionSet); }); RegisterExportHandler <MotionSet>(filePath => { var configuration = ConfigurationList.Instance.CurrentConfiguration; { Data.Save(filePath, configuration?.BoneDatabase?.Skeletons?[0], configuration?.MotionDatabase); } }); RegisterCustomHandler("Copy motion database info to clipboard", () => { int id = -1; using (var inputDialog = new InputDialog { WindowTitle = "Enter base id for motions", Input = Math.Max(0, Data.Motions.Max(x => x.Id) + 1).ToString() }) { while (inputDialog.ShowDialog() == DialogResult.OK) { bool result = int.TryParse(inputDialog.Input, out id); if (!result || id < 0) { MessageBox.Show("Please enter a correct id number.", "Luka Luka Model", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { break; } } } if (id < 0) { return; } var motionSetEntry = new MotionSetEntry { Id = 39, Name = Path.GetFileNameWithoutExtension(Name), }; if (motionSetEntry.Name.StartsWith("mot_", StringComparison.OrdinalIgnoreCase)) { motionSetEntry.Name = motionSetEntry.Name.Remove(0, 4); } foreach (var motion in Data.Motions) { motionSetEntry.Motions.Add(new MotionEntry { Name = motion.Name, Id = id++, }); } using (var stringWriter = new StringWriter()) using (var xmlWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings { Indent = true, OmitXmlDeclaration = true })) { sMotionSetEntrySerializer.Serialize(xmlWriter, motionSetEntry, new XmlSerializerNamespaces(new[] { XmlQualifiedName.Empty })); Clipboard.SetText(stringWriter.ToString()); } }); base.Initialize(); }
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(); }