Skip to content

Commit 6edd467

Browse files
committed
Fix Door & Lantern Crash
* Damn you file 3133
1 parent 0ce37c0 commit 6edd467

File tree

6 files changed

+77
-32
lines changed

6 files changed

+77
-32
lines changed

Zero2Undub/MainWindow.xaml.cs

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,36 @@ private void UndubGame(object sender, DoWorkEventArgs e)
3535
IsUndubLaunched = true;
3636

3737
(sender as BackgroundWorker)?.ReportProgress(10);
38-
var importer = new ZeroFileImporter(UndubOptions, OriginIsoFile, TargetIsoFile);
39-
40-
var task = Task.Factory.StartNew(() =>
41-
{
42-
importer.RestoreGame();
43-
});
44-
45-
while (!importer.InfoReporterUi.IsCompleted)
38+
39+
try
4640
{
47-
(sender as BackgroundWorker)?.ReportProgress(100 * importer.InfoReporterUi.FilesCompleted / importer.InfoReporterUi.TotalFiles);
48-
Thread.Sleep(100);
49-
}
50-
51-
(sender as BackgroundWorker)?.ReportProgress(100);
41+
var importer = new ZeroFileImporter(UndubOptions, OriginIsoFile, TargetIsoFile);
42+
43+
var task = Task.Factory.StartNew(() => { importer.RestoreGame(); });
5244

53-
if (!importer.InfoReporterUi.IsSuccess)
45+
while (!importer.InfoReporterUi.IsCompleted)
46+
{
47+
(sender as BackgroundWorker)?.ReportProgress(100 * importer.InfoReporterUi.FilesCompleted /
48+
importer.InfoReporterUi.TotalFiles);
49+
Thread.Sleep(100);
50+
}
51+
52+
(sender as BackgroundWorker)?.ReportProgress(100);
53+
54+
if (!importer.InfoReporterUi.IsSuccess)
55+
{
56+
MessageBox.Show(
57+
$"The program failed with the following message: {importer.InfoReporterUi.ErrorMessage}",
58+
WindowName);
59+
return;
60+
}
61+
62+
MessageBox.Show("All Done! Enjoy the game :D", WindowName);
63+
}
64+
catch (Exception ex)
5465
{
55-
MessageBox.Show($"The program failed with the following message: {importer.InfoReporterUi.ErrorMessage}", WindowName);
56-
return;
66+
MessageBox.Show(ex.Message);
5767
}
58-
59-
MessageBox.Show("All Done! Enjoy the game :D", WindowName);
6068
}
6169

6270
private void LaunchUndubbing(object sender, EventArgs e)

Zero2UndubProcess/Constants/Ps2Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ public static class Ps2Constants
44
{
55
public const int SectorSize = 0x800;
66
public const int GameTitleIdAddress = 0x8A010;
7+
public const int EuGameTitleIdAddress = 0x89810;
78
public const int GameTitleIdLength = 0xB;
89
}
910
}

Zero2UndubProcess/GameFiles/FileStatus.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ public enum FileType
1515
UNKNOWN,
1616
AUDIO,
1717
AUDIO_HEADER,
18-
VIDEO
18+
VIDEO,
19+
SOUNDEFFECT
1920
}
2021

2122
public static class FileEvaluations

Zero2UndubProcess/GameFiles/RegionHandler.cs

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ public RegionHandler(FileSystemInfo origin, FileSystemInfo target)
2424
(_targetGameRegion, _originGameRegion) = (_originGameRegion, _targetGameRegion);
2525
}
2626

27+
if (_targetGameRegion == _originGameRegion)
28+
{
29+
throw new Exception(
30+
$"You selected ISO for {_targetGameRegion} and {_originGameRegion}. Make sure to select US ISO then JP ISO.");
31+
}
32+
33+
if (_targetGameRegion == GameRegions.EU)
34+
{
35+
throw new Exception($"Sorry the EU version is not yet supported by this version!");
36+
}
37+
2738
OriginRegionInfo = GetRegionInfoFromGameRegion(_originGameRegion);
2839

2940
TargetRegionInfo = GetRegionInfoFromGameRegion(_targetGameRegion);
@@ -74,18 +85,33 @@ private static GameRegions GetGameRegionFromTitleId(FileSystemInfo file)
7485

