Cleaned a bit hooks and added sanity checks.

merge-requests/28/head
Nemirtingas 2019-08-26 19:36:07 +02:00
parent 2365b50c38
commit 9b178146c4
12 changed files with 595 additions and 142 deletions

View File

@ -0,0 +1,241 @@
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <cstdint>
#include <fstream>
#include <iomanip>
#include <curl/curl.h>
#include <json/json.hpp>
class CurlGlobal
{
bool _init;
CurlGlobal() :_init(false) {}
~CurlGlobal() { cleanup(); }
public:
static CurlGlobal& Inst()
{
static CurlGlobal _this;
return _this;
}
CURLcode init(long flags = CURL_GLOBAL_DEFAULT) { return curl_global_init(flags); }
void cleanup()
{
if (_init)
{
curl_global_cleanup();
_init = false;
}
}
};
class CurlEasy
{
CURL* _me;
bool _init;
std::string _buffer;
static int writer(char* data, size_t size, size_t nmemb,
CurlEasy* _this)
{
if (_this == nullptr)
return 0;
_this->_buffer.append(data, size * nmemb);
return size * nmemb;
}
public:
CurlEasy() :_me(nullptr), _init(false) {}
~CurlEasy() { cleanup(); }
bool init()
{
_init = (_me = curl_easy_init()) != nullptr;
if (_init)
{
if (curl_easy_setopt(_me, CURLOPT_WRITEFUNCTION, writer) != CURLE_OK)
{
cleanup();
return false;
}
if (curl_easy_setopt(_me, CURLOPT_WRITEDATA, this) != CURLE_OK)
{
cleanup();
return false;
}
}
return _init;
}
void cleanup()
{
if (_init)
{
curl_easy_cleanup(_me);
}
}
CURLcode set_url(const std::string& url)
{
return curl_easy_setopt(_me, CURLOPT_URL, url.c_str());
}
CURLcode skip_verifypeer(bool skip = true)
{
return curl_easy_setopt(_me, CURLOPT_SSL_VERIFYPEER, skip ? 0L : 1L);
}
CURLcode skip_verifhost(bool skip = true)
{
return curl_easy_setopt(_me, CURLOPT_SSL_VERIFYHOST, skip ? 0L : 1L);
}
CURLcode connect_only(bool connect = true)
{
return curl_easy_setopt(_me, CURLOPT_CONNECT_ONLY, connect ? 1L : 0L);
}
CURLcode perform()
{
_buffer.clear();
return curl_easy_perform(_me);
}
CURLcode recv(void* buffer, size_t buflen, size_t* read_len)
{
return curl_easy_recv(_me, buffer, buflen, read_len);
}
CURLcode get_html_code(long& code)
{
return curl_easy_getinfo(_me, CURLINFO_RESPONSE_CODE, &code);
}
std::string const& get_answer() const { return _buffer; }
};
// Get all steam appid with their name: http://api.steampowered.com/ISteamApps/GetAppList/v2/
// Steam storefront webapi: https://wiki.teamfortress.com/wiki/User:RJackson/StorefrontAPI
// http://api.steampowered.com/ISteamUserStats/GetSchemaForGame/v2/?key=<key>&appid=<appid>
/*
{
"game" : {
"gameName" : "<name>",
"availableGameStats" : {
"achievements" : {
("<id>" : {
"name" : "achievement_name",
"displayName" : "achievement name on screen",
"hidden" : (0|1),
["description" : "<desc>",]
"icon" : "<url to icon when achievement is earned>",
"icongray" : "<url to icon when achievement is not earned>"
},
...)
}
}
}
}
*/
// Get appid infos: http://store.steampowered.com/api/appdetails/?appids=218620
/*
"appid" : {
"success" : (true|false),
(success == true "data" : {
...
"name" : "<name>",
"steam_appid" : <appid>,
(OPT "dlc" : [<dlc id>, <dlc id>]),
"header_image" : "<miniature url>" <-- Use this in the overlay ?
(OPT "achievements" : {
"total" : <num of achievements>
}),
"background" : "<background url>" <-- Use this as the overlay background ?
(OPT "packages" : [<package id>, <package id>])
})
}
*/
#ifdef max
#undef max
#endif
//232090
int main()
{
CurlGlobal& cglobal = CurlGlobal::Inst();
cglobal.init();
CurlEasy easy;
if (easy.init())
{
std::string url;
std::string steam_apikey;
std::string app_id;
std::cout << "Enter the game appid: ";
std::cin >> app_id;
std::cout << "Enter your webapi key: ";
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cin >> steam_apikey;
url = "http://api.steampowered.com/ISteamUserStats/GetSchemaForGame/v2/?key=";
url += steam_apikey;
url += "&appid=";
url += app_id;
easy.set_url(url);
easy.perform();
try
{
std::ofstream ach_file("achievements.json", std::ios::trunc | std::ios::out);
nlohmann::json json = nlohmann::json::parse(easy.get_answer());
nlohmann::json output_json = nlohmann::json::array();
bool first = true;
int i = 0;
for (auto& item : json["game"]["availableGameStats"]["achievements"].items())
{
output_json[i]["name"] = item.value()["name"];
output_json[i]["displayName"] = item.value()["displayName"];
output_json[i]["hidden"] = item.value()["hidden"];
try
{
output_json[i]["description"] = item.value()["description"];
}
catch (...)
{
output_json[i]["description"] = "";
}
output_json[i]["icon"] = item.value()["icon"];
output_json[i]["icongray"] = item.value()["icongray"];
output_json[i]["time_earned"] = 0;
output_json[i]["earned"] = 0;
++i;
}
ach_file << std::setw(2) << output_json;
}
catch (std::exception& e)
{
std::cerr << "Failed to get infos: ";
long code;
if (easy.get_html_code(code) == CURLE_OK && code == 403)
{
std::cerr << "Error in webapi key";
}
else
{
std::cerr << "Error while parsing json. Try to go at " << url << " and see what you can do to build your achivements.json";
}
std::cerr << std::endl;
}
}
}

