Skip to content

Commit 0fb7095

Browse files
committed
Rewrote Undubber
1 parent d88f4c4 commit 0fb7095

29 files changed

+1048
-724
lines changed

Zero2Undub/MainWindow.xaml.cs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33
using System.Threading;
44
using System.Threading.Tasks;
55
using System.Windows;
6-
using System.Windows.Controls;
76
using Microsoft.Win32;
8-
using Zero2UndubProcess;
7+
using Zero2UndubProcess.Importer;
8+
using Zero2UndubProcess.Options;
99

1010
namespace Zero2Undub
1111
{
12-
/// <summary>
13-
/// Interaction logic for MainWindow.xaml
14-
/// </summary>
1512
public partial class MainWindow : Window
1613
{
1714
private string JpIsoFile { get; set; }
@@ -36,24 +33,24 @@ private void UndubGame(object sender, DoWorkEventArgs e)
3633
IsUndubLaunched = true;
3734

3835
(sender as BackgroundWorker)?.ReportProgress(10);
39-
var importer = new Zero2FileImporter(UsIsoFile, JpIsoFile);
36+
var importer = new ZeroFileImporter(JpIsoFile, UsIsoFile, new UndubOptions());
4037

4138
var task = Task.Factory.StartNew(() =>
4239
{
43-
importer.UndubGame();
40+
importer.RestoreGame();
4441
});
4542

46-
while (!importer.IsCompleted)
43+
while (!importer.InfoReporterUi.IsCompleted)
4744
{
48-
(sender as BackgroundWorker)?.ReportProgress(100 * importer.UndubbedFiles / (Ps2Constants.NumberFiles));
45+
(sender as BackgroundWorker)?.ReportProgress(100 * importer.InfoReporterUi.FilesCompleted / (importer.InfoReporterUi.TotalFiles));
4946
Thread.Sleep(100);
5047
}
5148

52-
(sender as BackgroundWorker)?.ReportProgress(100 * importer.UndubbedFiles / (Ps2Constants.NumberFiles));
49+
(sender as BackgroundWorker)?.ReportProgress(100 * importer.InfoReporterUi.FilesCompleted / (importer.InfoReporterUi.TotalFiles));
5350

54-
if (!importer.IsSuccess)
51+
if (!importer.InfoReporterUi.IsSuccess)
5552
{
56-
MessageBox.Show($"The program failed with the following message: {importer.ErrorMessage}", "PS2 Fatal Frame 2 Undubber");
53+
MessageBox.Show($"The program failed with the following message: {importer.InfoReporterUi.ErrorMessage}", "PS2 Fatal Frame 2 Undubber");
5754
return;
5855
}
5956

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace Zero2UndubProcess.Audio
2+
{
3+
public class AudioFileInfo
4+
{
5+
public int Frequency { get; set; }
6+
public int Interleave { get; set; }
7+
public int Offset { get; set; }
8+
public int Channel { get; set; }
9+
public byte PlaybackSpeed { get; set; }
10+
}
11+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Zero2UndubProcess.Constants
2+
{
3+
public static class GameConstants
4+
{
5+
public const int FileInfoByteSize = 0xC;
6+
}
7+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
namespace Zero2UndubProcess.Constants
2+
{
3+
public static class GameRegionConstants
4+
{
5+
public static class EuIsoConstants
6+
{
7+
public const int NumberFiles = 0x879;
8+
public const long FileTableStartAddress = 0xA63000;
9+
public const long FileTypeTableStartAddress = 0x2082D000;
10+
public const long FileArchiveStartAddress = 0x30D40000;
11+
}
12+
13+
public static class UsIsoConstants
14+
{
15+
public const int NumberFiles = 0x106B;
16+
public const long FileTableStartAddress = 0x2F90B8;
17+
public const long FileTypeTableStartAddress = 0x3055C0;
18+
public const long FileArchiveStartAddress = 0x30D40000;
19+
}
20+
21+
public static class JpIsoConstants
22+
{
23+
public const int NumberFiles = 0x106B;
24+
public const long FileTableStartAddress = 0x002F85F8;
25+
public const long FileTypeTableStartAddress = 0x304B00;
26+
public const long FileArchiveStartAddress = 0x30D40000;
27+
}
28+
}
29+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Zero2UndubProcess.Constants
2+
{
3+
public static class Ps2Constants
4+
{
5+
public const int SectorSize = 0x800;
6+
}
7+
}

Zero2UndubProcess/ExternalProcesses.cs

Lines changed: 0 additions & 134 deletions
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using static System.Enum;
2+
3+
namespace Zero2UndubProcess.GameFiles
4+
{
5+
public enum FileStatus
6+
{
7+
NoFile,
8+
FileNotCompressed = 2,
9+
FileCompressed = 3,
10+
Unknown = 4
11+
}
12+
13+
public enum FileType
14+
{
15+
UNKNOWN,
16+
AUDIO,
17+
AUDIO_HEADER,
18+
VIDEO
19+
}
20+
21+
public static class FileEvaluations
22+
{
23+
public static FileStatus EvaluateFileStatus(uint valueRead)
24+
{
25+
var fileStatus = valueRead & 0b00000011;
26+
27+
var tryParse = TryParse<FileStatus>(fileStatus.ToString(), out var returnValue);
28+
29+
return !tryParse ? FileStatus.Unknown : returnValue;
30+
}
31+
}
32+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using Zero2UndubProcess.Constants;
2+
3+
namespace Zero2UndubProcess.GameFiles
4+
{
5+
public class RegionHandler
6+
{
7+
private readonly GameRegions OriginGameRegion;
8+
private readonly GameRegions TargetGameRegion;
9+
public readonly RegionInfo OriginRegionInfo;
10+
public readonly RegionInfo TargetRegionInfo;
11+
12+
public RegionHandler(GameRegions originGameRegion, GameRegions targetGameRegion)
13+
{
14+
OriginGameRegion = originGameRegion;
15+
TargetGameRegion = targetGameRegion;
16+
17+
// TODO: Add game region check logic
18+
19+
OriginRegionInfo = new RegionInfo
20+
{
21+
FileArchiveStartAddress = GameRegionConstants.JpIsoConstants.FileArchiveStartAddress,
22+
FileTableStartAddress = GameRegionConstants.JpIsoConstants.FileTableStartAddress,
23+
FileTypeTableStartAddress = GameRegionConstants.JpIsoConstants.FileTypeTableStartAddress,
24+
NumberFiles = GameRegionConstants.JpIsoConstants.NumberFiles
25+
};
26+
27+
TargetRegionInfo = new RegionInfo
28+
{
29+
FileArchiveStartAddress = GameRegionConstants.UsIsoConstants.FileArchiveStartAddress,
30+
FileTableStartAddress = GameRegionConstants.UsIsoConstants.FileTableStartAddress,
31+
FileTypeTableStartAddress = GameRegionConstants.UsIsoConstants.FileTypeTableStartAddress,
32+
NumberFiles = GameRegionConstants.UsIsoConstants.NumberFiles
33+
};
34+
}
35+
}
36+
37+
public class RegionInfo
38+
{
39+
public long FileArchiveStartAddress { get; set; }
40+
public long FileTableStartAddress { get; set; }
41+
public long FileTypeTableStartAddress { get; set; }
42+
public int NumberFiles { get; set; }
43+
}
44+
45+
public enum GameRegions
46+
{
47+
Japan,
48+
USA,
49+
EU
50+
}
51+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Zero2UndubProcess.Audio;
2+
3+
namespace Zero2UndubProcess.GameFiles
4+
{
5+
public class ZeroFile
6+
{
7+
public int FileId { get; set; }
8+
public long Offset { get; set; }
9+
public long Size { get; set; }
10+
public long SizeUncompressed { get; set; }
11+
public long SizeCompress { get; set; }
12+
public FileStatus Status { get; set; }
13+
public FileType Type { get; set; }
14+
public AudioFileInfo AudioHeader { get; set; }
15+
}
16+
}

0 commit comments

Comments
 (0)