Added preprocessor exclusion for linux

This commit is contained in:
Nemirtingas 2019-08-14 14:55:31 +02:00
parent f9ee123a05
commit 56b4e6a7c7
14 changed files with 127 additions and 22 deletions

View file

@ -1,6 +1,10 @@
#ifndef __INCLUDED_BASE_HOOK_H__
#define __INCLUDED_BASE_HOOK_H__
#include "../dll/base.h"
#ifdef STEAM_WIN32
#define WIN32_LEAN_AND_MEAN
#define VC_EXTRALEAN
#include <Windows.h>
@ -45,4 +49,6 @@ public:
}
};
#endif
#endif//__INCLUDED_BASE_HOOK_H__

View file

@ -1,4 +1,7 @@
#include "../dll/base.h"
#ifdef STEAM_WIN32
#include "DX10_Hook.h"
#include "Hook_Manager.h"
@ -71,6 +74,7 @@ void DX10_Hook::resetRenderState()
}
}
// Try to make this function and overlay's proc as short as possible or it might affect game's fps.
void DX10_Hook::prepareForOverlay(IDXGISwapChain* pSwapChain)
{
DXGI_SWAP_CHAIN_DESC desc;
@ -208,4 +212,6 @@ void DX10_Hook::loadFunctions(ID3D10Device *pDevice, IDXGISwapChain *pSwapChain)
LOAD_FUNC(ResizeBuffers);
LOAD_FUNC(ResizeTarget);
#undef LOAD_FUNC
}
}
#endif

View file

@ -1,9 +1,11 @@
#ifndef __INCLUDED_DX10_HOOK_H__
#define __INCLUDED_DX10_HOOK_H__
#include "Base_Hook.h"
#ifdef STEAM_WIN32
#include <d3d10.h>
#include "DirectX_VTables.h"
#include "Base_Hook.h"
class DX10_Hook : public Base_Hook
{
@ -46,4 +48,6 @@ public:
void loadFunctions(ID3D10Device *pDevice, IDXGISwapChain *pSwapChain);
};
#endif//STEAM_WIN32
#endif//__INCLUDED_DX10_HOOK_H__

View file

@ -1,4 +1,7 @@
#include "../dll/base.h"
#ifdef STEAM_WIN32
#include "DX11_Hook.h"
#include "Hook_Manager.h"
@ -83,6 +86,7 @@ void DX11_Hook::resetRenderState()
}
}
// Try to make this function and overlay's proc as short as possible or it might affect game's fps.
void DX11_Hook::prepareForOverlay(IDXGISwapChain* pSwapChain)
{
DXGI_SWAP_CHAIN_DESC desc;
@ -227,4 +231,6 @@ void DX11_Hook::loadFunctions(ID3D11Device *pDevice, IDXGISwapChain *pSwapChain)
LOAD_FUNC(ResizeBuffers);
LOAD_FUNC(ResizeTarget);
#undef LOAD_FUNC
}
}
#endif

View file

@ -1,9 +1,11 @@
#ifndef __INCLUDED_DX11_HOOK_H__
#define __INCLUDED_DX11_HOOK_H__
#include "Base_Hook.h"
#ifdef STEAM_WIN32
#include <d3d11.h>
#include "DirectX_VTables.h"
#include "Base_Hook.h"
class DX11_Hook : public Base_Hook
{
@ -46,4 +48,6 @@ public:
void loadFunctions(ID3D11Device *pDevice, IDXGISwapChain *pSwapChain);
};
#endif//STEAM_WIN32
#endif//__INCLUDED_DX11_HOOK_H__

View file

