private void OnBoneDatabaseBrowse(object sender, EventArgs e) { mBoneDatabasePathTextBox.Text = ModuleImportUtilities.SelectModuleImport <BoneDatabase>( "Select a bone database file. (bone_data.bin/bone_data.bon)", SelectedConfiguration?.BoneDatabaseFilePath) ?? mBoneDatabasePathTextBox.Text; }
private void OnTextureDatabaseBrowse(object sender, EventArgs e) { mTextureDatabasePathTextBox.Text = ModuleImportUtilities.SelectModuleImport <TextureDatabase>( "Select a texture database file. (tex_db.bin)", SelectedConfiguration?.TextureDatabaseFilePath) ?? mTextureDatabasePathTextBox.Text; }
private void OnObjectDatabaseBrowse(object sender, EventArgs e) { mObjectDatabasePathTextBox.Text = ModuleImportUtilities.SelectModuleImport <ObjectDatabase>( "Select an object database file. (obj_db.bin)", SelectedConfiguration?.ObjectDatabaseFilePath) ?? mObjectDatabasePathTextBox.Text; }
private void OnMotionDatabaseBrowse(object sender, EventArgs e) { mMotionDatabasePathTextBox.Text = ModuleImportUtilities.SelectModuleImport( new[] { typeof(MotionDatabase), typeof(FarcArchive) }, "Select a motion database file. (mot_db.bin/mot_db.farc)", SelectedConfiguration?.MotionDatabaseFilePath) ?? mMotionDatabasePathTextBox.Text; }
private void OnCombineMotions(object sender, EventArgs e) { string filePath = ModuleImportUtilities.SelectModuleImport <Motion>("Select the root .mot file."); if (filePath == null) { return; } var configuration = ConfigurationList.Instance.FindConfiguration(filePath); if (configuration?.BoneDatabase == null) { MessageBox.Show("Could not find suitable configuration for the file.", Program.Name, MessageBoxButtons.OK, MessageBoxIcon.Error); } else { string baseFilePath = Path.ChangeExtension(filePath, null); string outputFilePath = ModuleExportUtilities.SelectModuleExport <Motion>( "Select a file to export to.", Path.GetFileName($"{baseFilePath}_combined.mot")); if (string.IsNullOrEmpty(outputFilePath)) { return; } var skeleton = configuration.BoneDatabase.Skeletons[0]; var rootMotion = new Motion(); { rootMotion.Load(filePath, skeleton); } var rootController = rootMotion.Bind(); for (int i = 1;; i++) { string divFilePath = $"{baseFilePath}_div_{i}.mot"; if (!File.Exists(divFilePath)) { break; } var divMotion = new Motion(); { divMotion.Load(divFilePath, skeleton); } var divController = divMotion.Bind(); rootController.Merge(divController); } rootMotion.Save(outputFilePath, skeleton); } }
private Skin PrompImportExData() { string filePath = ModuleImportUtilities.SelectModuleImport(new[] { typeof(FarcArchive), typeof(ObjectSet) }); if (string.IsNullOrEmpty(filePath)) { return(null); } ObjectSet objSet; if (filePath.EndsWith(".farc", StringComparison.OrdinalIgnoreCase)) { objSet = BinaryFileNode <ObjectSet> .PromptFarcArchiveViewForm(filePath, "Select a file to replace with.", "This archive has no object set file."); } else { objSet = BinaryFile.Load <ObjectSet>(filePath); } if (objSet == null) { return(null); } if (objSet.Objects.Count == 0 || !objSet.Objects.Any(x => x.Skin != null && x.Skin.Blocks.Count > 0)) { MessageBox.Show("This object set has no objects with ex data.", Program.Name, MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } if (objSet.Objects.Count == 1) { return(objSet.Objects[0].Skin); } using (var listNode = new ListNode <Object>("Objects", objSet.Objects, x => x.Name)) using (var nodeSelectForm = new NodeSelectForm <Object>(listNode, obj => obj.Skin != null && obj.Skin.Blocks.Count > 0)) { nodeSelectForm.Text = "Please select an object."; if (nodeSelectForm.ShowDialog() == DialogResult.OK) { return((( Object )nodeSelectForm.TopNode.Data).Skin); } } return(null); }
public static INode Create(string filePath, IEnumerable <Type> typesToMatch) { var module = ModuleImportUtilities.GetModule(filePath); if (module == null || !NodeTypes.ContainsKey(module.ModelType)) { throw new InvalidDataException("File type could not be determined."); } ConfigurationList.Instance.DetermineCurrentConfiguration(filePath); return(Create(module.ModelType, Path.GetFileName(filePath), module.Import(filePath))); }
public static INode Create(string filePath, IEnumerable <Type> typesToMatch) { var module = ModuleImportUtilities.GetModule(filePath); if (module == null || !NodeTypes.ContainsKey(module.ModelType)) { return(new StreamNode(Path.GetFileName(filePath), File.OpenRead(filePath))); } ConfigurationList.Instance.DetermineCurrentConfiguration(filePath); return(Create(module.ModelType, Path.GetFileName(filePath), module.Import(filePath))); }
private static void RemoveChunks() { foreach (var gmd in Directory.GetFiles(Input.retargetFolder, "*.GMD", SearchOption.TopDirectoryOnly)) { var modelPack = ModuleImportUtilities.ImportFile <ModelPack>(gmd); var newModelPack = new ModelPack(); newModelPack.Version = modelPack.Version; newModelPack.Textures = modelPack.Textures; newModelPack.Materials = modelPack.Materials; newModelPack.Model = modelPack.Model; newModelPack.AnimationPack = modelPack.AnimationPack; newModelPack.Save(gmd); } }
private static void ReplaceModels() { for (int i = 0; i < Input.ogModels.Length; i++) { bool foundMatch = false; for (int x = 0; x < Input.newModels.Length; x++) { //If filenames match except for character ID, replace new model with old one string renamedNewModel = Path.GetFileName(Input.newModels[x]).Replace(Path.GetFileName(Options.New), Path.GetFileName(Options.Old)); if (Path.GetFileName(Input.ogModels[i]) == renamedNewModel) { if (Options.GMD.Retarget) { //Retarget matching new model to old model's IDs, using default model when no match is found var originalModelPack = ModuleImportUtilities.ImportFile <ModelPack>(Input.ogModels[i]); var newModelPack = ModuleImportUtilities.ImportFile <ModelPack>(Input.newModels[x]); originalModelPack.ReplaceWith(newModelPack); originalModelPack.Save(Path.Combine(Input.retargetFolder, Path.GetFileName(Input.ogModels[i]))); Console.WriteLine($"Retargeting {Path.GetFileName(Input.newModels[x])} to {Path.GetFileName(Input.ogModels[i])}"); } else if (Options.GMD.Replace) { //If not retargeting, copy file foundMatch = true; File.Copy(Input.newModels[x], Path.Combine(Input.retargetFolder, Path.GetFileName(Input.ogModels[i]))); Console.WriteLine($"Copying {Path.GetFileName(Input.newModels[x])} to replace {Path.GetFileName(Input.ogModels[i])}"); } } } if (!foundMatch) { if (Options.GMD.Retarget) { //Retarget default model var originalModelPack = ModuleImportUtilities.ImportFile <ModelPack>(Input.ogModels[i]); var newModelPack = ModuleImportUtilities.ImportFile <ModelPack>(Input.newDefaultModel); originalModelPack.ReplaceWith(newModelPack); originalModelPack.Save(Path.Combine(Input.retargetFolder, Path.GetFileName(Input.ogModels[i]))); Console.WriteLine($"Retargeting {Path.GetFileName(Input.newDefaultModel)} to {Path.GetFileName(Input.ogModels[i])}"); } else if (Options.GMD.Replace) { //Copy default model to new location File.Copy(Input.newDefaultModel, Path.Combine(Input.retargetFolder, Path.GetFileName(Input.ogModels[i]))); Console.WriteLine($"Copying {Path.GetFileName(Input.newDefaultModel)} to replace {Path.GetFileName(Input.ogModels[i])}"); } } } }
private void ConvertOsageSkinParameters(BinaryFormat format) { var filePaths = ModuleImportUtilities.SelectModuleImportMultiselect <OsageSkinParameterSet>( "Select file(s) to convert."); if (filePaths == null) { return; } using (var folderBrowserDialog = new VistaFolderBrowserDialog { Description = "Select a folder to save file(s) to.", UseDescriptionForTitle = true }) { if (folderBrowserDialog.ShowDialog(this) != DialogResult.OK) { return; } new Thread(() => { try { Invoke(new Action(() => Enabled = false)); string extension = format.IsModern() ? ".osp" : ".txt"; foreach (string filePath in filePaths) { var ospSet = BinaryFile.Load <OsageSkinParameterSet>(filePath); ospSet.Format = format; ospSet.Save(Path.Combine(folderBrowserDialog.SelectedPath, Path.GetFileNameWithoutExtension(filePath) + extension)); } } finally { Invoke(new Action(() => Enabled = true)); } }).Start(); } }
/// <summary> /// Tries to create a view model from a given stream. /// </summary> /// <param name="text">Display text or filename of the resource for the resulting <see cref="DataViewNode"/>.</param> /// <param name="stream">Stream containing resource data.</param> /// <param name="viewModel">The resulting view model for the given resource.</param> /// <returns>Whether or not the operation succeeded.</returns> public static bool TryCreate(string text, Stream stream, object[] extraArguments, out DataViewNode viewModel) { // check if the given text is likely a filename string filename = null; if (stream is FileStream fileStream) { filename = fileStream.Name; } else { if (Path.HasExtension(text)) { filename = text; } } // try get module for importing if (!ModuleImportUtilities.TryGetModuleForImport(stream, out var module, filename)) { // fallback viewModel = new StreamViewNode(text, stream); viewModel.Initialize(); return(true); } // import resource w/ module var resource = module.Import(stream, filename); // try to create a view model if (!TryCreate(text, resource, module.ModelType, extraArguments, out viewModel)) { return(false); } return(true); }
private void HandleRetargetAnimationsToolStripMenuItemClick(object sender, EventArgs e) { var originalScene = ModuleImportUtilities.SelectImportFile <ModelPack>("Select the original model file.")?.Model; if (originalScene == null) { return; } var newScene = ModuleImportUtilities.SelectImportFile <ModelPack>("Select the new model file.")?.Model; if (newScene == null) { return; } bool fixArms = MessageBox.Show("Fix arms? If unsure, select No.", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes; string directoryPath; using (var dialog = new VistaFolderBrowserDialog()) { dialog.Description = "Select a directory containing GAP files, or subdirectories containing GAP files to retarget to the new model.\n" + "Note that this will replace the original files."; if (dialog.ShowDialog() != DialogResult.OK) { return; } directoryPath = dialog.SelectedPath; } var failures = new ConcurrentBag <string>(); using (var dialog = new ProgressDialog()) { dialog.DoWork += (o, progress) => { var filePaths = Directory.EnumerateFiles(directoryPath, "*.GAP", SearchOption.AllDirectories).ToList(); var processedFileCount = 0; Parallel.ForEach(filePaths, (filePath, state) => { lock ( dialog ) { if (dialog.CancellationPending) { state.Stop(); return; } dialog.ReportProgress(( int )((( float )++processedFileCount / filePaths.Count) * 100), $"Processing {Path.GetFileName( filePath )}", null); } try { var animationPack = Resource.Load <AnimationPack>(filePath); animationPack.Retarget(originalScene, newScene, fixArms); animationPack.Save(filePath); } catch (Exception) { failures.Add(filePath); } }); }; dialog.ShowDialog(); } if (failures.Count > 0) { MessageBox.Show("An error occured while processing the following files:\n" + string.Join("\n", failures)); } }
private static void ReplaceAnimations() { var newCharDefaultModel = ModuleImportUtilities.ImportFile <ModelPack>(Input.newDefaultModel); var ogCharDefaultModel = ModuleImportUtilities.ImportFile <ModelPack>(Input.ogDefaultModel); for (int i = 0; i < Input.ogAnims.Length; i++) { bool foundMatch = false; //Set destination to GMD folder if name contains emt string newDestination = ""; if (Input.ogAnims[i].Contains("emt")) { newDestination = Path.Combine(Input.retargetFolder, Path.GetFileName(Input.ogAnims[i])); } else { string gapFolder = Path.Combine(Input.retargetFolder, Path.GetFileName(Path.GetDirectoryName(Input.ogAnims[i]))); if (!Directory.Exists(gapFolder)) { Directory.CreateDirectory(gapFolder); } newDestination = Path.Combine(gapFolder, Path.GetFileName(Input.ogAnims[i])); } for (int x = 0; x < Input.newAnims.Length; x++) { //If filenames match except for character ID, replace new animation with old one string renamedNewAnim = Path.GetFileName(Input.newAnims[x]).Replace(Path.GetFileName(Options.New), Path.GetFileName(Options.Old)); if (Path.GetFileName(Input.ogAnims[i]) == renamedNewAnim) { foundMatch = true; //Delete new gap if it exists if (File.Exists(newDestination)) { File.Delete(newDestination); } if (Options.GAP.Replace) { //Copy gap to new location File.Copy(Input.newAnims[x], newDestination); Console.WriteLine($"Copying {Path.GetFileName(Input.newAnims[x])} to replace {Path.GetFileName(Input.ogAnims[i])}"); } else if (Options.GAP.Retarget) { //Save new retargeted gap var animationPack = Resource.Load <AnimationPack>(Input.ogAnims[i]); animationPack.Retarget(ogCharDefaultModel.Model, newCharDefaultModel.Model, Options.GAP.FixArms); animationPack.Save(newDestination); Console.WriteLine($"Retargeting {Path.GetFileName(Input.ogAnims[i])} comparing {Path.GetFileName(Input.ogDefaultModel)} to {Path.GetFileName(Input.newDefaultModel)}"); } } } if (!foundMatch && Options.GAP.Retarget) { //Delete new gap if it exists if (File.Exists(newDestination)) { File.Delete(newDestination); } //Save new retargeted gap var animationPack = Resource.Load <AnimationPack>(Input.ogAnims[i]); animationPack.Retarget(ogCharDefaultModel.Model, newCharDefaultModel.Model, Options.GAP.FixArms); animationPack.Save(newDestination); Console.WriteLine($"Retargeting {Path.GetFileName(Input.ogDefaultModel)} to {Path.GetFileName(Input.ogAnims[i])}"); } } }
private void copyP5SplitGAPToMultipleModelsInDirectoryToolStripMenuItem_Click(object sender, EventArgs e) { var aGap = ModuleImportUtilities.SelectImportFile <AnimationPack>("Select the gap file ending with a."); if (aGap == null) { return; } var bGap = ModuleImportUtilities.SelectImportFile <AnimationPack>("Select the gap file ending with b."); if (bGap == null) { return; } var cGap = ModuleImportUtilities.SelectImportFile <AnimationPack>("Select the gap file ending with c."); if (cGap == null) { return; } bool isGAP52 = MessageBox.Show("GAP ID 52? If unsure, select No.", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes; string directoryPath; var browserDialog = new VistaFolderBrowserDialog(); { browserDialog.Description = "Select a directory containing Model files, or subdirectories containing model files to make the new GAP files for.\n" + "Note that this will replace the original files."; if (browserDialog.ShowDialog() != true) { return; } directoryPath = browserDialog.SelectedPath; } var failures = new ConcurrentBag <string>(); string GAP_ID = "_051_"; if (isGAP52) { GAP_ID = "_052_"; } var filePaths = Directory.EnumerateFiles(directoryPath, "*.GMD", SearchOption.AllDirectories).ToList(); foreach (string filePath in filePaths) { var targetCharID = Path.GetFileName(filePath).Split("_")[0].Remove(0, 1); // get character ID from model var targetGAPname = Path.GetFileName(filePath).Split("_")[1]; // get model ID from model var targetGAPDir = Path.Join(Path.GetDirectoryName(filePath), "battle"); // directory of model try { var targetModel = ModuleImportUtilities.ImportFile <ModelPack>(filePath)?.Model; if (targetModel == null) { return; } aGap.FixTargetIds(targetModel); aGap.Save(Path.Join(targetGAPDir, "bb" + targetCharID + GAP_ID + targetGAPname + "a.GAP")); bGap.FixTargetIds(targetModel); bGap.Save(Path.Join(targetGAPDir, "bb" + targetCharID + GAP_ID + targetGAPname + "b.GAP")); cGap.FixTargetIds(targetModel); cGap.Save(Path.Join(targetGAPDir, "bb" + targetCharID + GAP_ID + targetGAPname + "c.GAP")); } catch (Exception) { failures.Add(filePath); } } if (failures.Count > 0) { MessageBox.Show("An error occured while processing the following files:\n" + string.Join("\n", failures)); } else { MessageBox.Show("All split GAPs successfully generated!"); } }
protected override void Initialize() { AddImportHandler <Texture>(filePath => { var texture = TextureEncoder.EncodeFromFile(filePath, TextureFormat.Unknown, Parent.FindParent <SpriteSetNode>() == null); { texture.Name = Path.GetFileNameWithoutExtension(filePath); texture.Id = MurmurHash.Calculate(texture.Name); } Data.Textures.Add(texture); }); AddExportHandler <TextureSet>(filePath => Data.Save(filePath)); AddReplaceHandler <TextureSet>(BinaryFile.Load <TextureSet>); AddCustomHandler("Export All", () => { string filePath = ModuleExportUtilities.SelectModuleExport <Texture>( "Select a folder to export textures to.", "Enter into a directory and press Save"); if (string.IsNullOrEmpty(filePath)) { return; } string directoryPath = Path.GetDirectoryName(filePath); string extension = Path.GetExtension(filePath).Trim('.'); foreach (var texture in Data.Textures) { TextureDecoder.DecodeToFile(texture, Path.Combine(directoryPath, $"{texture.Name}.{extension}")); } }, Keys.Control | Keys.Shift | Keys.E); AddCustomHandler("Export All (Flipped)", () => { string filePath = ModuleExportUtilities.SelectModuleExport <Bitmap>( "Select a folder to export textures to.", "Enter into a directory and press Save"); if (string.IsNullOrEmpty(filePath)) { return; } string directoryPath = Path.GetDirectoryName(filePath); string extension = Path.GetExtension(filePath).Trim('.'); foreach (var texture in Data.Textures) { using (var bitmap = TextureDecoder.DecodeToBitmap(texture)) { bitmap.RotateFlip(RotateFlipType.Rotate180FlipX); bitmap.Save(Path.Combine(directoryPath, $"{texture.Name}.{extension}")); } } }); AddCustomHandlerSeparator(); AddDirtyCustomHandler("Replace All", () => { var fileNames = ModuleImportUtilities.SelectModuleImportMultiselect <Texture>(); if (fileNames == null) { return(false); } bool any = false; foreach (string fileName in fileNames) { string textureName = Path.GetFileNameWithoutExtension(fileName); int textureIndex = Data.Textures.FindIndex(x => x.Name.Equals(textureName, StringComparison.OrdinalIgnoreCase)); if (textureIndex == -1) { continue; } any = true; var texture = Data.Textures[textureIndex]; var newTexture = TextureEncoder.EncodeFromFile(fileName, texture.IsYCbCr ? TextureFormat.RGBA8 : texture.Format, texture.MipMapCount != 1); newTexture.Name = texture.Name; newTexture.Id = texture.Id; Data.Textures[textureIndex] = newTexture; } return(any); }, Keys.Control | Keys.Shift | Keys.R, CustomHandlerFlags.Repopulate | CustomHandlerFlags.ClearMementos); AddDirtyCustomHandler("Replace All (Flipped)", () => { var fileNames = ModuleImportUtilities.SelectModuleImportMultiselect <Bitmap>(); if (fileNames == null) { return(false); } bool any = false; foreach (string fileName in fileNames) { // Boy do I love duplicate code C: string textureName = Path.GetFileNameWithoutExtension(fileName); int textureIndex = Data.Textures.FindIndex(x => x.Name.Equals(textureName, StringComparison.OrdinalIgnoreCase)); if (textureIndex == -1) { continue; } any = true; var texture = Data.Textures[textureIndex]; Texture newTexture; using (var bitmap = new Bitmap(fileName)) { bitmap.RotateFlip(RotateFlipType.Rotate180FlipX); newTexture = TextureEncoder.EncodeFromBitmap(bitmap, texture.IsYCbCr ? TextureFormat.RGBA8 : texture.Format, texture.MipMapCount != 1); } newTexture.Name = texture.Name; newTexture.Id = texture.Id; Data.Textures[textureIndex] = newTexture; } return(any); }, Keys.None, CustomHandlerFlags.Repopulate | CustomHandlerFlags.ClearMementos); base.Initialize(); }