mirror of
https://github.com/SabreTools/MPF.git
synced 2026-07-02 17:24:48 +00:00
Fix logic for deducing region from PlayStation ISN (#724)
* Deduce PS2 region from Redumper serial * Fix logic for deducing region from PlayStation ISN * Fix logic again * Fix logic again again * Fix this too * Undo Redumper change * Reorder functions * Fix OR/AND logic
This commit is contained in:
@@ -10,6 +10,7 @@ using Microsoft.Management.Infrastructure.Generic;
|
||||
#endif
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using MPF.Processors;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.RedumpLib.Data;
|
||||
|
||||
@@ -328,7 +329,7 @@ namespace MPF.Frontend
|
||||
.Replace(".", string.Empty);
|
||||
|
||||
// Get the region, if possible
|
||||
region = GetPlayStationRegion(exeName);
|
||||
region = ProcessingTool.GetPlayStationRegion(exeName);
|
||||
|
||||
// Now that we have the EXE name, try to get the fileinfo for it
|
||||
string exePath = Path.Combine(Name, exeName);
|
||||
@@ -344,91 +345,6 @@ namespace MPF.Frontend
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determine the region based on the PlayStation serial code
|
||||
/// </summary>
|
||||
/// <param name="serial">PlayStation serial code</param>
|
||||
/// <returns>Region mapped from name, if possible</returns>
|
||||
public static Region? GetPlayStationRegion(string? serial)
|
||||
{
|
||||
// If we have a fully invalid serial
|
||||
if (string.IsNullOrEmpty(serial))
|
||||
return null;
|
||||
|
||||
// Standardized "S" serials
|
||||
if (serial!.StartsWith("S"))
|
||||
{
|
||||
// string publisher = serial[0] + serial[1];
|
||||
// char secondRegion = serial[3];
|
||||
switch (serial[2])
|
||||
{
|
||||
case 'A': return Region.Asia;
|
||||
case 'C': return Region.China;
|
||||
case 'E': return Region.Europe;
|
||||
case 'K': return Region.SouthKorea;
|
||||
case 'U': return Region.UnitedStatesOfAmerica;
|
||||
case 'P':
|
||||
// Region of S_P_ serials may be Japan, Asia, or SouthKorea
|
||||
return serial[3] switch
|
||||
{
|
||||
// Check first two digits of S_PS serial
|
||||
'S' => (Region?)(serial.Substring(5, 2) switch
|
||||
{
|
||||
"46" => Region.SouthKorea,
|
||||
"51" => Region.Asia,
|
||||
"56" => Region.SouthKorea,
|
||||
"55" => Region.Asia,
|
||||
_ => Region.Japan,
|
||||
}),
|
||||
|
||||
// Check first three digits of S_PM serial
|
||||
'M' => (Region?)(serial.Substring(5, 3) switch
|
||||
{
|
||||
"645" => Region.SouthKorea,
|
||||
"675" => Region.SouthKorea,
|
||||
"885" => Region.SouthKorea,
|
||||
_ => Region.Japan, // Remaining S_PM serials may be Japan or Asia
|
||||
}),
|
||||
_ => (Region?)Region.Japan,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Japan-only special serial
|
||||
else if (serial.StartsWith("PAPX"))
|
||||
return Region.Japan;
|
||||
|
||||
// Region appears entirely random
|
||||
else if (serial.StartsWith("PABX"))
|
||||
return null;
|
||||
|
||||
// Region appears entirely random
|
||||
else if (serial.StartsWith("PBPX"))
|
||||
return null;
|
||||
|
||||
// Japan-only special serial
|
||||
else if (serial.StartsWith("PCBX"))
|
||||
return Region.Japan;
|
||||
|
||||
// Japan-only special serial
|
||||
else if (serial.StartsWith("PCXC"))
|
||||
return Region.Japan;
|
||||
|
||||
// Single disc known, Japan
|
||||
else if (serial.StartsWith("PDBX"))
|
||||
return Region.Japan;
|
||||
|
||||
// Single disc known, Europe
|
||||
else if (serial.StartsWith("PEBX"))
|
||||
return Region.Europe;
|
||||
|
||||
// Single disc known, USA
|
||||
else if (serial.StartsWith("PUBX"))
|
||||
return Region.UnitedStatesOfAmerica;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the version from a PlayStation 2 disc, if possible
|
||||
/// </summary>
|
||||
|
||||
@@ -698,8 +698,8 @@ namespace MPF.Frontend.Tools
|
||||
if (isDiscImageCreator)
|
||||
info.CommonDiscInfo!.EXEDateBuildDate = DiscImageCreator.GetPlayStationEXEDate($"{basePath}_volDesc.txt", drive?.GetPlayStationExecutableName());
|
||||
|
||||
if (!info.CommonDiscInfo!.CommentsSpecialFields!.TryGetValue(SiteCode.InternalSerialName, out string? kp2Exe) || string.IsNullOrEmpty(kp2Exe))
|
||||
info.CommonDiscInfo.Region = Drive.GetPlayStationRegion(kp2Exe);
|
||||
if (info.CommonDiscInfo!.CommentsSpecialFields!.TryGetValue(SiteCode.InternalSerialName, out string? kp2Exe) && !string.IsNullOrEmpty(kp2Exe))
|
||||
info.CommonDiscInfo.Region = ProcessingTool.GetPlayStationRegion(kp2Exe);
|
||||
|
||||
if (drive?.GetPlayStationExecutableInfo(out var kp2Serial, out Region? kp2Region, out var kp2Date) == true)
|
||||
{
|
||||
@@ -812,8 +812,8 @@ namespace MPF.Frontend.Tools
|
||||
if (isDiscImageCreator)
|
||||
info.CommonDiscInfo!.EXEDateBuildDate = DiscImageCreator.GetPlayStationEXEDate($"{basePath}_volDesc.txt", drive?.GetPlayStationExecutableName(), psx: true);
|
||||
|
||||
if (!info.CommonDiscInfo!.CommentsSpecialFields!.TryGetValue(SiteCode.InternalSerialName, out string? psxExe) || string.IsNullOrEmpty(psxExe))
|
||||
info.CommonDiscInfo.Region = Drive.GetPlayStationRegion(psxExe);
|
||||
if (info.CommonDiscInfo!.CommentsSpecialFields!.TryGetValue(SiteCode.InternalSerialName, out string? psxExe) && !string.IsNullOrEmpty(psxExe))
|
||||
info.CommonDiscInfo.Region = ProcessingTool.GetPlayStationRegion(psxExe);
|
||||
|
||||
if (drive?.GetPlayStationExecutableInfo(out var psxSerial, out Region? psxRegion, out var psxDate) == true)
|
||||
{
|
||||
@@ -833,8 +833,8 @@ namespace MPF.Frontend.Tools
|
||||
if (isDiscImageCreator)
|
||||
info.CommonDiscInfo!.EXEDateBuildDate = DiscImageCreator.GetPlayStationEXEDate($"{basePath}_volDesc.txt", drive?.GetPlayStationExecutableName());
|
||||
|
||||
if (!info.CommonDiscInfo!.CommentsSpecialFields!.TryGetValue(SiteCode.InternalSerialName, out string? ps2Exe) || string.IsNullOrEmpty(ps2Exe))
|
||||
info.CommonDiscInfo.Region = Drive.GetPlayStationRegion(ps2Exe);
|
||||
if (info.CommonDiscInfo!.CommentsSpecialFields!.TryGetValue(SiteCode.InternalSerialName, out string? ps2Exe) && !string.IsNullOrEmpty(ps2Exe))
|
||||
info.CommonDiscInfo.Region = ProcessingTool.GetPlayStationRegion(ps2Exe);
|
||||
|
||||
if (drive?.GetPlayStationExecutableInfo(out var ps2Serial, out Region? ps2Region, out var ps2Date) == true)
|
||||
{
|
||||
|
||||
@@ -352,6 +352,91 @@ namespace MPF.Processors
|
||||
|
||||
#region Region Extraction
|
||||
|
||||
/// <summary>
|
||||
/// Determine the region based on the PlayStation serial code
|
||||
/// </summary>
|
||||
/// <param name="serial">PlayStation serial code</param>
|
||||
/// <returns>Region mapped from name, if possible</returns>
|
||||
public static Region? GetPlayStationRegion(string? serial)
|
||||
{
|
||||
// If we have a fully invalid serial
|
||||
if (string.IsNullOrEmpty(serial))
|
||||
return null;
|
||||
|
||||
// Standardized "S" serials
|
||||
if (serial!.StartsWith("S"))
|
||||
{
|
||||
// string publisher = serial[0] + serial[1];
|
||||
// char secondRegion = serial[3];
|
||||
switch (serial[2])
|
||||
{
|
||||
case 'A': return Region.Asia;
|
||||
case 'C': return Region.China;
|
||||
case 'E': return Region.Europe;
|
||||
case 'K': return Region.SouthKorea;
|
||||
case 'U': return Region.UnitedStatesOfAmerica;
|
||||
case 'P':
|
||||
// Region of S_P_ serials may be Japan, Asia, or SouthKorea
|
||||
return serial[3] switch
|
||||
{
|
||||
// Check first two digits of S_PS serial
|
||||
'S' => (Region?)(serial.Substring(5, 2) switch
|
||||
{
|
||||
"46" => Region.SouthKorea,
|
||||
"51" => Region.Asia,
|
||||
"56" => Region.SouthKorea,
|
||||
"55" => Region.Asia,
|
||||
_ => Region.Japan,
|
||||
}),
|
||||
|
||||
// Check first three digits of S_PM serial
|
||||
'M' => (Region?)(serial.Substring(5, 3) switch
|
||||
{
|
||||
"645" => Region.SouthKorea,
|
||||
"675" => Region.SouthKorea,
|
||||
"885" => Region.SouthKorea,
|
||||
_ => Region.Japan, // Remaining S_PM serials may be Japan or Asia
|
||||
}),
|
||||
_ => (Region?)Region.Japan,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Japan-only special serial
|
||||
else if (serial.StartsWith("PAPX"))
|
||||
return Region.Japan;
|
||||
|
||||
// Region appears entirely random
|
||||
else if (serial.StartsWith("PABX"))
|
||||
return null;
|
||||
|
||||
// Region appears entirely random
|
||||
else if (serial.StartsWith("PBPX"))
|
||||
return null;
|
||||
|
||||
// Japan-only special serial
|
||||
else if (serial.StartsWith("PCBX"))
|
||||
return Region.Japan;
|
||||
|
||||
// Japan-only special serial
|
||||
else if (serial.StartsWith("PCXC"))
|
||||
return Region.Japan;
|
||||
|
||||
// Single disc known, Japan
|
||||
else if (serial.StartsWith("PDBX"))
|
||||
return Region.Japan;
|
||||
|
||||
// Single disc known, Europe
|
||||
else if (serial.StartsWith("PEBX"))
|
||||
return Region.Europe;
|
||||
|
||||
// Single disc known, USA
|
||||
else if (serial.StartsWith("PUBX"))
|
||||
return Region.UnitedStatesOfAmerica;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determine the region based on the XGD serial character
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user