@@ -51,53 +51,40 @@ static const Release RELEASES[] = {
5151 {" scus_974.87" , Game::DL, Region::US, " Ratchet: Deadlocked" } // us public beta
5252};
5353
54- static std::pair<Game, const char *> GAME_SEARCH_PATTERNS[] = {
55- {Game::DL, " Deadlocked" },
56- {Game::UYA, " Up Your Arsenal" },
57- {Game::GC, " Going Commando" },
58- {Game::RAC, " Ratchet & Clank" }
59- };
60-
61- Release identify_release (const IsoDirectory& root, InputStream& iso)
54+ Release identify_release (const std::string& elf_name)
6255{
6356 Release result;
64- // First check all of the known releases.
65- for (const IsoFileRecord& file : root.files ) {
66- for (const Release& release : RELEASES) {
67- if (release.elf_name == file.name ) {
68- result = release;
69- break ;
70- }
57+ for (const Release& release : RELEASES) {
58+ if (release.elf_name == elf_name) {
59+ result = release;
60+ break ;
7161 }
7262 }
73- if (result.game == Game::UNKNOWN) {
74- // Unknown build, try to identify it in a dirtier slower way.
75- for (const IsoFileRecord& record : root.files ) {
76- if (record.size > 4 ) {
77- // Look for the boot ELF.
78- u8 magic[4 ] = {};
79- iso.seek (record.lba .bytes ());
80- iso.read_n (magic, 4 );
81- if (memcmp (magic, " \x7f\x45\x4c\x46 " , 4 ) == 0 ) {
82- iso.seek (record.lba .bytes ());
83- std::vector<u8 > elf = iso.read_multiple <u8 >(record.size );
84- // Look for the names of the respective games in the boot ELF.
85- for (auto [game, pattern] : GAME_SEARCH_PATTERNS) {
86- for (s32 i = 0 ; i < (s32) elf.size () - strlen (pattern); i++) {
87- if (memcmp (&elf[i], pattern, strlen (pattern)) == 0 ) {
88- printf (" Unknown build identified as %s.\n " , game_to_string (game).c_str ());
89- result.elf_name = record.name ;
90- result.game = game;
91- result.name = " unknown" ;
92- break ;
93- }
94- }
95- if (result.game != Game::UNKNOWN) {
96- break ;
97- }
98- }
99- }
100- }
63+ return result;
64+ }
65+
66+ static std::string normalise_game_id (const std::string& game_id)
67+ {
68+ std::string result;
69+ for (char c : game_id) {
70+ if (c >= ' A' && c <= ' Z' ) {
71+ result.push_back (c + (' a' - ' A' ));
72+ } else if ((c >= ' a' && c <= ' z' ) || (c >= ' 0' && c <= ' 9' )) {
73+ result.push_back (c);
74+ }
75+ }
76+ return result;
77+ }
78+
79+ Release identify_release_fuzzy (const std::string& game_id)
80+ {
81+ std::string normal_game_id = normalise_game_id (game_id);
82+
83+ Release result;
84+ for (const Release& release : RELEASES) {
85+ if (normalise_game_id (release.elf_name ) == normal_game_id) {
86+ result = release;
87+ break ;
10188 }
10289 }
10390 return result;
0 commit comments