diff --git a/authors.txt b/authors.txt index fa9bd51..7338bc1 100644 --- a/authors.txt +++ b/authors.txt @@ -1 +1,2 @@ -Hendrik Polczynski \ No newline at end of file +Hendrik Polczynski +Nick - Coherent Labs (http://coherent-labs.com/) diff --git a/changelog.md b/changelog.md index f95c932..8d75356 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,16 @@ +Plugin_D3D 2.0.0 (18.11.2013) +============== +Stable Release for CryEngine 3.5.4 (32/64 bit), DX11, DX10, DX10.1 +Backward compatible with CryEngine 3.4.5 (32/64 bit), DX9 and DX11 (when recompiled) + +New: +* Added DirectX 10 Support +* Added Support for Featurelevels 10.0 and 10.1 +* Flownode to query DirectX and plugin status information + +Changes: +* Reactivated automatic DirectX Scan since EF_Query is missing again + Plugin_D3D 1.9.0 (02.03.2013) ============== Stable Release for CryEngine 3.4.5 (32/64 bit), DX9/DX11 diff --git a/inc/IPluginD3D.h b/inc/IPluginD3D.h index 1d932bd..a48caa6 100644 --- a/inc/IPluginD3D.h +++ b/inc/IPluginD3D.h @@ -14,6 +14,7 @@ namespace D3DPlugin D3D_NONE, D3D_DX9, D3D_DX11, + D3D_DX10, }; struct ID3DEventListener @@ -39,12 +40,15 @@ namespace D3DPlugin virtual void RegisterListener( ID3DEventListener* item ) = 0; virtual void UnregisterListener( ID3DEventListener* item ) = 0; - virtual void* GetSwapChain() = 0; // DX11 only - virtual void* GetDeviceContext() = 0; // DX11 only + virtual void* GetSwapChain() = 0; // >= DX10 only + virtual void* GetDeviceContext() = 0; // >= DX11 only virtual void* GetDevice() = 0; + virtual int GetFeatureLevel() = 0; virtual eD3DType GetType() = 0; + virtual const char* GetGPUName() = 0; // >= DX10 only + virtual ITexture* CreateTexture( void** pD3DTextureDst, int width, int height, int numMips, ETEX_Format eTF, int flags ) = 0; virtual ITexture* InjectTexture( void* pD3DTextureSrc, int nWidth, int nHeight, ETEX_Format eTF, int flags ) = 0; }; diff --git a/project/D3D.vcxproj b/project/D3D.vcxproj index 018583f..14b7c7f 100644 --- a/project/D3D.vcxproj +++ b/project/D3D.vcxproj @@ -33,8 +33,10 @@ + + Create Create @@ -44,12 +46,16 @@ - + + + + + diff --git a/project/D3D.vcxproj.filters b/project/D3D.vcxproj.filters index 4ef68b8..1809ae3 100644 --- a/project/D3D.vcxproj.filters +++ b/project/D3D.vcxproj.filters @@ -34,6 +34,15 @@ {c070122a-9e71-4ec8-bc5a-259b65125c77} + + {5a739495-a3b3-4850-8c38-8fd3cfadc499} + + + {34af623a-d47b-45e1-8ab9-6793ac61e5c1} + + + {a3fe528e-4827-4e17-b58f-c16326abce24} + @@ -73,6 +82,12 @@ Systems\DX11 + + Systems\DX10 + + + Flownodes + @@ -105,7 +120,19 @@ utils - + + Systems\DX10 + + + Systems\DX10 + + + Systems\DXGI + + + Systems\DXGI + + Samples diff --git a/project/version.rc b/project/version.rc index 332164b..dfd9e5c 100644 --- a/project/version.rc +++ b/project/version.rc @@ -30,8 +30,8 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL // VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,9,0,0 - PRODUCTVERSION 1,9,0,0 + FILEVERSION 2,0,0,0 + PRODUCTVERSION 2,0,0,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -48,11 +48,11 @@ BEGIN BEGIN VALUE "CompanyName", "D3D Plugin Project" VALUE "FileDescription", "D3D Plugin" - VALUE "FileVersion", "1.9.0.0" + VALUE "FileVersion", "2.0.0.0" VALUE "LegalCopyright", "Plugin_D3D Copyright (c) 2013, The D3D Plugin projects authors, All Rights reserved." VALUE "OriginalFilename", "Plugin_D3D.dll" VALUE "ProductName", "D3D Plugin for CryEngine SDK" - VALUE "ProductVersion", "1.9.0.0" + VALUE "ProductVersion", "2.0.0.0" END END BLOCK "VarFileInfo" diff --git a/readme.md b/readme.md index de25286..65a395b 100644 --- a/readme.md +++ b/readme.md @@ -56,6 +56,15 @@ Using a Plugin from a Plugin (Dependency) ----------------------------------------- * See [Plugin SDK Wiki: Plugin Dependencies](https://github.com/hendrikp/Plugin_SDK/wiki/Plugin-Dependencies) +Flownodes +========= +* ```D3D_Plugin:Info``` Retrieve Direct3D Informations + * In ```Get``` Retrieve the infos + * Out ```Hooked``` Is true when the Direct3D Plugin is working correctly + * Out ```Renderer``` CryEngine Render Subsystem in use (DX9, DX11) + * Out ```Featurelevel``` The FeatureLevel in use (9.3, 10.0, 10.1, 11.0) + * Out ```GPU``` The name of the GPU in use + Samples ======= @@ -95,4 +104,4 @@ base by simply adding it to your project and creating an instance. This event li This sample will make your rendering window green, but you are free to do something more meaningfull ;) -* [Sample File](sample/D3DPlugin_Sample_impl.h) (include into a cpp file of your choice or paste it there) +* [Sample File DX9](sample/D3DPlugin_Sample_DX9_impl.h) (include into a cpp file of your choice or paste it there) diff --git a/sample/D3DPlugin_Sample_impl.h b/sample/D3DPlugin_Sample_DX9_impl.h similarity index 95% rename from sample/D3DPlugin_Sample_impl.h rename to sample/D3DPlugin_Sample_DX9_impl.h index 3ba253d..257da3e 100644 --- a/sample/D3DPlugin_Sample_impl.h +++ b/sample/D3DPlugin_Sample_DX9_impl.h @@ -4,9 +4,6 @@ #include #include #include -#include -#include -#include class CMyD3D : private D3DPlugin::ID3DEventListener @@ -18,7 +15,6 @@ class CMyD3D { void* ptr; IDirect3DDevice9* dx9; - //ID3D11Device* dx11; } m_pDevice; PluginManager::IPluginBase* m_pD3DPlugin; diff --git a/src/CPluginD3D.cpp b/src/CPluginD3D.cpp index cb0fe84..6fc0062 100644 --- a/src/CPluginD3D.cpp +++ b/src/CPluginD3D.cpp @@ -4,6 +4,7 @@ #include #include "dx9/CD3DSystemDX9.h" +#include "dx10/CD3DSystemDX10.h" #include "dx11/CD3DSystemDX11.h" namespace D3DPlugin @@ -61,6 +62,12 @@ namespace D3DPlugin m_pDXSystem = new CD3DSystem11(); } + // This isnt used by CE3 instead it uses a DX11 device with reduced feature level + else if ( GetModuleHandle( "d3d10.dll" ) && gEnv->pRenderer->GetRenderType() != eRT_DX9 ) + { + m_pDXSystem = new CD3DSystem10(); + } + else if ( GetModuleHandle( "d3d9.dll" ) && gEnv->pRenderer->GetRenderType() == eRT_DX9 ) { m_pDXSystem = new CD3DSystem9(); diff --git a/src/CPluginD3D.h b/src/CPluginD3D.h index e8bd3b8..62bbe97 100644 --- a/src/CPluginD3D.h +++ b/src/CPluginD3D.h @@ -2,10 +2,10 @@ #pragma once +#include #include #include -#include #include #include @@ -64,7 +64,7 @@ namespace D3DPlugin * @brief Small helper to clean up the correct system type (but outside the main interface) */ struct IPluginD3DEx : - public IPluginD3D + public IPluginD3D { public: /** @@ -98,7 +98,7 @@ namespace D3DPlugin const char* GetVersion() const { - return "1.9.0.0"; + return "2.0.0.0"; }; const char* GetName() const @@ -125,7 +125,7 @@ namespace D3DPlugin void* GetConcreteInterface( const char* sInterfaceVersion ) { - return static_cast < IPluginD3D* > ( m_pDXSystem ); + return static_cast ( m_pDXSystem ); }; PluginManager::IPluginBase* GetBase() diff --git a/src/Flownodes/CFlowD3DNode.cpp b/src/Flownodes/CFlowD3DNode.cpp new file mode 100644 index 0000000..6af2f93 --- /dev/null +++ b/src/Flownodes/CFlowD3DNode.cpp @@ -0,0 +1,140 @@ +/* D3D_Plugin - for licensing and copyright see license.txt */ + +#include + +#include +#include +#include + +#include + +namespace D3DPlugin +{ + class CFlowD3DNode : + public CFlowBaseNode + { + enum EInputPorts + { + EIP_GET = 0, + }; + + enum EOutputPorts + { + EOP_HOOKED = 0, + EOP_RENDERER, + EOP_FEATURELEVEL, + EOP_GPU, + }; + + public: + virtual void GetMemoryUsage( ICrySizer* s ) const + { + s->Add( *this ); + } + + CFlowD3DNode( SActivationInfo* pActInfo ) + { + + } + + virtual void GetConfiguration( SFlowNodeConfig& config ) + { + static const SInputPortConfig inputs[] = + { + InputPortConfig_Void( "Get", _HELP( "Get" ) ), + InputPortConfig_Null(), + }; + + static const SOutputPortConfig outputs[] = + { + OutputPortConfig( "Hooked", _HELP( "D3D was hooked and D3D plugin is fully functional" ) ), + OutputPortConfig( "Renderer", _HELP( "CryEngine Renderer in use" ) ), + OutputPortConfig( "FeatureLevel", _HELP( "FeatureLevel in use" ) ), + OutputPortConfig( "GPU", _HELP( "GPU that is in use" ) ), + OutputPortConfig_Null(), + }; + + config.pInputPorts = inputs; + config.pOutputPorts = outputs; + config.sDescription = _HELP( " D3D Info" ); + + config.SetCategory( EFLN_APPROVED ); + } + + virtual void ProcessEvent( EFlowEvent evt, SActivationInfo* pActInfo ) + { + switch ( evt ) + { + case eFE_Activate: + + if ( IsPortActive( pActInfo, EIP_GET ) ) + { + // This plug in is a bit special since the concrete interface is inside of the dx subsystem instead of the gPlugin pointer + IPluginD3D* pD3DPlugin = PluginManager::safeGetPluginConcreteInterface( PLUGIN_NAME ); + + string sRenderer = "N/A"; + string sFeatureLevel = "N/A"; + string sGPUName = "N/A"; + bool bHooked = false; + + if ( pD3DPlugin ) + { + bHooked = pD3DPlugin->GetDevice(); + sGPUName = pD3DPlugin->GetGPUName(); + + switch ( pD3DPlugin->GetType() ) + { + case D3D_DX9: + sRenderer = "DX9"; + break; + + case D3D_DX10: + sRenderer = "DX10"; + break; + + case D3D_DX11: + sRenderer = "DX11"; + break; + } + + switch ( pD3DPlugin->GetFeatureLevel() ) + { + case D3D_FEATURE_LEVEL_9_1: + sFeatureLevel = "9.1"; + break; + + case D3D_FEATURE_LEVEL_9_2: + sFeatureLevel = "9.2"; + break; + + case D3D_FEATURE_LEVEL_9_3: + sFeatureLevel = "9.3"; + break; + + case D3D_FEATURE_LEVEL_10_0: + sFeatureLevel = "10.0"; + break; + + case D3D_FEATURE_LEVEL_10_1: + sFeatureLevel = "10.1"; + break; + + case D3D_FEATURE_LEVEL_11_0: + sFeatureLevel = "11.0"; + break; + } + } + + ActivateOutput( pActInfo, EOP_HOOKED, bHooked ); + ActivateOutput( pActInfo, EOP_RENDERER, sRenderer ); + ActivateOutput( pActInfo, EOP_FEATURELEVEL, sFeatureLevel ); + ActivateOutput( pActInfo, EOP_GPU, sGPUName ); + } + + break; + } + } + }; +} + +REGISTER_FLOW_NODE_EX( "D3D_Plugin:Info", D3DPlugin::CFlowD3DNode, CFlowD3DNode ); diff --git a/src/StdAfx.h b/src/StdAfx.h index 6002d56..6ea5b71 100644 --- a/src/StdAfx.h +++ b/src/StdAfx.h @@ -2,12 +2,6 @@ #pragma once -#if defined(XENON) || defined(PS3) -#define MAX_PLAYER_LIMIT 12 -#else -#define MAX_PLAYER_LIMIT 16 -#endif - // Insert your headers here #include #include diff --git a/src/dx10/CD3DSystemDX10.cpp b/src/dx10/CD3DSystemDX10.cpp new file mode 100644 index 0000000..c5c4ec1 --- /dev/null +++ b/src/dx10/CD3DSystemDX10.cpp @@ -0,0 +1,441 @@ +/* D3D_Plugin - for licensing and copyright see license.txt */ + +#include +#include "CD3DSystemDX10.h" +#include "d3d10hook.h" +#include "../dxgi/dxgihook.h" +#include "../dxgi/dxgiutils.hpp" + +#include + +//#pragma comment(lib, "dxerr.lib") // not needed atm + +D3DPlugin::CD3DSystem10* D3DPlugin::gD3DSystem10 = NULL; + +namespace dxgi_unique1 // need to make it unique since dx11 is using dxgi too +{ +#undef METHOD +#undef INTERFACE + +#define INTERFACE IDXGISwapChain + +#define METHOD Present + GEN_HOOK( UINT SyncInterval, UINT Flags ) + { + if ( !D3DPlugin::gD3DSystem10->m_pSwapChain && D3DPlugin::gD3DSystem10->m_pDevice ) + { + ID3D10Device* pSwapChainDevice = NULL; + HRESULT hrg = This->GetDevice( __uuidof( ID3D10Device ), ( void** )&pSwapChainDevice ); + + if ( pSwapChainDevice == D3DPlugin::gD3DSystem10->m_pDevice ) + { + D3DPlugin::gD3DSystem10->m_pSwapChain = This; + + D3DPlugin::gPlugin->LogAlways( "DXGI swap chain retrieved" ); + } + } + + bool bEngineSwapChain = D3DPlugin::gD3DSystem10->m_pSwapChain == This; + + if ( bEngineSwapChain ) + { + D3DPlugin::gD3DSystem10->OnPrePresent(); + } + + CALL_ORGINAL( SyncInterval, Flags ); + + if ( bEngineSwapChain ) + { + D3DPlugin::gD3DSystem10->OnPostPresent(); + D3DPlugin::gD3DSystem10->OnPostBeginScene(); // doesn't exist in dx10, but keep for compatibility + } + + rehookVT( This, IDXGISwapChain, Present ); + + return hr; + } +#undef METHOD +} + +using namespace dxgi_unique1; + +#undef INTERFACE +#define INTERFACE ID3D10Device + +#define METHOD CreateTexture2D +GEN_HOOK( __in const D3D10_TEXTURE2D_DESC* pDesc, __in_xcount_opt( pDesc->MipLevels * pDesc->ArraySize ) const D3D10_SUBRESOURCE_DATA* pInitialData, __out ID3D10Texture2D** ppTexture2D ) +{ + if ( D3DPlugin::gD3DSystem10->m_nTextureMode == HTM_INJECT ) + { + goto INJECTTEXTURE; + } + + CALL_ORGINAL( pDesc, pInitialData, ppTexture2D ); + + if ( SUCCEEDED( hr ) ) + { + switch ( D3DPlugin::gD3DSystem10->m_nTextureMode ) + { + case HTM_INJECT: +INJECTTEXTURE: + if ( pDesc && pDesc->ArraySize == 1 && ppTexture2D ) + { + ppTexture2D[0] = ( ID3D10Texture2D* )( D3DPlugin::gD3DSystem10->m_pTempTex ); + ppTexture2D[0]->AddRef(); + } + + hr = S_OK; + break; + + case HTM_CREATE: + D3DPlugin::gD3DSystem10->m_pTempTex = NULL; + + if ( pDesc && pDesc->ArraySize == 1 && ppTexture2D ) + { + D3DPlugin::gD3DSystem10->m_pTempTex = ( void* )( ppTexture2D[0] ); + } + + break; + } + + D3DPlugin::gD3DSystem10->m_nTextureMode = HTM_NONE; + } + + return hr; +} +#undef METHOD +#undef INTERFACE + +bool GetD3D10DeviceData( INT_PTR* unkdata, int nDatalen, void* pParam ) +{ + bool bRet = false; + HWND hWndDummy = CreateWindowEx( NULL, TEXT( "Message" ), TEXT( "DummyWindow" ), WS_MINIMIZE, 0, 0, 8, 8, HWND_MESSAGE, NULL, 0, NULL ); + + HMODULE hModule = NULL; + hModule = GetModuleHandle( "d3d10.dll" ); + + typedef HRESULT( WINAPI * fD3D10CreateDeviceAndSwapChain )( + _In_ IDXGIAdapter * pAdapter, + _In_ D3D10_DRIVER_TYPE DriverType, + _In_ HMODULE Software, + _In_ UINT Flags, + _In_ UINT SDKVersion, + _In_ DXGI_SWAP_CHAIN_DESC * pSwapChainDesc, + _Out_ IDXGISwapChain** ppSwapChain, + _Out_ ID3D10Device** ppDevice + ); + + fD3D10CreateDeviceAndSwapChain D3D10CreateDeviceAndSwapChain = ( fD3D10CreateDeviceAndSwapChain )GetProcAddress( hModule, "D3D10CreateDeviceAndSwapChain" ); + + IDXGISwapChain* pSwapChain = NULL; + ID3D10Device* pDevice = NULL; + + // dummy swap chain description struct + DXGI_SWAP_CHAIN_DESC sSwapChainDesc; + ZeroMemory( &sSwapChainDesc, sizeof( DXGI_SWAP_CHAIN_DESC ) ); + sSwapChainDesc.Windowed = TRUE; + sSwapChainDesc.OutputWindow = hWndDummy; + sSwapChainDesc.BufferCount = 1; + sSwapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + sSwapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; + sSwapChainDesc.SampleDesc.Count = 1; + + // create a device, device context and swap chain using the information in the scd struct + HRESULT hr = D3D10CreateDeviceAndSwapChain( + NULL, + D3D10_DRIVER_TYPE_HARDWARE, + NULL, + 0, + D3D10_SDK_VERSION, + &sSwapChainDesc, + &pSwapChain, + &pDevice ); + + if ( SUCCEEDED( hr ) ) + { + bRet = true; + + if ( pParam && *( ( bool* )pParam ) ) + { + hookVT( pSwapChain, IDXGISwapChain, Present ); + } + } + + if ( bRet && unkdata ) + { + void** vt = getVT( pDevice ); + + if ( vt ) + { + memcpy( unkdata, vt, nDatalen ); + } + + else + { + bRet = false; + } + } + + SAFE_RELEASE( pSwapChain ); + SAFE_RELEASE( pDevice ); + + DestroyWindow( hWndDummy ); + + return bRet; +} + +bool BootstrapD3D10SwapChainHook() +{ + bool bHook = true; + return GetD3D10DeviceData( NULL, 0, &bHook ); +} + +namespace D3DPlugin +{ + namespace dxgi_unique1 // need to make it unique since dx11 is using dxgi too + { + IDXGISwapChain* FindDXGISwapChain( INT_PTR nRelativeBase ) + { + INT_PTR nModuleOffset = ( INT_PTR )GetModuleHandle( TEXT( "dxgi.dll" ) ); + + if ( !nModuleOffset ) + { + gPlugin->LogWarning( "DX10/DXGI not active" ); + return NULL; + } + + // atm search is not needed since we receive swap chain through present + return NULL; + } + } + using namespace dxgi_unique1; + + ID3D10Device* FindD3D10Device( INT_PTR nRelativeBase, void* pTrialDevice ) + { + INT_PTR nModuleOffset = ( INT_PTR )GetModuleHandle( TEXT( "d3d10.dll" ) ); + + if ( !nModuleOffset ) + { + gPlugin->LogWarning( "DX10 not active" ); + return NULL; + } + + if ( pTrialDevice ) + { + return ( ID3D10Device* )pTrialDevice; + } + + // Set Defaults +#ifdef _WIN64 + static INT_PTR dxoffset = 0xF60; // placeholder +#else + static INT_PTR dxoffset = 0xF54; // placeholder +#endif + + static DWORD dxoffsetlen = sizeof( dxoffset ); + + static INT_PTR dxdata[3]; + static DWORD dxdatalen = sizeof( dxdata ); + + static bool bFirstCall = true; + +#ifdef _WIN64 + static LPCTSTR sSubKeyData = D3D_DATA SEP D3D_TARGETX64 SEP D3D_TARGETDX10; + static LPCTSTR sSubKeyOffset = D3D_OFFSET SEP D3D_TARGETX64 SEP D3D_TARGETDX10; + + if ( bFirstCall ) + { + dxdata[0] = 0x0000000000011AB8; // placeholder + dxdata[1] = 0x0000000000009738; + dxdata[2] = 0x0000000000009728; + } + +#else + static LPCTSTR sSubKeyData = D3D_DATA SEP D3D_TARGETX86 SEP D3D_TARGETDX10; + static LPCTSTR sSubKeyOffset = D3D_OFFSET SEP D3D_TARGETX86 SEP D3D_TARGETDX10; + + if ( bFirstCall ) + { + dxdata[0] = 0x0001230B; // placeholder + dxdata[1] = 0x000099B0; + dxdata[2] = 0x000099A1; + } + +#endif + bFirstCall = false; + + void* pInterfaceClass = ( void* )( nRelativeBase + dxoffset ); + int nFunctioncount = 98; //dx10 + + ID3D10Device* pRet = NULL; + + // Calculate Offsets of IUnknown Interface VTable + dxdata[0] += nModuleOffset; + dxdata[1] += nModuleOffset; + dxdata[2] += nModuleOffset; + + // Check EF_Query/Trial (should always be correct unless CDK decides its private again or faulty) + if ( pTrialDevice ) + { + if ( CheckForInterface( &pTrialDevice, dxdata, dxdatalen, __uuidof( ID3D10Device ), nFunctioncount ) ) + { + pRet = static_cast( pTrialDevice ); + } + } + + // Check saved/default memory offsets + if ( !pRet ) + { + if ( CheckForInterface( pInterfaceClass, dxdata, dxdatalen, __uuidof( ID3D10Device ), nFunctioncount ) ) + { + pRet = *static_cast( pInterfaceClass ); + } + } + + dxdata[0] -= nModuleOffset; + dxdata[1] -= nModuleOffset; + dxdata[2] -= nModuleOffset; + + // Offset already found + if ( !pRet ) + { + // Search for offset + return FindInterface( + nModuleOffset, + nRelativeBase, + nFunctioncount, + 0xFFF, + sSubKeyData, + dxdata, + dxdatalen, + sSubKeyOffset, + dxoffset, + dxoffsetlen, + &GetD3D10DeviceData ); + } + + return pRet; + } + + CD3DSystem10::CD3DSystem10() + { + gD3DSystem10 = this; + + m_bD3DHookInstalled = false; + m_nTextureMode = HTM_NONE; + m_pTempTex = NULL; + m_pSwapChain = NULL; + m_sGPUName = ""; + + void* pTrialDevice = NULL; +#if CDK_VERSION < 350 + pTrialDevice = gEnv->pRenderer->EF_Query( EFQ_D3DDevice ); +#elif CDK_VERSION > 354 + gEnv->pRenderer->EF_Query( EFQ_D3DDevice, pTrialDevice ); +#endif + m_pDevice = FindD3D10Device( ( INT_PTR )gEnv->pRenderer, pTrialDevice ); + + // Hook Swap Chain + if ( m_pDevice ) + { + if ( BootstrapD3D10SwapChainHook() ) + { + gPlugin->LogAlways( "DXGI swap chain hook set" ); + } + + else + { + gPlugin->LogAlways( "DXGI swap chain hook couldn't be installed" ); + } + } + + if ( m_pDevice ) + { + ID3D10Device* pDevice = ( ID3D10Device* )m_pDevice; + m_sGPUName = getGPUName( pDevice ); + + gPlugin->LogAlways( "DX10 device found: GPU(%s)", m_sGPUName.c_str() ); + } + + else + { + gPlugin->LogWarning( "DX10 device not found" ); + } + } + + CD3DSystem10::~CD3DSystem10() + { + hookD3D( false ); + + gD3DSystem10 = NULL; + } + + void CD3DSystem10::hookD3D( bool bHook ) + { +#if defined(D3D_DISABLE_HOOK) + return; +#endif + + if ( m_pDevice ) + { + if ( bHook && m_bD3DHookInstalled ) + { + if ( m_pSwapChain ) + { + rehookVT( m_pSwapChain, IDXGISwapChain, Present ); + } + + rehookVT( m_pDevice, ID3D10Device, CreateTexture2D ); + } + + else if ( bHook ) + { + hookVT( m_pDevice, ID3D10Device, CreateTexture2D ); + } + + else if ( m_bD3DHookInstalled ) + { + // For Unloading + if ( m_pSwapChain ) + { + unhookVT( m_pSwapChain, IDXGISwapChain, Present, false ); + } + + unhookVT( m_pDevice, ID3D10Device, CreateTexture2D, false ); + } + + m_bD3DHookInstalled = bHook; + } + } + + ITexture* CD3DSystem10::CreateTexture( void** pD3DTextureDst, int width, int height, int numMips, ETEX_Format eTF, int flags ) + { + gD3DSystem10->m_nTextureMode = HTM_CREATE; + int iTex = gEnv->pRenderer->SF_CreateTexture( width, height, numMips, NULL, eTF, flags ); // Create Texture + *pD3DTextureDst = m_pTempTex; + m_pTempTex = NULL; + + return gEnv->pRenderer->EF_GetTextureByID( iTex ); + } + + ITexture* CD3DSystem10::InjectTexture( void* pD3DTextureSrc, int nWidth, int nHeight, ETEX_Format eTF, int flags ) + { + gD3DSystem10->m_nTextureMode = HTM_INJECT; + m_pTempTex = pD3DTextureSrc; + int iTex = gEnv->pRenderer->SF_CreateTexture( nWidth, nHeight, 1, NULL, eTF, flags ); // Create Dummytexture and replace it to trick CE3 into using our texture. + m_pTempTex = NULL; + + return gEnv->pRenderer->EF_GetTextureByID( iTex ); + } + + int CD3DSystem10::GetFeatureLevel() + { + return m_pDevice ? D3D_FEATURE_LEVEL_10_0 : 0; + } + + const char* CD3DSystem10::GetGPUName() + { + return m_sGPUName.c_str(); + } + +} \ No newline at end of file diff --git a/src/dx10/CD3DSystemDX10.h b/src/dx10/CD3DSystemDX10.h new file mode 100644 index 0000000..fc7e555 --- /dev/null +++ b/src/dx10/CD3DSystemDX10.h @@ -0,0 +1,82 @@ +/* D3D_Plugin - for licensing and copyright see license.txt */ + +#pragma once + +#include + +namespace D3DPlugin +{ + class CD3DSystem10 : + public IPluginD3DEx, + private ID3DEventListener + { + private: + bool m_bD3DHookInstalled; + std::vector m_vecQueue; + void hookD3D( bool bHook ); + public: + int m_nTextureMode; + void* m_pTempTex; + void* m_pDevice; + void* m_pSwapChain; + + string m_sGPUName; + + CD3DSystem10(); + virtual ~CD3DSystem10(); + + void Release() + { + delete this; + } + + PluginManager::IPluginBase* GetBase() + { + return gPlugin->GetBase(); + }; + + void ActivateEventDispatcher( bool bActivate ) + { + hookD3D( bActivate ); + }; + + eD3DType GetType() + { + return m_pDevice ? D3D_DX10 : D3D_NONE; + }; + + void* GetDevice() + { + return m_pDevice; + } + + void* GetDeviceContext() + { + return NULL; + }; + + void* GetSwapChain() + { + return m_pSwapChain; + }; + + ITexture* CreateTexture( void** pD3DTextureDst, int width, int height, int numMips, ETEX_Format eTF, int flags ); + ITexture* InjectTexture( void* pD3DTextureSrc, int nWidth, int nHeight, ETEX_Format eTF, int flags ); + + public: + DECLARE_REGISTER_LISTENER( m_vecQueue ); + DECLARE_UNREGISTER_LISTENER( m_vecQueue ); + DECLARE_BROADCAST_EVENT( m_vecQueue, OnPrePresent ); + DECLARE_BROADCAST_EVENT( m_vecQueue, OnPostPresent ); + DECLARE_BROADCAST_EVENT( m_vecQueue, OnPreReset ); + DECLARE_BROADCAST_EVENT( m_vecQueue, OnPostReset ); + DECLARE_BROADCAST_EVENT( m_vecQueue, OnPostBeginScene ); + + virtual int GetFeatureLevel(); + + virtual const char* GetGPUName(); + + }; + + extern CD3DSystem10* gD3DSystem10; +}; \ No newline at end of file diff --git a/src/dx10/d3d10hook.h b/src/dx10/d3d10hook.h new file mode 100644 index 0000000..8e4cc40 --- /dev/null +++ b/src/dx10/d3d10hook.h @@ -0,0 +1,913 @@ +#include +#include + +#include "../hooktools.h" + +#pragma once + +#undef THIS_ +#define THIS_ INTERFACE * This, +#undef THIS +#define THIS INTERFACE * This +#undef STDMETHOD +#define STDMETHOD(method) DECLARE_FUNCTION_PTR(method) +#undef STDMETHOD_ +#define STDMETHOD_(type,method) DECLARE_FUNCTION_PTR_(type,method) + +// Create function pointer types +#undef INTERFACE +#define INTERFACE ID3D10Device + +// from d3d10.h vtable: +STDMETHOD( QueryInterface )DECLARE_PARAMS( + THIS, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + __RPC__deref_out void** ppvObject ); + +STDMETHOD_( ULONG, AddRef )DECLARE_PARAMS( + THIS ); + +STDMETHOD_( ULONG, Release )DECLARE_PARAMS( + THIS ); + +STDMETHOD_( void, VSSetConstantBuffers )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in_range( 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT - 1 ) UINT StartSlot, + /* [annotation] */ + __in_range( 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT - StartSlot ) UINT NumBuffers, + /* [annotation] */ + __in_ecount( NumBuffers ) ID3D10Buffer* const* ppConstantBuffers ); + +STDMETHOD_( void, PSSetShaderResources )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in_range( 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT - 1 ) UINT StartSlot, + /* [annotation] */ + __in_range( 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT - StartSlot ) UINT NumViews, + /* [annotation] */ + __in_ecount( NumViews ) ID3D10ShaderResourceView* const* ppShaderResourceViews ); + +STDMETHOD_( void, PSSetShader )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in_opt ID3D10PixelShader* pPixelShader ); + +STDMETHOD_( void, PSSetSamplers )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in_range( 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT - 1 ) UINT StartSlot, + /* [annotation] */ + __in_range( 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT - StartSlot ) UINT NumSamplers, + /* [annotation] */ + __in_ecount( NumSamplers ) ID3D10SamplerState* const* ppSamplers ); + +STDMETHOD_( void, VSSetShader )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in_opt ID3D10VertexShader* pVertexShader ); + +STDMETHOD_( void, DrawIndexed )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in UINT IndexCount, + /* [annotation] */ + __in UINT StartIndexLocation, + /* [annotation] */ + __in INT BaseVertexLocation ); + +STDMETHOD_( void, Draw )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in UINT VertexCount, + /* [annotation] */ + __in UINT StartVertexLocation ); + +STDMETHOD_( void, PSSetConstantBuffers )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in_range( 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT - 1 ) UINT StartSlot, + /* [annotation] */ + __in_range( 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT - StartSlot ) UINT NumBuffers, + /* [annotation] */ + __in_ecount( NumBuffers ) ID3D10Buffer* const* ppConstantBuffers ); + +STDMETHOD_( void, IASetInputLayout )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in_opt ID3D10InputLayout* pInputLayout ); + +STDMETHOD_( void, IASetVertexBuffers )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in_range( 0, D3D10_1_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT - 1 ) UINT StartSlot, + /* [annotation] */ + __in_range( 0, D3D10_1_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT - StartSlot ) UINT NumBuffers, + /* [annotation] */ + __in_ecount( NumBuffers ) ID3D10Buffer* const* ppVertexBuffers, + /* [annotation] */ + __in_ecount( NumBuffers ) const UINT* pStrides, + /* [annotation] */ + __in_ecount( NumBuffers ) const UINT* pOffsets ); + +STDMETHOD_( void, IASetIndexBuffer )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in_opt ID3D10Buffer* pIndexBuffer, + /* [annotation] */ + __in DXGI_FORMAT Format, + /* [annotation] */ + __in UINT Offset ); + +STDMETHOD_( void, DrawIndexedInstanced )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in UINT IndexCountPerInstance, + /* [annotation] */ + __in UINT InstanceCount, + /* [annotation] */ + __in UINT StartIndexLocation, + /* [annotation] */ + __in INT BaseVertexLocation, + /* [annotation] */ + __in UINT StartInstanceLocation ); + +STDMETHOD_( void, DrawInstanced )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in UINT VertexCountPerInstance, + /* [annotation] */ + __in UINT InstanceCount, + /* [annotation] */ + __in UINT StartVertexLocation, + /* [annotation] */ + __in UINT StartInstanceLocation ); + +STDMETHOD_( void, GSSetConstantBuffers )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in_range( 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT - 1 ) UINT StartSlot, + /* [annotation] */ + __in_range( 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT - StartSlot ) UINT NumBuffers, + /* [annotation] */ + __in_ecount( NumBuffers ) ID3D10Buffer* const* ppConstantBuffers ); + +STDMETHOD_( void, GSSetShader )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in_opt ID3D10GeometryShader* pShader ); + +STDMETHOD_( void, IASetPrimitiveTopology )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in D3D10_PRIMITIVE_TOPOLOGY Topology ); + +STDMETHOD_( void, VSSetShaderResources )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in_range( 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT - 1 ) UINT StartSlot, + /* [annotation] */ + __in_range( 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT - StartSlot ) UINT NumViews, + /* [annotation] */ + __in_ecount( NumViews ) ID3D10ShaderResourceView* const* ppShaderResourceViews ); + +STDMETHOD_( void, VSSetSamplers )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in_range( 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT - 1 ) UINT StartSlot, + /* [annotation] */ + __in_range( 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT - StartSlot ) UINT NumSamplers, + /* [annotation] */ + __in_ecount( NumSamplers ) ID3D10SamplerState* const* ppSamplers ); + +STDMETHOD_( void, SetPredication )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in_opt ID3D10Predicate* pPredicate, + /* [annotation] */ + __in BOOL PredicateValue ); + +STDMETHOD_( void, GSSetShaderResources )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in_range( 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT - 1 ) UINT StartSlot, + /* [annotation] */ + __in_range( 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT - StartSlot ) UINT NumViews, + /* [annotation] */ + __in_ecount( NumViews ) ID3D10ShaderResourceView* const* ppShaderResourceViews ); + +STDMETHOD_( void, GSSetSamplers )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in_range( 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT - 1 ) UINT StartSlot, + /* [annotation] */ + __in_range( 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT - StartSlot ) UINT NumSamplers, + /* [annotation] */ + __in_ecount( NumSamplers ) ID3D10SamplerState* const* ppSamplers ); + +STDMETHOD_( void, OMSetRenderTargets )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in_range( 0, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT ) UINT NumViews, + /* [annotation] */ + __in_ecount_opt( NumViews ) ID3D10RenderTargetView* const* ppRenderTargetViews, + /* [annotation] */ + __in_opt ID3D10DepthStencilView* pDepthStencilView ); + +STDMETHOD_( void, OMSetBlendState )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in_opt ID3D10BlendState* pBlendState, + /* [annotation] */ + __in const FLOAT BlendFactor[ 4 ], + /* [annotation] */ + __in UINT SampleMask ); + +STDMETHOD_( void, OMSetDepthStencilState )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in_opt ID3D10DepthStencilState* pDepthStencilState, + /* [annotation] */ + __in UINT StencilRef ); + +STDMETHOD_( void, SOSetTargets )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in_range( 0, D3D10_SO_BUFFER_SLOT_COUNT ) UINT NumBuffers, + /* [annotation] */ + __in_ecount_opt( NumBuffers ) ID3D10Buffer* const* ppSOTargets, + /* [annotation] */ + __in_ecount_opt( NumBuffers ) const UINT* pOffsets ); + +STDMETHOD_( void, DrawAuto )DECLARE_PARAMS( + THIS ); + +STDMETHOD_( void, RSSetState )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in_opt ID3D10RasterizerState* pRasterizerState ); + +STDMETHOD_( void, RSSetViewports )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in_range( 0, D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE ) UINT NumViewports, + /* [annotation] */ + __in_ecount_opt( NumViewports ) const D3D10_VIEWPORT* pViewports ); + +STDMETHOD_( void, RSSetScissorRects )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in_range( 0, D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE ) UINT NumRects, + /* [annotation] */ + __in_ecount_opt( NumRects ) const D3D10_RECT* pRects ); + +STDMETHOD_( void, CopySubresourceRegion )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in ID3D10Resource* pDstResource, + /* [annotation] */ + __in UINT DstSubresource, + /* [annotation] */ + __in UINT DstX, + /* [annotation] */ + __in UINT DstY, + /* [annotation] */ + __in UINT DstZ, + /* [annotation] */ + __in ID3D10Resource* pSrcResource, + /* [annotation] */ + __in UINT SrcSubresource, + /* [annotation] */ + __in_opt const D3D10_BOX* pSrcBox ); + +STDMETHOD_( void, CopyResource )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in ID3D10Resource* pDstResource, + /* [annotation] */ + __in ID3D10Resource* pSrcResource ); + +STDMETHOD_( void, UpdateSubresource )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in ID3D10Resource* pDstResource, + /* [annotation] */ + __in UINT DstSubresource, + /* [annotation] */ + __in_opt const D3D10_BOX* pDstBox, + /* [annotation] */ + __in const void* pSrcData, + /* [annotation] */ + __in UINT SrcRowPitch, + /* [annotation] */ + __in UINT SrcDepthPitch ); + +STDMETHOD_( void, ClearRenderTargetView )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in ID3D10RenderTargetView* pRenderTargetView, + /* [annotation] */ + __in const FLOAT ColorRGBA[ 4 ] ); + +STDMETHOD_( void, ClearDepthStencilView )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in ID3D10DepthStencilView* pDepthStencilView, + /* [annotation] */ + __in UINT ClearFlags, + /* [annotation] */ + __in FLOAT Depth, + /* [annotation] */ + __in UINT8 Stencil ); + +STDMETHOD_( void, GenerateMips )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in ID3D10ShaderResourceView* pShaderResourceView ); + +STDMETHOD_( void, ResolveSubresource )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in ID3D10Resource* pDstResource, + /* [annotation] */ + __in UINT DstSubresource, + /* [annotation] */ + __in ID3D10Resource* pSrcResource, + /* [annotation] */ + __in UINT SrcSubresource, + /* [annotation] */ + __in DXGI_FORMAT Format ); + +STDMETHOD_( void, VSGetConstantBuffers )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in_range( 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT - 1 ) UINT StartSlot, + /* [annotation] */ + __in_range( 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT - StartSlot ) UINT NumBuffers, + /* [annotation] */ + __out_ecount( NumBuffers ) ID3D10Buffer** ppConstantBuffers ); + +STDMETHOD_( void, PSGetShaderResources )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in_range( 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT - 1 ) UINT StartSlot, + /* [annotation] */ + __in_range( 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT - StartSlot ) UINT NumViews, + /* [annotation] */ + __out_ecount( NumViews ) ID3D10ShaderResourceView** ppShaderResourceViews ); + +STDMETHOD_( void, PSGetShader )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __out ID3D10PixelShader** ppPixelShader ); + +STDMETHOD_( void, PSGetSamplers )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in_range( 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT - 1 ) UINT StartSlot, + /* [annotation] */ + __in_range( 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT - StartSlot ) UINT NumSamplers, + /* [annotation] */ + __out_ecount( NumSamplers ) ID3D10SamplerState** ppSamplers ); + +STDMETHOD_( void, VSGetShader )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __out ID3D10VertexShader** ppVertexShader ); + +STDMETHOD_( void, PSGetConstantBuffers )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in_range( 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT - 1 ) UINT StartSlot, + /* [annotation] */ + __in_range( 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT - StartSlot ) UINT NumBuffers, + /* [annotation] */ + __out_ecount( NumBuffers ) ID3D10Buffer** ppConstantBuffers ); + +STDMETHOD_( void, IAGetInputLayout )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __out ID3D10InputLayout** ppInputLayout ); + +STDMETHOD_( void, IAGetVertexBuffers )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in_range( 0, D3D10_1_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT - 1 ) UINT StartSlot, + /* [annotation] */ + __in_range( 0, D3D10_1_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT - StartSlot ) UINT NumBuffers, + /* [annotation] */ + __out_ecount_opt( NumBuffers ) ID3D10Buffer** ppVertexBuffers, + /* [annotation] */ + __out_ecount_opt( NumBuffers ) UINT* pStrides, + /* [annotation] */ + __out_ecount_opt( NumBuffers ) UINT* pOffsets ); + +STDMETHOD_( void, IAGetIndexBuffer )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __out_opt ID3D10Buffer** pIndexBuffer, + /* [annotation] */ + __out_opt DXGI_FORMAT* Format, + /* [annotation] */ + __out_opt UINT* Offset ); + +STDMETHOD_( void, GSGetConstantBuffers )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in_range( 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT - 1 ) UINT StartSlot, + /* [annotation] */ + __in_range( 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT - StartSlot ) UINT NumBuffers, + /* [annotation] */ + __out_ecount( NumBuffers ) ID3D10Buffer** ppConstantBuffers ); + +STDMETHOD_( void, GSGetShader )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __out ID3D10GeometryShader** ppGeometryShader ); + +STDMETHOD_( void, IAGetPrimitiveTopology )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __out D3D10_PRIMITIVE_TOPOLOGY* pTopology ); + +STDMETHOD_( void, VSGetShaderResources )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in_range( 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT - 1 ) UINT StartSlot, + /* [annotation] */ + __in_range( 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT - StartSlot ) UINT NumViews, + /* [annotation] */ + __out_ecount( NumViews ) ID3D10ShaderResourceView** ppShaderResourceViews ); + +STDMETHOD_( void, VSGetSamplers )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in_range( 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT - 1 ) UINT StartSlot, + /* [annotation] */ + __in_range( 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT - StartSlot ) UINT NumSamplers, + /* [annotation] */ + __out_ecount( NumSamplers ) ID3D10SamplerState** ppSamplers ); + +STDMETHOD_( void, GetPredication )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __out_opt ID3D10Predicate** ppPredicate, + /* [annotation] */ + __out_opt BOOL* pPredicateValue ); + +STDMETHOD_( void, GSGetShaderResources )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in_range( 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT - 1 ) UINT StartSlot, + /* [annotation] */ + __in_range( 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT - StartSlot ) UINT NumViews, + /* [annotation] */ + __out_ecount( NumViews ) ID3D10ShaderResourceView** ppShaderResourceViews ); + +STDMETHOD_( void, GSGetSamplers )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in_range( 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT - 1 ) UINT StartSlot, + /* [annotation] */ + __in_range( 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT - StartSlot ) UINT NumSamplers, + /* [annotation] */ + __out_ecount( NumSamplers ) ID3D10SamplerState** ppSamplers ); + +STDMETHOD_( void, OMGetRenderTargets )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in_range( 0, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT ) UINT NumViews, + /* [annotation] */ + __out_ecount_opt( NumViews ) ID3D10RenderTargetView** ppRenderTargetViews, + /* [annotation] */ + __out_opt ID3D10DepthStencilView** ppDepthStencilView ); + +STDMETHOD_( void, OMGetBlendState )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __out_opt ID3D10BlendState** ppBlendState, + /* [annotation] */ + __out_opt FLOAT BlendFactor[ 4 ], + /* [annotation] */ + __out_opt UINT* pSampleMask ); + +STDMETHOD_( void, OMGetDepthStencilState )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __out_opt ID3D10DepthStencilState** ppDepthStencilState, + /* [annotation] */ + __out_opt UINT* pStencilRef ); + +STDMETHOD_( void, SOGetTargets )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in_range( 0, D3D10_SO_BUFFER_SLOT_COUNT ) UINT NumBuffers, + /* [annotation] */ + __out_ecount_opt( NumBuffers ) ID3D10Buffer** ppSOTargets, + /* [annotation] */ + __out_ecount_opt( NumBuffers ) UINT* pOffsets ); + +STDMETHOD_( void, RSGetState )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __out ID3D10RasterizerState** ppRasterizerState ); + +STDMETHOD_( void, RSGetViewports )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __inout /*_range(0, D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE )*/ UINT* NumViewports, + /* [annotation] */ + __out_ecount_opt( *NumViewports ) D3D10_VIEWPORT* pViewports ); + +STDMETHOD_( void, RSGetScissorRects )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __inout /*_range(0, D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE )*/ UINT* NumRects, + /* [annotation] */ + __out_ecount_opt( *NumRects ) D3D10_RECT* pRects ); + +STDMETHOD( GetDeviceRemovedReason )DECLARE_PARAMS( + THIS ); + +STDMETHOD( SetExceptionMode )DECLARE_PARAMS( + THIS, + UINT RaiseFlags ); + +STDMETHOD_( UINT, GetExceptionMode )DECLARE_PARAMS( + THIS ); + +STDMETHOD( GetPrivateData )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in REFGUID guid, + /* [annotation] */ + __inout UINT* pDataSize, + /* [annotation] */ + __out_bcount_opt( *pDataSize ) void* pData ); + +STDMETHOD( SetPrivateData )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in REFGUID guid, + /* [annotation] */ + __in UINT DataSize, + /* [annotation] */ + __in_bcount_opt( DataSize ) const void* pData ); + +STDMETHOD( SetPrivateDataInterface )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in REFGUID guid, + /* [annotation] */ + __in_opt const IUnknown* pData ); + +STDMETHOD_( void, ClearState )DECLARE_PARAMS( + THIS ); + +STDMETHOD_( void, Flush )DECLARE_PARAMS( + THIS ); + +STDMETHOD( CreateBuffer )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in const D3D10_BUFFER_DESC* pDesc, + /* [annotation] */ + __in_opt const D3D10_SUBRESOURCE_DATA* pInitialData, + /* [annotation] */ + __out_opt ID3D10Buffer** ppBuffer ); + +STDMETHOD( CreateTexture1D )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in const D3D10_TEXTURE1D_DESC* pDesc, + /* [annotation] */ + __in_xcount_opt( pDesc->MipLevels * pDesc->ArraySize ) const D3D10_SUBRESOURCE_DATA* pInitialData, + /* [annotation] */ + __out ID3D10Texture1D** ppTexture1D ); + +STDMETHOD( CreateTexture2D )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in const D3D10_TEXTURE2D_DESC* pDesc, + /* [annotation] */ + __in_xcount_opt( pDesc->MipLevels * pDesc->ArraySize ) const D3D10_SUBRESOURCE_DATA* pInitialData, + /* [annotation] */ + __out ID3D10Texture2D** ppTexture2D ); + +STDMETHOD( CreateTexture3D )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in const D3D10_TEXTURE3D_DESC* pDesc, + /* [annotation] */ + __in_xcount_opt( pDesc->MipLevels ) const D3D10_SUBRESOURCE_DATA* pInitialData, + /* [annotation] */ + __out ID3D10Texture3D** ppTexture3D ); + +STDMETHOD( CreateShaderResourceView )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in ID3D10Resource* pResource, + /* [annotation] */ + __in_opt const D3D10_SHADER_RESOURCE_VIEW_DESC* pDesc, + /* [annotation] */ + __out_opt ID3D10ShaderResourceView** ppSRView ); + +STDMETHOD( CreateRenderTargetView )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in ID3D10Resource* pResource, + /* [annotation] */ + __in_opt const D3D10_RENDER_TARGET_VIEW_DESC* pDesc, + /* [annotation] */ + __out_opt ID3D10RenderTargetView** ppRTView ); + +STDMETHOD( CreateDepthStencilView )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in ID3D10Resource* pResource, + /* [annotation] */ + __in_opt const D3D10_DEPTH_STENCIL_VIEW_DESC* pDesc, + /* [annotation] */ + __out_opt ID3D10DepthStencilView** ppDepthStencilView ); + +STDMETHOD( CreateInputLayout )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in_ecount( NumElements ) const D3D10_INPUT_ELEMENT_DESC* pInputElementDescs, + /* [annotation] */ + __in_range( 0, D3D10_1_IA_VERTEX_INPUT_STRUCTURE_ELEMENT_COUNT ) UINT NumElements, + /* [annotation] */ + __in const void* pShaderBytecodeWithInputSignature, + /* [annotation] */ + __in SIZE_T BytecodeLength, + /* [annotation] */ + __out_opt ID3D10InputLayout** ppInputLayout ); + +STDMETHOD( CreateVertexShader )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in const void* pShaderBytecode, + /* [annotation] */ + __in SIZE_T BytecodeLength, + /* [annotation] */ + __out_opt ID3D10VertexShader** ppVertexShader ); + +STDMETHOD( CreateGeometryShader )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in const void* pShaderBytecode, + /* [annotation] */ + __in SIZE_T BytecodeLength, + /* [annotation] */ + __out_opt ID3D10GeometryShader** ppGeometryShader ); + +STDMETHOD( CreateGeometryShaderWithStreamOutput )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in const void* pShaderBytecode, + /* [annotation] */ + __in SIZE_T BytecodeLength, + /* [annotation] */ + __in_ecount_opt( NumEntries ) const D3D10_SO_DECLARATION_ENTRY* pSODeclaration, + /* [annotation] */ + __in_range( 0, D3D10_SO_SINGLE_BUFFER_COMPONENT_LIMIT ) UINT NumEntries, + /* [annotation] */ + __in UINT OutputStreamStride, + /* [annotation] */ + __out_opt ID3D10GeometryShader** ppGeometryShader ); + +STDMETHOD( CreatePixelShader )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in const void* pShaderBytecode, + /* [annotation] */ + __in SIZE_T BytecodeLength, + /* [annotation] */ + __out_opt ID3D10PixelShader** ppPixelShader ); + +STDMETHOD( CreateBlendState )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in const D3D10_BLEND_DESC* pBlendStateDesc, + /* [annotation] */ + __out_opt ID3D10BlendState** ppBlendState ); + +STDMETHOD( CreateDepthStencilState )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in const D3D10_DEPTH_STENCIL_DESC* pDepthStencilDesc, + /* [annotation] */ + __out_opt ID3D10DepthStencilState** ppDepthStencilState ); + +STDMETHOD( CreateRasterizerState )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in const D3D10_RASTERIZER_DESC* pRasterizerDesc, + /* [annotation] */ + __out_opt ID3D10RasterizerState** ppRasterizerState ); + +STDMETHOD( CreateSamplerState )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in const D3D10_SAMPLER_DESC* pSamplerDesc, + /* [annotation] */ + __out_opt ID3D10SamplerState** ppSamplerState ); + +STDMETHOD( CreateQuery )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in const D3D10_QUERY_DESC* pQueryDesc, + /* [annotation] */ + __out_opt ID3D10Query** ppQuery ); + +STDMETHOD( CreatePredicate )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in const D3D10_QUERY_DESC* pPredicateDesc, + /* [annotation] */ + __out_opt ID3D10Predicate** ppPredicate ); + +STDMETHOD( CreateCounter )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in const D3D10_COUNTER_DESC* pCounterDesc, + /* [annotation] */ + __out_opt ID3D10Counter** ppCounter ); + +STDMETHOD( CheckFormatSupport )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in DXGI_FORMAT Format, + /* [annotation] */ + __out UINT* pFormatSupport ); + +STDMETHOD( CheckMultisampleQualityLevels )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in DXGI_FORMAT Format, + /* [annotation] */ + __in UINT SampleCount, + /* [annotation] */ + __out UINT* pNumQualityLevels ); + +STDMETHOD_( void, CheckCounterInfo )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __out D3D10_COUNTER_INFO* pCounterInfo ); + +STDMETHOD( CheckCounter )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in const D3D10_COUNTER_DESC* pDesc, + /* [annotation] */ + __out D3D10_COUNTER_TYPE* pType, + /* [annotation] */ + __out UINT* pActiveCounters, + /* [annotation] */ + __out_ecount_opt( *pNameLength ) LPSTR szName, + /* [annotation] */ + __inout_opt UINT* pNameLength, + /* [annotation] */ + __out_ecount_opt( *pUnitsLength ) LPSTR szUnits, + /* [annotation] */ + __inout_opt UINT* pUnitsLength, + /* [annotation] */ + __out_ecount_opt( *pDescriptionLength ) LPSTR szDescription, + /* [annotation] */ + __inout_opt UINT* pDescriptionLength ); + +STDMETHOD_( UINT, GetCreationFlags )DECLARE_PARAMS( + THIS ); + +STDMETHOD( OpenSharedResource )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in HANDLE hResource, + /* [annotation] */ + __in REFIID ReturnedInterface, + /* [annotation] */ + __out_opt void** ppResource ); + +STDMETHOD_( void, SetTextFilterSize )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __in UINT Width, + /* [annotation] */ + __in UINT Height ); + +STDMETHOD_( void, GetTextFilterSize )DECLARE_PARAMS( + THIS, + /* [annotation] */ + __out_opt UINT* pWidth, + /* [annotation] */ + __out_opt UINT* pHeight ); + +// Create vtable offsets +#undef STDMETHOD +#define STDMETHOD(method) PPCAT(PPCAT(PPCAT(vt, INTERFACE),_), method), +#undef STDMETHOD_ +#define STDMETHOD_(type,method) PPCAT(PPCAT(PPCAT(vt, INTERFACE),_), method), + +enum PPCAT( vt, INTERFACE ) +{ + // from d3d10.h + STDMETHOD( QueryInterface ) + STDMETHOD_( ULONG, AddRef ) + STDMETHOD_( ULONG, Release ) + STDMETHOD_( void, VSSetConstantBuffers ) + STDMETHOD_( void, PSSetShaderResources ) + STDMETHOD_( void, PSSetShader ) + STDMETHOD_( void, PSSetSamplers ) + STDMETHOD_( void, VSSetShader ) + STDMETHOD_( void, DrawIndexed ) + STDMETHOD_( void, Draw ) + STDMETHOD_( void, PSSetConstantBuffers ) + STDMETHOD_( void, IASetInputLayout ) + STDMETHOD_( void, IASetVertexBuffers ) + STDMETHOD_( void, IASetIndexBuffer ) + STDMETHOD_( void, DrawIndexedInstanced ) + STDMETHOD_( void, DrawInstanced ) + STDMETHOD_( void, GSSetConstantBuffers ) + STDMETHOD_( void, GSSetShader ) + STDMETHOD_( void, IASetPrimitiveTopology ) + STDMETHOD_( void, VSSetShaderResources ) + STDMETHOD_( void, VSSetSamplers ) + STDMETHOD_( void, SetPredication ) + STDMETHOD_( void, GSSetShaderResources ) + STDMETHOD_( void, GSSetSamplers ) + STDMETHOD_( void, OMSetRenderTargets ) + STDMETHOD_( void, OMSetBlendState ) + STDMETHOD_( void, OMSetDepthStencilState ) + STDMETHOD_( void, SOSetTargets ) + STDMETHOD_( void, DrawAuto ) + STDMETHOD_( void, RSSetState ) + STDMETHOD_( void, RSSetViewports ) + STDMETHOD_( void, RSSetScissorRects ) + STDMETHOD_( void, CopySubresourceRegion ) + STDMETHOD_( void, CopyResource ) + STDMETHOD_( void, UpdateSubresource ) + STDMETHOD_( void, ClearRenderTargetView ) + STDMETHOD_( void, ClearDepthStencilView ) + STDMETHOD_( void, GenerateMips ) + STDMETHOD_( void, ResolveSubresource ) + STDMETHOD_( void, VSGetConstantBuffers ) + STDMETHOD_( void, PSGetShaderResources ) + STDMETHOD_( void, PSGetShader ) + STDMETHOD_( void, PSGetSamplers ) + STDMETHOD_( void, VSGetShader ) + STDMETHOD_( void, PSGetConstantBuffers ) + STDMETHOD_( void, IAGetInputLayout ) + STDMETHOD_( void, IAGetVertexBuffers ) + STDMETHOD_( void, IAGetIndexBuffer ) + STDMETHOD_( void, GSGetConstantBuffers ) + STDMETHOD_( void, GSGetShader ) + STDMETHOD_( void, IAGetPrimitiveTopology ) + STDMETHOD_( void, VSGetShaderResources ) + STDMETHOD_( void, VSGetSamplers ) + STDMETHOD_( void, GetPredication ) + STDMETHOD_( void, GSGetShaderResources ) + STDMETHOD_( void, GSGetSamplers ) + STDMETHOD_( void, OMGetRenderTargets ) + STDMETHOD_( void, OMGetBlendState ) + STDMETHOD_( void, OMGetDepthStencilState ) + STDMETHOD_( void, SOGetTargets ) + STDMETHOD_( void, RSGetState ) + STDMETHOD_( void, RSGetViewports ) + STDMETHOD_( void, RSGetScissorRects ) + STDMETHOD( GetDeviceRemovedReason ) + STDMETHOD( SetExceptionMode ) + STDMETHOD_( UINT, GetExceptionMode ) + STDMETHOD( GetPrivateData ) + STDMETHOD( SetPrivateData ) + STDMETHOD( SetPrivateDataInterface ) + STDMETHOD_( void, ClearState ) + STDMETHOD_( void, Flush ) + STDMETHOD( CreateBuffer ) + STDMETHOD( CreateTexture1D ) + STDMETHOD( CreateTexture2D ) + STDMETHOD( CreateTexture3D ) + STDMETHOD( CreateShaderResourceView ) + STDMETHOD( CreateRenderTargetView ) + STDMETHOD( CreateDepthStencilView ) + STDMETHOD( CreateInputLayout ) + STDMETHOD( CreateVertexShader ) + STDMETHOD( CreateGeometryShader ) + STDMETHOD( CreateGeometryShaderWithStreamOutput ) + STDMETHOD( CreatePixelShader ) + STDMETHOD( CreateBlendState ) + STDMETHOD( CreateDepthStencilState ) + STDMETHOD( CreateRasterizerState ) + STDMETHOD( CreateSamplerState ) + STDMETHOD( CreateQuery ) + STDMETHOD( CreatePredicate ) + STDMETHOD( CreateCounter ) + STDMETHOD( CheckFormatSupport ) + STDMETHOD( CheckMultisampleQualityLevels ) + STDMETHOD_( void, CheckCounterInfo ) + STDMETHOD( CheckCounter ) + STDMETHOD_( UINT, GetCreationFlags ) + STDMETHOD( OpenSharedResource ) + STDMETHOD_( void, SetTextFilterSize ) + STDMETHOD_( void, GetTextFilterSize ) +}; \ No newline at end of file diff --git a/src/dx11/CD3DSystemDX11.cpp b/src/dx11/CD3DSystemDX11.cpp index 0293643..e59bd02 100644 --- a/src/dx11/CD3DSystemDX11.cpp +++ b/src/dx11/CD3DSystemDX11.cpp @@ -3,6 +3,8 @@ #include #include "CD3DSystemDX11.h" #include "d3d11hook.h" +#include "../dxgi/dxgihook.h" +#include "../dxgi/dxgiutils.hpp" #include @@ -60,12 +62,8 @@ GEN_HOOK_( void, __in_opt ID3D11GeometryShader* pShader, __in_ecount_opt( NumCla { CALL_ORGINAL_( , pShader, ppClassInstances, NumClassInstances ); - //FIXME: - // Note: this is more of a hack since access to swap chain not yet implemented - // (multiple calls for each frame will come through the listener must handle it by registering a OnPostUpdate and setting a dirty flag) if ( pShader == NULL && ppClassInstances == NULL && NumClassInstances == 0 ) { - //D3DPlugin::gD3DSystem11->OnPostBeginScene(); if ( D3DPlugin::gD3DSystem11->m_pSwapChain ) { rehookVT( D3DPlugin::gD3DSystem11->m_pSwapChain, IDXGISwapChain, Present ); @@ -80,17 +78,15 @@ GEN_HOOK_( void, __in_opt ID3D11GeometryShader* pShader, __in_ecount_opt( NumCla GEN_HOOK_( void, __in ID3D11RenderTargetView* pRenderTargetView, __in const FLOAT ColorRGBA[ 4 ] ) { CALL_ORGINAL_( , pRenderTargetView, ColorRGBA ); - //D3DPlugin::gD3DSystem11->OnPostBeginScene(); rehookVT( This, ID3D11DeviceContext, ClearRenderTargetView ); }; #undef METHOD #define METHOD End -GEN_HOOK_( void, __in ID3D11Asynchronous* pAsync ) +GEN_HOOK_( void, __in ID3D11Asynchronous* pAsync ) { CALL_ORGINAL_( , pAsync ); - //D3DPlugin::gD3DSystem11->OnPostBeginScene(); rehookVT( This, ID3D11DeviceContext, ClearRenderTargetView ); rehookVT( This, ID3D11DeviceContext, End ); } @@ -143,7 +139,7 @@ GEN_HOOK( __in const D3D11_TEXTURE2D_DESC* pDesc, __in_xcount_opt( pDesc->MipLev #undef METHOD #define METHOD GetImmediateContext -GEN_HOOK_( void, __out ID3D11DeviceContext** ppImmediateContext ) +GEN_HOOK_( void, __out ID3D11DeviceContext** ppImmediateContext ) { CALL_ORGINAL_( , ppImmediateContext ); @@ -154,7 +150,7 @@ GEN_HOOK_( void, __out ID3D11DeviceContext** ppImmediateContext ) #undef METHOD #undef INTERFACE -bool BootstrapD3D11SwapChainHook( ) +bool GetD3D11DeviceData( INT_PTR* unkdata, int nDatalen, void* pParam ) { bool bRet = false; HWND hWndDummy = CreateWindowEx( NULL, TEXT( "Message" ), TEXT( "DummyWindow" ), WS_MINIMIZE, 0, 0, 8, 8, HWND_MESSAGE, NULL, 0, NULL ); @@ -162,7 +158,7 @@ bool BootstrapD3D11SwapChainHook( ) HMODULE hModule = NULL; hModule = GetModuleHandle( "d3d11.dll" ); - typedef HRESULT ( WINAPI * fD3D11CreateDeviceAndSwapChain )( + typedef HRESULT( WINAPI * fD3D11CreateDeviceAndSwapChain )( _In_ IDXGIAdapter * pAdapter, _In_ D3D_DRIVER_TYPE DriverType, _In_ HMODULE Software, @@ -210,27 +206,27 @@ bool BootstrapD3D11SwapChainHook( ) if ( SUCCEEDED( hr ) ) { bRet = true; - hookVT( pSwapChain, IDXGISwapChain, Present ); + + if ( pParam && *( ( bool* )pParam ) ) + { + hookVT( pSwapChain, IDXGISwapChain, Present ); + } } - /* - INT_PTR* unkdata, int nDatalen, void* pParam; + if ( bRet && unkdata ) + { + void** vt = getVT( pDevice ); - if ( bRet && nDatalen > 0 && unkdata ) + if ( vt ) { - void** vt = getVT( pSwapChain ); - - if ( vt ) - { - memcpy( unkdata, vt, nDatalen ); - } + memcpy( unkdata, vt, nDatalen ); + } - else - { - bRet = false; - } + else + { + bRet = false; } - */ + } SAFE_RELEASE( pSwapChain ); SAFE_RELEASE( pDevice ); @@ -241,6 +237,12 @@ bool BootstrapD3D11SwapChainHook( ) return bRet; } +bool BootstrapD3D11SwapChainHook() +{ + bool bHook = true; + return GetD3D11DeviceData( NULL, 0, &bHook ); +} + namespace D3DPlugin { IDXGISwapChain* FindDXGISwapChain( INT_PTR nRelativeBase ) @@ -255,57 +257,6 @@ namespace D3DPlugin // atm search is not needed since we receive swap chain through present return NULL; - - /* - // Not needed anymore DX11/DXGI is easier to handle (by creating Dummy SwapChain) - - // Set Defaults - static INT_PTR dxoffset = 0xC00 + sizeof( INT_PTR ); - static DWORD dxoffsetlen = sizeof( dxoffset ); - - static INT_PTR dxdata[3]; - static DWORD dxdatalen = sizeof( dxdata ); - - static bool bFirstCall = true; - - #ifdef _WIN64 - static LPCTSTR sSubKeyData = D3D_DATA SEP D3D_TARGETX64 SEP D3D_TARGETDX11; - static LPCTSTR sSubKeyOffset = D3D_OFFSET SEP D3D_TARGETX64 SEP D3D_TARGETDX11; - - if ( bFirstCall ) - { - dxdata[0] = 0x0; - dxdata[1] = 0x0; - dxdata[2] = 0x0; - } - - #else - static LPCTSTR sSubKeyData = D3D_DATA SEP D3D_TARGETX86 SEP D3D_TARGETDX11; - static LPCTSTR sSubKeyOffset = D3D_OFFSET SEP D3D_TARGETX86 SEP D3D_TARGETDX11; - - if ( bFirstCall ) - { - dxdata[0] = 0x0; - dxdata[1] = 0x0; - dxdata[2] = 0x0; - } - - #endif - int nFunctioncount = 18; - - return FindInterface( - nModuleOffset, - nRelativeBase, - nFunctioncount, - 0xFFF, - "", - dxdata, - dxdatalen, - "", - dxoffset, - dxoffsetlen, - &GetD3D11DeviceData ); - */ } ID3D11Device* FindD3D11Device( INT_PTR nRelativeBase, void* pTrialDevice ) @@ -323,11 +274,13 @@ namespace D3DPlugin return ( ID3D11Device* )pTrialDevice; } - // Not required for DX11, Device can be retrieved via SwapChain - // Set Defaults - //static INT_PTR dxoffset = 0xC00 + sizeof( INT_PTR ); +#ifdef _WIN64 + static INT_PTR dxoffset = 0xF60; +#else static INT_PTR dxoffset = 0xF54; +#endif + static DWORD dxoffsetlen = sizeof( dxoffset ); static INT_PTR dxdata[3]; @@ -361,39 +314,56 @@ namespace D3DPlugin bFirstCall = false; void* pInterfaceClass = ( void* )( nRelativeBase + dxoffset ); - int nFunctioncount = 43; + int nFunctioncount = 43; //dx11 + + ID3D11Device* pRet = NULL; // Calculate Offsets of IUnknown Interface VTable dxdata[0] += nModuleOffset; dxdata[1] += nModuleOffset; dxdata[2] += nModuleOffset; - bool bInterfaceOk = CheckForInterface( pInterfaceClass, dxdata, dxdatalen, __uuidof( ID3D11Device ), nFunctioncount ); + + // Check EF_Query/Trial (should always be correct unless CDK decides its private again or faulty) + if ( pTrialDevice ) + { + if ( CheckForInterface( &pTrialDevice, dxdata, dxdatalen, __uuidof( ID3D11Device ), nFunctioncount ) ) + { + pRet = static_cast( pTrialDevice ); + } + } + + // Check saved/default memory offsets + if ( !pRet ) + { + if ( CheckForInterface( pInterfaceClass, dxdata, dxdatalen, __uuidof( ID3D11Device ), nFunctioncount ) ) + { + pRet = *static_cast( pInterfaceClass ); + } + } + dxdata[0] -= nModuleOffset; dxdata[1] -= nModuleOffset; dxdata[2] -= nModuleOffset; // Offset already found - if ( bInterfaceOk ) + if ( !pRet ) { - return *( ID3D11Device** )pInterfaceClass; + // Search for offset + return FindInterface( + nModuleOffset, + nRelativeBase, + nFunctioncount, + 0xFFF, + sSubKeyData, + dxdata, + dxdatalen, + sSubKeyOffset, + dxoffset, + dxoffsetlen, + &GetD3D11DeviceData ); } - return NULL; - /* - // Search for offset - return FindInterface( - nModuleOffset, - nRelativeBase, - nFunctioncount, - 0xFFF, - sSubKeyData, - dxdata, - dxdatalen, - sSubKeyOffset, - dxoffset, - dxoffsetlen, - &GetD3D11DeviceData ); - */ + return pRet; } CD3DSystem11::CD3DSystem11() @@ -403,12 +373,17 @@ namespace D3DPlugin m_bD3DHookInstalled = false; m_nTextureMode = HTM_NONE; m_pTempTex = NULL; + m_nFeatureLevel = 0; + m_sGPUName = ""; m_pDeviceCtx = NULL; - m_pSwapChain = NULL; // FindDXGISwapChain( ( INT_PTR )gEnv->pRenderer ); + m_pSwapChain = NULL; + void* pTrialDevice = NULL; -#if CDK_VERSION < 354 +#if CDK_VERSION < 350 pTrialDevice = gEnv->pRenderer->EF_Query( EFQ_D3DDevice ); +#elif CDK_VERSION > 354 + gEnv->pRenderer->EF_Query( EFQ_D3DDevice, pTrialDevice ); #endif m_pDevice = FindD3D11Device( ( INT_PTR )gEnv->pRenderer, pTrialDevice ); @@ -442,23 +417,16 @@ namespace D3DPlugin gPlugin->LogWarning( "DX11 device context not found" ); } - gPlugin->LogAlways( "DX11 device found" ); + m_nFeatureLevel = pDevice->GetFeatureLevel(); + m_sGPUName = getGPUName( pDevice ); + + gPlugin->LogAlways( "DX11 device found: FeatureLevel(0x%05x) GPU(%s)", int( m_nFeatureLevel ), m_sGPUName.c_str() ); } else { gPlugin->LogWarning( "DX11 device not found" ); } - - /* - // Alternative Method would only work on Debug devices.. - ID3D11Debug* pDbgDevice = NULL; - HRESULT hr = pDevice->QueryInterface(__uuidof(ID3D11Debug), (void**)&pDbgDevice); - - IDXGISwapChain* pSwapChain = NULL; - if(pDbgDevice) - hr = pDbgDevice->GetSwapChain(&pSwapChain); - */ } CD3DSystem11::~CD3DSystem11() @@ -492,12 +460,6 @@ namespace D3DPlugin else if ( bHook ) { - // This way isn't possible. Only via bootstrap - //if ( m_pSwapChain ) - //{ - // hookVT( m_pSwapChain, IDXGISwapChain, Present ); - //} - hookVT( m_pDevice, ID3D11Device, CreateTexture2D ); hookVT( m_pDevice, ID3D11Device, GetImmediateContext ); hookVT( m_pDeviceCtx, ID3D11DeviceContext, ClearRenderTargetView ); @@ -513,10 +475,10 @@ namespace D3DPlugin unhookVT( m_pSwapChain, IDXGISwapChain, Present, false ); } - unhookVT( m_pDevice, ID3D11Device, CreateTexture2D, false ); - unhookVT( m_pDevice, ID3D11Device, GetImmediateContext, false ); - unhookVT( m_pDeviceCtx, ID3D11DeviceContext, ClearRenderTargetView, false ); - unhookVT( m_pDeviceCtx, ID3D11DeviceContext, End, false ); + unhookVT( m_pDevice, ID3D11Device, CreateTexture2D, false ); + unhookVT( m_pDevice, ID3D11Device, GetImmediateContext, false ); + unhookVT( m_pDeviceCtx, ID3D11DeviceContext, ClearRenderTargetView, false ); + unhookVT( m_pDeviceCtx, ID3D11DeviceContext, End, false ); unhookVT( m_pDeviceCtx, ID3D11DeviceContext, GSSetShader, false ); } @@ -544,4 +506,14 @@ namespace D3DPlugin return gEnv->pRenderer->EF_GetTextureByID( iTex ); } + int CD3DSystem11::GetFeatureLevel() + { + return m_pDevice ? m_nFeatureLevel : 0; + } + + const char* CD3DSystem11::GetGPUName() + { + return m_sGPUName.c_str(); + } + } \ No newline at end of file diff --git a/src/dx11/CD3DSystemDX11.h b/src/dx11/CD3DSystemDX11.h index 7eead98..1fee4c4 100644 --- a/src/dx11/CD3DSystemDX11.h +++ b/src/dx11/CD3DSystemDX11.h @@ -16,11 +16,14 @@ namespace D3DPlugin void hookD3D( bool bHook ); public: int m_nTextureMode; + int m_nFeatureLevel; void* m_pTempTex; void* m_pDevice; void* m_pDeviceCtx; void* m_pSwapChain; + string m_sGPUName; + CD3DSystem11(); virtual ~CD3DSystem11(); @@ -70,6 +73,11 @@ namespace D3DPlugin DECLARE_BROADCAST_EVENT( m_vecQueue, OnPreReset ); DECLARE_BROADCAST_EVENT( m_vecQueue, OnPostReset ); DECLARE_BROADCAST_EVENT( m_vecQueue, OnPostBeginScene ); + + virtual int GetFeatureLevel(); + + virtual const char* GetGPUName(); + }; extern CD3DSystem11* gD3DSystem11; diff --git a/src/dx11/d3d11hook.h b/src/dx11/d3d11hook.h index d6ab2b9..36b1723 100644 --- a/src/dx11/d3d11hook.h +++ b/src/dx11/d3d11hook.h @@ -1511,132 +1511,3 @@ enum PPCAT( vt, INTERFACE ) STDMETHOD_( UINT, GetContextFlags ) STDMETHOD( FinishCommandList ) }; - -#undef THIS_ -#define THIS_ INTERFACE * This, -#undef THIS -#define THIS INTERFACE * This -#undef STDMETHOD -#define STDMETHOD(method) DECLARE_FUNCTION_PTR(method) -#undef STDMETHOD_ -#define STDMETHOD_(type,method) DECLARE_FUNCTION_PTR_(type,method) - -// Create function pointer types -#undef INTERFACE -#define INTERFACE IDXGISwapChain - -STDMETHOD( QueryInterface )DECLARE_PARAMS( - THIS, - /* [in] */ REFIID riid, - /* [annotation][iid_is][out] */ - __RPC__deref_out void** ppvObject ); - -STDMETHOD_( ULONG, AddRef )DECLARE_PARAMS( - THIS ); - -STDMETHOD_( ULONG, Release )DECLARE_PARAMS( - THIS ); - -STDMETHOD( SetPrivateData )DECLARE_PARAMS( - THIS, - /* [in] */ REFGUID Name, - /* [in] */ UINT DataSize, - /* [in] */ const void* pData ); - -STDMETHOD( SetPrivateDataInterface )DECLARE_PARAMS( - THIS, - /* [in] */ REFGUID Name, - /* [in] */ const IUnknown* pUnknown ); - -STDMETHOD( GetPrivateData )DECLARE_PARAMS( - THIS, - /* [in] */ REFGUID Name, - /* [out][in] */ UINT* pDataSize, - /* [out] */ void* pData ); - -STDMETHOD( GetParent )DECLARE_PARAMS( - THIS, - /* [in] */ REFIID riid, - /* [retval][out] */ void** ppParent ); - -STDMETHOD( GetDevice )DECLARE_PARAMS( - THIS, - /* [in] */ REFIID riid, - /* [retval][out] */ void** ppDevice ); - -STDMETHOD( Present )DECLARE_PARAMS( - THIS, - /* [in] */ UINT SyncInterval, - /* [in] */ UINT Flags ); - -STDMETHOD( GetBuffer )DECLARE_PARAMS( - THIS, - /* [in] */ UINT Buffer, - /* [in] */ REFIID riid, - /* [out][in] */ void** ppSurface ); - -STDMETHOD( SetFullscreenState )DECLARE_PARAMS( - THIS, - /* [in] */ BOOL Fullscreen, - /* [in] */ IDXGIOutput* pTarget ); - -STDMETHOD( GetFullscreenState )DECLARE_PARAMS( - THIS, - /* [out] */ BOOL* pFullscreen, - /* [out] */ IDXGIOutput** ppTarget ); - -STDMETHOD( GetDesc )DECLARE_PARAMS( - THIS, - /* [out] */ DXGI_SWAP_CHAIN_DESC* pDesc ); - -STDMETHOD( ResizeBuffers )DECLARE_PARAMS( - THIS, - /* [in] */ UINT BufferCount, - /* [in] */ UINT Width, - /* [in] */ UINT Height, - /* [in] */ DXGI_FORMAT NewFormat, - /* [in] */ UINT SwapChainFlags ); - -STDMETHOD( ResizeTarget )DECLARE_PARAMS( - THIS, - /* [in] */ const DXGI_MODE_DESC* pNewTargetParameters ); - -STDMETHOD( GetContainingOutput )DECLARE_PARAMS( - THIS, - IDXGIOutput** ppOutput ); - -STDMETHOD( GetFrameStatistics )DECLARE_PARAMS( - THIS, - /* [out] */ DXGI_FRAME_STATISTICS* pStats ); - -STDMETHOD( GetLastPresentCount )DECLARE_PARAMS( - THIS, - /* [out] */ UINT* pLastPresentCount ); - -// Create vtable offsets -#undef STDMETHOD -#define STDMETHOD(method) PPCAT(PPCAT(PPCAT(vt, INTERFACE),_), method), -#undef STDMETHOD_ -#define STDMETHOD_(type,method) PPCAT(PPCAT(PPCAT(vt, INTERFACE),_), method), - -enum PPCAT( vt, INTERFACE ) -{ - STDMETHOD( QueryInterface ) - STDMETHOD_( ULONG, AddRef ) - STDMETHOD_( ULONG, Release ) - STDMETHOD( SetPrivateData ) - STDMETHOD( SetPrivateDataInterface ) - STDMETHOD( GetPrivateData ) - STDMETHOD( GetParent ) - STDMETHOD( GetDevice ) - STDMETHOD( Present ) - STDMETHOD( GetBuffer ) - STDMETHOD( SetFullscreenState ) - STDMETHOD( GetFullscreenState ) - STDMETHOD( GetDesc ) - STDMETHOD( ResizeBuffers ) - STDMETHOD( ResizeTarget ) - STDMETHOD( GetContainingOutput ) - STDMETHOD( GetFrameStatistics ) - STDMETHOD( GetLastPresentCount ) -}; \ No newline at end of file diff --git a/src/dx9/CD3DSystemDX9.cpp b/src/dx9/CD3DSystemDX9.cpp index e47033f..d3b6a58 100644 --- a/src/dx9/CD3DSystemDX9.cpp +++ b/src/dx9/CD3DSystemDX9.cpp @@ -89,6 +89,8 @@ GEN_HOOK( UINT Width, UINT Height, UINT Levels, DWORD Usage, D3DFORMAT Format, D return hr; } #undef METHOD +#undef INTERFACE +#undef STDMETHOD bool GetD3D9DeviceData( INT_PTR* unkdata, int nDatalen, void* pParam ) { @@ -215,8 +217,7 @@ namespace D3DPlugin // Check saved/default memory offsets if ( !pRet ) { - if ( CheckForInterface( pInterfaceClass, dxdata, dxdatalen, __uuidof( IDirect3DDevice9 ), nFunctioncount ) ); - + if ( CheckForInterface( pInterfaceClass, dxdata, dxdatalen, __uuidof( IDirect3DDevice9 ), nFunctioncount ) ) { pRet = *static_cast( pInterfaceClass ); } @@ -254,8 +255,10 @@ namespace D3DPlugin m_pTempTex = NULL; void* pTrialDevice = NULL; -#if CDK_VERSION < 354 +#if CDK_VERSION < 350 pTrialDevice = gEnv->pRenderer->EF_Query( EFQ_D3DDevice ); +#elif CDK_VERSION > 354 + gEnv->pRenderer->EF_Query( EFQ_D3DDevice, pTrialDevice ); #endif m_pDevice = FindD3D9Device( ( INT_PTR )gEnv->pRenderer, pTrialDevice ); @@ -344,4 +347,15 @@ namespace D3DPlugin return gEnv->pRenderer->EF_GetTextureByID( iTex ); } + int CD3DSystem9::GetFeatureLevel() + { +#define D3D_FEATURE_LEVEL_9_3 0x9300 + return m_pDevice ? D3D_FEATURE_LEVEL_9_3 : 0; + } + + const char* CD3DSystem9::GetGPUName() + { + return ""; + } + } \ No newline at end of file diff --git a/src/dx9/CD3DSystemDX9.h b/src/dx9/CD3DSystemDX9.h index 36f2218..0bd5c6a 100644 --- a/src/dx9/CD3DSystemDX9.h +++ b/src/dx9/CD3DSystemDX9.h @@ -64,6 +64,11 @@ namespace D3DPlugin DECLARE_BROADCAST_EVENT( m_vecQueue, OnPreReset ); DECLARE_BROADCAST_EVENT( m_vecQueue, OnPostReset ); DECLARE_BROADCAST_EVENT( m_vecQueue, OnPostBeginScene ); + + virtual int GetFeatureLevel(); + + virtual const char* GetGPUName(); + }; extern CD3DSystem9* gD3DSystem9; diff --git a/src/dxgi/dxgihook.h b/src/dxgi/dxgihook.h new file mode 100644 index 0000000..74f1070 --- /dev/null +++ b/src/dxgi/dxgihook.h @@ -0,0 +1,134 @@ +#include + +#include "../hooktools.h" + +#pragma once + +#undef THIS_ +#define THIS_ INTERFACE * This, +#undef THIS +#define THIS INTERFACE * This +#undef STDMETHOD +#define STDMETHOD(method) DECLARE_FUNCTION_PTR(method) +#undef STDMETHOD_ +#define STDMETHOD_(type,method) DECLARE_FUNCTION_PTR_(type,method) + +// Create function pointer types +#undef INTERFACE +#define INTERFACE IDXGISwapChain + +STDMETHOD( QueryInterface )DECLARE_PARAMS( + THIS, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + __RPC__deref_out void** ppvObject ); + +STDMETHOD_( ULONG, AddRef )DECLARE_PARAMS( + THIS ); + +STDMETHOD_( ULONG, Release )DECLARE_PARAMS( + THIS ); + +STDMETHOD( SetPrivateData )DECLARE_PARAMS( + THIS, + /* [in] */ REFGUID Name, + /* [in] */ UINT DataSize, + /* [in] */ const void* pData ); + +STDMETHOD( SetPrivateDataInterface )DECLARE_PARAMS( + THIS, + /* [in] */ REFGUID Name, + /* [in] */ const IUnknown* pUnknown ); + +STDMETHOD( GetPrivateData )DECLARE_PARAMS( + THIS, + /* [in] */ REFGUID Name, + /* [out][in] */ UINT* pDataSize, + /* [out] */ void* pData ); + +STDMETHOD( GetParent )DECLARE_PARAMS( + THIS, + /* [in] */ REFIID riid, + /* [retval][out] */ void** ppParent ); + +STDMETHOD( GetDevice )DECLARE_PARAMS( + THIS, + /* [in] */ REFIID riid, + /* [retval][out] */ void** ppDevice ); + +STDMETHOD( Present )DECLARE_PARAMS( + THIS, + /* [in] */ UINT SyncInterval, + /* [in] */ UINT Flags ); + +STDMETHOD( GetBuffer )DECLARE_PARAMS( + THIS, + /* [in] */ UINT Buffer, + /* [in] */ REFIID riid, + /* [out][in] */ void** ppSurface ); + +STDMETHOD( SetFullscreenState )DECLARE_PARAMS( + THIS, + /* [in] */ BOOL Fullscreen, + /* [in] */ IDXGIOutput* pTarget ); + +STDMETHOD( GetFullscreenState )DECLARE_PARAMS( + THIS, + /* [out] */ BOOL* pFullscreen, + /* [out] */ IDXGIOutput** ppTarget ); + +STDMETHOD( GetDesc )DECLARE_PARAMS( + THIS, + /* [out] */ DXGI_SWAP_CHAIN_DESC* pDesc ); + +STDMETHOD( ResizeBuffers )DECLARE_PARAMS( + THIS, + /* [in] */ UINT BufferCount, + /* [in] */ UINT Width, + /* [in] */ UINT Height, + /* [in] */ DXGI_FORMAT NewFormat, + /* [in] */ UINT SwapChainFlags ); + +STDMETHOD( ResizeTarget )DECLARE_PARAMS( + THIS, + /* [in] */ const DXGI_MODE_DESC* pNewTargetParameters ); + +STDMETHOD( GetContainingOutput )DECLARE_PARAMS( + THIS, + IDXGIOutput** ppOutput ); + +STDMETHOD( GetFrameStatistics )DECLARE_PARAMS( + THIS, + /* [out] */ DXGI_FRAME_STATISTICS* pStats ); + +STDMETHOD( GetLastPresentCount )DECLARE_PARAMS( + THIS, + /* [out] */ UINT* pLastPresentCount ); + +// Create vtable offsets +#undef STDMETHOD +#define STDMETHOD(method) PPCAT(PPCAT(PPCAT(vt, INTERFACE),_), method), +#undef STDMETHOD_ +#define STDMETHOD_(type,method) PPCAT(PPCAT(PPCAT(vt, INTERFACE),_), method), + +enum PPCAT( vt, INTERFACE ) +{ + STDMETHOD( QueryInterface ) + STDMETHOD_( ULONG, AddRef ) + STDMETHOD_( ULONG, Release ) + STDMETHOD( SetPrivateData ) + STDMETHOD( SetPrivateDataInterface ) + STDMETHOD( GetPrivateData ) + STDMETHOD( GetParent ) + STDMETHOD( GetDevice ) + STDMETHOD( Present ) + STDMETHOD( GetBuffer ) + STDMETHOD( SetFullscreenState ) + STDMETHOD( GetFullscreenState ) + STDMETHOD( GetDesc ) + STDMETHOD( ResizeBuffers ) + STDMETHOD( ResizeTarget ) + STDMETHOD( GetContainingOutput ) + STDMETHOD( GetFrameStatistics ) + STDMETHOD( GetLastPresentCount ) +}; \ No newline at end of file diff --git a/src/dxgi/dxgiutils.hpp b/src/dxgi/dxgiutils.hpp new file mode 100644 index 0000000..7fa7e64 --- /dev/null +++ b/src/dxgi/dxgiutils.hpp @@ -0,0 +1,55 @@ +#include +#include + +#pragma once + +static string getOutputName( IDXGISwapChain* pSwapChain ) +{ + string sRet = ""; + + if ( pSwapChain ) + { + IDXGIOutput* pOutput = NULL; + pSwapChain->GetContainingOutput( &pOutput ); + + if ( pOutput ) + { + DXGI_OUTPUT_DESC desc; + + if ( SUCCEEDED( pOutput->GetDesc( &desc ) ) ) + { + sRet = PluginManager::UTF82ACP( PluginManager::UCS22UTF8( desc.DeviceName ) ); + } + + SAFE_RELEASE( pOutput ); + } + } + + return sRet; +} + +static string getGPUName( IUnknown* pDevice ) +{ + string sRet = ""; + + IDXGIDevice* pDXGIDevice = NULL; + pDevice->QueryInterface( __uuidof( IDXGIDevice ), ( void** )&pDXGIDevice ); + + if ( pDXGIDevice ) + { + IDXGIAdapter* pDXGIAdapter = NULL; + pDXGIDevice->GetAdapter( &pDXGIAdapter ); + + if ( pDXGIAdapter ) + { + DXGI_ADAPTER_DESC adapterDesc; + pDXGIAdapter->GetDesc( &adapterDesc ); + sRet = PluginManager::UTF82ACP( PluginManager::UCS22UTF8( adapterDesc.Description ) ); + SAFE_RELEASE( pDXGIAdapter ); + } + + SAFE_RELEASE( pDXGIDevice ); + } + + return sRet; +} \ No newline at end of file diff --git a/src/hooktools.h b/src/hooktools.h index 768b630..c81af4a 100644 --- a/src/hooktools.h +++ b/src/hooktools.h @@ -145,7 +145,7 @@ template bool changeVTEx( void** ppVt, vttype n, VirtualProtect( &ppVt[n], sizeof( LPCVOID ), dwOldProtections, &dwOldProtections ); // flush instructions since vtable changed - FlushInstructionCache ( GetCurrentProcess (), NULL, 0 ); + FlushInstructionCache( GetCurrentProcess(), NULL, 0 ); } } @@ -153,6 +153,7 @@ template bool changeVTEx( void** ppVt, vttype n, } #define D3D_TARGETDX9 TEXT("dx9") +#define D3D_TARGETDX10 TEXT("dx10") #define D3D_TARGETDX11 TEXT("dx11") typedef bool( *ptGetVTData )( INT_PTR*, int, void* ); diff --git a/tools/AStyle/AStyle.exe b/tools/AStyle/AStyle.exe new file mode 100644 index 0000000..49d123f Binary files /dev/null and b/tools/AStyle/AStyle.exe differ diff --git a/tools/AStyle/license.html b/tools/AStyle/license.html new file mode 100644 index 0000000..dbfb7c8 --- /dev/null +++ b/tools/AStyle/license.html @@ -0,0 +1,213 @@ + + + + + + Artistic Style License + + + + + + + +

+ Artistic Style License

+ +

+ Artistic Style may be used and/or modified and/or distributed under + the GNU Lesser General Public License (LGPL), as detailed + below. The LGPL is a set of additional permissions added to version 3 of the + GNU General Public License.

+

+  

+ +

+ GNU LESSER GENERAL PUBLIC LICENSE

+ +

+ Version 3, 29 June 2007

+

+ Copyright © 2007 Free Software Foundation, Inc. <http://fsf.org/>

+

+ Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not + allowed.

+

+ This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the + GNU General Public License, supplemented by the additional permissions listed below.

+ +

+ 0. Additional Definitions.

+ +

+ As used herein, “this License” refers to version 3 of the GNU Lesser General Public License, and the + “GNU GPL” refers to version 3 of the GNU General Public License.

+

+ “The Library” refers to a covered work governed by this License, other than an Application or a Combined + Work as defined below.

+

+ An “Application” is any work that makes use of an interface provided by the Library, but which is + not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of + using an interface provided by the Library.

+

+ A “Combined Work” is a work produced by combining or linking an Application with the Library. The + particular version of the Library with which the Combined Work was made is also called the “Linked Version”.

+

+ The “Minimal Corresponding Source” for a Combined Work means the Corresponding Source for the Combined + Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on + the Application, and not on the Linked Version.

+

+ The “Corresponding Application Code” for a Combined Work means the object code and/or source code + for the Application, including any data and utility programs needed for reproducing the Combined Work from the + Application, but excluding the System Libraries of the Combined Work.

+ +

+ 1. Exception to Section 3 of the GNU GPL.

+ +

+ You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU + GPL.

+ +

+ 2. Conveying Modified Versions.

+ +

+ If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be + supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), + then you may convey a copy of the modified version:

