Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
Improve d3d9ex support
Browse files Browse the repository at this point in the history
* On d3d9ex IDirect3DDevice9::Reset() isn't called,
  thus we need to also hook IDirect3DDevice9Ex::ResetEx()
  so that our textures are recreated properly on switching
  in-game resolution etc.
  • Loading branch information
luk1337 committed Apr 29, 2019
1 parent c03ea92 commit 2380b7e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions csgo/hooking/hooks/ResetEx.cpp
@@ -0,0 +1,11 @@
#include "../../inc.h"

HRESULT __stdcall hook::ResetEx( IDirect3DDevice9Ex *device, D3DPRESENT_PARAMETERS *pPresentationParameters, D3DDISPLAYMODEEX *pFullscreenDisplayMode ) {
g_renderer.get_renderer( ).PreD3DReset( );

const long ret = g_hooks.m_directx.get_old_method< fn::ResetEx_t >( hook::idx::RESETEX )( device, pPresentationParameters, pFullscreenDisplayMode);

g_renderer.get_renderer( ).PostD3DReset( );

return ret;
}
5 changes: 5 additions & 0 deletions csgo/hooking/manager.cpp
Expand Up @@ -67,6 +67,11 @@ bool c_hooks::hook( ) {
return false;
}

if (!m_directx.hook_method(hook::idx::RESETEX, &hook::ResetEx)) {
_RPTF0(_CRT_ERROR, "Failed to hook ResetEx. This is fatal.");
return false;
}

if( !m_directx.hook_method( hook::idx::END_SCENE, &hook::EndScene ) ) {
_RPTF0( _CRT_ERROR, "Failed to hook EndScene. This is fatal." );
return false;
Expand Down
3 changes: 3 additions & 0 deletions csgo/hooking/manager.h
Expand Up @@ -7,6 +7,7 @@ namespace hook {
namespace fn {
using Present_t = HRESULT (__stdcall *)( IDirect3DDevice9Ex *, const RECT *, const RECT *, HWND, const RGNDATA * );
using Reset_t = HRESULT (__stdcall *)( IDirect3DDevice9Ex *, D3DPRESENT_PARAMETERS * );
using ResetEx_t = HRESULT(__stdcall *)( IDirect3DDevice9Ex *, D3DPRESENT_PARAMETERS *, D3DDISPLAYMODEEX * );
using EndScene_t = HRESULT (__stdcall *)( IDirect3DDevice9Ex * );
using PaintTraverse_t = void (__thiscall *)( uintptr_t, int, bool, bool );
using LevelInitPostEntity_t = void (__thiscall *)( uintptr_t );
Expand Down Expand Up @@ -37,6 +38,7 @@ namespace hook {
RESET = 16,
PRESENT = 17,
END_SCENE = 42,
RESETEX = 132,

// clientmode
SHOULD_DRAW_FOG = 17,
Expand Down Expand Up @@ -84,6 +86,7 @@ namespace hook {
HRESULT __stdcall Present( IDirect3DDevice9Ex *device, const RECT *pSourceRect, const RECT *pDestRect,
HWND hDestWindowOverride, const RGNDATA *pDirtyRegion );
HRESULT __stdcall Reset( IDirect3DDevice9Ex *device, D3DPRESENT_PARAMETERS *pPresentationParameters );
HRESULT __stdcall ResetEx(IDirect3DDevice9Ex *device, D3DPRESENT_PARAMETERS *pPresentationParameters, D3DDISPLAYMODEEX *pFullscreenDisplayMode );
HRESULT __stdcall EndScene( IDirect3DDevice9Ex *device );
void __stdcall LockCursor( );
void __fastcall PaintTraverse( uintptr_t ecx, uintptr_t edx, int vguiPanel, bool forceRepaint, bool allowForce );
Expand Down
1 change: 1 addition & 0 deletions dc-csgo.vcxproj
Expand Up @@ -56,6 +56,7 @@
<ClCompile Include="csgo\hooking\hooks\Present.cpp" />
<ClCompile Include="csgo\hooking\hooks\RenderSmokeOverlay.cpp" />
<ClCompile Include="csgo\hooking\hooks\Reset.cpp" />
<ClCompile Include="csgo\hooking\hooks\ResetEx.cpp" />
<ClCompile Include="csgo\hooking\hooks\SceneEnd.cpp" />
<ClCompile Include="csgo\hooking\hooks\SetupBones.cpp" />
<ClCompile Include="csgo\hooking\hooks\ShouldDrawFog.cpp" />
Expand Down
3 changes: 3 additions & 0 deletions dc-csgo.vcxproj.filters
Expand Up @@ -226,6 +226,9 @@
<ClCompile Include="csgo\features\chaiscript\chai_wrapper.cpp">
<Filter>dc-csgo</Filter>
</ClCompile>
<ClCompile Include="csgo\hooking\hooks\ResetEx.cpp">
<Filter>dc-csgo\hooking\hooks</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="csgo\sdk\custom classes\animstate.h">
Expand Down

0 comments on commit 2380b7e

Please sign in to comment.