Repository navigation
Expand file tree
/
Copy pathMain.cs
More file actions
2063 lines (1815 loc) · 83 KB
/
Copy pathMain.cs
File metadata and controls
2063 lines (1815 loc) · 83 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
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using IntelOrca.Biohazard;
using System.Diagnostics;
using System.Reflection;
using System.Linq;
using System.Media;
using System.Text;
using Tool_Hazard.Biohazard;
using Tool_Hazard.Biohazard.emd;
using Tool_Hazard.Biohazard.GCA;
using Tool_Hazard.Biohazard.GCA;
using Tool_Hazard.Biohazard.RDT;
using Tool_Hazard.Biohazard.RE4;
using Tool_Hazard.Forms;
using Tool_Hazard.Nintendo;
using Tool_Hazard.Sony_PS1;
using Tool_Hazard.White_Day;
namespace Tool_Hazard
{
public partial class Main : Form
{
private readonly ushort[] SonnoriLz77Key = { 0xFF21, 0x834F, 0x675F, 0x0034, 0xF237, 0x815F, 0x4765, 0x0233 };
private readonly Encoding EucKr;
public static Main Instance { get; private set; }
//private NopCompression selectedCompression = NopCompression.None;
//Other C# files to use functions from should be defined here, so we can use them in Form1/Main.cs/Main Window??
//Rebirth Manager
private readonly RebirthManager rebirth = new RebirthManager();
private BioVersion CurrentBioVersion;
public Main()
{
try
{
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
EucKr = Encoding.GetEncoding("EUC-KR");
}
catch
{
// fallback to UTF-8 if EUC-KR not available
EucKr = Encoding.UTF8;
MessageBox.Show("EUC-KR encoding not available. Using UTF-8 instead. Korean filenames may appear incorrect.",
"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
InitializeComponent();
UpdateStatus("Ready");
// Sync menu check state from saved setting
playStartupSoundToolStripMenuItem.Checked = Properties.Settings.Default.PlayStartupSound;
playStartupSoundToolStripMenuItem.CheckedChanged += (_, __) =>
{
Properties.Settings.Default.PlayStartupSound = playStartupSoundToolStripMenuItem.Checked;
Properties.Settings.Default.Save();
};
}
// --------------------------------------------------------------------
// Helpers
// --------------------------------------------------------------------
//Rebirth Status Bar Update Helper
private void UpdateRebirthStatus(string status)
{
if (InvokeRequired)
{
Invoke(new Action(() =>
toolStripStatusLabel1.Text = status));
}
else
{
toolStripStatusLabel1.Text = status;
}
}
// Play the embedded WAV at startupPlays a .wav sound embedded as a resource in the assembly.
// The resource name is the full namespace path to the .wav file.
public static void PlayEmbeddedWav(string resourceName)
{
var asm = Assembly.GetExecutingAssembly();
using Stream? s = asm.GetManifestResourceStream(resourceName);
if (s == null) return;
using var player = new SoundPlayer(s);
player.Play();
}
//Update Status Bar Text
public void UpdateStatus(string text)
{
//Just as a fail safe
try
{
//toolStripStatusLabel1.Text = text;
//statusStrip1.Refresh();
if (InvokeRequired)
{
Invoke(new Action(() => toolStripStatusLabel1.Text = text));
}
else
{
toolStripStatusLabel1.Text = text;
}
}
//Fail safe/exeption message triggered if a exception is caught
catch (Exception ex)
{
MessageBox.Show($"Error Updating Status Bar to '{text}'.\n\nThe error is: {ex}", "UpdateStatus Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
//UDAS Extraction helper (for RE4 UHD UDAS Tool)
private async Task<List<string>> RunUdasToolAsync(
string mode,
IEnumerable<string> inputFiles,
string outputDirectory)
{
string workDirectory = Path.Combine(
Path.GetTempPath(),
"ToolHazard_UDAS_" + Guid.NewGuid().ToString("N")
);
Directory.CreateDirectory(workDirectory);
Directory.CreateDirectory(outputDirectory);
try
{
// Extract embedded executable.
Assembly assembly = Assembly.GetExecutingAssembly();
string? resourceName = assembly
.GetManifestResourceNames()
.FirstOrDefault(n =>
n.EndsWith(
"RE4_UHD_UDAS_Tool.exe",
StringComparison.OrdinalIgnoreCase));
if (resourceName == null)
throw new FileNotFoundException(
"Embedded RE4_UHD_UDAS_Tool.exe was not found.");
string exePath = Path.Combine(
workDirectory, "RE4_UHD_UDAS_Tool.exe");
using (Stream resource =
assembly.GetManifestResourceStream(resourceName)
?? throw new FileNotFoundException(resourceName))
using (FileStream output = File.Create(exePath))
{
await resource.CopyToAsync(output);
}
// Copy inputs beside the executable.
var stagedFiles = new HashSet<string>(
StringComparer.OrdinalIgnoreCase);
foreach (string sourceFile in inputFiles)
{
string fileName = Path.GetFileName(sourceFile);
string stagedPath = Path.Combine(workDirectory, fileName);
if (!stagedFiles.Add(fileName))
throw new IOException(
$"Duplicate input filename: {fileName}");
File.Copy(sourceFile, stagedPath, true);
}
// Run the tool in batch mode, with no file arguments.
var startInfo = new ProcessStartInfo
{
FileName = exePath,
WorkingDirectory = workDirectory,
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true
};
startInfo.ArgumentList.Add(mode);
using Process process = new Process
{
StartInfo = startInfo
};
process.Start();
Task<string> stdout =
process.StandardOutput.ReadToEndAsync();
Task<string> stderr =
process.StandardError.ReadToEndAsync();
using var timeout = new CancellationTokenSource(
TimeSpan.FromMinutes(3));
try
{
await process.WaitForExitAsync(timeout.Token);
}
catch (OperationCanceledException)
{
process.Kill(entireProcessTree: true);
throw new TimeoutException(
"UDAS tool did not finish within 3 minutes.");
}
string outputText = await stdout;
string errorText = await stderr;
if (process.ExitCode != 0)
{
throw new Exception(
$"UDAS tool exited with code {process.ExitCode}.\n" +
errorText + "\n" + outputText);
}
// Collect generated files, excluding the executable
// and the original staged input files.
var generatedFiles = new List<string>();
foreach (string file in Directory.GetFiles(
workDirectory, "*", SearchOption.AllDirectories))
{
string name = Path.GetFileName(file);
if (name.Equals("RE4_UHD_UDAS_Tool.exe",
StringComparison.OrdinalIgnoreCase))
continue;
if (stagedFiles.Contains(name) &&
Path.GetDirectoryName(file) == workDirectory)
continue;
string relativePath = Path.GetRelativePath(
workDirectory, file);
string destination = Path.Combine(
outputDirectory, relativePath);
Directory.CreateDirectory(
Path.GetDirectoryName(destination)!);
File.Copy(file, destination, true);
generatedFiles.Add(destination);
}
return generatedFiles;
}
finally
{
if (Directory.Exists(workDirectory))
Directory.Delete(workDirectory, true);
}
}
// --------------------------------------------------------------------
// Menu Hooks
// --------------------------------------------------------------------
//White Day (2001) NOP Unpack
private async void unpackToolStripMenuItem1_Click(object sender, EventArgs e)
{
using (OpenFileDialog openDialog = new OpenFileDialog())
{
openDialog.Filter = "NOP Files (*.nop)|*.nop";
openDialog.Multiselect = true;
if (openDialog.ShowDialog() == DialogResult.OK)
{
System.Windows.Forms.ProgressBar progressBar = new System.Windows.Forms.ProgressBar
{
Dock = DockStyle.Bottom,
Minimum = 0,
Maximum = openDialog.FileNames.Length
};
Label statusLabel = new Label
{
Dock = DockStyle.Bottom,
Text = "Starting...",
AutoSize = true
};
this.Controls.Add(progressBar);
this.Controls.Add(statusLabel);
unpackToolStripMenuItem1.Enabled = false;
StringBuilder errorLog = new StringBuilder();
await Task.Run(() =>
{
int progress = 0;
foreach (string filePath in openDialog.FileNames)
{
try
{
string outputDir = Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath) + "_unpacked");
Directory.CreateDirectory(outputDir);
// Update UI safely
this.Invoke(new Action(() =>
{
statusLabel.Text = $"Unpacking: {Path.GetFileName(filePath)}";
progressBar.Value = progress;
}));
var archive = new SonnoriArchive();
archive.UnpackNopFile(filePath, outputDir);
}
catch (Exception ex)
{
errorLog.AppendLine($"Error unpacking {Path.GetFileName(filePath)}: {ex.Message}");
}
progress++;
}
});
statusLabel.Text = "Completed";
progressBar.Value = progressBar.Maximum;
if (errorLog.Length > 0)
{
string logPath = Path.Combine(System.Windows.Forms.Application.StartupPath, "UnpackErrors.log");
File.WriteAllText(logPath, errorLog.ToString());
MessageBox.Show($"Unpacking finished with some errors.\nSee log: {logPath}", "Finished", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
MessageBox.Show("All files unpacked successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
this.Controls.Remove(progressBar);
this.Controls.Remove(statusLabel);
unpackToolStripMenuItem1.Enabled = true;
}
}
}
//File -> Exit
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Close();
}
private void repackToolStripMenuItem1_Click(object sender, EventArgs e)
{
//NOP Repack Code Here
using (FolderBrowserDialog folderDialog = new FolderBrowserDialog())
{
folderDialog.Description = "Select the folder to repack into a .nop file";
if (folderDialog.ShowDialog() == DialogResult.OK)
{
string sourceDir = folderDialog.SelectedPath;
string nopFilePath = Path.Combine(Path.GetDirectoryName(sourceDir), Path.GetFileName(sourceDir) + ".nop");
SaveFileDialog saveDialog = new SaveFileDialog
{
Filter = "NOP Files (*.nop)|*.nop",
FileName = Path.GetFileName(nopFilePath)
};
if (saveDialog.ShowDialog() == DialogResult.OK)
{
nopFilePath = saveDialog.FileName;
// Ask user for compression
var result = MessageBox.Show("Choose compression:\nYes = LZ77\nNo = Sonnori\nCancel = None",
"Compression Method",
MessageBoxButtons.YesNoCancel,
MessageBoxIcon.Question);
SonnoriArchive.NopCompression method = SonnoriArchive.NopCompression.None;
if (result == DialogResult.Yes)
method = SonnoriArchive.NopCompression.Lz77;
else if (result == DialogResult.No)
method = SonnoriArchive.NopCompression.Sonnori;
var archive = new SonnoriArchive();
archive.RepackNopFile(sourceDir, nopFilePath, method);
MessageBox.Show($"Repacking complete: {nopFilePath}", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}
//White Day Font Editor
private void fontEditorToolStripMenuItem1_Click(object sender, EventArgs e)
{
// Open Font Editor form
using (var fontEditor = new WhiteDayFontEditor())
{
fontEditor.ShowDialog();
}
}
//Clasic Rebirth Installers Menu Hooks
//RE1 Classic Rebirth Installer Menu Hook
private async void menuInstallRE1CR_Click(object sender, EventArgs e)
{
System.Media.SystemSounds.Exclamation.Play();//Play sound to grab attention
DialogResult ask_setup = MessageBox.Show(
$"Classic Rebirth is a fan-patch made by Gemini-Loboto3.\n\n" +
$"This patch for the Mediakite version of Resident Evil/Biohazard fixes common compatibility issues on modern systems, " +
$"and includes several other enhancements such as raw and native xinput controller support, higher resolution display options, " +
$"and forcefeedback (vibration), among other things.\n\n" +
$"Would you like to proceed with install?",
"Classic Rebirth Installer",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question
);
if (ask_setup == DialogResult.Yes)
{
using var dlg = new FolderBrowserDialog
{
Description = "Select Resident Evil 1 directory"
};
if (dlg.ShowDialog() == DialogResult.OK)
{
UpdateRebirthStatus("Preparing Resident Evil 1 Classic Rebirth...");
var rebirth = new RebirthManager(UpdateRebirthStatus);
await rebirth.Install(
BioVersion.Biohazard1,
dlg.SelectedPath
);
UpdateRebirthStatus("Resident Evil 1 Classic Rebirth operation finished.");
}
}
}
//RE2 Classic Rebirth Installer Menu Hook
private async void menuInstallRE2CR_Click_1(object sender, EventArgs e)
{
System.Media.SystemSounds.Exclamation.Play();//Play sound to grab attention
DialogResult ask_setup = MessageBox.Show(
$"Classic Rebirth is a fan-patch made by Gemini-Loboto3.\n\n" +
$"This patch for Resident Evil/Biohazard 2 Sourcenext fix common compatibility issues on modern systems, " +
$"and includes several other enhancements such as raw and native xinput controller support, higher resolution display options, " +
$"and forcefeedback (vibration), among other things.\n\n" +
$"Would you like to proceed with install?",
"Classic Rebirth Installer",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question
);
if (ask_setup == DialogResult.Yes)
{
using var dlg = new FolderBrowserDialog
{
Description = "Select Resident Evil 2 directory"
};
if (dlg.ShowDialog() == DialogResult.OK)
{
UpdateRebirthStatus("Preparing Resident Evil 2 Classic Rebirth...");
var rebirth = new RebirthManager(UpdateRebirthStatus);
await rebirth.Install(
BioVersion.Biohazard2,
dlg.SelectedPath
);
UpdateRebirthStatus("Resident Evil 2 Classic Rebirth operation finished.");
}
}
}
//RE3 Classic Rebirth Installer Menu Hook
private async void menuInstallRE3CR_Click_1(object sender, EventArgs e)
{
System.Media.SystemSounds.Exclamation.Play();//Play sound to grab attention
DialogResult ask_setup = MessageBox.Show(
$"Classic Rebirth is a fan-patch made by Gemini-Loboto3.\n\n" +
$"This patch for Resident Evil/Biohazard 3 Sourcenext ver 1.1.0 fixes common compatibility issues on modern systems, " +
$"and includes several other enhancements and features.\n\n" +
$"These features include fixing wobbly polygons, crash issues, controller support, a PC friendly version of the PS1's options menu restored and upgraded, " +
$"Mercenaries launch-able through the main executable, among other things.\n\n" +
$"Would you like to proceed with install?",
"Classic Rebirth Installer",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question
);
if (ask_setup == DialogResult.Yes)
{
using var dlg = new FolderBrowserDialog
{
Description = "Select Resident Evil 3 directory"
};
if (dlg.ShowDialog() == DialogResult.OK)
{
UpdateRebirthStatus("Preparing Resident Evil 3 Classic Rebirth...");
var rebirth = new RebirthManager(UpdateRebirthStatus);
await rebirth.Install(
BioVersion.Biohazard3,
dlg.SelectedPath
);
UpdateRebirthStatus("Resident Evil 3 Classic Rebirth operation finished.");
}
}
}
//Classic Rebirth Website launcher menu hook
private void websiteToolStripMenuItem_Click(object sender, EventArgs e)
{
//visit Classic Rebirth website
string url = "https://classicrebirth.com/";
try
{
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo
{
FileName = url,
UseShellExecute = true
});
}
catch (Exception ex)
{
MessageBox.Show($"Failed to open documentation URL:\n{ex.Message}", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
//
//VH/BH VAB Tool menu hook
//this is a tool to extract and repack VH/BH VAB files
//for the PS1 versions of Biohazard 1-3
//
private void vBVHToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
// Just create and show the form.
// The SampleManagerForm will handle prompting for files in its Shown event.
VHVB_Tool managerForm = new VHVB_Tool();
managerForm.Show();
}
catch (Exception ex)
{
MessageBox.Show($"Failed to open Sample Manager: {ex.Message}", "Form Load Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void vHVBToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
// Just create and show the form.
// The SampleManagerForm will handle prompting for files in its Shown event.
VHVB_Tool managerForm = new VHVB_Tool();
managerForm.Show();
}
catch (Exception ex)
{
MessageBox.Show($"Failed to open Sample Manager: {ex.Message}", "Form Load Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
// ------------------ Biohazard 1-3 RDT Unpack/Repack Menu Hooks -----------------
private void unpackToolStripMenuItem4_Click(object sender, EventArgs e)
{
//Bio1 RDT Unpack (RdtUnpacker.cs)
using var ofd = new OpenFileDialog
{
Filter = "RDT Files (*.rdt)|*.rdt",
Title = "Select Bio1 .rdt to Unpack"
};
if (ofd.ShowDialog() != DialogResult.OK) return;
using var fbd = new FolderBrowserDialog { Description = "Select Output Folder" };
if (fbd.ShowDialog() != DialogResult.OK) return;
string rdtName = Path.GetFileNameWithoutExtension(ofd.FileName);
string outputDir = Path.Combine(fbd.SelectedPath, rdtName);
Directory.CreateDirectory(outputDir);
var unpacker = new RdtUnpacker(BioVersion.Biohazard1, ofd.FileName, outputDir);
unpacker.Unpack();
UpdateStatus("Bio1 RDT unpacked successfully!");
}
private void repackToolStripMenuItem5_Click(object sender, EventArgs e)
{
// Bio1 RDT Repack (RdtPacker.cs)
using var ofd = new OpenFileDialog
{
Filter = "INI Files (*.ini)|*.ini",
Title = "Select Bio1 header.ini to Repack"
};
if (ofd.ShowDialog() != DialogResult.OK) return;
string? folder = Path.GetDirectoryName(ofd.FileName);
if (string.IsNullOrEmpty(folder))
{
MessageBox.Show("Could not determine the folder of the selected INI.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
var packer = new RdtPacker(BioVersion.Biohazard1, folder);
packer.Pack();
UpdateStatus("Bio1 RDT repacked successfully!");
}
private void Bio2RDTunpackToolStripMenuItem_Click(object sender, EventArgs e)
{
//Bio2 RDT Unpack (RdtUnpacker.cs)
using var ofd = new OpenFileDialog
{
Filter = "RDT Files (*.rdt)|*.rdt",
Title = "Select Bio2 .rdt to Unpack"
};
if (ofd.ShowDialog() != DialogResult.OK) return;
using var fbd = new FolderBrowserDialog { Description = "Select Output Folder" };
if (fbd.ShowDialog() != DialogResult.OK) return;
string rdtName = Path.GetFileNameWithoutExtension(ofd.FileName);
string outputDir = Path.Combine(fbd.SelectedPath, rdtName);
Directory.CreateDirectory(outputDir);
var unpacker = new RdtUnpacker(BioVersion.Biohazard2, ofd.FileName, outputDir);
unpacker.Unpack();
UpdateStatus("Bio2 RDT unpacked successfully!");
}
private void Bio2RDTrepackToolStripMenuItem_Click_1(object sender, EventArgs e)
{
// Bio2 RDT Repack (RdtPacker.cs)
using var ofd = new OpenFileDialog
{
Filter = "INI Files (*.ini)|*.ini",
Title = "Select Bio2 header.ini to Repack"
};
if (ofd.ShowDialog() != DialogResult.OK) return;
string? folder = Path.GetDirectoryName(ofd.FileName);
if (string.IsNullOrEmpty(folder))
{
MessageBox.Show("Could not determine the folder of the selected INI.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
var packer = new RdtPacker(BioVersion.Biohazard2, folder);
packer.Pack();
UpdateStatus("Bio2 RDT repacked successfully!");
}
//Bio3 RDT Unpack (RdtUnpacker.cs)
private void Bio3RDTunpackToolStripMenuItem_Click(object sender, EventArgs e)
{
using var ofd = new OpenFileDialog
{
Filter = "RDT Files (*.rdt)|*.rdt",
Title = "Select Bio3 .rdt to Unpack"
};
if (ofd.ShowDialog() != DialogResult.OK) return;
using var fbd = new FolderBrowserDialog { Description = "Select Output Folder" };
if (fbd.ShowDialog() != DialogResult.OK) return;
string rdtName = Path.GetFileNameWithoutExtension(ofd.FileName);
string outputDir = Path.Combine(fbd.SelectedPath, rdtName);
Directory.CreateDirectory(outputDir);
var unpacker = new RdtUnpacker(BioVersion.Biohazard3, ofd.FileName, outputDir);
unpacker.Unpack();
UpdateStatus("Bio3 RDT unpacked successfully!");
}
private void Bio3RDTrepackToolStripMenuItem_Click(object sender, EventArgs e)
{
// Bio3 RDT Repack (RdtPacker.cs)
using var ofd = new OpenFileDialog
{
Filter = "INI Files (*.ini)|*.ini",
Title = "Select Bio3 header.ini to Repack"
};
if (ofd.ShowDialog() != DialogResult.OK) return;
string? folder = Path.GetDirectoryName(ofd.FileName);
if (string.IsNullOrEmpty(folder))
{
MessageBox.Show("Could not determine the folder of the selected INI.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
var packer = new RdtPacker(BioVersion.Biohazard3, folder);
packer.Pack();
UpdateStatus("Bio3 RDT repacked successfully!");
}
//RDT Conversion menu hooks
private void convertToBIO3ToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("This is an experimental functionality and as such it may not work correctly.", "Experimental Code", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
//Bio2 to Bio3 RDT Conversion (basically unpack a ofd selected rdt to a specific selecter out folder path and then usag the .hdr file got unpacked, e.g. if we extracted x.rdt to a specific folder, its likely we got outpath/x/x.hdr so that is used to repack as the usage is explained in the other menu hooks... the different is this will be automatic conversion without having to do it manually
using var ofd = new OpenFileDialog
{
Filter = "RDT Files (*.rdt)|*.rdt",
Title = "Select Bio2 RDT File"
};
if (ofd.ShowDialog() != DialogResult.OK) return;
using var fbd = new FolderBrowserDialog { Description = "Select Temp Extraction Folder" };
if (fbd.ShowDialog() != DialogResult.OK) return;
// 1) Unpack Bio2
string rdtName = Path.GetFileNameWithoutExtension(ofd.FileName);
MessageBox.Show("RDT Name:\n\n" + rdtName, "DEBUG", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
string outputDir = Path.Combine(fbd.SelectedPath, rdtName);
MessageBox.Show("directory set to:\n\n" + outputDir, "DEBUG", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
Directory.CreateDirectory(outputDir);
var unpacker = new RdtUnpacker(BioVersion.Biohazard2, ofd.FileName, outputDir);
unpacker.Unpack();
// HDR path inside temp
var hdrPath = Path.Combine(outputDir,
Path.GetFileNameWithoutExtension(ofd.FileName) + ".hdr");
var newRDTpath = Path.Combine(outputDir,
Path.GetFileNameWithoutExtension(ofd.FileName) + ".RDT");
MessageBox.Show("HDR File Path:\n\n" + hdrPath, "DEBUG", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
// 2) Repack as Bio3
var packer = new RdtPacker(BioVersion.Biohazard3, hdrPath);
packer.Pack();
MessageBox.Show("Converted Bio2 → Bio3 successfully!\n\n" + newRDTpath, "Success!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
private void convertToBIO2ToolStripMenuItem_Click(object sender, EventArgs e)
{
//same as above but for Bio3/RE3 to Bio2/RE2
using var ofd = new OpenFileDialog
{
Filter = "RDT Files (*.rdt)|*.rdt",
Title = "Select Bio3 RDT File"
};
if (ofd.ShowDialog() != DialogResult.OK) return;
using var tempFolder = new FolderBrowserDialog { Description = "Select Temp Extraction Folder" };
if (tempFolder.ShowDialog() != DialogResult.OK) return;
// 1) Unpack Bio3
var unpacker = new RdtUnpacker(BioVersion.Biohazard3, ofd.FileName, tempFolder.SelectedPath + Path.GetFileNameWithoutExtension(ofd.FileName));
unpacker.Unpack();
// HDR path inside temp
var hdrPath = Path.Combine(tempFolder.SelectedPath,
Path.GetFileNameWithoutExtension(ofd.FileName) + ".hdr");
// 2) Repack as Bio2
var packer = new RdtPacker(BioVersion.Biohazard2, hdrPath);
packer.Pack();
MessageBox.Show("Converted Bio3 → Bio2 successfully!");
//statusStrip1.Update("Converted Bio3 → Bio2 successfully!");
//statusStrip1.Text = "Importing data file"; //see next line
}
//Biohazard RDT Script Data (SCD) Menu hooks
private void decompiletoSToolStripMenuItem1_Click(object sender, EventArgs e)
{
//Dcompile Bio2 RDT Script Data to .s
}
private void recompiletoRDTToolStripMenuItem1_Click(object sender, EventArgs e)
{
//Recompile Decompiled (.s) Script Data to Bio2 RDT
}
private void decompiletoSToolStripMenuItem_Click(object sender, EventArgs e)
{
//Bio3 RDT Script Data to .S
}
private void recompiletoRDTToolStripMenuItem_Click(object sender, EventArgs e)
{
//Bio2 Recompile Decompiled (.s) Script Data to .RDT
}
//RE3 ROFS Tool Menu Hooks
private void ROFSunpackToolStripMenuItem_Click(object sender, EventArgs e)
{
using var ofd = new OpenFileDialog
{
Filter = "RE3 ROFS (*.dat)|*.dat|All Files (*.*)|*.*"
};
if (ofd.ShowDialog() != DialogResult.OK)
return;
string inputPath = ofd.FileName;
string outputDir = Path.Combine(
Path.GetDirectoryName(inputPath)!,
Path.GetFileNameWithoutExtension(inputPath)
);
try
{
using var archive = new RE3Archive(inputPath);
archive.Extract(outputDir);
MessageBox.Show(
$"Extracted to:\n{outputDir}",
"ROFS Unpack",
MessageBoxButtons.OK,
MessageBoxIcon.Information
);
}
catch (Exception ex)
{
MessageBox.Show(
ex.Message,
"ROFS Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error
);
}
}
//Biohazard 1-3 SCD decompiler/compiler/extractor menu hooks
private void decompiletoSToolStripMenuItem_Click_1(object sender, EventArgs e)
{
//Decompile SCD from a Bio3 RDT to .S editable script
using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
openFileDialog.Filter = "RDT files (*.rdt)|*.rdt|All files (*.*)|*.*";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
string rdtPath = openFileDialog.FileName;
string outputPath = Path.ChangeExtension(rdtPath, ".s");
//Finish this off / To be added
}
}
}
private void decompileSCDToSToolStripMenuItem_Click(object sender, EventArgs e)
{
//Diassemble/Decompile Bio3 SCD to .S/.LST
using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
openFileDialog.Filter = "Script Data files (*.scd)|*.scd|All files (*.*)|*.*";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
string scdPath = openFileDialog.FileName;
string outputPath = Path.ChangeExtension(scdPath, ".s");
//Execute our SCD to .S/.LST Decompile function from ScdService.cs
ScdService.DecompileScd(scdPath, BioVersion.Biohazard3);
}
}
}
private void extractSCDFromRDTToolStripMenuItem1_Click(object sender, EventArgs e)
{
//Extract SCD/Script Data from a Bio2/RE2 RDT
using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
openFileDialog.Filter = "RDT files (*.rdt)|*.rdt|All files (*.*)|*.*";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
string rdtPath = openFileDialog.FileName;
string outputPath = Path.ChangeExtension(rdtPath, ".scd");
//Execute our ScdService.cs Extract SCD function and set path, outputpath and global version
ScdService.ExtractScdFromRdt(rdtPath, outputPath, BioVersion.Biohazard2);
}
}
}
private void extractSCDFromRDTToolStripMenuItem_Click(object sender, EventArgs e)
{
//Extract SCD from a Bio3/RE3 RDT
using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
openFileDialog.Filter = "RDT files (*.rdt)|*.rdt|All files (*.*)|*.*";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
string rdtPath = openFileDialog.FileName;
string outputPath = Path.ChangeExtension(rdtPath, ".scd");
//Execute our ScdService.cs Extract SCD function and set path, outputpath and global version
ScdService.ExtractScdFromRdt(rdtPath, outputPath, BioVersion.Biohazard3);
}
}
}
private void decompileSCDToSToolStripMenuItem1_Click(object sender, EventArgs e)
{
//Diassemble/Decompile Bio2 SCD to .S/.LST
using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
openFileDialog.Filter = "Script Data files (*.scd)|*.scd|All files (*.*)|*.*";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
string scdPath = openFileDialog.FileName;
string outputPath = Path.ChangeExtension(scdPath, ".s");
//Execute our SCD to .S/.LST Decompile function from ScdService.cs
ScdService.DecompileScd(scdPath, BioVersion.Biohazard2);
}
}
}
//Load SCD Editor with selected game version
private void sCDOpCodeEditorToolStripMenuItem_Click(object sender, EventArgs e)
{
var editor = new BiohazardOpcodeEditorForm(BioVersion.Biohazard3);
editor.Show(this);
}
private void sCDOpCodeEditorToolStripMenuItem1_Click(object sender, EventArgs e)
{
var editor = new BiohazardOpcodeEditorForm(BioVersion.Biohazard2);
editor.Show(this);
}
private void toolStripMenuItem3_Click(object sender, EventArgs e)
{
var editor = new BiohazardOpcodeEditorForm(BioVersion.Biohazard1);
editor.Show(this);
}
// --- Version select/set based on selected menu strip item ---
private void toolStripMenuItem1_Click(object sender, EventArgs e)
{
CurrentBioVersion = BioVersion.Biohazard1;
UpdateStatus("Selected Resident Evil 1/Biohazard 1");
}
private void bIO151997ToolStripMenuItem_Click(object sender, EventArgs e)
{
CurrentBioVersion = BioVersion.Biohazard1_5;
UpdateStatus("Selected Resident Evil 1.5/Biohazard 1.5");
}
private void bIO2RE21998ToolStripMenuItem_Click(object sender, EventArgs e)
{
CurrentBioVersion = BioVersion.Biohazard2;
UpdateStatus("Selected Resident Evil 2/Biohazard 2");
}
private void bIORE31999ToolStripMenuItem_Click(object sender, EventArgs e)
{
CurrentBioVersion = BioVersion.Biohazard3;
UpdateStatus("Selected Resident Evil 3/Biohazard 3");
}
private void rESURVVBIOGUNSURVToolStripMenuItem_Click(object sender, EventArgs e)
{
CurrentBioVersion = BioVersion.BiohazardSurvivor;
UpdateStatus("Selected Resident Evil Survivor/Biohazard Gun Survivor");
}
private void rECVBIOCV2000ToolStripMenuItem_Click(object sender, EventArgs e)
{
CurrentBioVersion = BioVersion.BiohazardCv;
UpdateStatus("Selected Resident Evil CODE: Veronica/Biohazard CODE: Veronica");
}
// --- Resident Evil EMD/PLD Unpack/Repack Menu Hooks ---
private void unpackOriginalToolStripMenuItem3_Click(object sender, EventArgs e)
{
//RE3 EMD [MD2 + TIM ONLY] Unpack
using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
openFileDialog.Filter = "Resident Evil Enemy Data (*.emd)|*.EMD|All files (*.*)|*.*";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
string selectedFile = openFileDialog.FileName;
//try catch errors
try
{
//Call EMD tool and pass our paths and version to unpack as Original format
EmdTool.Unpack(selectedFile, BioVersion.Biohazard3, EmdTool.Format.Original);
}
catch (Exception ex)
{
MessageBox.Show($"Error:\n{ex.Message}", "EMD Tool",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}