3 Commits
Author SHA1 Message Date
Deterous 82d53db68f Bump version 2024-04-11 18:18:45 +09:00
Deterous f8a9c8515d Relax ISO requirements 2024-04-11 18:18:17 +09:00
Deterous 0ef06c36e9 Fix rename functionality, mention in reademe 2024-03-25 13:27:56 +09:00
6 changed files with 85 additions and 39 deletions
+1 -1
View File
@@ -11,7 +11,7 @@
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings> <SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Version>0.9.0</Version> <Version>0.9.2</Version>
<!-- Package Properties --> <!-- Package Properties -->
<Authors>Deterous</Authors> <Authors>Deterous</Authors>
+9 -4
View File
@@ -97,6 +97,9 @@ namespace IRDKit
[Option('s', "serial", HelpText = "Appends disc serial to new IRD filename")] [Option('s', "serial", HelpText = "Appends disc serial to new IRD filename")]
public bool Serial { get; set; } public bool Serial { get; set; }
[Option('e', "version", HelpText = "Appends disc version to new IRD filename")]
public bool Ver { get; set; }
[Option('c', "crc", HelpText = "Appends ISO CRC to new IRD filename")] [Option('c', "crc", HelpText = "Appends ISO CRC to new IRD filename")]
public bool CRC { get; set; } public bool CRC { get; set; }
@@ -414,7 +417,7 @@ namespace IRDKit
{ {
try try
{ {
RenameIRD(file, datfile, serial: opt.Serial, crc: opt.CRC, verbose: opt.Verbose); RenameIRD(file, datfile, serial: opt.Serial, ver: opt.Ver, crc: opt.CRC, verbose: opt.Verbose);
} }
catch (Exception e) catch (Exception e)
{ {
@@ -435,7 +438,7 @@ namespace IRDKit
// Rename provided IRD path // Rename provided IRD path
try try
{ {
RenameIRD(irdPath, datfile, serial: opt.Serial, crc: opt.CRC, verbose: opt.Verbose); RenameIRD(irdPath, datfile, serial: opt.Serial, ver: opt.Ver, crc: opt.CRC, verbose: opt.Verbose);
} }
catch (Exception e) catch (Exception e)
{ {
@@ -1034,7 +1037,7 @@ namespace IRDKit
return node.Attribute("name").Value; return node.Attribute("name").Value;
} }
public static void RenameIRD(string irdPath, XDocument datfile, bool serial = false, bool crc = false, bool verbose = false) public static void RenameIRD(string irdPath, XDocument datfile, bool serial = false, bool ver = false, bool crc = false, bool verbose = false)
{ {
IRD ird = IRD.Read(irdPath); IRD ird = IRD.Read(irdPath);
@@ -1043,7 +1046,9 @@ namespace IRDKit
string filename = GetDatFilename(ird, datfile) ?? throw new ArgumentException($"Cannot determine DAT filename for {irdPath}"); string filename = GetDatFilename(ird, datfile) ?? throw new ArgumentException($"Cannot determine DAT filename for {irdPath}");
if (serial) if (serial)
filename += $" [{ird.TitleID.Substring(0, 4)}-{ird.TitleID.Substring(5, 5)}]"; filename += $" [{ird.TitleID.Substring(0, 4).Replace('\0', ' ')}-{ird.TitleID.Substring(4, 5).Replace('\0', ' ')}]";
if (ver)
filename += $" [{ird.DiscVersion.Replace('\0', ' ')}]";
if (crc) if (crc)
filename += $" [{ird.UID:X8}]"; filename += $" [{ird.UID:X8}]";
+6
View File
@@ -39,3 +39,9 @@ For all options, run `irdkit help diff`
To compare two IRDs, run `irdkit diff game1.ird game2.ird` To compare two IRDs, run `irdkit diff game1.ird game2.ird`
The comparison can be printed to a file, e.g. `-o out.txt` or `--output=` The comparison can be printed to a file, e.g. `-o out.txt` or `--output=`
## Renaming IRDs
For all options, run `irdkit help rename`
To rename an IRD (or folder of IRDs) according to a redump DAT, run `irdkit rename -d redump.dat game.ird`
+55 -20
View File
@@ -280,11 +280,6 @@ namespace LibIRD
/// <remarks>Last byte to read when reading the header</remarks> /// <remarks>Last byte to read when reading the header</remarks>
private long FirstDataSector { get; set; } private long FirstDataSector { get; set; }
/// <summary>
/// First byte of the PS3UPDAT.PUP file
/// </summary>
private long UpdateOffset { get; set; }
/// <summary> /// <summary>
/// Last byte of the PS3UPDAT.PUP file /// Last byte of the PS3UPDAT.PUP file
/// </summary> /// </summary>
@@ -652,6 +647,9 @@ namespace LibIRD
// Redump-style IRDs set the lowest bit of ExtraConfig to 1 // Redump-style IRDs set the lowest bit of ExtraConfig to 1
ExtraConfig |= 0x01; ExtraConfig |= 0x01;
// Try to get Title ID and Disc Version from PS3_DISC.SFB
try
{
// Redump-style IRDs use fields from PS3_DISC.SFB // Redump-style IRDs use fields from PS3_DISC.SFB
using SparseStream s = reader.OpenFile("PS3_DISC.SFB", FileMode.Open, FileAccess.Read); using SparseStream s = reader.OpenFile("PS3_DISC.SFB", FileMode.Open, FileAccess.Read);
@@ -669,10 +667,15 @@ namespace LibIRD
if (discVersionFound) if (discVersionFound)
DiscVersion = discVersion; DiscVersion = discVersion;
} }
catch { }
}
// Read PS3 Metadata from PARAM.SFO // Try to get Title ID, Title, Disc Version, and App Version from PARAM.SFO
using (SparseStream s = reader.OpenFile("\\PS3_GAME\\PARAM.SFO", FileMode.Open, FileAccess.Read)) try
{ {
// Read PS3 Metadata from PARAM.SFO
using SparseStream s = reader.OpenFile("\\PS3_GAME\\PARAM.SFO", FileMode.Open, FileAccess.Read);
// Parse PARAM.SFO file // Parse PARAM.SFO file
ParamSFO paramSFO = new(s); ParamSFO paramSFO = new(s);
@@ -707,18 +710,33 @@ namespace LibIRD
else else
AppVersion = "\0\0\0\0\0"; AppVersion = "\0\0\0\0\0";
} }
catch { }
// Determine system update version // Ensure Title ID is set and valid
if (string.IsNullOrEmpty(TitleID) || TitleID.Length != 9)
TitleID = "\0\0\0\0\0\0\0\0\0";
// Ensure Title is set
Title ??= string.Empty;
// Ensure Disc Version is set and valid
if (string.IsNullOrEmpty(DiscVersion) || DiscVersion.Length != 5)
DiscVersion = "\0\0\0\0\0";
// Ensure App Version is set and valid
if (string.IsNullOrEmpty(AppVersion) || AppVersion.Length != 5)
AppVersion = "\0\0\0\0\0";
// Try determine system update version
try
{
GetSystemVersion(fs, reader); GetSystemVersion(fs, reader);
}
catch { }
// Read and compress the ISO header // Ensure System Version was set and valid
GetHeader(fs, reader); if (string.IsNullOrEmpty(SystemVersion) || SystemVersion.Length != 4)
SystemVersion = "\0\0\0\0";
// Read and compress the ISO footer
GetFooter(fs);
// Get info region info from ISO
GetRegions(fs);
// Recursively count all files in ISO to allocate file arrays // Recursively count all files in ISO to allocate file arrays
DiscDirectoryInfo rootDir = reader.GetDirectoryInfo("\\"); DiscDirectoryInfo rootDir = reader.GetDirectoryInfo("\\");
@@ -747,6 +765,23 @@ namespace LibIRD
// Sort files by offset // Sort files by offset
Array.Sort(FileKeys, FileExtents); Array.Sort(FileKeys, FileExtents);
// Determine start of footer if no update file present
if (UpdateEnd == 0)
{
int lastFile = FileExtents.Length - 1;
int lastExtent = FileExtents[lastFile].Length - 1;
UpdateEnd = SectorSize * FileExtents[lastFile][lastExtent].Offset + FileExtents[lastFile][lastExtent].Count;
}
// Read and compress the ISO header
GetHeader(fs, reader);
// Read and compress the ISO footer
GetFooter(fs);
// Get info region info from ISO
GetRegions(fs);
// Calculate CRC32 hash of ISO only if generating a redump IRD and the UID is not already set // Calculate CRC32 hash of ISO only if generating a redump IRD and the UID is not already set
RegionHashes = new byte[RegionCount][]; RegionHashes = new byte[RegionCount][];
FileHashes = new byte[FileCount][]; FileHashes = new byte[FileCount][];
@@ -772,13 +807,13 @@ namespace LibIRD
throw new IOException("Invalid file extents for PS3UPDAT.PUP"); throw new IOException("Invalid file extents for PS3UPDAT.PUP");
// PS3UPDAT.PUP file begins at first byte of dedicated cluster // PS3UPDAT.PUP file begins at first byte of dedicated cluster
UpdateOffset = SectorSize * updateClusters[0].Offset; long updateOffset = SectorSize * updateClusters[0].Offset;
// Update file ends at the last byte of the last cluster // Update file ends at the last byte of the last cluster
int lastExtent = updateClusters.Length - 1; int lastExtent = updateClusters.Length - 1;
UpdateEnd = SectorSize * updateClusters[lastExtent].Offset + updateClusters[lastExtent].Count; UpdateEnd = SectorSize * updateClusters[lastExtent].Offset + updateClusters[lastExtent].Count;
// Check PUP file Magic // Check PUP file Magic
fs.Seek(UpdateOffset, SeekOrigin.Begin); fs.Seek(updateOffset, SeekOrigin.Begin);
byte[] pupMagic = new byte[5]; byte[] pupMagic = new byte[5];
fs.Read(pupMagic, 0, pupMagic.Length); fs.Read(pupMagic, 0, pupMagic.Length);
// If magic is incorrect, set version to all nulls, "\0\0\0\0" (unknown) // If magic is incorrect, set version to all nulls, "\0\0\0\0" (unknown)
@@ -787,13 +822,13 @@ namespace LibIRD
else else
{ {
// Determine location of version string // Determine location of version string
fs.Seek(UpdateOffset + 0x3E, SeekOrigin.Begin); fs.Seek(updateOffset + 0x3E, SeekOrigin.Begin);
byte[] offset = new byte[2]; byte[] offset = new byte[2];
fs.Read(offset, 0, 2); fs.Read(offset, 0, 2);
// Move stream to PUP version string // Move stream to PUP version string
Array.Reverse(offset); Array.Reverse(offset);
ushort versionOffset = BitConverter.ToUInt16(offset, 0); ushort versionOffset = BitConverter.ToUInt16(offset, 0);
fs.Seek(UpdateOffset + versionOffset, SeekOrigin.Begin); fs.Seek(updateOffset + versionOffset, SeekOrigin.Begin);
// Read version string // Read version string
byte[] version = new byte[4]; byte[] version = new byte[4];
fs.Read(version, 0, version.Length); fs.Read(version, 0, version.Length);
+1 -1
View File
@@ -7,7 +7,7 @@
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings> <SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Version>0.9.0</Version> <Version>0.9.1</Version>
<PackageOutputPath>../nupkg</PackageOutputPath> <PackageOutputPath>../nupkg</PackageOutputPath>
<!-- Package Properties --> <!-- Package Properties -->
+1 -1
View File
@@ -13,7 +13,7 @@ IRDKit is a tool that allows direct use of LibIRD functionality from a command l
- Printing info about all ISOs and IRDs in a folder: `irdkit info .` - Printing info about all ISOs and IRDs in a folder: `irdkit info .`
- Creating an IRD from an ISO: `irdkit create game.iso` - Creating an IRD from an ISO: `irdkit create game.iso`
- Finding differences between two IRDs: `irdkit diff game1.ird game2.ird` - Finding differences between two IRDs: `irdkit diff game1.ird game2.ird`
- Renaming a folder of IRDs using a redump DAT: `irdkit rename -d redump.dat IRDs\` - Renaming an IRD or folder of IRDs using a redump DAT: `irdkit rename -d redump.dat game.ird`
For detailed usage, read more [here](IRDKit). For detailed usage, read more [here](IRDKit).