eden-miror/src/yuzu
crueter 39f226a853
[qt] Ryujinx save data link (#2815)
This adds an action to the Game List context menu that lets users link
save data from Eden to Ryujinx, or vice versa.

Unfortunately, this isn't so simple to deal with due to the way Ryujinx's saves work. Ryujinx stores its saves in the... config directory... in `bis/user/save`. Unlike Yuzu, however, it doesn't store things by TitleID, instead it's just a bunch of directories from 000...01 to 000...0f and so on. The way it *maps* TitleID to SaveID is via `imkvdb.arc` in `bis/system/save/8000000000000000/0/` and also an identical copy in the `1` directory for... some reason. `imkvdb.arc` is handled by `FlatMapKeyValueStore` in LibHac, which, as the name implies, is a key-value storage system that `imkvdb.arc`, and seemingly `imkvdb.arc` alone, uses. The way this class is written is really weird, almost as if it's designed to accommodate more types of kvdbs... but for now we can safely assume that there aren't gonna be any other `kvdb` implementations added to HorizonNX.

Regardless, the file format is ridiculously simple so I didn't actually need to do a deep dive into C# code... of which I can basically only read Avalonia. A simple `xxd` on the `imkvdb.arc` is all that's needed, and here's everything that matters:
- The `IMKV` magic header (4 bytes)
- 8 bytes that don't really have anything useful to us, except for a size byte (presumably a `u32`) strewn at offset `0x08` from the start of the file, which is useless to us
- Then we start the `IMEN` list. I don't know what the `IM` stands for, but `IMEN` is just, well, an ENtry. Offsets shown are relative to the start of the `IMEN` header.
  * 4-byte `IMEN` magic header at 0x0
  * 8 bytes of filler data. It contains two `0x40` bytes, but I'm not really sure what they do
  * TitleID (u64) at `0xC`, for example `00a0 df10  501f 0001` for Legends: Arceus (the byte order is swapped)
  * 0x38 bytes of filler starting at offset 0x14
  * SaveID (u64) at `0x4C`, for example `0a00 0000 0000 0000` for my Legends: Arceus save
  * 0x38 bytes of filler starting at offset 0x54

Full example for Legends: Arceus:
```
000001b0: 494d 454e 4000 0000 4000 0000 00a0 df10  IMEN@...@.......
000001c0: 501f 0001 0100 0000 0000 0000 0000 0000  P...............
000001d0: 0000 0000 0000 0000 0000 0000 0100 0000  ................
000001e0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000001f0: 0000 0000 0000 0000 0000 0000 0a00 0000  ................
00000200: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000210: 0000 0000 0100 0000 0000 0000 0000 0000  ................
00000220: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000230: 0000 0000 0000 0000 0000 0000 494d 454e  ............IMEN
```
Ultimately, the size of the `IMEN` sits at 0x8C or 140 bytes. With this knowledge reading all the TitleID -> SaveID pairs is basically free, and outside of validation and stuff is like 15 lines of relevant code. Some interesting caveats, though:
- There are two entries for some TitleIDs for... some reason? Ignoring the second one seems to work though.
- Within each save directory, there are directories `0` and `1`... and only `0` ever seems used??? It's where Ryujinx points you to for save, so I just chose to use that.

Once everything is parsed, the rest of the implementation is extremely trivial:
- When the user requests a Ryujinx link, match the current program_id to the corresponding SaveID in `imkvdb`
- If it doesn't exist, just error out (save data is probably nonexistent)
- If it does though, give the user the option to use Eden's current save data OR Ryujinx's current save data.

Old save data is deleted depending on which one you chose.

Signed-off-by: crueter <crueter@eden-emu.dev>
Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/2815
Reviewed-by: Lizzie <lizzie@eden-emu.dev>
Reviewed-by: MaranBr <maranbr@eden-emu.dev>
2025-10-28 03:46:47 +01:00
..
applets [qt_common] reorg + checkstate abstraction (#2735) 2025-10-15 05:05:03 +02:00
configuration [desktop] Fix misaligned output device (#2786) 2025-10-20 04:08:38 +02:00
debugger [qt_common] reorg + checkstate abstraction (#2735) 2025-10-15 05:05:03 +02:00
multiplayer [qt_common] reorg + checkstate abstraction (#2735) 2025-10-15 05:05:03 +02:00
util [cmake] enable clang-cl and WoA builds (#348) 2025-09-09 20:47:49 +02:00
about_dialog.cpp [meta] allow customisation of auto-updater, remove hardcoded title names and fix dup title names (#2588) 2025-10-01 05:07:59 +02:00
about_dialog.h general: Convert source file copyright comments over to SPDX 2022-04-23 05:55:32 -04:00
aboutdialog.ui [cmake, frontend] feat: CPMUtil + dependency viewer (#238) 2025-08-11 22:27:29 +02:00
bootmanager.cpp [qt_common] reorg + checkstate abstraction (#2735) 2025-10-15 05:05:03 +02:00
bootmanager.h Fix more typos 2024-01-15 23:26:53 +00:00
breakpad.cpp User Data Migration from Citron, Sudachi, and Yuzu (#91) 2025-05-08 22:16:07 +00:00
breakpad.h qt: implement automatic crash dump support 2023-10-08 11:35:53 -04:00
CMakeLists.txt [qt] Ryujinx save data link (#2815) 2025-10-28 03:46:47 +01:00
compatdb.cpp [desktop] Data Manager, data import/export (#2700) 2025-10-15 04:54:41 +02:00
compatdb.h Removed telemetry and anonymized SCM (git) strings 2025-04-04 03:40:47 +02:00
compatdb.ui fix a large variety of issues (#101) 2025-05-11 23:58:25 +00:00
compatibility_list.cpp Update fmt to allow for v11 2025-04-10 01:11:22 +02:00
compatibility_list.h general: Convert source file copyright comments over to SPDX 2022-04-23 05:55:32 -04:00
data_dialog.cpp [qt] Ryujinx save data link (#2815) 2025-10-28 03:46:47 +01:00
data_dialog.h [desktop] Data Manager, data import/export (#2700) 2025-10-15 04:54:41 +02:00
data_dialog.ui [desktop] Data Manager, data import/export (#2700) 2025-10-15 04:54:41 +02:00
data_widget.ui [desktop] Data Manager, data import/export (#2700) 2025-10-15 04:54:41 +02:00
deps_dialog.cpp [cmake, frontend] feat: CPMUtil + dependency viewer (#238) 2025-08-11 22:27:29 +02:00
deps_dialog.h [cmake, frontend] feat: CPMUtil + dependency viewer (#238) 2025-08-11 22:27:29 +02:00
deps_dialog.ui [cmake, frontend] feat: CPMUtil + dependency viewer (#238) 2025-08-11 22:27:29 +02:00
game_list.cpp [qt] Ryujinx save data link (#2815) 2025-10-28 03:46:47 +01:00
game_list.h [qt] Ryujinx save data link (#2815) 2025-10-28 03:46:47 +01:00
game_list_p.h [core, android] Initial playtime implementation (#2535) 2025-10-17 22:47:43 +02:00
game_list_worker.cpp [qt_common] reorg + checkstate abstraction (#2735) 2025-10-15 05:05:03 +02:00
game_list_worker.h [core, android] Initial playtime implementation (#2535) 2025-10-17 22:47:43 +02:00
hotkeys.cpp [qt_common] reorg + checkstate abstraction (#2735) 2025-10-15 05:05:03 +02:00
hotkeys.h hid_core: Move hid to it's own subproject 2024-01-05 11:41:15 -06:00
Info.plist [macos] associate .XCI/NSP file extensions (#2617) 2025-09-29 18:43:13 +02:00
install_dialog.cpp [qt_common] reorg + checkstate abstraction (#2735) 2025-10-15 05:05:03 +02:00
install_dialog.h general: Convert source file copyright comments over to SPDX 2022-04-23 05:55:32 -04:00
loading_screen.cpp general: fix spelling mistakes 2023-03-12 11:33:01 -04:00
loading_screen.h Update some files with Qt 5.15.2 best practices in mind 2022-05-29 09:21:52 -07:00
loading_screen.ui
main.cpp [qt] Ryujinx save data link (#2815) 2025-10-28 03:46:47 +01:00
main.h [qt] Ryujinx save data link (#2815) 2025-10-28 03:46:47 +01:00
main.ui [desktop] Data Manager, data import/export (#2700) 2025-10-15 04:54:41 +02:00
migration_dialog.cpp Properly migrate internal NAND, Load, etc. directories (#167) 2025-06-11 22:57:13 +00:00
migration_dialog.h Options for Data Migration (#95) 2025-05-10 15:40:15 +00:00
migration_worker.cpp [qt] Ryujinx save data link (#2815) 2025-10-28 03:46:47 +01:00
migration_worker.h [qt] Ryujinx save data link (#2815) 2025-10-28 03:46:47 +01:00
ryujinx_dialog.cpp [qt] Ryujinx save data link (#2815) 2025-10-28 03:46:47 +01:00
ryujinx_dialog.h [qt] Ryujinx save data link (#2815) 2025-10-28 03:46:47 +01:00
ryujinx_dialog.ui [qt] Ryujinx save data link (#2815) 2025-10-28 03:46:47 +01:00
set_play_time_dialog.cpp [core, android] Initial playtime implementation (#2535) 2025-10-17 22:47:43 +02:00
set_play_time_dialog.h [core, android] Initial playtime implementation (#2535) 2025-10-17 22:47:43 +02:00
set_play_time_dialog.ui [core, android] Initial playtime implementation (#2535) 2025-10-17 22:47:43 +02:00
startup_checks.cpp [compat] fix solaris Qt build (#194) 2025-08-15 04:12:45 +02:00
startup_checks.h [compat] fix solaris Qt build (#194) 2025-08-15 04:12:45 +02:00
user_data_migration.cpp [qt] fix translations (#2773) 2025-10-18 22:19:06 +02:00
user_data_migration.h [qt_common] reorg + checkstate abstraction (#2735) 2025-10-15 05:05:03 +02:00
vk_device_info.cpp [qt] refactor: qt_common lib (#94) 2025-09-15 17:21:18 +02:00
vk_device_info.h vk_device_info: Check only affected Intel drivers 2023-06-18 16:15:51 -04:00
yuzu.qrc Rename Yuzu logo to Eden 2025-04-13 01:15:36 +01:00
yuzu.rc Rename Yuzu logo to Eden 2025-04-13 01:15:36 +01:00