@ -1,4 +1,7 @@
#include "../dll/base.h"
#ifdef STEAM_WIN32
#include "DX12_Hook.h"
#include "Hook_Manager.h"
@ -33,6 +36,7 @@ void DX12_Hook::resetRenderState()
}
}
// Try to make this function and overlay's proc as short as possible or it might affect game's fps.
void DX12_Hook::prepareForOverlay(IDXGISwapChain* pSwapChain)
{
DXGI_SWAP_CHAIN_DESC desc;
@ -134,21 +138,23 @@ DX12_Hook::DX12_Hook():
{
_dll = GetModuleHandle(DLL_NAME);
_hooked = false;
// Hook to D3D11CreateDevice and D3D11CreateDeviceAndSwapChain so we know when it gets called.
// If its called, then DX11 will be used to render the overlay.
D3D12CreateDevice = (decltype(D3D12CreateDevice))GetProcAddress(_dll, "D3D12CreateDevice");
BeginHook();
HookFuncs(
std::make_pair<void**, void*>(&(PVOID&)D3D12CreateDevice, &DX12_Hook::MyD3D12CreateDevice)
);
EndHook();
PRINT_DEBUG("Trying to hook DX12 but DX12_Hook is not implemented yet, please report to DEV with the game name.");
// Hook to D3D12CreateDevice and D3D12CreateDeviceAndSwapChain so we know when it gets called.
// If its called, then DX12 will be used to render the overlay.
//D3D12CreateDevice = (decltype(D3D12CreateDevice))GetProcAddress(_dll, "D3D12CreateDevice");
//
//BeginHook();
//HookFuncs(
// std::make_pair<void**, void*>(&(PVOID&)D3D12CreateDevice, &DX12_Hook::MyD3D12CreateDevice)
//);
//EndHook();
}
DX12_Hook::~DX12_Hook()
{
PRINT_DEBUG("DX11 Hook removed\n");
PRINT_DEBUG("DX12 Hook removed\n");
if (_hooked)
resetRenderState();
@ -181,4 +187,6 @@ void DX12_Hook::loadFunctions(ID3D12Device *pDevice, IDXGISwapChain *pSwapChain)
LOAD_FUNC(ResizeBuffers);
LOAD_FUNC(ResizeTarget);
#undef LOAD_FUNC
}
}
#endif

View file

@ -1,9 +1,11 @@
#ifndef __INCLUDED_DX12_HOOK_H__
#define __INCLUDED_DX12_HOOK_H__
#include "Base_Hook.h"
#ifdef STEAM_WIN32
#include <d3d12.h>
#include "DirectX_VTables.h"
#include "Base_Hook.h"
class DX12_Hook : public Base_Hook
{
@ -46,4 +48,5 @@ public:
void loadFunctions(ID3D12Device *pDevice, IDXGISwapChain *pSwapChain);
};
#endif//STEAM_WIN32
#endif//__INCLUDED_DX12_HOOK_H__

View file

@ -1,5 +1,7 @@
#include "../dll/base.h"
#include "DX9_Hook.h"
#ifdef STEAM_WIN32
#include "Hook_Manager.h"
#include <imgui.h>
@ -72,6 +74,7 @@ void DX9_Hook::resetRenderState()
}
}
// Try to make this function and overlay's proc as short as possible or it might affect game's fps.
void DX9_Hook::prepareForOverlay(IDirect3DDevice9 *pDevice)
{
IDirect3DSwapChain9* pSwapChain;
@ -83,6 +86,7 @@ void DX9_Hook::prepareForOverlay(IDirect3DDevice9 *pDevice)
D3DDEVICE_CREATION_PARAMETERS param;
pDevice->GetCreationParameters(&param);
// Workaround to detect if we changed window.
if (param.hFocusWindow != Hook_Manager::Inst().GetOverlay()->GetGameHwnd())
resetRenderState();
@ -221,4 +225,6 @@ void DX9_Hook::loadFunctions(IDirect3DDevice9Ex* pDeviceEx)
LOAD_FUNC(Present);
LOAD_FUNC(PresentEx);
#undef LOAD_FUNC
}
}
#endif

View file

