Jump to content
LaunchBox Community Forums

Naming PS2 games


Soop
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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;
        }

 

Link to comment
Share on other sites

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

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...