View File

@ -0,0 +1,157 @@
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <vector>
#include <iomanip>
#include <thread>
#include <json/json.hpp>
#include <steam_gameserver.h>
struct ClientCBS
{
STEAM_CALLBACK(ClientCBS, OnSteamInventoryDefinitionUpdate, SteamInventoryDefinitionUpdate_t);
STEAM_CALLBACK(ClientCBS, OnSteamInventoryResultReady , SteamInventoryResultReady_t);
};
bool definition_update = false;
std::vector<std::string> split(const std::string& s, char delimiter)
{
std::vector<std::string> tokens;
std::string token;
std::istringstream tokenStream(s);
while (std::getline(tokenStream, token, delimiter))
{
tokens.push_back(token);
}
return tokens;
}
void ClientCBS::OnSteamInventoryResultReady(SteamInventoryResultReady_t* param)
{
switch (param->m_result)
{
case k_EResultOK: break;
case k_EResultPending: break;
}
if (param->m_handle)
{
SteamInventory()->DestroyResult(param->m_handle);
}
}
void ClientCBS::OnSteamInventoryDefinitionUpdate(SteamInventoryDefinitionUpdate_t* param)
{
std::ofstream out("items.json", std::ios::out | std::ios::trunc);
nlohmann::json json = nlohmann::json::object();
SteamItemDef_t* items;
uint32 size = 0;
SteamInventory()->GetItemDefinitionIDs(nullptr, &size);
items = new SteamItemDef_t[size];
SteamInventory()->GetItemDefinitionIDs(items, &size);
definition_update = true;
std::cerr << "Creating json, please wait..." << std::endl;
for (int i = 0; i < size; ++i)
{
uint32 len;
len = 0;
if (SteamInventory()->GetItemDefinitionProperty(items[i], nullptr, nullptr, &len))
{
std::string buffer(len, '\0');
if (SteamInventory()->GetItemDefinitionProperty(items[i], nullptr, &buffer[0], &len))
{
buffer.pop_back();
std::vector<std::string> strs(std::move(split(buffer, ',')));
std::string key = std::to_string(items[i]);
for (auto j = strs.begin(); j != strs.end(); ++j)
{
len = 0;
if (SteamInventory()->GetItemDefinitionProperty(items[i], j->c_str(), nullptr, &len))
{
std::string buffer(len, '\0');
if (SteamInventory()->GetItemDefinitionProperty(items[i], j->c_str(), &buffer[0], &len))
{
buffer.pop_back();
if( *j == "quantity")
json[key][*j] = "0";
else
json[key][*j] = buffer;
}
}
}
}
}
}
out << std::setw(2) << json;
delete[]items;
}
int main(int argc, char *argv[])
{
uint32_t appid;
if (argc == 2)
{
appid = std::stoi(argv[1]);
}
else
{
std::cout << "Enter the game appid: ";
std::cin >> appid;
}
std::ofstream steam_api("steam_appid.txt", std::ios::out | std::ios::trunc);
steam_api << appid;
steam_api.close();
if (SteamAPI_RestartAppIfNecessary(0))
{
std::cerr << "This app needs restart" << std::endl;
return EXIT_FAILURE;
}
if (!SteamAPI_Init())
{
std::cerr << "SteamAPI_Init() failed" << std::endl;
return EXIT_FAILURE;
}
auto SUser = SteamUser();
if (!SUser->BLoggedOn())
{
std::cerr << "Steam user is not logged in" << std::endl;
return EXIT_FAILURE;
}
ClientCBS cbs;
int max_retry = 10;
while (!definition_update && max_retry-- > 0)
{
std::cerr << "Running LoadItemDefinitions" << std::endl;
bool ret = SteamInventory()->LoadItemDefinitions();
int retry = 0;
while (retry++ <= 100 && !definition_update)
{
SteamAPI_RunCallbacks();
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
}
SteamAPI_Shutdown();
return 0;
}

View File

@ -139,7 +139,10 @@ HRESULT STDMETHODCALLTYPE DX10_Hook::MyResizeBuffers(IDXGISwapChain* _this, UINT
DX10_Hook::DX10_Hook(): DX10_Hook::DX10_Hook():
initialized(false), initialized(false),
pDevice(nullptr), pDevice(nullptr),
mainRenderTargetView(nullptr) mainRenderTargetView(nullptr),
Present(nullptr),
ResizeBuffers(nullptr),
ResizeTarget(nullptr)
{ {
_library = LoadLibrary(DLL_NAME); _library = LoadLibrary(DLL_NAME);
@ -190,13 +193,9 @@ const char* DX10_Hook::get_lib_name() const
return DLL_NAME; return DLL_NAME;
} }
void DX10_Hook::loadFunctions(ID3D10Device *pDevice, IDXGISwapChain *pSwapChain) void DX10_Hook::loadFunctions(IDXGISwapChain *pSwapChain)
{ {
void** vTable = *reinterpret_cast<void***>(pDevice); void** vTable;
#define LOAD_FUNC(X) (void*&)X = vTable[(int)ID3D10DeviceVTable::X]
#undef LOAD_FUNC
vTable = *reinterpret_cast<void***>(pSwapChain); vTable = *reinterpret_cast<void***>(pSwapChain);
#define LOAD_FUNC(X) (void*&)X = vTable[(int)IDXGISwapChainVTable::X] #define LOAD_FUNC(X) (void*&)X = vTable[(int)IDXGISwapChainVTable::X]

View File

@ -48,7 +48,7 @@ public:
static DX10_Hook* Inst(); static DX10_Hook* Inst();
virtual const char* get_lib_name() const; virtual const char* get_lib_name() const;
void loadFunctions(ID3D10Device *pDevice, IDXGISwapChain *pSwapChain); void loadFunctions(IDXGISwapChain *pSwapChain);
}; };
#endif//NO_OVERLAY #endif//NO_OVERLAY

View File

@ -156,7 +156,10 @@ HRESULT STDMETHODCALLTYPE DX11_Hook::MyResizeBuffers(IDXGISwapChain* _this, UINT
DX11_Hook::DX11_Hook(): DX11_Hook::DX11_Hook():
initialized(false), initialized(false),
pContext(nullptr), pContext(nullptr),
mainRenderTargetView(nullptr) mainRenderTargetView(nullptr),
Present(nullptr),
ResizeBuffers(nullptr),
ResizeTarget(nullptr)
{ {
_library = LoadLibrary(DLL_NAME); _library = LoadLibrary(DLL_NAME);
@ -208,13 +211,9 @@ const char* DX11_Hook::get_lib_name() const
return DLL_NAME; return DLL_NAME;
} }
void DX11_Hook::loadFunctions(ID3D11Device *pDevice, IDXGISwapChain *pSwapChain) void DX11_Hook::loadFunctions(IDXGISwapChain *pSwapChain)
{ {
void** vTable = *reinterpret_cast<void***>(pDevice); void** vTable;
#define LOAD_FUNC(X) (void*&)X = vTable[(int)ID3D11DeviceVTable::X]
#undef LOAD_FUNC
vTable = *reinterpret_cast<void***>(pSwapChain); vTable = *reinterpret_cast<void***>(pSwapChain);
#define LOAD_FUNC(X) (void*&)X = vTable[(int)IDXGISwapChainVTable::X] #define LOAD_FUNC(X) (void*&)X = vTable[(int)IDXGISwapChainVTable::X]

View File

@ -48,7 +48,7 @@ public:
static DX11_Hook* Inst(); static DX11_Hook* Inst();
virtual const char* get_lib_name() const; virtual const char* get_lib_name() const;
void loadFunctions(ID3D11Device *pDevice, IDXGISwapChain *pSwapChain); void loadFunctions(IDXGISwapChain *pSwapChain);
}; };
#endif//NO_OVERLAY #endif//NO_OVERLAY

View File

@ -178,7 +178,7 @@ DX12_Hook::DX12_Hook():
{ {
_library = LoadLibrary(DLL_NAME); _library = LoadLibrary(DLL_NAME);
PRINT_DEBUG("Trying to hook DX12 but DX12_Hook is not implemented yet, please report to DEV with the game name.\n"); PRINT_DEBUG("DX12 support is experimental, don't complain if it doesn't work as expected.\n");
// Hook to D3D12CreateDevice and D3D12CreateDeviceAndSwapChain so we know when it gets called. // Hook to D3D12CreateDevice and D3D12CreateDeviceAndSwapChain so we know when it gets called.
// If its called, then DX12 will be used to render the overlay. // If its called, then DX12 will be used to render the overlay.
@ -223,24 +223,9 @@ const char* DX12_Hook::get_lib_name() const
return DLL_NAME; return DLL_NAME;
} }
void DX12_Hook::loadFunctions(ID3D12Device* pDevice, ID3D12CommandQueue* pCommandQueue, IDXGISwapChain *pSwapChain) void DX12_Hook::loadFunctions(ID3D12CommandList* pCommandList, IDXGISwapChain *pSwapChain)
{ {
void** vTable = *reinterpret_cast<void***>(pDevice); void** vTable;
#define LOAD_FUNC(X) (void*&)X = vTable[(int)ID3D12DeviceVTable::X]
#undef LOAD_FUNC
vTable = *reinterpret_cast<void***>(pCommandQueue);
#define LOAD_FUNC(X) (void*&)X = vTable[(int)ID3D12CommandQueueVTable::X]
LOAD_FUNC(ExecuteCommandLists);
#undef LOAD_FUNC
ID3D12CommandAllocator* pCommandAllocator;
ID3D12CommandList* pCommandList;
pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&pCommandAllocator));
pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, pCommandAllocator, NULL, IID_PPV_ARGS(&pCommandList));
vTable = *reinterpret_cast<void***>(pCommandList); vTable = *reinterpret_cast<void***>(pCommandList);
#define LOAD_FUNC(X) (void*&)X = vTable[(int)ID3D12GraphicsCommandListVTable::X] #define LOAD_FUNC(X) (void*&)X = vTable[(int)ID3D12GraphicsCommandListVTable::X]
@ -253,9 +238,6 @@ void DX12_Hook::loadFunctions(ID3D12Device* pDevice, ID3D12CommandQueue* pComman
LOAD_FUNC(ResizeBuffers); LOAD_FUNC(ResizeBuffers);
LOAD_FUNC(ResizeTarget); LOAD_FUNC(ResizeTarget);
#undef LOAD_FUNC #undef LOAD_FUNC
pCommandList->Release();
pCommandAllocator->Release();
} }
#endif//NO_OVERLAY #endif//NO_OVERLAY

View File

@ -52,7 +52,7 @@ public:
static DX12_Hook* Inst(); static DX12_Hook* Inst();
virtual const char* get_lib_name() const; virtual const char* get_lib_name() const;
void loadFunctions(ID3D12Device *pDevice, ID3D12CommandQueue *pCommandQueue, IDXGISwapChain *pSwapChain); void loadFunctions(ID3D12CommandList *pCommandList, IDXGISwapChain *pSwapChain);
}; };
#endif//NO_OVERLAY #endif//NO_OVERLAY

