Skip to content

Commit

Permalink
Remove use of psxt001
Browse files Browse the repository at this point in the history
  • Loading branch information
mnadareski committed Dec 19, 2024
1 parent 4f48ccc commit 717590b
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
- Introduce maximum log length
- Print PS4/PS5 app.pkg info
- Ensure .NET versions are installed for testing
- Remove use of psxt001

### 3.2.4 (2024-11-24)

Expand Down
8 changes: 6 additions & 2 deletions MPF.Processors/DiscImageCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Linq;
#endif
using System.Text.RegularExpressions;
using psxt001z;
using SabreTools.Models.Logiqx;
using SabreTools.RedumpLib;
using SabreTools.RedumpLib.Data;
Expand Down Expand Up @@ -956,8 +955,13 @@ internal static bool GetDiscType(string disc, out string? discTypeOrBookType)

try
{
#if NET20
// Create a list to contain all of the found values
var discTypeOrBookTypeSet = new List<string>();
#else
// Create a hashset to contain all of the found values
var discTypeOrBookTypeSet = new HashSet<string>();
#endif

using var sr = File.OpenText(disc);
var line = sr.ReadLine();
Expand Down Expand Up @@ -1346,7 +1350,7 @@ private static void GetLibCryptDetected(string basePath, out YesNo detected, out
return;
}

if (!LibCrypt.DetectLibCrypt([subPath]))
if (!ProcessingTool.DetectLibCrypt(subPath))
{
detected = YesNo.No;
data = null;
Expand Down
1 change: 0 additions & 1 deletion MPF.Processors/MPF.Processors.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="psxt001z.Library" Version="0.21.0-rc2" />
<PackageReference Include="SabreTools.Hashing" Version="1.4.1" />
<PackageReference Include="SabreTools.Models" Version="1.5.8" />
<PackageReference Include="SabreTools.RedumpLib" Version="1.6.2" />
Expand Down
101 changes: 101 additions & 0 deletions MPF.Processors/ProcessingTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
using SabreTools.Hashing;
using SabreTools.IO.Extensions;
using SabreTools.Matching;
using SabreTools.Models.Logiqx;
using SabreTools.Models.PIC;
using SabreTools.RedumpLib.Data;
Expand Down Expand Up @@ -421,6 +423,105 @@ static int ReadFromArrayBigEndian(byte[]? bytes, int offset)

#endregion

#region PlayStation specific tools

/// <summary>
/// Get if LibCrypt data is detected in the subchannel file, if possible
/// </summary>
/// <param name="subPath">Path to the subchannel file</param>
/// <returns>True if LibCrypt was detected, false otherwise</returns>
public static bool DetectLibCrypt(string? subPath)
{
if (string.IsNullOrEmpty(subPath))
return false;

// Create conversion delegates
byte _btoi(byte b) => (byte)(b / 16 * 10 + b % 16);
byte _itob(byte i) => (byte)(i / 10 * 16 + i % 10);

try
{
if (!File.Exists(subPath))
return false;

// Open the subfile
var subFile = File.OpenRead(subPath);

// Check the size
long size = subFile.Length;
if (size % 96 != 0)
return false;

byte[] sub = new byte[12];
uint tpos = 0;

for (uint sector = 150; sector < ((size / 96) + 150); sector++)
{
// Read the sector header
subFile.Seek(12, SeekOrigin.Current);
byte[] buffer = subFile.ReadBytes(12);

// Skip the rest of the data for the sector
subFile.Seek(72, SeekOrigin.Current);

// New track
if ((_btoi(buffer[1]) == (_btoi(sub[1]) + 1)) && (buffer[2] == 0 || buffer[2] == 1))
{
Array.Copy(buffer, sub, 6);
tpos = (uint)((_btoi((byte)(buffer[3] * 60)) + _btoi(buffer[4])) * 75) + _btoi(buffer[5]);
}

// New index
else if (_btoi(buffer[2]) == (_btoi(sub[2]) + 1) && buffer[1] == sub[1])
{
Array.Copy(buffer, 2, sub, 2, 4);
tpos = (uint)((_btoi((byte)(buffer[3] * 60)) + _btoi(buffer[4])) * 75) + _btoi(buffer[5]);
}

// MSF1 [3-5]
else
{
if (sub[2] == 0)
tpos--;
else
tpos++;

sub[3] = _itob((byte)(tpos / 60 / 75));
sub[4] = _itob((byte)((tpos / 75) % 60));
sub[5] = _itob((byte)(tpos % 75));
}

// Force skip [6]
buffer[6] = sub[6] = 0;

// MSF2 [7-9]
sub[7] = _itob((byte)(sector / 60 / 75));
sub[8] = _itob((byte)((sector / 75) % 60));
sub[9] = _itob((byte)(sector % 75));

// CRC-16 [10-11]
var crcWrapper = new HashWrapper(HashType.CRC16);
crcWrapper.Process(sub, 0, 10);
byte[] crc = crcWrapper.CurrentHashBytes!;
sub[10] = crc[0];
sub[11] = crc[1];

// If a LibCrypt sector is detected
if (!buffer.EqualsExactly(sub))
return true;
}
}
catch
{
// We are not concerned with the error
return false;
}

return true;
}

#endregion

#region PlayStation 3 specific tools

/// <summary>
Expand Down

0 comments on commit 717590b

Please sign in to comment.