Skip to content

Commit d88f4c4

Browse files
committed
Switch Pss Audio
1 parent fc1a444 commit d88f4c4

File tree

6 files changed

+128
-4
lines changed

6 files changed

+128
-4
lines changed

Zero2Undub/MainWindow.xaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,5 @@
2020
<Button x:Name="button1" Content="Select Files" HorizontalAlignment="Left" Margin="198,347,-8.856,0" VerticalAlignment="Top" Width="99" Click="Button_Click" Foreground="#FFD6DBE9" Background="#FF2C3E5F" BorderBrush="{x:Null}" Height="22"/>
2121
<Image x:Name="image" HorizontalAlignment="Left" Height="312" Margin="70,24,0,0" VerticalAlignment="Top" Width="200" Source="main.png" Stretch="Fill"/>
2222
<ProgressBar Name="pbStatus" HorizontalAlignment="Left" Height="11" Margin="120,414,0,0" VerticalAlignment="Top" Width="100"/>
23-
24-
2523
</Grid>
2624
</Window>

Zero2UndubProcess/ExternalProcesses.cs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Diagnostics;
3+
using System.IO;
34

45
namespace Zero2UndubProcess
56
{
@@ -52,5 +53,82 @@ public static bool MfAudioCompress(Zero2File file, AudioFileInfo audioFile, int
5253

5354
return true;
5455
}
56+
57+
public static void PssSwitchAudio(int fileId, string folder)
58+
{
59+
folder = folder.Replace("/", "\\");
60+
PssDemux(fileId, "us", folder);
61+
PssDemux(fileId, "jp", folder);
62+
PssMux(fileId, folder);
63+
}
64+
65+
public static void PssDemux(int fileId, string region, string folder)
66+
{
67+
var args =
68+
$"D /N \"{folder}\\{fileId}_{region}.PSS\" \"{folder}\\{fileId}_{region}.M2V\" \"{folder}\\{fileId}_{region}.WAV\"";
69+
70+
var process = new Process
71+
{
72+
StartInfo =
73+
{
74+
FileName = "PSS_Plex.exe",
75+
UseShellExecute = false,
76+
CreateNoWindow = false,
77+
Arguments = args
78+
}
79+
};
80+
81+
process.Start();
82+
83+
if (!process.WaitForExit(10000))
84+
{
85+
try
86+
{
87+
process.Kill(true);
88+
Console.WriteLine($"Extracting audio file: {fileId} took too long, it was killed!");
89+
}
90+
catch (InvalidOperationException)
91+
{
92+
}
93+
}
94+
95+
File.Delete($"{folder}/{fileId}_{region}.PSS");
96+
}
97+
98+
public static void PssMux(int fileId, string folder)
99+
{
100+
var args = $"M /N \"{folder}\\{fileId}_us.M2V\" \"{folder}\\{fileId}_jp.WAV\" \"{folder}\\{fileId}.PSS\"";
101+
102+
var process = new Process
103+
{
104+
StartInfo =
105+
{
106+
FileName = "PSS_Plex.exe",
107+
UseShellExecute = false,
108+
CreateNoWindow = false,
109+
Arguments = args
110+
}
111+
};
112+
113+
process.Start();
114+
115+
if (!process.WaitForExit(10000))
116+
{
117+
try
118+
{
119+
process.Kill(true);
120+
Console.WriteLine($"Extracting video file: {fileId} took too long, it was killed!");
121+
}
122+
catch (InvalidOperationException)
123+
{
124+
}
125+
}
126+
127+
128+
File.Delete($"{folder}/{fileId}_us.WAV");
129+
File.Delete($"{folder}/{fileId}_jp.WAV");
130+
File.Delete($"{folder}/{fileId}_us.M2V");
131+
File.Delete($"{folder}/{fileId}_jp.M2V");
132+
}
55133
}
56134
}

Zero2UndubProcess/PSS_Plex.dll

30.5 KB
Binary file not shown.

Zero2UndubProcess/PSS_Plex.exe

183 KB
Binary file not shown.

Zero2UndubProcess/Zero2FileImporter.cs

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.IO;
3-
using System.Linq;
43

