diff --git a/librecomp/include/recomp_game.h b/librecomp/include/recomp_game.h index 652ad17..4727088 100644 --- a/librecomp/include/recomp_game.h +++ b/librecomp/include/recomp_game.h @@ -9,16 +9,18 @@ namespace recomp { struct GameHandle { - uint64_t id; + std::u8string_view id; }; struct GameEntry { uint64_t rom_hash; std::string internal_name; - void (*entrypoint)(); + std::u8string_view game_id; std::span cache_data; bool is_enabled; - std::string stored_filename() const; + void (*entrypoint)(); + + std::u8string stored_filename() const; }; enum class RomValidationError { Good, @@ -43,6 +45,7 @@ namespace recomp { void start_game(GameHandle game); void message_box(const char* message); std::filesystem::path get_app_folder_path(); + std::u8string_view current_game_id(); } #endif diff --git a/librecomp/src/pi.cpp b/librecomp/src/pi.cpp index 2ae13ce..405823d 100644 --- a/librecomp/src/pi.cpp +++ b/librecomp/src/pi.cpp @@ -6,7 +6,6 @@ #include #include "recomp.h" #include "recomp_game.h" -#include "recomp_config.h" #include #include @@ -95,7 +94,7 @@ struct { } save_context; const std::u8string save_folder = u8"saves"; -const std::u8string save_filename = std::u8string{recomp::mm_game_id} + u8".bin"; +const std::u8string save_filename = std::u8string{recomp::current_game_id()} + u8".bin"; std::filesystem::path get_save_file_path() { return recomp::get_app_folder_path() / save_folder / save_filename; diff --git a/librecomp/src/recomp.cpp b/librecomp/src/recomp.cpp index 1698648..14d146d 100644 --- a/librecomp/src/recomp.cpp +++ b/librecomp/src/recomp.cpp @@ -40,16 +40,16 @@ std::mutex current_game_mutex; // Global variables std::vector patch_data; -std::unordered_map game_roms {}; +std::unordered_map game_roms {}; -std::string recomp::GameEntry::stored_filename() const { - return std::to_string(rom_hash) + ".z64"; +std::u8string recomp::GameEntry::stored_filename() const { + return std::u8string{game_id} + u8".z64"; } recomp::GameHandle recomp::register_game(const recomp::GameEntry& entry) { std::lock_guard lock(game_roms_mutex); - game_roms.insert({ entry.rom_hash, entry }); - return { entry.rom_hash }; + game_roms.insert({ entry.game_id, entry }); + return { entry.game_id }; } void recomp::register_patch(const char* patch, std::size_t size) { @@ -129,7 +129,7 @@ bool check_stored_rom(const recomp::GameEntry& game_entry) { return true; } -static std::unordered_set valid_game_roms; +static std::unordered_set valid_game_roms; bool recomp::is_rom_valid(recomp::GameHandle game) { return valid_game_roms.contains(game.id); @@ -394,6 +394,11 @@ void init(uint8_t* rdram, recomp_context* ctx) { std::optional current_game = std::nullopt; std::atomic game_status = GameStatus::None; +std::u8string_view recomp::current_game_id() { + std::lock_guard lock(current_game_mutex); + return current_game.value().id; +}; + void recomp::start_game(recomp::GameHandle game) { std::lock_guard lock(current_game_mutex); current_game = game;