+
    +
  • a) under this License, provided that you make a good faith effort to ensure that, in the event an Application + does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains + meaningful, or
  • +
  • b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy.
  • +
+ +

+ 3. Object Code Incorporating Material from Library Header Files.

+ +

+ The object code form of an Application may incorporate material from a header file that is part of the Library. + You may convey such object code under terms of your choice, provided that, if the incorporated material is not + limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates + (ten or fewer lines in length), you do both of the following:

+
    +
  • a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library + and its use are covered by this License.
  • +
  • b) Accompany the object code with a copy of the GNU GPL and this license document.
  • +
+ +

+ 4. Combined Works.

+ +

+ You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification + of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, + if you also do each of the following:

+
    +
  • a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library + and its use are covered by this License.
  • +
  • b) Accompany the Combined Work with a copy of the GNU GPL and this license document.
  • +
  • c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the + Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license + document.
  • +
  • d) Do one of the following: +
      +
    • 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application + Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with + a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section + 6 of the GNU GPL for conveying Corresponding Source.
    • +
    • 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) + uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly + with a modified version of the Library that is interface-compatible with the Linked Version.
    • +
    +
  • +
  • e) Provide Installation Information, but only if you would otherwise be required to provide such information under + section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified + version of the Combined Work produced by recombining or relinking the Application with a modified version of the + Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding + Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information + in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.)
  • +