54
namespace Zero2UndubProcess
65
{
@@ -18,6 +17,7 @@ public class Zero2FileImporter
1817
private FileInfo JpIsoFile { get; set; }
1918
private FileInfo UsIsoFile { get; set; }
2019
private BinaryReader jpIsoData { get; set; }
20+
private BinaryReader usIsoDataRead { get; set; }
2121
private BinaryWriter usIsoData { get; set; }
2222
private Zero2TocFile _usFileDb { get; set; }
2323
private Zero2TocFile _jpFileDb { get; set; }
@@ -30,6 +30,7 @@ public Zero2FileImporter(string usIsoFile, string jpIsoFile)
3030
JpIsoFile = new FileInfo(jpIsoFile);
3131
jpIsoData = new BinaryReader(File.OpenRead(JpIsoFile.FullName));
3232
usIsoData = new BinaryWriter(File.OpenWrite(UsIsoFile.FullName));
33+
usIsoDataRead = new BinaryReader(File.OpenRead(tempFile.FullName));
3334
_usFileDb = Zero2TocFile.CreateUsFileDb();
3435
_jpFileDb = Zero2TocFile.CreateJpFileDb();
3536
}
@@ -63,7 +64,11 @@ public void UndubGame()
6364
}
6465
else if (currentFileJp.FileExtension == FileExtension.Audio)
6566
{
66-
CompressAudioFile(currentFileUs, currentFileJp);
67+
//CompressAudioFile(currentFileUs, currentFileJp);
68+
}
69+
else if (currentFileJp.FileExtension == FileExtension.Video)
70+
{
71+
PssAudioSwitch(currentFileJp, currentFileUs);
6772
}
6873
else
6974
{
@@ -86,6 +91,43 @@ public void UndubGame()
8691
IsSuccess = true;
8792
}
8893

94+
private void PssAudioSwitch(Zero2File jp, Zero2File us)
95+
{
96+
JpSeekFile(jp);
97+
var jpBuffer = jpIsoData.ReadBytes((int)jp.Size);
98+
99+
CreateFile($"{UsIsoFile.DirectoryName}/{jp.FileId}_jp.PSS", jpBuffer);
100+
101+
usIsoDataRead.BaseStream.Seek(ImgBinStartAddressInIso, SeekOrigin.Begin);
102+
usIsoDataRead.BaseStream.Seek(us.BinStartAddress, SeekOrigin.Current);
103+
104+
var usBuffer = usIsoDataRead.ReadBytes((int) us.Size);
105+
CreateFile($"{UsIsoFile.DirectoryName}/{us.FileId}_us.PSS", usBuffer);
106+
107+
ExternalProcesses.PssSwitchAudio(jp.FileId, UsIsoFile.DirectoryName);
108+
109+
var newVideoBuffer = File.ReadAllBytes($"{UsIsoFile.DirectoryName}/{us.FileId}.PSS");
110+
111+
File.Delete($"{UsIsoFile.DirectoryName}/{us.FileId}.PSS");
112+
113+
if (newVideoBuffer.Length > us.Size)
114+
{
115+
Console.WriteLine($"File {us.FileId} is too big to be imported");
116+
return;
117+
}
118+
119+
UsSeekFile(us);
120+
usIsoData.Write(newVideoBuffer);
121+
WriteFileNewSize(us.FileId, newVideoBuffer.Length);
122+
}
123+
124+
private void CreateFile(string fileName, byte[] buffer)
125+
{
126+
var file = File.Create(fileName);
127+
file.Write(buffer);
128+
file.Close();
129+
}
130+
89131
private void CompressAudioFile(Zero2File usFile, Zero2File jpFile)
90132
{
91133
/**

Zero2UndubProcess/Zero2UndubProcess.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
<None Update="MFAudio.exe">
1818
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
1919
</None>
20+
<None Update="PSS_Plex.dll">
21+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
22+
</None>
23+
<None Update="PSS_Plex.exe">
24+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
25+
</None>
2026
</ItemGroup>
2127

2228
</Project>

0 commit comments

Comments
 (0)