Skip to content

Commit

Permalink
Fix "overwrite" extension, browse for .exe on launch
Browse files Browse the repository at this point in the history
- 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)
  • Loading branch information
ShrineFox committed Apr 5, 2024
1 parent 14777fc commit 2a16de6
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 9 deletions.
4 changes: 4 additions & 0 deletions AtlusScriptGUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@
<Folder Include="Properties\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Atlus-Script-Tools\Source\AtlusScriptLibrary\AtlusScriptLibrary.csproj">
<Project>{62ee486f-ae33-4dbb-ac4c-409a22cb04ad}</Project>
<Name>AtlusScriptLibrary</Name>
</ProjectReference>
<ProjectReference Include="..\ShrineFox.IO\ShrineFox.IO.csproj">
<Project>{7640412a-7372-4925-b20c-0178d8818a8f}</Project>
<Name>ShrineFox.IO</Name>
Expand Down
6 changes: 6 additions & 0 deletions AtlusScriptGUI.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
45 changes: 44 additions & 1 deletion Events.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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!");
}

}
}
22 changes: 16 additions & 6 deletions Forms/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";

Expand All @@ -31,5 +32,6 @@ public MainForm(string[] args)

this.Text += $" v{version.Major}.{version.Minor}";
}

}
}
16 changes: 15 additions & 1 deletion GUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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"}\" ");
}
}

Expand Down

0 comments on commit 2a16de6

Please sign in to comment.