@ -1,9 +1,11 @@
#ifndef __INCLUDED_DX9_HOOK_H__
#define __INCLUDED_DX9_HOOK_H__
#include "Base_Hook.h"
#ifdef STEAM_WIN32
#include <d3d9.h>
#include "DirectX_VTables.h"
#include "Base_Hook.h"
class DX9_Hook : public Base_Hook
{
@ -47,4 +49,6 @@ public:
void loadFunctions(IDirect3DDevice9Ex *pDeviceEx);
};
#endif//STEAM_WIN32
#endif//__INCLUDED_DX9_HOOK_H__

View file

@ -1,9 +1,12 @@
#ifndef __INCLUDED_HOOK_BASE_H__
#define __INCLUDED_HOOK_BASE_H__
#include "Base_Hook.h"
#ifdef STEAM_WIN32
#include <Windows.h>
#include <vector>
#include "Base_Hook.h"
class Hook_Manager
{
@ -42,5 +45,6 @@ public:
Steam_Overlay* GetOverlay() const { return overlay; }
};
#endif//STEAM_WIN32
#endif//__INCLUDED_HOOK_BASE_H__

View file

@ -1,4 +1,7 @@
#include "../dll/base.h"
#ifdef STEAM_WIN32
#include "OpenGL_Hook.h"
#include "Hook_Manager.h"
@ -56,6 +59,7 @@ void OpenGL_Hook::resetRenderState()
}
}
// Try to make this function and overlay's proc as short as possible or it might affect game's fps.
void OpenGL_Hook::prepareForOverlay(HDC hDC)
{
HWND hWnd = WindowFromDC(hDC);
@ -146,4 +150,6 @@ void OpenGL_Hook::Create()
// Register the hook to the Hook Manager
Hook_Manager::Inst().AddHook(hook);
}
}
}
#endif

View file

@ -1,8 +1,8 @@
#ifndef __INCLUDED_OPENGL_HOOK_H__
#define __INCLUDED_OPENGL_HOOK_H__
#include "DirectX_VTables.h"
#include "Base_Hook.h"
#ifdef STEAM_WIN32
class OpenGL_Hook : public Base_Hook
{
@ -38,4 +38,5 @@ public:
static void Create(); // Initialize OGL Hook.
};
#endif//STEAM_WIN32
#endif//__INCLUDED_OPENGL_HOOK_H__

View file

@ -1,5 +1,7 @@
#include "steam_overlay.h"
#ifdef STEAM_WIN32
#include <thread>
#include <string>
#include <sstream>
@ -585,4 +587,12 @@ void Steam_Overlay::RunCallbacks()
}
has_friend_action.pop();
}
}
}
#else
/* TODO:
* Add here the code for Linux overlay
*/
#endif

View file

@ -39,6 +39,8 @@ struct Friend_Less
}
};
#ifdef STEAM_WIN32
class Steam_Overlay
{
Settings* settings;
@ -117,4 +119,39 @@ public:
void FriendDisconnect(Friend _friend);
};
#else
class Steam_Overlay
{
public:
Steam_Overlay(Settings* settings, SteamCallResults* callback_results, SteamCallBacks* callbacks, RunEveryRunCB* run_every_runcb, Networking *network);
~Steam_Overlay();
bool Ready() const { return false: }
bool NeedPresent() const { return false; }
void SetNotificationPosition(ENotificationPosition eNotificationPosition) {}
void SetNotificationInset(int nHorizontalInset, int nVerticalInset) {}
void SetupOverlay() {}
void HookReady(void* hWnd) {}
void OverlayProc(int width, int height) {}
void OpenOverlayInvite(CSteamID lobbyId) {}
void OpenOverlay(const char* pchDialog) {}
void ShowOverlay(bool state) {}
void SetLobbyInvite(Friend friendId, uint64 lobbyId) {}
void SetRichInvite(Friend friendId, const char* connect_str) {}
void FriendConnect(Friend _friend) {}
void FriendDisconnect(Friend _friend) {}
};
#endif
#endif//__INCLUDED_STEAM_OVERLAY_H__