a1ex4 / ownfoil

Switch library manager, with a self-hosted Tinfoil Shop.
430 stars 43 forks source link

DLC unrecognized after CNMT lookup failure, fallback infers incorrect base title_id #97

Closed PortableProgrammer closed 1 month ago

PortableProgrammer commented 2 months ago

For certain DLC (e.g. The Legend of Heroes Trails through Daybreak [DLC][010040C01D249001][v0].nsp) that are not present in cnmts.json, the base title_id is not correctly inferred.

Ownfoil attempts to locate the base title_id by replacing the last three characters of the app_id with 000 to get the assumed base, which results in 010040C01D249000 instead of the correct base 010040C01D248000, causing the base title_id to be Unrecognized. The Unrecognized title also causes QoL features like Missing Update and Missing DLC to be less useful, since the default is "missing", potentially masking true missing updates/DLC.

While researching this issue, I spot-checked ~50 DLC ("titleType": 130) entries in cnmts.json and found that in every case, the correct base title_id could be inferred by subtracting 0x01 from app_id[:-3] before appending 000.

So instead of: https://github.com/a1ex4/ownfoil/blob/8e772924daf18fb83f245e63d3820153ea48841b/app/titles.py#L83-L84

You could do:

app_type = APP_TYPE_DLC
title_id = hex(int(app_id[:-3], base=16) - 0x01)[2:].rjust(13, '0') + '000'

Which works in basic testing:

> python3
>>> app_id = '010040C01D249001'
>>> hex(int(app_id[:-3], base=16) - 0x01)[2:].rjust(13, '0') + '000'
'010040c01d248000'
>>> app_id = '0100ED9018F3F001'
>>> hex(int(app_id[:-3], base=16) - 0x01)[2:].rjust(13, '0') + '000'
'0100ed9018f3e000'
The DLC is present in titles.US.en.json, so the banner, DLC name, etc. are pulled correctly. ![Screenshot 2024-08-07 at 9 17 20 AM](https://github.com/user-attachments/assets/ef653d7b-0e77-42de-8629-81bde1d43a6f) ```json "70050000048589": { "bannerUrl": "https://img-eshop.cdn.nintendo.net/i/f79b3345414d4df502720155c76e25f65213b86a7c7fb2dea0080add46145c59.jpg", "category": null, "description": "This set includes the following DLC:\n- Holo Core Voice: Latoya Hamilton\n- Risette's Marduk Battle Maid Suit\n- Feri's Kruga Priestess Garb\n- 'Gift from Spriggan A' Item Set \n- 'Gift from Spriggan B' Item Set \n- Agn\u00e8s' Old Calvardian Kingdom Dress\n- Dark Azure Treasure Box\n- 40th Anniversary Xipha Cover\n- 4SPG UNITED: Van\n- 4SPG UNITED: Agn\u00e8s\n- 4SPG UNITED: Feri\n- 4SPG UNITED: Aaron\n- Judith's Golden Blood Suit", "developer": null, "frontBoxArt": null, "iconUrl": null, "id": "010040C01D249001", "ids": [ "010040C01D249001" ], "intro": null, "isDemo": false, "key": null, "languages": null, "name": "Trails through Daybreak - Bonus Set", "nsuId": 70050000048589, "numberOfPlayers": null, "publisher": "NIS America", "rating": 13, "ratingContent": [ "Blood", "Drug Reference", "Fantasy Violence", "Language", "Suggestive Themes" ], "region": null, "releaseDate": 20240705, "rightsId": null, "screenshots": null, "size": 0, "version": null }, ```

So far I have seen this behavior on the following titles:

Edit: add rjust() to ensure proper hex string length

a1ex4 commented 2 months ago

Thank you very much for your investigations and providing the fix! I couldn't figure it out and always was wondering how to get the correct Title ID. I implemented the fix in the develop branch, the new version can be tested by pulling the develop tag of the image. Although you need to rescan the library from scratch, by first deleting the directory and adding it again in the settings page.

PortableProgrammer commented 2 months ago

Confirmed, develop has fixed this issue: Screenshot 2024-08-13 at 4 23 05 PM

I see one other null DLC, but it appears to be a different issue. I believe it's just not in titles.US.en.json at all, which displays null for the DLC title and no image. I'll research it when I can get a few minutes to play around with it some more.

a1ex4 commented 2 months ago

Thanks for the feedback. I just noticed and fixed an issue where titledb was not updating to the latest available, it was stuck with a 19 days old titlesdb. Maybe that's why it is missing currently, you can test the new version when the image is done building in ~20 minutes.

PortableProgrammer commented 1 month ago

The DLC that is failing with null, 0100ED9018F3F004, is not in the latest version of blawar/titledb/US.en.json as of this writing, so the titledb update above wouldn't have mattered, unfortunately. Regardless, I believe my original issue is fixed; this remaining one appears to be a product of a pending titledb update.

I have another DLC, 01002E7016C47005, which is also missing from titledb, but it's handled differently, labeled as Unrecognized and not found in titledb. I'll review and see if I can suss out the null problem with 0100ED9018F3F004.

0100ED9018F3F004 and 01002E7016C47005

![Screenshot 2024-08-14 at 8 08 03 AM](https://github.com/user-attachments/assets/133883da-ce66-4671-ac8a-e0fa68919afc) ![Screenshot 2024-08-14 at 8 07 53 AM](https://github.com/user-attachments/assets/0530c179-41b1-4427-be3e-e4a65b0120ea)

a1ex4 commented 1 month ago

Fix merged in master.