-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathEvents.cs
186 lines (159 loc) · 6.5 KB
/
Events.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
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.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace AtlusScriptGUI
{
public partial class MainForm : MetroSetForm
{
private void Btn_Click(object sender, EventArgs e)
{
if (!File.Exists(CompilerPath))
RunUpdater();
var btn = (Button)sender;
bool decompile = btn.Name.Contains("Decompile");
string browseWindowTitle = "Choose .MSG/.FLOW to Compile";
if (decompile)
browseWindowTitle = "Choose .BMD/.BF to Decompile";
var files = WinFormsDialogs.SelectFile(browseWindowTitle, true);
Compile(files.ToArray(), decompile);
}
private void Btn_DragDrop(object sender, DragEventArgs e)
{
if (!File.Exists(CompilerPath))
RunUpdater();
var btn = (Button)sender;
string[] fileList = (string[])e.Data.GetData(DataFormats.FileDrop, false);
Compile(fileList, btn.Name.Contains("Decompile"));
}
private void Btn_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Move;
}
private void OpenLog_Click(object sender, EventArgs e)
{
OpenLog();
}
private void Game_Changed(object sender, EventArgs e)
{
settings.Game = comboBox_Game.SelectedItem.ToString();
settings.SaveJson(settings);
SetEncodingDropDown();
}
private void Encoding_Changed(object sender, EventArgs e)
{
if (!comboBox_Encoding.Enabled)
return;
settings.Encoding = comboBox_Encoding.SelectedItem.ToString();
settings.SaveJson(settings);
var encoding = GetSelectedEncoding();
Output.Log(encoding.EncodingName);
}
private void VanillaText_Changed(object sender, EventArgs e)
{
try
{
string result = ConvertVanillaFlag(txtBox_Vanilla.Text);
if (result != "-1")
txtBox_Royal.Text = result;
else
txtBox_Royal.Text = txtBox_Vanilla.Text;
}
catch
{
txtBox_Royal.Text = "Out of Range";
}
}
private void RoyalText_Changed(object sender, EventArgs e)
{
try
{
string result = ConvertRoyalFlag(txtBox_Royal.Text);
if (result != "-1")
txtBox_Vanilla.Text = result;
else
txtBox_Vanilla.Text = txtBox_Royal.Text;
}
catch
{
txtBox_Vanilla.Text = "Out of Range";
}
}
private void Check_Changed(object sender, EventArgs e)
{
var item = (ToolStripMenuItem)sender;
if (!item.Enabled)
return;
settings.CompilerLogOutput = chk_CompilerLogOutput.Checked;
settings.DeleteHeader = chk_DeleteHeader.Checked;
settings.Disassemble = chk_Disassemble.Checked;
settings.Hook = chk_Hook.Checked;
settings.Overwrite = chk_Overwrite.Checked;
settings.SumBits = chk_SumBits.Checked;
settings.BigEndianFlow = chk_BigEndianFlowP3RE.Checked;
settings.SaveJson(settings);
}
private void ToggleTheme_Click(object sender, EventArgs e)
{
ToggleTheme();
ApplyTheme();
}
private void InjectMSG_Click(object sender, EventArgs e)
{
if (!File.Exists(CompilerPath))
RunUpdater();
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, GetSelectedEncoding());
MessageScript messageScript;
if (Path.GetExtension(msgPath).ToLower() == ".bmd")
messageScript = MessageScript.FromFile(msgPath, AtlusScriptLibrary.MessageScriptLanguage.FormatVersion.Version1BigEndian, GetSelectedEncoding());
else
using (FileStream fileStream = File.OpenRead(msgPath))
{
MessageScriptCompiler messageScriptCompiler = new MessageScriptCompiler(
AtlusScriptLibrary.MessageScriptLanguage.FormatVersion.Version1BigEndian, GetSelectedEncoding());
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!");
}
private Encoding GetSelectedEncoding()
{
return AtlusEncoding.GetEncodings().First(x => x.Name.Equals(comboBox_Encoding.SelectedItem.ToString())).GetEncoding();
}
private void UpdateCompiler_Click(object sender, EventArgs e)
{
RunUpdater();
}
private void RunUpdater()
{
Exe.Run(Path.Combine(Exe.Directory(), "Updater/AtlusScriptToolsUpdater.exe"), Exe.Directory(), false, "", false, false);
Environment.Exit(0);
}
}
}