snarfblam / hasher-js

Javascript-based ROM validation tool
Do What The F*ck You Want To Public License
14 stars 2 forks source link

hasher-js doesn't recognize some Game Gear ROMs #2

Open angrylion7 opened 1 year ago

angrylion7 commented 1 year ago

hasher-js doesn't recognize some Game Gear and potentially Master System ROMs, even though the hashes for these ROMs are present in the bundled .json files. For example, "Chessmaster, The (USA, Europe, Brazil) (En).gg": File/ROM SHA-1: DAEA9A76DEDC080B9965CFA32E2DDB1EAAAAB0B4 File/ROM CRC32: DA811BA6 See the attached .jpg.

I don't really know any JavaScript, but the following was confirmed by one other person.

In src/platforms/Platform_gg_sms.js the function isPlatformMatch() returns false for any SMS/GG ROM, which is wrong. That's because in src/romUtils/smsUtil.js function verifyMagicNumber() returns false, even though the "TMR SEGA" header string is present. This is because Platform_gg_sms.js makes smsUtil.js use the wrong rom[] indexing instead of the expected rom.preview[] indexing, for example, on lines 41 and 42 in the former .js file. Comparison with "undefined" then happens on line 30 in smsUtil.js. So, in the present state hasher-js detects SMS/GG games against No-Intro solely by looking at a ROM's file extension after no candidate platforms (a.k.a. console models) were found. In src/platforms/snes.js function isPlatformMatch() returns true by happenstance, because of the contents of bytes 0x7fdc to 0x7fdf in The Chessmaster ROM, which corresponds to the SNES Internal ROM Header. Then in src/platformLookup.js on line 37 hasher-js doesn't want to check the aforementioned file extension as per usual, because SNES has emerged as the only candidate platform, so it's declared that The Chessmaster is SNES.

iwzk6c

robertnhart commented 1 year ago

This was also discussed in the following ROMhacking.net forum thread: Online ROM Hasher doesn't work for some Game Gear ROMs

I believe a fix could be to go to the source code file Platform_gg_sms.js, class Platform_gg_sms, method isPlatformMatch, and change the following lines:

if (!smsUtil.verifyMagicNumber(rom, headerOffset)) return false;
var region = smsUtil.getRegionCode(rom, headerOffset);

to use rom.preview instead:

if (!smsUtil.verifyMagicNumber(rom.preview, headerOffset)) return false;
var region = smsUtil.getRegionCode(rom.preview, headerOffset);