-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormFuncs.cs
More file actions
586 lines (464 loc) · 22.1 KB
/
Copy pathFormFuncs.cs
File metadata and controls
586 lines (464 loc) · 22.1 KB
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
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
using SimpleRIFF.Interfaces;
using SimpleRIFF.RIFF_Objects;
using SimpleRIFF.Streams;
#pragma warning disable CS8602
namespace FSB5BankParser
{
public partial class MainForm
{
#region Bank Loading Funcs
private void LoadFSB5Files()
{
using FolderBrowserDialog dialog = new();
dialog.Description = "Select Folder with FSB5 files";
dialog.UseDescriptionForTitle = true;
if (dialog.ShowDialog() == DialogResult.OK && !string.IsNullOrWhiteSpace(dialog.SelectedPath))
{
UnloadFSB5Files();
BankFolder = dialog.SelectedPath;
Console.WriteLine($"Selected Path: {BankFolder}" +
$"\nLoading Bank Files...");
// Get all files in the folder, and make sure that Master.strings.bank is loaded first
// (this is actually no longer needed, but i'll keep it anyways)
var FolderFiles = Directory.GetFiles(BankFolder, "*.bank")
.OrderByDescending(f => Path.GetFileName(f).Equals("Master.strings.bank", StringComparison.OrdinalIgnoreCase));
#region Idiot Proof Checks
if (Directory.GetFiles(BankFolder, "*.fsb").Length > 0)
{
// prevent user from using FSB4 files, since this tool obviously doesn't support that
Console.WriteLine("ERROR: Input is unsupported (FSB4)");
MessageBox.Show("FSB4 files (.fsb) are unsupported by this tool" +
"\nPlease use FSB5 files (.bank) instead", "Error");
BankFolder = string.Empty;
return;
}
if (!FolderFiles.Any())
{
// prevent user from using FSB4 files, since this tool obviously doesn't support that
Console.WriteLine("ERROR: No .bank files were found");
MessageBox.Show("No .bank files were found in the selected directory" +
"\nPlease check the selected directory and try again", "Error");
BankFolder = string.Empty;
return;
}
if (!File.Exists($"{BankFolder}/Master.strings.bank"))
{
Console.WriteLine("ERROR: Master.strings.bank is not present!");
MessageBox.Show("Master.strings.bank is not present!" +
"\nPlease ensure that it's within the selected folder", "Error");
BankFolder = string.Empty;
return;
}
#endregion
// Get Paths from Master.strings.bank
if (File.Exists($"{BankFolder}/Master.strings.bank"))
GetStringPaths($"{BankFolder}/Master.strings.bank");
// Load every bank file
foreach (string bankFilePath in FolderFiles)
{
var bankname = Path.GetFileName(bankFilePath);
using FileStream fs = new(bankFilePath, FileMode.Open, FileAccess.Read);
using (RIFFStream rs = new(fs))
{
// Create RIFF Object
RIFFObject? riffObject = new();
// Parse it
riffObject?.Read(rs);
rs.Close();
// Keep track of all RIFF Objects through these
BankFiles.Add(bankname);
RIFFObjects[bankname] = riffObject;
Console.WriteLine($"Loaded Bank: {bankname}");
}
fs.Close();
}
Console.WriteLine("Loading TreeView...");
LoadTreeView();
}
}
private void UnloadFSB5Files()
{
if (BankFiles.Count == 0) return; // if empty
Console.WriteLine("Unloading Bank Files...");
// Get every loaded RIFF Object and clear it
foreach (string bank in BankFiles)
{
RIFFObjects?[bank]?.Children.Clear();
Console.WriteLine($"Unloaded Bank File {bank}");
}
// Clear these vars
FMODSystem = new();
BankFolder = string.Empty;
OutputDir = string.Empty;
BankFiles = [];
RIFFObjects = [];
Console.WriteLine("Unloaded System Data");
ClearMasterGUIDs();
UnloadTreeView();
Console.WriteLine("Unloaded TreeView");
GC.Collect();
}
#endregion
#region TreeView
void LoadTreeView()
{
UnloadTreeView();
foreach (string bank in BankFiles)
{
// Get RIFF Object
RIFFObject? BankRIFF = RIFFObjects?[bank];
// Add Bank File to Tree
if (BankRIFF != null)
{
var BankNode = bankTreeView.Nodes.Add(bank);
BankNode.ToolTipText = getBankTooltip(bank);
addChildrenToNode(BankNode, BankRIFF, bank);
}
}
// because why not
GC.Collect();
Console.WriteLine($"Loaded TreeView");
return;
void addChildrenToNode(TreeNode node, IContainerChunk chunk, string bankfile)
{
foreach (IGenericChunk item in chunk.Children)
{
cCode = item.CharacterCode.Code;
ItemAsObj = item as RIFFGenericDataObject;
ItemAsList = item as RIFFListObject;
switch (cCode)
{
case "LIST": // Chunk is a List
var listType = ItemAsList.ListType;
string displayName = getFullNameFromNodeName(listType.Code) ?? $"{cCode} - TYPE: {listType}";
var newNode = node.Nodes.Add(displayName);
newNode.ToolTipText = getTooltipInfo(listType.Code);
addChildrenToNode(newNode, ItemAsList, bankfile);
CheckEmptyChunk(newNode);
break;
case "LCNT": // List Count Chunk Header (comes after LIST)
node.Nodes.Add($"List Count: ({BitConverter.ToInt32(ItemAsObj.Data)})");
break;
default: // Parse any other chunk
string DisplayName = getFullNameFromNodeName(cCode) ?? cCode;
// node stuffs
latestNode = node.Nodes.Add($"{DisplayName} - ({ItemAsObj.Data.Length})");
latestNode.ToolTipText = getTooltipInfo(cCode);
latestNode.Tag = ItemAsObj;
latestNode.ContextMenuStrip = blockContextMenuStrip;
// Parse Chunks and add chunk info to node
ParseChunk(item, bankfile);
CheckEmptyChunk(latestNode);
break;
}
// clean this shit
cCode = null;
ItemAsObj = null;
ItemAsList = null;
latestNode = null;
// thing to remove empty nodes
void CheckEmptyChunk(TreeNode newNode)
{
if (!ShowEmptyChunks && newNode.Nodes.Count == 0)
node.Nodes.Remove(newNode);
}
}
}
}
void UnloadTreeView() {
bankTreeView.Nodes.Clear();
}
#region Parse Chunk Resolver
void ParseChunk(IGenericChunk item, string bankfile)
{
switch (cCode)
{
// Sounds
case "SND ": ParseChunkSND($"{BankFolder}/{bankfile}"); break;
// Events
case "EVTB": ParseChunkEVTB(bankfile); break;
// Timelines
case "TLNB": ParseChunkTLNB(); break;
// Sound Modules (Point to Sound Files, used in Timelines and Action)
case "WAIB": ParseChunkWAIB(); break;
// SubChunk
case "INST": ParseChunkINST(); break;
// Action Only Chunk
// Replaces Timeline if Event is Action, and is connected to MUIB
case "PLST": ParseChunkPLST(); break;
// VCA's
case "VCAB": ParseChunkVCAB(); break;
// Parameters
case "PRMB": ParseChunkPRMB(); break;
// Properties (Can be used by different chunks)
case "PROP": ParseChunkPROP(item); break;
// Master.strings.bank only chunk
// Has ALL GUIDs and String Paths
case "STDT": ParseChunkSTDT(bankfile); break;
case "HASH": ParseChunkHASH(); break;
// Bank File Info Chunk
case "BNKI": ParseChunkBNKI(bankfile); break;
// MixerMaster
case "MBSB": ParseChunkMBSB(); break;
case "RBSB": // MixerReturn
case "IBSB": // MixerInput
case "GBSB": // MixerGroup
ParseMixerChunks();
break;
// Parameter Settings?
case "PMLB": ParseChunkPMLB(); break;
// idk needs research
case "CTRL": ParseChunkCTRL(); break;
// idk needs research
case "CURV": ParseChunkCURV(); break;
// Effects
case "BEFB": ParseChunkBEFB(); break;
// Snapshot
case "SNAB": ParseChunkSNAB(); break;
// Transitions
// basically markers and shit in timelines
case "TRNB": ParseChunkTRNB(); break;
// connects GBSB, MBSB, CURVs
case "TRTL": ParseChunkTRTL(); break;
// connects Transitions to CURV/CTRL (sometimes empty)
case "CTRO": ParseChunkCTRO(); break;
// Generic Buses idk
case "BUS ": ParseChunkBUS(); break;
// Modules
case "MODB": ParseChunkMODB(); break;
// Command
case "CMDB": ParseChunkCMDB(); break;
// Nested Events
case "EVIB": ParseChunkEVIB(); break;
// Chunks that just have their own GUID
// (although there might be unknown vals)
case "PLAT": ParseChunkPLAT(); break; // Platform
case "MUIB": // MultiSound (in action events)
case "WAV ": // Sound files
case "SLNB": // SilenceSound
case "MAP ": // Manages PROP GUIDs
case "SCEF": // idk
ParseChunkGeneric();
break;
}
}
#endregion
#region Node Name Strings
string? getFullNameFromNodeName(string nodeName)
{
return nodeName switch
{
"PROJ" => $"Project ({nodeName})",
"FMT " => $"Format ({nodeName})",
"BNKI" => $"Bank Info ({nodeName})",
"PRPS" => $"Properties ({nodeName})",
"PROP" => $"Property ({nodeName})",
"BUS " => $"Generic Bus ({nodeName})",
"GBSS" => $"MixerGroup Buses ({nodeName})",
"GBUS" => $"MixerGroup Bus ({nodeName})",
"GBSB" => $"MixerGroup Bus Binary ({nodeName})",
"RBSS" => $"MixerReturn Buses ({nodeName})",
"RBUS" => $"MixerReturn Bus ({nodeName})",
"RBSB" => $"MixerReturn Bus Binary ({nodeName})",
"MBSS" => $"MixerMaster Buses ({nodeName})",
"MBUS" => $"MixerMaster Bus ({nodeName})",
"MBSB" => $"MixerMaster Bus Binary ({nodeName})",
"IBSS" => $"MixerInput Buses ({nodeName})",
"IBUS" => $"MixerInput Bus ({nodeName})",
"IBSB" => $"MixerInput Bus Binary ({nodeName})",
"EVTS" => $"Events ({nodeName})",
"EVNT" => $"Event ({nodeName})",
"EVTB" => $"Event Binary ({nodeName})",
"EVIS" => $"Nested Events ({nodeName})",
"EVIT" => $"Nested Event ({nodeName})",
"EVIB" => $"Nested Event Binary ({nodeName})",
"TLNS" => $"Timelines ({nodeName})",
"TMLN" => $"Timeline ({nodeName})",
"TLNB" => $"Timeline Binary ({nodeName})",
"INST" => $"Timeline Instance ({nodeName})",
"TRNS" => $"Tranisitions ({nodeName})",
"TRAN" => $"Tranisition ({nodeName})",
"TRNB" => $"Tranisition Binary ({nodeName})",
"MUIS" => $"MultiSounds ({nodeName})",
"MUIT" => $"MultiSound ({nodeName})",
"MUIB" => $"MultiSound Binary ({nodeName})",
"PLST" => $"Sound List ({nodeName})",
"PRMS" => $"Parameters ({nodeName})",
"PARM" => $"Parameter ({nodeName})",
"PRMB" => $"Parameter Binary ({nodeName})",
"PMLS" => $"Event Parameters ({nodeName})",
"PMLO" => $"Event Parameter ({nodeName})",
"PMLB" => $"Event Parameter Binary ({nodeName})",
"CTRS" => $"Fade Curves ({nodeName})",
"CTRL" => $"Fade Curve ({nodeName})",
"CRVS" => $"Transition Curves ({nodeName})",
"CURV" => $"Transition Curve ({nodeName})",
"CMDS" => $"Commands ({nodeName})",
"CMDI" => $"Command ({nodeName})",
"CMDB" => $"Command Binary ({nodeName})",
"MODS" => $"Modules ({nodeName})",
"MODU" => $"Module ({nodeName})",
"MODB" => $"Module Binary ({nodeName})",
"BEFX" => $"Effects ({nodeName})",
"BEFF" => $"Effect ({nodeName})",
"BEFB" => $"Effect Binary ({nodeName})",
"WAVS" => $"WAV Files ({nodeName})",
"WAV " => $"WAV File ({nodeName})",
"WAIS" => $"WAV Instances ({nodeName})",
"WAIT" => $"WAV Instance ({nodeName})",
"WAIB" => $"WAV Instance Binary ({nodeName})",
"VCAS" => $"VCAs ({nodeName})",
"VCA " => $"VCA ({nodeName})",
"VCAB" => $"VCA Binary ({nodeName})",
"SNAS" => $"Snapshots ({nodeName})",
"SNAP" => $"Snapshot ({nodeName})",
"SNAB" => $"Snapshot Binary ({nodeName})",
"SLNS" => $"SilenceSounds ({nodeName})",
"SLNI" => $"SilenceSound ({nodeName})",
"SLNB" => $"SilenceSound Binary ({nodeName})",
"MPGS" => $"Managed Properties ({nodeName})",
"MAP " => $"Managed Property ({nodeName})",
"HASH" => $"Hash ({nodeName})",
"SND " => $"Sound ({nodeName})",
"PLAT" => $"Platform ({nodeName})",
"STDT" => $"String Data Table ({nodeName})",
_ => null,
};
}
#endregion
#region ToolTip Strings
// TODO - make better and more informative tooltips
// aka use current research to explain what these chunks are used for
string getTooltipInfo(string nodeName)
{
return nodeName switch
{
"PROJ" => "Project Information",
"FMT " => "Format Information",
"BNKI" => "Bank File Information",
"PRPS" => "List of all Chunk Property Entries",
"PROP" => "Chunk Property Entry",
"BUS " => "Generic Bus Entry",
"GBSS" => "List of all Group Bus Entries",
"GBUS" => "Group Bus Entry",
"GBSB" => "Group Bus Entry Information",
"RBSS" => "List of all Return Bus Entries",
"RBUS" => "Return Bus Entry",
"RBSB" => "Return Bus Entry Information",
"MBSS" => "List of all Master Bus Entries",
"MBUS" => "Master Bus Entry",
"MBSB" => "Master Bus Entry Information",
"IBSS" => "List of all Input Bus Entries",
"IBUS" => "Input Bus Entry",
"IBSB" => "Input Bus Entry Information",
"EVTS" => "List of all Event Entries",
"EVNT" => "Event Entry",
"EVTB" => "Event Entry Information",
"EVIS" => "List of all Nested Events",
"EVIT" => "Nested Event Entry",
"EVIB" => "Nested Event Entry Information",
"TLNS" => "List of all Timeline Entries",
"TMLN" => "Timeline Entry",
"TLNB" => "Timeline Entry Information",
"INST" => "A Reference to a Timeline Instance",
"TRNS" => "List of all Tranisition Entries",
"TRAN" => "Tranisition Entry",
"TRNB" => "Tranisition Entry Information",
"MUIS" => "List of all MultiSound Module Entries",
"MUIT" => "MultiSound Module Entry",
"MUIB" => "MultiSound Module Entry Information",
"PLST" => "Alongside MultiSounds\n" +
"List of Sound WAV GUIDs referenced\n" +
"As well as info on what instrument the MultiSound is",
"PRMS" => "List of all Parameter Entries",
"PARM" => "Parameter Entry",
"PRMB" => "Parameter Entry Information",
"PMLS" => "List of all Parameters references in Events",
"PMLO" => "Parameter reference",
"PMLB" => "Parameter reference Information",
"CTRS" => "List of all Fade Curve Entries",
"CTRL" => "Fade Curve Entry",
"CRVS" => "List of all Transition Curve Entries",
"CURV" => "Transition Curve Entry",
"CMDS" => "List of all Command Entries",
"CMDI" => "Command Entry",
"CMDB" => "Command Entry Information",
"MODS" => "List of all Module Entries",
"MODU" => "Module Entry",
"MODB" => "Module Entry Information",
"BEFX" => "List of all Event/Bus Effect Entries",
"BEFF" => "Event/Bus Effect Entry",
"BEFB" => "Event/Bus Effect Entry Information",
"WAVS" => "List of all WAV File Entries\n(Only provides their GUIDs)",
"WAV " => "WAV File Entry\n(Only provides their GUIDs)",
"WAIS" => "List of all WAV Instance Entries\n(Every seperate instance of a sound being used)",
"WAIT" => "WAV Instance Entry\n(Every seperate instance of a sound being used)",
"WAIB" => "WAV Instance Entry Information",
"VCAS" => "List of all VCA Entries",
"VCA " => "VCA Entry",
"VCAB" => "VCA Entry Information",
"SNAS" => "List of all Snapshot Entries",
"SNAP" => "Snapshot Entry",
"SNAB" => "Snapshot Entry Information",
"SLNS" => "List of all SilenceSound Entries",
"SLNI" => "SilenceSound Entry",
"SLNB" => "SilenceSound Entry Information",
"MPGS" => "List of all Managed Property Entries",
"MAP " => "Managed Property Entry",
"HASH" => "Contains all GUIDs in the Bank File",
"SND " => "List of all Sound Files in the Bank File",
"PLAT" => "Platform Information",
"STDT" => "A Table that contains all Paths and their GUIDs",
_ => string.Empty
};
}
#endregion
#region Bank File Tooltip
string getBankTooltip(string bank)
{
return bank switch
{
"Master.strings.bank" =>
"The main bank file that links all the other bank files together",
// TODO - see if including Master.bank is really always required
//"Master.bank" => "The default bank file that is always included along side Master.strings",
// default
_ => "An additional bank file containing most of the important data"
};
}
#endregion
#endregion
#region Export Chunk
private void ExportSelectedChunk()
{
// check tag type
switch (bankTreeView.SelectedNode.Tag)
{
// if type string
case string text:
// copy to clipboard
Clipboard.SetText(text);
break;
// if sound file, save as .wav/.ogg/whatever extension
case AudioConstructor snd:
SaveFile("Sound", snd.Name, snd.Ext, snd.Data);
break;
// if just binary file
case RIFFGenericDataObject bin:
SaveFile("Binary", bankTreeView.SelectedNode.Text, "bin", bin.Data);
break;
}
static void SaveFile(string Name, string FileName, string FileExt, byte[] Data)
{
using SaveFileDialog dlg = new();
dlg.Title = $"Choose where to save the {Name} File";
dlg.Filter = $"{Name} files (*.{FileExt})|*.{FileExt}|All files (*.*)|*.*";
dlg.DefaultExt = FileExt;
dlg.FileName = $"{FileName}.{FileExt}";
if (dlg.ShowDialog() == DialogResult.OK)
File.WriteAllBytes(dlg.FileName, Data);
}
}
#endregion
}
}