-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathGUI.cs
462 lines (418 loc) · 19.4 KB
/
GUI.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
using MetroSet_UI.Forms;
using ShrineFox.IO;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
namespace AtlusScriptGUI
{
public partial class MainForm : MetroSetForm
{
public static string CompilerPath = Path.Combine(Exe.Directory(), "AtlusScriptCompiler.exe");
public static List<string> GamesList = new List<string>()
{
"SMT 3 Nocturne",
"SMT Digital Devil Saga",
"Persona 3 Portable",
"Persona 3",
"Persona 3 FES",
"Persona 3 Reload",
"Persona 4",
"Persona 4 Golden",
"Persona 5",
"Persona 5 Royal (PS4)",
"Persona 5 Royal (PC/Switch)",
"Persona Q2",
"Catherine Classic",
"Catherine Full-Body",
};
private void ApplyCheckboxStates()
{
chk_CompilerLogOutput.Checked = settings.CompilerLogOutput;
chk_DeleteHeader.Checked = settings.DeleteHeader;
chk_Disassemble.Checked = settings.Disassemble;
chk_Hook.Checked = settings.Hook;
chk_Overwrite.Checked = settings.Overwrite;
chk_SumBits.Checked = settings.SumBits;
chk_BigEndianFlowP3RE.Checked = settings.BigEndianFlow;
EnableCheckboxes();
}
private void EnableCheckboxes()
{
chk_CompilerLogOutput.Enabled = true;
chk_DeleteHeader.Enabled = true;
chk_Disassemble.Enabled = true;
chk_Hook.Enabled = true;
chk_Overwrite.Enabled = true;
chk_SumBits.Enabled = true;
chk_BigEndianFlowP3RE.Enabled = true;
}
private void SetLogging()
{
Output.Logging = true;
Output.LogControl = rtb_Log;
}
private void SetDropDowns()
{
SetGameDropDown();
SetEncodingDropDown();
}
private void SetGameDropDown()
{
foreach (var game in GamesList)
comboBox_Game.Items.Add(game);
comboBox_Game.SelectedIndex = comboBox_Game.Items.IndexOf(settings.Game);
}
private void SetEncodingDropDown()
{
comboBox_Encoding.Enabled = false;
comboBox_Encoding.Items.Clear();
// Hide encoding options and display text saying default option will be used
comboBox_Encoding.Visible = false;
defaultEncodingToolStripMenuItem.Visible = true;
// Show encoding dropdown if there are optional encodings, select commonly used default
switch (settings.Game)
{
case "Persona 3 Portable":
foreach (var encoding in new string[] { "P3", "P3P_EFIGS" })
comboBox_Encoding.Items.Add(encoding);
comboBox_Encoding.SelectedIndex = 0;
comboBox_Encoding.Visible = true;
defaultEncodingToolStripMenuItem.Visible = false;
break;
case "Persona 5":
// Populate comboBox options with all available AtlusEncodings
foreach (var encoding in new string[] { "P5", "P5_Chinese" })
comboBox_Encoding.Items.Add(encoding);
comboBox_Encoding.SelectedIndex = comboBox_Encoding.Items.IndexOf("P5");
comboBox_Encoding.Visible = true;
defaultEncodingToolStripMenuItem.Visible = false;
break;
case "Persona 5 Royal (PS4)":
foreach (var encoding in new string[] { "P5", "P5_Chinese" })
comboBox_Encoding.Items.Add(encoding);
comboBox_Encoding.SelectedIndex = 0;
comboBox_Encoding.Visible = true;
defaultEncodingToolStripMenuItem.Visible = false;
break;
case "Persona 5 Royal (PC/Switch)":
// Populate comboBox options with all available AtlusEncodings
foreach (var encoding in new string[] { "P5R_EFIGS", "P5R_Japanese", "P5R_Chinese" })
comboBox_Encoding.Items.Add(encoding);
comboBox_Encoding.SelectedIndex = comboBox_Encoding.Items.IndexOf("P5R_EFIGS");
comboBox_Encoding.Visible = true;
defaultEncodingToolStripMenuItem.Visible = false;
break;
default:
comboBox_Encoding.Items.Add("P3");
comboBox_Encoding.SelectedIndex = 0;
break;
}
// Select previous setting if it's still in the list
foreach (var item in comboBox_Encoding.Items)
if (item.ToString() == settings.Encoding)
comboBox_Encoding.SelectedIndex = comboBox_Encoding.Items.IndexOf(item);
comboBox_Encoding.Enabled = true;
// Save selected encoding to config
settings.Encoding = comboBox_Encoding.SelectedItem.ToString();
settings.SaveJson(settings);
}
public void Compile(string[] fileList, bool decompile = false)
{
rtb_Log.Clear();
new Thread(() =>
{
string args = "";
for (int i = 0; i < fileList.Count(); i++)
{
string ext = Path.GetExtension(fileList[i]).ToUpper();
if (!decompile && (ext == ".MSG" || ext == ".FLOW"))
args = GetArguments(fileList[i], ext, "-Compile ");
else if (decompile && (ext == ".BMD" || ext == ".BF" || ext == ".UASSET"))
args = GetArguments(fileList[i], ext, "-Decompile ");
else
return;
bool success = Exe.Run(Path.GetFullPath(CompilerPath), args, redirectStdOut: settings.CompilerLogOutput);
if (success)
{
Output.Log("Task Succeeded!", ConsoleColor.Green);
ProcessUassetOutput(fileList[i], decompile);
DeleteHeaderFiles(fileList[i]);
}
else
Output.Log("Task Failed.", ConsoleColor.Red);
}
}).Start();
}
private void ProcessUassetOutput(string file, bool decompile)
{
if (settings.Game != "Persona 3 Reload" || !settings.Overwrite)
return;
if (decompile && Path.GetExtension(file).ToUpper() == ".UASSET")
{
string bfFile = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + "_unwrapped.bf");
string bmdFile = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + "_unwrapped.bmd");
string flowFile = bfFile + ".flow";
string msgFile = bmdFile + ".msg";
string newFlowDest = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + ".flow");
string newMsgDest = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + ".msg");
string hFile = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + "_unwrapped.bmd.msg.h");
string newHFileDest = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + ".msg.h");
if (File.Exists(bfFile))
File.Delete(bfFile);
if (File.Exists(bmdFile))
File.Delete(bmdFile);
if (File.Exists(newFlowDest))
File.Delete(newFlowDest);
if (File.Exists(newMsgDest))
File.Delete(newMsgDest);
if (File.Exists(newHFileDest))
File.Delete(newHFileDest);
if (File.Exists(flowFile))
File.Move(flowFile, newFlowDest);
if (File.Exists(msgFile))
File.Move(msgFile, newMsgDest);
if (File.Exists(hFile))
File.Move(hFile, newHFileDest);
}
else
{
string extension = ".bf";
if (Path.GetFileName(file).ToLower().Contains("bmd"))
extension = ".bmd";
string scriptFile = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + extension);
string uassetFile = scriptFile + ".uasset";
string newUassetDest = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + ".uasset");
if (File.Exists(scriptFile))
File.Delete(scriptFile);
if (File.Exists(newUassetDest))
File.Delete(newUassetDest);
if (File.Exists(uassetFile))
File.Move(uassetFile, newUassetDest);
}
}
private void DeleteHeaderFiles(string file)
{
if (!settings.DeleteHeader)
return;
if (Path.GetExtension(file).ToUpper() == ".BMD")
{
string headerFile = file + ".msg.h";
if (settings.Overwrite)
headerFile = FileSys.GetExtensionlessPath(file) + ".msg.h";
if (File.Exists(headerFile))
File.Delete(headerFile);
}
else if (Path.GetExtension(file).ToUpper() == ".UASSET" && Path.GetFileName(file).ToLower().Contains("bmd"))
{
string headerFile = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + "_unwrapped.bmd.msg.h");
if (settings.Overwrite)
headerFile = FileSys.GetExtensionlessPath(file) + ".msg.h";
if (File.Exists(headerFile))
File.Delete(headerFile);
}
}
private string GetArguments(string inputFile, string extension, string compileArg)
{
string encodingArg = "";
string libraryArg = "";
string outFormatArg = "";
encodingArg = $"-Encoding {settings.Encoding}";
switch (settings.Game)
{
case "SMT 3 Nocturne":
encodingArg = "-Encoding P3";
libraryArg = "-Library SMT3";
if (extension == ".MSG")
outFormatArg = "-OutFormat V1";
if (extension == ".FLOW")
outFormatArg = "-OutFormat V1";
break;
case "SMT Digital Devil Saga":
encodingArg = "-Encoding P3";
libraryArg = "-Library DDS";
if (extension == ".MSG")
outFormatArg = "-OutFormat V1DDS";
if (extension == ".FLOW")
outFormatArg = "-OutFormat V1DDS";
break;
case "Persona 3 Portable":
//encodingArg = "-Encoding P3";
libraryArg = "-Library P3P";
if (extension == ".MSG" || extension == ".FLOW")
outFormatArg = "-OutFormat V1";
break;
case "Persona 3":
encodingArg = "-Encoding P3";
libraryArg = "-Library P3";
if (extension == ".MSG" || extension == ".FLOW")
outFormatArg = "-OutFormat V1";
break;
case "Persona 3 FES":
encodingArg = "-Encoding P3";
libraryArg = "-Library P3F";
if (extension == ".MSG" || extension == ".FLOW")
outFormatArg = "-OutFormat V1";
break;
case "Persona 3 Reload":
encodingArg = "-Encoding UT";
libraryArg = "-Library P3RE";
// OutFormat
if (extension == ".MSG" || extension == ".FLOW")
{
if (extension == ".MSG")
outFormatArg = "-OutFormat V1RE";
else if (extension == ".FLOW")
{
if (settings.BigEndianFlow)
outFormatArg = "-OutFormat V4BE";
else
outFormatArg = "-OutFormat V4";
}
}
else if (Path.GetFileName(inputFile).ToLowerInvariant().Contains("bmd"))
outFormatArg = "-InFormat MessageScriptBinary -OutFormat V1RE";
else if (Path.GetFileName(inputFile).ToLowerInvariant().Contains("bf"))
outFormatArg = "-InFormat FlowScriptBinary";
break;
case "Persona 4":
encodingArg = "-Encoding P4";
libraryArg = "-Library P4";
if (extension == ".MSG" || extension == ".FLOW")
outFormatArg = "-OutFormat V1";
break;
case "Persona 4 Golden":
encodingArg = "-Encoding P4";
libraryArg = "-Library P4G";
if (extension == ".MSG" || extension == ".FLOW")
outFormatArg = "-OutFormat V1";
break;
case "Persona 5":
//encodingArg = "-Encoding P5";
libraryArg = "-Library P5";
if (extension == ".MSG")
outFormatArg = "-OutFormat V1BE";
if (extension == ".FLOW")
outFormatArg = "-OutFormat V3BE";
break;
case "Persona 5 Royal (PS4)":
//encodingArg = "-Encoding P5";
libraryArg = "-Library P5R";
if (extension == ".MSG")
outFormatArg = "-OutFormat V1";
if (extension == ".FLOW")
outFormatArg = "-OutFormat V3BE";
break;
case "Persona 5 Royal (PC/Switch)":
//encodingArg = "-Encoding P5R_EFIGS";
//if (extension != ".BMD")
libraryArg = "-Library P5R";
if (extension == ".MSG")
outFormatArg = "-OutFormat V1BE";
if (extension == ".FLOW")
outFormatArg = "-OutFormat V3BE";
break;
case "Persona Q2":
encodingArg = "-Encoding SJ";
libraryArg = "-Library PQ2";
if (extension == ".MSG")
outFormatArg = "-OutFormat V1";
if (extension == ".FLOW")
outFormatArg = "-OutFormat V2";
break;
case "Catherine Classic":
encodingArg = "-Enconding CAT";
libraryArg = "-Library CAT";
if (extension == ".MSG")
outFormatArg = "-OutFormat V2BE";
if (extension == ".FLOW")
outFormatArg = "-OutFormat V2BE";
break;
case "Catherine Full-Body":
encodingArg = "-Enconding CFB";
libraryArg = "-Library CFB";
if (extension == ".MSG")
outFormatArg = "-OutFormat V2";
if (extension == ".FLOW")
outFormatArg = "-OutFormat V2";
break;
default:
break;
}
StringBuilder args = new StringBuilder();
args.Append($"\"{inputFile}\" ");
if (settings.Disassemble) //Omits all args if you are disassembling
args.Append($" -Disassemble");
else
{
args.Append($"{compileArg} ");
args.Append($"{outFormatArg} ");
args.Append($"{libraryArg} ");
args.Append($"{encodingArg} ");
if (settings.Hook)
args.Append(" -Hook ");
if (settings.SumBits)
args.Append(" -SumBits ");
if (compileArg == "-Compile " && File.Exists(Path.ChangeExtension(inputFile, ".uasset")))
{
args.Append("-UPatch \"" + Path.ChangeExtension(inputFile, ".uasset") + "\" ");
}
if (compileArg == "-Compile " && settings.Overwrite)
{
string outPath = inputFile.Replace(".flow", "")
.Replace(".FLOW", "").Replace(".msg", "").Replace(".MSG", "")
.Replace(".bf", "").Replace(".BF", "").Replace(".bmd", "")
.Replace(".BMD", "");
if (extension == ".MSG")
args.Append($"-Out \"{outPath + ".bmd"}\" ");
else if (extension == ".FLOW")
args.Append($"-Out \"{outPath + ".bf"}\" ");
}
else if (compileArg == "-Decompile " && settings.Overwrite)
{
string outPath = inputFile.Replace(".bmd", "").Replace(".BMD", "");
if (extension == ".BF")
args.Append($"-Out \"{outPath + ".flow"}\" ");
else if (extension == ".BMD")
args.Append($"-Out \"{outPath + ".msg"}\" ");
}
}
Output.Log(args.ToString(), ConsoleColor.Green);
return args.ToString();
}
public static string ConvertRoyalFlag(string text)
{
return Flag.ConvertToVanilla(Convert.ToInt32(text)).ToString();
}
public static string ConvertVanillaFlag(string text)
{
return Flag.ConvertToRoyal(Convert.ToInt32(text)).ToString();
}
public void OpenLog()
{
string logPath = Path.Combine(Path.GetDirectoryName(Path.GetFullPath(CompilerPath)), "AtlusScriptCompiler.log");
if (File.Exists(logPath))
Exe.Run(logPath);
}
private void ToggleTheme()
{
if (Theme.ThemeStyle == MetroSet_UI.Enums.Style.Light)
{
Theme.ThemeStyle = MetroSet_UI.Enums.Style.Dark;
settings.DarkMode = true;
}
else
{
Theme.ThemeStyle = MetroSet_UI.Enums.Style.Light;
settings.DarkMode = false;
}
settings.SaveJson(settings);
}
private void ApplyTheme()
{
Theme.ApplyToForm(this);
}
}
}