From 32f4f1871d44b952ec7bc2d7ca6af73344d148ee Mon Sep 17 00:00:00 2001 From: "[ ]" <[ ]> Date: Mon, 2 Oct 2023 23:56:13 +0900 Subject: [PATCH] feat: Add global access for selected Game object > separated commit in case this functionality is already provided through other means and needs to be reverted > probably target for rehaul in the future for better/less invasive approach --- games/game.cpp | 4 ++++ games/game.h | 1 + hooks/audio/implementations/pipewire.cpp | 2 +- launcher/launcher.cpp | 2 ++ launcher/launcher.h | 2 ++ 5 files changed, 10 insertions(+), 1 deletion(-) diff --git a/games/game.cpp b/games/game.cpp index 54e7f10..3701f4c 100644 --- a/games/game.cpp +++ b/games/game.cpp @@ -5,6 +5,10 @@ games::Game::Game(std::string name) { this->name = name; } +const char *games::Game::title() { + return this->name.c_str(); +} + void games::Game::attach() { log_info("game", "attach: {}", name); } diff --git a/games/game.h b/games/game.h index 775434d..a0dee5f 100644 --- a/games/game.h +++ b/games/game.h @@ -15,6 +15,7 @@ namespace games { // where the main magic will happen virtual void attach(); + virtual const char *title(); // optional virtual void pre_attach(); diff --git a/hooks/audio/implementations/pipewire.cpp b/hooks/audio/implementations/pipewire.cpp index 664af26..dd85d0e 100644 --- a/hooks/audio/implementations/pipewire.cpp +++ b/hooks/audio/implementations/pipewire.cpp @@ -34,7 +34,7 @@ HRESULT PipewireBackend::on_initialize( if (!bmsw_) log_fatal("audio::pipewire", "Library not found: '{}'", (MODULE_PATH / "bmsound-wine.dll").string()); auto pipewireinit = (BmswClientInit_t)GetProcAddress(bmsw_, "BmswClientInit"); if (!pipewireinit) log_fatal("audio::pipewire", "Library invalid: '{}'", (MODULE_PATH / "bmsound-wine.dll").string()); - internal_ = std::thread(pipewireinit,"GAME TITLE"); + internal_ = std::thread(pipewireinit,GAME_INSTANCE->title()); return S_OK; } diff --git a/launcher/launcher.cpp b/launcher/launcher.cpp index edd9a82..a3a416e 100644 --- a/launcher/launcher.cpp +++ b/launcher/launcher.cpp @@ -108,6 +108,7 @@ std::string LOG_FILE_PATH = ""; int LAUNCHER_ARGC = 0; char **LAUNCHER_ARGV = nullptr; std::unique_ptr> LAUNCHER_OPTIONS; +games::Game *GAME_INSTANCE = nullptr; std::string CARD_OVERRIDES[2]; // sub-systems @@ -1424,6 +1425,7 @@ int main_implementation(int argc, char *argv[]) { avs::core::set_default_heap_size("kamunity.dll"); games.push_back(new games::bc::BCGame()); } + GAME_INSTANCE = games.back(); // apply user heap size, if defined if (user_heap_size > 0) { diff --git a/launcher/launcher.h b/launcher/launcher.h index 8d1ac12..3b51236 100644 --- a/launcher/launcher.h +++ b/launcher/launcher.h @@ -7,6 +7,7 @@ #include #include "cfg/option.h" +#include "games/game.h" namespace rawinput { class RawInputManager; @@ -21,6 +22,7 @@ extern std::string LOG_FILE_PATH; extern int LAUNCHER_ARGC; extern char **LAUNCHER_ARGV; extern std::unique_ptr> LAUNCHER_OPTIONS; +extern games::Game *GAME_INSTANCE; extern std::unique_ptr API_CONTROLLER; extern std::unique_ptr RI_MGR;