+ +

+ 5. Combined Libraries.

+ +

+ You may place library facilities that are a work based on the Library side by side in a single library together + with other library facilities that are not Applications and are not covered by this License, and convey such a + combined library under terms of your choice, if you do both of the following:

+
    +
  • a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other + library facilities, conveyed under the terms of this License.
  • +
  • b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work.
  • +
+ +

+ 6. Revised Versions of the GNU Lesser General Public License.

+ +

+ The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License + from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail + to address new problems or concerns.

+

+ Each version is given a distinguishing version number. If the Library as you received it specifies that a certain + numbered version of the GNU Lesser General Public License “or any later version” applies to it, you + have the option of following the terms and conditions either of that published version or of any later version + published by the Free Software Foundation. If the Library as you received it does not specify a version number + of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License + ever published by the Free Software Foundation.

+

+ If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser + General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization + for you to choose that version for the Library.

+

+  

+ +
+ + [SourceForge.net] +
+ +

+  

+ + + + + + + + + + + + + + + diff --git a/tools/AStyle/styles.css b/tools/AStyle/styles.css new file mode 100644 index 0000000..f634b39 --- /dev/null +++ b/tools/AStyle/styles.css @@ -0,0 +1,43 @@ + +/* h1 is a title + * h2 is a subtitle + * h3 is a hanging text title + * h4 is a non-hanging text title + * p.noindent is non-hanging text (text without a title) + * div.code is a light-blue backgroung color for preformatted code + * pre is preformatted source code + * p.contents entries are for the table of contents + * a.contents are table of contents links (not underlined) + * a.links are links (underlined) + * .footer is the image table at the bottom of the page + * img does not have a border + */ + + +body { background-color:white; margin-top:0.5in; margin-right:0.8in; margin-bottom:0.5in; margin-left:1.3in; } + +h1 { color:#0000A0; text-align:center; font-style:italic; margin-top:18pt; margin-left:-0.5in; } +h2.large { color:#0000A0; text-align:center; font-size:x-large; margin-top:0.4in; margin-left:-0.5in; } +h2 { color:#0000A0; text-align:center; font-size:larger; margin-top:0.4in; margin-left:-0.5in; } +h3 { color:#0000A0; margin-top:0.4in; margin-left:-0.4in; } +h4 { color:#0000A0; } + +p.noindent { margin-left:-0.4in; } + +div.code { background:#E0E8FF; } +pre { margin-left:0.3in; } +/* pre.em { background:#FDFCFF; margin-right:0.3in;} */ + +p.contents1 { font-size:105%; margin-top:0in; margin-left:0in; margin-bottom:0in; margin-right:0in; } +p.contents2 { margin-top:0in; margin-left:.4in; margin-bottom:0in; margin-right:.4in; } +/* p.contents3 { margin-top:0in; margin-left:.8in; margin-bottom:0in; margin-right:.8in; } */ +a.contents:link, a.contents:visited { color:#0000A0; text-decoration:none; } +a.contents:hover { color:#F00000; text-decoration:none; } + +a:link, a:visited { color:#0000A0; text-decoration:underline; } +a:hover { color:#F00000; text-decoration:underline; } + +center.footer { margin-left:-0.4in; margin-top:0.25in; } +h2.footer { font-size:x-large; margin-top:0; margin-left:0; } + +img { border:none; } diff --git a/tools/D3D_Installer.nsi b/tools/D3D_Installer.nsi index c8a53ce..3bfb6ab 100644 --- a/tools/D3D_Installer.nsi +++ b/tools/D3D_Installer.nsi @@ -6,7 +6,7 @@ ################################## XPStyle on -!define VERSION "1.9.0.0" +!define VERSION "2.0.0.0" Name "D3D Plugin ${VERSION} for CryEngine" ; The file to write diff --git a/tools/_astyle.exe b/tools/_astyle.exe deleted file mode 100644 index 115dd67..0000000 Binary files a/tools/_astyle.exe and /dev/null differ diff --git a/tools/_stylehelper.bat b/tools/_stylehelper.bat deleted file mode 100644 index 22404a7..0000000 --- a/tools/_stylehelper.bat +++ /dev/null @@ -1,42 +0,0 @@ -@echo off - -IF (%1)==() GOTO error -dir /b /ad %1 >nul 2>nul && GOTO indentDir -IF NOT EXIST %1 GOTO error -goto indentFile - -:indentDir -set searchdir=%1 - -IF (%2)==() GOTO assignDefaultSuffix -set filesuffix=%2 - -GOTO run - -:assignDefaultSuffix -::echo !!!!DEFAULT SUFFIX!!! -set filesuffix=* - -:run -FOR /F "tokens=*" %%G IN ('DIR /B /S %searchdir%\*.%filesuffix%') DO ( -echo Indenting file "%%G" -"_astyle.exe" "%%G" --options="codestyle.astylerc" -) -GOTO ende - -:indentFile -echo Indenting one file %1 -"_astyle.exe" "%1" --options="codestyle.astylerc" - - -GOTO ende - -:error -echo . -echo ERROR: As parameter given directory or file does not exist! -echo Syntax is: call_Artistic_Style.bat dirname filesuffix -echo Syntax is: call_Artistic_Style.bat filename -echo Example: call_Artistic_Style.bat temp cpp -echo . - -:ende diff --git a/tools/codestyle.astylerc b/tools/codestyle.astylerc index 5f110f6..a86224f 100644 --- a/tools/codestyle.astylerc +++ b/tools/codestyle.astylerc @@ -3,12 +3,14 @@ --indent-cases --indent-namespaces --indent-classes ---indent-preprocessor +--indent-preproc-define --indent-col1-comments +--indent-modifiers --max-instatement-indent=40 --break-blocks=all --pad-oper --pad-header +--unpad-paren --pad-paren-in --add-brackets --align-pointer=type @@ -18,3 +20,4 @@ --lineend=windows --mode=c --suffix=none +--close-templates diff --git a/tools/stylecode.bat b/tools/stylecode.bat index e18ffc2..4162a4b 100644 --- a/tools/stylecode.bat +++ b/tools/stylecode.bat @@ -1,10 +1,18 @@ -@echo off +@echo OFF -cmd /C "_stylehelper.bat ..\src cpp" -cmd /C "_stylehelper.bat ..\src h" -cmd /C "_stylehelper.bat ..\src hpp" -cmd /C "_stylehelper.bat ..\inc cpp" -cmd /C "_stylehelper.bat ..\inc h" -cmd /C "_stylehelper.bat ..\inc hpp" +set ASTYLE=%~dp0AStyle\AStyle.exe +set APROFILE=%~dp0codestyle.astylerc -pause \ No newline at end of file +:: Use a personal style or a style suitable for source control / team? +if not (%~1)==() ( + set APROFILE=%~1 +) + +:: Now indent the files + +set EXTENSIONS=h hpp c cc cpp + +FOR %%i IN (%EXTENSIONS%) DO ( + "%ASTYLE%" --options="%APROFILE%" -RnqZ %~dp0..\src\*.%%i 2> nul + "%ASTYLE%" --options="%APROFILE%" -RnqZ %~dp0..\inc\*.%%i 2> nul +)