7586
binaryReader.BaseStream.Position = Ps2Constants.GameTitleIdAddress;
7687
var titleIdBytes = binaryReader.ReadBytes(Ps2Constants.GameTitleIdLength);
77-
78-
binaryReader.Close();
79-
88+
8089
var titleId = System.Text.Encoding.UTF8.GetString(titleIdBytes);
8190

82-
return titleId switch
91+
GameRegions gameRegion;
92+
93+
switch (titleId)
8394
{
84-
GameRegionConstants.EuIsoConstants.TitleId => GameRegions.EU,
85-
GameRegionConstants.JpIsoConstants.TitleId => GameRegions.Japan,
86-
GameRegionConstants.UsIsoConstants.TitleId => GameRegions.USA,
87-
_ => GameRegions.UNKNOWN
88-
};
95+
case GameRegionConstants.JpIsoConstants.TitleId:
96+
gameRegion = GameRegions.Japan;
97+
break;
98+
case GameRegionConstants.UsIsoConstants.TitleId:
99+
gameRegion = GameRegions.USA;
100+
break;
101+
default:
102+
binaryReader.BaseStream.Position = Ps2Constants.EuGameTitleIdAddress;
103+
titleIdBytes = binaryReader.ReadBytes(Ps2Constants.GameTitleIdLength);
104+
titleId = System.Text.Encoding.UTF8.GetString(titleIdBytes);
105+
106+
gameRegion = titleId == GameRegionConstants.EuIsoConstants.TitleId
107+
? GameRegions.EU
108+
: GameRegions.UNKNOWN;
109+
break;
110+
}
111+
112+
binaryReader.Close();
113+
114+
return gameRegion;
89115
}
90116
}
91117

Zero2UndubProcess/Importer/ZeroFileImporter.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System;
2+
using System.IO;
3+
using System.Text;
24
using Zero2UndubProcess.GameFiles;
35
using Zero2UndubProcess.Iso;
46
using Zero2UndubProcess.Reporter;
@@ -15,7 +17,7 @@ public ZeroFileImporter(UndubOptions undubOptions, string originFile, string tar
1517
{
1618
_undubOptions = undubOptions;
1719
_isoHandler = new IsoHandler(originFile, targetFile);
18-
20+
1921
InfoReporterUi = new InfoReporter
2022
{
2123
IsCompleted = false,
@@ -39,6 +41,7 @@ public void RestoreGame()
3941
if (targetFile.FileId == 2)
4042
{
4143
_isoHandler.OverwriteSplashScreen(originFile, targetFile);
44+
continue;
4245
}
4346

4447
if (targetFile.Type != FileType.VIDEO && targetFile.Type != FileType.AUDIO)
@@ -54,7 +57,7 @@ public void RestoreGame()
5457
{
5558
continue;
5659
}
57-
60+
5861
HandleAudioFile(originFile, targetFile);
5962
}
6063
else if (targetFile.Type == FileType.AUDIO && !_undubOptions.SafeUndub)
@@ -85,9 +88,15 @@ private void HandleAudioFile(ZeroFile origin, ZeroFile target)
8588
{
8689
var originHeaderFile = _isoHandler.OriginGetFile(origin.FileId - 1);
8790
var targetHeaderFile = _isoHandler.TargetGetFile(target.FileId - 1);
91+
92+
if (targetHeaderFile.Size > originHeaderFile.Size || originHeaderFile.Status is FileStatus.Unknown or FileStatus.NoFile || originHeaderFile.Type != FileType.AUDIO_HEADER || targetHeaderFile.Type != FileType.AUDIO_HEADER)
93+
{
94+
return;
95+
}
96+
8897
_isoHandler.WriteNewFile(originHeaderFile, targetHeaderFile);
8998
}
90-
99+
91100
private void CloseFiles()
92101
{
93102
_isoHandler.Close();

Zero2UndubProcess/Iso/IsoReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ private FileType ReadFileTypeTableOffset(int fileId)
7373
{
7474
0xC => FileType.AUDIO_HEADER,
7575
0xD => FileType.AUDIO,
76-
0xE => FileType.AUDIO,
76+
0xE => FileType.SOUNDEFFECT,
7777
0xF => FileType.VIDEO,
7878
_ => FileType.UNKNOWN
7979
};

0 commit comments

Comments
 (0)