Skip to content

Commit

Permalink
Hook d3d device's reset method and reset imgui when the user changes …
Browse files Browse the repository at this point in the history
…graphic settings
  • Loading branch information
Ochii committed Feb 19, 2019
1 parent a9cf49a commit 68af3df
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
2 changes: 2 additions & 0 deletions launcher/header/console.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class GameConsole

int ConsoleInputCallBack( ImGuiInputTextCallbackData* data );

void OnPreReset();
void OnPostReset();
void OnEndScene();

bool OnWindowCallback( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
Expand Down
16 changes: 16 additions & 0 deletions launcher/source/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,22 @@ int GameConsole::ConsoleInputCallBack( ImGuiInputTextCallbackData* data )
return 0;
}

//
// reset imgui when changing graphics settings
//
void GameConsole::OnPreReset()
{
ImGui_ImplDX9_InvalidateDeviceObjects();
}

//
// once the new graphics settings are applied, setup imgui again
//
void GameConsole::OnPostReset()
{
ImGui_ImplDX9_CreateDeviceObjects();
}

// this is called by the game's d3d device's endscene
// draws our own console
void GameConsole::OnEndScene()
Expand Down
15 changes: 13 additions & 2 deletions launcher/source/hooks/shaderapidx9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,20 @@ LPDIRECT3DDEVICE9 GetD3dDevice( const uintptr_t base )
static std::unique_ptr<PLH::VTableSwapHook> g_pDeviceHook;
static PLH::VFuncMap g_DeviceOrig;

NOINLINE HRESULT WINAPI hkEndScene( LPDIRECT3DDEVICE9 pDevice )
NOINLINE HRESULT WINAPI hkReset(
LPDIRECT3DDEVICE9 thisptr, D3DPRESENT_PARAMETERS* pPresentationParameters )
{
g_GameConsole.OnPreReset();
const HRESULT result = PLH::FnCast( g_DeviceOrig.at( 16 ), &hkReset )(
thisptr, pPresentationParameters );
g_GameConsole.OnPostReset();
return result;
}

NOINLINE HRESULT WINAPI hkEndScene( LPDIRECT3DDEVICE9 thisptr )
{
g_GameConsole.OnEndScene();
return PLH::FnCast( g_DeviceOrig.at( 42 ), &hkEndScene )( pDevice );
return PLH::FnCast( g_DeviceOrig.at( 42 ), &hkEndScene )( thisptr );
}

static std::unique_ptr<PLH::x86Detour> g_pCreateDeviceHook;
Expand All @@ -42,6 +52,7 @@ NOINLINE bool __fastcall hkCreateD3DDevice(
// hook the game's d3d device endscene (its virtual function table index
// is 42)
static const PLH::VFuncMap deviceRedirects = {
{ uint16_t( 16 ), reinterpret_cast<uint64_t>( &hkReset ) },
{ uint16_t( 42 ), reinterpret_cast<uint64_t>( &hkEndScene ) }
};
g_pDeviceHook = SetupVtableSwap( pDevice, deviceRedirects );
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.1
0.3.2

0 comments on commit 68af3df

Please sign in to comment.