Add DLC Support

This commit is contained in:
Li 2023-07-10 12:25:35 +12:00
parent 4c38ee8972
commit 56439d95ad
5 changed files with 109 additions and 21 deletions

9
.gitignore vendored Normal file
View File

@ -0,0 +1,9 @@
.vs/*
*/obj/*
*/bin/*
CHOVY-GEN/Debug/*
CHOVY-GEN/Release/*
CHOVY-TRANSFER/obj/*
CHOVY-TRANSFER/bin/*

View File

@ -29,32 +29,32 @@
<ProjectGuid>{DCDBF747-DFB6-450E-A403-1C592D20EAEB}</ProjectGuid> <ProjectGuid>{DCDBF747-DFB6-450E-A403-1C592D20EAEB}</ProjectGuid>
<Keyword>Win32Proj</Keyword> <Keyword>Win32Proj</Keyword>
<RootNamespace>CHOVYGEN</RootNamespace> <RootNamespace>CHOVYGEN</RootNamespace>
<WindowsTargetPlatformVersion>10.0.14393.0</WindowsTargetPlatformVersion> <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset> <PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset> <PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset> <PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset> <PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>

View File

@ -43,6 +43,7 @@
this.progressStatus = new System.Windows.Forms.Label(); this.progressStatus = new System.Windows.Forms.Label();
this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.dexToggle = new System.Windows.Forms.PictureBox(); this.dexToggle = new System.Windows.Forms.PictureBox();
this.currentFile = new System.Windows.Forms.Label();
this.groupBox1.SuspendLayout(); this.groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dexToggle)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dexToggle)).BeginInit();
@ -247,7 +248,7 @@
this.pictureBox1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.pictureBox1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.pictureBox1.Location = new System.Drawing.Point(9, 8); this.pictureBox1.Location = new System.Drawing.Point(9, 8);
this.pictureBox1.Name = "pictureBox1"; this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(144, 317); this.pictureBox1.Size = new System.Drawing.Size(144, 330);
this.pictureBox1.TabIndex = 9; this.pictureBox1.TabIndex = 9;
this.pictureBox1.TabStop = false; this.pictureBox1.TabStop = false;
// //
@ -260,12 +261,23 @@
this.dexToggle.TabStop = false; this.dexToggle.TabStop = false;
this.dexToggle.Click += new System.EventHandler(this.dexToggle_Click); this.dexToggle.Click += new System.EventHandler(this.dexToggle_Click);
// //
// currentFile
//
this.currentFile.AutoSize = true;
this.currentFile.ForeColor = System.Drawing.Color.Lime;
this.currentFile.Location = new System.Drawing.Point(173, 328);
this.currentFile.Name = "currentFile";
this.currentFile.Size = new System.Drawing.Size(55, 13);
this.currentFile.TabIndex = 11;
this.currentFile.Text = "Waiting ...";
//
// CHOVYTRANSFER // CHOVYTRANSFER
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.Black; this.BackColor = System.Drawing.Color.Black;
this.ClientSize = new System.Drawing.Size(796, 332); this.ClientSize = new System.Drawing.Size(796, 350);
this.Controls.Add(this.currentFile);
this.Controls.Add(this.dexToggle); this.Controls.Add(this.dexToggle);
this.Controls.Add(this.pictureBox1); this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.progressStatus); this.Controls.Add(this.progressStatus);
@ -303,6 +315,7 @@
private System.Windows.Forms.Label progressStatus; private System.Windows.Forms.Label progressStatus;
private System.Windows.Forms.PictureBox pictureBox1; private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.PictureBox dexToggle; private System.Windows.Forms.PictureBox dexToggle;
private System.Windows.Forms.Label currentFile;
} }
} }

View File

@ -9,6 +9,8 @@ using KeyDerivation;
using PSVIMGTOOLS; using PSVIMGTOOLS;
using System.Drawing; using System.Drawing;
using System.Threading; using System.Threading;
using System.Collections.Generic;
using System.Linq;
namespace CHOVY_TRANSFER namespace CHOVY_TRANSFER
{ {
@ -152,12 +154,13 @@ namespace CHOVY_TRANSFER
try try
{ {
string EbootPbp = Path.Combine(game, "EBOOT.PBP"); string EbootPbp = Path.Combine(game, "EBOOT.PBP");
if (!File.Exists(EbootPbp))
EbootPbp = Path.Combine(game, "PARAM.PBP");
string TitleId = Path.GetFileName(game); string TitleId = Path.GetFileName(game);
string Title = GetTitleFromPbp(EbootPbp); string Title = GetTitleFromPbp(EbootPbp);
string ContentId = GetContentIdFromPbp(EbootPbp); string ContentId = GetContentIdFromPbp(EbootPbp);
string LicenseFile = Path.Combine(PspDir, "LICENSE", ContentId); string LicenseFile = Path.Combine(PspDir, "LICENSE", ContentId);
if (TitleId.Length == 9 && File.Exists(LicenseFile)); if (TitleId.Length == 9 && File.Exists(LicenseFile));
@ -173,6 +176,21 @@ namespace CHOVY_TRANSFER
catch (Exception) { }; catch (Exception) { };
} }
public string[] SearchEdats(string gameFolder)
{
List<string> contentIds = new List<string>();
foreach(string file in Directory.GetFiles(gameFolder, "*", SearchOption.AllDirectories))
{
if(Path.GetExtension(file).ToUpperInvariant() == ".EDAT")
{
string contentId = GetContentIdFromPspEdat(file);
contentIds.Add(contentId);
}
}
return contentIds.ToArray();
}
public string GetTitleFromPbp(string pbp) public string GetTitleFromPbp(string pbp)
{ {
byte[] SfoData = GetSfo(pbp); byte[] SfoData = GetSfo(pbp);
@ -191,8 +209,6 @@ namespace CHOVY_TRANSFER
int sfoOffset = ReadInt32(pbps); int sfoOffset = ReadInt32(pbps);
int sfoSize = ReadInt32(pbps); int sfoSize = ReadInt32(pbps);
pbps.Seek(sfoOffset, SeekOrigin.Begin); pbps.Seek(sfoOffset, SeekOrigin.Begin);
sfoSize -= (int)pbps.Position; sfoSize -= (int)pbps.Position;
@ -218,7 +234,15 @@ namespace CHOVY_TRANSFER
pbps.Dispose(); pbps.Dispose();
return IconData; return IconData;
} }
public string GetContentIdFromPspEdat(string edat)
{
FileStream edats = File.OpenRead(edat);
edats.Seek(0x10, SeekOrigin.Begin);
byte[] ContentId = new byte[0x24];
edats.Read(ContentId, 0x00, 0x24);
edats.Close();
return Encoding.UTF8.GetString(ContentId);
}
public string GetContentIdFromPs1Pbp(string pbp) public string GetContentIdFromPs1Pbp(string pbp)
{ {
FileStream pbps = File.OpenRead(pbp); FileStream pbps = File.OpenRead(pbp);
@ -230,8 +254,7 @@ namespace CHOVY_TRANSFER
pbps.Close(); pbps.Close();
return Encoding.UTF8.GetString(ContentId); return Encoding.UTF8.GetString(ContentId);
} }
public bool IsPsp(string pbp)
public bool IsPs1(string pbp)
{ {
FileStream pbps = File.OpenRead(pbp); FileStream pbps = File.OpenRead(pbp);
pbps.Seek(0x24, SeekOrigin.Begin); pbps.Seek(0x24, SeekOrigin.Begin);
@ -241,6 +264,26 @@ namespace CHOVY_TRANSFER
pbps.Read(Header, 0x00, 0x8); pbps.Read(Header, 0x00, 0x8);
pbps.Close(); pbps.Close();
string header = Encoding.UTF8.GetString(Header); string header = Encoding.UTF8.GetString(Header);
if (header == "NPUMDIMG")
{
return true;
}
else
{
return false;
}
}
public bool IsPs1(string pbp)
{
FileStream pbps = File.OpenRead(pbp);
pbps.Seek(0x24, SeekOrigin.Begin);
Int64 PSIMGOffest = ReadInt32(pbps);
pbps.Seek(PSIMGOffest, SeekOrigin.Begin);
byte[] Header = new byte[0x8];
pbps.Read(Header, 0x00, 0x8);
pbps.Close();
string header = Encoding.UTF8.GetString(Header);
if (header == "PSISOIMG" /*Single Disc PSX*/ || header == "PSTITLEI" /*Multi Disc PSX*/) if (header == "PSISOIMG" /*Single Disc PSX*/ || header == "PSTITLEI" /*Multi Disc PSX*/)
{ {
return true; return true;
@ -257,10 +300,17 @@ namespace CHOVY_TRANSFER
{ {
return GetContentIdFromPs1Pbp(pbp); return GetContentIdFromPs1Pbp(pbp);
} }
else else if(IsPsp(pbp))
{ {
return GetContentIdFromPspPbp(pbp); return GetContentIdFromPspPbp(pbp);
} }
else
{
string[] cids = SearchEdats(Path.GetDirectoryName(pbp));
if (cids.Length <= 0)
return "";
return cids.First();
}
} }
public string GetContentIdFromPspPbp(string pbp) public string GetContentIdFromPspPbp(string pbp)
@ -357,14 +407,19 @@ namespace CHOVY_TRANSFER
string titleId = pspGames.SelectedItem.ToString().Substring(0, 9); string titleId = pspGames.SelectedItem.ToString().Substring(0, 9);
string gameFolder = Path.Combine(driveLetterSrc.Text, pspFolder.Text, "GAME", titleId); string gameFolder = Path.Combine(driveLetterSrc.Text, pspFolder.Text, "GAME", titleId);
string ebootFile = Path.Combine(gameFolder, "EBOOT.PBP"); string ebootFile = Path.Combine(gameFolder, "EBOOT.PBP");
if (!File.Exists(ebootFile))
ebootFile = Path.Combine(gameFolder, "PARAM.PBP");
List<string> licenseFiles = new List<string>();
string cid = GetContentIdFromPbp(ebootFile); string cid = GetContentIdFromPbp(ebootFile);
string licenseFile = Path.Combine(driveLetterSrc.Text, pspFolder.Text, "LICENSE", cid + ".RIF"); licenseFiles.Add(Path.Combine(driveLetterSrc.Text, pspFolder.Text, "LICENSE", cid + ".RIF"));
string sigFile = Path.Combine(gameFolder, "__sce_ebootpbp"); string sigFile = Path.Combine(gameFolder, "__sce_ebootpbp");
string backupDir = Path.Combine(driveLetterDst.Text, cmaDir.Text); string backupDir = Path.Combine(driveLetterDst.Text, cmaDir.Text);
bool isDlc = Path.GetFileName(gameFolder) == "PARAM.PBP";
bool isPs1 = IsPs1(ebootFile); bool isPs1 = IsPs1(ebootFile);
if (!File.Exists(licenseFile)) if (!File.Exists(licenseFiles.First()))
{ {
MessageBox.Show("Could not find LICENSE file!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Could not find LICENSE file!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
transVita.Enabled = true; transVita.Enabled = true;
@ -376,7 +431,7 @@ namespace CHOVY_TRANSFER
return; return;
} }
FileStream rif = File.OpenRead(licenseFile); FileStream rif = File.OpenRead(licenseFiles.First());
byte[] bAid = new byte[0x08]; byte[] bAid = new byte[0x08];
rif.Seek(0x08, SeekOrigin.Begin); rif.Seek(0x08, SeekOrigin.Begin);
rif.Read(bAid, 0x00, 0x08); rif.Read(bAid, 0x00, 0x08);
@ -401,7 +456,7 @@ namespace CHOVY_TRANSFER
Application.DoEvents(); Application.DoEvents();
} }
if (!File.Exists(sigFile) || ChovyGenRes != 0) if (!File.Exists(sigFile) || ChovyGenRes != 0 && !isDlc)
{ {
MessageBox.Show("CHOVY-GEN Failed! Please check CHOVY.DLL exists\nand that the Microsoft Visual C++ 2015 Redistributable Update 3 RC is installed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("CHOVY-GEN Failed! Please check CHOVY.DLL exists\nand that the Microsoft Visual C++ 2015 Redistributable Update 3 RC is installed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
transVita.Enabled = true; transVita.Enabled = true;
@ -456,7 +511,7 @@ namespace CHOVY_TRANSFER
{ {
pgameFolder = Path.Combine(backupDir, "PGAME", "0000000000000000", titleId, "game"); pgameFolder = Path.Combine(backupDir, "PGAME", "0000000000000000", titleId, "game");
pgameFolderl = Path.Combine(backupDir, "PGAME", "0000000000000000", titleId, "license"); pgameFolderl = Path.Combine(backupDir, "PGAME", "0000000000000000", titleId, "license");
scesys = Path.Combine(backupDir, "PSGAME", "0000000000000000", titleId, "sce_sys"); scesys = Path.Combine(backupDir, "PGAME", "0000000000000000", titleId, "sce_sys");
} }
} }
@ -496,6 +551,14 @@ namespace CHOVY_TRANSFER
string relativePath = entry.Remove(0, gameFolder.Length); string relativePath = entry.Remove(0, gameFolder.Length);
relativePath = relativePath.Replace('\\', '/'); relativePath = relativePath.Replace('\\', '/');
if(Path.GetExtension(entry).ToUpperInvariant() == ".EDAT")
{
string edatContentId = GetContentIdFromPspEdat(entry);
string rifPath = Path.Combine(driveLetterSrc.Text, pspFolder.Text, "LICENSE", edatContentId + ".RIF");
if (!licenseFiles.Contains(rifPath) && File.Exists(rifPath))
licenseFiles.Add(rifPath);
}
bool isDir = File.GetAttributes(entry).HasFlag(FileAttributes.Directory); bool isDir = File.GetAttributes(entry).HasFlag(FileAttributes.Directory);
if (isDir) if (isDir)
@ -513,6 +576,7 @@ namespace CHOVY_TRANSFER
progressBar.Value = tBlocks; progressBar.Value = tBlocks;
decimal progress = Math.Floor(((decimal)tBlocks / (decimal)noBlocks) * 100); decimal progress = Math.Floor(((decimal)tBlocks / (decimal)noBlocks) * 100);
progressStatus.Text = progress.ToString() + "%"; progressStatus.Text = progress.ToString() + "%";
currentFile.Text = "Processing: " + Path.GetFileName(entry);
} }
catch (Exception) { } catch (Exception) { }
@ -533,7 +597,8 @@ namespace CHOVY_TRANSFER
FileStream licensePsvimg = File.OpenWrite(psvimgFilepathl); FileStream licensePsvimg = File.OpenWrite(psvimgFilepathl);
licensePsvimg.SetLength(0); licensePsvimg.SetLength(0);
builder = new PSVIMGBuilder(licensePsvimg, CmaKey); builder = new PSVIMGBuilder(licensePsvimg, CmaKey);
builder.AddFile(licenseFile, "ux0:pspemu/temp/game/PSP/LICENSE", "/" + cid + ".rif"); foreach(string licenseFile in licenseFiles)
builder.AddFile(licenseFile, "ux0:pspemu/temp/game/PSP/LICENSE", "/" + Path.GetFileNameWithoutExtension(licenseFile) + ".rif");
ContentSize = builder.Finish(); ContentSize = builder.Finish();
licensePsvimg = File.OpenRead(psvimgFilepathl); licensePsvimg = File.OpenRead(psvimgFilepathl);
@ -559,6 +624,7 @@ namespace CHOVY_TRANSFER
} }
progressBar.Value = 0; progressBar.Value = 0;
progressStatus.Text = "0%"; progressStatus.Text = "0%";
currentFile.Text = "Waiting ...";
transVita.Enabled = true; transVita.Enabled = true;
driveLetterDst.Enabled = true; driveLetterDst.Enabled = true;

BIN
Thumbs.db Normal file

Binary file not shown.