|
8 | 8 | #include "Common/CommonPaths.h" |
9 | 9 | #include "Core/CommonTitles.h" |
10 | 10 | #include "Common/FileUtil.h" |
| 11 | +#include "Common/StringUtil.h" |
11 | 12 | #include "Common/Version.h" |
12 | 13 | #include "Core/Boot/Boot.h" |
13 | 14 | #include "Core/BootManager.h" |
|
19 | 20 | #include "Core/GeckoCodeConfig.h" |
20 | 21 | #include "Core/HW/DVD/DVDInterface.h" |
21 | 22 | #include "Core/HW/EXI/EXI_Device.h" |
| 23 | +#include "Core/HW/HSP/HSP_Device.h" |
22 | 24 | #include "Core/HW/VideoInterface.h" |
23 | 25 | #include "Core/HW/WiimoteReal/WiimoteReal.h" |
24 | 26 | #include "Core/PowerPC/PowerPC.h" |
@@ -53,6 +55,10 @@ static unsigned disk_index = 0; |
53 | 55 | static bool eject_state; |
54 | 56 | static std::vector<std::string> disk_paths; |
55 | 57 |
|
| 58 | +// GBPlayer |
| 59 | +static std::string GBPlayer_rom_path; |
| 60 | +static bool GBPlayer_active; |
| 61 | + |
56 | 62 | // silence forward declaration warnings |
57 | 63 | void reload_cheats_from_ini(); |
58 | 64 | void generate_cht_from_ini(std::string fileName); |
@@ -168,12 +174,64 @@ void generate_cht_from_ini(std::string fileName) |
168 | 174 | bool retro_load_game(const struct retro_game_info* game) |
169 | 175 | { |
170 | 176 | const char* save_dir = NULL; |
| 177 | + const char* gba_save_dir = NULL; |
171 | 178 | const char* system_dir = NULL; |
172 | 179 | const char* core_assets_dir = NULL; |
| 180 | + std::string rebuild_save_dir; |
173 | 181 | std::string user_dir; |
174 | 182 | std::string sys_dir; |
175 | 183 |
|
176 | | - Libretro::environ_cb(RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY, &save_dir); |
| 184 | + /* |
| 185 | + * If the GBPlayer is active, we try to reconstruct the GC save dir location |
| 186 | + * with regards to content sorting and core sorting. If we do not do this, |
| 187 | + * there will be a User directory with GC saves in the GB/GBC/GBA rom save path |
| 188 | + * when a user has content/core sorting enabled. Since the user is trying to avoid |
| 189 | + * said behavior actively if those sorting options are enabled, |
| 190 | + * we should seperate them accordingly. |
| 191 | + */ |
| 192 | + if (Libretro::GBPlayer_active) |
| 193 | + { |
| 194 | + std::filesystem::path gba_content_dir = std::filesystem::path(""); |
| 195 | + if (!Libretro::GBPlayer_rom_path.empty()) |
| 196 | + gba_content_dir = std::filesystem::path(Libretro::GBPlayer_rom_path).parent_path().filename().string(); |
| 197 | + |
| 198 | + Libretro::environ_cb(RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY, &gba_save_dir); |
| 199 | + std::filesystem::path base = std::filesystem::path(gba_save_dir); |
| 200 | + |
| 201 | + bool core_sort = false; |
| 202 | + retro_system_info sys_info{}; |
| 203 | + retro_get_system_info(&sys_info); |
| 204 | + const std::string library_name = sys_info.library_name; |
| 205 | + |
| 206 | + if (!base.empty() && !library_name.empty()) |
| 207 | + core_sort = Common::CaseInsensitiveEquals(base.filename().string(), library_name); |
| 208 | + if (core_sort) |
| 209 | + base = base.parent_path(); |
| 210 | + |
| 211 | + bool content_sort = false; |
| 212 | + std::string gc_content_dir; |
| 213 | + if (!gba_content_dir.empty() && !base.empty()) |
| 214 | + content_sort = Common::CaseInsensitiveEquals(base.filename().string(), gba_content_dir.string()); |
| 215 | + if (content_sort) |
| 216 | + { |
| 217 | + gc_content_dir = std::filesystem::path(game->path).parent_path().filename().string(); |
| 218 | + base = base.parent_path(); |
| 219 | + } |
| 220 | + |
| 221 | + rebuild_save_dir = base.string(); |
| 222 | + if (content_sort) |
| 223 | + rebuild_save_dir = rebuild_save_dir + DIR_SEP + gc_content_dir; |
| 224 | + if (core_sort) |
| 225 | + rebuild_save_dir = rebuild_save_dir + DIR_SEP + library_name; |
| 226 | + |
| 227 | + save_dir = rebuild_save_dir.c_str(); |
| 228 | + INFO_LOG_FMT(BOOT, "GBPlayer: GC save dir reconstructed to: '{}'", save_dir); |
| 229 | + } |
| 230 | + else |
| 231 | + { |
| 232 | + Libretro::environ_cb(RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY, &save_dir); |
| 233 | + } |
| 234 | + |
177 | 235 | Libretro::environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &system_dir); |
178 | 236 | Libretro::environ_cb(RETRO_ENVIRONMENT_GET_CORE_ASSETS_DIRECTORY, &core_assets_dir); |
179 | 237 | Libretro::InitDiskControlInterface(); |
@@ -212,6 +270,22 @@ bool retro_load_game(const struct retro_game_info* game) |
212 | 270 | UICommon::CreateDirectories(); |
213 | 271 | UICommon::Init(); |
214 | 272 | Libretro::Log::Init(); |
| 273 | + |
| 274 | + if (Libretro::GBPlayer_active) |
| 275 | + { |
| 276 | + Config::SetBase(Config::MAIN_GBA_ROM_PATHS[Config::GBPLAYER_GBA_INDEX], Libretro::GBPlayer_rom_path); |
| 277 | + INFO_LOG_FMT(BOOT, "GBPlayer: GBA ROM path applied from subsystem: '{}'", Libretro::GBPlayer_rom_path); |
| 278 | + Config::SetBase(Config::MAIN_GBA_SAVES_PATH, std::string(gba_save_dir)); |
| 279 | + INFO_LOG_FMT(BOOT, "GBPlayer: ROM save set to: '{}'", gba_save_dir); |
| 280 | + // In order to prevent confusion for the settings of the save location between RA and the |
| 281 | + // emulator we just turn this off |
| 282 | + Config::SetBase(Config::MAIN_GBA_SAVES_IN_ROM_PATH, false); |
| 283 | + } |
| 284 | + else |
| 285 | + { |
| 286 | + Config::SetBase(Config::MAIN_GBA_ROM_PATHS[Config::GBPLAYER_GBA_INDEX], std::string{}); |
| 287 | + } |
| 288 | + |
215 | 289 | Discord::SetDiscordPresenceEnabled(false); |
216 | 290 | Common::SetEnableAlert(false); |
217 | 291 | Common::SetAbortOnPanicAlert(false); |
@@ -633,10 +707,44 @@ bool retro_load_game(const struct retro_game_info* game) |
633 | 707 | return true; |
634 | 708 | } |
635 | 709 |
|
636 | | -bool retro_load_game_special(unsigned game_type, const struct retro_game_info* info, |
637 | | - size_t num_info) |
| 710 | +bool retro_load_game_special(unsigned game_type, const struct retro_game_info* info, size_t num_info) |
638 | 711 | { |
639 | | - return false; |
| 712 | + if (game_type != Libretro::g_gbplayer_subsystem_id) |
| 713 | + { |
| 714 | + ERROR_LOG_FMT(BOOT, "retro_load_game_special: unknown game_type {}", game_type); |
| 715 | + return false; |
| 716 | + } |
| 717 | + if (num_info < 1 || !info) |
| 718 | + { |
| 719 | + ERROR_LOG_FMT(BOOT, "retro_load_game_special: no content info"); |
| 720 | + return false; |
| 721 | + } |
| 722 | + |
| 723 | + const retro_game_info* gba_slot = (num_info >= 2 && info[0].path && *info[0].path) ? &info[0] : nullptr; |
| 724 | + |
| 725 | + const retro_game_info* gc_slot = (info[1].path && *info[1].path) ? &info[1] : nullptr; |
| 726 | + |
| 727 | + if (!gc_slot) |
| 728 | + { |
| 729 | + ERROR_LOG_FMT(BOOT, "GBPlayer: no GC disc path provided in slot 0"); |
| 730 | + return false; |
| 731 | + } |
| 732 | + |
| 733 | + INFO_LOG_FMT(BOOT, "GBPlayer: GC disc = '{}'", gc_slot->path); |
| 734 | + if (gba_slot) |
| 735 | + { |
| 736 | + Libretro::GBPlayer_rom_path = gba_slot->path; |
| 737 | + INFO_LOG_FMT(BOOT, "GBPlayer: ROM = '{}'", gba_slot->path); |
| 738 | + } |
| 739 | + else |
| 740 | + { |
| 741 | + Libretro::GBPlayer_rom_path.clear(); |
| 742 | + INFO_LOG_FMT(BOOT, "GBPlayer: no ROM"); |
| 743 | + } |
| 744 | + |
| 745 | + Libretro::GBPlayer_active = true; |
| 746 | + |
| 747 | + return retro_load_game(gc_slot); |
640 | 748 | } |
641 | 749 |
|
642 | 750 | void retro_unload_game(void) |
|
0 commit comments