From 2a16de6740d5552d41830436100ebb5b07344447 Mon Sep 17 00:00:00 2001 From: ShrineFoxMods Date: Fri, 5 Apr 2024 17:15:24 -0400 Subject: [PATCH] Fix "overwrite" extension, browse for .exe on launch - Fixes output extension always being .msg when decompiling with "overwrite" setting enabled - Prompts you for your AtlusScriptCompiler.exe path if the one in the Config.json isn't found - Added option to inject .msg into existing .bf (skips recompiling .BF to edit message data) --- AtlusScriptGUI.csproj | 4 ++++ AtlusScriptGUI.sln | 6 +++++ Events.cs | 45 +++++++++++++++++++++++++++++++++++++- Forms/MainForm.Designer.cs | 22 ++++++++++++++----- Forms/MainForm.cs | 4 +++- GUI.cs | 16 +++++++++++++- 6 files changed, 88 insertions(+), 9 deletions(-) diff --git a/AtlusScriptGUI.csproj b/AtlusScriptGUI.csproj index 58aaf2b..e2bcca9 100644 --- a/AtlusScriptGUI.csproj +++ b/AtlusScriptGUI.csproj @@ -112,6 +112,10 @@ + + {62ee486f-ae33-4dbb-ac4c-409a22cb04ad} + AtlusScriptLibrary + {7640412a-7372-4925-b20c-0178d8818a8f} ShrineFox.IO diff --git a/AtlusScriptGUI.sln b/AtlusScriptGUI.sln index f720cd8..a72091d 100644 --- a/AtlusScriptGUI.sln +++ b/AtlusScriptGUI.sln @@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AtlusScriptGUI", "AtlusScri EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShrineFox.IO", "..\ShrineFox.IO\ShrineFox.IO.csproj", "{7640412A-7372-4925-B20C-0178D8818A8F}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AtlusScriptLibrary", "..\Atlus-Script-Tools\Source\AtlusScriptLibrary\AtlusScriptLibrary.csproj", "{62EE486F-AE33-4DBB-AC4C-409A22CB04AD}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ Global {7640412A-7372-4925-B20C-0178D8818A8F}.Debug|Any CPU.Build.0 = Debug|Any CPU {7640412A-7372-4925-B20C-0178D8818A8F}.Release|Any CPU.ActiveCfg = Release|Any CPU {7640412A-7372-4925-B20C-0178D8818A8F}.Release|Any CPU.Build.0 = Release|Any CPU + {62EE486F-AE33-4DBB-AC4C-409A22CB04AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {62EE486F-AE33-4DBB-AC4C-409A22CB04AD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {62EE486F-AE33-4DBB-AC4C-409A22CB04AD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {62EE486F-AE33-4DBB-AC4C-409A22CB04AD}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Events.cs b/Events.cs index a796933..16bbdd1 100644 --- a/Events.cs +++ b/Events.cs @@ -1,4 +1,10 @@ -using MetroSet_UI.Forms; +using AtlusScriptLibrary.Common.Libraries; +using AtlusScriptLibrary.Common.Logging; +using AtlusScriptLibrary.Common.Text.Encodings; +using AtlusScriptLibrary.FlowScriptLanguage; +using AtlusScriptLibrary.MessageScriptLanguage.Compiler; +using AtlusScriptLibrary.MessageScriptLanguage; +using MetroSet_UI.Forms; using ShrineFox.IO; using System; using System.Collections; @@ -123,5 +129,42 @@ private void ToggleTheme_Click(object sender, EventArgs e) ToggleTheme(); ApplyTheme(); } + + private void InjectMSG_Click(object sender, EventArgs e) + { + string bfPath = ""; + string msgPath = ""; + var bfSelect = ShrineFox.IO.WinFormsDialogs.SelectFile("Choose Original BF File", false, new string[] { "Flowscript Binary (.BF)" }); + if (bfSelect.Count <= 0 || string.IsNullOrEmpty(bfSelect.First())) + return; + else + bfPath = bfSelect.FirstOrDefault(); + var msgSelect = ShrineFox.IO.WinFormsDialogs.SelectFile("Choose File To Inject", false, new string[] { "Messagescript Text (.MSG)", "Messagescript Binary (.BMD)" }); + if (msgSelect.Count <= 0 || string.IsNullOrEmpty(msgSelect.First())) + return; + else + msgPath = msgSelect.FirstOrDefault(); + + FlowScript flowScript = FlowScript.FromFile(bfPath, AtlusEncoding.GetByName(comboBox_Encoding.SelectedItem.ToString())); + MessageScript messageScript; + + if (Path.GetExtension(msgPath).ToLower() == ".bmd") + messageScript = MessageScript.FromFile(msgPath, AtlusScriptLibrary.MessageScriptLanguage.FormatVersion.Version1BigEndian, AtlusEncoding.GetByName(comboBox_Encoding.SelectedItem.ToString())); + else + using (FileStream fileStream = File.OpenRead(msgPath)) + { + MessageScriptCompiler messageScriptCompiler = new MessageScriptCompiler( + AtlusScriptLibrary.MessageScriptLanguage.FormatVersion.Version1BigEndian, AtlusEncoding.GetByName(comboBox_Encoding.SelectedItem.ToString())); + messageScriptCompiler.AddListener(new ConsoleLogListener(true, LogLevel.Info | LogLevel.Warning + | LogLevel.Error | LogLevel.Fatal)); + messageScriptCompiler.Library = LibraryLookup.GetLibrary("P5R"); + if (!messageScriptCompiler.TryCompile(fileStream, out messageScript)) + return; + } + flowScript.MessageScript = messageScript; + flowScript.ToFile(bfPath); + MessageBox.Show("Done injecting message into .BF!"); + } + } } diff --git a/Forms/MainForm.Designer.cs b/Forms/MainForm.Designer.cs index 52434f7..abab331 100644 --- a/Forms/MainForm.Designer.cs +++ b/Forms/MainForm.Designer.cs @@ -59,6 +59,7 @@ private void InitializeComponent() this.groupBox_BitFlagConverter = new System.Windows.Forms.GroupBox(); this.tlp_BitFlagConverter = new System.Windows.Forms.TableLayoutPanel(); this.rtb_Log = new System.Windows.Forms.RichTextBox(); + this.injectMSGIntoBFToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip_Main.SuspendLayout(); this.tlp_Main.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer_Log)).BeginInit(); @@ -213,7 +214,8 @@ private void InitializeComponent() this.chk_Disassemble, this.chk_Overwrite, this.chk_SumBits, - this.chk_DeleteHeader}); + this.chk_DeleteHeader, + this.injectMSGIntoBFToolStripMenuItem}); this.optionsToolStripMenuItem.Name = "optionsToolStripMenuItem"; this.optionsToolStripMenuItem.Size = new System.Drawing.Size(75, 24); this.optionsToolStripMenuItem.Text = "Options"; @@ -225,7 +227,7 @@ private void InitializeComponent() this.chk_Hook.CheckState = System.Windows.Forms.CheckState.Checked; this.chk_Hook.Enabled = false; this.chk_Hook.Name = "chk_Hook"; - this.chk_Hook.Size = new System.Drawing.Size(198, 26); + this.chk_Hook.Size = new System.Drawing.Size(228, 26); this.chk_Hook.Text = "Enable Hooking"; this.chk_Hook.CheckedChanged += new System.EventHandler(this.Check_Changed); // @@ -234,7 +236,7 @@ private void InitializeComponent() this.chk_Disassemble.CheckOnClick = true; this.chk_Disassemble.Enabled = false; this.chk_Disassemble.Name = "chk_Disassemble"; - this.chk_Disassemble.Size = new System.Drawing.Size(198, 26); + this.chk_Disassemble.Size = new System.Drawing.Size(228, 26); this.chk_Disassemble.Text = "Disassemble"; this.chk_Disassemble.CheckedChanged += new System.EventHandler(this.Check_Changed); // @@ -243,7 +245,7 @@ private void InitializeComponent() this.chk_Overwrite.CheckOnClick = true; this.chk_Overwrite.Enabled = false; this.chk_Overwrite.Name = "chk_Overwrite"; - this.chk_Overwrite.Size = new System.Drawing.Size(198, 26); + this.chk_Overwrite.Size = new System.Drawing.Size(228, 26); this.chk_Overwrite.Text = "Overwrite"; this.chk_Overwrite.CheckedChanged += new System.EventHandler(this.Check_Changed); // @@ -254,7 +256,7 @@ private void InitializeComponent() this.chk_SumBits.CheckState = System.Windows.Forms.CheckState.Checked; this.chk_SumBits.Enabled = false; this.chk_SumBits.Name = "chk_SumBits"; - this.chk_SumBits.Size = new System.Drawing.Size(198, 26); + this.chk_SumBits.Size = new System.Drawing.Size(228, 26); this.chk_SumBits.Text = "Sum Bits"; this.chk_SumBits.CheckedChanged += new System.EventHandler(this.Check_Changed); // @@ -263,7 +265,7 @@ private void InitializeComponent() this.chk_DeleteHeader.CheckOnClick = true; this.chk_DeleteHeader.Enabled = false; this.chk_DeleteHeader.Name = "chk_DeleteHeader"; - this.chk_DeleteHeader.Size = new System.Drawing.Size(198, 26); + this.chk_DeleteHeader.Size = new System.Drawing.Size(228, 26); this.chk_DeleteHeader.Text = "Delete .h"; this.chk_DeleteHeader.CheckedChanged += new System.EventHandler(this.Check_Changed); // @@ -361,6 +363,13 @@ private void InitializeComponent() this.rtb_Log.TabIndex = 0; this.rtb_Log.Text = ""; // + // injectMSGIntoBFToolStripMenuItem + // + this.injectMSGIntoBFToolStripMenuItem.Name = "injectMSGIntoBFToolStripMenuItem"; + this.injectMSGIntoBFToolStripMenuItem.Size = new System.Drawing.Size(228, 26); + this.injectMSGIntoBFToolStripMenuItem.Text = "Inject .MSG into .BF..."; + this.injectMSGIntoBFToolStripMenuItem.Click += new System.EventHandler(this.InjectMSG_Click); + // // MainForm // this.AllowDrop = true; @@ -428,6 +437,7 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripMenuItem encodingToolStripMenuItem; private System.Windows.Forms.ToolStripComboBox comboBox_Encoding; private System.Windows.Forms.ToolStripMenuItem defaultEncodingToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem injectMSGIntoBFToolStripMenuItem; } } diff --git a/Forms/MainForm.cs b/Forms/MainForm.cs index 0336f20..4520226 100644 --- a/Forms/MainForm.cs +++ b/Forms/MainForm.cs @@ -3,6 +3,7 @@ using ShrineFox.IO; using System; using System.IO; +using System.Linq; using System.Text; using System.Threading; using System.Windows.Forms; @@ -11,7 +12,7 @@ namespace AtlusScriptGUI { public partial class MainForm : MetroSetForm { - public static Version version = new Version(3, 2); + public static Version version = new Version(3, 3); public Config settings = new Config(); public string CompilerPath { get; set; } = "./AtlusScriptCompiler.exe"; @@ -31,5 +32,6 @@ public MainForm(string[] args) this.Text += $" v{version.Major}.{version.Minor}"; } + } } diff --git a/GUI.cs b/GUI.cs index 82c0f94..7939c74 100644 --- a/GUI.cs +++ b/GUI.cs @@ -64,6 +64,17 @@ private void SetCompilerPath(string[] args) CompilerPath = Path.GetFullPath(args[0]); else CompilerPath = settings.CompilerPath; + + while (!File.Exists(CompilerPath)) + { + var fileSelect = WinFormsDialogs.SelectFile("Select your AtlusScriptCompiler.exe", false, new string[] { "Executable File (.exe)" }); + if (fileSelect.Count > 0 && File.Exists(fileSelect.First())) + { + CompilerPath = fileSelect.First(); + settings.CompilerPath = CompilerPath; + settings.SaveJson(settings); + } + } } private void SetDropDowns() @@ -300,7 +311,10 @@ private string GetArguments(string droppedFilePath, string extension, string com else if (compileArg == "-Decompile " && settings.Overwrite) { string outPath = droppedFilePath.Replace(".bmd", "").Replace(".BMD", ""); - args.Append($"-Out \"{outPath + ".msg"}\" "); + if (extension == ".BF") + args.Append($"-Out \"{outPath + ".flow"}\" "); + else if (extension == ".BMD") + args.Append($"-Out \"{outPath + ".msg"}\" "); } }