From 5e880cd9748bd65447853f643fdb5638e9d30e7b Mon Sep 17 00:00:00 2001 From: Mr_Goldberg Date: Fri, 5 Aug 2022 02:09:43 -0400 Subject: [PATCH] Add achievements display to overlay and ability to change some settings. --- build_win_debug_experimental.bat | 4 +- build_win_debug_experimental_steamclient.bat | 4 +- build_win_release_experimental.bat | 9 +- ...d_win_release_experimental_steamclient.bat | 4 +- dll/settings.cpp | 10 + dll/settings.h | 9 + dll/settings_parser.cpp | 31 +- dll/settings_parser.h | 2 +- dll/steam_friends.h | 16 +- overlay_experimental/steam_overlay.cpp | 321 +++++++++++++++++- overlay_experimental/steam_overlay.h | 37 +- 11 files changed, 411 insertions(+), 36 deletions(-) diff --git a/build_win_debug_experimental.bat b/build_win_debug_experimental.bat index 806a815..7f3a080 100755 --- a/build_win_debug_experimental.bat +++ b/build_win_debug_experimental.bat @@ -4,11 +4,11 @@ call build_set_protobuf_directories.bat "%PROTOC_X86_EXE%" -I.\dll\ --cpp_out=.\dll\ .\dll\net.proto call build_env_x86.bat cl dll/rtlgenrandom.c dll/rtlgenrandom.def -cl /LD /IImGui /Iglew\include /I%PROTOBUF_X86_DIRECTORY%\include\ /DGLEW_STATIC /DEMU_EXPERIMENTAL_BUILD /DCONTROLLER_SUPPORT /DEMU_OVERLAY dll/*.cpp dll/*.cc detours/*.cpp controller/gamepad.c ImGui/*.cpp ImGui/impls/*.cpp ImGui/impls/windows/*.cpp overlay_experimental/*.cpp overlay_experimental/windows/*.cpp "%PROTOBUF_X86_LIBRARY%" glew\glew.c opengl32.lib Iphlpapi.lib Ws2_32.lib rtlgenrandom.lib Shell32.lib Winmm.lib /EHsc /MP12 /link /OUT:steam_api.dll +cl /Z7 /LD /IImGui /I%PROTOBUF_X86_DIRECTORY%\include\ /DEMU_EXPERIMENTAL_BUILD /DCONTROLLER_SUPPORT /DEMU_OVERLAY /Ioverlay_experimental dll/*.cpp dll/*.cc detours/*.cpp controller/gamepad.c ImGui/*.cpp ImGui/backends/imgui_impl_dx*.cpp ImGui/backends/imgui_impl_win32.cpp ImGui/backends/imgui_impl_vulkan.cpp ImGui/backends/imgui_impl_opengl3.cpp ImGui/backends/imgui_win_shader_blobs.cpp overlay_experimental/*.cpp overlay_experimental/windows/*.cpp overlay_experimental/System/*.cpp "%PROTOBUF_X86_LIBRARY%" opengl32.lib Iphlpapi.lib Ws2_32.lib rtlgenrandom.lib Shell32.lib Winmm.lib /EHsc /MP12 /link /OUT:steam_api.dll cl /LD steamclient.cpp /EHsc /MP12 /link /OUT:steamclient.dll "%PROTOC_X64_EXE%" -I.\dll\ --cpp_out=.\dll\ .\dll\net.proto call build_env_x64.bat cl dll/rtlgenrandom.c dll/rtlgenrandom.def -cl /LD /IImGui /Iglew\include /I%PROTOBUF_X64_DIRECTORY%\include\ /DGLEW_STATIC /DEMU_EXPERIMENTAL_BUILD /DCONTROLLER_SUPPORT /DEMU_OVERLAY dll/*.cpp dll/*.cc detours/*.cpp controller/gamepad.c ImGui/*.cpp ImGui/impls/*.cpp ImGui/impls/windows/*.cpp overlay_experimental/*.cpp overlay_experimental/windows/*.cpp "%PROTOBUF_X64_LIBRARY%" glew\glew.c opengl32.lib Iphlpapi.lib Ws2_32.lib rtlgenrandom.lib Shell32.lib Winmm.lib /EHsc /MP12 /link /OUT:steam_api64.dll +cl /Z7 /LD /IImGui /I%PROTOBUF_X64_DIRECTORY%\include\ /DEMU_EXPERIMENTAL_BUILD /DCONTROLLER_SUPPORT /DEMU_OVERLAY /Ioverlay_experimental dll/*.cpp dll/*.cc detours/*.cpp controller/gamepad.c ImGui/*.cpp ImGui/backends/imgui_impl_dx*.cpp ImGui/backends/imgui_impl_win32.cpp ImGui/backends/imgui_impl_vulkan.cpp ImGui/backends/imgui_impl_opengl3.cpp ImGui/backends/imgui_win_shader_blobs.cpp overlay_experimental/*.cpp overlay_experimental/windows/*.cpp overlay_experimental/System/*.cpp "%PROTOBUF_X64_LIBRARY%" opengl32.lib Iphlpapi.lib Ws2_32.lib rtlgenrandom.lib Shell32.lib Winmm.lib /EHsc /MP12 /link /OUT:steam_api64.dll cl /LD steamclient.cpp /EHsc /MP12 /link /OUT:steamclient64.dll diff --git a/build_win_debug_experimental_steamclient.bat b/build_win_debug_experimental_steamclient.bat index f247afa..1eec4aa 100644 --- a/build_win_debug_experimental_steamclient.bat +++ b/build_win_debug_experimental_steamclient.bat @@ -3,7 +3,7 @@ call build_set_protobuf_directories.bat "%PROTOC_X86_EXE%" -I.\dll\ --cpp_out=.\dll\ .\dll\net.proto call build_env_x86.bat cl dll/rtlgenrandom.c dll/rtlgenrandom.def -cl /LD /IImGui /Iglew\include /I%PROTOBUF_X86_DIRECTORY%\include\ /DSTEAMCLIENT_DLL /DCONTROLLER_SUPPORT /DEMU_EXPERIMENTAL_BUILD /DGLEW_STATIC /DEMU_OVERLAY dll/*.cpp dll/*.cc detours/*.cpp controller/gamepad.c ImGui/*.cpp ImGui/impls/*.cpp ImGui/impls/windows/*.cpp overlay_experimental/*.cpp overlay_experimental/windows/*.cpp "%PROTOBUF_X86_LIBRARY%" glew\glew.c opengl32.lib Iphlpapi.lib Ws2_32.lib rtlgenrandom.lib Shell32.lib Winmm.lib /EHsc /MP12 /link /OUT:steamclient.dll +cl /LD /IImGui /I%PROTOBUF_X86_DIRECTORY%\include\ /DSTEAMCLIENT_DLL /DCONTROLLER_SUPPORT /DEMU_EXPERIMENTAL_BUILD /DEMU_OVERLAY /Ioverlay_experimental dll/*.cpp dll/*.cc detours/*.cpp controller/gamepad.c ImGui/*.cpp ImGui/backends/imgui_impl_dx*.cpp ImGui/backends/imgui_impl_win32.cpp ImGui/backends/imgui_impl_vulkan.cpp ImGui/backends/imgui_impl_opengl3.cpp ImGui/backends/imgui_win_shader_blobs.cpp overlay_experimental/*.cpp overlay_experimental/windows/*.cpp overlay_experimental/System/*.cpp "%PROTOBUF_X86_LIBRARY%" opengl32.lib Iphlpapi.lib Ws2_32.lib rtlgenrandom.lib Shell32.lib Winmm.lib /EHsc /MP12 /link /OUT:steamclient.dll call build_env_x64.bat cl dll/rtlgenrandom.c dll/rtlgenrandom.def -cl /LD /IImGui /Iglew\include /I%PROTOBUF_X64_DIRECTORY%\include\ /DSTEAMCLIENT_DLL /DCONTROLLER_SUPPORT /DEMU_EXPERIMENTAL_BUILD /DGLEW_STATIC /DEMU_OVERLAY dll/*.cpp dll/*.cc detours/*.cpp controller/gamepad.c ImGui/*.cpp ImGui/impls/*.cpp ImGui/impls/windows/*.cpp overlay_experimental/*.cpp overlay_experimental/windows/*.cpp "%PROTOBUF_X64_LIBRARY%" glew\glew.c opengl32.lib Iphlpapi.lib Ws2_32.lib rtlgenrandom.lib Shell32.lib Winmm.lib /EHsc /MP12 /link /OUT:steamclient64.dll +cl /LD /IImGui /I%PROTOBUF_X64_DIRECTORY%\include\ /DSTEAMCLIENT_DLL /DCONTROLLER_SUPPORT /DEMU_EXPERIMENTAL_BUILD /DEMU_OVERLAY /Ioverlay_experimental dll/*.cpp dll/*.cc detours/*.cpp controller/gamepad.c ImGui/*.cpp ImGui/backends/imgui_impl_dx*.cpp ImGui/backends/imgui_impl_win32.cpp ImGui/backends/imgui_impl_vulkan.cpp ImGui/backends/imgui_impl_opengl3.cpp ImGui/backends/imgui_win_shader_blobs.cpp overlay_experimental/*.cpp overlay_experimental/windows/*.cpp overlay_experimental/System/*.cpp "%PROTOBUF_X64_LIBRARY%" opengl32.lib Iphlpapi.lib Ws2_32.lib rtlgenrandom.lib Shell32.lib Winmm.lib /EHsc /MP12 /link /OUT:steamclient64.dll diff --git a/build_win_release_experimental.bat b/build_win_release_experimental.bat index d3ab784..5c3ff84 100755 --- a/build_win_release_experimental.bat +++ b/build_win_release_experimental.bat @@ -6,11 +6,12 @@ call build_set_protobuf_directories.bat "%PROTOC_X86_EXE%" -I.\dll\ --cpp_out=.\dll\ .\dll\net.proto call build_env_x86.bat cl dll/rtlgenrandom.c dll/rtlgenrandom.def -cl /LD /DEMU_RELEASE_BUILD /DEMU_EXPERIMENTAL_BUILD /DGLEW_STATIC /DCONTROLLER_SUPPORT /DEMU_OVERLAY /DNDEBUG /IImGui /Iglew\include /I%PROTOBUF_X86_DIRECTORY%\include\ dll/*.cpp dll/*.cc detours/*.cpp controller/gamepad.c ImGui/*.cpp ImGui/impls/*.cpp ImGui/impls/windows/*.cpp overlay_experimental/*.cpp overlay_experimental/windows/*.cpp "%PROTOBUF_X86_LIBRARY%" glew\glew.c opengl32.lib Iphlpapi.lib Ws2_32.lib rtlgenrandom.lib Shell32.lib Winmm.lib /EHsc /MP12 /Ox /link /debug:none /OUT:release\experimental\steam_api.dll -cl /LD /DEMU_RELEASE_BUILD /DEMU_EXPERIMENTAL_BUILD /DNDEBUG steamclient.cpp /EHsc /MP12 /Ox /link /OUT:release\experimental\steamclient.dll +cl /LD /DEMU_RELEASE_BUILD /DEMU_EXPERIMENTAL_BUILD /DCONTROLLER_SUPPORT /DEMU_OVERLAY /DNDEBUG /IImGui /I%PROTOBUF_X86_DIRECTORY%\include\ /Ioverlay_experimental dll/*.cpp dll/*.cc detours/*.cpp controller/gamepad.c ImGui/*.cpp ImGui/backends/imgui_impl_dx*.cpp ImGui/backends/imgui_impl_win32.cpp ImGui/backends/imgui_impl_vulkan.cpp ImGui/backends/imgui_impl_opengl3.cpp ImGui/backends/imgui_win_shader_blobs.cpp overlay_experimental/*.cpp overlay_experimental/windows/*.cpp overlay_experimental/System/*.cpp "%PROTOBUF_X86_LIBRARY%" opengl32.lib Iphlpapi.lib Ws2_32.lib rtlgenrandom.lib Shell32.lib Winmm.lib /EHsc /MP12 /Ox /link /debug:none /OUT:release\experimental\steam_api.dll +cl /LD /DEMU_RELEASE_BUILD /DEMU_EXPERIMENTAL_BUILD /DNDEBUG steamclient.cpp /EHsc /MP4 /Ox /link /OUT:release\experimental\steamclient.dll + "%PROTOC_X64_EXE%" -I.\dll\ --cpp_out=.\dll\ .\dll\net.proto call build_env_x64.bat cl dll/rtlgenrandom.c dll/rtlgenrandom.def -cl /LD /DEMU_RELEASE_BUILD /DEMU_EXPERIMENTAL_BUILD /DGLEW_STATIC /DCONTROLLER_SUPPORT /DEMU_OVERLAY /DNDEBUG /IImGui /Iglew\include /I%PROTOBUF_X64_DIRECTORY%\include\ dll/*.cpp dll/*.cc detours/*.cpp controller/gamepad.c ImGui/*.cpp ImGui/impls/*.cpp ImGui/impls/windows/*.cpp overlay_experimental/*.cpp overlay_experimental/windows/*.cpp "%PROTOBUF_X64_LIBRARY%" glew\glew.c opengl32.lib Iphlpapi.lib Ws2_32.lib rtlgenrandom.lib Shell32.lib Winmm.lib /EHsc /MP12 /Ox /link /debug:none /OUT:release\experimental\steam_api64.dll -cl /LD /DEMU_RELEASE_BUILD /DEMU_EXPERIMENTAL_BUILD /DNDEBUG steamclient.cpp /EHsc /MP12 /Ox /link /OUT:release\experimental\steamclient64.dll +cl /LD /DEMU_RELEASE_BUILD /DEMU_EXPERIMENTAL_BUILD /DCONTROLLER_SUPPORT /DEMU_OVERLAY /DNDEBUG /IImGui /I%PROTOBUF_X64_DIRECTORY%\include\ /Ioverlay_experimental dll/*.cpp dll/*.cc detours/*.cpp controller/gamepad.c ImGui/*.cpp ImGui/backends/imgui_impl_dx*.cpp ImGui/backends/imgui_impl_win32.cpp ImGui/backends/imgui_impl_vulkan.cpp ImGui/backends/imgui_impl_opengl3.cpp ImGui/backends/imgui_win_shader_blobs.cpp overlay_experimental/*.cpp overlay_experimental/windows/*.cpp overlay_experimental/System/*.cpp "%PROTOBUF_X64_LIBRARY%" opengl32.lib Iphlpapi.lib Ws2_32.lib rtlgenrandom.lib Shell32.lib Winmm.lib /EHsc /MP12 /Ox /link /debug:none /OUT:release\experimental\steam_api64.dll +cl /LD /DEMU_RELEASE_BUILD /DEMU_EXPERIMENTAL_BUILD /DNDEBUG steamclient.cpp /EHsc /MP4 /Ox /link /OUT:release\experimental\steamclient64.dll copy Readme_experimental.txt release\experimental\Readme.txt diff --git a/build_win_release_experimental_steamclient.bat b/build_win_release_experimental_steamclient.bat index 22566d4..cd55557 100644 --- a/build_win_release_experimental_steamclient.bat +++ b/build_win_release_experimental_steamclient.bat @@ -6,11 +6,11 @@ call build_set_protobuf_directories.bat "%PROTOC_X86_EXE%" -I.\dll\ --cpp_out=.\dll\ .\dll\net.proto call build_env_x86.bat cl dll/rtlgenrandom.c dll/rtlgenrandom.def -cl /LD /DEMU_RELEASE_BUILD /DEMU_EXPERIMENTAL_BUILD /DSTEAMCLIENT_DLL /DCONTROLLER_SUPPORT /DEMU_OVERLAY /DGLEW_STATIC /IImGui /Iglew\include /DNDEBUG /I%PROTOBUF_X86_DIRECTORY%\include\ dll/*.cpp dll/*.cc detours/*.cpp controller/gamepad.c ImGui/*.cpp ImGui/impls/*.cpp ImGui/impls/windows/*.cpp overlay_experimental/*.cpp overlay_experimental/windows/*.cpp "%PROTOBUF_X86_LIBRARY%" glew\glew.c opengl32.lib Iphlpapi.lib Ws2_32.lib rtlgenrandom.lib Shell32.lib Winmm.lib /EHsc /MP12 /Ox /link /debug:none /OUT:release\experimental_steamclient\steamclient.dll +cl /LD /DEMU_RELEASE_BUILD /DEMU_EXPERIMENTAL_BUILD /DSTEAMCLIENT_DLL /DCONTROLLER_SUPPORT /DEMU_OVERLAY /IImGui /DNDEBUG /I%PROTOBUF_X86_DIRECTORY%\include\ /Ioverlay_experimental dll/*.cpp dll/*.cc detours/*.cpp controller/gamepad.c ImGui/*.cpp ImGui/backends/imgui_impl_dx*.cpp ImGui/backends/imgui_impl_win32.cpp ImGui/backends/imgui_impl_vulkan.cpp ImGui/backends/imgui_impl_opengl3.cpp ImGui/backends/imgui_win_shader_blobs.cpp overlay_experimental/*.cpp overlay_experimental/windows/*.cpp overlay_experimental/System/*.cpp "%PROTOBUF_X86_LIBRARY%" opengl32.lib Iphlpapi.lib Ws2_32.lib rtlgenrandom.lib Shell32.lib Winmm.lib /EHsc /MP12 /Ox /link /debug:none /OUT:release\experimental_steamclient\steamclient.dll "%PROTOC_X64_EXE%" -I.\dll\ --cpp_out=.\dll\ .\dll\net.proto cl steamclient_loader/*.cpp advapi32.lib user32.lib /EHsc /MP12 /Ox /link /debug:none /OUT:release\experimental_steamclient\steamclient_loader.exe copy steamclient_loader\ColdClientLoader.ini release\experimental_steamclient\ call build_env_x64.bat cl dll/rtlgenrandom.c dll/rtlgenrandom.def -cl /LD /DEMU_RELEASE_BUILD /DEMU_EXPERIMENTAL_BUILD /DSTEAMCLIENT_DLL /DCONTROLLER_SUPPORT /DEMU_OVERLAY /DGLEW_STATIC /IImGui /Iglew\include /DNDEBUG /I%PROTOBUF_X64_DIRECTORY%\include\ dll/*.cpp dll/*.cc detours/*.cpp controller/gamepad.c ImGui/*.cpp ImGui/impls/*.cpp ImGui/impls/windows/*.cpp overlay_experimental/*.cpp overlay_experimental/windows/*.cpp "%PROTOBUF_X64_LIBRARY%" glew\glew.c opengl32.lib Iphlpapi.lib Ws2_32.lib rtlgenrandom.lib Shell32.lib Winmm.lib /EHsc /MP12 /Ox /link /debug:none /OUT:release\experimental_steamclient\steamclient64.dll +cl /LD /DEMU_RELEASE_BUILD /DEMU_EXPERIMENTAL_BUILD /DSTEAMCLIENT_DLL /DCONTROLLER_SUPPORT /DEMU_OVERLAY /IImGui /DNDEBUG /I%PROTOBUF_X64_DIRECTORY%\include\ /Ioverlay_experimental dll/*.cpp dll/*.cc detours/*.cpp controller/gamepad.c ImGui/*.cpp ImGui/backends/imgui_impl_dx*.cpp ImGui/backends/imgui_impl_win32.cpp ImGui/backends/imgui_impl_vulkan.cpp ImGui/backends/imgui_impl_opengl3.cpp ImGui/backends/imgui_win_shader_blobs.cpp overlay_experimental/*.cpp overlay_experimental/windows/*.cpp overlay_experimental/System/*.cpp "%PROTOBUF_X64_LIBRARY%" opengl32.lib Iphlpapi.lib Ws2_32.lib rtlgenrandom.lib Shell32.lib Winmm.lib /EHsc /MP12 /Ox /link /debug:none /OUT:release\experimental_steamclient\steamclient64.dll copy Readme_experimental_steamclient.txt release\experimental_steamclient\Readme.txt diff --git a/dll/settings.cpp b/dll/settings.cpp index 95ab05a..f347c0a 100644 --- a/dll/settings.cpp +++ b/dll/settings.cpp @@ -76,6 +76,16 @@ const char *Settings::get_language() return language.c_str(); } +void Settings::set_local_name(char *name) +{ + this->name = name; +} + +void Settings::set_language(char *language) +{ + this->language = language; +} + void Settings::set_game_id(CGameID game_id) { this->game_id = game_id; diff --git a/dll/settings.h b/dll/settings.h index 03c956d..28fc3f0 100644 --- a/dll/settings.h +++ b/dll/settings.h @@ -92,7 +92,10 @@ public: CSteamID get_local_steam_id(); CGameID get_local_game_id(); const char *get_local_name(); + void set_local_name(char *name); const char *get_language(); + void set_language(char *language); + void set_game_id(CGameID game_id); void set_lobby(CSteamID lobby_id); CSteamID get_lobby(); @@ -155,6 +158,12 @@ public: //make lobby creation fail in the matchmaking interface bool disable_lobby_creation = false; + + //warn people who use force_ settings + bool warn_forced = false; + + //warn people who use local save + bool warn_local_save = false; }; #endif diff --git a/dll/settings_parser.cpp b/dll/settings_parser.cpp index fb4a6a8..4d5fcf3 100644 --- a/dll/settings_parser.cpp +++ b/dll/settings_parser.cpp @@ -180,10 +180,13 @@ uint32 create_localstorage_settings(Settings **settings_client_out, Settings **s } } + bool local_save = false; + { char array[33] = {}; if (Local_Storage::get_file_data(program_path + "local_save.txt", array, sizeof(array) - 1) != -1) { save_path = program_path + Settings::sanitize(array); + local_save = true; } } @@ -263,6 +266,8 @@ uint32 create_localstorage_settings(Settings **settings_client_out, Settings **s bool disable_lobby_creation = false; int build_id = 10; + bool warn_forced = false; + { std::string steam_settings_path = Local_Storage::get_game_settings_path(); @@ -279,22 +284,32 @@ uint32 create_localstorage_settings(Settings **settings_client_out, Settings **s disable_lobby_creation = true; } else if (p == "force_language.txt") { int len = Local_Storage::get_file_data(steam_settings_path + "force_language.txt", language, sizeof(language) - 1); - if (len > 0) language[len] = 0; + if (len > 0) { + language[len] = 0; + warn_forced = true; + } } else if (p == "force_steamid.txt") { char steam_id_text[32] = {}; if (Local_Storage::get_file_data(steam_settings_path + "force_steamid.txt", steam_id_text, sizeof(steam_id_text) - 1) > 0) { CSteamID temp_id = CSteamID((uint64)std::atoll(steam_id_text)); if (temp_id.IsValid()) { user_id = temp_id; + warn_forced = true; } } } else if (p == "force_account_name.txt") { int len = Local_Storage::get_file_data(steam_settings_path + "force_account_name.txt", name, sizeof(name) - 1); - if (len > 0) name[len] = 0; + if (len > 0) { + name[len] = 0; + warn_forced = true; + } } else if (p == "force_listen_port.txt") { char array_port[10] = {}; int len = Local_Storage::get_file_data(steam_settings_path + "force_listen_port.txt", array_port, sizeof(array_port) - 1); - if (len > 0) port = std::stoi(array_port); + if (len > 0) { + port = std::stoi(array_port); + warn_forced = true; + } } else if (p == "build_id.txt") { char array_id[10] = {}; int len = Local_Storage::get_file_data(steam_settings_path + "build_id.txt", array_id, sizeof(array_id) - 1); @@ -317,6 +332,10 @@ uint32 create_localstorage_settings(Settings **settings_client_out, Settings **s settings_server->disable_lobby_creation = disable_lobby_creation; settings_client->build_id = build_id; settings_server->build_id = build_id; + settings_client->warn_forced = warn_forced; + settings_server->warn_forced = warn_forced; + settings_client->warn_local_save = local_save; + settings_server->warn_local_save = local_save; { std::string dlc_config_path = Local_Storage::get_game_settings_path() + "DLC.txt"; @@ -571,3 +590,9 @@ uint32 create_localstorage_settings(Settings **settings_client_out, Settings **s return appid; } + +void save_global_settings(Local_Storage *local_storage, char *name, char *language) +{ + local_storage->store_data_settings("account_name.txt", name, strlen(name)); + local_storage->store_data_settings("language.txt", language, strlen(language)); +} diff --git a/dll/settings_parser.h b/dll/settings_parser.h index 5c20ea4..38b926c 100644 --- a/dll/settings_parser.h +++ b/dll/settings_parser.h @@ -22,6 +22,6 @@ //returns appid uint32 create_localstorage_settings(Settings **settings_client_out, Settings **settings_server_out, Local_Storage **local_storage_out); - +void save_global_settings(Local_Storage *local_storage, char *name, char *language); #endif diff --git a/dll/steam_friends.h b/dll/steam_friends.h index 576ebca..5f28c95 100644 --- a/dll/steam_friends.h +++ b/dll/steam_friends.h @@ -133,6 +133,11 @@ static void steam_friends_run_every_runcb(void *object) steam_friends->RunCallbacks(); } +void resend_friend_data() +{ + modified = true; +} + Steam_Friends(Settings* settings, Networking* network, SteamCallResults* callback_results, SteamCallBacks* callbacks, RunEveryRunCB* run_every_runcb, Steam_Overlay* overlay): settings(settings), network(network), @@ -550,7 +555,8 @@ void ActivateGameOverlayToUser( const char *pchDialog, CSteamID steamID ) // full address with protocol type is required, e.g. http://www.steamgames.com/ void ActivateGameOverlayToWebPage( const char *pchURL, EActivateGameOverlayToWebPageMode eMode = k_EActivateGameOverlayToWebPageMode_Default ) { - PRINT_DEBUG("Steam_Friends::ActivateGameOverlayToWebPage\n"); + PRINT_DEBUG("Steam_Friends::ActivateGameOverlayToWebPage %s %u\n", pchURL, eMode); + overlay->OpenOverlayWebpage(pchURL); } void ActivateGameOverlayToWebPage( const char *pchURL ) @@ -721,13 +727,13 @@ bool SetRichPresence( const char *pchKey, const char *pchValue ) auto prev_value = (*us.mutable_rich_presence()).find(pchKey); if (prev_value == (*us.mutable_rich_presence()).end() || prev_value->second != pchValue) { (*us.mutable_rich_presence())[pchKey] = pchValue; - modified = true; + resend_friend_data(); } } else { auto to_remove = us.mutable_rich_presence()->find(pchKey); if (to_remove != us.mutable_rich_presence()->end()) { us.mutable_rich_presence()->erase(to_remove); - modified = true; + resend_friend_data(); } } @@ -739,7 +745,7 @@ void ClearRichPresence() PRINT_DEBUG("Steam_Friends::ClearRichPresence\n"); std::lock_guard lock(global_mutex); us.mutable_rich_presence()->clear(); - modified = true; + resend_friend_data(); } @@ -1053,7 +1059,7 @@ void RunCallbacks() PRINT_DEBUG("Steam_Friends::RunCallbacks\n"); if (settings->get_lobby() != lobby_id) { lobby_id = settings->get_lobby(); - modified = true; + resend_friend_data(); } if (modified) { diff --git a/overlay_experimental/steam_overlay.cpp b/overlay_experimental/steam_overlay.cpp index 4002278..26fe2bd 100644 --- a/overlay_experimental/steam_overlay.cpp +++ b/overlay_experimental/steam_overlay.cpp @@ -9,6 +9,7 @@ #include #include "../dll/dll.h" +#include "../dll/settings_parser.h" #include "Renderer_Detector.h" @@ -17,6 +18,40 @@ 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; +static constexpr char *valid_languages[] = { + "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", + "vietnamese" +}; + +#define URL_WINDOW_NAME "URL Window" + int find_free_id(std::vector & ids, int base) { std::sort(ids.begin(), ids.end()); @@ -90,8 +125,40 @@ Steam_Overlay::Steam_Overlay(Settings* settings, SteamCallResults* callback_resu h_inset(0), v_inset(0), overlay_state_changed(false), - i_have_lobby(false) + i_have_lobby(false), + show_achievements(false), + show_settings(false), + _renderer(nullptr) { + strncpy(username_text, settings->get_local_name(), sizeof(username_text)); + + if (settings->warn_forced) { + this->disable_forced = true; + this->warning_forced = true; + } else { + this->disable_forced = false; + this->warning_forced = false; + } + + if (settings->warn_local_save) { + this->local_save = true; + } else { + this->local_save = false; + } + + current_language = 0; + const char *language = settings->get_language(); + + int i = 0; + for (auto l : valid_languages) { + if (strcmp(l, language) == 0) { + current_language = i; + break; + } + + ++i; + } + run_every_runcb->add(&Steam_Overlay::steam_overlay_run_every_runcb, this); this->network->setCallback(CALLBACK_ID_STEAM_MESSAGES, settings->get_local_steam_id(), &Steam_Overlay::steam_overlay_callback, this); } @@ -129,21 +196,25 @@ void Steam_Overlay::SetupOverlay() if (!setup_overlay_called) { setup_overlay_called = true; - Renderer_Detector::Inst().find_renderer(); + future_renderer = detect_renderer(); } } -void Steam_Overlay::HookReady() +void Steam_Overlay::HookReady(bool ready) { - if (!is_ready) { // TODO: Uncomment this and draw our own cursor (cosmetics) - //ImGuiIO &io = ImGui::GetIO(); + ImGuiIO &io = ImGui::GetIO(); //io.WantSetMousePos = false; //io.MouseDrawCursor = false; //io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange; - is_ready = true; + io.IniFilename = NULL; + + is_ready = ready; + if (is_ready) { + CreateFonts(); + } } } @@ -158,11 +229,26 @@ void Steam_Overlay::OpenOverlay(const char* pchDialog) ShowOverlay(true); } +void Steam_Overlay::OpenOverlayWebpage(const char* pchURL) +{ + show_url = pchURL; + ShowOverlay(true); +} + bool Steam_Overlay::ShowOverlay() const { return show_overlay; } +bool Steam_Overlay::OpenOverlayHook(bool toggle) +{ + if (toggle) { + ShowOverlay(!show_overlay); + } + + return show_overlay; +} + void Steam_Overlay::ShowOverlay(bool state) { if (!Ready() || show_overlay == state) @@ -310,6 +396,7 @@ void Steam_Overlay::AddMessageNotification(std::string const& message) notif.message = message; notif.start_time = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()); notifications.emplace_back(notif); + have_notifications = true; } else PRINT_DEBUG("No more free id to create a notification window\n"); @@ -328,9 +415,21 @@ void Steam_Overlay::AddAchievementNotification(nlohmann::json const& ach) notif.message = ach["displayName"].get() + "\n" + ach["description"].get(); notif.start_time = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()); notifications.emplace_back(notif); + have_notifications = true; } else PRINT_DEBUG("No more free id to create a notification window\n"); + + std::string ach_name = ach.value("name", ""); + for (auto &a : achievements) { + if (a.name == ach_name) { + 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; + } + } } void Steam_Overlay::AddInviteNotification(std::pair& wnd_state) @@ -346,6 +445,7 @@ void Steam_Overlay::AddInviteNotification(std::pair(std::chrono::system_clock::now().time_since_epoch()); notifications.emplace_back(notif); + have_notifications = true; } else PRINT_DEBUG("No more free id to create a notification window\n"); @@ -584,6 +684,8 @@ void Steam_Overlay::BuildNotifications(int width, int height) notifications.erase(std::remove_if(notifications.begin(), notifications.end(), [&now](Notification &item) { return (now - item.start_time) > Notification::show_time; }), notifications.end()); + + have_notifications = !notifications.empty(); } if (!friend_actions_temp.empty()) { @@ -604,10 +706,7 @@ void Steam_Overlay::CreateFonts() fontcfg.PixelSnapH = true; fontcfg.GlyphRanges = io.Fonts->GetGlyphRangesDefault(); - fontcfg.SizePixels = std::round(io.DisplaySize.y / 68); font_default = io.Fonts->AddFontDefault(&fontcfg); - - fontcfg.SizePixels = std::round(io.DisplaySize.y / 60); font_notif = io.Fonts->AddFontDefault(&fontcfg); ImGuiStyle& style = ImGui::GetStyle(); @@ -622,9 +721,11 @@ void Steam_Overlay::OverlayProc() ImGuiIO& io = ImGui::GetIO(); - ImGui::PushFont(font_notif); - BuildNotifications(io.DisplaySize.x, io.DisplaySize.y); - ImGui::PopFont(); + if (have_notifications) { + ImGui::PushFont(font_notif); + BuildNotifications(io.DisplaySize.x, io.DisplaySize.y); + ImGui::PopFont(); + } if (show_overlay) { @@ -647,9 +748,21 @@ void Steam_Overlay::OverlayProc() settings->get_local_steam_id().ConvertToUint64(), settings->get_local_game_id().AppID()); ImGui::SameLine(); - Base_Hook* hook = Renderer_Detector::Inst().get_renderer(); - ImGui::LabelText("##label", "Renderer: %s", (hook == nullptr ? "Unknown" : hook->get_lib_name())); + ImGui::LabelText("##label", "Renderer: %s", (_renderer == nullptr ? "Unknown" : _renderer->GetLibraryName().c_str())); + + ImGui::Spacing(); + if (ImGui::Button("Show Achievements")) { + show_achievements = true; + } + + ImGui::SameLine(); + + if (ImGui::Button("Settings")) { + show_settings = true; + } + + ImGui::Spacing(); ImGui::Spacing(); ImGui::LabelText("##label", "Friends"); @@ -676,6 +789,123 @@ void Steam_Overlay::OverlayProc() ImGui::ListBoxFooter(); } } + + if (show_achievements && achievements.size()) { + ImGui::SetNextWindowSizeConstraints(ImVec2(ImGui::GetFontSize() * 32, ImGui::GetFontSize() * 32), ImVec2(8192, 8192)); + bool show = show_achievements; + if (ImGui::Begin("Achievement Window", &show)) { + ImGui::Text("List of achievements"); + ImGui::BeginChild("Achievements"); + for (auto & x : achievements) { + bool achieved = x.achieved; + bool hidden = x.hidden && !achieved; + + ImGui::Separator(); + ImGui::Text(x.title.c_str()); + if (x.hidden) { + ImGui::Text("hidden achievement"); + } else { + ImGui::TextWrapped(x.description.c_str()); + } + + if (achieved) { + char buffer[80] = {}; + time_t unlock_time = (time_t)x.unlock_time; + std::strftime(buffer, 80, "%Y-%m-%d at %H:%M:%S", std::localtime(&unlock_time)); + + ImGui::TextColored(ImVec4(0, 255, 0, 255), "achieved on %s", buffer); + } else { + ImGui::TextColored(ImVec4(255, 0, 0, 255), "not achieved"); + } + ImGui::Separator(); + } + ImGui::EndChild(); + } + ImGui::End(); + show_achievements = show; + } + + if (show_settings) { + if (ImGui::Begin("Global Settings Window", &show_settings)) { + ImGui::Text("These are global emulator settings and will apply to all games."); + + ImGui::Separator(); + + ImGui::Text("Username:"); + ImGui::SameLine(); + ImGui::InputText("##username", username_text, sizeof(username_text), disable_forced ? ImGuiInputTextFlags_ReadOnly : 0); + + ImGui::Separator(); + + ImGui::Text("Language:"); + + if (ImGui::ListBox("##language", ¤t_language, valid_languages, sizeof(valid_languages) / sizeof(char *), 7)) { + + } + + ImGui::Text("Selected Language: %s", valid_languages[current_language]); + + ImGui::Separator(); + + if (!disable_forced) { + ImGui::Text("You may have to restart the game for these to apply."); + if (ImGui::Button("Save")) { + save_settings = true; + show_settings = false; + } + } else { + ImGui::TextColored(ImVec4(255, 0, 0, 255), "WARNING WARNING WARNING"); + ImGui::TextWrapped("Some steam_settings/force_*.txt files have been detected. Please delete them if you want this menu to work."); + ImGui::TextColored(ImVec4(255, 0, 0, 255), "WARNING WARNING WARNING"); + } + } + + ImGui::End(); + } + + std::string url = show_url; + if (url.size()) { + bool show = true; + if (ImGui::Begin(URL_WINDOW_NAME, &show)) { + ImGui::Text("The game tried to get the steam overlay to open this url:"); + 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("Close") || !show) + show_url = ""; + // ImGui::SetWindowSize(ImVec2(ImGui::CalcTextSize(url.c_str()).x + 10, 0)); + } + ImGui::End(); + } + + bool show_warning = local_save || warning_forced || appid == 0; + if (show_warning) { + ImGui::SetNextWindowSizeConstraints(ImVec2(ImGui::GetFontSize() * 64, ImGui::GetFontSize() * 64), ImVec2(8192, 8192)); + ImGui::SetNextWindowFocus(); + if (ImGui::Begin("WARNING", &show_warning)) { + if (appid == 0) { + ImGui::TextColored(ImVec4(255, 0, 0, 255), "WARNING WARNING WARNING"); + ImGui::TextWrapped("AppID is 0, please create a steam_appid.txt with the right appid and restart the game."); + ImGui::TextColored(ImVec4(255, 0, 0, 255), "WARNING WARNING WARNING"); + } + if (local_save) { + ImGui::TextColored(ImVec4(255, 0, 0, 255), "WARNING WARNING WARNING"); + ImGui::TextWrapped("local_save.txt detected, the emu is saving locally to the game folder. Please delete it if you don't want this."); + ImGui::TextColored(ImVec4(255, 0, 0, 255), "WARNING WARNING WARNING"); + } + if (warning_forced) { + ImGui::TextColored(ImVec4(255, 0, 0, 255), "WARNING WARNING WARNING"); + ImGui::TextWrapped("Some steam_settings/force_*.txt files have been detected. You will not be able to save some settings."); + ImGui::TextColored(ImVec4(255, 0, 0, 255), "WARNING WARNING WARNING"); + } + } + ImGui::End(); + if (!show_warning) { + local_save = warning_forced = false; + } + } } ImGui::End(); @@ -714,6 +944,22 @@ void Steam_Overlay::Callback(Common_Message *msg) void Steam_Overlay::RunCallbacks() { + if (!Ready() && future_renderer.valid()) { + if (future_renderer.wait_for(std::chrono::milliseconds{0}) == std::future_status::ready) { + _renderer = future_renderer.get(); + PRINT_DEBUG("got renderer %p\n", _renderer); + } + } + + if (!Ready() && _renderer) { + _renderer->OverlayHookReady = std::bind(&Steam_Overlay::HookReady, this, std::placeholders::_1); + _renderer->OverlayProc = std::bind(&Steam_Overlay::OverlayProc, this); + auto callback = std::bind(&Steam_Overlay::OpenOverlayHook, this, std::placeholders::_1); + PRINT_DEBUG("start renderer\n", _renderer); + bool started = _renderer->StartHook(callback); + PRINT_DEBUG("tried to start renderer %u\n", started); + } + if (overlay_state_changed) { GameOverlayActivated_t data = { 0 }; @@ -726,6 +972,19 @@ void Steam_Overlay::RunCallbacks() Steam_Friends* steamFriends = get_steam_client()->steam_friends; Steam_Matchmaking* steamMatchmaking = get_steam_client()->steam_matchmaking; + if (save_settings) { + char *language_text = valid_languages[current_language]; + save_global_settings(get_steam_client()->local_storage, username_text, language_text); + 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(); + save_settings = false; + } + + appid = settings->get_local_game_id().AppID(); + i_have_lobby = IHaveLobby(); std::lock_guard lock(overlay_mutex); std::for_each(friends.begin(), friends.end(), [this](std::pair &i) @@ -824,6 +1083,40 @@ void Steam_Overlay::RunCallbacks() } has_friend_action.pop(); } + + if (!achievements.size()) { + Steam_User_Stats* steamUserStats = get_steam_client()->steam_user_stats; + uint32 achievements_num = steamUserStats->GetNumAchievements(); + if (achievements_num) { + PRINT_DEBUG("POPULATE OVERLAY ACHIEVEMENTS\n"); + for (unsigned 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"); + if (strlen(hidden) && hidden[0] == '1') { + ach.hidden = true; + } else { + ach.hidden = false; + } + + 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; + } + + achievements.push_back(ach); + } + + PRINT_DEBUG("POPULATE OVERLAY ACHIEVEMENTS DONE\n"); + } + } } #endif diff --git a/overlay_experimental/steam_overlay.h b/overlay_experimental/steam_overlay.h index d3b301e..8345b57 100644 --- a/overlay_experimental/steam_overlay.h +++ b/overlay_experimental/steam_overlay.h @@ -70,8 +70,19 @@ struct Notification std::pair* frd; }; -#ifdef EMU_OVERLAY +struct Overlay_Achievement +{ + std::string name; + std::string title; + std::string description; + bool hidden; + bool achieved; + uint32 unlock_time; +}; +#ifdef EMU_OVERLAY +#include +#include "Renderer_Hook.h" class Steam_Overlay { Settings* settings; @@ -88,16 +99,32 @@ class Steam_Overlay bool show_overlay; ENotificationPosition notif_position; int h_inset, v_inset; + std::string show_url; + std::vector achievements; + bool show_achievements, show_settings; + + bool disable_forced, local_save, warning_forced; + uint32_t appid; + + char username_text[256]; + std::atomic_bool save_settings; + + int current_language; + + std::string warning_message; // Callback infos std::queue has_friend_action; std::vector notifications; std::recursive_mutex notifications_mutex; + std::atomic have_notifications; bool overlay_state_changed; std::recursive_mutex overlay_mutex; std::atomic i_have_lobby; + std::future future_renderer; + Renderer_Hook* _renderer; Steam_Overlay(Steam_Overlay const&) = delete; Steam_Overlay(Steam_Overlay&&) = delete; @@ -135,16 +162,18 @@ public: void SetNotificationInset(int nHorizontalInset, int nVerticalInset); void SetupOverlay(); - void HookReady(); + void HookReady(bool ready); void CreateFonts(); void OverlayProc(); void OpenOverlayInvite(CSteamID lobbyId); void OpenOverlay(const char* pchDialog); + void OpenOverlayWebpage(const char* pchURL); bool ShowOverlay() const; void ShowOverlay(bool state); + bool OpenOverlayHook(bool toggle); void SetLobbyInvite(Friend friendId, uint64 lobbyId); void SetRichInvite(Friend friendId, const char* connect_str); @@ -174,16 +203,18 @@ public: void SetNotificationInset(int nHorizontalInset, int nVerticalInset) {} void SetupOverlay() {} - void HookReady() {} + void HookReady(bool ready) {} void CreateFonts() {} void OverlayProc() {} void OpenOverlayInvite(CSteamID lobbyId) {} void OpenOverlay(const char* pchDialog) {} + void OpenOverlayWebpage(const char* pchURL) {} bool ShowOverlay() const {} void ShowOverlay(bool state) {} + bool OpenOverlayHook(bool toggle) {} void SetLobbyInvite(Friend friendId, uint64 lobbyId) {} void SetRichInvite(Friend friendId, const char* connect_str) {}