From 65edb7081a0d716e96a612b9758b4f7e0028e6f8 Mon Sep 17 00:00:00 2001 From: otavepto Date: Fri, 8 Mar 2024 13:50:25 +0200 Subject: [PATCH] allow controlling the renderer detector timeout via a config file --- dll/dll/settings.h | 3 ++- dll/settings_parser.cpp | 25 ++++++++++++++++++- overlay_experimental/steam_overlay.cpp | 17 +++++++------ post_build/README.release.md | 17 ++++++++----- ..._renderer_detector_timeout_sec.EXAMPLE.txt | 1 + 5 files changed, 48 insertions(+), 15 deletions(-) create mode 100644 post_build/steam_settings.EXAMPLE/overlay_renderer_detector_timeout_sec.EXAMPLE.txt diff --git a/dll/dll/settings.h b/dll/dll/settings.h index 4c8a619e..a791cbc1 100644 --- a/dll/dll/settings.h +++ b/dll/dll/settings.h @@ -275,7 +275,8 @@ public: //overlay bool disable_overlay = false; - int overlay_hook_delay_sec = 3; + int overlay_hook_delay_sec = 5; // "Saints Row (2022)" needs a lot of time to initialize, otherwise detection will fail + int overlay_renderer_detector_timeout_sec = 15; // "Saints Row (2022)" takes almost ~8 sec to detect renderer (DX12) bool disable_overlay_achievement_notification = false; bool disable_overlay_friend_notification = false; //warn people who use force_ settings diff --git a/dll/settings_parser.cpp b/dll/settings_parser.cpp index 81e2ee8c..f35a1eee 100644 --- a/dll/settings_parser.cpp +++ b/dll/settings_parser.cpp @@ -1137,7 +1137,6 @@ static void parse_overlay_hook_delay_sec(class Settings *settings_client, Settin std::string auto_accept_list_path = Local_Storage::get_game_settings_path() + "overlay_hook_delay_sec.txt"; std::ifstream input( utf8_decode(auto_accept_list_path) ); if (input.is_open()) { - bool accept_any_invite = true; common_helpers::consume_bom(input); std::string line{}; std::getline( input, line ); @@ -1155,6 +1154,29 @@ static void parse_overlay_hook_delay_sec(class Settings *settings_client, Settin } } +// overlay_renderer_detector_timeout_sec.txt +static void parse_overlay_renderer_detector_timeout_sec(class Settings *settings_client, Settings *settings_server) +{ + std::string auto_accept_list_path = Local_Storage::get_game_settings_path() + "overlay_renderer_detector_timeout_sec.txt"; + std::ifstream input( utf8_decode(auto_accept_list_path) ); + if (input.is_open()) { + common_helpers::consume_bom(input); + std::string line{}; + std::getline( input, line ); + line = common_helpers::string_strip(line); + if (!line.empty()) { + try { + auto timeout_sec = std::stoi(line); + if (timeout_sec > 0) { + settings_client->overlay_renderer_detector_timeout_sec = timeout_sec; + settings_server->overlay_renderer_detector_timeout_sec = timeout_sec; + PRINT_DEBUG("Setting overlay renderer detector timeout to %i seconds\n", timeout_sec); + } + } catch (...) {} + } + } +} + uint32 create_localstorage_settings(Settings **settings_client_out, Settings **settings_server_out, Local_Storage **local_storage_out) { std::string program_path = Local_Storage::get_program_path(); @@ -1367,6 +1389,7 @@ uint32 create_localstorage_settings(Settings **settings_client_out, Settings **s parse_auto_accept_invite(settings_client, settings_server); parse_ip_country(settings_client, settings_server); parse_overlay_hook_delay_sec(settings_client, settings_server); + parse_overlay_renderer_detector_timeout_sec(settings_client, settings_server); *settings_client_out = settings_client; *settings_server_out = settings_server; diff --git a/overlay_experimental/steam_overlay.cpp b/overlay_experimental/steam_overlay.cpp index c811c701..ee474be5 100644 --- a/overlay_experimental/steam_overlay.cpp +++ b/overlay_experimental/steam_overlay.cpp @@ -155,6 +155,7 @@ Steam_Overlay::~Steam_Overlay() run_every_runcb->remove(&Steam_Overlay::steam_overlay_run_every_runcb, this); } +constexpr static const int renderer_detector_polling_ms = 100; void Steam_Overlay::renderer_hook_init_thread() { @@ -172,9 +173,9 @@ void Steam_Overlay::renderer_hook_init_thread() // request renderer detection auto future_renderer = InGameOverlay::DetectRenderer(); PRINT_DEBUG("Steam_Overlay::renderer_hook_init requested renderer detector/hook\n"); - int polling_time_ms = 500; - int timeout_ctr = 10 /*seconds*/ * 1000 /*milli per second*/ / polling_time_ms; - while (timeout_ctr > 0 && setup_overlay_called && future_renderer.wait_for(std::chrono::milliseconds(polling_time_ms)) != std::future_status::ready) { + + int timeout_ctr = settings->overlay_renderer_detector_timeout_sec /*seconds*/ * 1000 /*milli per second*/ / renderer_detector_polling_ms; + while (timeout_ctr > 0 && setup_overlay_called && future_renderer.wait_for(std::chrono::milliseconds(renderer_detector_polling_ms)) != std::future_status::ready) { --timeout_ctr; } @@ -182,10 +183,12 @@ void Steam_Overlay::renderer_hook_init_thread() InGameOverlay::StopRendererDetection(); InGameOverlay::FreeDetector(); // exit on failure - if (timeout_ctr <= 0 || !setup_overlay_called || !future_renderer.valid()) { + bool final_chance = (future_renderer.wait_for(std::chrono::milliseconds(1)) == std::future_status::ready) && future_renderer.valid(); + // again check for 'setup_overlay_called' to be extra sure that the overlay wasn't deinitialized + if (!setup_overlay_called || !final_chance || timeout_ctr <= 0) { PRINT_DEBUG( - "Steam_Overlay::renderer_hook_init failed to detect renderer, ctr=%i, overlay was set up=%i, valid hook intance-%i\n", - timeout_ctr, (int)setup_overlay_called, future_renderer.valid() + "Steam_Overlay::renderer_hook_init failed to detect renderer, ctr=%i, overlay was set up=%i, hook intance state=%i\n", + timeout_ctr, (int)setup_overlay_called, (int)final_chance ); return; } @@ -1225,7 +1228,7 @@ void Steam_Overlay::UnSetupOverlay() is_ready = false; // allow the future_renderer thread to exit if needed - std::this_thread::sleep_for(std::chrono::milliseconds(500 + 50)); + std::this_thread::sleep_for(std::chrono::milliseconds((int)(renderer_detector_polling_ms * 1.3f))); if (_renderer) { for (auto &ach : achievements) { diff --git a/post_build/README.release.md b/post_build/README.release.md index ed8fcd72..c7c4f21b 100644 --- a/post_build/README.release.md +++ b/post_build/README.release.md @@ -515,18 +515,23 @@ Also, match making servers will return the info of the server from the incoming --- -## Overlay hook delay: +## Overlay hook delay and renderer detector timeout: **Note: at the moment this feature is only enabled in the experimental builds** --- -By default the emu will wait `3 seconds` before attempting to start the overlay renderer detector, this allows some games to initialize properly, otherwise the detector may not detect the renderer (DirectX, OpenGL, etc...) and the overlay will not work (example game: `Have a Nice Death`). -You can control this delay via the configuration file `overlay_hook_delay_sec.txt`. It must contain only one line, specifying the amount of seconds to wait. -It is **NOT** recommended to remove this delay or setting it to 0, also negative values will be ignored. +By default the emu will wait `5 seconds` before attempting to start the overlay renderer detector, this allows some games to initialize properly, otherwise the detector may not detect the current renderer (DirectX, OpenGL, etc...) and the overlay will not work (example games: `Have a Nice Death`, `Saints Row (2022)`). -The renderer detector will have a `10 second` timeout after initialization (not including the delay), after that it will fail. +After that initial delay, the emu will give the detector `15 seconds` as a timeout, after that time if the detector didn't return a valid result, it will fail. This avoids an infinite detection loop and a potential FPS drop on failure. -Check the example file in the `steam_settings` folder +You can control these timings via the configuration files: +* `overlay_hook_delay_sec.txt`: controls the amount of seconds to wait for initially before attempting the detection. +* `overlay_renderer_detector_timeout_sec.txt`: controls the timeout (in seconds) of the detection. + +It is **NOT** recommended to remove these timings or setting them to 0. +Negative values will be ignored, also the renderer detector timeout cannot be 0. + +Check the example files in the `steam_settings` folder --- diff --git a/post_build/steam_settings.EXAMPLE/overlay_renderer_detector_timeout_sec.EXAMPLE.txt b/post_build/steam_settings.EXAMPLE/overlay_renderer_detector_timeout_sec.EXAMPLE.txt new file mode 100644 index 00000000..3f10ffe7 --- /dev/null +++ b/post_build/steam_settings.EXAMPLE/overlay_renderer_detector_timeout_sec.EXAMPLE.txt @@ -0,0 +1 @@ +15 \ No newline at end of file