Skip to content

Commit

Permalink
Don't use D3D device when it's null
Browse files Browse the repository at this point in the history
  • Loading branch information
TheIndra55 committed Dec 15, 2021
1 parent aa12c0f commit 8f07519
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions Hooking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,19 @@ char __fastcall PCDeviceManager__CreateDevice(DWORD* _this, DWORD _, DWORD a2)
{
auto val = original__PCDeviceManager__CreateDevice(_this, a2);

if (!val)
{
return val;
}

#if TRAE
auto address = *reinterpret_cast<DWORD*>(0xA6669C);
#elif TR8
auto address = *reinterpret_cast<DWORD*>(0xAD75E4);
#elif TR7
auto address = *reinterpret_cast<DWORD*>(0x139C758);
#endif
auto device = *reinterpret_cast<DWORD*>(address + 0x20);
pDevice = reinterpret_cast<IDirect3DDevice9*>(device);
pDevice = *reinterpret_cast<IDirect3DDevice9**>(address + 0x20);

Hooking::GetInstance().GetMenu()->SetDevice(pDevice);

Expand Down Expand Up @@ -104,6 +108,8 @@ void __fastcall PCDeviceManager__ReleaseDevice(DWORD* _this, DWORD _, int status
{
Hooking::GetInstance().GetMenu()->OnDeviceReleased();
ImGui_ImplDX9_InvalidateDeviceObjects();

pDevice = nullptr;

orginal_PCDeviceManager__ReleaseDevice(_this, status);
}
Expand Down Expand Up @@ -712,7 +718,10 @@ int hooked_Direct3DInit()
#if TRAE || TR7
void __fastcall hooked_PCRenderContext_Present(DWORD* _this, void* _, int a2, int a3, int a4)
{
Hooking::GetInstance().GetMenu()->OnPresent();
if (pDevice)
{
Hooking::GetInstance().GetMenu()->OnPresent();
}

// call orginal game present function to draw on the screen
original_PCRenderContext_Present(_this, a2, a3, a4);
Expand Down

0 comments on commit 8f07519

Please sign in to comment.