Skip to content

Commit

Permalink
Added d3d debug info
Browse files Browse the repository at this point in the history
  • Loading branch information
DeadlySurprise authored and DeadlySurprise committed Dec 10, 2017
1 parent 7c43621 commit 012ba6b
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 3 deletions.
10 changes: 10 additions & 0 deletions FlatOut2/CDirect3D9DevHook.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
#include "stdafx.h"
#include "CDirect3D9DevHook.h"

CDirect3D9DevHook::CDirect3D9DevHook(IDirect3DDevice9 * ptr)
{
if (ptr == NULL) {
MessageBox(NULL, L"Error in CDirect3D9DevHook::CDirect3D9DevHook. DirectX object pointer was null!", L"DirectX Error", MB_OK | MB_ICONERROR);
throw std::exception("Error in CDirect3D9DevHook::CDirect3D9DevHook. DirectX object pointer was null!");
}

m_ptr = ptr;
}

HRESULT CDirect3D9DevHook::EndScene()
{
return m_ptr->EndScene();
Expand Down
2 changes: 1 addition & 1 deletion FlatOut2/CDirect3D9DevHook.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class CDirect3D9DevHook : public IDirect3DDevice9
private:
IDirect3DDevice9* m_ptr;
public:
CDirect3D9DevHook(IDirect3DDevice9* ptr) : m_ptr(ptr) {}
CDirect3D9DevHook(IDirect3DDevice9* ptr);
public:
HRESULT _stdcall EndScene();
#pragma region stubs
Expand Down
60 changes: 60 additions & 0 deletions FlatOut2/CDirect3D9Hook.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,70 @@
#include "stdafx.h"
#include "CDirect3D9Hook.h"

CDirect3D9Hook::CDirect3D9Hook(IDirect3D9 * ptr)
{
if (ptr == NULL) {
MessageBox(NULL, L"Error in CDirect3D9Hook::CDirect3D9Hook. DirectX object pointer was null!", L"DirectX Error", MB_OK | MB_ICONERROR);
throw std::exception("Error in CDirect3D9Hook::CDirect3D9Hook. DirectX object pointer was null!");
}

m_ptr = ptr;
}

BOOL WriteErrorLog(const char* filename, HRESULT hr, UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS * pPresentationParameters, IDirect3DDevice9 ** ppReturnedDeviceInterface)
{
std::ofstream errorLog = std::ofstream(filename, std::ofstream::out | std::ofstream::app);
errorLog
<< "Error log CDirect3D9Hook::CreateDevice." << std::endl
<< "HRESULT : " << hr << std::endl
<< "Adapter : " << Adapter << std::endl
<< "DeviceType : " << DeviceType << std::endl
<< "hFocusWindow : " << hFocusWindow << std::endl
<< "BehaviorFlags : " << BehaviorFlags << std::endl
<< "pPresentationParameters : " << pPresentationParameters << std::endl
<< "ppReturnedDeviceInterface : " << ppReturnedDeviceInterface << std::endl
<< "Presentation Parameters : " << std::endl
<< "\tBackBufferWidth : " << pPresentationParameters->BackBufferWidth << std::endl
<< "\tBackBufferHeight : " << pPresentationParameters->BackBufferHeight << std::endl
<< "\tBackBufferFormat : " << pPresentationParameters->BackBufferFormat << std::endl
<< "\tBackBufferCount : " << pPresentationParameters->BackBufferCount << std::endl
<< "\tMultiSampleType : " << pPresentationParameters->MultiSampleType << std::endl
<< "\tMultiSampleQuality : " << pPresentationParameters->MultiSampleQuality << std::endl
<< "\tSwapEffect : " << pPresentationParameters->SwapEffect << std::endl
<< "\thDeviceWindow : " << pPresentationParameters->hDeviceWindow << std::endl
<< "\tWindowed : " << pPresentationParameters->Windowed << std::endl
<< "\tEnableAutoDepthStencil : " << pPresentationParameters->EnableAutoDepthStencil << std::endl
<< "\tAutoDepthStencilFormat : " << pPresentationParameters->AutoDepthStencilFormat << std::endl
<< "\tFlags : " << pPresentationParameters->Flags << std::endl
<< "\tFullScreen_RefreshRateInHz : " << pPresentationParameters->FullScreen_RefreshRateInHz << std::endl;
bool good = errorLog.good();
errorLog.close();
return good;
}

HRESULT CDirect3D9Hook::CreateDevice(UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS * pPresentationParameters, IDirect3DDevice9 ** ppReturnedDeviceInterface)
{
pPresentationParameters->Windowed = true;
HRESULT hr = m_ptr->CreateDevice(Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, ppReturnedDeviceInterface);
if (hr != D3D_OK)
{
WCHAR errMsg[DEFAULT_ERRMSG_BUFFER];
const WCHAR* error =
(hr == D3DERR_DEVICELOST ? L"D3DERR_DEVICELOST" :
hr == D3DERR_INVALIDCALL ? L"D3DERR_INVALIDCALL" :
hr == D3DERR_NOTAVAILABLE ? L"D3DERR_NOTAVAILABLE" :
hr == D3DERR_OUTOFVIDEOMEMORY ? L"D3DERR_OUTOFVIDEOMEMORY" : L"D3DERR_UNKNOWN");
if (WriteErrorLog("d3derror.txt", hr, Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, ppReturnedDeviceInterface))
{
StringCbPrintf(errMsg, sizeof(errMsg), L"Failed to create DirectX9 Device : %s(%d). Additional info was written to d3derror.txt.", error, hr);
}
else
{
StringCbPrintf(errMsg, sizeof(errMsg), L"Failed to create DirectX9 Device : %s(%d). Additional info could NOT be written to disk.", error, hr);
}
MessageBox(NULL, errMsg, L"DirectX Error", MB_OK | MB_ICONERROR);
throw new std::exception("Failed to create DirectX9 Device.");
}
m_pdev = new CDirect3D9DevHook(*ppReturnedDeviceInterface);
*ppReturnedDeviceInterface = m_pdev;
return hr;
Expand Down
3 changes: 1 addition & 2 deletions FlatOut2/CDirect3D9Hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ class CDirect3D9Hook : public IDirect3D9
IDirect3D9* m_ptr;
CDirect3D9DevHook* m_pdev;
public:
CDirect3D9Hook(IDirect3D9* ptr) : m_ptr(ptr) {}
CDirect3D9Hook(IDirect3D9* ptr);
public:
void _stdcall SetDebugText(LPWSTR text);
HRESULT _stdcall CreateDevice(UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DDevice9** ppReturnedDeviceInterface);

/*** IUnknown methods ***/
Expand Down
7 changes: 7 additions & 0 deletions FlatOut2/DXDetours.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ CDirect3D9Hook* d3d;
IDirect3D9* WINAPI myCreateDx9(UINT sdkVer)
{
IDirect3D9* idx = ((dxCreate)oDX9Create)(sdkVer);
if (idx == NULL)
{
WCHAR errMsg[DEFAULT_ERRMSG_BUFFER];
StringCbPrintf(errMsg, sizeof(errMsg), L"Failed to create DirectX9 object. SDK Version : %d", sdkVer);
MessageBox(NULL, errMsg, L"DirectX Error", MB_OK | MB_ICONERROR);
throw std::exception("Failed to create DirectX9 object.");
}
d3d = new CDirect3D9Hook(idx);
IDirect3D9* proxy = static_cast<IDirect3D9*>(d3d);
InstanceSettings::GetSettings()->SetDirect3DHook(d3d);
Expand Down
1 change: 1 addition & 0 deletions FlatOut2/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#pragma once
#include "targetver.h"
#define DIRECTINPUT_VERSION 0x0800
#define DEFAULT_ERRMSG_BUFFER 4096
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
// Windows Header Files:
#include <windows.h>
Expand Down

0 comments on commit 012ba6b

Please sign in to comment.