View File

@ -49,13 +49,13 @@ HRESULT STDMETHODCALLTYPE Hook_Manager::MyIDXGISwapChain_Present(IDXGISwapChain*
} }
else else
{ {
_this->GetDevice(__uuidof(ID3D12Device), (void**)& pDevice); //_this->GetDevice(__uuidof(ID3D12Device), (void**)& pDevice);
if (pDevice) //if (pDevice)
{ //{
// DX12_Hook* hook = DX12_Hook::Inst(); // DX12_Hook* hook = DX12_Hook::Inst();
// if (hook->start_hook()) // if (hook->start_hook())
// inst.AddHook(hook); // inst.AddHook(hook);
} //}
} }
} }
if (pDevice) pDevice->Release(); if (pDevice) pDevice->Release();
@ -142,11 +142,14 @@ void Hook_Manager::HookDX9Present(IDirect3DDevice9* pDevice, bool ex)
} }
} }
void Hook_Manager::HookwglMakeCurrent() void Hook_Manager::HookwglMakeCurrent(BOOL(WINAPI* wglMakeCurrent)(HDC, HGLRC))
{ {
if (!_ogl_hooked) if (!_ogl_hooked)
{ {
_ogl_hooked = true; _ogl_hooked = true;
_wglMakeCurrent = wglMakeCurrent;
rendererdetect_hook->BeginHook(); rendererdetect_hook->BeginHook();
rendererdetect_hook->HookFuncs( rendererdetect_hook->HookFuncs(
@ -167,7 +170,11 @@ void Hook_Manager::hook_dx9()
IDirect3D9Ex* pD3D = nullptr; IDirect3D9Ex* pD3D = nullptr;
IUnknown* pDevice = nullptr; IUnknown* pDevice = nullptr;
HMODULE library = GetModuleHandle(DX9_Hook::DLL_NAME);
decltype(Direct3DCreate9Ex)* Direct3DCreate9Ex = nullptr;
if (library != nullptr)
{
Direct3DCreate9Ex = (decltype(Direct3DCreate9Ex))GetProcAddress(library, "Direct3DCreate9Ex");
D3DPRESENT_PARAMETERS params = {}; D3DPRESENT_PARAMETERS params = {};
params.BackBufferWidth = 1; params.BackBufferWidth = 1;
params.BackBufferHeight = 1; params.BackBufferHeight = 1;
@ -176,21 +183,21 @@ void Hook_Manager::hook_dx9()
params.Windowed = TRUE; params.Windowed = TRUE;
params.SwapEffect = D3DSWAPEFFECT_DISCARD; params.SwapEffect = D3DSWAPEFFECT_DISCARD;
decltype(Direct3DCreate9Ex)* Direct3DCreate9Ex = (decltype(Direct3DCreate9Ex))GetProcAddress(GetModuleHandle(DX9_Hook::DLL_NAME), "Direct3DCreate9Ex");
if (Direct3DCreate9Ex != nullptr) if (Direct3DCreate9Ex != nullptr)
{ {
Direct3DCreate9Ex(D3D_SDK_VERSION, &pD3D); Direct3DCreate9Ex(D3D_SDK_VERSION, &pD3D);
pD3D->CreateDeviceEx(D3DADAPTER_DEFAULT, D3DDEVTYPE_NULLREF, NULL, D3DCREATE_HARDWARE_VERTEXPROCESSING, &params, NULL, reinterpret_cast<IDirect3DDevice9Ex**>(&pDevice)); pD3D->CreateDeviceEx(D3DADAPTER_DEFAULT, D3DDEVTYPE_NULLREF, NULL, D3DCREATE_HARDWARE_VERTEXPROCESSING, &params, NULL, reinterpret_cast<IDirect3DDevice9Ex * *>(&pDevice));
} }
else else
{ {
decltype(Direct3DCreate9)* Direct3DCreate9 = (decltype(Direct3DCreate9))GetProcAddress(GetModuleHandle(DX9_Hook::DLL_NAME), "Direct3DCreate9"); decltype(Direct3DCreate9)* Direct3DCreate9 = (decltype(Direct3DCreate9))GetProcAddress(library, "Direct3DCreate9");
if (Direct3DCreate9) if (Direct3DCreate9 != nullptr)
{ {
pD3D = reinterpret_cast<IDirect3D9Ex*>(Direct3DCreate9(D3D_SDK_VERSION)); pD3D = reinterpret_cast<IDirect3D9Ex*>(Direct3DCreate9(D3D_SDK_VERSION));
pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_NULLREF, NULL, D3DCREATE_HARDWARE_VERTEXPROCESSING, &params, reinterpret_cast<IDirect3DDevice9 * *>(&pDevice)); pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_NULLREF, NULL, D3DCREATE_HARDWARE_VERTEXPROCESSING, &params, reinterpret_cast<IDirect3DDevice9 * *>(&pDevice));
} }
} }
}
if (pDevice != nullptr) if (pDevice != nullptr)
{ {
@ -218,11 +225,17 @@ void Hook_Manager::hook_dx10()
if (!hWnd) if (!hWnd)
return; return;
IDXGISwapChain* pSwapChain; IDXGISwapChain* pSwapChain = nullptr;
ID3D10Device* pDevice; ID3D10Device* pDevice = nullptr;
DXGI_SWAP_CHAIN_DESC SwapChainDesc = {}; HMODULE library = GetModuleHandle(DX10_Hook::DLL_NAME);
if (library != nullptr)
{
decltype(D3D10CreateDeviceAndSwapChain)* D3D10CreateDeviceAndSwapChain = decltype(D3D10CreateDeviceAndSwapChain)* D3D10CreateDeviceAndSwapChain =
(decltype(D3D10CreateDeviceAndSwapChain))GetProcAddress(GetModuleHandle(DX10_Hook::DLL_NAME), "D3D10CreateDeviceAndSwapChain"); (decltype(D3D10CreateDeviceAndSwapChain))GetProcAddress(library, "D3D10CreateDeviceAndSwapChain");
if (D3D10CreateDeviceAndSwapChain != nullptr)
{
DXGI_SWAP_CHAIN_DESC SwapChainDesc = {};
SwapChainDesc.BufferCount = 1; SwapChainDesc.BufferCount = 1;
SwapChainDesc.BufferDesc.Width = 1; SwapChainDesc.BufferDesc.Width = 1;
SwapChainDesc.BufferDesc.Height = 1; SwapChainDesc.BufferDesc.Height = 1;
@ -236,12 +249,13 @@ void Hook_Manager::hook_dx10()
SwapChainDesc.Windowed = TRUE; SwapChainDesc.Windowed = TRUE;
D3D10CreateDeviceAndSwapChain(NULL, D3D10_DRIVER_TYPE_NULL, NULL, 0, D3D10_SDK_VERSION, &SwapChainDesc, &pSwapChain, &pDevice); D3D10CreateDeviceAndSwapChain(NULL, D3D10_DRIVER_TYPE_NULL, NULL, 0, D3D10_SDK_VERSION, &SwapChainDesc, &pSwapChain, &pDevice);
}
if (pDevice != nullptr && pSwapChain != nullptr) }
if (pSwapChain != nullptr)
{ {
PRINT_DEBUG("Hooked IDXGISwapChain::Present to detect DX Version\n"); PRINT_DEBUG("Hooked IDXGISwapChain::Present to detect DX Version\n");
auto h = DX10_Hook::Inst(); auto h = DX10_Hook::Inst();
h->loadFunctions(pDevice, pSwapChain); h->loadFunctions(pSwapChain);
_hooks.insert(h); _hooks.insert(h);
HookDXGIPresent(pSwapChain); HookDXGIPresent(pSwapChain);
} }
@ -262,11 +276,17 @@ void Hook_Manager::hook_dx11()
if (!hWnd) if (!hWnd)
return; return;
IDXGISwapChain* pSwapChain; IDXGISwapChain* pSwapChain = nullptr;
ID3D11Device* pDevice; ID3D11Device* pDevice = nullptr;
DXGI_SWAP_CHAIN_DESC SwapChainDesc = {}; HMODULE library = GetModuleHandle(DX11_Hook::DLL_NAME);
if (library != nullptr)
{
decltype(D3D11CreateDeviceAndSwapChain)* D3D11CreateDeviceAndSwapChain = decltype(D3D11CreateDeviceAndSwapChain)* D3D11CreateDeviceAndSwapChain =
(decltype(D3D11CreateDeviceAndSwapChain))GetProcAddress(GetModuleHandle(DX11_Hook::DLL_NAME), "D3D11CreateDeviceAndSwapChain"); (decltype(D3D11CreateDeviceAndSwapChain))GetProcAddress(library, "D3D11CreateDeviceAndSwapChain");
if (D3D11CreateDeviceAndSwapChain != nullptr)
{
DXGI_SWAP_CHAIN_DESC SwapChainDesc = {};
SwapChainDesc.BufferCount = 1; SwapChainDesc.BufferCount = 1;
SwapChainDesc.BufferDesc.Width = 1; SwapChainDesc.BufferDesc.Width = 1;
SwapChainDesc.BufferDesc.Height = 1; SwapChainDesc.BufferDesc.Height = 1;
@ -280,12 +300,13 @@ void Hook_Manager::hook_dx11()
SwapChainDesc.Windowed = TRUE; SwapChainDesc.Windowed = TRUE;
D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_NULL, NULL, 0, NULL, NULL, D3D11_SDK_VERSION, &SwapChainDesc, &pSwapChain, &pDevice, NULL, NULL); D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_NULL, NULL, 0, NULL, NULL, D3D11_SDK_VERSION, &SwapChainDesc, &pSwapChain, &pDevice, NULL, NULL);
}
if (pDevice != nullptr && pSwapChain != nullptr) }
if (pSwapChain != nullptr)
{ {
PRINT_DEBUG("Hooked IDXGISwapChain::Present to detect DX Version\n"); PRINT_DEBUG("Hooked IDXGISwapChain::Present to detect DX Version\n");
auto h = DX11_Hook::Inst(); auto h = DX11_Hook::Inst();
h->loadFunctions(pDevice, pSwapChain); h->loadFunctions(pSwapChain);
_hooks.insert(h); _hooks.insert(h);
HookDXGIPresent(pSwapChain); HookDXGIPresent(pSwapChain);
} }
@ -309,16 +330,22 @@ void Hook_Manager::hook_dx12()
IDXGIFactory4* pDXGIFactory = nullptr; IDXGIFactory4* pDXGIFactory = nullptr;
IDXGISwapChain1* pSwapChain = nullptr; IDXGISwapChain1* pSwapChain = nullptr;
D3D12_COMMAND_QUEUE_DESC queueDesc = {};
ID3D12CommandQueue* pCommandQueue = nullptr; ID3D12CommandQueue* pCommandQueue = nullptr;
ID3D12Device* pDevice = nullptr; ID3D12Device* pDevice = nullptr;
ID3D12CommandAllocator* pCommandAllocator = nullptr;
ID3D12CommandList* pCommandList = nullptr;
HMODULE library = GetModuleHandle(DX12_Hook::DLL_NAME);
if (library != nullptr)
{
decltype(D3D12CreateDevice)* D3D12CreateDevice = decltype(D3D12CreateDevice)* D3D12CreateDevice =
(decltype(D3D12CreateDevice))GetProcAddress(GetModuleHandle(DX12_Hook::DLL_NAME), "D3D12CreateDevice"); (decltype(D3D12CreateDevice))GetProcAddress(library, "D3D12CreateDevice");
if (D3D12CreateDevice != nullptr)
{
D3D12CreateDevice(NULL, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&pDevice)); D3D12CreateDevice(NULL, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&pDevice));
if (pDevice) if (pDevice != nullptr)
{ {
DXGI_SWAP_CHAIN_DESC1 SwapChainDesc = {}; DXGI_SWAP_CHAIN_DESC1 SwapChainDesc = {};
SwapChainDesc.BufferCount = 2; SwapChainDesc.BufferCount = 2;
@ -332,20 +359,42 @@ void Hook_Manager::hook_dx12()
SwapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD; SwapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
SwapChainDesc.AlphaMode = DXGI_ALPHA_MODE_UNSPECIFIED; SwapChainDesc.AlphaMode = DXGI_ALPHA_MODE_UNSPECIFIED;
D3D12_COMMAND_QUEUE_DESC queueDesc = {};
queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT; queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE; queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
pDevice->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&pCommandQueue)); pDevice->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&pCommandQueue));
if (pCommandQueue) if (pCommandQueue != nullptr)
{
HMODULE dxgi = GetModuleHandle("dxgi.dll");
if (dxgi != nullptr)
{
decltype(CreateDXGIFactory1)* CreateDXGIFactory1 = (decltype(CreateDXGIFactory1))GetProcAddress(dxgi, "CreateDXGIFactory1");
if (CreateDXGIFactory1 != nullptr)
{
CreateDXGIFactory1(IID_PPV_ARGS(&pDXGIFactory));
if (pDXGIFactory != nullptr)
{ {
reinterpret_cast<decltype(CreateDXGIFactory1)*>(GetProcAddress(GetModuleHandle("dxgi.dll"), "CreateDXGIFactory1"))(IID_PPV_ARGS(&pDXGIFactory));
pDXGIFactory->CreateSwapChainForHwnd(pCommandQueue, hWnd, &SwapChainDesc, NULL, NULL, &pSwapChain); pDXGIFactory->CreateSwapChainForHwnd(pCommandQueue, hWnd, &SwapChainDesc, NULL, NULL, &pSwapChain);
if (pSwapChain != nullptr)
pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&pCommandAllocator));
if (pCommandAllocator != nullptr)
{
pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, pCommandAllocator, NULL, IID_PPV_ARGS(&pCommandList));
}
}
}
}
}
}//if (pDevice != nullptr)
}//if (D3D12CreateDevice != nullptr)
}//if (library != nullptr)
if (pSwapChain != nullptr && pCommandList != nullptr)
{ {
PRINT_DEBUG("Hooked IDXGISwapChain::Present to detect DX Version\n"); PRINT_DEBUG("Hooked IDXGISwapChain::Present to detect DX Version\n");
auto h = DX12_Hook::Inst(); auto h = DX12_Hook::Inst();
h->loadFunctions(pDevice, pCommandQueue, pSwapChain); h->loadFunctions(pCommandList, pSwapChain);
_hooks.insert(h); _hooks.insert(h);
HookDXGIPresent(pSwapChain); HookDXGIPresent(pSwapChain);
} }
@ -353,9 +402,9 @@ void Hook_Manager::hook_dx12()
{ {
PRINT_DEBUG("Failed to Hook IDXGISwapChain::Present to detect DX Version\n"); PRINT_DEBUG("Failed to Hook IDXGISwapChain::Present to detect DX Version\n");
} }
}
}
if (pCommandList) pCommandList->Release();
if (pCommandAllocator) pCommandAllocator->Release();
if (pSwapChain) pSwapChain->Release(); if (pSwapChain) pSwapChain->Release();
if (pDXGIFactory) pDXGIFactory->Release(); if (pDXGIFactory) pDXGIFactory->Release();
if (pCommandQueue) pCommandQueue->Release(); if (pCommandQueue) pCommandQueue->Release();
@ -367,8 +416,21 @@ void Hook_Manager::hook_opengl()
{ {
if (!_ogl_hooked && !_renderer_found) if (!_ogl_hooked && !_renderer_found)
{ {
_wglMakeCurrent = (decltype(_wglMakeCurrent))GetProcAddress(GetModuleHandle(OpenGL_Hook::DLL_NAME), "wglMakeCurrent"); HMODULE library = GetModuleHandle(OpenGL_Hook::DLL_NAME);
HookwglMakeCurrent(); decltype(wglMakeCurrent)* wglMakeCurrent = nullptr;
if (library != nullptr)
{
_wglMakeCurrent = (decltype(_wglMakeCurrent))GetProcAddress(library, "wglMakeCurrent");
}
if (wglMakeCurrent != nullptr)
{
PRINT_DEBUG("Hooked wglMakeCurrent to detect OpenGL\n");
HookwglMakeCurrent(wglMakeCurrent);
}
else
{
PRINT_DEBUG("Failed to Hook wglMakeCurrent to detect OpenGL\n");
}
} }
} }

