2024-01-22 07:31:02 +08:00
|
|
|
#ifdef EMU_OVERLAY
|
|
|
|
|
|
|
|
// if you're wondering about text like: ##PopupAcceptInvite
|
|
|
|
// these are unique labels (keys) for each button/label/text,etc...
|
|
|
|
// ImGui uses the labels as keys, adding a suffic like "My Text##SomeKey"
|
|
|
|
// avoids confusing ImGui when another label has the same text "MyText"
|
|
|
|
|
2023-12-27 15:21:59 +08:00
|
|
|
#include "overlay/steam_overlay.h"
|
2024-03-02 22:09:22 +08:00
|
|
|
#include "overlay/notification.h"
|
2023-12-27 15:21:59 +08:00
|
|
|
#include "overlay/steam_overlay_translations.h"
|
2019-08-01 04:21:02 +08:00
|
|
|
|
|
|
|
#include <thread>
|
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
2019-08-03 18:58:48 +08:00
|
|
|
#include <cctype>
|
2024-03-13 03:21:09 +08:00
|
|
|
#include <utility>
|
|
|
|
|
2024-03-02 05:16:29 +08:00
|
|
|
#include "InGameOverlay/ImGui/imgui.h"
|
2019-08-01 04:21:02 +08:00
|
|
|
|
2023-12-27 15:21:59 +08:00
|
|
|
#include "dll/dll.h"
|
|
|
|
#include "dll/settings_parser.h"
|
2019-08-01 04:21:02 +08:00
|
|
|
|
2024-03-02 05:16:29 +08:00
|
|
|
#include "InGameOverlay/RendererDetector.h"
|
2019-08-18 22:22:07 +08:00
|
|
|
|
2024-03-08 08:26:52 +08:00
|
|
|
// fonts
|
2024-03-31 23:51:38 +08:00
|
|
|
#include "fonts/unifont.hpp"
|
2024-03-08 08:26:52 +08:00
|
|
|
|
2024-03-08 05:19:31 +08:00
|
|
|
#define URL_WINDOW_NAME "URL Window"
|
|
|
|
|
2019-10-11 19:10:48 +08:00
|
|
|
static constexpr int max_window_id = 10000;
|
|
|
|
static constexpr int base_notif_window_id = 0 * max_window_id;
|
|
|
|
static constexpr int base_friend_window_id = 1 * max_window_id;
|
|
|
|
static constexpr int base_friend_item_id = 2 * max_window_id;
|
|
|
|
|
2024-03-03 09:32:17 +08:00
|
|
|
static const char* valid_languages[] = {
|
2022-08-05 14:09:43 +08:00
|
|
|
"english",
|
|
|
|
"arabic",
|
|
|
|
"bulgarian",
|
|
|
|
"schinese",
|
|
|
|
"tchinese",
|
|
|
|
"czech",
|
|
|
|
"danish",
|
|
|
|
"dutch",
|
|
|
|
"finnish",
|
|
|
|
"french",
|
|
|
|
"german",
|
|
|
|
"greek",
|
|
|
|
"hungarian",
|
|
|
|
"italian",
|
|
|
|
"japanese",
|
|
|
|
"koreana",
|
|
|
|
"norwegian",
|
|
|
|
"polish",
|
|
|
|
"portuguese",
|
|
|
|
"brazilian",
|
|
|
|
"romanian",
|
|
|
|
"russian",
|
|
|
|
"spanish",
|
|
|
|
"latam",
|
|
|
|
"swedish",
|
|
|
|
"thai",
|
|
|
|
"turkish",
|
|
|
|
"ukrainian",
|
2023-08-25 01:59:01 +08:00
|
|
|
"vietnamese",
|
|
|
|
"croatian"
|
2022-08-05 14:09:43 +08:00
|
|
|
};
|
|
|
|
|
2024-04-10 03:03:07 +08:00
|
|
|
static ImFontAtlas fonts_atlas{};
|
|
|
|
static ImFont *font_default{};
|
|
|
|
static ImFont *font_notif{};
|
2024-03-02 22:09:22 +08:00
|
|
|
|
2024-04-10 03:03:07 +08:00
|
|
|
static std::recursive_mutex overlay_mutex{};
|
|
|
|
static std::atomic<bool> setup_overlay_called = false;
|
2024-03-04 08:39:50 +08:00
|
|
|
|
2024-04-10 14:10:50 +08:00
|
|
|
static std::map<std::string, std::vector<char>> wav_files{
|
|
|
|
{ "overlay_achievement_notification.wav", std::vector<char>{} },
|
|
|
|
{ "overlay_friend_notification.wav", std::vector<char>{} },
|
|
|
|
};
|
2024-03-04 08:39:50 +08:00
|
|
|
|
2019-10-11 19:10:48 +08:00
|
|
|
|
2024-03-08 05:19:31 +08:00
|
|
|
// ListBoxHeader() is deprecated and inlined inside <imgui.h>
|
|
|
|
// Helper to calculate size from items_count and height_in_items
|
|
|
|
static inline bool ImGuiHelper_BeginListBox(const char* label, int items_count) {
|
|
|
|
int min_items = items_count < 7 ? items_count : 7;
|
|
|
|
float height = ImGui::GetTextLineHeightWithSpacing() * (min_items + 0.25f) + ImGui::GetStyle().FramePadding.y * 2.0f;
|
|
|
|
return ImGui::BeginListBox(label, ImVec2(0.0f, height));
|
2019-10-11 19:10:48 +08:00
|
|
|
}
|
|
|
|
|
2019-08-17 00:31:56 +08:00
|
|
|
|
2024-03-15 01:23:39 +08:00
|
|
|
void Steam_Overlay::overlay_run_callback(void* object)
|
2019-08-06 19:46:43 +08:00
|
|
|
{
|
2024-04-06 13:49:07 +08:00
|
|
|
// PRINT_DEBUG_ENTRY();
|
2019-08-06 19:46:43 +08:00
|
|
|
Steam_Overlay* _this = reinterpret_cast<Steam_Overlay*>(object);
|
2024-03-15 01:23:39 +08:00
|
|
|
_this->steam_run_callback();
|
2019-08-06 19:46:43 +08:00
|
|
|
}
|
|
|
|
|
2024-03-15 01:23:39 +08:00
|
|
|
void Steam_Overlay::overlay_networking_callback(void* object, Common_Message* msg)
|
2019-08-06 19:46:43 +08:00
|
|
|
{
|
|
|
|
Steam_Overlay* _this = reinterpret_cast<Steam_Overlay*>(object);
|
2024-03-15 01:23:39 +08:00
|
|
|
_this->networking_msg_received(msg);
|
2019-08-06 19:46:43 +08:00
|
|
|
}
|
|
|
|
|
2024-04-10 03:00:19 +08:00
|
|
|
Steam_Overlay::Steam_Overlay(Settings* settings, Local_Storage *local_storage, SteamCallResults* callback_results, SteamCallBacks* callbacks, RunEveryRunCB* run_every_runcb, Networking* network) :
|
2019-08-01 04:21:02 +08:00
|
|
|
settings(settings),
|
2024-04-10 03:00:19 +08:00
|
|
|
local_storage(local_storage),
|
2019-08-01 04:21:02 +08:00
|
|
|
callback_results(callback_results),
|
|
|
|
callbacks(callbacks),
|
|
|
|
run_every_runcb(run_every_runcb),
|
2024-03-15 01:23:39 +08:00
|
|
|
network(network)
|
2019-08-01 04:21:02 +08:00
|
|
|
{
|
2024-03-09 09:45:21 +08:00
|
|
|
// don't even bother initializing the overlay
|
|
|
|
if (settings->disable_overlay) return;
|
|
|
|
|
2022-08-05 14:09:43 +08:00
|
|
|
strncpy(username_text, settings->get_local_name(), sizeof(username_text));
|
|
|
|
|
2023-12-29 09:55:11 +08:00
|
|
|
// we need these copies to show the warning only once, then disable the flag
|
|
|
|
// avoid manipulating settings->xxx
|
|
|
|
this->warn_local_save =
|
|
|
|
!settings->disable_overlay_warning_any && !settings->disable_overlay_warning_local_save && settings->overlay_warn_local_save;
|
|
|
|
this->warn_bad_appid =
|
|
|
|
!settings->disable_overlay_warning_any && !settings->disable_overlay_warning_bad_appid && settings->get_local_game_id().AppID() == 0;
|
2022-08-05 14:09:43 +08:00
|
|
|
|
|
|
|
current_language = 0;
|
|
|
|
const char *language = settings->get_language();
|
|
|
|
|
|
|
|
int i = 0;
|
2024-03-03 09:32:17 +08:00
|
|
|
for (auto &lang : valid_languages) {
|
|
|
|
if (strcmp(lang, language) == 0) {
|
2022-08-05 14:09:43 +08:00
|
|
|
current_language = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
2024-03-15 01:23:39 +08:00
|
|
|
this->network->setCallback(CALLBACK_ID_STEAM_MESSAGES, settings->get_local_steam_id(), &Steam_Overlay::overlay_networking_callback, this);
|
2024-03-23 23:01:27 +08:00
|
|
|
run_every_runcb->add(&Steam_Overlay::overlay_run_callback, this);
|
2019-08-01 04:21:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Steam_Overlay::~Steam_Overlay()
|
|
|
|
{
|
2024-03-09 09:45:21 +08:00
|
|
|
if (settings->disable_overlay) return;
|
|
|
|
|
2024-03-23 23:01:27 +08:00
|
|
|
this->network->rmCallback(CALLBACK_ID_STEAM_MESSAGES, settings->get_local_steam_id(), &Steam_Overlay::overlay_networking_callback, this);
|
2024-03-15 01:23:39 +08:00
|
|
|
run_every_runcb->remove(&Steam_Overlay::overlay_run_callback, this);
|
2019-08-01 04:21:02 +08:00
|
|
|
}
|
|
|
|
|
2024-03-09 03:33:13 +08:00
|
|
|
void Steam_Overlay::request_renderer_detector()
|
|
|
|
{
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG_ENTRY();
|
2024-03-09 03:33:13 +08:00
|
|
|
// request renderer detection
|
|
|
|
future_renderer = InGameOverlay::DetectRenderer();
|
|
|
|
}
|
2019-08-01 04:21:02 +08:00
|
|
|
|
2024-03-09 03:33:13 +08:00
|
|
|
void Steam_Overlay::renderer_detector_delay_thread()
|
2019-08-01 04:21:02 +08:00
|
|
|
{
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("waiting for %i seconds", settings->overlay_hook_delay_sec);
|
2024-03-09 03:33:13 +08:00
|
|
|
// give games some time to init their renderer (DirectX, OpenGL, etc...)
|
|
|
|
int timeout_ctr = settings->overlay_hook_delay_sec /*seconds*/ * 1000 /*milli per second*/ / renderer_detector_polling_ms;
|
|
|
|
while (timeout_ctr > 0 && setup_overlay_called ) {
|
|
|
|
--timeout_ctr;
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(renderer_detector_polling_ms));
|
2024-03-06 04:59:17 +08:00
|
|
|
}
|
|
|
|
|
2024-03-07 08:57:48 +08:00
|
|
|
// early exit before we get a chance to do anything
|
|
|
|
if (!setup_overlay_called) {
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("early exit before renderer detection");
|
2024-03-07 08:57:48 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-06 04:59:17 +08:00
|
|
|
// request renderer detection
|
2024-03-09 03:33:13 +08:00
|
|
|
request_renderer_detector();
|
|
|
|
renderer_hook_init_thread();
|
|
|
|
}
|
2024-03-08 19:50:25 +08:00
|
|
|
|
2024-03-09 03:33:13 +08:00
|
|
|
void Steam_Overlay::renderer_hook_init_thread()
|
|
|
|
{
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG_ENTRY();
|
2024-03-08 19:50:25 +08:00
|
|
|
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) {
|
2024-03-06 04:59:17 +08:00
|
|
|
--timeout_ctr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// free detector resources and check for failure
|
|
|
|
InGameOverlay::StopRendererDetection();
|
|
|
|
InGameOverlay::FreeDetector();
|
|
|
|
// exit on failure
|
2024-03-08 19:50:25 +08:00
|
|
|
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) {
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("failed to detect renderer, ctr=%i, overlay was set up=%i, hook intance state=%i",
|
2024-03-08 19:50:25 +08:00
|
|
|
timeout_ctr, (int)setup_overlay_called, (int)final_chance
|
2024-03-08 05:19:31 +08:00
|
|
|
);
|
2024-03-06 04:59:17 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// do a one time initialization
|
2024-03-15 01:23:39 +08:00
|
|
|
// std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
2024-03-06 04:59:17 +08:00
|
|
|
_renderer = future_renderer.get();
|
2024-04-09 18:29:08 +08:00
|
|
|
if (!_renderer) { // is this even possible?
|
|
|
|
PRINT_DEBUG("renderer hook was null!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
PRINT_DEBUG("got renderer hook %p for '%s'", _renderer, _renderer->GetLibraryName().c_str());
|
2024-04-04 08:47:12 +08:00
|
|
|
|
|
|
|
// note: make sure to load all relevant strings before creating the font(s), otherwise some glyphs ranges will be missing
|
2024-03-15 01:23:39 +08:00
|
|
|
load_achievements_data();
|
2024-04-04 08:47:12 +08:00
|
|
|
load_audio();
|
|
|
|
create_fonts();
|
2024-03-06 04:59:17 +08:00
|
|
|
|
|
|
|
// setup renderer callbacks
|
|
|
|
const static std::set<InGameOverlay::ToggleKey> overlay_toggle_keys = {
|
|
|
|
InGameOverlay::ToggleKey::SHIFT, InGameOverlay::ToggleKey::TAB
|
|
|
|
};
|
2024-03-07 08:57:48 +08:00
|
|
|
auto overlay_toggle_callback = [this]() { open_overlay_hook(true); };
|
2024-03-15 01:23:39 +08:00
|
|
|
_renderer->OverlayProc = [this]() { overlay_render_proc(); };
|
2024-03-06 04:59:17 +08:00
|
|
|
_renderer->OverlayHookReady = [this](InGameOverlay::OverlayHookState state) {
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("hook state changed to <%i>", (int)state);
|
2024-03-07 08:57:48 +08:00
|
|
|
overlay_state_hook(state == InGameOverlay::OverlayHookState::Ready || state == InGameOverlay::OverlayHookState::Reset);
|
2024-03-06 04:59:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
bool started = _renderer->StartHook(overlay_toggle_callback, overlay_toggle_keys, &fonts_atlas);
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("started renderer hook (result=%i)", (int)started);
|
2024-03-06 04:59:17 +08:00
|
|
|
}
|
|
|
|
|
2024-04-04 08:47:12 +08:00
|
|
|
// note: make sure to load all relevant strings before creating the font(s), otherwise some glyphs ranges will be missing
|
2024-03-08 05:19:31 +08:00
|
|
|
void Steam_Overlay::create_fonts()
|
2024-03-06 04:59:17 +08:00
|
|
|
{
|
2024-04-10 14:10:50 +08:00
|
|
|
PRINT_DEBUG_ENTRY();
|
2024-03-06 04:59:17 +08:00
|
|
|
|
2024-03-08 05:19:31 +08:00
|
|
|
// disable rounding the texture height to the next power of two
|
|
|
|
// see this: https://github.com/ocornut/imgui/blob/master/docs/FONTS.md#4-font-atlas-texture-fails-to-upload-to-gpu
|
|
|
|
fonts_atlas.Flags |= ImFontAtlasFlags_NoPowerOfTwoHeight;
|
|
|
|
|
|
|
|
float font_size = settings->overlay_appearance.font_size;
|
2024-04-03 17:41:05 +08:00
|
|
|
|
2024-03-08 08:26:52 +08:00
|
|
|
static ImFontConfig font_cfg{};
|
|
|
|
font_cfg.FontDataOwnedByAtlas = false; // https://github.com/ocornut/imgui/blob/master/docs/FONTS.md#loading-font-data-from-memory
|
|
|
|
font_cfg.PixelSnapH = true;
|
|
|
|
font_cfg.OversampleH = 1;
|
|
|
|
font_cfg.OversampleV = 1;
|
|
|
|
font_cfg.SizePixels = font_size;
|
2024-03-08 20:15:38 +08:00
|
|
|
// non-latin characters look ugly and squeezed without this horizontal spacing
|
|
|
|
font_cfg.GlyphExtraSpacing.x = settings->overlay_appearance.font_glyph_extra_spacing_x;
|
|
|
|
font_cfg.GlyphExtraSpacing.y = settings->overlay_appearance.font_glyph_extra_spacing_y;
|
2024-03-08 05:19:31 +08:00
|
|
|
|
|
|
|
static ImFontGlyphRangesBuilder font_builder{};
|
2024-04-04 02:20:14 +08:00
|
|
|
for (const auto &ach : achievements) {
|
|
|
|
font_builder.AddText(ach.title.c_str());
|
|
|
|
font_builder.AddText(ach.description.c_str());
|
2019-08-26 22:38:01 +08:00
|
|
|
}
|
2024-03-08 05:19:31 +08:00
|
|
|
for (int i = 0; i < TRANSLATION_NUMBER_OF_LANGUAGES; i++) {
|
|
|
|
font_builder.AddText(translationChat[i]);
|
|
|
|
font_builder.AddText(translationCopyId[i]);
|
|
|
|
font_builder.AddText(translationInvite[i]);
|
|
|
|
font_builder.AddText(translationInviteAll[i]);
|
|
|
|
font_builder.AddText(translationJoin[i]);
|
|
|
|
font_builder.AddText(translationInvitedYouToJoinTheGame[i]);
|
|
|
|
font_builder.AddText(translationAccept[i]);
|
|
|
|
font_builder.AddText(translationRefuse[i]);
|
|
|
|
font_builder.AddText(translationSend[i]);
|
|
|
|
font_builder.AddText(translationUserPlaying[i]);
|
|
|
|
font_builder.AddText(translationRenderer[i]);
|
|
|
|
font_builder.AddText(translationShowAchievements[i]);
|
|
|
|
font_builder.AddText(translationSettings[i]);
|
|
|
|
font_builder.AddText(translationFriends[i]);
|
|
|
|
font_builder.AddText(translationAchievementWindow[i]);
|
|
|
|
font_builder.AddText(translationListOfAchievements[i]);
|
|
|
|
font_builder.AddText(translationAchievements[i]);
|
|
|
|
font_builder.AddText(translationHiddenAchievement[i]);
|
|
|
|
font_builder.AddText(translationAchievedOn[i]);
|
|
|
|
font_builder.AddText(translationNotAchieved[i]);
|
|
|
|
font_builder.AddText(translationGlobalSettingsWindow[i]);
|
|
|
|
font_builder.AddText(translationGlobalSettingsWindowDescription[i]);
|
|
|
|
font_builder.AddText(translationUsername[i]);
|
|
|
|
font_builder.AddText(translationLanguage[i]);
|
|
|
|
font_builder.AddText(translationSelectedLanguage[i]);
|
|
|
|
font_builder.AddText(translationRestartTheGameToApply[i]);
|
|
|
|
font_builder.AddText(translationSave[i]);
|
|
|
|
font_builder.AddText(translationWarning[i]);
|
|
|
|
font_builder.AddText(translationWarningWarningWarning[i]);
|
2024-04-20 06:49:28 +08:00
|
|
|
font_builder.AddText(translationWarningDescription_badAppid[i]);
|
|
|
|
font_builder.AddText(translationWarningDescription_localSave[i]);
|
2024-03-08 05:19:31 +08:00
|
|
|
font_builder.AddText(translationSteamOverlayURL[i]);
|
|
|
|
font_builder.AddText(translationClose[i]);
|
|
|
|
font_builder.AddText(translationPlaying[i]);
|
|
|
|
font_builder.AddText(translationAutoAcceptFriendInvite[i]);
|
|
|
|
}
|
|
|
|
font_builder.AddRanges(fonts_atlas.GetGlyphRangesDefault());
|
2019-08-18 20:29:08 +08:00
|
|
|
|
2024-03-08 05:19:31 +08:00
|
|
|
static ImVector<ImWchar> ranges{};
|
|
|
|
font_builder.BuildRanges(&ranges);
|
2024-03-08 08:26:52 +08:00
|
|
|
font_cfg.GlyphRanges = ranges.Data;
|
|
|
|
|
2024-04-04 02:20:14 +08:00
|
|
|
if (settings->overlay_appearance.font_override.size()) {
|
|
|
|
fonts_atlas.AddFontFromFileTTF(settings->overlay_appearance.font_override.c_str(), font_size, &font_cfg);
|
2024-04-03 17:41:05 +08:00
|
|
|
font_cfg.MergeMode = true; // merge next fonts into the first one, as if they were all just 1 font file
|
|
|
|
}
|
|
|
|
|
2024-04-04 02:20:14 +08:00
|
|
|
// note: base85 compressed arrays caused a compiler heap allocation error, regular compression is more guaranteed
|
2024-03-31 23:51:38 +08:00
|
|
|
ImFont *font = fonts_atlas.AddFontFromMemoryCompressedTTF(unifont_compressed_data, unifont_compressed_size, font_size, &font_cfg);
|
2024-03-08 05:19:31 +08:00
|
|
|
font_notif = font_default = font;
|
|
|
|
|
2024-03-08 08:26:52 +08:00
|
|
|
bool res = fonts_atlas.Build();
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("created fonts atlas (result=%i)", (int)res);
|
2024-03-08 05:19:31 +08:00
|
|
|
|
|
|
|
reset_LastError();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Overlay::load_audio()
|
2022-08-08 11:11:21 +08:00
|
|
|
{
|
2024-04-10 14:10:50 +08:00
|
|
|
PRINT_DEBUG_ENTRY();
|
2024-03-06 04:59:17 +08:00
|
|
|
|
2024-04-10 14:10:50 +08:00
|
|
|
for (auto &kv : wav_files) {
|
|
|
|
std::string file_path{};
|
|
|
|
unsigned int file_size{};
|
2024-03-06 04:59:17 +08:00
|
|
|
|
2024-04-10 14:10:50 +08:00
|
|
|
// try local location first, then try global location
|
|
|
|
for (const auto &settings_path : { Local_Storage::get_game_settings_path(), local_storage->get_global_settings_path() }) {
|
2024-04-11 05:49:01 +08:00
|
|
|
file_path = settings_path + Steam_Overlay::ACH_SOUNDS_FOLDER + PATH_SEPARATOR + kv.first;
|
2024-03-08 05:19:31 +08:00
|
|
|
file_size = file_size_(file_path);
|
2024-04-10 14:10:50 +08:00
|
|
|
if (file_size) break;
|
2024-03-08 05:19:31 +08:00
|
|
|
}
|
|
|
|
|
2024-04-10 18:27:37 +08:00
|
|
|
kv.second.clear();
|
2024-04-10 14:10:50 +08:00
|
|
|
if (file_size) {
|
2024-04-10 18:27:37 +08:00
|
|
|
kv.second.assign(file_size + 1, 0); // +1 because this will be treated as a null-terminated string later
|
|
|
|
int read = Local_Storage::get_file_data(file_path, (char *)&kv.second[0], file_size);
|
|
|
|
if (read <= 0) kv.second.clear();
|
2024-04-11 05:49:01 +08:00
|
|
|
PRINT_DEBUG("loaded '%s' (read %i/%u bytes)", file_path.c_str(), read, file_size);
|
2024-03-02 22:09:22 +08:00
|
|
|
}
|
|
|
|
}
|
2022-08-08 11:11:21 +08:00
|
|
|
}
|
|
|
|
|
2024-03-15 01:23:39 +08:00
|
|
|
void Steam_Overlay::load_achievements_data()
|
|
|
|
{
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG_ENTRY();
|
2024-03-15 01:23:39 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
|
|
|
|
|
|
|
Steam_User_Stats* steamUserStats = get_steam_client()->steam_user_stats;
|
|
|
|
uint32 achievements_num = steamUserStats->GetNumAchievements();
|
|
|
|
for (uint32 i = 0; i < achievements_num; ++i) {
|
|
|
|
Overlay_Achievement ach{};
|
|
|
|
ach.name = steamUserStats->GetAchievementName(i);
|
|
|
|
ach.title = steamUserStats->GetAchievementDisplayAttribute(ach.name.c_str(), "name");
|
|
|
|
ach.description = steamUserStats->GetAchievementDisplayAttribute(ach.name.c_str(), "desc");
|
|
|
|
|
|
|
|
const char *hidden = steamUserStats->GetAchievementDisplayAttribute(ach.name.c_str(), "hidden");
|
|
|
|
ach.hidden = hidden && hidden[0] == '1';
|
|
|
|
|
|
|
|
bool achieved = false;
|
|
|
|
uint32 unlock_time = 0;
|
|
|
|
if (steamUserStats->GetAchievementAndUnlockTime(ach.name.c_str(), &achieved, &unlock_time)) {
|
|
|
|
ach.achieved = achieved;
|
|
|
|
ach.unlock_time = unlock_time;
|
|
|
|
} else {
|
|
|
|
ach.achieved = false;
|
|
|
|
ach.unlock_time = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ach.icon_name = steamUserStats->get_achievement_icon_name(ach.name.c_str(), true);
|
|
|
|
ach.icon_gray_name = steamUserStats->get_achievement_icon_name(ach.name.c_str(), false);
|
|
|
|
|
|
|
|
achievements.push_back(ach);
|
|
|
|
|
|
|
|
if (!setup_overlay_called) return;
|
|
|
|
}
|
|
|
|
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("count=%u, loaded=%zu", achievements_num, achievements.size());
|
2024-03-15 01:23:39 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Overlay::initial_load_achievements_icons()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
|
|
|
if (late_init_ach_icons) return;
|
|
|
|
}
|
|
|
|
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG_ENTRY();
|
2024-03-15 01:23:39 +08:00
|
|
|
for (auto &ach : achievements) {
|
|
|
|
{
|
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
|
|
|
if (!is_ready || !setup_overlay_called) {
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("early exit");
|
2024-03-15 01:23:39 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-10 14:10:50 +08:00
|
|
|
try_load_ach_icon(ach, true);
|
2024-03-15 01:23:39 +08:00
|
|
|
|
|
|
|
{
|
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
|
|
|
if (!is_ready || !setup_overlay_called) {
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("early exit");
|
2024-03-15 01:23:39 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-10 14:10:50 +08:00
|
|
|
try_load_ach_icon(ach, false);
|
2024-03-15 01:23:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
|
|
|
late_init_ach_icons = true;
|
|
|
|
}
|
|
|
|
|
2024-03-04 08:39:50 +08:00
|
|
|
// called initially and when window size is updated
|
2024-03-07 08:57:48 +08:00
|
|
|
void Steam_Overlay::overlay_state_hook(bool ready)
|
2019-08-01 04:21:02 +08:00
|
|
|
{
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("%i", (int)ready);
|
2024-03-15 01:23:39 +08:00
|
|
|
|
2024-03-04 08:39:50 +08:00
|
|
|
// NOTE usage of local objects here cause an exception when this is called with false state
|
2024-03-06 04:59:17 +08:00
|
|
|
// the reason is that by the time this hook is called, the object may have been already destructed
|
|
|
|
// this is why we use global mutex
|
|
|
|
// TODO this also doesn't seem right, no idea why it happens though
|
2024-03-08 05:19:31 +08:00
|
|
|
// NOTE after initializing the renderer detector on another thread this was solved
|
2024-03-02 22:09:22 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
2024-03-04 08:39:50 +08:00
|
|
|
if (!setup_overlay_called) return;
|
|
|
|
|
2024-03-02 22:09:22 +08:00
|
|
|
is_ready = ready;
|
2024-03-02 18:09:21 +08:00
|
|
|
|
2024-03-15 01:23:39 +08:00
|
|
|
if (ready) {
|
|
|
|
// Antichamber may crash here because ImGui Context is null!, no idea why
|
|
|
|
bool not_yet = false;
|
|
|
|
if (ImGui::GetCurrentContext() && late_init_imgui.compare_exchange_weak(not_yet, true)) {
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("late init ImGui");
|
2024-03-02 18:09:21 +08:00
|
|
|
|
2024-03-15 01:23:39 +08:00
|
|
|
ImGuiIO &io = ImGui::GetIO();
|
|
|
|
// disable loading the default ini file
|
|
|
|
io.IniFilename = NULL;
|
2024-03-04 08:39:50 +08:00
|
|
|
|
2024-03-15 01:23:39 +08:00
|
|
|
ImGuiStyle &style = ImGui::GetStyle();
|
|
|
|
// Disable round window
|
|
|
|
style.WindowRounding = 0.0;
|
|
|
|
}
|
2024-03-04 08:39:50 +08:00
|
|
|
}
|
2019-08-01 04:21:02 +08:00
|
|
|
}
|
|
|
|
|
2024-03-04 08:39:50 +08:00
|
|
|
// called when the user presses SHIFT + TAB
|
2024-03-07 08:57:48 +08:00
|
|
|
bool Steam_Overlay::open_overlay_hook(bool toggle)
|
2022-08-05 14:09:43 +08:00
|
|
|
{
|
2024-03-02 22:09:22 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
2022-08-05 14:09:43 +08:00
|
|
|
if (toggle) {
|
|
|
|
ShowOverlay(!show_overlay);
|
|
|
|
}
|
|
|
|
|
|
|
|
return show_overlay;
|
|
|
|
}
|
|
|
|
|
2024-03-12 05:55:19 +08:00
|
|
|
void Steam_Overlay::allow_renderer_frame_processing(bool state, bool cleaning_up_overlay)
|
2019-08-01 04:21:02 +08:00
|
|
|
{
|
2024-03-04 08:59:35 +08:00
|
|
|
// this is very important internally it calls the necessary fuctions
|
2024-03-15 01:23:39 +08:00
|
|
|
// to properly update ImGui window size on the next overlay_render_proc() call
|
2024-03-12 05:55:19 +08:00
|
|
|
|
2024-03-02 05:16:29 +08:00
|
|
|
if (state) {
|
2024-03-12 05:55:19 +08:00
|
|
|
auto new_val = ++renderer_frame_processing_requests;
|
|
|
|
if (new_val == 1) { // only take an action on first request
|
|
|
|
// allow internal frmae processing
|
|
|
|
_renderer->HideOverlayInputs(false);
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("enabled frame processing (count=%u)", new_val);
|
2024-03-12 05:55:19 +08:00
|
|
|
}
|
2024-03-06 06:44:33 +08:00
|
|
|
} else {
|
2024-03-12 05:55:19 +08:00
|
|
|
if (renderer_frame_processing_requests > 0) {
|
|
|
|
auto new_val = --renderer_frame_processing_requests;
|
|
|
|
if (!new_val || cleaning_up_overlay) { // only take an action when the requests reach 0 or by force
|
|
|
|
_renderer->HideOverlayInputs(true);
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("disabled frame processing (count=%u, force=%i)", new_val, (int)cleaning_up_overlay);
|
2024-03-12 05:55:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-15 01:23:39 +08:00
|
|
|
void Steam_Overlay::obscure_game_input(bool state) {
|
2024-03-12 06:25:47 +08:00
|
|
|
if (state) {
|
|
|
|
auto new_val = ++obscure_cursor_requests;
|
|
|
|
if (new_val == 1) { // only take an action on first request
|
2024-03-15 01:23:39 +08:00
|
|
|
ImGuiIO &io = ImGui::GetIO();
|
|
|
|
// force draw the cursor, otherwise games like Truberbrook will not have an overlay cursor
|
|
|
|
io.MouseDrawCursor = state;
|
|
|
|
// not necessary, just to be sure
|
|
|
|
io.WantCaptureMouse = state;
|
|
|
|
// not necessary, just to be sure
|
|
|
|
io.WantCaptureKeyboard = state;
|
|
|
|
|
2024-03-12 05:55:19 +08:00
|
|
|
// clip the cursor
|
|
|
|
_renderer->HideAppInputs(true);
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("obscured app input (count=%u)", new_val);
|
2024-03-12 06:25:47 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (obscure_cursor_requests > 0) {
|
|
|
|
auto new_val = --obscure_cursor_requests;
|
|
|
|
if (!new_val) { // only take an action when the requests reach 0
|
2024-03-15 01:23:39 +08:00
|
|
|
ImGuiIO &io = ImGui::GetIO();
|
|
|
|
// force draw the cursor, otherwise games like Truberbrook will not have an overlay cursor
|
|
|
|
io.MouseDrawCursor = state;
|
|
|
|
// not necessary, just to be sure
|
|
|
|
io.WantCaptureMouse = state;
|
|
|
|
// not necessary, just to be sure
|
|
|
|
io.WantCaptureKeyboard = state;
|
|
|
|
|
2024-03-12 06:25:47 +08:00
|
|
|
// restore the old cursor
|
|
|
|
_renderer->HideAppInputs(false);
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("restored app input (count=%u)", new_val);
|
2024-03-12 06:25:47 +08:00
|
|
|
}
|
2024-03-12 05:55:19 +08:00
|
|
|
}
|
2019-10-16 22:56:41 +08:00
|
|
|
}
|
2019-08-01 04:21:02 +08:00
|
|
|
}
|
|
|
|
|
2024-03-08 05:19:31 +08:00
|
|
|
void Steam_Overlay::notify_sound_user_invite(friend_window_state& friend_state)
|
2019-09-05 01:31:31 +08:00
|
|
|
{
|
2023-08-25 01:59:01 +08:00
|
|
|
if (settings->disable_overlay_friend_notification) return;
|
2024-04-10 03:03:07 +08:00
|
|
|
|
|
|
|
if (!(friend_state.window_state & window_state_show) || !show_overlay) {
|
2019-09-05 01:31:31 +08:00
|
|
|
friend_state.window_state |= window_state_need_attention;
|
|
|
|
#ifdef __WINDOWS__
|
2024-04-10 14:10:50 +08:00
|
|
|
auto wav_data = wav_files.find("overlay_friend_notification.wav");
|
|
|
|
if (wav_files.end() != wav_data && wav_data->second.size()) {
|
|
|
|
PlaySoundA((LPCSTR)&wav_data->second[0], NULL, SND_ASYNC | SND_MEMORY);
|
2023-11-10 23:25:36 +08:00
|
|
|
} else {
|
|
|
|
PlaySoundA((LPCSTR)notif_invite_wav, NULL, SND_ASYNC | SND_MEMORY);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-07 08:57:48 +08:00
|
|
|
void Steam_Overlay::notify_sound_user_achievement()
|
2023-11-10 23:25:36 +08:00
|
|
|
{
|
|
|
|
if (settings->disable_overlay_achievement_notification) return;
|
2024-04-10 03:03:07 +08:00
|
|
|
|
|
|
|
if (!show_overlay) {
|
2023-11-10 23:25:36 +08:00
|
|
|
#ifdef __WINDOWS__
|
2024-04-10 14:10:50 +08:00
|
|
|
auto wav_data = wav_files.find("overlay_achievement_notification.wav");
|
|
|
|
if (wav_files.end() != wav_data && wav_data->second.size()) {
|
|
|
|
PlaySoundA((LPCSTR)&wav_data->second[0], NULL, SND_ASYNC | SND_MEMORY);
|
2023-11-10 23:25:36 +08:00
|
|
|
}
|
2019-09-05 01:31:31 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-07 08:57:48 +08:00
|
|
|
void Steam_Overlay::notify_sound_auto_accept_friend_invite()
|
2024-01-06 13:41:32 +08:00
|
|
|
{
|
|
|
|
#ifdef __WINDOWS__
|
2024-04-10 14:10:50 +08:00
|
|
|
auto wav_data = wav_files.find("overlay_friend_notification.wav");
|
|
|
|
if (wav_files.end() != wav_data && wav_data->second.size()) {
|
|
|
|
PlaySoundA((LPCSTR)&wav_data->second[0], NULL, SND_ASYNC | SND_MEMORY);
|
2024-01-06 13:41:32 +08:00
|
|
|
} else {
|
|
|
|
PlaySoundA((LPCSTR)notif_invite_wav, NULL, SND_ASYNC | SND_MEMORY);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2024-03-08 05:19:31 +08:00
|
|
|
int find_free_id(std::vector<int> & ids, int base)
|
2019-08-02 17:16:30 +08:00
|
|
|
{
|
2024-03-08 05:19:31 +08:00
|
|
|
std::sort(ids.begin(), ids.end());
|
2019-08-16 16:37:45 +08:00
|
|
|
|
2024-03-08 05:19:31 +08:00
|
|
|
int id = base;
|
|
|
|
for (auto i : ids)
|
2019-08-02 19:02:20 +08:00
|
|
|
{
|
2024-03-08 05:19:31 +08:00
|
|
|
if (id < i)
|
|
|
|
break;
|
|
|
|
id = i + 1;
|
2019-08-02 19:02:20 +08:00
|
|
|
}
|
2024-03-08 05:19:31 +08:00
|
|
|
|
|
|
|
return id > (base+max_window_id) ? 0 : id;
|
2019-08-02 17:16:30 +08:00
|
|
|
}
|
|
|
|
|
2024-03-08 05:19:31 +08:00
|
|
|
int find_free_friend_id(const std::map<Friend, friend_window_state, Friend_Less> &friend_windows)
|
2019-08-02 17:16:30 +08:00
|
|
|
{
|
2024-03-08 05:19:31 +08:00
|
|
|
std::vector<int> ids{};
|
|
|
|
ids.reserve(friend_windows.size());
|
2019-08-16 16:37:45 +08:00
|
|
|
|
2024-03-08 05:19:31 +08:00
|
|
|
std::for_each(friend_windows.begin(), friend_windows.end(), [&ids](std::pair<Friend const, friend_window_state> const& i)
|
2019-08-02 19:02:20 +08:00
|
|
|
{
|
2024-03-08 05:19:31 +08:00
|
|
|
ids.emplace_back(i.second.id);
|
|
|
|
});
|
2024-03-06 04:59:17 +08:00
|
|
|
|
2024-03-08 05:19:31 +08:00
|
|
|
return find_free_id(ids, base_friend_window_id);
|
2019-08-02 17:16:30 +08:00
|
|
|
}
|
|
|
|
|
2024-03-08 05:19:31 +08:00
|
|
|
int find_free_notification_id(std::vector<Notification> const& notifications)
|
2019-08-02 17:16:30 +08:00
|
|
|
{
|
2024-03-08 05:19:31 +08:00
|
|
|
std::vector<int> ids{};
|
|
|
|
ids.reserve(notifications.size());
|
|
|
|
|
|
|
|
std::for_each(notifications.begin(), notifications.end(), [&ids](Notification const& i)
|
|
|
|
{
|
|
|
|
ids.emplace_back(i.id);
|
|
|
|
});
|
2024-03-06 04:59:17 +08:00
|
|
|
|
2024-03-08 05:19:31 +08:00
|
|
|
|
|
|
|
return find_free_id(ids, base_friend_window_id);
|
2019-08-02 17:16:30 +08:00
|
|
|
}
|
|
|
|
|
2024-03-04 08:39:50 +08:00
|
|
|
bool Steam_Overlay::submit_notification(notification_type type, const std::string &msg, std::pair<const Friend, friend_window_state> *frd, const std::weak_ptr<uint64_t> &icon)
|
2019-09-05 01:31:31 +08:00
|
|
|
{
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("%i", (int)type);
|
2024-03-04 08:39:50 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
2024-03-06 04:59:17 +08:00
|
|
|
if (!Ready()) return false;
|
|
|
|
|
2019-10-11 19:10:48 +08:00
|
|
|
int id = find_free_notification_id(notifications);
|
2024-03-04 08:39:50 +08:00
|
|
|
if (id == 0) {
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("error no free id to create a notification window");
|
2024-03-04 08:39:50 +08:00
|
|
|
return false;
|
2019-10-11 19:10:48 +08:00
|
|
|
}
|
2024-03-04 08:39:50 +08:00
|
|
|
|
|
|
|
Notification notif{};
|
|
|
|
notif.start_time = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch());
|
|
|
|
notif.id = id;
|
|
|
|
notif.type = type;
|
|
|
|
notif.message = msg;
|
|
|
|
notif.frd = frd;
|
|
|
|
notif.icon = icon;
|
|
|
|
|
|
|
|
notifications.emplace_back(notif);
|
2024-03-12 06:25:47 +08:00
|
|
|
allow_renderer_frame_processing(true);
|
2024-03-13 03:21:09 +08:00
|
|
|
// uncomment this block to obscure cursor input and steal focus for these specific notifications
|
2024-03-18 11:57:24 +08:00
|
|
|
switch (type) {
|
|
|
|
// we want to steal focus for these ones
|
|
|
|
case notification_type_invite:
|
|
|
|
obscure_game_input(true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
// not effective
|
|
|
|
case notification_type_achievement:
|
|
|
|
case notification_type_auto_accept_invite:
|
|
|
|
case notification_type_message:
|
|
|
|
// nothing
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("error unhandled type %i", (int)type);
|
2024-03-18 11:57:24 +08:00
|
|
|
break;
|
|
|
|
}
|
2024-03-06 04:59:17 +08:00
|
|
|
|
2024-03-04 08:39:50 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-03-07 08:57:48 +08:00
|
|
|
void Steam_Overlay::add_chat_message_notification(std::string const &message)
|
2024-03-04 08:39:50 +08:00
|
|
|
{
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("'%s'", message.c_str());
|
2024-03-04 08:39:50 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
|
|
|
if (settings->disable_overlay_friend_notification) return;
|
|
|
|
|
|
|
|
submit_notification(notification_type_message, message);
|
2019-09-05 01:31:31 +08:00
|
|
|
}
|
|
|
|
|
2024-03-07 08:57:48 +08:00
|
|
|
bool Steam_Overlay::is_friend_joinable(std::pair<const Friend, friend_window_state> &f)
|
2019-08-06 19:46:43 +08:00
|
|
|
{
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("%" PRIu64 "", f.first.id());
|
2024-03-04 08:39:50 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
2019-08-06 19:46:43 +08:00
|
|
|
Steam_Friends* steamFriends = get_steam_client()->steam_friends;
|
|
|
|
|
2024-03-20 04:07:43 +08:00
|
|
|
if (std::string(steamFriends->GetFriendRichPresence((uint64)f.first.id(), "connect")).length() > 0 ) {
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("%" PRIu64 " true (connect string)", f.first.id());
|
2019-08-06 19:46:43 +08:00
|
|
|
return true;
|
2024-03-20 04:07:43 +08:00
|
|
|
}
|
2019-08-06 19:46:43 +08:00
|
|
|
|
2024-03-06 04:59:17 +08:00
|
|
|
FriendGameInfo_t friend_game_info{};
|
2024-03-03 09:33:47 +08:00
|
|
|
steamFriends->GetFriendGamePlayed((uint64)f.first.id(), &friend_game_info);
|
2024-03-20 04:07:43 +08:00
|
|
|
if (friend_game_info.m_steamIDLobby.IsValid() && (f.second.window_state & window_state_lobby_invite)) {
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("%" PRIu64 " true (friend in a game)", f.first.id());
|
2019-08-06 19:46:43 +08:00
|
|
|
return true;
|
2024-03-20 04:07:43 +08:00
|
|
|
}
|
2019-08-06 19:46:43 +08:00
|
|
|
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("%" PRIu64 " false", f.first.id());
|
2019-08-06 19:46:43 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-03-07 08:57:48 +08:00
|
|
|
bool Steam_Overlay::got_lobby()
|
2019-08-06 19:46:43 +08:00
|
|
|
{
|
2024-03-04 08:39:50 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
2019-08-06 19:46:43 +08:00
|
|
|
Steam_Friends* steamFriends = get_steam_client()->steam_friends;
|
|
|
|
if (std::string(steamFriends->GetFriendRichPresence(settings->get_local_steam_id(), "connect")).length() > 0)
|
|
|
|
return true;
|
2019-09-01 02:49:07 +08:00
|
|
|
|
2019-08-06 19:46:43 +08:00
|
|
|
if (settings->get_lobby().IsValid())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-03-07 08:57:48 +08:00
|
|
|
void Steam_Overlay::build_friend_context_menu(Friend const& frd, friend_window_state& state)
|
2019-08-02 21:26:16 +08:00
|
|
|
{
|
2024-01-23 07:44:32 +08:00
|
|
|
if (ImGui::BeginPopupContextItem("Friends_ContextMenu", 1)) {
|
2024-01-22 07:31:02 +08:00
|
|
|
// this is set to true if any button was clicked
|
|
|
|
// otherwise, after clicking any button, the menu will be persistent
|
2019-08-06 19:46:43 +08:00
|
|
|
bool close_popup = false;
|
|
|
|
|
2024-01-22 07:31:02 +08:00
|
|
|
// user clicked on "chat"
|
2024-01-23 07:44:32 +08:00
|
|
|
if (ImGui::Button(translationChat[current_language])) {
|
2019-08-06 19:46:43 +08:00
|
|
|
close_popup = true;
|
2024-01-22 07:31:02 +08:00
|
|
|
state.window_state |= window_state_show;
|
2019-08-06 19:46:43 +08:00
|
|
|
}
|
2024-01-23 07:44:32 +08:00
|
|
|
// user clicked on "copy id" on a friend
|
|
|
|
if (ImGui::Button(translationCopyId[current_language])) {
|
|
|
|
close_popup = true;
|
|
|
|
auto friend_id_str = std::to_string(frd.id());
|
|
|
|
ImGui::SetClipboardText(friend_id_str.c_str());
|
|
|
|
}
|
2019-10-14 22:35:36 +08:00
|
|
|
// If we have the same appid, activate the invite/join buttons
|
2024-01-23 07:44:32 +08:00
|
|
|
if (settings->get_local_game_id().AppID() == frd.appid()) {
|
2024-01-22 07:31:02 +08:00
|
|
|
// user clicked on "invite to game"
|
|
|
|
std::string translationInvite_tmp(translationInvite[current_language]);
|
|
|
|
translationInvite_tmp.append("##PopupInviteToGame");
|
2024-01-23 07:44:32 +08:00
|
|
|
if (i_have_lobby && ImGui::Button(translationInvite_tmp.c_str())) {
|
2024-01-22 07:31:02 +08:00
|
|
|
close_popup = true;
|
2019-10-14 22:35:36 +08:00
|
|
|
state.window_state |= window_state_invite;
|
|
|
|
has_friend_action.push(frd);
|
|
|
|
}
|
2024-01-22 07:31:02 +08:00
|
|
|
|
|
|
|
// user clicked on "accept game invite"
|
|
|
|
std::string translationJoin_tmp(translationJoin[current_language]);
|
|
|
|
translationJoin_tmp.append("##PopupAcceptInvite");
|
2024-01-23 07:44:32 +08:00
|
|
|
if (state.joinable && ImGui::Button(translationJoin_tmp.c_str())) {
|
2019-10-14 22:35:36 +08:00
|
|
|
close_popup = true;
|
2024-01-22 07:31:02 +08:00
|
|
|
// don't bother adding this friend if the button "invite all" was clicked
|
2024-03-15 01:23:39 +08:00
|
|
|
// we will send them the invitation later in Steam_Overlay::steam_run_callback()
|
2024-01-22 07:31:02 +08:00
|
|
|
if (!invite_all_friends_clicked) {
|
|
|
|
state.window_state |= window_state_join;
|
|
|
|
has_friend_action.push(frd);
|
|
|
|
}
|
2019-10-14 22:35:36 +08:00
|
|
|
}
|
2019-08-02 21:26:16 +08:00
|
|
|
}
|
2024-01-22 07:31:02 +08:00
|
|
|
|
2024-01-23 07:44:32 +08:00
|
|
|
if (close_popup || invite_all_friends_clicked) {
|
2019-08-06 19:46:43 +08:00
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
}
|
|
|
|
|
2019-08-02 21:26:16 +08:00
|
|
|
ImGui::EndPopup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-07 08:57:48 +08:00
|
|
|
void Steam_Overlay::build_friend_window(Friend const& frd, friend_window_state& state)
|
2019-08-02 21:26:16 +08:00
|
|
|
{
|
|
|
|
if (!(state.window_state & window_state_show))
|
|
|
|
return;
|
|
|
|
|
|
|
|
bool show = true;
|
2019-08-06 19:46:43 +08:00
|
|
|
bool send_chat_msg = false;
|
2019-08-03 18:58:48 +08:00
|
|
|
|
2019-10-11 19:10:48 +08:00
|
|
|
float width = ImGui::CalcTextSize("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA").x;
|
|
|
|
|
2024-03-10 00:38:05 +08:00
|
|
|
if (state.window_state & window_state_need_attention && ImGui::IsWindowFocused()) {
|
2019-10-11 19:10:48 +08:00
|
|
|
state.window_state &= ~window_state_need_attention;
|
|
|
|
}
|
2021-01-18 11:58:42 +08:00
|
|
|
ImGui::SetNextWindowSizeConstraints(ImVec2{ width, ImGui::GetFontSize()*8 + ImGui::GetFrameHeightWithSpacing()*4 },
|
2019-10-11 19:10:48 +08:00
|
|
|
ImVec2{ std::numeric_limits<float>::max() , std::numeric_limits<float>::max() });
|
|
|
|
|
2024-03-10 00:38:05 +08:00
|
|
|
ImGui::SetNextWindowBgAlpha(0.9f);
|
2019-10-11 19:10:48 +08:00
|
|
|
// Window id is after the ###, the window title is the friend name
|
2019-10-14 22:35:36 +08:00
|
|
|
std::string friend_window_id = std::move("###" + std::to_string(state.id));
|
2024-03-10 00:38:05 +08:00
|
|
|
if (ImGui::Begin((state.window_title + friend_window_id).c_str(), &show)) {
|
2019-08-17 00:31:56 +08:00
|
|
|
if (state.window_state & window_state_need_attention && ImGui::IsWindowFocused())
|
|
|
|
{
|
|
|
|
state.window_state &= ~window_state_need_attention;
|
|
|
|
}
|
|
|
|
|
2019-08-02 21:26:16 +08:00
|
|
|
// Fill this with the chat box and maybe the invitation
|
|
|
|
if (state.window_state & (window_state_lobby_invite | window_state_rich_invite))
|
|
|
|
{
|
2023-08-21 11:58:55 +08:00
|
|
|
ImGui::LabelText("##label", translationInvitedYouToJoinTheGame[current_language], frd.name().c_str(), frd.appid());
|
2019-08-02 21:26:16 +08:00
|
|
|
ImGui::SameLine();
|
2023-08-21 11:58:55 +08:00
|
|
|
if (ImGui::Button(translationAccept[current_language]))
|
2019-08-02 21:26:16 +08:00
|
|
|
{
|
2020-02-03 08:07:30 +08:00
|
|
|
state.window_state |= window_state_join;
|
2019-08-02 21:26:16 +08:00
|
|
|
this->has_friend_action.push(frd);
|
|
|
|
}
|
|
|
|
ImGui::SameLine();
|
2023-08-21 11:58:55 +08:00
|
|
|
if (ImGui::Button(translationRefuse[current_language]))
|
2019-08-02 21:26:16 +08:00
|
|
|
{
|
|
|
|
state.window_state &= ~(window_state_lobby_invite | window_state_rich_invite);
|
|
|
|
}
|
|
|
|
}
|
2019-08-03 18:58:48 +08:00
|
|
|
|
2022-09-03 16:13:58 +08:00
|
|
|
ImGui::InputTextMultiline("##chat_history", &state.chat_history[0], state.chat_history.length(), { -1.0f, -2.0f * ImGui::GetFontSize() }, ImGuiInputTextFlags_ReadOnly);
|
2019-08-14 20:56:57 +08:00
|
|
|
// TODO: Fix the layout of the chat line + send button.
|
|
|
|
// It should be like this: chat input should fill the window size minus send button size (button size is fixed)
|
|
|
|
// |------------------------------|
|
|
|
|
// | /--------------------------\ |
|
|
|
|
// | | | |
|
|
|
|
// | | chat history | |
|
|
|
|
// | | | |
|
|
|
|
// | \--------------------------/ |
|
|
|
|
// | [____chat line______] [send] |
|
|
|
|
// |------------------------------|
|
|
|
|
//
|
|
|
|
// And it is like this
|
|
|
|
// |------------------------------|
|
|
|
|
// | /--------------------------\ |
|
|
|
|
// | | | |
|
|
|
|
// | | chat history | |
|
|
|
|
// | | | |
|
|
|
|
// | \--------------------------/ |
|
|
|
|
// | [__chat line__] [send] |
|
|
|
|
// |------------------------------|
|
2024-03-02 05:16:29 +08:00
|
|
|
float wnd_width = ImGui::GetContentRegionAvail().x;
|
2019-10-11 19:10:48 +08:00
|
|
|
ImGuiStyle &style = ImGui::GetStyle();
|
2023-08-21 11:58:55 +08:00
|
|
|
wnd_width -= ImGui::CalcTextSize(translationSend[current_language]).x + style.FramePadding.x * 2 + style.ItemSpacing.x + 1;
|
2019-10-11 19:10:48 +08:00
|
|
|
|
2024-01-23 07:44:32 +08:00
|
|
|
uint64_t frd_id = frd.id();
|
|
|
|
ImGui::PushID((const char *)&frd_id, (const char *)&frd_id + sizeof(frd_id));
|
2019-10-11 19:10:48 +08:00
|
|
|
ImGui::PushItemWidth(wnd_width);
|
2024-01-23 07:44:32 +08:00
|
|
|
|
2019-08-03 18:58:48 +08:00
|
|
|
if (ImGui::InputText("##chat_line", state.chat_input, max_chat_len, ImGuiInputTextFlags_EnterReturnsTrue))
|
|
|
|
{
|
2019-08-06 19:46:43 +08:00
|
|
|
send_chat_msg = true;
|
2022-09-03 16:13:58 +08:00
|
|
|
ImGui::SetKeyboardFocusHere(-1);
|
2019-08-03 18:58:48 +08:00
|
|
|
}
|
2019-10-11 19:10:48 +08:00
|
|
|
ImGui::PopItemWidth();
|
2024-01-23 07:44:32 +08:00
|
|
|
ImGui::PopID();
|
2019-08-03 18:58:48 +08:00
|
|
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
2023-08-21 11:58:55 +08:00
|
|
|
if (ImGui::Button(translationSend[current_language]))
|
2019-08-06 19:46:43 +08:00
|
|
|
{
|
|
|
|
send_chat_msg = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (send_chat_msg)
|
2019-08-03 18:58:48 +08:00
|
|
|
{
|
|
|
|
if (!(state.window_state & window_state_send_message))
|
|
|
|
{
|
|
|
|
has_friend_action.push(frd);
|
|
|
|
state.window_state |= window_state_send_message;
|
|
|
|
}
|
|
|
|
}
|
2019-08-02 21:26:16 +08:00
|
|
|
}
|
2024-03-10 00:38:05 +08:00
|
|
|
|
2019-08-02 21:26:16 +08:00
|
|
|
// User closed the friend window
|
|
|
|
if (!show)
|
|
|
|
state.window_state &= ~window_state_show;
|
2019-08-06 19:46:43 +08:00
|
|
|
|
2019-08-02 21:26:16 +08:00
|
|
|
ImGui::End();
|
|
|
|
}
|
|
|
|
|
2024-01-26 11:49:03 +08:00
|
|
|
// set the position of the next notification
|
2024-03-07 08:57:48 +08:00
|
|
|
void Steam_Overlay::set_next_notification_pos(float width, float height, float font_size, notification_type type, struct NotificationsIndexes &idx)
|
2024-01-26 11:49:03 +08:00
|
|
|
{
|
|
|
|
// 0 on the y-axis is top, 0 on the x-axis is left
|
|
|
|
|
|
|
|
// get the required position
|
|
|
|
Overlay_Appearance::NotificationPosition pos = Overlay_Appearance::default_pos;
|
|
|
|
switch (type) {
|
|
|
|
case notification_type::notification_type_achievement: pos = settings->overlay_appearance.ach_earned_pos; break;
|
|
|
|
case notification_type::notification_type_invite: pos = settings->overlay_appearance.invite_pos; break;
|
|
|
|
case notification_type::notification_type_message: pos = settings->overlay_appearance.chat_msg_pos; break;
|
|
|
|
default: /* satisfy compiler warning */ break;
|
|
|
|
}
|
|
|
|
|
|
|
|
float x = 0.0f;
|
|
|
|
float y = 0.0f;
|
|
|
|
const float noti_width = width * Notification::width_percent;
|
|
|
|
const float noti_height = Notification::height * font_size;
|
|
|
|
switch (pos) {
|
|
|
|
// top
|
|
|
|
case Overlay_Appearance::NotificationPosition::top_left:
|
|
|
|
x = 0.0f;
|
|
|
|
y = noti_height * idx.top_left;
|
|
|
|
++idx.top_left;
|
|
|
|
break;
|
|
|
|
case Overlay_Appearance::NotificationPosition::top_center:
|
|
|
|
x = (width / 2) - (noti_width / 2);
|
|
|
|
y = noti_height * idx.top_center;
|
|
|
|
++idx.top_center;
|
|
|
|
break;
|
|
|
|
case Overlay_Appearance::NotificationPosition::top_right:
|
|
|
|
x = width - noti_width;
|
|
|
|
y = noti_height * idx.top_right;
|
|
|
|
++idx.top_right;
|
|
|
|
break;
|
|
|
|
|
|
|
|
// bot
|
|
|
|
case Overlay_Appearance::NotificationPosition::bot_left:
|
|
|
|
x = 0.0f;
|
|
|
|
y = height - noti_height * (idx.bot_left + 1);
|
|
|
|
++idx.bot_left;
|
|
|
|
break;
|
|
|
|
case Overlay_Appearance::NotificationPosition::bot_center:
|
|
|
|
x = (width / 2) - (noti_width / 2);
|
|
|
|
y = height - noti_height * (idx.bot_center + 1);
|
|
|
|
++idx.bot_center;
|
|
|
|
break;
|
|
|
|
case Overlay_Appearance::NotificationPosition::bot_right:
|
|
|
|
x = width - noti_width;
|
|
|
|
y = height - noti_height * (idx.bot_right + 1);
|
|
|
|
++idx.bot_right;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* satisfy compiler warning */ break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::SetNextWindowPos(ImVec2( x, y ));
|
|
|
|
}
|
|
|
|
|
2024-03-07 08:57:48 +08:00
|
|
|
void Steam_Overlay::build_notifications(int width, int height)
|
2019-08-27 01:36:07 +08:00
|
|
|
{
|
2019-09-05 01:31:31 +08:00
|
|
|
auto now = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch());
|
2024-01-26 11:49:03 +08:00
|
|
|
float font_size = ImGui::GetFontSize();
|
|
|
|
std::queue<Friend> friend_actions_temp{};
|
2020-01-26 22:46:57 +08:00
|
|
|
|
2024-03-04 08:39:50 +08:00
|
|
|
NotificationsIndexes idx{};
|
|
|
|
for (auto it = notifications.begin(); it != notifications.end(); ++it) {
|
|
|
|
auto elapsed_notif = now - it->start_time;
|
|
|
|
|
2024-03-07 08:57:48 +08:00
|
|
|
set_next_notification_pos(width, height, font_size, (notification_type)it->type, idx);
|
2024-03-06 06:44:33 +08:00
|
|
|
ImGui::SetNextWindowSize(ImVec2( width * Notification::width_percent, Notification::height * font_size ));
|
2024-03-10 00:38:05 +08:00
|
|
|
ImGui::SetNextWindowBgAlpha(0.9f);
|
2024-03-06 06:44:33 +08:00
|
|
|
|
2024-03-04 08:39:50 +08:00
|
|
|
if ( elapsed_notif < Notification::fade_in) { // still appearing (fading in)
|
|
|
|
float alpha = settings->overlay_appearance.notification_a * (elapsed_notif.count() / static_cast<float>(Notification::fade_in.count()));
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0, 0, 0, alpha));
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(settings->overlay_appearance.notification_r, settings->overlay_appearance.notification_g, settings->overlay_appearance.notification_b, alpha));
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(255, 255, 255, alpha*2));
|
|
|
|
} else if ( elapsed_notif > Notification::fade_out_start) { // fading out
|
|
|
|
float alpha = settings->overlay_appearance.notification_a * ((Notification::show_time - elapsed_notif).count() / static_cast<float>(Notification::fade_out.count()));
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0, 0, 0, alpha));
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(settings->overlay_appearance.notification_r, settings->overlay_appearance.notification_g, settings->overlay_appearance.notification_b, alpha));
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(255, 255, 255, alpha*2));
|
|
|
|
} else { // still in the visible time limit
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0, 0, 0, settings->overlay_appearance.notification_a));
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(settings->overlay_appearance.notification_r, settings->overlay_appearance.notification_g, settings->overlay_appearance.notification_b, settings->overlay_appearance.notification_a));
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(255, 255, 255, settings->overlay_appearance.notification_a*2));
|
|
|
|
}
|
|
|
|
|
2024-03-10 00:38:05 +08:00
|
|
|
// some extra window flags for each notification type
|
2024-03-13 03:21:09 +08:00
|
|
|
ImGuiWindowFlags extra_flags = ImGuiWindowFlags_NoFocusOnAppearing;
|
2024-03-10 00:38:05 +08:00
|
|
|
switch (it->type) {
|
|
|
|
// games like "Mafia Definitive Edition" will pause the entire game/scene if focus was stolen
|
|
|
|
// be less intrusive for notifications that do not require interaction
|
|
|
|
case notification_type_achievement:
|
|
|
|
case notification_type_auto_accept_invite:
|
2024-03-13 03:21:09 +08:00
|
|
|
case notification_type_message:
|
|
|
|
extra_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoInputs;
|
2024-03-10 00:38:05 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case notification_type_invite:
|
|
|
|
// nothing
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("error unhandled flags for type %i", (int)it->type);
|
2024-03-10 00:38:05 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-03-04 08:39:50 +08:00
|
|
|
std::string wnd_name = "NotiPopupShow" + std::to_string(it->id);
|
2024-03-10 00:38:05 +08:00
|
|
|
if (ImGui::Begin(wnd_name.c_str(), nullptr,
|
|
|
|
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoResize | extra_flags)) {
|
|
|
|
switch (it->type) {
|
|
|
|
case notification_type_achievement: {
|
|
|
|
if (!it->icon.expired() && ImGui::BeginTable("imgui_table", 2)) {
|
|
|
|
ImGui::TableSetupColumn("imgui_table_image", ImGuiTableColumnFlags_WidthFixed, settings->overlay_appearance.icon_size);
|
|
|
|
ImGui::TableSetupColumn("imgui_table_text");
|
|
|
|
ImGui::TableNextRow(ImGuiTableRowFlags_None, settings->overlay_appearance.icon_size);
|
2024-03-04 08:39:50 +08:00
|
|
|
|
2024-03-10 00:38:05 +08:00
|
|
|
ImGui::TableSetColumnIndex(0);
|
|
|
|
ImGui::Image((ImTextureID)*it->icon.lock().get(), ImVec2(settings->overlay_appearance.icon_size, settings->overlay_appearance.icon_size));
|
2024-03-04 08:39:50 +08:00
|
|
|
|
2024-03-10 00:38:05 +08:00
|
|
|
ImGui::TableSetColumnIndex(1);
|
|
|
|
ImGui::TextWrapped("%s", it->message.c_str());
|
2024-03-04 08:39:50 +08:00
|
|
|
|
2024-03-10 00:38:05 +08:00
|
|
|
ImGui::EndTable();
|
|
|
|
} else {
|
|
|
|
ImGui::TextWrapped("%s", it->message.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2019-09-05 01:31:31 +08:00
|
|
|
|
2024-03-10 00:38:05 +08:00
|
|
|
case notification_type_invite: {
|
2024-03-04 08:39:50 +08:00
|
|
|
ImGui::TextWrapped("%s", it->message.c_str());
|
2024-03-10 00:38:05 +08:00
|
|
|
if (ImGui::Button(translationJoin[current_language]))
|
|
|
|
{
|
|
|
|
it->frd->second.window_state |= window_state_join;
|
|
|
|
friend_actions_temp.push(it->frd->first);
|
|
|
|
it->start_time = std::chrono::seconds(0);
|
|
|
|
}
|
2024-03-04 08:39:50 +08:00
|
|
|
}
|
2024-03-10 00:38:05 +08:00
|
|
|
break;
|
2023-11-10 23:25:36 +08:00
|
|
|
|
2024-03-10 00:38:05 +08:00
|
|
|
case notification_type_message:
|
|
|
|
ImGui::TextWrapped("%s", it->message.c_str());
|
|
|
|
break;
|
2020-01-27 06:24:16 +08:00
|
|
|
|
2024-03-10 00:38:05 +08:00
|
|
|
case notification_type_auto_accept_invite:
|
|
|
|
ImGui::TextWrapped("%s", it->message.c_str());
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("error unhandled notification for type %i", (int)it->type);
|
2024-03-10 00:38:05 +08:00
|
|
|
break;
|
|
|
|
}
|
2019-09-05 01:31:31 +08:00
|
|
|
|
2020-01-27 06:24:16 +08:00
|
|
|
}
|
2022-08-05 14:09:43 +08:00
|
|
|
|
2024-03-04 08:39:50 +08:00
|
|
|
ImGui::End();
|
|
|
|
|
|
|
|
ImGui::PopStyleColor(3);
|
2020-01-27 06:24:16 +08:00
|
|
|
}
|
2019-09-05 01:31:31 +08:00
|
|
|
|
2024-03-04 08:39:50 +08:00
|
|
|
// erase all notifications whose visible time exceeded the max
|
2024-03-12 05:55:19 +08:00
|
|
|
notifications.erase(std::remove_if(notifications.begin(), notifications.end(), [this, &now](Notification &item) {
|
|
|
|
if ((now - item.start_time) > Notification::show_time) {
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("removing a notification");
|
2024-03-12 05:55:19 +08:00
|
|
|
allow_renderer_frame_processing(false);
|
2024-03-13 03:21:09 +08:00
|
|
|
// uncomment this block to restore app input focus
|
2024-03-18 11:57:24 +08:00
|
|
|
switch (item.type) {
|
|
|
|
// we want to restore focus for these ones
|
|
|
|
case notification_type_invite:
|
|
|
|
obscure_game_input(false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
// not effective
|
|
|
|
case notification_type_achievement:
|
|
|
|
case notification_type_auto_accept_invite:
|
|
|
|
case notification_type_message:
|
|
|
|
// nothing
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("error unhandled remove for type %i", (int)item.type);
|
2024-03-18 11:57:24 +08:00
|
|
|
break;
|
|
|
|
}
|
2024-03-12 06:25:47 +08:00
|
|
|
|
2024-03-12 05:55:19 +08:00
|
|
|
return true;
|
|
|
|
}
|
2024-03-12 06:25:47 +08:00
|
|
|
|
2024-03-12 05:55:19 +08:00
|
|
|
return false;
|
2024-03-04 08:39:50 +08:00
|
|
|
}), notifications.end());
|
|
|
|
|
2020-01-27 06:24:16 +08:00
|
|
|
if (!friend_actions_temp.empty()) {
|
|
|
|
while (!friend_actions_temp.empty()) {
|
|
|
|
has_friend_action.push(friend_actions_temp.front());
|
|
|
|
friend_actions_temp.pop();
|
|
|
|
}
|
2019-09-05 01:31:31 +08:00
|
|
|
}
|
2019-08-27 01:36:07 +08:00
|
|
|
}
|
|
|
|
|
2024-03-08 05:19:31 +08:00
|
|
|
void Steam_Overlay::add_auto_accept_invite_notification()
|
2019-09-05 15:00:02 +08:00
|
|
|
{
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG_ENTRY();
|
2024-03-08 05:19:31 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
|
|
|
if (!Ready()) return;
|
2024-03-02 22:09:22 +08:00
|
|
|
|
2024-03-08 05:19:31 +08:00
|
|
|
char tmp[TRANSLATION_BUFFER_SIZE]{};
|
|
|
|
snprintf(tmp, sizeof(tmp), "%s", translationAutoAcceptFriendInvite[current_language]);
|
2024-03-02 22:09:22 +08:00
|
|
|
|
2024-03-08 05:19:31 +08:00
|
|
|
submit_notification(notification_type_auto_accept_invite, tmp);
|
|
|
|
notify_sound_auto_accept_friend_invite();
|
2019-09-05 15:00:02 +08:00
|
|
|
}
|
|
|
|
|
2024-03-09 09:45:21 +08:00
|
|
|
void Steam_Overlay::add_invite_notification(std::pair<const Friend, friend_window_state>& wnd_state)
|
|
|
|
{
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG_ENTRY();
|
2024-03-09 09:45:21 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
|
|
|
if (settings->disable_overlay_friend_notification) return;
|
|
|
|
if (!Ready()) return;
|
|
|
|
|
|
|
|
char tmp[TRANSLATION_BUFFER_SIZE]{};
|
|
|
|
auto &first_friend = wnd_state.first;
|
|
|
|
auto &name = first_friend.name();
|
|
|
|
snprintf(tmp, sizeof(tmp), translationInvitedYouToJoinTheGame[current_language], name.c_str(), (uint64)first_friend.id());
|
|
|
|
|
|
|
|
submit_notification(notification_type_invite, tmp, &wnd_state);
|
|
|
|
}
|
|
|
|
|
2024-03-08 05:19:31 +08:00
|
|
|
void Steam_Overlay::invite_friend(uint64 friend_id, class Steam_Friends* steamFriends, class Steam_Matchmaking* steamMatchmaking)
|
2023-11-10 23:25:36 +08:00
|
|
|
{
|
2024-03-08 05:19:31 +08:00
|
|
|
std::string connect_str = steamFriends->GetFriendRichPresence(settings->get_local_steam_id(), "connect");
|
|
|
|
if (connect_str.length() > 0) {
|
|
|
|
steamFriends->InviteUserToGame(friend_id, connect_str.c_str());
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("sent game invitation to friend with id = %llu", friend_id);
|
2024-03-08 05:19:31 +08:00
|
|
|
} else if (settings->get_lobby().IsValid()) {
|
|
|
|
steamMatchmaking->InviteUserToLobby(settings->get_lobby(), friend_id);
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("sent lobby invitation to friend with id = %llu", friend_id);
|
2023-11-10 23:25:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-10 14:10:50 +08:00
|
|
|
bool Steam_Overlay::try_load_ach_icon(Overlay_Achievement &ach, bool achieved)
|
2024-03-13 03:21:09 +08:00
|
|
|
{
|
|
|
|
if (!_renderer) return false;
|
|
|
|
|
2024-04-10 14:10:50 +08:00
|
|
|
std::weak_ptr<uint64_t> &icon_rsrc = achieved ? ach.icon : ach.icon_gray;
|
|
|
|
const std::string &icon_name = achieved ? ach.icon_name : ach.icon_gray_name;
|
|
|
|
uint8_t &load_trials = achieved ? ach.icon_load_trials : ach.icon_gray_load_trials;
|
2024-03-13 03:21:09 +08:00
|
|
|
|
2024-04-10 14:10:50 +08:00
|
|
|
if (!icon_rsrc.expired()) return true;
|
2024-03-13 03:21:09 +08:00
|
|
|
|
2024-04-10 14:10:50 +08:00
|
|
|
if (load_trials && icon_name.size()) {
|
|
|
|
--load_trials;
|
|
|
|
std::string file_path(Local_Storage::get_game_settings_path() + icon_name);
|
|
|
|
unsigned int file_size = file_size_(file_path);
|
2024-03-13 03:21:09 +08:00
|
|
|
if (!file_size) {
|
2024-04-11 05:49:01 +08:00
|
|
|
file_path = Local_Storage::get_game_settings_path() + Steam_Overlay::ACH_FALLBACK_DIR + PATH_SEPARATOR + icon_name;
|
2024-03-13 03:21:09 +08:00
|
|
|
file_size = file_size_(file_path);
|
|
|
|
}
|
|
|
|
if (file_size) {
|
|
|
|
std::string img = Local_Storage::load_image_resized(file_path, "", settings->overlay_appearance.icon_size);
|
|
|
|
if (img.length() > 0) {
|
2024-04-10 14:10:50 +08:00
|
|
|
icon_rsrc = _renderer->CreateImageResource(
|
2024-03-13 03:21:09 +08:00
|
|
|
(void*)img.c_str(),
|
|
|
|
settings->overlay_appearance.icon_size, settings->overlay_appearance.icon_size);
|
2024-04-10 14:10:50 +08:00
|
|
|
|
|
|
|
if (!icon_rsrc.expired()) load_trials = Overlay_Achievement::ICON_LOAD_MAX_TRIALS;
|
|
|
|
PRINT_DEBUG("'%s' (result=%i)", ach.name.c_str(), (int)!icon_rsrc.expired());
|
2024-03-13 03:21:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-10 14:10:50 +08:00
|
|
|
return !icon_rsrc.expired();
|
2024-03-13 03:21:09 +08:00
|
|
|
}
|
|
|
|
|
2019-08-14 20:56:57 +08:00
|
|
|
// Try to make this function as short as possible or it might affect game's fps.
|
2024-03-15 01:23:39 +08:00
|
|
|
void Steam_Overlay::overlay_render_proc()
|
2019-08-01 04:21:02 +08:00
|
|
|
{
|
2024-03-15 01:23:39 +08:00
|
|
|
initial_load_achievements_icons();
|
2024-03-20 04:07:43 +08:00
|
|
|
|
2024-03-02 22:09:22 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
2024-03-06 04:59:17 +08:00
|
|
|
if (!Ready()) return;
|
2019-08-16 16:37:45 +08:00
|
|
|
|
2024-03-10 00:38:05 +08:00
|
|
|
ImGuiIO &io = ImGui::GetIO();
|
2019-09-05 15:00:02 +08:00
|
|
|
|
2024-03-04 08:39:50 +08:00
|
|
|
// Set the overlay windows to the size of the game window
|
|
|
|
// only if we have a reason (full overlay or just some notification)
|
|
|
|
if (show_overlay || notifications.size()) {
|
2019-08-14 20:56:57 +08:00
|
|
|
ImGui::SetNextWindowPos({ 0,0 });
|
2024-03-02 22:09:22 +08:00
|
|
|
ImGui::SetNextWindowSize({ io.DisplaySize.x, io.DisplaySize.y });
|
2024-03-10 00:38:05 +08:00
|
|
|
ImGui::SetNextWindowBgAlpha(0.55f);
|
2024-03-02 22:09:22 +08:00
|
|
|
}
|
2019-08-01 04:21:02 +08:00
|
|
|
|
2024-03-20 04:07:43 +08:00
|
|
|
if (show_overlay) {
|
|
|
|
render_main_window();
|
|
|
|
}
|
|
|
|
|
2024-03-04 08:39:50 +08:00
|
|
|
if (notifications.size()) {
|
2024-03-02 22:09:22 +08:00
|
|
|
ImGui::PushFont(font_notif);
|
2024-03-07 08:57:48 +08:00
|
|
|
build_notifications(io.DisplaySize.x, io.DisplaySize.y);
|
2024-03-02 22:09:22 +08:00
|
|
|
ImGui::PopFont();
|
|
|
|
}
|
2019-10-11 06:25:44 +08:00
|
|
|
|
2024-03-20 04:07:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Try to make this function as short as possible or it might affect game's fps.
|
|
|
|
void Steam_Overlay::render_main_window()
|
|
|
|
{
|
2024-03-04 08:39:50 +08:00
|
|
|
//ImGui::SetNextWindowFocus();
|
|
|
|
ImGui::PushFont(font_default);
|
2024-03-02 22:09:22 +08:00
|
|
|
bool show = true;
|
2023-11-10 23:25:36 +08:00
|
|
|
|
2024-03-02 22:09:22 +08:00
|
|
|
char tmp[TRANSLATION_BUFFER_SIZE]{};
|
|
|
|
snprintf(tmp, sizeof(tmp), translationRenderer[current_language], (_renderer == nullptr ? "Unknown" : _renderer->GetLibraryName().c_str()));
|
2024-04-12 10:25:50 +08:00
|
|
|
std::string windowTitle{};
|
|
|
|
// Note: don't translate this, project and author names are nouns, they must be kept intact for proper referral
|
2024-04-13 16:04:30 +08:00
|
|
|
// think of it as translating "Protobuf - Google"
|
|
|
|
windowTitle.append("Ingame Overlay project - Nemirtingas (").append(tmp).append(")");
|
2024-03-02 22:09:22 +08:00
|
|
|
|
2024-03-15 01:23:39 +08:00
|
|
|
if ((settings->overlay_appearance.background_r >= 0) &&
|
|
|
|
(settings->overlay_appearance.background_g >= 0) &&
|
|
|
|
(settings->overlay_appearance.background_b >= 0) &&
|
|
|
|
(settings->overlay_appearance.background_a >= 0)) {
|
|
|
|
ImVec4 colorSet = ImVec4(
|
|
|
|
settings->overlay_appearance.background_r,
|
|
|
|
settings->overlay_appearance.background_g,
|
|
|
|
settings->overlay_appearance.background_b,
|
|
|
|
settings->overlay_appearance.background_a
|
|
|
|
);
|
2024-03-02 22:09:22 +08:00
|
|
|
ImGui::PushStyleColor(ImGuiCol_WindowBg, colorSet);
|
|
|
|
}
|
2024-03-15 01:23:39 +08:00
|
|
|
|
|
|
|
if ((settings->overlay_appearance.element_r >= 0) &&
|
|
|
|
(settings->overlay_appearance.element_g >= 0) &&
|
|
|
|
(settings->overlay_appearance.element_b >= 0) &&
|
|
|
|
(settings->overlay_appearance.element_a >= 0)) {
|
|
|
|
ImVec4 colorSet = ImVec4(
|
|
|
|
settings->overlay_appearance.element_r,
|
|
|
|
settings->overlay_appearance.element_g,
|
|
|
|
settings->overlay_appearance.element_b,
|
|
|
|
settings->overlay_appearance.element_a
|
|
|
|
);
|
2024-03-02 22:09:22 +08:00
|
|
|
ImGui::PushStyleColor(ImGuiCol_TitleBgActive, colorSet);
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Button, colorSet);
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_FrameBg, colorSet);
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_ResizeGrip, colorSet);
|
|
|
|
}
|
2024-03-15 01:23:39 +08:00
|
|
|
|
|
|
|
if ((settings->overlay_appearance.element_hovered_r >= 0) &&
|
|
|
|
(settings->overlay_appearance.element_hovered_g >= 0) &&
|
|
|
|
(settings->overlay_appearance.element_hovered_b >= 0) &&
|
|
|
|
(settings->overlay_appearance.element_hovered_a >= 0)) {
|
|
|
|
ImVec4 colorSet = ImVec4(
|
|
|
|
settings->overlay_appearance.element_hovered_r,
|
|
|
|
settings->overlay_appearance.element_hovered_g,
|
|
|
|
settings->overlay_appearance.element_hovered_b,
|
|
|
|
settings->overlay_appearance.element_hovered_a
|
|
|
|
);
|
2024-03-02 22:09:22 +08:00
|
|
|
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, colorSet);
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, colorSet);
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_ResizeGripHovered, colorSet);
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_HeaderHovered, colorSet);
|
|
|
|
}
|
2024-03-15 01:23:39 +08:00
|
|
|
|
|
|
|
if ((settings->overlay_appearance.element_active_r >= 0) &&
|
|
|
|
(settings->overlay_appearance.element_active_g >= 0) &&
|
|
|
|
(settings->overlay_appearance.element_active_b >= 0) &&
|
|
|
|
(settings->overlay_appearance.element_active_a >= 0)) {
|
|
|
|
ImVec4 colorSet = ImVec4(
|
|
|
|
settings->overlay_appearance.element_active_r,
|
|
|
|
settings->overlay_appearance.element_active_g,
|
|
|
|
settings->overlay_appearance.element_active_b,
|
|
|
|
settings->overlay_appearance.element_active_a
|
|
|
|
);
|
2024-03-02 22:09:22 +08:00
|
|
|
ImGui::PushStyleColor(ImGuiCol_ButtonActive, colorSet);
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_FrameBgActive, colorSet);
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_ResizeGripActive, colorSet);
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Header, colorSet);
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_HeaderActive, colorSet);
|
|
|
|
}
|
2023-11-13 05:09:17 +08:00
|
|
|
|
2024-03-06 06:44:33 +08:00
|
|
|
if (ImGui::Begin(windowTitle.c_str(), &show,
|
2024-03-08 05:19:31 +08:00
|
|
|
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse |
|
2024-03-15 01:23:39 +08:00
|
|
|
ImGuiWindowFlags_NoBringToFrontOnFocus)) {
|
2024-03-06 06:44:33 +08:00
|
|
|
ImGui::LabelText("##playinglabel", translationUserPlaying[current_language],
|
2024-03-02 22:09:22 +08:00
|
|
|
settings->get_local_name(),
|
|
|
|
settings->get_local_steam_id().ConvertToUint64(),
|
|
|
|
settings->get_local_game_id().AppID());
|
2022-08-05 14:09:43 +08:00
|
|
|
|
2024-03-02 22:09:22 +08:00
|
|
|
ImGui::SameLine();
|
|
|
|
ImGui::Spacing();
|
2024-03-06 04:59:17 +08:00
|
|
|
// user clicked on "show achievements"
|
2024-03-02 22:09:22 +08:00
|
|
|
if (ImGui::Button(translationShowAchievements[current_language])) {
|
|
|
|
show_achievements = true;
|
|
|
|
}
|
2022-08-05 14:09:43 +08:00
|
|
|
|
2024-03-02 22:09:22 +08:00
|
|
|
ImGui::SameLine();
|
2024-03-06 04:59:17 +08:00
|
|
|
// user clicked on "settings"
|
2024-03-02 22:09:22 +08:00
|
|
|
if (ImGui::Button(translationSettings[current_language])) {
|
|
|
|
show_settings = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
// user clicked on "copy id" on themselves
|
|
|
|
if (ImGui::Button(translationCopyId[current_language])) {
|
|
|
|
auto friend_id_str = std::to_string(settings->get_local_steam_id().ConvertToUint64());
|
|
|
|
ImGui::SetClipboardText(friend_id_str.c_str());
|
|
|
|
}
|
2024-01-23 07:44:32 +08:00
|
|
|
|
2024-03-02 22:09:22 +08:00
|
|
|
ImGui::Spacing();
|
|
|
|
ImGui::Spacing();
|
2024-03-03 09:34:19 +08:00
|
|
|
ImGui::LabelText("##label", "%s", translationFriends[current_language]);
|
2020-01-26 22:46:57 +08:00
|
|
|
|
2024-03-02 22:09:22 +08:00
|
|
|
if (!friends.empty()) {
|
|
|
|
if (i_have_lobby) {
|
|
|
|
std::string inviteAll(translationInviteAll[current_language]);
|
|
|
|
inviteAll.append("##PopupInviteAllFriends");
|
|
|
|
if (ImGui::Button(inviteAll.c_str())) { // if btn clicked
|
|
|
|
invite_all_friends_clicked = true;
|
2024-01-22 07:31:02 +08:00
|
|
|
}
|
2024-03-02 22:09:22 +08:00
|
|
|
}
|
2024-01-22 07:31:02 +08:00
|
|
|
|
2024-03-02 22:09:22 +08:00
|
|
|
if (ImGuiHelper_BeginListBox("##label", friends.size())) {
|
|
|
|
std::for_each(friends.begin(), friends.end(), [this](std::pair<Friend const, friend_window_state> &i) {
|
|
|
|
ImGui::PushID(i.second.id-base_friend_window_id+base_friend_item_id);
|
2021-05-09 16:11:35 +08:00
|
|
|
|
2024-03-02 22:09:22 +08:00
|
|
|
ImGui::Selectable(i.second.window_title.c_str(), false, ImGuiSelectableFlags_AllowDoubleClick);
|
2024-03-07 08:57:48 +08:00
|
|
|
build_friend_context_menu(i.first, i.second);
|
2024-03-02 22:09:22 +08:00
|
|
|
if (ImGui::IsItemClicked() && ImGui::IsMouseDoubleClicked(0)) {
|
|
|
|
i.second.window_state |= window_state_show;
|
|
|
|
}
|
|
|
|
ImGui::PopID();
|
2019-08-17 00:31:56 +08:00
|
|
|
|
2024-03-07 08:57:48 +08:00
|
|
|
build_friend_window(i.first, i.second);
|
2024-03-02 22:09:22 +08:00
|
|
|
});
|
|
|
|
ImGui::EndListBox();
|
2019-08-17 00:31:56 +08:00
|
|
|
}
|
2024-03-02 22:09:22 +08:00
|
|
|
}
|
2022-08-05 14:09:43 +08:00
|
|
|
|
2024-03-10 00:38:05 +08:00
|
|
|
// user clicked on "show achievements" button
|
|
|
|
if (show_achievements && achievements.size()) {
|
2024-03-02 22:09:22 +08:00
|
|
|
ImGui::SetNextWindowSizeConstraints(ImVec2(ImGui::GetFontSize() * 32, ImGui::GetFontSize() * 32), ImVec2(8192, 8192));
|
2024-03-10 00:38:05 +08:00
|
|
|
ImGui::SetNextWindowBgAlpha(0.9f);
|
2024-03-02 22:09:22 +08:00
|
|
|
bool show = show_achievements;
|
|
|
|
if (ImGui::Begin(translationAchievementWindow[current_language], &show)) {
|
2024-03-03 09:34:19 +08:00
|
|
|
ImGui::Text("%s", translationListOfAchievements[current_language]);
|
2024-03-02 22:09:22 +08:00
|
|
|
ImGui::BeginChild(translationAchievements[current_language]);
|
|
|
|
for (auto & x : achievements) {
|
|
|
|
bool achieved = x.achieved;
|
|
|
|
bool hidden = x.hidden && !achieved;
|
|
|
|
|
2024-04-10 14:10:50 +08:00
|
|
|
try_load_ach_icon(x, true);
|
|
|
|
try_load_ach_icon(x, false);
|
2023-11-10 23:25:36 +08:00
|
|
|
|
2024-03-02 22:09:22 +08:00
|
|
|
ImGui::Separator();
|
2023-11-10 23:25:36 +08:00
|
|
|
|
2024-03-10 00:38:05 +08:00
|
|
|
bool could_create_ach_table_entry = false;
|
|
|
|
if (!x.icon.expired() || !x.icon_gray.expired()) {
|
|
|
|
if (ImGui::BeginTable(x.title.c_str(), 2)) {
|
|
|
|
could_create_ach_table_entry = true;
|
|
|
|
|
|
|
|
ImGui::TableSetupColumn("imgui_table_image", ImGuiTableColumnFlags_WidthFixed, settings->overlay_appearance.icon_size);
|
|
|
|
ImGui::TableSetupColumn("imgui_table_text");
|
|
|
|
ImGui::TableNextRow(ImGuiTableRowFlags_None, settings->overlay_appearance.icon_size);
|
|
|
|
|
|
|
|
ImGui::TableSetColumnIndex(0);
|
|
|
|
if (achieved) {
|
|
|
|
if (!x.icon.expired()) {
|
|
|
|
ImGui::Image(
|
|
|
|
(ImTextureID)*x.icon.lock().get(),
|
|
|
|
ImVec2(settings->overlay_appearance.icon_size, settings->overlay_appearance.icon_size)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!x.icon_gray.expired()) {
|
|
|
|
ImGui::Image(
|
|
|
|
(ImTextureID)*x.icon_gray.lock().get(),
|
|
|
|
ImVec2(settings->overlay_appearance.icon_size, settings->overlay_appearance.icon_size)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2023-11-10 23:25:36 +08:00
|
|
|
|
2024-03-10 00:38:05 +08:00
|
|
|
ImGui::TableSetColumnIndex(1);
|
|
|
|
// the next column is the achievement text below
|
2022-08-05 14:09:43 +08:00
|
|
|
}
|
2024-03-02 22:09:22 +08:00
|
|
|
}
|
2024-03-10 00:38:05 +08:00
|
|
|
|
|
|
|
// we want to display the ach text regardless the icons were displayed or not
|
|
|
|
ImGui::Text("%s", x.title.c_str());
|
2022-08-05 14:09:43 +08:00
|
|
|
|
2024-03-15 01:23:39 +08:00
|
|
|
if (hidden) {
|
2024-03-03 09:34:19 +08:00
|
|
|
ImGui::Text("%s", translationHiddenAchievement[current_language]);
|
2024-03-02 22:09:22 +08:00
|
|
|
} else {
|
|
|
|
ImGui::TextWrapped("%s", x.description.c_str());
|
|
|
|
}
|
2023-11-10 23:25:36 +08:00
|
|
|
|
2024-03-02 22:09:22 +08:00
|
|
|
if (achieved) {
|
|
|
|
char buffer[80] = {};
|
|
|
|
time_t unlock_time = (time_t)x.unlock_time;
|
2024-04-13 17:57:49 +08:00
|
|
|
// TODO add this format to the overlay_appearance.txt
|
|
|
|
std::strftime(buffer, 80, "%Y/%m/%d - %H:%M:%S", std::localtime(&unlock_time));
|
2023-11-10 23:25:36 +08:00
|
|
|
|
2024-03-02 22:09:22 +08:00
|
|
|
ImGui::TextColored(ImVec4(0, 255, 0, 255), translationAchievedOn[current_language], buffer);
|
|
|
|
} else {
|
2024-03-03 09:34:19 +08:00
|
|
|
ImGui::TextColored(ImVec4(255, 0, 0, 255), "%s", translationNotAchieved[current_language]);
|
2022-08-05 14:09:43 +08:00
|
|
|
}
|
2024-03-02 22:09:22 +08:00
|
|
|
|
2024-03-10 00:38:05 +08:00
|
|
|
if (could_create_ach_table_entry) ImGui::EndTable();
|
2024-03-02 22:09:22 +08:00
|
|
|
|
|
|
|
ImGui::Separator();
|
2022-08-05 14:09:43 +08:00
|
|
|
}
|
2024-03-02 22:09:22 +08:00
|
|
|
ImGui::EndChild();
|
2022-08-05 14:09:43 +08:00
|
|
|
}
|
2024-03-10 00:38:05 +08:00
|
|
|
|
2024-03-02 22:09:22 +08:00
|
|
|
ImGui::End();
|
|
|
|
show_achievements = show;
|
|
|
|
}
|
2022-08-05 14:09:43 +08:00
|
|
|
|
2024-03-10 00:38:05 +08:00
|
|
|
// user clicked on "settings" button
|
2024-03-02 22:09:22 +08:00
|
|
|
if (show_settings) {
|
2024-03-10 00:38:05 +08:00
|
|
|
ImGui::SetNextWindowBgAlpha(0.9f);
|
2024-03-02 22:09:22 +08:00
|
|
|
if (ImGui::Begin(translationGlobalSettingsWindow[current_language], &show_settings)) {
|
2024-03-03 09:34:19 +08:00
|
|
|
ImGui::Text("%s", translationGlobalSettingsWindowDescription[current_language]);
|
2022-08-05 14:09:43 +08:00
|
|
|
|
2024-03-02 22:09:22 +08:00
|
|
|
ImGui::Separator();
|
2022-08-05 14:09:43 +08:00
|
|
|
|
2024-03-03 09:34:19 +08:00
|
|
|
ImGui::Text("%s", translationUsername[current_language]);
|
2024-03-02 22:09:22 +08:00
|
|
|
ImGui::SameLine();
|
2024-04-20 06:49:28 +08:00
|
|
|
ImGui::InputText("##username", username_text, sizeof(username_text), 0);
|
2022-08-05 14:09:43 +08:00
|
|
|
|
2024-03-02 22:09:22 +08:00
|
|
|
ImGui::Separator();
|
2022-08-05 14:09:43 +08:00
|
|
|
|
2024-03-03 09:34:19 +08:00
|
|
|
ImGui::Text("%s", translationLanguage[current_language]);
|
|
|
|
ImGui::ListBox("##language", ¤t_language, valid_languages, sizeof(valid_languages) / sizeof(valid_languages[0]), 7);
|
2024-03-02 22:09:22 +08:00
|
|
|
ImGui::Text(translationSelectedLanguage[current_language], valid_languages[current_language]);
|
2022-08-05 14:09:43 +08:00
|
|
|
|
2024-03-02 22:09:22 +08:00
|
|
|
ImGui::Separator();
|
2022-08-05 14:09:43 +08:00
|
|
|
|
2024-04-20 06:49:28 +08:00
|
|
|
ImGui::Text("%s", translationRestartTheGameToApply[current_language]);
|
|
|
|
if (ImGui::Button(translationSave[current_language])) {
|
|
|
|
save_settings = true;
|
|
|
|
show_settings = false;
|
2022-08-05 14:09:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-02 22:09:22 +08:00
|
|
|
ImGui::End();
|
|
|
|
}
|
|
|
|
|
2024-03-15 01:23:39 +08:00
|
|
|
// we have a url to open/display
|
2024-03-10 00:38:05 +08:00
|
|
|
if (show_url.size()) {
|
|
|
|
std::string url = show_url;
|
2024-03-02 22:09:22 +08:00
|
|
|
bool show = true;
|
2024-03-10 00:38:05 +08:00
|
|
|
ImGui::SetNextWindowBgAlpha(0.9f);
|
2024-03-02 22:09:22 +08:00
|
|
|
if (ImGui::Begin(URL_WINDOW_NAME, &show)) {
|
2024-03-03 09:34:19 +08:00
|
|
|
ImGui::Text("%s", translationSteamOverlayURL[current_language]);
|
2024-03-02 22:09:22 +08:00
|
|
|
ImGui::Spacing();
|
|
|
|
ImGui::PushItemWidth(ImGui::CalcTextSize(url.c_str()).x + 20);
|
|
|
|
ImGui::InputText("##url_copy", (char *)url.data(), url.size(), ImGuiInputTextFlags_ReadOnly);
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
ImGui::Spacing();
|
|
|
|
if (ImGui::Button(translationClose[current_language]) || !show)
|
|
|
|
show_url = "";
|
|
|
|
// ImGui::SetWindowSize(ImVec2(ImGui::CalcTextSize(url.c_str()).x + 10, 0));
|
2022-08-05 14:09:43 +08:00
|
|
|
}
|
2024-03-10 00:38:05 +08:00
|
|
|
|
2024-03-02 22:09:22 +08:00
|
|
|
ImGui::End();
|
|
|
|
}
|
2022-08-05 14:09:43 +08:00
|
|
|
|
2024-04-20 06:49:28 +08:00
|
|
|
bool show_warning = warn_local_save || warn_bad_appid;
|
2024-03-02 22:09:22 +08:00
|
|
|
if (show_warning) {
|
|
|
|
ImGui::SetNextWindowSizeConstraints(ImVec2(ImGui::GetFontSize() * 32, ImGui::GetFontSize() * 32), ImVec2(8192, 8192));
|
|
|
|
ImGui::SetNextWindowFocus();
|
2024-03-10 00:38:05 +08:00
|
|
|
ImGui::SetNextWindowBgAlpha(0.9f);
|
2024-03-02 22:09:22 +08:00
|
|
|
if (ImGui::Begin(translationWarning[current_language], &show_warning)) {
|
|
|
|
if (warn_bad_appid) {
|
2024-03-03 09:34:19 +08:00
|
|
|
ImGui::TextColored(ImVec4(255, 0, 0, 255), "%s", translationWarningWarningWarning[current_language]);
|
2024-04-20 06:49:28 +08:00
|
|
|
ImGui::TextWrapped("%s", translationWarningDescription_badAppid[current_language]);
|
2024-03-03 09:34:19 +08:00
|
|
|
ImGui::TextColored(ImVec4(255, 0, 0, 255), "%s", translationWarningWarningWarning[current_language]);
|
2024-03-02 22:09:22 +08:00
|
|
|
}
|
|
|
|
if (warn_local_save) {
|
2024-03-03 09:34:19 +08:00
|
|
|
ImGui::TextColored(ImVec4(255, 0, 0, 255), "%s", translationWarningWarningWarning[current_language]);
|
2024-04-20 06:49:28 +08:00
|
|
|
ImGui::TextWrapped("%s", translationWarningDescription_localSave[current_language]);
|
2024-03-03 09:34:19 +08:00
|
|
|
ImGui::TextColored(ImVec4(255, 0, 0, 255), "%s", translationWarningWarningWarning[current_language]);
|
2022-08-05 14:09:43 +08:00
|
|
|
}
|
|
|
|
}
|
2024-03-10 00:38:05 +08:00
|
|
|
|
2024-03-02 22:09:22 +08:00
|
|
|
ImGui::End();
|
|
|
|
if (!show_warning) {
|
2024-04-20 06:49:28 +08:00
|
|
|
warn_local_save = false;
|
2024-03-02 22:09:22 +08:00
|
|
|
}
|
2019-08-14 20:56:57 +08:00
|
|
|
}
|
2024-03-02 22:09:22 +08:00
|
|
|
}
|
2024-03-10 00:38:05 +08:00
|
|
|
|
2024-03-02 22:09:22 +08:00
|
|
|
ImGui::End();
|
2019-09-05 15:00:02 +08:00
|
|
|
|
2024-03-02 22:09:22 +08:00
|
|
|
ImGui::PopFont();
|
2019-10-11 06:25:44 +08:00
|
|
|
|
2024-03-20 04:07:43 +08:00
|
|
|
if (!show) ShowOverlay(false);
|
|
|
|
|
2019-08-01 04:21:02 +08:00
|
|
|
}
|
|
|
|
|
2024-03-15 01:23:39 +08:00
|
|
|
void Steam_Overlay::networking_msg_received(Common_Message *msg)
|
|
|
|
{
|
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
|
|
|
|
|
|
|
if (!Ready()) return;
|
|
|
|
|
|
|
|
if (msg->has_steam_messages()) {
|
|
|
|
Friend frd;
|
|
|
|
frd.set_id(msg->source_id());
|
|
|
|
auto friend_info = friends.find(frd);
|
|
|
|
if (friend_info != friends.end()) {
|
|
|
|
Steam_Messages const& steam_message = msg->steam_messages();
|
|
|
|
// Change color to cyan for friend
|
|
|
|
friend_info->second.chat_history.append(friend_info->first.name() + ": " + steam_message.message()).append("\n", 1);
|
|
|
|
if (!(friend_info->second.window_state & window_state_show)) {
|
|
|
|
friend_info->second.window_state |= window_state_need_attention;
|
|
|
|
}
|
|
|
|
|
|
|
|
add_chat_message_notification(friend_info->first.name() + ": " + steam_message.message());
|
|
|
|
notify_sound_user_invite(friend_info->second);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Overlay::steam_run_callback()
|
|
|
|
{
|
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
|
|
|
|
|
|
|
if (!Ready()) return;
|
|
|
|
|
|
|
|
if (overlay_state_changed) {
|
|
|
|
overlay_state_changed = false;
|
|
|
|
|
|
|
|
GameOverlayActivated_t data{};
|
|
|
|
data.m_bActive = show_overlay;
|
|
|
|
data.m_bUserInitiated = true;
|
|
|
|
data.m_dwOverlayPID = 123;
|
|
|
|
data.m_nAppID = settings->get_local_game_id().AppID();
|
|
|
|
callbacks->addCBResult(data.k_iCallback, &data, sizeof(data));
|
|
|
|
}
|
|
|
|
|
|
|
|
Steam_Friends* steamFriends = get_steam_client()->steam_friends;
|
|
|
|
Steam_Matchmaking* steamMatchmaking = get_steam_client()->steam_matchmaking;
|
|
|
|
|
|
|
|
if (save_settings) {
|
|
|
|
save_settings = false;
|
|
|
|
|
|
|
|
const char *language_text = valid_languages[current_language];
|
2024-04-20 06:49:28 +08:00
|
|
|
save_global_settings(username_text, language_text);
|
2024-03-15 01:23:39 +08:00
|
|
|
get_steam_client()->settings_client->set_local_name(username_text);
|
|
|
|
get_steam_client()->settings_server->set_local_name(username_text);
|
|
|
|
get_steam_client()->settings_client->set_language(language_text);
|
|
|
|
get_steam_client()->settings_server->set_language(language_text);
|
|
|
|
steamFriends->resend_friend_data();
|
|
|
|
}
|
|
|
|
|
|
|
|
i_have_lobby = got_lobby();
|
|
|
|
std::for_each(friends.begin(), friends.end(), [this](std::pair<Friend const, friend_window_state> &i)
|
|
|
|
{
|
|
|
|
i.second.joinable = is_friend_joinable(i);
|
|
|
|
});
|
|
|
|
|
|
|
|
while (!has_friend_action.empty()) {
|
|
|
|
auto friend_info = friends.find(has_friend_action.front());
|
|
|
|
if (friend_info != friends.end()) {
|
|
|
|
uint64 friend_id = (uint64)friend_info->first.id();
|
|
|
|
// The user clicked on "Send"
|
|
|
|
if (friend_info->second.window_state & window_state_send_message) {
|
|
|
|
char* input = friend_info->second.chat_input;
|
|
|
|
char* end_input = input + strlen(input);
|
|
|
|
char* printable_char = std::find_if(input, end_input, [](char c) { return std::isgraph(c); });
|
|
|
|
|
|
|
|
// Check if the message contains something else than blanks
|
|
|
|
if (printable_char != end_input) {
|
|
|
|
// Handle chat send
|
|
|
|
Common_Message msg;
|
|
|
|
Steam_Messages* steam_messages = new Steam_Messages;
|
|
|
|
steam_messages->set_type(Steam_Messages::FRIEND_CHAT);
|
|
|
|
steam_messages->set_message(friend_info->second.chat_input);
|
|
|
|
msg.set_allocated_steam_messages(steam_messages);
|
|
|
|
msg.set_source_id(settings->get_local_steam_id().ConvertToUint64());
|
|
|
|
msg.set_dest_id(friend_id);
|
|
|
|
network->sendTo(&msg, true);
|
|
|
|
|
|
|
|
friend_info->second.chat_history.append(get_steam_client()->settings_client->get_local_name()).append(": ").append(input).append("\n", 1);
|
|
|
|
}
|
|
|
|
*input = 0; // Reset the input field
|
|
|
|
|
|
|
|
friend_info->second.window_state &= ~window_state_send_message;
|
|
|
|
}
|
|
|
|
// The user clicked on "Invite" (but invite all wasn't clicked)
|
|
|
|
if (friend_info->second.window_state & window_state_invite) {
|
|
|
|
invite_friend(friend_id, steamFriends, steamMatchmaking);
|
|
|
|
|
|
|
|
friend_info->second.window_state &= ~window_state_invite;
|
|
|
|
}
|
|
|
|
// The user clicked on "Join"
|
|
|
|
if (friend_info->second.window_state & window_state_join) {
|
|
|
|
std::string connect = steamFriends->GetFriendRichPresence(friend_id, "connect");
|
|
|
|
// The user got a lobby invite and accepted it
|
|
|
|
if (friend_info->second.window_state & window_state_lobby_invite) {
|
|
|
|
GameLobbyJoinRequested_t data;
|
|
|
|
data.m_steamIDLobby.SetFromUint64(friend_info->second.lobbyId);
|
|
|
|
data.m_steamIDFriend.SetFromUint64(friend_id);
|
|
|
|
callbacks->addCBResult(data.k_iCallback, &data, sizeof(data));
|
|
|
|
|
|
|
|
friend_info->second.window_state &= ~window_state_lobby_invite;
|
|
|
|
} else {
|
|
|
|
// The user got a rich presence invite and accepted it
|
|
|
|
if (friend_info->second.window_state & window_state_rich_invite) {
|
|
|
|
GameRichPresenceJoinRequested_t data = {};
|
|
|
|
data.m_steamIDFriend.SetFromUint64(friend_id);
|
|
|
|
strncpy(data.m_rgchConnect, friend_info->second.connect, k_cchMaxRichPresenceValueLength - 1);
|
|
|
|
callbacks->addCBResult(data.k_iCallback, &data, sizeof(data));
|
|
|
|
|
|
|
|
friend_info->second.window_state &= ~window_state_rich_invite;
|
|
|
|
} else if (connect.length() > 0) {
|
|
|
|
GameRichPresenceJoinRequested_t data = {};
|
|
|
|
data.m_steamIDFriend.SetFromUint64(friend_id);
|
|
|
|
strncpy(data.m_rgchConnect, connect.c_str(), k_cchMaxRichPresenceValueLength - 1);
|
|
|
|
callbacks->addCBResult(data.k_iCallback, &data, sizeof(data));
|
|
|
|
}
|
|
|
|
|
|
|
|
//Not sure about this but it fixes sonic racing transformed invites
|
|
|
|
FriendGameInfo_t friend_game_info = {};
|
|
|
|
steamFriends->GetFriendGamePlayed(friend_id, &friend_game_info);
|
|
|
|
uint64 lobby_id = friend_game_info.m_steamIDLobby.ConvertToUint64();
|
|
|
|
if (lobby_id) {
|
|
|
|
GameLobbyJoinRequested_t data;
|
|
|
|
data.m_steamIDLobby.SetFromUint64(lobby_id);
|
|
|
|
data.m_steamIDFriend.SetFromUint64(friend_id);
|
|
|
|
callbacks->addCBResult(data.k_iCallback, &data, sizeof(data));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
friend_info->second.window_state &= ~window_state_join;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
has_friend_action.pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
// if variable == true, then set it to false and return true (because state was changed) in that case
|
|
|
|
bool yes_clicked = true;
|
|
|
|
if (invite_all_friends_clicked.compare_exchange_weak(yes_clicked, false)) {
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("Steam_Overlay will send invitations to [%zu] friends if they're using the same app", friends.size());
|
2024-03-15 01:23:39 +08:00
|
|
|
uint32 current_appid = settings->get_local_game_id().AppID();
|
|
|
|
for (auto &fr : friends) {
|
|
|
|
if (fr.first.appid() == current_appid) { // friend is playing the same game
|
|
|
|
uint64 friend_id = (uint64)fr.first.id();
|
|
|
|
invite_friend(friend_id, steamFriends, steamMatchmaking);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-08 05:19:31 +08:00
|
|
|
|
|
|
|
void Steam_Overlay::SetupOverlay()
|
|
|
|
{
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG_ENTRY();
|
2024-03-08 05:19:31 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
2024-03-09 09:45:21 +08:00
|
|
|
if (settings->disable_overlay) return;
|
2024-03-08 05:19:31 +08:00
|
|
|
|
|
|
|
bool not_called_yet = false;
|
|
|
|
if (setup_overlay_called.compare_exchange_weak(not_called_yet, true)) {
|
2024-03-09 03:33:13 +08:00
|
|
|
if (settings->overlay_hook_delay_sec > 0) {
|
|
|
|
std::thread([this]() { renderer_detector_delay_thread(); }).detach();
|
|
|
|
} else {
|
|
|
|
// "HITMAN 3" fails if the detector was started later (after a delay)
|
|
|
|
// so request the renderer detector immediately (the old behavior)
|
|
|
|
request_renderer_detector();
|
|
|
|
std::thread([this]() { renderer_hook_init_thread(); }).detach();
|
|
|
|
}
|
2024-03-08 05:19:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Overlay::UnSetupOverlay()
|
|
|
|
{
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG_ENTRY();
|
2024-03-08 05:19:31 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
|
|
|
|
|
|
|
bool already_called = true;
|
|
|
|
if (setup_overlay_called.compare_exchange_weak(already_called, false)) {
|
|
|
|
is_ready = false;
|
|
|
|
|
2024-03-12 05:55:19 +08:00
|
|
|
// stop internal frame processing & restore cursor
|
|
|
|
if (_renderer) {
|
|
|
|
// for some reason this gets triggered after the overlay instance has been destroyed
|
|
|
|
// I assume because the game de-initializes DX later after closing Steam APIs
|
|
|
|
// this hacky solution just sets it to an empty function
|
2024-04-10 14:10:50 +08:00
|
|
|
_renderer->OverlayHookReady = [](InGameOverlay::OverlayHookState state){};
|
|
|
|
|
|
|
|
allow_renderer_frame_processing(false, true);
|
|
|
|
obscure_game_input(false);
|
2024-03-12 05:55:19 +08:00
|
|
|
}
|
2024-03-09 04:19:12 +08:00
|
|
|
|
2024-03-08 05:19:31 +08:00
|
|
|
// allow the future_renderer thread to exit if needed
|
2024-03-09 03:33:13 +08:00
|
|
|
// std::this_thread::sleep_for(std::chrono::milliseconds((int)(renderer_detector_polling_ms * 1.3f)));
|
|
|
|
common_helpers::thisThreadYieldFor(
|
|
|
|
std::chrono::duration_cast<std::chrono::microseconds>(
|
|
|
|
std::chrono::milliseconds((int)(renderer_detector_polling_ms * 1.3f))
|
|
|
|
)
|
|
|
|
);
|
2024-03-08 05:19:31 +08:00
|
|
|
|
|
|
|
if (_renderer) {
|
2024-04-10 14:10:50 +08:00
|
|
|
PRINT_DEBUG("free-ing any images resources");
|
2024-03-08 05:19:31 +08:00
|
|
|
for (auto &ach : achievements) {
|
2024-03-13 03:21:09 +08:00
|
|
|
if (!ach.icon.expired()) {
|
|
|
|
_renderer->ReleaseImageResource(ach.icon);
|
|
|
|
ach.icon.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ach.icon_gray.expired()) {
|
|
|
|
_renderer->ReleaseImageResource(ach.icon_gray);
|
|
|
|
ach.icon_gray.reset();
|
|
|
|
}
|
2024-03-08 05:19:31 +08:00
|
|
|
}
|
2024-03-12 05:55:19 +08:00
|
|
|
|
2024-03-08 05:19:31 +08:00
|
|
|
_renderer = nullptr;
|
|
|
|
}
|
2024-04-10 03:03:07 +08:00
|
|
|
|
2024-04-10 14:10:50 +08:00
|
|
|
// cleanup everything
|
|
|
|
fonts_atlas.Clear();
|
|
|
|
memset(&fonts_atlas, 0, sizeof(fonts_atlas));
|
|
|
|
font_default = nullptr;
|
|
|
|
font_notif = nullptr;
|
|
|
|
for (auto &kv : wav_files) {
|
|
|
|
kv.second.clear();
|
2024-04-10 03:03:07 +08:00
|
|
|
}
|
2024-03-08 05:19:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Steam_Overlay::Ready() const
|
|
|
|
{
|
2024-04-01 08:37:46 +08:00
|
|
|
return !settings->disable_overlay && is_ready && late_init_imgui && late_init_ach_icons;
|
2024-03-08 05:19:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Steam_Overlay::NeedPresent() const
|
|
|
|
{
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG_ENTRY();
|
2024-03-08 05:19:31 +08:00
|
|
|
return !settings->disable_overlay;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Overlay::SetNotificationPosition(ENotificationPosition eNotificationPosition)
|
|
|
|
{
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("TODO %i", (int)eNotificationPosition);
|
2024-03-08 05:19:31 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
2024-04-01 03:16:17 +08:00
|
|
|
if (settings->disable_overlay) return;
|
2024-03-08 05:19:31 +08:00
|
|
|
|
|
|
|
notif_position = eNotificationPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Overlay::SetNotificationInset(int nHorizontalInset, int nVerticalInset)
|
|
|
|
{
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("TODO x=%i y=%i", nHorizontalInset, nVerticalInset);
|
2024-03-08 05:19:31 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
2024-04-01 03:16:17 +08:00
|
|
|
if (settings->disable_overlay) return;
|
2024-03-08 05:19:31 +08:00
|
|
|
|
|
|
|
h_inset = nHorizontalInset;
|
|
|
|
v_inset = nVerticalInset;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Overlay::OpenOverlayInvite(CSteamID lobbyId)
|
|
|
|
{
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("TODO %llu", lobbyId.ConvertToUint64());
|
2024-03-08 05:19:31 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
|
|
|
if (!Ready()) return;
|
|
|
|
|
|
|
|
ShowOverlay(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Overlay::OpenOverlay(const char* pchDialog)
|
|
|
|
{
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("TODO '%s'", pchDialog);
|
2024-03-08 05:19:31 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
|
|
|
if (!Ready()) return;
|
|
|
|
|
|
|
|
// TODO: Show pages depending on pchDialog
|
|
|
|
if ((strncmp(pchDialog, "Friends", sizeof("Friends") - 1) == 0) && (settings->overlayAutoAcceptInvitesCount() > 0)) {
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("won't open overlay's friends list because some friends are defined in the auto accept list");
|
2024-03-08 05:19:31 +08:00
|
|
|
add_auto_accept_invite_notification();
|
|
|
|
} else {
|
|
|
|
ShowOverlay(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Overlay::OpenOverlayWebpage(const char* pchURL)
|
|
|
|
{
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("TODO '%s'", pchURL);
|
2024-03-08 05:19:31 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
|
|
|
if (!Ready()) return;
|
|
|
|
|
|
|
|
show_url = pchURL;
|
|
|
|
ShowOverlay(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Steam_Overlay::ShowOverlay() const
|
|
|
|
{
|
|
|
|
return show_overlay;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Overlay::ShowOverlay(bool state)
|
|
|
|
{
|
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
|
|
|
if (!Ready() || show_overlay == state) return;
|
|
|
|
|
|
|
|
show_overlay = state;
|
|
|
|
overlay_state_changed = true;
|
2024-03-15 01:23:39 +08:00
|
|
|
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("%i", (int)state);
|
2024-03-08 05:19:31 +08:00
|
|
|
|
|
|
|
Steam_Overlay::allow_renderer_frame_processing(state);
|
2024-03-15 01:23:39 +08:00
|
|
|
Steam_Overlay::obscure_game_input(state);
|
2024-03-08 05:19:31 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Overlay::SetLobbyInvite(Friend friendId, uint64 lobbyId)
|
|
|
|
{
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("%" PRIu64 " %llu", friendId.id(), lobbyId);
|
2024-03-08 05:19:31 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
|
|
|
if (!Ready()) return;
|
|
|
|
|
|
|
|
auto i = friends.find(friendId);
|
|
|
|
if (i != friends.end())
|
|
|
|
{
|
|
|
|
auto& frd = i->second;
|
|
|
|
frd.lobbyId = lobbyId;
|
|
|
|
frd.window_state |= window_state_lobby_invite;
|
|
|
|
// Make sure don't have rich presence invite and a lobby invite (it should not happen but who knows)
|
|
|
|
frd.window_state &= ~window_state_rich_invite;
|
2024-03-09 09:45:21 +08:00
|
|
|
add_invite_notification(*i);
|
2024-03-08 05:19:31 +08:00
|
|
|
notify_sound_user_invite(i->second);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Overlay::SetRichInvite(Friend friendId, const char* connect_str)
|
|
|
|
{
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("%" PRIu64 " '%s'", friendId.id(), connect_str);
|
2024-03-08 05:19:31 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
|
|
|
if (!Ready()) return;
|
|
|
|
|
|
|
|
auto i = friends.find(friendId);
|
|
|
|
if (i != friends.end())
|
|
|
|
{
|
|
|
|
auto& frd = i->second;
|
|
|
|
strncpy(frd.connect, connect_str, k_cchMaxRichPresenceValueLength - 1);
|
|
|
|
frd.window_state |= window_state_rich_invite;
|
|
|
|
// Make sure don't have rich presence invite and a lobby invite (it should not happen but who knows)
|
|
|
|
frd.window_state &= ~window_state_lobby_invite;
|
2024-03-09 09:45:21 +08:00
|
|
|
add_invite_notification(*i);
|
2024-03-08 05:19:31 +08:00
|
|
|
notify_sound_user_invite(i->second);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Overlay::FriendConnect(Friend _friend)
|
|
|
|
{
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("%" PRIu64 "", _friend.id());
|
2024-03-08 05:19:31 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
2024-04-01 03:16:17 +08:00
|
|
|
if (settings->disable_overlay) return;
|
|
|
|
|
2024-03-25 15:21:11 +08:00
|
|
|
// players connections might happen earlier before the overlay is ready
|
|
|
|
// we don't want to miss them
|
|
|
|
//if (!Ready()) return;
|
2024-03-08 05:19:31 +08:00
|
|
|
|
|
|
|
int id = find_free_friend_id(friends);
|
|
|
|
if (id != 0) {
|
|
|
|
auto& item = friends[_friend];
|
|
|
|
item.window_title = std::move(_friend.name() + translationPlaying[current_language] + std::to_string(_friend.appid()));
|
|
|
|
item.window_state = window_state_none;
|
|
|
|
item.id = id;
|
|
|
|
memset(item.chat_input, 0, max_chat_len);
|
|
|
|
item.joinable = false;
|
|
|
|
} else {
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("error no free id to create a friend window");
|
2024-03-08 05:19:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Overlay::FriendDisconnect(Friend _friend)
|
|
|
|
{
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG("%" PRIu64 "", _friend.id());
|
2024-03-08 05:19:31 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
2024-04-01 03:16:17 +08:00
|
|
|
if (settings->disable_overlay) return;
|
|
|
|
|
2024-03-25 15:21:11 +08:00
|
|
|
// players connections might happen earlier before the overlay is ready
|
|
|
|
// we don't want to miss them
|
|
|
|
//if (!Ready()) return;
|
2024-03-08 05:19:31 +08:00
|
|
|
|
|
|
|
auto it = friends.find(_friend);
|
|
|
|
if (it != friends.end())
|
|
|
|
friends.erase(it);
|
|
|
|
}
|
|
|
|
|
|
|
|
// show a notification when the user unlocks an achievement
|
|
|
|
void Steam_Overlay::AddAchievementNotification(nlohmann::json const& ach)
|
|
|
|
{
|
2024-04-06 13:49:07 +08:00
|
|
|
PRINT_DEBUG_ENTRY();
|
2024-03-08 05:19:31 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
2024-03-09 09:45:21 +08:00
|
|
|
if (!Ready()) return;
|
2024-03-08 05:19:31 +08:00
|
|
|
|
2024-03-15 01:38:56 +08:00
|
|
|
// don't return early when disable_overlay_achievement_notification is true
|
|
|
|
// otherwise when you open the achievements list/menu you won't see the new unlock status
|
|
|
|
|
2024-03-13 03:21:09 +08:00
|
|
|
std::vector<Overlay_Achievement*> found_achs{};
|
2024-03-08 05:19:31 +08:00
|
|
|
{
|
|
|
|
std::lock_guard<std::recursive_mutex> lock2(global_mutex);
|
|
|
|
|
|
|
|
std::string ach_name = ach.value("name", std::string());
|
|
|
|
for (auto &a : achievements) {
|
|
|
|
if (a.name == ach_name) {
|
2024-03-13 03:21:09 +08:00
|
|
|
found_achs.push_back(&a);
|
|
|
|
|
2024-03-08 05:19:31 +08:00
|
|
|
bool achieved = false;
|
|
|
|
uint32 unlock_time = 0;
|
|
|
|
get_steam_client()->steam_user_stats->GetAchievementAndUnlockTime(a.name.c_str(), &achieved, &unlock_time);
|
|
|
|
a.achieved = achieved;
|
|
|
|
a.unlock_time = unlock_time;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!settings->disable_overlay_achievement_notification) {
|
2024-03-13 03:21:09 +08:00
|
|
|
for (auto found_ach : found_achs) {
|
2024-04-10 14:10:50 +08:00
|
|
|
try_load_ach_icon(*found_ach, true);
|
2024-03-13 03:21:09 +08:00
|
|
|
submit_notification(
|
|
|
|
notification_type_achievement,
|
|
|
|
ach.value("displayName", std::string()) + "\n" + ach.value("description", std::string()),
|
|
|
|
{},
|
|
|
|
found_ach->icon
|
|
|
|
);
|
2024-03-08 05:19:31 +08:00
|
|
|
}
|
2024-03-13 03:21:09 +08:00
|
|
|
|
2024-03-08 05:19:31 +08:00
|
|
|
notify_sound_user_achievement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-01 02:49:07 +08:00
|
|
|
#endif
|