Soop Posted August 22, 2021 Share Posted August 22, 2021 I have an issue where I've used the tool to rip PS2 games for use on the PS2 internal HDD, and it's named the games appropriately with the SLUS xxx number. As far as I know, OPL still needs that code in order to run PS2 games. I'm trying to find the easiest solution that doesn't cause difficulties down the line. I could use regex to rename all these files, but that means if I decide to put the games on a PS2 hard drive, I have to recreate the SLUS code for each game somehow. Has anyone here encountered the same problem? Just weighing up my options before I commit. Quote Link to comment Share on other sites More sharing options...
jayjay Posted August 22, 2021 Share Posted August 22, 2021 (edited) What format are your roms in? iso or bin or? Edited August 22, 2021 by jayjay Quote Link to comment Share on other sites More sharing options...
Soop Posted August 22, 2021 Author Share Posted August 22, 2021 37 minutes ago, jayjay said: What format are your roms in? iso or bin or? Originally ISO but just finished converting them to .chd Quote Link to comment Share on other sites More sharing options...
jayjay Posted August 22, 2021 Share Posted August 22, 2021 Cant help with .chd or any other format other than iso or bin. I have some ugly c# code to get the SLUSXXXXX code from bin or iso. I assumed if your using them on PS2, your roms might be iso, I know nothing about PS2 homebrew. Anyway if you want the code I can post it. Quote Link to comment Share on other sites More sharing options...
Soop Posted August 22, 2021 Author Share Posted August 22, 2021 thanks, that's appreciated. Is the SLUS code inside the image somewhere, or does it reference an external database? My C# is a little rusty, but it might help! Quote Link to comment Share on other sites More sharing options...
jayjay Posted August 22, 2021 Share Posted August 22, 2021 Yeah its in the image. As I said its ugly. I was writing a save state manager type app for LB and pcsx2 saves the states using the blusXXXXX code. I never did finish it or clean up the code but it works. private string Get_Id_PCSX2(string romPath) { string id = string.Empty; if (romPath.ToLower().EndsWith(".iso") || romPath.ToLower().EndsWith(".bin")) { byte[] bytes = Get_Bytes(romPath, 0, 1000000); string s = GetIdFromString_PCSX2(Encoding.ASCII.GetString(bytes)); if (!string.IsNullOrEmpty(Check_Id(s.Replace("-", "")))) { return s; } } else { return string.Empty; } return id; } private byte[] Get_Bytes(string path, int origin, int length) { byte[] data = new byte[length]; using (BinaryReader reader = new BinaryReader(new FileStream(path, FileMode.Open))) { reader.BaseStream.Seek(origin, SeekOrigin.Begin); reader.Read(data, 0, length); } return data; } private string GetIdFromString_PCSX2(string data) { string id = string.Empty; if (data.Contains("SCUS-")) //NTSC-U { int length = data.IndexOf("SCUS-"); id = data.Substring(length, 10); } else if (data.Contains("SCUS_")) //NTSC-U, contains underscore and period { int length = data.IndexOf("SCUS_"); id = CleanPS2(data.Substring(length, 11)); } else if (data.Contains("SLUS-")) //NTSC-U { int length = data.IndexOf("SLUS-"); id = data.Substring(length, 10); } else if (data.Contains("SLUS_")) //NTSC-U, contains underscore and period { int length = data.IndexOf("SLUS_"); id = CleanPS2(data.Substring(length, 11)); } else if (data.Contains("SLES-")) //PAL { int length = data.IndexOf("SCES-"); id = CleanPS2(data.Substring(length, 10)); } else if (data.Contains("SLES_")) //PAL, contains underscore and period { int length = data.IndexOf("SLES_"); id = CleanPS2(data.Substring(length, 11)); } else if (data.Contains("SCED-")) //PAL { int length = data.IndexOf("SCED-"); id = data.Substring(length, 10); } else if (data.Contains("SCED_")) //PAL { int length = data.IndexOf("SCED_"); id = CleanPS2(data.Substring(length, 11)); } else if (data.Contains("SCES-")) //PAL { int length = data.IndexOf("SCES-"); id = data.Substring(length, 10); } else if (data.Contains("SCES_")) //PAL, contains underscore and period { int length = data.IndexOf("SCES_"); id = CleanPS2(data.Substring(length, 11)); } else if (data.Contains("SLPM-")) //NTSC-J { int length = data.IndexOf("SLPM-"); id = data.Substring(length, 10); } else if (data.Contains("SLPM_")) //NTSC-J, contains underscore and period { int length = data.IndexOf("SLPM_"); id = CleanPS2(data.Substring(length, 11)); } else if (data.Contains("SLPS-")) //NTSC-J { int length = data.IndexOf("SLPS-"); id = data.Substring(length, 10); } else if (data.Contains("SLPS_")) ////NTSC-J, contains underscore and period { int length = data.IndexOf("SLPS_"); id = CleanPS2(data.Substring(length, 11)); } else if (data.Contains("PBPX-")) { int length = data.IndexOf("PBPX-"); id = data.Substring(length, 10); } else if (data.Contains("PBPX_")) { int length = data.IndexOf("PBPX_"); id = CleanPS2(data.Substring(length, 11)); } else if (data.Contains("PCPX-")) //NTSC-J { int length = data.IndexOf("PCPX-"); id = data.Substring(length, 10); } else if (data.Contains("PCPX_")) //NTSC-J, contains underscore and period { int length = data.IndexOf("PCPX_"); id = CleanPS2(data.Substring(length, 11)); } else if (data.Contains("SCAJ-")) //NTSC-J { int length = data.IndexOf("SCAJ-"); id = data.Substring(length, 10); } else if (data.Contains("SCAJ_")) //NTSC-J, contains underscore and period { int length = data.IndexOf("SCAJ_"); id = CleanPS2(data.Substring(length, 11)); } else if (data.Contains("SCKA-")) //NTSC-K { int length = data.IndexOf("SCKA-"); id = data.Substring(length, 10); } else if (data.Contains("SCKA_")) //NTSC-K , contains underscore and period { int length = data.IndexOf("SCKA_"); id = CleanPS2(data.Substring(length, 11)); } if (id.Length == 11) { id = id.Remove(8, 1); } return id; } private string CleanPS2(string s) { StringBuilder sb = new StringBuilder(s); sb.Replace(" ", ""); sb.Replace("_", "-"); sb.Replace(".", ""); return sb.ToString(); } private string Check_Id(string id) { foreach (char c in id) { if (!char.IsUpper(c) && !char.IsNumber(c)) { return string.Empty; } } return id; } Quote Link to comment Share on other sites More sharing options...
Soop Posted August 22, 2021 Author Share Posted August 22, 2021 ok, sweet, I think I get the gist of it. I think the main takeway is that it is possible to recreate a useable filename from the image itself, in which case I shou;d be fine to rename the files knowing I won't have to manually recreate the necessary filenames later. I might have a go at repurposing your code at some point for file naming, maybe in Python. If I do, I'll let you know and hand the code back 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.