View File

@ -59,7 +59,7 @@ protected:
// DX9 Present and PresentEx will be used to detect if DX9 should be used for overlay // DX9 Present and PresentEx will be used to detect if DX9 should be used for overlay
void HookDX9Present(IDirect3DDevice9* pDevice, bool ex); void HookDX9Present(IDirect3DDevice9* pDevice, bool ex);
// wglMakeCurrent will be used to detect if OpenGL3 should be used for overlay // wglMakeCurrent will be used to detect if OpenGL3 should be used for overlay
void HookwglMakeCurrent(); void HookwglMakeCurrent(BOOL (WINAPI *wglMakeCurrent)(HDC, HGLRC));
// Setup DX9 Device and get vtable // Setup DX9 Device and get vtable
void hook_dx9(); void hook_dx9();
// Setup DX10 Device and get vtable // Setup DX10 Device and get vtable

View File

@ -369,6 +369,17 @@ void Steam_Overlay::BuildFriendWindow(Friend const& frd, friend_window_state& st
ImGui::End(); ImGui::End();
} }
void Steam_Overlay::BuildNotifications()
{
//ImGui::SetNextWindowPos(ImVec2{ (float)width - 300, (float)height - 80 });
//ImGui::SetNextWindowSize(ImVec2{ 300.0, 80.0 });
//ImGui::Begin("##notification", nullptr, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse
// | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoFocusOnAppearing
// | ImGuiWindowFlags_NoDecoration);
//
//ImGui::End();
}
// Try to make this function as short as possible or it might affect game's fps. // Try to make this function as short as possible or it might affect game's fps.
void Steam_Overlay::OverlayProc( int width, int height ) void Steam_Overlay::OverlayProc( int width, int height )
{ {
@ -430,6 +441,7 @@ void Steam_Overlay::OverlayProc( int width, int height )
ImGui::End(); ImGui::End();
}// if(show_overlay) }// if(show_overlay)
BuildNotifications();
} }
void Steam_Overlay::Callback(Common_Message *msg) void Steam_Overlay::Callback(Common_Message *msg)

View File

@ -80,7 +80,8 @@ class Steam_Overlay
void BuildContextMenu(Friend const& frd, friend_window_state &state); void BuildContextMenu(Friend const& frd, friend_window_state &state);
// Double click on friend // Double click on friend
void BuildFriendWindow(Friend const& frd, friend_window_state &state); void BuildFriendWindow(Friend const& frd, friend_window_state &state);
// Notifications like achievements, chat and invitations
void BuildNotifications();
public: public:
Steam_Overlay(Settings* settings, SteamCallResults* callback_results, SteamCallBacks* callbacks, RunEveryRunCB* run_every_runcb, Networking *network); Steam_Overlay(Settings* settings, SteamCallResults* callback_results, SteamCallBacks* callbacks, RunEveryRunCB* run_every_runcb, Networking *network);