Exemple #1
0
        public static GameInfo GetGameInfo(byte[] romData, string fileName)
        {
            CompactGameInfo cgi;
            var             hash = string.Format("{0:X8}", CRC32.Calculate(romData));

            if (db.TryGetValue(hash, out cgi))
            {
                return(new GameInfo(cgi));
            }

            hash = romData.HashMD5();
            if (db.TryGetValue(hash, out cgi))
            {
                return(new GameInfo(cgi));
            }

            hash = romData.HashSHA1();
            if (db.TryGetValue(hash, out cgi))
            {
                return(new GameInfo(cgi));
            }

            // rom is not in database. make some best-guesses
            var game = new GameInfo
            {
                Hash          = hash,
                Status        = RomStatus.NotInDatabase,
                NotInDatabase = true
            };

            Console.WriteLine(
                "Game was not in DB. CRC: {0:X8} MD5: {1}",
                CRC32.Calculate(romData),
                System.Security.Cryptography.MD5.Create().ComputeHash(romData).BytesToHexString());

            var ext = Path.GetExtension(fileName).ToUpperInvariant();

            switch (ext)
            {
            case ".NES":
            case ".UNF":
            case ".FDS":
                game.System = "NES";
                break;

            case ".SFC":
            case ".SMC":
                game.System = "SNES";
                break;

            case ".GB":
                game.System = "GB";
                break;

            case ".GBC":
                game.System = "GBC";
                break;

            case ".GBA":
                game.System = "GBA";
                break;

            case ".SMS":
                game.System = "SMS";
                break;

            case ".GG":
                game.System = "GG";
                break;

            case ".SG":
                game.System = "SG";
                break;

            case ".GEN":
            case ".MD":
            case ".SMD":
                game.System = "GEN";
                break;

            case ".PSF":
                game.System = "PSX";
                break;

            case ".PCE":
                game.System = "PCE";
                break;

            case ".SGX":
                game.System = "SGX";
                break;

            case ".A26":
                game.System = "A26";
                break;

            case ".A78":
                game.System = "A78";
                break;

            case ".COL":
                game.System = "Coleco";
                break;

            case ".INT":
                game.System = "INTV";
                break;

            case ".PRG":
            case ".D64":
            case ".T64":
            case ".G64":
            case ".CRT":
                game.System = "C64";
                break;

            case ".Z64":
            case ".V64":
            case ".N64":
                game.System = "N64";
                break;

            case ".DEBUG":
                game.System = "DEBUG";
                break;

            case ".WS":
            case ".WSC":
                game.System = "WSWAN";
                break;

            case ".LNX":
                game.System = "Lynx";
                break;

            case ".83P":
                game.System = "83P";
                break;

            case ".DSK":
            case ".PO":
            case ".DO":
                game.System = "AppleII";
                break;
            }

            game.Name = Path.GetFileNameWithoutExtension(fileName).Replace('_', ' ');

            // If filename is all-caps, then attempt to proper-case the title.
            if (game.Name == game.Name.ToUpperInvariant())
            {
                game.Name = Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(game.Name.ToLower());
            }

            return(game);
        }
Exemple #2
0
        public static GameInfo GetGameInfo(byte[] romData, string fileName)
        {
            CompactGameInfo cgi;
            var             hash = $"{CRC32.Calculate(romData):X8}";

            if (DB.TryGetValue(hash, out cgi))
            {
                return(new GameInfo(cgi));
            }

            hash = romData.HashMD5();
            if (DB.TryGetValue(hash, out cgi))
            {
                return(new GameInfo(cgi));
            }

            hash = romData.HashSHA1();
            if (DB.TryGetValue(hash, out cgi))
            {
                return(new GameInfo(cgi));
            }

            // rom is not in database. make some best-guesses
            var game = new GameInfo
            {
                Hash          = hash,
                Status        = RomStatus.NotInDatabase,
                NotInDatabase = true
            };

            Console.WriteLine(
                "Game was not in DB. CRC: {0:X8} MD5: {1}",
                CRC32.Calculate(romData),
                System.Security.Cryptography.MD5.Create().ComputeHash(romData).BytesToHexString());

            var ext = Path.GetExtension(fileName)?.ToUpperInvariant();

            switch (ext)
            {
            case ".NES":
            case ".UNF":
            case ".FDS":
                game.System = "NES";
                break;

            case ".SFC":
            case ".SMC":
                game.System = "SNES";
                break;

            case ".GB":
                game.System = "GB";
                break;

            case ".GBC":
                game.System = "GBC";
                break;

            case ".GBA":
                game.System = "GBA";
                break;

            case ".SMS":
                game.System = "SMS";
                break;

            case ".GG":
                game.System = "GG";
                break;

            case ".SG":
                game.System = "SG";
                break;

            case ".GEN":
            case ".MD":
            case ".SMD":
                game.System = "GEN";
                break;

            case ".PSF":
            case ".MINIPSF":
                game.System = "PSX";
                break;

            case ".PCE":
                game.System = "PCE";
                break;

            case ".SGX":
                game.System = "SGX";
                break;

            case ".A26":
                game.System = "A26";
                break;

            case ".A78":
                game.System = "A78";
                break;

            case ".COL":
                game.System = "Coleco";
                break;

            case ".INT":
                game.System = "INTV";
                break;

            case ".PRG":
            case ".D64":
            case ".T64":
            case ".G64":
            case ".CRT":
                game.System = "C64";
                break;

            case ".TZX":
            case ".PZX":
                game.System = "ZXSpectrum";
                break;

            case ".TAP":

                byte[] head = romData.Take(8).ToArray();
                if (System.Text.Encoding.Default.GetString(head).Contains("C64-TAPE"))
                {
                    game.System = "C64";
                }
                else
                {
                    game.System = "ZXSpectrum";
                }
                break;

            case ".Z64":
            case ".V64":
            case ".N64":
                game.System = "N64";
                break;

            case ".DEBUG":
                game.System = "DEBUG";
                break;

            case ".WS":
            case ".WSC":
                game.System = "WSWAN";
                break;

            case ".LNX":
                game.System = "Lynx";
                break;

            case ".83P":
                game.System = "83P";
                break;

            case ".DSK":
                byte[] head2 = romData.Take(20).ToArray();
                string ident = System.Text.Encoding.Default.GetString(head2);
                if (ident.ToUpper().Contains("EXTENDED CPC DSK") ||
                    ident.ToUpper().Contains("MV - CPC"))
                {
                    game.System = "ZXSpectrum";
                }
                else
                {
                    game.System = "AppleII";
                }
                break;

            case ".PO":
            case ".DO":
                game.System = "AppleII";
                break;

            case ".VB":
                game.System = "VB";
                break;

            case ".NGP":
            case ".NGC":
                game.System = "NGP";
                break;

            case ".O2":
                game.System = "O2";
                break;

            case ".UZE":
                game.System = "UZE";
                break;

            case ".32X":
                game.System = "32X";
                game.AddOption("32X", "true");
                break;
            }

            game.Name = Path.GetFileNameWithoutExtension(fileName)?.Replace('_', ' ');

            // If filename is all-caps, then attempt to proper-case the title.
            if (!string.IsNullOrWhiteSpace(game.Name) && game.Name == game.Name.ToUpperInvariant())
            {
                game.Name = Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(game.Name.ToLower());
            }

            return(game);
        }