From f8a8edde2171de3a973759363486c5968a40208d Mon Sep 17 00:00:00 2001 From: momo5502 Date: Thu, 7 Jan 2016 16:55:10 +0100 Subject: [PATCH] Implement steam overlay. --- .gitmodules | 4 ---- src/Steam/Interfaces/SteamUtils.cpp | 5 +++++ src/Steam/Steam.cpp | 20 ++++++++++++++++++++ src/Steam/Steam.hpp | 2 ++ src/Utils/Hooking.hpp | 5 +++++ 5 files changed, 32 insertions(+), 4 deletions(-) diff --git a/.gitmodules b/.gitmodules index be58e14f..ccba2999 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,7 +1,3 @@ -[submodule "tools/premake/github-package"] - path = tools/premake/github-package - url = https://github.com/mversluys/premake-github-package.git - branch = master [submodule "deps/zlib"] path = deps/zlib url = https://github.com/madler/zlib.git diff --git a/src/Steam/Interfaces/SteamUtils.cpp b/src/Steam/Interfaces/SteamUtils.cpp index 7bfbb9b2..296f959c 100644 --- a/src/Steam/Interfaces/SteamUtils.cpp +++ b/src/Steam/Interfaces/SteamUtils.cpp @@ -54,6 +54,11 @@ namespace Steam void Utils::SetOverlayNotificationPosition(int eNotificationPosition) { + if (Steam::Overlay) + { + FARPROC setPosition = GetProcAddress(Steam::Overlay, "SetNotificationPosition"); + ::Utils::Hook::Call(setPosition)(eNotificationPosition); + } } bool Utils::IsAPICallCompleted(unsigned __int64 hSteamAPICall, bool *pbFailed) diff --git a/src/Steam/Steam.cpp b/src/Steam/Steam.cpp index cae565f3..d74d5410 100644 --- a/src/Steam/Steam.cpp +++ b/src/Steam/Steam.cpp @@ -3,6 +3,8 @@ namespace Steam { + HMODULE Overlay = 0; + uint64_t Callbacks::CallID = 0; std::map Callbacks::Calls; std::map Callbacks::ResultHandlers; @@ -70,6 +72,24 @@ namespace Steam { bool SteamAPI_Init() { + Overlay = GetModuleHandleA("gameoverlayrenderer.dll"); + + if (!Overlay) + { + HKEY hRegKey; + char steamPath[MAX_PATH] = { 0 }; + if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\Valve\\Steam", 0, KEY_QUERY_VALUE, &hRegKey) == ERROR_SUCCESS) + { + DWORD dwLength = sizeof(steamPath); + RegQueryValueExA(hRegKey, "InstallPath", NULL, NULL, (BYTE*)steamPath, &dwLength); + RegCloseKey(hRegKey); + + SetDllDirectory(steamPath); + } + + Overlay = LoadLibraryA(::Utils::VA("%s\\%s", steamPath, "gameoverlayrenderer.dll")); + } + return true; } diff --git a/src/Steam/Steam.hpp b/src/Steam/Steam.hpp index c8abd611..0c51403c 100644 --- a/src/Steam/Steam.hpp +++ b/src/Steam/Steam.hpp @@ -88,4 +88,6 @@ namespace Steam STEAM_EXPORT Steam::RemoteStorage* SteamRemoteStorage(); STEAM_EXPORT Steam::User* SteamUser(); STEAM_EXPORT Steam::Utils* SteamUtils(); + + extern HMODULE Overlay; } diff --git a/src/Utils/Hooking.hpp b/src/Utils/Hooking.hpp index e7e7d6e4..08983163 100644 --- a/src/Utils/Hooking.hpp +++ b/src/Utils/Hooking.hpp @@ -28,6 +28,11 @@ namespace Utils return std::function((T*)function); } + template static std::function Call(FARPROC function) + { + return Call((DWORD)function); + } + static void SetString(void* place, const char* string, size_t length); static void SetString(DWORD place, const char* string, size_t length);