├── premake5.bat ├── premake5.exe ├── source ├── VersionInfo.h ├── VersionInfo.rc ├── dxsdk │ ├── lib │ │ ├── x64 │ │ │ └── d3dx9.lib │ │ └── x86 │ │ │ └── d3dx9.lib │ ├── d3dx9.h │ ├── d3dx9shape.h │ ├── d3dx9xof.h │ └── d3dx9core.h ├── d3d9.def ├── IDirect3DStateBlock9.h ├── License.txt ├── IDirect3DPixelShader9.h ├── IDirect3DVertexShader9.h ├── IDirect3DVertexDeclaration9.h ├── IDirect3DQuery9.h ├── IDirect3DVolume9.h ├── IDirect3DIndexBuffer9.h ├── IDirect3DVertexBuffer9.h ├── IDirect3DSurface9.h ├── IDirect3DSwapChain9Ex.h ├── IDirect3DTexture9.h ├── IDirect3DVolumeTexture9.h ├── IDirect3DPixelShader9.cpp ├── IDirect3DVertexShader9.cpp ├── IDirect3DCubeTexture9.h ├── IDirect3DStateBlock9.cpp ├── IDirect3DVertexDeclaration9.cpp ├── d3d9.h ├── IDirect3DQuery9.cpp ├── IDirect3D9Ex.h ├── InterfaceQuery.cpp ├── IDirect3DVolume9.cpp ├── IDirect3DIndexBuffer9.cpp ├── IDirect3DVertexBuffer9.cpp ├── IDirect3DSurface9.cpp ├── IDirect3DSwapChain9Ex.cpp ├── AddressLookupTable.h ├── IDirect3DTexture9.cpp ├── IDirect3DVolumeTexture9.cpp ├── IDirect3DCubeTexture9.cpp ├── IDirect3D9Ex.cpp ├── helpers.h ├── iathook.h ├── launcher │ └── d3d9-wrapper-launcher.c └── IDirect3DDevice9Ex.h ├── .gitattributes ├── appveyor.yml ├── data └── d3d9.ini ├── license ├── premake5.lua └── .gitignore /premake5.bat: -------------------------------------------------------------------------------- 1 | premake5 vs2022 -------------------------------------------------------------------------------- /premake5.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThirteenAG/d3d9-wrapper/HEAD/premake5.exe -------------------------------------------------------------------------------- /source/VersionInfo.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThirteenAG/d3d9-wrapper/HEAD/source/VersionInfo.h -------------------------------------------------------------------------------- /source/VersionInfo.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThirteenAG/d3d9-wrapper/HEAD/source/VersionInfo.rc -------------------------------------------------------------------------------- /source/dxsdk/lib/x64/d3dx9.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThirteenAG/d3d9-wrapper/HEAD/source/dxsdk/lib/x64/d3dx9.lib -------------------------------------------------------------------------------- /source/dxsdk/lib/x86/d3dx9.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThirteenAG/d3d9-wrapper/HEAD/source/dxsdk/lib/x86/d3dx9.lib -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /source/d3d9.def: -------------------------------------------------------------------------------- 1 | LIBRARY d3d9 2 | EXPORTS 3 | 4 | Direct3DShaderValidatorCreate9 @19 5 | PSGPError @20 6 | PSGPSampleTexture @21 7 | D3DPERF_BeginEvent @22 8 | D3DPERF_EndEvent @23 9 | D3DPERF_GetStatus @24 10 | D3DPERF_QueryRepeatFrame @25 11 | D3DPERF_SetMarker @26 12 | D3DPERF_SetOptions @27 13 | D3DPERF_SetRegion @28 14 | DebugSetLevel @29 15 | DebugSetMute @30 16 | Direct3D9EnableMaximizedWindowedModeShim @31 17 | Direct3DCreate9 @32 18 | Direct3DCreate9Ex @33 19 | -------------------------------------------------------------------------------- /source/IDirect3DStateBlock9.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class m_IDirect3DStateBlock9 : public IDirect3DStateBlock9, public AddressLookupTableObject 4 | { 5 | private: 6 | LPDIRECT3DSTATEBLOCK9 ProxyInterface; 7 | m_IDirect3DDevice9Ex* m_pDeviceEx = nullptr; 8 | 9 | public: 10 | m_IDirect3DStateBlock9(LPDIRECT3DSTATEBLOCK9 pBlock9, m_IDirect3DDevice9Ex* pDevice) : ProxyInterface(pBlock9), m_pDeviceEx(pDevice) 11 | { 12 | pDevice->ProxyAddressLookupTable->SaveAddress(this, ProxyInterface); 13 | } 14 | ~m_IDirect3DStateBlock9() {} 15 | 16 | LPDIRECT3DSTATEBLOCK9 GetProxyInterface() { return ProxyInterface; } 17 | 18 | /*** IUnknown methods ***/ 19 | STDMETHOD(QueryInterface)(THIS_ REFIID riid, void** ppvObj); 20 | STDMETHOD_(ULONG, AddRef)(THIS); 21 | STDMETHOD_(ULONG, Release)(THIS); 22 | 23 | /*** IDirect3DStateBlock9 methods ***/ 24 | STDMETHOD(GetDevice)(THIS_ IDirect3DDevice9** ppDevice); 25 | STDMETHOD(Capture)(THIS); 26 | STDMETHOD(Apply)(THIS); 27 | }; 28 | -------------------------------------------------------------------------------- /source/License.txt: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2020 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ -------------------------------------------------------------------------------- /source/IDirect3DPixelShader9.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class m_IDirect3DPixelShader9 : public IDirect3DPixelShader9, public AddressLookupTableObject 4 | { 5 | private: 6 | LPDIRECT3DPIXELSHADER9 ProxyInterface; 7 | m_IDirect3DDevice9Ex* m_pDeviceEx = nullptr; 8 | 9 | public: 10 | m_IDirect3DPixelShader9(LPDIRECT3DPIXELSHADER9 pShader9, m_IDirect3DDevice9Ex* pDevice) : ProxyInterface(pShader9), m_pDeviceEx(pDevice) 11 | { 12 | pDevice->ProxyAddressLookupTable->SaveAddress(this, ProxyInterface); 13 | } 14 | ~m_IDirect3DPixelShader9() {} 15 | 16 | LPDIRECT3DPIXELSHADER9 GetProxyInterface() { return ProxyInterface; } 17 | 18 | /*** IUnknown methods ***/ 19 | STDMETHOD(QueryInterface)(THIS_ REFIID riid, void** ppvObj); 20 | STDMETHOD_(ULONG, AddRef)(THIS); 21 | STDMETHOD_(ULONG, Release)(THIS); 22 | 23 | /*** IDirect3DPixelShader9 methods ***/ 24 | STDMETHOD(GetDevice)(THIS_ IDirect3DDevice9** ppDevice); 25 | STDMETHOD(GetFunction)(THIS_ void* pData, UINT* pSizeOfData); 26 | }; 27 | -------------------------------------------------------------------------------- /source/IDirect3DVertexShader9.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class m_IDirect3DVertexShader9 : public IDirect3DVertexShader9, public AddressLookupTableObject 4 | { 5 | private: 6 | LPDIRECT3DVERTEXSHADER9 ProxyInterface; 7 | m_IDirect3DDevice9Ex* m_pDeviceEx = nullptr; 8 | 9 | public: 10 | m_IDirect3DVertexShader9(LPDIRECT3DVERTEXSHADER9 pShader9, m_IDirect3DDevice9Ex* pDevice) : ProxyInterface(pShader9), m_pDeviceEx(pDevice) 11 | { 12 | pDevice->ProxyAddressLookupTable->SaveAddress(this, ProxyInterface); 13 | } 14 | ~m_IDirect3DVertexShader9() {} 15 | 16 | LPDIRECT3DVERTEXSHADER9 GetProxyInterface() { return ProxyInterface; } 17 | 18 | /*** IUnknown methods ***/ 19 | STDMETHOD(QueryInterface)(THIS_ REFIID riid, void** ppvObj); 20 | STDMETHOD_(ULONG, AddRef)(THIS); 21 | STDMETHOD_(ULONG, Release)(THIS); 22 | 23 | /*** IDirect3DVertexShader9 methods ***/ 24 | STDMETHOD(GetDevice)(THIS_ IDirect3DDevice9** ppDevice); 25 | STDMETHOD(GetFunction)(THIS_ void* pData, UINT* pSizeOfData); 26 | }; 27 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: 1.{build} 2 | skip_tags: true 3 | image: Visual Studio 2022 4 | configuration: Release 5 | platform: 6 | - Win32 7 | - Win64 8 | install: 9 | - cmd: premake5.bat 10 | build: 11 | project: build/d3d9-wrapper.sln 12 | verbosity: minimal 13 | for: 14 | - 15 | matrix: 16 | only: 17 | - platform: Win32 18 | after_build: 19 | - cmd: 7z a d3d9.zip %APPVEYOR_BUILD_FOLDER%\data\d3d9.dll %APPVEYOR_BUILD_FOLDER%\data\d3d9.ini 20 | artifacts: 21 | - path: d3d9.zip 22 | name: d3d9 23 | - 24 | matrix: 25 | only: 26 | - platform: Win64 27 | after_build: 28 | - cmd: 7z a d3d9_x64.zip %APPVEYOR_BUILD_FOLDER%\data\x64\d3d9.dll %APPVEYOR_BUILD_FOLDER%\data\d3d9.ini 29 | artifacts: 30 | - path: d3d9_x64.zip 31 | name: d3d9_x64 32 | deploy: 33 | - provider: GitHub 34 | release: d3d9-wrapper v$(appveyor_build_version) 35 | auth_token: 36 | secure: ugbti+bXX/7zqu39OyiPxgRPd2pQn2FEV/12ABees2fHfpZob0tWXzqD/zSYmibJ 37 | artifact: d3d9.zip,d3d9_x64.zip 38 | matrix: 39 | fast_finish: true 40 | -------------------------------------------------------------------------------- /source/IDirect3DVertexDeclaration9.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class m_IDirect3DVertexDeclaration9 : public IDirect3DVertexDeclaration9, public AddressLookupTableObject 4 | { 5 | private: 6 | LPDIRECT3DVERTEXDECLARATION9 ProxyInterface; 7 | m_IDirect3DDevice9Ex* m_pDeviceEx = nullptr; 8 | 9 | public: 10 | m_IDirect3DVertexDeclaration9(LPDIRECT3DVERTEXDECLARATION9 pDeclaration9, m_IDirect3DDevice9Ex* pDevice) : ProxyInterface(pDeclaration9), m_pDeviceEx(pDevice) 11 | { 12 | pDevice->ProxyAddressLookupTable->SaveAddress(this, ProxyInterface); 13 | } 14 | ~m_IDirect3DVertexDeclaration9() {} 15 | 16 | LPDIRECT3DVERTEXDECLARATION9 GetProxyInterface() { return ProxyInterface; } 17 | 18 | /*** IUnknown methods ***/ 19 | STDMETHOD(QueryInterface)(THIS_ REFIID riid, void** ppvObj); 20 | STDMETHOD_(ULONG, AddRef)(THIS); 21 | STDMETHOD_(ULONG, Release)(THIS); 22 | 23 | /*** IDirect3DVertexDeclaration9 methods ***/ 24 | STDMETHOD(GetDevice)(THIS_ IDirect3DDevice9** ppDevice); 25 | STDMETHOD(GetDeclaration)(THIS_ D3DVERTEXELEMENT9* pElement, UINT* pNumElements); 26 | }; 27 | -------------------------------------------------------------------------------- /source/IDirect3DQuery9.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class m_IDirect3DQuery9 : public IDirect3DQuery9, public AddressLookupTableObject 4 | { 5 | private: 6 | LPDIRECT3DQUERY9 ProxyInterface; 7 | m_IDirect3DDevice9Ex* m_pDeviceEx = nullptr; 8 | 9 | public: 10 | m_IDirect3DQuery9(LPDIRECT3DQUERY9 pQuery9, m_IDirect3DDevice9Ex* pDevice) : ProxyInterface(pQuery9), m_pDeviceEx(pDevice) 11 | { 12 | pDevice->ProxyAddressLookupTable->SaveAddress(this, ProxyInterface); 13 | } 14 | ~m_IDirect3DQuery9() {} 15 | 16 | LPDIRECT3DQUERY9 GetProxyInterface() { return ProxyInterface; } 17 | 18 | /*** IUnknown methods ***/ 19 | STDMETHOD(QueryInterface)(THIS_ REFIID riid, void** ppvObj); 20 | STDMETHOD_(ULONG, AddRef)(THIS); 21 | STDMETHOD_(ULONG, Release)(THIS); 22 | 23 | /*** IDirect3DQuery9 methods ***/ 24 | STDMETHOD(GetDevice)(THIS_ IDirect3DDevice9** ppDevice); 25 | STDMETHOD_(D3DQUERYTYPE, GetType)(THIS); 26 | STDMETHOD_(DWORD, GetDataSize)(THIS); 27 | STDMETHOD(Issue)(THIS_ DWORD dwIssueFlags); 28 | STDMETHOD(GetData)(THIS_ void* pData, DWORD dwSize, DWORD dwGetDataFlags); 29 | }; 30 | -------------------------------------------------------------------------------- /data/d3d9.ini: -------------------------------------------------------------------------------- 1 | [MAIN] 2 | FPSLimit = 0 // max fps (0: unlimited/off) 3 | FPSLimitMode = 2 // 1: realtime (thread-lock) | 2: accurate (sleep-yield) 4 | FullScreenRefreshRateInHz = 0 // overrides refresh rate selected by directx 5 | DisplayFPSCounter = 0 // displays fps and frametime on screen 6 | ForceWindowedMode = 0 // activates forced windowed mode 7 | EnableHooks = 0 // needed for DoNotNotifyOnTaskSwitch, might need for CaptureMouse 8 | 9 | [FORCEWINDOWED] 10 | UsePrimaryMonitor = 0 // move window to primary monitor 11 | CenterWindow = 1 // center window on screen 12 | AlwaysOnTop = 0 // window stays always on top 13 | DoNotNotifyOnTaskSwitch = 0 // window ignores focus loss 14 | ForceWindowStyle = 0 // 0: no change | 1: borderless fullscreen | 2: window | 3: resizable window | 4: no style 15 | CaptureMouse = 0 // capture mouse to window 16 | 17 | [LAUNCHER] 18 | AppExe = 19 | AppArgs = 20 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /source/IDirect3DVolume9.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class m_IDirect3DVolume9 : public IDirect3DVolume9, public AddressLookupTableObject 4 | { 5 | private: 6 | LPDIRECT3DVOLUME9 ProxyInterface; 7 | m_IDirect3DDevice9Ex* m_pDeviceEx = nullptr; 8 | 9 | public: 10 | m_IDirect3DVolume9(LPDIRECT3DVOLUME9 pVolume8, m_IDirect3DDevice9Ex* pDevice) : ProxyInterface(pVolume8), m_pDeviceEx(pDevice) 11 | { 12 | pDevice->ProxyAddressLookupTable->SaveAddress(this, ProxyInterface); 13 | } 14 | ~m_IDirect3DVolume9() {} 15 | 16 | LPDIRECT3DVOLUME9 GetProxyInterface() { return ProxyInterface; } 17 | 18 | /*** IUnknown methods ***/ 19 | STDMETHOD(QueryInterface)(THIS_ REFIID riid, void** ppvObj); 20 | STDMETHOD_(ULONG, AddRef)(THIS); 21 | STDMETHOD_(ULONG, Release)(THIS); 22 | 23 | /*** IDirect3DVolume9 methods ***/ 24 | STDMETHOD(GetDevice)(THIS_ IDirect3DDevice9** ppDevice); 25 | STDMETHOD(SetPrivateData)(THIS_ REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags); 26 | STDMETHOD(GetPrivateData)(THIS_ REFGUID refguid, void* pData, DWORD* pSizeOfData); 27 | STDMETHOD(FreePrivateData)(THIS_ REFGUID refguid); 28 | STDMETHOD(GetContainer)(THIS_ REFIID riid, void** ppContainer); 29 | STDMETHOD(GetDesc)(THIS_ D3DVOLUME_DESC *pDesc); 30 | STDMETHOD(LockBox)(THIS_ D3DLOCKED_BOX * pLockedVolume, CONST D3DBOX* pBox, DWORD Flags); 31 | STDMETHOD(UnlockBox)(THIS); 32 | }; 33 | -------------------------------------------------------------------------------- /source/IDirect3DIndexBuffer9.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class m_IDirect3DIndexBuffer9 : public IDirect3DIndexBuffer9, public AddressLookupTableObject 4 | { 5 | private: 6 | LPDIRECT3DINDEXBUFFER9 ProxyInterface; 7 | m_IDirect3DDevice9Ex* m_pDeviceEx = nullptr; 8 | 9 | public: 10 | m_IDirect3DIndexBuffer9(LPDIRECT3DINDEXBUFFER9 pBuffer9, m_IDirect3DDevice9Ex* pDevice) : ProxyInterface(pBuffer9), m_pDeviceEx(pDevice) 11 | { 12 | pDevice->ProxyAddressLookupTable->SaveAddress(this, ProxyInterface); 13 | } 14 | ~m_IDirect3DIndexBuffer9() {} 15 | 16 | LPDIRECT3DINDEXBUFFER9 GetProxyInterface() { return ProxyInterface; } 17 | 18 | /*** IUnknown methods ***/ 19 | STDMETHOD(QueryInterface)(THIS_ REFIID riid, void** ppvObj); 20 | STDMETHOD_(ULONG, AddRef)(THIS); 21 | STDMETHOD_(ULONG, Release)(THIS); 22 | 23 | /*** IDirect3DResource9 methods ***/ 24 | STDMETHOD(GetDevice)(THIS_ IDirect3DDevice9** ppDevice); 25 | STDMETHOD(SetPrivateData)(THIS_ REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags); 26 | STDMETHOD(GetPrivateData)(THIS_ REFGUID refguid, void* pData, DWORD* pSizeOfData); 27 | STDMETHOD(FreePrivateData)(THIS_ REFGUID refguid); 28 | STDMETHOD_(DWORD, SetPriority)(THIS_ DWORD PriorityNew); 29 | STDMETHOD_(DWORD, GetPriority)(THIS); 30 | STDMETHOD_(void, PreLoad)(THIS); 31 | STDMETHOD_(D3DRESOURCETYPE, GetType)(THIS); 32 | STDMETHOD(Lock)(THIS_ UINT OffsetToLock, UINT SizeToLock, void** ppbData, DWORD Flags); 33 | STDMETHOD(Unlock)(THIS); 34 | STDMETHOD(GetDesc)(THIS_ D3DINDEXBUFFER_DESC *pDesc); 35 | }; 36 | -------------------------------------------------------------------------------- /source/IDirect3DVertexBuffer9.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class m_IDirect3DVertexBuffer9 : public IDirect3DVertexBuffer9, public AddressLookupTableObject 4 | { 5 | private: 6 | LPDIRECT3DVERTEXBUFFER9 ProxyInterface; 7 | m_IDirect3DDevice9Ex* m_pDeviceEx = nullptr; 8 | 9 | public: 10 | m_IDirect3DVertexBuffer9(LPDIRECT3DVERTEXBUFFER9 pBuffer8, m_IDirect3DDevice9Ex* pDevice) : ProxyInterface(pBuffer8), m_pDeviceEx(pDevice) 11 | { 12 | pDevice->ProxyAddressLookupTable->SaveAddress(this, ProxyInterface); 13 | } 14 | ~m_IDirect3DVertexBuffer9() {} 15 | 16 | LPDIRECT3DVERTEXBUFFER9 GetProxyInterface() { return ProxyInterface; } 17 | 18 | /*** IUnknown methods ***/ 19 | STDMETHOD(QueryInterface)(THIS_ REFIID riid, void** ppvObj); 20 | STDMETHOD_(ULONG, AddRef)(THIS); 21 | STDMETHOD_(ULONG, Release)(THIS); 22 | 23 | /*** IDirect3DResource9 methods ***/ 24 | STDMETHOD(GetDevice)(THIS_ IDirect3DDevice9** ppDevice); 25 | STDMETHOD(SetPrivateData)(THIS_ REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags); 26 | STDMETHOD(GetPrivateData)(THIS_ REFGUID refguid, void* pData, DWORD* pSizeOfData); 27 | STDMETHOD(FreePrivateData)(THIS_ REFGUID refguid); 28 | STDMETHOD_(DWORD, SetPriority)(THIS_ DWORD PriorityNew); 29 | STDMETHOD_(DWORD, GetPriority)(THIS); 30 | STDMETHOD_(void, PreLoad)(THIS); 31 | STDMETHOD_(D3DRESOURCETYPE, GetType)(THIS); 32 | STDMETHOD(Lock)(THIS_ UINT OffsetToLock, UINT SizeToLock, void** ppbData, DWORD Flags); 33 | STDMETHOD(Unlock)(THIS); 34 | STDMETHOD(GetDesc)(THIS_ D3DVERTEXBUFFER_DESC *pDesc); 35 | }; 36 | -------------------------------------------------------------------------------- /premake5.lua: -------------------------------------------------------------------------------- 1 | workspace "d3d9-wrapper" 2 | configurations { "Release", "Debug" } 3 | platforms { "Win32", "Win64" } 4 | location "build" 5 | objdir ("build/obj") 6 | buildlog ("build/log/%{prj.name}.log") 7 | buildoptions {"-std:c++latest"} 8 | 9 | kind "SharedLib" 10 | language "C++" 11 | targetname "d3d9" 12 | targetextension ".dll" 13 | characterset ("MBCS") 14 | staticruntime "On" 15 | 16 | defines { "rsc_CompanyName=\"ThirteenAG\"" } 17 | defines { "rsc_LegalCopyright=\"MIT License\""} 18 | defines { "rsc_FileVersion=\"1.0.0.0\"", "rsc_ProductVersion=\"1.0.0.0\"" } 19 | defines { "rsc_InternalName=\"%{prj.name}\"", "rsc_ProductName=\"%{prj.name}\"", "rsc_OriginalFilename=\"d3d9.dll\"" } 20 | defines { "rsc_FileDescription=\"https://thirteenag.github.io/wfp\"" } 21 | defines { "rsc_UpdateUrl=\"https://github.com/ThirteenAG/%{prj.name}\"" } 22 | 23 | files { "source/*.h", "source/*.cpp" } 24 | files { "source/*.def" } 25 | files { "source/*.rc" } 26 | includedirs { "source/dxsdk" } 27 | 28 | filter "configurations:Debug" 29 | defines "DEBUG" 30 | symbols "On" 31 | 32 | filter "configurations:Release" 33 | defines "NDEBUG" 34 | optimize "On" 35 | 36 | filter "platforms:Win32" 37 | architecture "x32" 38 | targetdir "data" 39 | libdirs { "source/dxsdk/lib/x86" } 40 | 41 | filter "platforms:Win64" 42 | architecture "x64" 43 | targetdir "data/x64" 44 | libdirs { "source/dxsdk/lib/x64" } 45 | 46 | project "d3d9-wrapper" 47 | -------------------------------------------------------------------------------- /source/IDirect3DSurface9.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class m_IDirect3DSurface9 : public IDirect3DSurface9, public AddressLookupTableObject 4 | { 5 | private: 6 | LPDIRECT3DSURFACE9 ProxyInterface; 7 | m_IDirect3DDevice9Ex* m_pDeviceEx = nullptr; 8 | 9 | public: 10 | m_IDirect3DSurface9(LPDIRECT3DSURFACE9 pSurface9, m_IDirect3DDevice9Ex* pDevice) : ProxyInterface(pSurface9), m_pDeviceEx(pDevice) 11 | { 12 | pDevice->ProxyAddressLookupTable->SaveAddress(this, ProxyInterface); 13 | } 14 | ~m_IDirect3DSurface9() {} 15 | 16 | LPDIRECT3DSURFACE9 GetProxyInterface() { return ProxyInterface; } 17 | 18 | /*** IUnknown methods ***/ 19 | STDMETHOD(QueryInterface)(THIS_ REFIID riid, void** ppvObj); 20 | STDMETHOD_(ULONG, AddRef)(THIS); 21 | STDMETHOD_(ULONG, Release)(THIS); 22 | 23 | /*** IDirect3DResource9 methods ***/ 24 | STDMETHOD(GetDevice)(THIS_ IDirect3DDevice9** ppDevice); 25 | STDMETHOD(SetPrivateData)(THIS_ REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags); 26 | STDMETHOD(GetPrivateData)(THIS_ REFGUID refguid, void* pData, DWORD* pSizeOfData); 27 | STDMETHOD(FreePrivateData)(THIS_ REFGUID refguid); 28 | STDMETHOD_(DWORD, SetPriority)(THIS_ DWORD PriorityNew); 29 | STDMETHOD_(DWORD, GetPriority)(THIS); 30 | STDMETHOD_(void, PreLoad)(THIS); 31 | STDMETHOD_(D3DRESOURCETYPE, GetType)(THIS); 32 | STDMETHOD(GetContainer)(THIS_ REFIID riid, void** ppContainer); 33 | STDMETHOD(GetDesc)(THIS_ D3DSURFACE_DESC *pDesc); 34 | STDMETHOD(LockRect)(THIS_ D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags); 35 | STDMETHOD(UnlockRect)(THIS); 36 | STDMETHOD(GetDC)(THIS_ HDC *phdc); 37 | STDMETHOD(ReleaseDC)(THIS_ HDC hdc); 38 | }; 39 | -------------------------------------------------------------------------------- /source/IDirect3DSwapChain9Ex.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class m_IDirect3DSwapChain9Ex : public IDirect3DSwapChain9Ex, public AddressLookupTableObject 4 | { 5 | private: 6 | LPDIRECT3DSWAPCHAIN9EX ProxyInterface; 7 | m_IDirect3DDevice9Ex* m_pDeviceEx = nullptr; 8 | REFIID WrapperID; 9 | 10 | public: 11 | m_IDirect3DSwapChain9Ex(LPDIRECT3DSWAPCHAIN9EX pSwapChain9, m_IDirect3DDevice9Ex* pDevice, REFIID DeviceID = IID_IDirect3DSwapChain9) : ProxyInterface(pSwapChain9), m_pDeviceEx(pDevice), WrapperID(DeviceID) 12 | { 13 | pDevice->ProxyAddressLookupTable->SaveAddress(this, ProxyInterface); 14 | } 15 | ~m_IDirect3DSwapChain9Ex() {} 16 | 17 | LPDIRECT3DSWAPCHAIN9EX GetProxyInterface() { return ProxyInterface; } 18 | 19 | /*** IUnknown methods ***/ 20 | STDMETHOD(QueryInterface)(THIS_ REFIID riid, void** ppvObj); 21 | STDMETHOD_(ULONG, AddRef)(THIS); 22 | STDMETHOD_(ULONG, Release)(THIS); 23 | 24 | /*** IDirect3DSwapChain9 methods ***/ 25 | STDMETHOD(Present)(THIS_ CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion, DWORD dwFlags); 26 | STDMETHOD(GetFrontBufferData)(THIS_ IDirect3DSurface9* pDestSurface); 27 | STDMETHOD(GetBackBuffer)(THIS_ UINT iBackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface9** ppBackBuffer); 28 | STDMETHOD(GetRasterStatus)(THIS_ D3DRASTER_STATUS* pRasterStatus); 29 | STDMETHOD(GetDisplayMode)(THIS_ D3DDISPLAYMODE* pMode); 30 | STDMETHOD(GetDevice)(THIS_ IDirect3DDevice9** ppDevice); 31 | STDMETHOD(GetPresentParameters)(THIS_ D3DPRESENT_PARAMETERS* pPresentationParameters); 32 | STDMETHOD(GetLastPresentCount)(THIS_ UINT* pLastPresentCount); 33 | STDMETHOD(GetPresentStats)(THIS_ D3DPRESENTSTATS* pPresentationStatistics); 34 | STDMETHOD(GetDisplayModeEx)(THIS_ D3DDISPLAYMODEEX* pMode, D3DDISPLAYROTATION* pRotation); 35 | }; 36 | -------------------------------------------------------------------------------- /source/IDirect3DTexture9.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class m_IDirect3DTexture9 : public IDirect3DTexture9, public AddressLookupTableObject 4 | { 5 | private: 6 | LPDIRECT3DTEXTURE9 ProxyInterface; 7 | m_IDirect3DDevice9Ex* m_pDeviceEx = nullptr; 8 | 9 | public: 10 | m_IDirect3DTexture9(LPDIRECT3DTEXTURE9 pTexture9, m_IDirect3DDevice9Ex* pDevice) : ProxyInterface(pTexture9), m_pDeviceEx(pDevice) 11 | { 12 | pDevice->ProxyAddressLookupTable->SaveAddress(this, ProxyInterface); 13 | } 14 | ~m_IDirect3DTexture9() {} 15 | 16 | LPDIRECT3DTEXTURE9 GetProxyInterface() { return ProxyInterface; } 17 | 18 | /*** IUnknown methods ***/ 19 | STDMETHOD(QueryInterface)(THIS_ REFIID riid, void** ppvObj); 20 | STDMETHOD_(ULONG, AddRef)(THIS); 21 | STDMETHOD_(ULONG, Release)(THIS); 22 | 23 | /*** IDirect3DBaseTexture9 methods ***/ 24 | STDMETHOD(GetDevice)(THIS_ IDirect3DDevice9** ppDevice); 25 | STDMETHOD(SetPrivateData)(THIS_ REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags); 26 | STDMETHOD(GetPrivateData)(THIS_ REFGUID refguid, void* pData, DWORD* pSizeOfData); 27 | STDMETHOD(FreePrivateData)(THIS_ REFGUID refguid); 28 | STDMETHOD_(DWORD, SetPriority)(THIS_ DWORD PriorityNew); 29 | STDMETHOD_(DWORD, GetPriority)(THIS); 30 | STDMETHOD_(void, PreLoad)(THIS); 31 | STDMETHOD_(D3DRESOURCETYPE, GetType)(THIS); 32 | STDMETHOD_(DWORD, SetLOD)(THIS_ DWORD LODNew); 33 | STDMETHOD_(DWORD, GetLOD)(THIS); 34 | STDMETHOD_(DWORD, GetLevelCount)(THIS); 35 | STDMETHOD(SetAutoGenFilterType)(THIS_ D3DTEXTUREFILTERTYPE FilterType); 36 | STDMETHOD_(D3DTEXTUREFILTERTYPE, GetAutoGenFilterType)(THIS); 37 | STDMETHOD_(void, GenerateMipSubLevels)(THIS); 38 | STDMETHOD(GetLevelDesc)(THIS_ UINT Level, D3DSURFACE_DESC *pDesc); 39 | STDMETHOD(GetSurfaceLevel)(THIS_ UINT Level, IDirect3DSurface9** ppSurfaceLevel); 40 | STDMETHOD(LockRect)(THIS_ UINT Level, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags); 41 | STDMETHOD(UnlockRect)(THIS_ UINT Level); 42 | STDMETHOD(AddDirtyRect)(THIS_ CONST RECT* pDirtyRect); 43 | }; 44 | -------------------------------------------------------------------------------- /source/IDirect3DVolumeTexture9.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class m_IDirect3DVolumeTexture9 : public IDirect3DVolumeTexture9, public AddressLookupTableObject 4 | { 5 | private: 6 | LPDIRECT3DVOLUMETEXTURE9 ProxyInterface; 7 | m_IDirect3DDevice9Ex* m_pDeviceEx = nullptr; 8 | 9 | public: 10 | m_IDirect3DVolumeTexture9(LPDIRECT3DVOLUMETEXTURE9 pTexture8, m_IDirect3DDevice9Ex* pDevice) : ProxyInterface(pTexture8), m_pDeviceEx(pDevice) 11 | { 12 | pDevice->ProxyAddressLookupTable->SaveAddress(this, ProxyInterface); 13 | } 14 | ~m_IDirect3DVolumeTexture9() {} 15 | 16 | LPDIRECT3DVOLUMETEXTURE9 GetProxyInterface() { return ProxyInterface; } 17 | 18 | /*** IUnknown methods ***/ 19 | STDMETHOD(QueryInterface)(THIS_ REFIID riid, void** ppvObj); 20 | STDMETHOD_(ULONG, AddRef)(THIS); 21 | STDMETHOD_(ULONG, Release)(THIS); 22 | 23 | /*** IDirect3DBaseTexture9 methods ***/ 24 | STDMETHOD(GetDevice)(THIS_ IDirect3DDevice9** ppDevice); 25 | STDMETHOD(SetPrivateData)(THIS_ REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags); 26 | STDMETHOD(GetPrivateData)(THIS_ REFGUID refguid, void* pData, DWORD* pSizeOfData); 27 | STDMETHOD(FreePrivateData)(THIS_ REFGUID refguid); 28 | STDMETHOD_(DWORD, SetPriority)(THIS_ DWORD PriorityNew); 29 | STDMETHOD_(DWORD, GetPriority)(THIS); 30 | STDMETHOD_(void, PreLoad)(THIS); 31 | STDMETHOD_(D3DRESOURCETYPE, GetType)(THIS); 32 | STDMETHOD_(DWORD, SetLOD)(THIS_ DWORD LODNew); 33 | STDMETHOD_(DWORD, GetLOD)(THIS); 34 | STDMETHOD_(DWORD, GetLevelCount)(THIS); 35 | STDMETHOD(SetAutoGenFilterType)(THIS_ D3DTEXTUREFILTERTYPE FilterType); 36 | STDMETHOD_(D3DTEXTUREFILTERTYPE, GetAutoGenFilterType)(THIS); 37 | STDMETHOD_(void, GenerateMipSubLevels)(THIS); 38 | STDMETHOD(GetLevelDesc)(THIS_ UINT Level, D3DVOLUME_DESC *pDesc); 39 | STDMETHOD(GetVolumeLevel)(THIS_ UINT Level, IDirect3DVolume9** ppVolumeLevel); 40 | STDMETHOD(LockBox)(THIS_ UINT Level, D3DLOCKED_BOX* pLockedVolume, CONST D3DBOX* pBox, DWORD Flags); 41 | STDMETHOD(UnlockBox)(THIS_ UINT Level); 42 | STDMETHOD(AddDirtyBox)(THIS_ CONST D3DBOX* pDirtyBox); 43 | }; 44 | -------------------------------------------------------------------------------- /source/IDirect3DPixelShader9.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2020 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #include "d3d9.h" 18 | 19 | HRESULT m_IDirect3DPixelShader9::QueryInterface(THIS_ REFIID riid, void** ppvObj) 20 | { 21 | if ((riid == IID_IDirect3DPixelShader9 || riid == IID_IUnknown) && ppvObj) 22 | { 23 | AddRef(); 24 | 25 | *ppvObj = this; 26 | 27 | return S_OK; 28 | } 29 | 30 | HRESULT hr = ProxyInterface->QueryInterface(riid, ppvObj); 31 | 32 | if (SUCCEEDED(hr)) 33 | { 34 | genericQueryInterface(riid, ppvObj, m_pDeviceEx); 35 | } 36 | 37 | return hr; 38 | } 39 | 40 | ULONG m_IDirect3DPixelShader9::AddRef(THIS) 41 | { 42 | return ProxyInterface->AddRef(); 43 | } 44 | 45 | ULONG m_IDirect3DPixelShader9::Release(THIS) 46 | { 47 | return ProxyInterface->Release(); 48 | } 49 | 50 | HRESULT m_IDirect3DPixelShader9::GetDevice(THIS_ IDirect3DDevice9** ppDevice) 51 | { 52 | if (!ppDevice) 53 | { 54 | return D3DERR_INVALIDCALL; 55 | } 56 | 57 | m_pDeviceEx->AddRef(); 58 | 59 | *ppDevice = m_pDeviceEx; 60 | 61 | return D3D_OK; 62 | } 63 | 64 | HRESULT m_IDirect3DPixelShader9::GetFunction(THIS_ void* pData, UINT* pSizeOfData) 65 | { 66 | return ProxyInterface->GetFunction(pData, pSizeOfData); 67 | } 68 | -------------------------------------------------------------------------------- /source/IDirect3DVertexShader9.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2020 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #include "d3d9.h" 18 | 19 | HRESULT m_IDirect3DVertexShader9::QueryInterface(THIS_ REFIID riid, void** ppvObj) 20 | { 21 | if ((riid == IID_IDirect3DVertexShader9 || riid == IID_IUnknown) && ppvObj) 22 | { 23 | AddRef(); 24 | 25 | *ppvObj = this; 26 | 27 | return S_OK; 28 | } 29 | 30 | HRESULT hr = ProxyInterface->QueryInterface(riid, ppvObj); 31 | 32 | if (SUCCEEDED(hr)) 33 | { 34 | genericQueryInterface(riid, ppvObj, m_pDeviceEx); 35 | } 36 | 37 | return hr; 38 | } 39 | 40 | ULONG m_IDirect3DVertexShader9::AddRef(THIS) 41 | { 42 | return ProxyInterface->AddRef(); 43 | } 44 | 45 | ULONG m_IDirect3DVertexShader9::Release(THIS) 46 | { 47 | return ProxyInterface->Release(); 48 | } 49 | 50 | HRESULT m_IDirect3DVertexShader9::GetDevice(THIS_ IDirect3DDevice9** ppDevice) 51 | { 52 | if (!ppDevice) 53 | { 54 | return D3DERR_INVALIDCALL; 55 | } 56 | 57 | m_pDeviceEx->AddRef(); 58 | 59 | *ppDevice = m_pDeviceEx; 60 | 61 | return D3D_OK; 62 | } 63 | 64 | HRESULT m_IDirect3DVertexShader9::GetFunction(THIS_ void* pData, UINT* pSizeOfData) 65 | { 66 | return ProxyInterface->GetFunction(pData, pSizeOfData); 67 | } 68 | -------------------------------------------------------------------------------- /source/IDirect3DCubeTexture9.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class m_IDirect3DCubeTexture9 : public IDirect3DCubeTexture9, public AddressLookupTableObject 4 | { 5 | private: 6 | LPDIRECT3DCUBETEXTURE9 ProxyInterface; 7 | m_IDirect3DDevice9Ex* m_pDeviceEx = nullptr; 8 | 9 | public: 10 | m_IDirect3DCubeTexture9(LPDIRECT3DCUBETEXTURE9 pTexture9, m_IDirect3DDevice9Ex* pDevice) : ProxyInterface(pTexture9), m_pDeviceEx(pDevice) 11 | { 12 | pDevice->ProxyAddressLookupTable->SaveAddress(this, ProxyInterface); 13 | } 14 | ~m_IDirect3DCubeTexture9() {} 15 | 16 | LPDIRECT3DCUBETEXTURE9 GetProxyInterface() { return ProxyInterface; } 17 | 18 | /*** IUnknown methods ***/ 19 | STDMETHOD(QueryInterface)(THIS_ REFIID riid, void** ppvObj); 20 | STDMETHOD_(ULONG, AddRef)(THIS); 21 | STDMETHOD_(ULONG, Release)(THIS); 22 | 23 | /*** IDirect3DBaseTexture9 methods ***/ 24 | STDMETHOD(GetDevice)(THIS_ IDirect3DDevice9** ppDevice); 25 | STDMETHOD(SetPrivateData)(THIS_ REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags); 26 | STDMETHOD(GetPrivateData)(THIS_ REFGUID refguid, void* pData, DWORD* pSizeOfData); 27 | STDMETHOD(FreePrivateData)(THIS_ REFGUID refguid); 28 | STDMETHOD_(DWORD, SetPriority)(THIS_ DWORD PriorityNew); 29 | STDMETHOD_(DWORD, GetPriority)(THIS); 30 | STDMETHOD_(void, PreLoad)(THIS); 31 | STDMETHOD_(D3DRESOURCETYPE, GetType)(THIS); 32 | STDMETHOD_(DWORD, SetLOD)(THIS_ DWORD LODNew); 33 | STDMETHOD_(DWORD, GetLOD)(THIS); 34 | STDMETHOD_(DWORD, GetLevelCount)(THIS); 35 | STDMETHOD(SetAutoGenFilterType)(THIS_ D3DTEXTUREFILTERTYPE FilterType); 36 | STDMETHOD_(D3DTEXTUREFILTERTYPE, GetAutoGenFilterType)(THIS); 37 | STDMETHOD_(void, GenerateMipSubLevels)(THIS); 38 | STDMETHOD(GetLevelDesc)(THIS_ UINT Level, D3DSURFACE_DESC *pDesc); 39 | STDMETHOD(GetCubeMapSurface)(THIS_ D3DCUBEMAP_FACES FaceType, UINT Level, IDirect3DSurface9** ppCubeMapSurface); 40 | STDMETHOD(LockRect)(THIS_ D3DCUBEMAP_FACES FaceType, UINT Level, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags); 41 | STDMETHOD(UnlockRect)(THIS_ D3DCUBEMAP_FACES FaceType, UINT Level); 42 | STDMETHOD(AddDirtyRect)(THIS_ D3DCUBEMAP_FACES FaceType, CONST RECT* pDirtyRect); 43 | }; 44 | -------------------------------------------------------------------------------- /source/IDirect3DStateBlock9.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2020 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #include "d3d9.h" 18 | 19 | HRESULT m_IDirect3DStateBlock9::QueryInterface(THIS_ REFIID riid, void** ppvObj) 20 | { 21 | if ((riid == IID_IDirect3DStateBlock9 || riid == IID_IUnknown) && ppvObj) 22 | { 23 | AddRef(); 24 | 25 | *ppvObj = this; 26 | 27 | return S_OK; 28 | } 29 | 30 | HRESULT hr = ProxyInterface->QueryInterface(riid, ppvObj); 31 | 32 | if (SUCCEEDED(hr)) 33 | { 34 | genericQueryInterface(riid, ppvObj, m_pDeviceEx); 35 | } 36 | 37 | return hr; 38 | } 39 | 40 | ULONG m_IDirect3DStateBlock9::AddRef(THIS) 41 | { 42 | return ProxyInterface->AddRef(); 43 | } 44 | 45 | ULONG m_IDirect3DStateBlock9::Release(THIS) 46 | { 47 | return ProxyInterface->Release(); 48 | } 49 | 50 | HRESULT m_IDirect3DStateBlock9::GetDevice(THIS_ IDirect3DDevice9** ppDevice) 51 | { 52 | if (!ppDevice) 53 | { 54 | return D3DERR_INVALIDCALL; 55 | } 56 | 57 | m_pDeviceEx->AddRef(); 58 | 59 | *ppDevice = m_pDeviceEx; 60 | 61 | return D3D_OK; 62 | } 63 | 64 | HRESULT m_IDirect3DStateBlock9::Capture(THIS) 65 | { 66 | return ProxyInterface->Capture(); 67 | } 68 | 69 | HRESULT m_IDirect3DStateBlock9::Apply(THIS) 70 | { 71 | return ProxyInterface->Apply(); 72 | } 73 | -------------------------------------------------------------------------------- /source/IDirect3DVertexDeclaration9.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2020 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #include "d3d9.h" 18 | 19 | HRESULT m_IDirect3DVertexDeclaration9::QueryInterface(THIS_ REFIID riid, void** ppvObj) 20 | { 21 | if ((riid == IID_IDirect3DVertexDeclaration9 || riid == IID_IUnknown) && ppvObj) 22 | { 23 | AddRef(); 24 | 25 | *ppvObj = this; 26 | 27 | return S_OK; 28 | } 29 | 30 | HRESULT hr = ProxyInterface->QueryInterface(riid, ppvObj); 31 | 32 | if (SUCCEEDED(hr)) 33 | { 34 | genericQueryInterface(riid, ppvObj, m_pDeviceEx); 35 | } 36 | 37 | return hr; 38 | } 39 | 40 | ULONG m_IDirect3DVertexDeclaration9::AddRef(THIS) 41 | { 42 | return ProxyInterface->AddRef(); 43 | } 44 | 45 | ULONG m_IDirect3DVertexDeclaration9::Release(THIS) 46 | { 47 | return ProxyInterface->Release(); 48 | } 49 | 50 | HRESULT m_IDirect3DVertexDeclaration9::GetDevice(THIS_ IDirect3DDevice9** ppDevice) 51 | { 52 | if (!ppDevice) 53 | { 54 | return D3DERR_INVALIDCALL; 55 | } 56 | 57 | m_pDeviceEx->AddRef(); 58 | 59 | *ppDevice = m_pDeviceEx; 60 | 61 | return D3D_OK; 62 | } 63 | 64 | HRESULT m_IDirect3DVertexDeclaration9::GetDeclaration(THIS_ D3DVERTEXELEMENT9* pElement, UINT* pNumElements) 65 | { 66 | return ProxyInterface->GetDeclaration(pElement, pNumElements); 67 | } 68 | -------------------------------------------------------------------------------- /source/d3d9.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define INITGUID 4 | 5 | #include 6 | 7 | class m_IDirect3D9Ex; 8 | class m_IDirect3DDevice9Ex; 9 | class m_IDirect3DCubeTexture9; 10 | class m_IDirect3DIndexBuffer9; 11 | class m_IDirect3DPixelShader9; 12 | class m_IDirect3DQuery9; 13 | class m_IDirect3DStateBlock9; 14 | class m_IDirect3DSurface9; 15 | class m_IDirect3DSwapChain9Ex; 16 | class m_IDirect3DTexture9; 17 | class m_IDirect3DVertexBuffer9; 18 | class m_IDirect3DVertexDeclaration9; 19 | class m_IDirect3DVertexShader9; 20 | class m_IDirect3DVolume9; 21 | class m_IDirect3DVolumeTexture9; 22 | 23 | #include "AddressLookupTable.h" 24 | 25 | typedef HRESULT(WINAPI *Direct3DShaderValidatorCreate9Proc)(); 26 | typedef HRESULT(WINAPI *PSGPErrorProc)(); 27 | typedef HRESULT(WINAPI *PSGPSampleTextureProc)(); 28 | typedef int(WINAPI *D3DPERF_BeginEventProc)(D3DCOLOR, LPCWSTR); 29 | typedef int(WINAPI *D3DPERF_EndEventProc)(); 30 | typedef DWORD(WINAPI *D3DPERF_GetStatusProc)(); 31 | typedef BOOL(WINAPI *D3DPERF_QueryRepeatFrameProc)(); 32 | typedef void(WINAPI *D3DPERF_SetMarkerProc)(D3DCOLOR, LPCWSTR); 33 | typedef void(WINAPI *D3DPERF_SetOptionsProc)(DWORD); 34 | typedef void(WINAPI *D3DPERF_SetRegionProc)(D3DCOLOR, LPCWSTR); 35 | typedef HRESULT(WINAPI *DebugSetLevelProc)(DWORD); 36 | typedef void(WINAPI *DebugSetMuteProc)(); 37 | typedef int(WINAPI *Direct3D9EnableMaximizedWindowedModeShimProc)(BOOL); 38 | typedef IDirect3D9 *(WINAPI *Direct3DCreate9Proc)(UINT); 39 | typedef HRESULT(WINAPI *Direct3DCreate9ExProc)(UINT, IDirect3D9Ex **); 40 | 41 | void genericQueryInterface(REFIID riid, LPVOID *ppvObj, m_IDirect3DDevice9Ex* m_pDeviceEx); 42 | 43 | #include "IDirect3D9Ex.h" 44 | #include "IDirect3DDevice9Ex.h" 45 | #include "IDirect3DCubeTexture9.h" 46 | #include "IDirect3DIndexBuffer9.h" 47 | #include "IDirect3DPixelShader9.h" 48 | #include "IDirect3DQuery9.h" 49 | #include "IDirect3DStateBlock9.h" 50 | #include "IDirect3DSurface9.h" 51 | #include "IDirect3DSwapChain9Ex.h" 52 | #include "IDirect3DTexture9.h" 53 | #include "IDirect3DVertexBuffer9.h" 54 | #include "IDirect3DVertexDeclaration9.h" 55 | #include "IDirect3DVertexShader9.h" 56 | #include "IDirect3DVolume9.h" 57 | #include "IDirect3DVolumeTexture9.h" 58 | -------------------------------------------------------------------------------- /source/dxsdk/d3dx9.h: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (C) Microsoft Corporation. All Rights Reserved. 4 | // 5 | // File: d3dx9.h 6 | // Content: D3DX utility library 7 | // 8 | ////////////////////////////////////////////////////////////////////////////// 9 | 10 | #ifdef __D3DX_INTERNAL__ 11 | #error Incorrect D3DX header used 12 | #endif 13 | 14 | #ifndef __D3DX9_H__ 15 | #define __D3DX9_H__ 16 | 17 | 18 | // Defines 19 | #include 20 | 21 | #define D3DX_DEFAULT ((UINT) -1) 22 | #define D3DX_DEFAULT_NONPOW2 ((UINT) -2) 23 | #define D3DX_DEFAULT_FLOAT FLT_MAX 24 | #define D3DX_FROM_FILE ((UINT) -3) 25 | #define D3DFMT_FROM_FILE ((D3DFORMAT) -3) 26 | 27 | #ifndef D3DXINLINE 28 | #ifdef _MSC_VER 29 | #if (_MSC_VER >= 1200) 30 | #define D3DXINLINE __forceinline 31 | #else 32 | #define D3DXINLINE __inline 33 | #endif 34 | #else 35 | #ifdef __cplusplus 36 | #define D3DXINLINE inline 37 | #else 38 | #define D3DXINLINE 39 | #endif 40 | #endif 41 | #endif 42 | 43 | 44 | 45 | // Includes 46 | #include "d3d9.h" 47 | #include "d3dx9math.h" 48 | #include "d3dx9core.h" 49 | #include "d3dx9xof.h" 50 | #include "d3dx9mesh.h" 51 | #include "d3dx9shader.h" 52 | #include "d3dx9effect.h" 53 | 54 | #include "d3dx9tex.h" 55 | #include "d3dx9shape.h" 56 | #include "d3dx9anim.h" 57 | 58 | 59 | 60 | // Errors 61 | #define _FACDD 0x876 62 | #define MAKE_DDHRESULT( code ) MAKE_HRESULT( 1, _FACDD, code ) 63 | 64 | enum _D3DXERR { 65 | D3DXERR_CANNOTMODIFYINDEXBUFFER = MAKE_DDHRESULT(2900), 66 | D3DXERR_INVALIDMESH = MAKE_DDHRESULT(2901), 67 | D3DXERR_CANNOTATTRSORT = MAKE_DDHRESULT(2902), 68 | D3DXERR_SKINNINGNOTSUPPORTED = MAKE_DDHRESULT(2903), 69 | D3DXERR_TOOMANYINFLUENCES = MAKE_DDHRESULT(2904), 70 | D3DXERR_INVALIDDATA = MAKE_DDHRESULT(2905), 71 | D3DXERR_LOADEDMESHASNODATA = MAKE_DDHRESULT(2906), 72 | D3DXERR_DUPLICATENAMEDFRAGMENT = MAKE_DDHRESULT(2907), 73 | D3DXERR_CANNOTREMOVELASTITEM = MAKE_DDHRESULT(2908), 74 | }; 75 | 76 | 77 | #endif //__D3DX9_H__ 78 | 79 | -------------------------------------------------------------------------------- /source/IDirect3DQuery9.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2020 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #include "d3d9.h" 18 | 19 | HRESULT m_IDirect3DQuery9::QueryInterface(THIS_ REFIID riid, void** ppvObj) 20 | { 21 | if ((riid == IID_IDirect3DQuery9 || riid == IID_IUnknown) && ppvObj) 22 | { 23 | AddRef(); 24 | 25 | *ppvObj = this; 26 | 27 | return S_OK; 28 | } 29 | 30 | HRESULT hr = ProxyInterface->QueryInterface(riid, ppvObj); 31 | 32 | if (SUCCEEDED(hr)) 33 | { 34 | genericQueryInterface(riid, ppvObj, m_pDeviceEx); 35 | } 36 | 37 | return hr; 38 | } 39 | 40 | ULONG m_IDirect3DQuery9::AddRef(THIS) 41 | { 42 | return ProxyInterface->AddRef(); 43 | } 44 | 45 | ULONG m_IDirect3DQuery9::Release(THIS) 46 | { 47 | return ProxyInterface->Release(); 48 | } 49 | 50 | HRESULT m_IDirect3DQuery9::GetDevice(THIS_ IDirect3DDevice9** ppDevice) 51 | { 52 | if (!ppDevice) 53 | { 54 | return D3DERR_INVALIDCALL; 55 | } 56 | 57 | m_pDeviceEx->AddRef(); 58 | 59 | *ppDevice = m_pDeviceEx; 60 | 61 | return D3D_OK; 62 | } 63 | 64 | D3DQUERYTYPE m_IDirect3DQuery9::GetType(THIS) 65 | { 66 | return ProxyInterface->GetType(); 67 | } 68 | 69 | DWORD m_IDirect3DQuery9::GetDataSize(THIS) 70 | { 71 | return ProxyInterface->GetDataSize(); 72 | } 73 | 74 | HRESULT m_IDirect3DQuery9::Issue(THIS_ DWORD dwIssueFlags) 75 | { 76 | return ProxyInterface->Issue(dwIssueFlags); 77 | } 78 | 79 | HRESULT m_IDirect3DQuery9::GetData(THIS_ void* pData, DWORD dwSize, DWORD dwGetDataFlags) 80 | { 81 | return ProxyInterface->GetData(pData, dwSize, dwGetDataFlags); 82 | } 83 | -------------------------------------------------------------------------------- /source/IDirect3D9Ex.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class m_IDirect3D9Ex : public IDirect3D9Ex 4 | { 5 | private: 6 | LPDIRECT3D9EX ProxyInterface; 7 | REFIID WrapperID; 8 | 9 | public: 10 | m_IDirect3D9Ex(LPDIRECT3D9EX pDirect3D, REFIID DeviceID) : ProxyInterface(pDirect3D), WrapperID(DeviceID) { } 11 | 12 | /*** IUnknown methods ***/ 13 | STDMETHOD(QueryInterface)(THIS_ REFIID riid, void** ppvObj); 14 | STDMETHOD_(ULONG, AddRef)(THIS); 15 | STDMETHOD_(ULONG, Release)(THIS); 16 | 17 | /*** IDirect3D9 methods ***/ 18 | STDMETHOD(RegisterSoftwareDevice)(THIS_ void* pInitializeFunction); 19 | STDMETHOD_(UINT, GetAdapterCount)(THIS); 20 | STDMETHOD(GetAdapterIdentifier)(THIS_ UINT Adapter, DWORD Flags, D3DADAPTER_IDENTIFIER9* pIdentifier); 21 | STDMETHOD_(UINT, GetAdapterModeCount)(THIS_ UINT Adapter, D3DFORMAT Format); 22 | STDMETHOD(EnumAdapterModes)(THIS_ UINT Adapter, D3DFORMAT Format, UINT Mode, D3DDISPLAYMODE* pMode); 23 | STDMETHOD(GetAdapterDisplayMode)(THIS_ UINT Adapter, D3DDISPLAYMODE* pMode); 24 | STDMETHOD(CheckDeviceType)(THIS_ UINT Adapter, D3DDEVTYPE DevType, D3DFORMAT AdapterFormat, D3DFORMAT BackBufferFormat, BOOL bWindowed); 25 | STDMETHOD(CheckDeviceFormat)(THIS_ UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat); 26 | STDMETHOD(CheckDeviceMultiSampleType)(THIS_ UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat, BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType, DWORD* pQualityLevels); 27 | STDMETHOD(CheckDepthStencilMatch)(THIS_ UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, D3DFORMAT RenderTargetFormat, D3DFORMAT DepthStencilFormat); 28 | STDMETHOD(CheckDeviceFormatConversion)(THIS_ UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SourceFormat, D3DFORMAT TargetFormat); 29 | STDMETHOD(GetDeviceCaps)(THIS_ UINT Adapter, D3DDEVTYPE DeviceType, D3DCAPS9* pCaps); 30 | STDMETHOD_(HMONITOR, GetAdapterMonitor)(THIS_ UINT Adapter); 31 | STDMETHOD(CreateDevice)(THIS_ UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DDevice9** ppReturnedDeviceInterface); 32 | STDMETHOD_(UINT, GetAdapterModeCountEx)(THIS_ UINT Adapter, CONST D3DDISPLAYMODEFILTER* pFilter); 33 | STDMETHOD(EnumAdapterModesEx)(THIS_ UINT Adapter, CONST D3DDISPLAYMODEFILTER* pFilter, UINT Mode, D3DDISPLAYMODEEX* pMode); 34 | STDMETHOD(GetAdapterDisplayModeEx)(THIS_ UINT Adapter, D3DDISPLAYMODEEX* pMode, D3DDISPLAYROTATION* pRotation); 35 | STDMETHOD(CreateDeviceEx)(THIS_ UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS* pPresentationParameters, D3DDISPLAYMODEEX* pFullscreenDisplayMode, IDirect3DDevice9Ex** ppReturnedDeviceInterface); 36 | STDMETHOD(GetAdapterLUID)(THIS_ UINT Adapter, LUID * pLUID); 37 | }; 38 | -------------------------------------------------------------------------------- /source/InterfaceQuery.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2020 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #include "d3d9.h" 18 | 19 | void genericQueryInterface(REFIID riid, LPVOID *ppvObj, m_IDirect3DDevice9Ex* m_pDeviceEx) 20 | { 21 | if (!ppvObj || !*ppvObj || !m_pDeviceEx) 22 | { 23 | return; 24 | } 25 | 26 | if (riid == IID_IDirect3D9 || riid == IID_IDirect3D9Ex) 27 | { 28 | IDirect3D9 *pD3D9 = nullptr; 29 | if (SUCCEEDED(m_pDeviceEx->GetDirect3D(&pD3D9)) && pD3D9) 30 | { 31 | IDirect3D9 *pD3D9wrapper = nullptr; 32 | if (SUCCEEDED(pD3D9->QueryInterface(riid, (LPVOID*)&pD3D9wrapper)) && pD3D9wrapper) 33 | { 34 | pD3D9wrapper->Release(); 35 | } 36 | pD3D9->Release(); 37 | return; 38 | } 39 | } 40 | 41 | if (riid == IID_IDirect3DDevice9 || riid == IID_IDirect3DDevice9Ex) 42 | { 43 | IDirect3DDevice9 *pD3DDevice9 = nullptr; 44 | if (SUCCEEDED(m_pDeviceEx->QueryInterface(riid, (LPVOID*)&pD3DDevice9)) && pD3DDevice9) 45 | { 46 | pD3DDevice9->Release(); 47 | } 48 | return; 49 | } 50 | 51 | if (riid == IID_IDirect3DSwapChain9 || riid == IID_IDirect3DSwapChain9Ex) 52 | { 53 | *ppvObj = m_pDeviceEx->ProxyAddressLookupTable->FindAddress(*ppvObj, riid); 54 | return; 55 | } 56 | 57 | #define QUERYINTERFACE(x) \ 58 | if (riid == IID_ ## x) \ 59 | { \ 60 | *ppvObj = m_pDeviceEx->ProxyAddressLookupTable->FindAddress(*ppvObj); \ 61 | return; \ 62 | } 63 | 64 | QUERYINTERFACE(IDirect3DCubeTexture9); 65 | QUERYINTERFACE(IDirect3DIndexBuffer9); 66 | QUERYINTERFACE(IDirect3DPixelShader9); 67 | QUERYINTERFACE(IDirect3DQuery9); 68 | QUERYINTERFACE(IDirect3DStateBlock9); 69 | QUERYINTERFACE(IDirect3DSurface9); 70 | QUERYINTERFACE(IDirect3DTexture9); 71 | QUERYINTERFACE(IDirect3DVertexBuffer9); 72 | QUERYINTERFACE(IDirect3DVertexDeclaration9); 73 | QUERYINTERFACE(IDirect3DVertexShader9); 74 | QUERYINTERFACE(IDirect3DVolume9); 75 | QUERYINTERFACE(IDirect3DVolumeTexture9); 76 | } 77 | -------------------------------------------------------------------------------- /source/IDirect3DVolume9.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2020 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #include "d3d9.h" 18 | 19 | HRESULT m_IDirect3DVolume9::QueryInterface(THIS_ REFIID riid, void** ppvObj) 20 | { 21 | if ((riid == IID_IDirect3DVolume9 || riid == IID_IUnknown) && ppvObj) 22 | { 23 | AddRef(); 24 | 25 | *ppvObj = this; 26 | 27 | return S_OK; 28 | } 29 | 30 | HRESULT hr = ProxyInterface->QueryInterface(riid, ppvObj); 31 | 32 | if (SUCCEEDED(hr)) 33 | { 34 | genericQueryInterface(riid, ppvObj, m_pDeviceEx); 35 | } 36 | 37 | return hr; 38 | } 39 | 40 | ULONG m_IDirect3DVolume9::AddRef(THIS) 41 | { 42 | return ProxyInterface->AddRef(); 43 | } 44 | 45 | ULONG m_IDirect3DVolume9::Release(THIS) 46 | { 47 | return ProxyInterface->Release(); 48 | } 49 | 50 | HRESULT m_IDirect3DVolume9::GetDevice(THIS_ IDirect3DDevice9** ppDevice) 51 | { 52 | if (!ppDevice) 53 | { 54 | return D3DERR_INVALIDCALL; 55 | } 56 | 57 | m_pDeviceEx->AddRef(); 58 | 59 | *ppDevice = m_pDeviceEx; 60 | 61 | return D3D_OK; 62 | } 63 | 64 | HRESULT m_IDirect3DVolume9::SetPrivateData(THIS_ REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) 65 | { 66 | return ProxyInterface->SetPrivateData(refguid, pData, SizeOfData, Flags); 67 | } 68 | 69 | HRESULT m_IDirect3DVolume9::GetPrivateData(THIS_ REFGUID refguid, void* pData, DWORD* pSizeOfData) 70 | { 71 | return ProxyInterface->GetPrivateData(refguid, pData, pSizeOfData); 72 | } 73 | 74 | HRESULT m_IDirect3DVolume9::FreePrivateData(THIS_ REFGUID refguid) 75 | { 76 | return ProxyInterface->FreePrivateData(refguid); 77 | } 78 | 79 | HRESULT m_IDirect3DVolume9::GetContainer(THIS_ REFIID riid, void** ppContainer) 80 | { 81 | HRESULT hr = ProxyInterface->GetContainer(riid, ppContainer); 82 | 83 | if (SUCCEEDED(hr)) 84 | { 85 | genericQueryInterface(riid, ppContainer, m_pDeviceEx); 86 | } 87 | 88 | return hr; 89 | } 90 | 91 | HRESULT m_IDirect3DVolume9::GetDesc(THIS_ D3DVOLUME_DESC *pDesc) 92 | { 93 | return ProxyInterface->GetDesc(pDesc); 94 | } 95 | 96 | HRESULT m_IDirect3DVolume9::LockBox(THIS_ D3DLOCKED_BOX * pLockedVolume, CONST D3DBOX* pBox, DWORD Flags) 97 | { 98 | return ProxyInterface->LockBox(pLockedVolume, pBox, Flags); 99 | } 100 | 101 | HRESULT m_IDirect3DVolume9::UnlockBox(THIS) 102 | { 103 | return ProxyInterface->UnlockBox(); 104 | } 105 | -------------------------------------------------------------------------------- /source/IDirect3DIndexBuffer9.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2020 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #include "d3d9.h" 18 | 19 | HRESULT m_IDirect3DIndexBuffer9::QueryInterface(THIS_ REFIID riid, void** ppvObj) 20 | { 21 | if ((riid == IID_IDirect3DIndexBuffer9 || riid == IID_IUnknown || riid == IID_IDirect3DResource9) && ppvObj) 22 | { 23 | AddRef(); 24 | 25 | *ppvObj = this; 26 | 27 | return S_OK; 28 | } 29 | 30 | HRESULT hr = ProxyInterface->QueryInterface(riid, ppvObj); 31 | 32 | if (SUCCEEDED(hr)) 33 | { 34 | genericQueryInterface(riid, ppvObj, m_pDeviceEx); 35 | } 36 | 37 | return hr; 38 | } 39 | 40 | ULONG m_IDirect3DIndexBuffer9::AddRef(THIS) 41 | { 42 | return ProxyInterface->AddRef(); 43 | } 44 | 45 | ULONG m_IDirect3DIndexBuffer9::Release(THIS) 46 | { 47 | return ProxyInterface->Release(); 48 | } 49 | 50 | HRESULT m_IDirect3DIndexBuffer9::GetDevice(THIS_ IDirect3DDevice9** ppDevice) 51 | { 52 | if (!ppDevice) 53 | { 54 | return D3DERR_INVALIDCALL; 55 | } 56 | 57 | m_pDeviceEx->AddRef(); 58 | 59 | *ppDevice = m_pDeviceEx; 60 | 61 | return D3D_OK; 62 | } 63 | 64 | HRESULT m_IDirect3DIndexBuffer9::SetPrivateData(THIS_ REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) 65 | { 66 | return ProxyInterface->SetPrivateData(refguid, pData, SizeOfData, Flags); 67 | } 68 | 69 | HRESULT m_IDirect3DIndexBuffer9::GetPrivateData(THIS_ REFGUID refguid, void* pData, DWORD* pSizeOfData) 70 | { 71 | return ProxyInterface->GetPrivateData(refguid, pData, pSizeOfData); 72 | } 73 | 74 | HRESULT m_IDirect3DIndexBuffer9::FreePrivateData(THIS_ REFGUID refguid) 75 | { 76 | return ProxyInterface->FreePrivateData(refguid); 77 | } 78 | 79 | DWORD m_IDirect3DIndexBuffer9::SetPriority(THIS_ DWORD PriorityNew) 80 | { 81 | return ProxyInterface->SetPriority(PriorityNew); 82 | } 83 | 84 | DWORD m_IDirect3DIndexBuffer9::GetPriority(THIS) 85 | { 86 | return ProxyInterface->GetPriority(); 87 | } 88 | 89 | void m_IDirect3DIndexBuffer9::PreLoad(THIS) 90 | { 91 | return ProxyInterface->PreLoad(); 92 | } 93 | 94 | D3DRESOURCETYPE m_IDirect3DIndexBuffer9::GetType(THIS) 95 | { 96 | return ProxyInterface->GetType(); 97 | } 98 | 99 | HRESULT m_IDirect3DIndexBuffer9::Lock(THIS_ UINT OffsetToLock, UINT SizeToLock, void** ppbData, DWORD Flags) 100 | { 101 | return ProxyInterface->Lock(OffsetToLock, SizeToLock, ppbData, Flags); 102 | } 103 | 104 | HRESULT m_IDirect3DIndexBuffer9::Unlock(THIS) 105 | { 106 | return ProxyInterface->Unlock(); 107 | } 108 | 109 | HRESULT m_IDirect3DIndexBuffer9::GetDesc(THIS_ D3DINDEXBUFFER_DESC *pDesc) 110 | { 111 | return ProxyInterface->GetDesc(pDesc); 112 | } 113 | -------------------------------------------------------------------------------- /source/IDirect3DVertexBuffer9.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2020 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #include "d3d9.h" 18 | 19 | HRESULT m_IDirect3DVertexBuffer9::QueryInterface(THIS_ REFIID riid, void** ppvObj) 20 | { 21 | if ((riid == IID_IDirect3DVertexBuffer9 || riid == IID_IUnknown || riid == IID_IDirect3DResource9) && ppvObj) 22 | { 23 | AddRef(); 24 | 25 | *ppvObj = this; 26 | 27 | return S_OK; 28 | } 29 | 30 | HRESULT hr = ProxyInterface->QueryInterface(riid, ppvObj); 31 | 32 | if (SUCCEEDED(hr)) 33 | { 34 | genericQueryInterface(riid, ppvObj, m_pDeviceEx); 35 | } 36 | 37 | return hr; 38 | } 39 | 40 | ULONG m_IDirect3DVertexBuffer9::AddRef(THIS) 41 | { 42 | return ProxyInterface->AddRef(); 43 | } 44 | 45 | ULONG m_IDirect3DVertexBuffer9::Release(THIS) 46 | { 47 | return ProxyInterface->Release(); 48 | } 49 | 50 | HRESULT m_IDirect3DVertexBuffer9::GetDevice(THIS_ IDirect3DDevice9** ppDevice) 51 | { 52 | if (!ppDevice) 53 | { 54 | return D3DERR_INVALIDCALL; 55 | } 56 | 57 | m_pDeviceEx->AddRef(); 58 | 59 | *ppDevice = m_pDeviceEx; 60 | 61 | return D3D_OK; 62 | } 63 | 64 | HRESULT m_IDirect3DVertexBuffer9::SetPrivateData(THIS_ REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) 65 | { 66 | return ProxyInterface->SetPrivateData(refguid, pData, SizeOfData, Flags); 67 | } 68 | 69 | HRESULT m_IDirect3DVertexBuffer9::GetPrivateData(THIS_ REFGUID refguid, void* pData, DWORD* pSizeOfData) 70 | { 71 | return ProxyInterface->GetPrivateData(refguid, pData, pSizeOfData); 72 | } 73 | 74 | HRESULT m_IDirect3DVertexBuffer9::FreePrivateData(THIS_ REFGUID refguid) 75 | { 76 | return ProxyInterface->FreePrivateData(refguid); 77 | } 78 | 79 | DWORD m_IDirect3DVertexBuffer9::SetPriority(THIS_ DWORD PriorityNew) 80 | { 81 | return ProxyInterface->SetPriority(PriorityNew); 82 | } 83 | 84 | DWORD m_IDirect3DVertexBuffer9::GetPriority(THIS) 85 | { 86 | return ProxyInterface->GetPriority(); 87 | } 88 | 89 | void m_IDirect3DVertexBuffer9::PreLoad(THIS) 90 | { 91 | return ProxyInterface->PreLoad(); 92 | } 93 | 94 | D3DRESOURCETYPE m_IDirect3DVertexBuffer9::GetType(THIS) 95 | { 96 | return ProxyInterface->GetType(); 97 | } 98 | 99 | HRESULT m_IDirect3DVertexBuffer9::Lock(THIS_ UINT OffsetToLock, UINT SizeToLock, void** ppbData, DWORD Flags) 100 | { 101 | return ProxyInterface->Lock(OffsetToLock, SizeToLock, ppbData, Flags); 102 | } 103 | 104 | HRESULT m_IDirect3DVertexBuffer9::Unlock(THIS) 105 | { 106 | return ProxyInterface->Unlock(); 107 | } 108 | 109 | HRESULT m_IDirect3DVertexBuffer9::GetDesc(THIS_ D3DVERTEXBUFFER_DESC *pDesc) 110 | { 111 | return ProxyInterface->GetDesc(pDesc); 112 | } 113 | -------------------------------------------------------------------------------- /source/IDirect3DSurface9.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2020 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #include "d3d9.h" 18 | 19 | HRESULT m_IDirect3DSurface9::QueryInterface(THIS_ REFIID riid, void** ppvObj) 20 | { 21 | if ((riid == IID_IDirect3DSurface9 || riid == IID_IUnknown || riid == IID_IDirect3DResource9) && ppvObj) 22 | { 23 | AddRef(); 24 | 25 | *ppvObj = this; 26 | 27 | return S_OK; 28 | } 29 | 30 | HRESULT hr = ProxyInterface->QueryInterface(riid, ppvObj); 31 | 32 | if (SUCCEEDED(hr)) 33 | { 34 | genericQueryInterface(riid, ppvObj, m_pDeviceEx); 35 | } 36 | 37 | return hr; 38 | } 39 | 40 | ULONG m_IDirect3DSurface9::AddRef(THIS) 41 | { 42 | return ProxyInterface->AddRef(); 43 | } 44 | 45 | ULONG m_IDirect3DSurface9::Release(THIS) 46 | { 47 | return ProxyInterface->Release(); 48 | } 49 | 50 | HRESULT m_IDirect3DSurface9::GetDevice(THIS_ IDirect3DDevice9** ppDevice) 51 | { 52 | if (!ppDevice) 53 | { 54 | return D3DERR_INVALIDCALL; 55 | } 56 | 57 | m_pDeviceEx->AddRef(); 58 | 59 | *ppDevice = m_pDeviceEx; 60 | 61 | return D3D_OK; 62 | } 63 | 64 | HRESULT m_IDirect3DSurface9::SetPrivateData(THIS_ REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) 65 | { 66 | return ProxyInterface->SetPrivateData(refguid, pData, SizeOfData, Flags); 67 | } 68 | 69 | HRESULT m_IDirect3DSurface9::GetPrivateData(THIS_ REFGUID refguid, void* pData, DWORD* pSizeOfData) 70 | { 71 | return ProxyInterface->GetPrivateData(refguid, pData, pSizeOfData); 72 | } 73 | 74 | HRESULT m_IDirect3DSurface9::FreePrivateData(THIS_ REFGUID refguid) 75 | { 76 | return ProxyInterface->FreePrivateData(refguid); 77 | } 78 | 79 | DWORD m_IDirect3DSurface9::SetPriority(THIS_ DWORD PriorityNew) 80 | { 81 | return ProxyInterface->SetPriority(PriorityNew); 82 | } 83 | 84 | DWORD m_IDirect3DSurface9::GetPriority(THIS) 85 | { 86 | return ProxyInterface->GetPriority(); 87 | } 88 | 89 | void m_IDirect3DSurface9::PreLoad(THIS) 90 | { 91 | return ProxyInterface->PreLoad(); 92 | } 93 | 94 | D3DRESOURCETYPE m_IDirect3DSurface9::GetType(THIS) 95 | { 96 | return ProxyInterface->GetType(); 97 | } 98 | 99 | HRESULT m_IDirect3DSurface9::GetContainer(THIS_ REFIID riid, void** ppContainer) 100 | { 101 | HRESULT hr = ProxyInterface->GetContainer(riid, ppContainer); 102 | 103 | if (SUCCEEDED(hr)) 104 | { 105 | genericQueryInterface(riid, ppContainer, m_pDeviceEx); 106 | } 107 | 108 | return hr; 109 | } 110 | 111 | HRESULT m_IDirect3DSurface9::GetDesc(THIS_ D3DSURFACE_DESC *pDesc) 112 | { 113 | return ProxyInterface->GetDesc(pDesc); 114 | } 115 | 116 | HRESULT m_IDirect3DSurface9::LockRect(THIS_ D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) 117 | { 118 | return ProxyInterface->LockRect(pLockedRect, pRect, Flags); 119 | } 120 | 121 | HRESULT m_IDirect3DSurface9::UnlockRect(THIS) 122 | { 123 | return ProxyInterface->UnlockRect(); 124 | } 125 | 126 | HRESULT m_IDirect3DSurface9::GetDC(THIS_ HDC *phdc) 127 | { 128 | return ProxyInterface->GetDC(phdc); 129 | } 130 | 131 | HRESULT m_IDirect3DSurface9::ReleaseDC(THIS_ HDC hdc) 132 | { 133 | return ProxyInterface->ReleaseDC(hdc); 134 | } 135 | -------------------------------------------------------------------------------- /source/IDirect3DSwapChain9Ex.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2020 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #include "d3d9.h" 18 | 19 | HRESULT m_IDirect3DSwapChain9Ex::QueryInterface(THIS_ REFIID riid, void** ppvObj) 20 | { 21 | if ((riid == IID_IDirect3DSwapChain9 || riid == IID_IUnknown) && ppvObj) 22 | { 23 | AddRef(); 24 | 25 | *ppvObj = this; 26 | 27 | return S_OK; 28 | } 29 | 30 | HRESULT hr = ProxyInterface->QueryInterface(riid, ppvObj); 31 | 32 | if (SUCCEEDED(hr)) 33 | { 34 | genericQueryInterface(riid, ppvObj, m_pDeviceEx); 35 | } 36 | 37 | return hr; 38 | } 39 | 40 | ULONG m_IDirect3DSwapChain9Ex::AddRef(THIS) 41 | { 42 | return ProxyInterface->AddRef(); 43 | } 44 | 45 | ULONG m_IDirect3DSwapChain9Ex::Release(THIS) 46 | { 47 | return ProxyInterface->Release(); 48 | } 49 | 50 | HRESULT m_IDirect3DSwapChain9Ex::Present(THIS_ CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion, DWORD dwFlags) 51 | { 52 | return ProxyInterface->Present(pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags); 53 | } 54 | 55 | HRESULT m_IDirect3DSwapChain9Ex::GetFrontBufferData(THIS_ IDirect3DSurface9* pDestSurface) 56 | { 57 | if (pDestSurface) 58 | { 59 | pDestSurface = static_cast(pDestSurface)->GetProxyInterface(); 60 | } 61 | 62 | return GetFrontBufferData(pDestSurface); 63 | } 64 | 65 | HRESULT m_IDirect3DSwapChain9Ex::GetBackBuffer(THIS_ UINT BackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface9** ppBackBuffer) 66 | { 67 | HRESULT hr = ProxyInterface->GetBackBuffer(BackBuffer, Type, ppBackBuffer); 68 | 69 | if (SUCCEEDED(hr) && ppBackBuffer) 70 | { 71 | *ppBackBuffer = m_pDeviceEx->ProxyAddressLookupTable->FindAddress(*ppBackBuffer); 72 | } 73 | 74 | return hr; 75 | } 76 | 77 | HRESULT m_IDirect3DSwapChain9Ex::GetRasterStatus(THIS_ D3DRASTER_STATUS* pRasterStatus) 78 | { 79 | return ProxyInterface->GetRasterStatus(pRasterStatus); 80 | } 81 | 82 | HRESULT m_IDirect3DSwapChain9Ex::GetDisplayMode(THIS_ D3DDISPLAYMODE* pMode) 83 | { 84 | return ProxyInterface->GetDisplayMode(pMode); 85 | } 86 | 87 | HRESULT m_IDirect3DSwapChain9Ex::GetDevice(THIS_ IDirect3DDevice9** ppDevice) 88 | { 89 | if (!ppDevice) 90 | { 91 | return D3DERR_INVALIDCALL; 92 | } 93 | 94 | m_pDeviceEx->AddRef(); 95 | 96 | *ppDevice = m_pDeviceEx; 97 | 98 | return D3D_OK; 99 | } 100 | 101 | HRESULT m_IDirect3DSwapChain9Ex::GetPresentParameters(THIS_ D3DPRESENT_PARAMETERS* pPresentationParameters) 102 | { 103 | return ProxyInterface->GetPresentParameters(pPresentationParameters); 104 | } 105 | 106 | HRESULT m_IDirect3DSwapChain9Ex::GetLastPresentCount(THIS_ UINT* pLastPresentCount) 107 | { 108 | return ProxyInterface->GetLastPresentCount(pLastPresentCount); 109 | } 110 | 111 | HRESULT m_IDirect3DSwapChain9Ex::GetPresentStats(THIS_ D3DPRESENTSTATS* pPresentationStatistics) 112 | { 113 | return ProxyInterface->GetPresentStats(pPresentationStatistics); 114 | } 115 | 116 | HRESULT m_IDirect3DSwapChain9Ex::GetDisplayModeEx(THIS_ D3DDISPLAYMODEEX* pMode, D3DDISPLAYROTATION* pRotation) 117 | { 118 | return ProxyInterface->GetDisplayModeEx(pMode, pRotation); 119 | } 120 | -------------------------------------------------------------------------------- /source/AddressLookupTable.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | constexpr UINT MaxIndex = 16; 7 | 8 | template 9 | class AddressLookupTable 10 | { 11 | public: 12 | explicit AddressLookupTable(D *pDevice) : pDevice(pDevice) {} 13 | ~AddressLookupTable() 14 | { 15 | ConstructorFlag = true; 16 | 17 | for (const auto& cache : g_map) 18 | { 19 | for (const auto& entry : cache) 20 | { 21 | entry.second->DeleteMe(); 22 | } 23 | } 24 | } 25 | 26 | template 27 | struct AddressCacheIndex { static constexpr UINT CacheIndex = 0; }; 28 | template <> 29 | struct AddressCacheIndex { static constexpr UINT CacheIndex = 1; }; 30 | template <> 31 | struct AddressCacheIndex { static constexpr UINT CacheIndex = 2; }; 32 | template <> 33 | struct AddressCacheIndex { static constexpr UINT CacheIndex = 3; }; 34 | template <> 35 | struct AddressCacheIndex { static constexpr UINT CacheIndex = 4; }; 36 | template <> 37 | struct AddressCacheIndex { static constexpr UINT CacheIndex = 5; }; 38 | template <> 39 | struct AddressCacheIndex { static constexpr UINT CacheIndex = 6; }; 40 | template <> 41 | struct AddressCacheIndex { static constexpr UINT CacheIndex = 7; }; 42 | template <> 43 | struct AddressCacheIndex { static constexpr UINT CacheIndex = 8; }; 44 | template <> 45 | struct AddressCacheIndex { static constexpr UINT CacheIndex = 9; }; 46 | template <> 47 | struct AddressCacheIndex { static constexpr UINT CacheIndex = 10; }; 48 | template <> 49 | struct AddressCacheIndex { static constexpr UINT CacheIndex = 11; }; 50 | template <> 51 | struct AddressCacheIndex { static constexpr UINT CacheIndex = 12; }; 52 | template <> 53 | struct AddressCacheIndex { static constexpr UINT CacheIndex = 13; }; 54 | template <> 55 | struct AddressCacheIndex { static constexpr UINT CacheIndex = 14; }; 56 | template <> 57 | struct AddressCacheIndex { static constexpr UINT CacheIndex = 15; }; 58 | 59 | m_IDirect3DSwapChain9Ex *CreateInterface(void *Proxy, REFIID riid) 60 | { 61 | return new m_IDirect3DSwapChain9Ex(static_cast(Proxy), pDevice, riid); 62 | } 63 | 64 | template 65 | T *CreateInterface(void *Proxy) 66 | { 67 | return new T(static_cast(Proxy), pDevice); 68 | } 69 | 70 | template 71 | T *FindAddress(void *Proxy, REFIID riid = IID_IUnknown) 72 | { 73 | if (!Proxy) 74 | { 75 | return nullptr; 76 | } 77 | 78 | constexpr UINT CacheIndex = AddressCacheIndex::CacheIndex; 79 | auto it = g_map[CacheIndex].find(Proxy); 80 | 81 | if (it != std::end(g_map[CacheIndex])) 82 | { 83 | return static_cast(it->second); 84 | } 85 | 86 | if (riid == IID_IUnknown) 87 | { 88 | return CreateInterface(Proxy); 89 | } 90 | else 91 | { 92 | return (T*)CreateInterface(Proxy, riid); 93 | } 94 | } 95 | 96 | template 97 | void SaveAddress(T *Wrapper, void *Proxy) 98 | { 99 | constexpr UINT CacheIndex = AddressCacheIndex::CacheIndex; 100 | if (Wrapper && Proxy) 101 | { 102 | g_map[CacheIndex][Proxy] = Wrapper; 103 | } 104 | } 105 | 106 | template 107 | void DeleteAddress(T *Wrapper) 108 | { 109 | if (!Wrapper || ConstructorFlag) 110 | { 111 | return; 112 | } 113 | 114 | constexpr UINT CacheIndex = AddressCacheIndex::CacheIndex; 115 | auto it = std::find_if(g_map[CacheIndex].begin(), g_map[CacheIndex].end(), 116 | [=](auto Map) -> bool { return Map.second == Wrapper; }); 117 | 118 | if (it != std::end(g_map[CacheIndex])) 119 | { 120 | it = g_map[CacheIndex].erase(it); 121 | } 122 | } 123 | 124 | private: 125 | bool ConstructorFlag = false; 126 | D *const pDevice; 127 | std::unordered_map g_map[MaxIndex]; 128 | }; 129 | 130 | class AddressLookupTableObject 131 | { 132 | public: 133 | virtual ~AddressLookupTableObject() { } 134 | 135 | void DeleteMe() 136 | { 137 | delete this; 138 | } 139 | }; 140 | -------------------------------------------------------------------------------- /source/IDirect3DTexture9.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2020 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #include "d3d9.h" 18 | 19 | HRESULT m_IDirect3DTexture9::QueryInterface(THIS_ REFIID riid, void** ppvObj) 20 | { 21 | if ((riid == IID_IDirect3DTexture9 || riid == IID_IUnknown || riid == IID_IDirect3DResource9 || riid == IID_IDirect3DBaseTexture9) && ppvObj) 22 | { 23 | AddRef(); 24 | 25 | *ppvObj = this; 26 | 27 | return S_OK; 28 | } 29 | 30 | HRESULT hr = ProxyInterface->QueryInterface(riid, ppvObj); 31 | 32 | if (SUCCEEDED(hr)) 33 | { 34 | genericQueryInterface(riid, ppvObj, m_pDeviceEx); 35 | } 36 | 37 | return hr; 38 | } 39 | 40 | ULONG m_IDirect3DTexture9::AddRef(THIS) 41 | { 42 | return ProxyInterface->AddRef(); 43 | } 44 | 45 | ULONG m_IDirect3DTexture9::Release(THIS) 46 | { 47 | return ProxyInterface->Release(); 48 | } 49 | 50 | HRESULT m_IDirect3DTexture9::GetDevice(THIS_ IDirect3DDevice9** ppDevice) 51 | { 52 | if (!ppDevice) 53 | { 54 | return D3DERR_INVALIDCALL; 55 | } 56 | 57 | m_pDeviceEx->AddRef(); 58 | 59 | *ppDevice = m_pDeviceEx; 60 | 61 | return D3D_OK; 62 | } 63 | 64 | HRESULT m_IDirect3DTexture9::SetPrivateData(THIS_ REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) 65 | { 66 | return ProxyInterface->SetPrivateData(refguid, pData, SizeOfData, Flags); 67 | } 68 | 69 | HRESULT m_IDirect3DTexture9::GetPrivateData(THIS_ REFGUID refguid, void* pData, DWORD* pSizeOfData) 70 | { 71 | return ProxyInterface->GetPrivateData(refguid, pData, pSizeOfData); 72 | } 73 | 74 | HRESULT m_IDirect3DTexture9::FreePrivateData(THIS_ REFGUID refguid) 75 | { 76 | return ProxyInterface->FreePrivateData(refguid); 77 | } 78 | 79 | DWORD m_IDirect3DTexture9::SetPriority(THIS_ DWORD PriorityNew) 80 | { 81 | return ProxyInterface->SetPriority(PriorityNew); 82 | } 83 | 84 | DWORD m_IDirect3DTexture9::GetPriority(THIS) 85 | { 86 | return ProxyInterface->GetPriority(); 87 | } 88 | 89 | void m_IDirect3DTexture9::PreLoad(THIS) 90 | { 91 | return ProxyInterface->PreLoad(); 92 | } 93 | 94 | D3DRESOURCETYPE m_IDirect3DTexture9::GetType(THIS) 95 | { 96 | return ProxyInterface->GetType(); 97 | } 98 | 99 | DWORD m_IDirect3DTexture9::SetLOD(THIS_ DWORD LODNew) 100 | { 101 | return ProxyInterface->SetLOD(LODNew); 102 | } 103 | 104 | DWORD m_IDirect3DTexture9::GetLOD(THIS) 105 | { 106 | return ProxyInterface->GetLOD(); 107 | } 108 | 109 | DWORD m_IDirect3DTexture9::GetLevelCount(THIS) 110 | { 111 | return ProxyInterface->GetLevelCount(); 112 | } 113 | 114 | HRESULT m_IDirect3DTexture9::SetAutoGenFilterType(THIS_ D3DTEXTUREFILTERTYPE FilterType) 115 | { 116 | return ProxyInterface->SetAutoGenFilterType(FilterType); 117 | } 118 | 119 | D3DTEXTUREFILTERTYPE m_IDirect3DTexture9::GetAutoGenFilterType(THIS) 120 | { 121 | return ProxyInterface->GetAutoGenFilterType(); 122 | } 123 | 124 | void m_IDirect3DTexture9::GenerateMipSubLevels(THIS) 125 | { 126 | return ProxyInterface->GenerateMipSubLevels(); 127 | } 128 | 129 | HRESULT m_IDirect3DTexture9::GetLevelDesc(THIS_ UINT Level, D3DSURFACE_DESC *pDesc) 130 | { 131 | return ProxyInterface->GetLevelDesc(Level, pDesc); 132 | } 133 | 134 | HRESULT m_IDirect3DTexture9::GetSurfaceLevel(THIS_ UINT Level, IDirect3DSurface9** ppSurfaceLevel) 135 | { 136 | HRESULT hr = ProxyInterface->GetSurfaceLevel(Level, ppSurfaceLevel); 137 | 138 | if (SUCCEEDED(hr) && ppSurfaceLevel) 139 | { 140 | *ppSurfaceLevel = m_pDeviceEx->ProxyAddressLookupTable->FindAddress(*ppSurfaceLevel); 141 | } 142 | 143 | return hr; 144 | } 145 | 146 | HRESULT m_IDirect3DTexture9::LockRect(THIS_ UINT Level, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) 147 | { 148 | return ProxyInterface->LockRect(Level, pLockedRect, pRect, Flags); 149 | } 150 | 151 | HRESULT m_IDirect3DTexture9::UnlockRect(THIS_ UINT Level) 152 | { 153 | return ProxyInterface->UnlockRect(Level); 154 | } 155 | 156 | HRESULT m_IDirect3DTexture9::AddDirtyRect(THIS_ CONST RECT* pDirtyRect) 157 | { 158 | return ProxyInterface->AddDirtyRect(pDirtyRect); 159 | } 160 | -------------------------------------------------------------------------------- /source/IDirect3DVolumeTexture9.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2020 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #include "d3d9.h" 18 | 19 | HRESULT m_IDirect3DVolumeTexture9::QueryInterface(THIS_ REFIID riid, void** ppvObj) 20 | { 21 | if ((riid == IID_IDirect3DVolumeTexture9 || riid == IID_IUnknown || riid == IID_IDirect3DResource9 || riid == IID_IDirect3DBaseTexture9) && ppvObj) 22 | { 23 | AddRef(); 24 | 25 | *ppvObj = this; 26 | 27 | return S_OK; 28 | } 29 | 30 | HRESULT hr = ProxyInterface->QueryInterface(riid, ppvObj); 31 | 32 | if (SUCCEEDED(hr)) 33 | { 34 | genericQueryInterface(riid, ppvObj, m_pDeviceEx); 35 | } 36 | 37 | return hr; 38 | } 39 | 40 | ULONG m_IDirect3DVolumeTexture9::AddRef(THIS) 41 | { 42 | return ProxyInterface->AddRef(); 43 | } 44 | 45 | ULONG m_IDirect3DVolumeTexture9::Release(THIS) 46 | { 47 | return ProxyInterface->Release(); 48 | } 49 | 50 | HRESULT m_IDirect3DVolumeTexture9::GetDevice(THIS_ IDirect3DDevice9** ppDevice) 51 | { 52 | if (!ppDevice) 53 | { 54 | return D3DERR_INVALIDCALL; 55 | } 56 | 57 | m_pDeviceEx->AddRef(); 58 | 59 | *ppDevice = m_pDeviceEx; 60 | 61 | return D3D_OK; 62 | } 63 | 64 | HRESULT m_IDirect3DVolumeTexture9::SetPrivateData(THIS_ REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) 65 | { 66 | return ProxyInterface->SetPrivateData(refguid, pData, SizeOfData, Flags); 67 | } 68 | 69 | HRESULT m_IDirect3DVolumeTexture9::GetPrivateData(THIS_ REFGUID refguid, void* pData, DWORD* pSizeOfData) 70 | { 71 | return ProxyInterface->GetPrivateData(refguid, pData, pSizeOfData); 72 | } 73 | 74 | HRESULT m_IDirect3DVolumeTexture9::FreePrivateData(THIS_ REFGUID refguid) 75 | { 76 | return ProxyInterface->FreePrivateData(refguid); 77 | } 78 | 79 | DWORD m_IDirect3DVolumeTexture9::SetPriority(THIS_ DWORD PriorityNew) 80 | { 81 | return ProxyInterface->SetPriority(PriorityNew); 82 | } 83 | 84 | DWORD m_IDirect3DVolumeTexture9::GetPriority(THIS) 85 | { 86 | return ProxyInterface->GetPriority(); 87 | } 88 | 89 | void m_IDirect3DVolumeTexture9::PreLoad(THIS) 90 | { 91 | return ProxyInterface->PreLoad(); 92 | } 93 | 94 | D3DRESOURCETYPE m_IDirect3DVolumeTexture9::GetType(THIS) 95 | { 96 | return ProxyInterface->GetType(); 97 | } 98 | 99 | DWORD m_IDirect3DVolumeTexture9::SetLOD(THIS_ DWORD LODNew) 100 | { 101 | return ProxyInterface->SetLOD(LODNew); 102 | } 103 | 104 | DWORD m_IDirect3DVolumeTexture9::GetLOD(THIS) 105 | { 106 | return ProxyInterface->GetLOD(); 107 | } 108 | 109 | DWORD m_IDirect3DVolumeTexture9::GetLevelCount(THIS) 110 | { 111 | return ProxyInterface->GetLevelCount(); 112 | } 113 | 114 | HRESULT m_IDirect3DVolumeTexture9::SetAutoGenFilterType(THIS_ D3DTEXTUREFILTERTYPE FilterType) 115 | { 116 | return ProxyInterface->SetAutoGenFilterType(FilterType); 117 | } 118 | 119 | D3DTEXTUREFILTERTYPE m_IDirect3DVolumeTexture9::GetAutoGenFilterType(THIS) 120 | { 121 | return ProxyInterface->GetAutoGenFilterType(); 122 | } 123 | 124 | void m_IDirect3DVolumeTexture9::GenerateMipSubLevels(THIS) 125 | { 126 | return ProxyInterface->GenerateMipSubLevels(); 127 | } 128 | 129 | HRESULT m_IDirect3DVolumeTexture9::GetLevelDesc(THIS_ UINT Level, D3DVOLUME_DESC *pDesc) 130 | { 131 | return ProxyInterface->GetLevelDesc(Level, pDesc); 132 | } 133 | 134 | HRESULT m_IDirect3DVolumeTexture9::GetVolumeLevel(THIS_ UINT Level, IDirect3DVolume9** ppVolumeLevel) 135 | { 136 | HRESULT hr = ProxyInterface->GetVolumeLevel(Level, ppVolumeLevel); 137 | 138 | if (SUCCEEDED(hr) && ppVolumeLevel) 139 | { 140 | *ppVolumeLevel = m_pDeviceEx->ProxyAddressLookupTable->FindAddress(*ppVolumeLevel); 141 | } 142 | 143 | return hr; 144 | } 145 | 146 | HRESULT m_IDirect3DVolumeTexture9::LockBox(THIS_ UINT Level, D3DLOCKED_BOX* pLockedVolume, CONST D3DBOX* pBox, DWORD Flags) 147 | { 148 | return ProxyInterface->LockBox(Level, pLockedVolume, pBox, Flags); 149 | } 150 | 151 | HRESULT m_IDirect3DVolumeTexture9::UnlockBox(THIS_ UINT Level) 152 | { 153 | return ProxyInterface->UnlockBox(Level); 154 | } 155 | 156 | HRESULT m_IDirect3DVolumeTexture9::AddDirtyBox(THIS_ CONST D3DBOX* pDirtyBox) 157 | { 158 | return ProxyInterface->AddDirtyBox(pDirtyBox); 159 | } 160 | -------------------------------------------------------------------------------- /source/IDirect3DCubeTexture9.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2020 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #include "d3d9.h" 18 | 19 | HRESULT m_IDirect3DCubeTexture9::QueryInterface(THIS_ REFIID riid, void** ppvObj) 20 | { 21 | if ((riid == IID_IDirect3DCubeTexture9 || riid == IID_IUnknown || riid == IID_IDirect3DResource9 || riid == IID_IDirect3DBaseTexture9) && ppvObj) 22 | { 23 | AddRef(); 24 | 25 | *ppvObj = this; 26 | 27 | return S_OK; 28 | } 29 | 30 | HRESULT hr = ProxyInterface->QueryInterface(riid, ppvObj); 31 | 32 | if (SUCCEEDED(hr)) 33 | { 34 | genericQueryInterface(riid, ppvObj, m_pDeviceEx); 35 | } 36 | 37 | return hr; 38 | } 39 | 40 | ULONG m_IDirect3DCubeTexture9::AddRef(THIS) 41 | { 42 | return ProxyInterface->AddRef(); 43 | } 44 | 45 | ULONG m_IDirect3DCubeTexture9::Release(THIS) 46 | { 47 | return ProxyInterface->Release(); 48 | } 49 | 50 | HRESULT m_IDirect3DCubeTexture9::GetDevice(THIS_ IDirect3DDevice9** ppDevice) 51 | { 52 | if (!ppDevice) 53 | { 54 | return D3DERR_INVALIDCALL; 55 | } 56 | 57 | m_pDeviceEx->AddRef(); 58 | 59 | *ppDevice = m_pDeviceEx; 60 | 61 | return D3D_OK; 62 | } 63 | 64 | HRESULT m_IDirect3DCubeTexture9::SetPrivateData(THIS_ REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) 65 | { 66 | return ProxyInterface->SetPrivateData(refguid, pData, SizeOfData, Flags); 67 | } 68 | 69 | HRESULT m_IDirect3DCubeTexture9::GetPrivateData(THIS_ REFGUID refguid, void* pData, DWORD* pSizeOfData) 70 | { 71 | return ProxyInterface->GetPrivateData(refguid, pData, pSizeOfData); 72 | } 73 | 74 | HRESULT m_IDirect3DCubeTexture9::FreePrivateData(THIS_ REFGUID refguid) 75 | { 76 | return ProxyInterface->FreePrivateData(refguid); 77 | } 78 | 79 | DWORD m_IDirect3DCubeTexture9::SetPriority(THIS_ DWORD PriorityNew) 80 | { 81 | return ProxyInterface->SetPriority(PriorityNew); 82 | } 83 | 84 | DWORD m_IDirect3DCubeTexture9::GetPriority(THIS) 85 | { 86 | return ProxyInterface->GetPriority(); 87 | } 88 | 89 | void m_IDirect3DCubeTexture9::PreLoad(THIS) 90 | { 91 | ProxyInterface->PreLoad(); 92 | } 93 | 94 | D3DRESOURCETYPE m_IDirect3DCubeTexture9::GetType(THIS) 95 | { 96 | return ProxyInterface->GetType(); 97 | } 98 | 99 | DWORD m_IDirect3DCubeTexture9::SetLOD(THIS_ DWORD LODNew) 100 | { 101 | return ProxyInterface->SetLOD(LODNew); 102 | } 103 | 104 | DWORD m_IDirect3DCubeTexture9::GetLOD(THIS) 105 | { 106 | return ProxyInterface->GetLOD(); 107 | } 108 | 109 | DWORD m_IDirect3DCubeTexture9::GetLevelCount(THIS) 110 | { 111 | return ProxyInterface->GetLevelCount(); 112 | } 113 | 114 | HRESULT m_IDirect3DCubeTexture9::SetAutoGenFilterType(THIS_ D3DTEXTUREFILTERTYPE FilterType) 115 | { 116 | return ProxyInterface->SetAutoGenFilterType(FilterType); 117 | } 118 | 119 | D3DTEXTUREFILTERTYPE m_IDirect3DCubeTexture9::GetAutoGenFilterType(THIS) 120 | { 121 | return ProxyInterface->GetAutoGenFilterType(); 122 | } 123 | 124 | void m_IDirect3DCubeTexture9::GenerateMipSubLevels(THIS) 125 | { 126 | return ProxyInterface->GenerateMipSubLevels(); 127 | } 128 | 129 | HRESULT m_IDirect3DCubeTexture9::GetLevelDesc(THIS_ UINT Level, D3DSURFACE_DESC *pDesc) 130 | { 131 | return ProxyInterface->GetLevelDesc(Level, pDesc); 132 | } 133 | 134 | HRESULT m_IDirect3DCubeTexture9::GetCubeMapSurface(THIS_ D3DCUBEMAP_FACES FaceType, UINT Level, IDirect3DSurface9** ppCubeMapSurface) 135 | { 136 | HRESULT hr = ProxyInterface->GetCubeMapSurface(FaceType, Level, ppCubeMapSurface); 137 | 138 | if (SUCCEEDED(hr) && ppCubeMapSurface) 139 | { 140 | *ppCubeMapSurface = m_pDeviceEx->ProxyAddressLookupTable->FindAddress(*ppCubeMapSurface); 141 | } 142 | 143 | return hr; 144 | } 145 | 146 | HRESULT m_IDirect3DCubeTexture9::LockRect(THIS_ D3DCUBEMAP_FACES FaceType, UINT Level, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) 147 | { 148 | return ProxyInterface->LockRect(FaceType, Level, pLockedRect, pRect, Flags); 149 | } 150 | 151 | HRESULT m_IDirect3DCubeTexture9::UnlockRect(THIS_ D3DCUBEMAP_FACES FaceType, UINT Level) 152 | { 153 | return ProxyInterface->UnlockRect(FaceType, Level); 154 | } 155 | 156 | HRESULT m_IDirect3DCubeTexture9::AddDirtyRect(THIS_ D3DCUBEMAP_FACES FaceType, CONST RECT* pDirtyRect) 157 | { 158 | return ProxyInterface->AddDirtyRect(FaceType, pDirtyRect); 159 | } 160 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | data/**/*.* 4 | !data/**/*.ini 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | bld/ 21 | [Bb]uild/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | [Ll]og/ 25 | 26 | # Visual Studio 2015 cache/options directory 27 | .vs/ 28 | # Uncomment if you have tasks that create the project's static files in wwwroot 29 | #wwwroot/ 30 | 31 | # MSTest test Results 32 | [Tt]est[Rr]esult*/ 33 | [Bb]uild[Ll]og.* 34 | 35 | # NUNIT 36 | *.VisualState.xml 37 | TestResult.xml 38 | 39 | # Build Results of an ATL Project 40 | [Dd]ebugPS/ 41 | [Rr]eleasePS/ 42 | dlldata.c 43 | 44 | # DNX 45 | project.lock.json 46 | artifacts/ 47 | 48 | *_i.c 49 | *_p.c 50 | *_i.h 51 | *.ilk 52 | *.meta 53 | *.obj 54 | *.pch 55 | *.pdb 56 | *.pgc 57 | *.pgd 58 | *.rsp 59 | *.sbr 60 | *.tlb 61 | *.tli 62 | *.tlh 63 | *.tmp 64 | *.tmp_proj 65 | *.log 66 | *.vspscc 67 | *.vssscc 68 | .builds 69 | *.pidb 70 | *.svclog 71 | *.scc 72 | 73 | # Chutzpah Test files 74 | _Chutzpah* 75 | 76 | # Visual C++ cache files 77 | ipch/ 78 | *.aps 79 | *.ncb 80 | *.opendb 81 | *.opensdf 82 | *.sdf 83 | *.cachefile 84 | *.VC.db 85 | *.VC.VC.opendb 86 | 87 | # Visual Studio profiler 88 | *.psess 89 | *.vsp 90 | *.vspx 91 | *.sap 92 | 93 | # TFS 2012 Local Workspace 94 | $tf/ 95 | 96 | # Guidance Automation Toolkit 97 | *.gpState 98 | 99 | # ReSharper is a .NET coding add-in 100 | _ReSharper*/ 101 | *.[Rr]e[Ss]harper 102 | *.DotSettings.user 103 | 104 | # JustCode is a .NET coding add-in 105 | .JustCode 106 | 107 | # TeamCity is a build add-in 108 | _TeamCity* 109 | 110 | # DotCover is a Code Coverage Tool 111 | *.dotCover 112 | 113 | # NCrunch 114 | _NCrunch_* 115 | .*crunch*.local.xml 116 | nCrunchTemp_* 117 | 118 | # MightyMoose 119 | *.mm.* 120 | AutoTest.Net/ 121 | 122 | # Web workbench (sass) 123 | .sass-cache/ 124 | 125 | # Installshield output folder 126 | [Ee]xpress/ 127 | 128 | # DocProject is a documentation generator add-in 129 | DocProject/buildhelp/ 130 | DocProject/Help/*.HxT 131 | DocProject/Help/*.HxC 132 | DocProject/Help/*.hhc 133 | DocProject/Help/*.hhk 134 | DocProject/Help/*.hhp 135 | DocProject/Help/Html2 136 | DocProject/Help/html 137 | 138 | # Click-Once directory 139 | publish/ 140 | 141 | # Publish Web Output 142 | *.[Pp]ublish.xml 143 | *.azurePubxml 144 | # TODO: Comment the next line if you want to checkin your web deploy settings 145 | # but database connection strings (with potential passwords) will be unencrypted 146 | *.pubxml 147 | *.publishproj 148 | 149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 150 | # checkin your Azure Web App publish settings, but sensitive information contained 151 | # in these scripts will be unencrypted 152 | PublishScripts/ 153 | 154 | # NuGet Packages 155 | *.nupkg 156 | # The packages folder can be ignored because of Package Restore 157 | **/packages/* 158 | # except build/, which is used as an MSBuild target. 159 | !**/packages/build/ 160 | # Uncomment if necessary however generally it will be regenerated when needed 161 | #!**/packages/repositories.config 162 | # NuGet v3's project.json files produces more ignoreable files 163 | *.nuget.props 164 | *.nuget.targets 165 | 166 | # Microsoft Azure Build Output 167 | csx/ 168 | *.build.csdef 169 | 170 | # Microsoft Azure Emulator 171 | ecf/ 172 | rcf/ 173 | 174 | # Windows Store app package directories and files 175 | AppPackages/ 176 | BundleArtifacts/ 177 | Package.StoreAssociation.xml 178 | _pkginfo.txt 179 | 180 | # Visual Studio cache files 181 | # files ending in .cache can be ignored 182 | *.[Cc]ache 183 | # but keep track of directories ending in .cache 184 | !*.[Cc]ache/ 185 | 186 | # Others 187 | ClientBin/ 188 | ~$* 189 | *~ 190 | *.dbmdl 191 | *.dbproj.schemaview 192 | *.pfx 193 | *.publishsettings 194 | node_modules/ 195 | orleans.codegen.cs 196 | 197 | # Since there are multiple workflows, uncomment next line to ignore bower_components 198 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 199 | #bower_components/ 200 | 201 | # RIA/Silverlight projects 202 | Generated_Code/ 203 | 204 | # Backup & report files from converting an old project file 205 | # to a newer Visual Studio version. Backup files are not needed, 206 | # because we have git ;-) 207 | _UpgradeReport_Files/ 208 | Backup*/ 209 | UpgradeLog*.XML 210 | UpgradeLog*.htm 211 | 212 | # SQL Server files 213 | *.mdf 214 | *.ldf 215 | 216 | # Business Intelligence projects 217 | *.rdl.data 218 | *.bim.layout 219 | *.bim_*.settings 220 | 221 | # Microsoft Fakes 222 | FakesAssemblies/ 223 | 224 | # GhostDoc plugin setting file 225 | *.GhostDoc.xml 226 | 227 | # Node.js Tools for Visual Studio 228 | .ntvs_analysis.dat 229 | 230 | # Visual Studio 6 build log 231 | *.plg 232 | 233 | # Visual Studio 6 workspace options file 234 | *.opt 235 | 236 | # Visual Studio LightSwitch build output 237 | **/*.HTMLClient/GeneratedArtifacts 238 | **/*.DesktopClient/GeneratedArtifacts 239 | **/*.DesktopClient/ModelManifest.xml 240 | **/*.Server/GeneratedArtifacts 241 | **/*.Server/ModelManifest.xml 242 | _Pvt_Extensions 243 | 244 | # Paket dependency manager 245 | .paket/paket.exe 246 | paket-files/ 247 | 248 | # FAKE - F# Make 249 | .fake/ 250 | 251 | # JetBrains Rider 252 | .idea/ 253 | *.sln.iml 254 | 255 | # ========================= 256 | # Operating System Files 257 | # ========================= 258 | 259 | # OSX 260 | # ========================= 261 | 262 | .DS_Store 263 | .AppleDouble 264 | .LSOverride 265 | 266 | # Thumbnails 267 | ._* 268 | 269 | # Files that might appear in the root of a volume 270 | .DocumentRevisions-V100 271 | .fseventsd 272 | .Spotlight-V100 273 | .TemporaryItems 274 | .Trashes 275 | .VolumeIcon.icns 276 | 277 | # Directories potentially created on remote AFP share 278 | .AppleDB 279 | .AppleDesktop 280 | Network Trash Folder 281 | Temporary Items 282 | .apdisk 283 | 284 | # Windows 285 | # ========================= 286 | 287 | # Windows image file caches 288 | Thumbs.db 289 | ehthumbs.db 290 | 291 | # Folder config file 292 | Desktop.ini 293 | 294 | # Recycle Bin used on file shares 295 | $RECYCLE.BIN/ 296 | 297 | # Windows Installer files 298 | *.cab 299 | *.msi 300 | *.msm 301 | *.msp 302 | 303 | # Windows shortcuts 304 | *.lnk 305 | -------------------------------------------------------------------------------- /source/IDirect3D9Ex.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2020 Elisha Riedlinger 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will the 5 | * authors be held liable for any damages arising from the use of this software. 6 | * Permission is granted to anyone to use this software for any purpose, including commercial 7 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | * 9 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | * original software. If you use this software in a product, an acknowledgment in the product 11 | * documentation would be appreciated but is not required. 12 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | * being the original software. 14 | * 3. This notice may not be removed or altered from any source distribution. 15 | */ 16 | 17 | #include "d3d9.h" 18 | 19 | HRESULT m_IDirect3D9Ex::QueryInterface(REFIID riid, void** ppvObj) 20 | { 21 | if ((riid == IID_IUnknown || riid == WrapperID) && ppvObj) 22 | { 23 | AddRef(); 24 | 25 | *ppvObj = this; 26 | 27 | return S_OK; 28 | } 29 | 30 | return ProxyInterface->QueryInterface(riid, ppvObj); 31 | } 32 | 33 | ULONG m_IDirect3D9Ex::AddRef() 34 | { 35 | return ProxyInterface->AddRef(); 36 | } 37 | 38 | ULONG m_IDirect3D9Ex::Release() 39 | { 40 | ULONG count = ProxyInterface->Release(); 41 | 42 | if (count == 0) 43 | { 44 | delete this; 45 | } 46 | 47 | return count; 48 | } 49 | 50 | HRESULT m_IDirect3D9Ex::EnumAdapterModes(THIS_ UINT Adapter, D3DFORMAT Format, UINT Mode, D3DDISPLAYMODE* pMode) 51 | { 52 | return ProxyInterface->EnumAdapterModes(Adapter, Format, Mode, pMode); 53 | } 54 | 55 | UINT m_IDirect3D9Ex::GetAdapterCount() 56 | { 57 | return ProxyInterface->GetAdapterCount(); 58 | } 59 | 60 | HRESULT m_IDirect3D9Ex::GetAdapterDisplayMode(UINT Adapter, D3DDISPLAYMODE *pMode) 61 | { 62 | return ProxyInterface->GetAdapterDisplayMode(Adapter, pMode); 63 | } 64 | 65 | HRESULT m_IDirect3D9Ex::GetAdapterIdentifier(UINT Adapter, DWORD Flags, D3DADAPTER_IDENTIFIER9 *pIdentifier) 66 | { 67 | return ProxyInterface->GetAdapterIdentifier(Adapter, Flags, pIdentifier); 68 | } 69 | 70 | UINT m_IDirect3D9Ex::GetAdapterModeCount(THIS_ UINT Adapter, D3DFORMAT Format) 71 | { 72 | return ProxyInterface->GetAdapterModeCount(Adapter, Format); 73 | } 74 | 75 | HMONITOR m_IDirect3D9Ex::GetAdapterMonitor(UINT Adapter) 76 | { 77 | return ProxyInterface->GetAdapterMonitor(Adapter); 78 | } 79 | 80 | HRESULT m_IDirect3D9Ex::GetDeviceCaps(UINT Adapter, D3DDEVTYPE DeviceType, D3DCAPS9 *pCaps) 81 | { 82 | return ProxyInterface->GetDeviceCaps(Adapter, DeviceType, pCaps); 83 | } 84 | 85 | HRESULT m_IDirect3D9Ex::RegisterSoftwareDevice(void *pInitializeFunction) 86 | { 87 | return ProxyInterface->RegisterSoftwareDevice(pInitializeFunction); 88 | } 89 | 90 | HRESULT m_IDirect3D9Ex::CheckDepthStencilMatch(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, D3DFORMAT RenderTargetFormat, D3DFORMAT DepthStencilFormat) 91 | { 92 | return ProxyInterface->CheckDepthStencilMatch(Adapter, DeviceType, AdapterFormat, RenderTargetFormat, DepthStencilFormat); 93 | } 94 | 95 | HRESULT m_IDirect3D9Ex::CheckDeviceFormat(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat) 96 | { 97 | return ProxyInterface->CheckDeviceFormat(Adapter, DeviceType, AdapterFormat, Usage, RType, CheckFormat); 98 | } 99 | 100 | HRESULT m_IDirect3D9Ex::CheckDeviceMultiSampleType(THIS_ UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat, BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType, DWORD* pQualityLevels) 101 | { 102 | return ProxyInterface->CheckDeviceMultiSampleType(Adapter, DeviceType, SurfaceFormat, Windowed, MultiSampleType, pQualityLevels); 103 | } 104 | 105 | HRESULT m_IDirect3D9Ex::CheckDeviceType(UINT Adapter, D3DDEVTYPE CheckType, D3DFORMAT DisplayFormat, D3DFORMAT BackBufferFormat, BOOL Windowed) 106 | { 107 | return ProxyInterface->CheckDeviceType(Adapter, CheckType, DisplayFormat, BackBufferFormat, Windowed); 108 | } 109 | 110 | HRESULT m_IDirect3D9Ex::CheckDeviceFormatConversion(THIS_ UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SourceFormat, D3DFORMAT TargetFormat) 111 | { 112 | return ProxyInterface->CheckDeviceFormatConversion(Adapter, DeviceType, SourceFormat, TargetFormat); 113 | } 114 | 115 | //HRESULT m_IDirect3D9Ex::CreateDevice(UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS *pPresentationParameters, IDirect3DDevice9 **ppReturnedDeviceInterface) 116 | //{ 117 | // HRESULT hr = ProxyInterface->CreateDevice(Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, ppReturnedDeviceInterface); 118 | // 119 | // if (SUCCEEDED(hr) && ppReturnedDeviceInterface) 120 | // { 121 | // *ppReturnedDeviceInterface = new m_IDirect3DDevice9Ex((IDirect3DDevice9Ex*)*ppReturnedDeviceInterface, this, IID_IDirect3DDevice9); 122 | // } 123 | // 124 | // return hr; 125 | //} 126 | 127 | UINT m_IDirect3D9Ex::GetAdapterModeCountEx(THIS_ UINT Adapter, CONST D3DDISPLAYMODEFILTER* pFilter) 128 | { 129 | return ProxyInterface->GetAdapterModeCountEx(Adapter, pFilter); 130 | } 131 | 132 | HRESULT m_IDirect3D9Ex::EnumAdapterModesEx(THIS_ UINT Adapter, CONST D3DDISPLAYMODEFILTER* pFilter, UINT Mode, D3DDISPLAYMODEEX* pMode) 133 | { 134 | return ProxyInterface->EnumAdapterModesEx(Adapter, pFilter, Mode, pMode); 135 | } 136 | 137 | HRESULT m_IDirect3D9Ex::GetAdapterDisplayModeEx(THIS_ UINT Adapter, D3DDISPLAYMODEEX* pMode, D3DDISPLAYROTATION* pRotation) 138 | { 139 | return ProxyInterface->GetAdapterDisplayModeEx(Adapter, pMode, pRotation); 140 | } 141 | 142 | //HRESULT m_IDirect3D9Ex::CreateDeviceEx(THIS_ UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS* pPresentationParameters, D3DDISPLAYMODEEX* pFullscreenDisplayMode, IDirect3DDevice9Ex** ppReturnedDeviceInterface) 143 | //{ 144 | // HRESULT hr = ProxyInterface->CreateDeviceEx(Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, pFullscreenDisplayMode, ppReturnedDeviceInterface); 145 | // 146 | // if (SUCCEEDED(hr) && ppReturnedDeviceInterface) 147 | // { 148 | // *ppReturnedDeviceInterface = new m_IDirect3DDevice9Ex(*ppReturnedDeviceInterface, this, IID_IDirect3DDevice9Ex); 149 | // } 150 | // 151 | // return hr; 152 | //} 153 | 154 | HRESULT m_IDirect3D9Ex::GetAdapterLUID(THIS_ UINT Adapter, LUID * pLUID) 155 | { 156 | return ProxyInterface->GetAdapterLUID(Adapter, pLUID); 157 | } 158 | -------------------------------------------------------------------------------- /source/helpers.h: -------------------------------------------------------------------------------- 1 | #ifndef __HELPERS_H 2 | #define __HELPERS_H 3 | 4 | #include 5 | 6 | typedef BOOL(WINAPI* LPFN_ISTOPLEVELWINDOW)(HWND); 7 | LPFN_ISTOPLEVELWINDOW fnIsTopLevelWindow = NULL; 8 | 9 | BOOL _fnIsTopLevelWindow(HWND hWnd) 10 | { 11 | /* IsTopLevelWindow is not available on all versions of Windows. 12 | * Use GetModuleHandle to get a handle to the DLL that contains the function 13 | * and GetProcAddress to get a pointer to the function if available. 14 | */ 15 | if (fnIsTopLevelWindow == NULL) { 16 | fnIsTopLevelWindow = (LPFN_ISTOPLEVELWINDOW)GetProcAddress(GetModuleHandleA("user32"), "IsTopLevelWindow"); 17 | if (fnIsTopLevelWindow == NULL) { 18 | fnIsTopLevelWindow = (LPFN_ISTOPLEVELWINDOW)-1; 19 | } 20 | } 21 | if (fnIsTopLevelWindow != (LPFN_ISTOPLEVELWINDOW)-1) { 22 | return fnIsTopLevelWindow(hWnd); 23 | } 24 | /* If no avail, use older method which is available in Win2000+ */ 25 | return (GetAncestor(hWnd, GA_ROOT) == hWnd); 26 | } 27 | 28 | BOOL IsValueIntAtom(DWORD dw) 29 | { 30 | return (HIWORD(dw) == 0 && LOWORD(dw) < 0xC000); 31 | } 32 | 33 | BOOL IsSystemClassNameA(LPCSTR classNameA) 34 | { 35 | if (!lstrcmpiA(classNameA, "BUTTON")) 36 | return TRUE; 37 | if (!lstrcmpiA(classNameA, "COMBOBOX")) 38 | return TRUE; 39 | if (!lstrcmpiA(classNameA, "EDIT")) 40 | return TRUE; 41 | if (!lstrcmpiA(classNameA, "LISTBOX")) 42 | return TRUE; 43 | if (!lstrcmpiA(classNameA, "MDICLIENT")) 44 | return TRUE; 45 | if (!lstrcmpiA(classNameA, "RICHEDIT")) 46 | return TRUE; 47 | if (!lstrcmpiA(classNameA, "RICHEDIT_CLASS")) 48 | return TRUE; 49 | if (!lstrcmpiA(classNameA, "SCROLLBAR")) 50 | return TRUE; 51 | if (!lstrcmpiA(classNameA, "STATIC")) 52 | return TRUE; 53 | if (!lstrcmpiA(classNameA, "ANIMATE_CLASS")) 54 | return TRUE; 55 | if (!lstrcmpiA(classNameA, "DATETIMEPICK_CLASS")) 56 | return TRUE; 57 | if (!lstrcmpiA(classNameA, "HOTKEY_CLASS")) 58 | return TRUE; 59 | if (!lstrcmpiA(classNameA, "LINK_CLASS")) 60 | return TRUE; 61 | if (!lstrcmpiA(classNameA, "MONTHCAL_CLASS")) 62 | return TRUE; 63 | if (!lstrcmpiA(classNameA, "NATIVEFNTCTL_CLASS")) 64 | return TRUE; 65 | if (!lstrcmpiA(classNameA, "PROGRESS_CLASS")) 66 | return TRUE; 67 | if (!lstrcmpiA(classNameA, "REBARCLASSNAME")) 68 | return TRUE; 69 | if (!lstrcmpiA(classNameA, "STANDARD_CLASSES")) 70 | return TRUE; 71 | if (!lstrcmpiA(classNameA, "STATUSCLASSNAME")) 72 | return TRUE; 73 | if (!lstrcmpiA(classNameA, "TOOLBARCLASSNAME")) 74 | return TRUE; 75 | if (!lstrcmpiA(classNameA, "TOOLTIPS_CLASS")) 76 | return TRUE; 77 | if (!lstrcmpiA(classNameA, "TRACKBAR_CLASS")) 78 | return TRUE; 79 | if (!lstrcmpiA(classNameA, "UPDOWN_CLASS")) 80 | return TRUE; 81 | if (!lstrcmpiA(classNameA, "WC_BUTTON")) 82 | return TRUE; 83 | if (!lstrcmpiA(classNameA, "WC_COMBOBOX")) 84 | return TRUE; 85 | if (!lstrcmpiA(classNameA, "WC_COMBOBOXEX")) 86 | return TRUE; 87 | if (!lstrcmpiA(classNameA, "WC_EDIT")) 88 | return TRUE; 89 | if (!lstrcmpiA(classNameA, "WC_HEADER")) 90 | return TRUE; 91 | if (!lstrcmpiA(classNameA, "WC_LISTBOX")) 92 | return TRUE; 93 | if (!lstrcmpiA(classNameA, "WC_IPADDRESS")) 94 | return TRUE; 95 | if (!lstrcmpiA(classNameA, "WC_LINK")) 96 | return TRUE; 97 | if (!lstrcmpiA(classNameA, "WC_LISTVIEW")) 98 | return TRUE; 99 | if (!lstrcmpiA(classNameA, "WC_NATIVEFONTCTL")) 100 | return TRUE; 101 | if (!lstrcmpiA(classNameA, "WC_PAGESCROLLER")) 102 | return TRUE; 103 | if (!lstrcmpiA(classNameA, "WC_SCROLLBAR")) 104 | return TRUE; 105 | if (!lstrcmpiA(classNameA, "WC_STATIC")) 106 | return TRUE; 107 | if (!lstrcmpiA(classNameA, "WC_TABCONTROL")) 108 | return TRUE; 109 | if (!lstrcmpiA(classNameA, "WC_TREEVIEW")) 110 | return TRUE; 111 | return FALSE; 112 | } 113 | 114 | BOOL IsSystemClassNameW(LPCWSTR classNameW) 115 | { 116 | if (!lstrcmpiW(classNameW, L"BUTTON")) 117 | return TRUE; 118 | if (!lstrcmpiW(classNameW, L"COMBOBOX")) 119 | return TRUE; 120 | if (!lstrcmpiW(classNameW, L"EDIT")) 121 | return TRUE; 122 | if (!lstrcmpiW(classNameW, L"LISTBOX")) 123 | return TRUE; 124 | if (!lstrcmpiW(classNameW, L"MDICLIENT")) 125 | return TRUE; 126 | if (!lstrcmpiW(classNameW, L"RICHEDIT")) 127 | return TRUE; 128 | if (!lstrcmpiW(classNameW, L"RICHEDIT_CLASS")) 129 | return TRUE; 130 | if (!lstrcmpiW(classNameW, L"SCROLLBAR")) 131 | return TRUE; 132 | if (!lstrcmpiW(classNameW, L"STATIC")) 133 | return TRUE; 134 | if (!lstrcmpiW(classNameW, L"ANIMATE_CLASS")) 135 | return TRUE; 136 | if (!lstrcmpiW(classNameW, L"DATETIMEPICK_CLASS")) 137 | return TRUE; 138 | if (!lstrcmpiW(classNameW, L"HOTKEY_CLASS")) 139 | return TRUE; 140 | if (!lstrcmpiW(classNameW, L"LINK_CLASS")) 141 | return TRUE; 142 | if (!lstrcmpiW(classNameW, L"MONTHCAL_CLASS")) 143 | return TRUE; 144 | if (!lstrcmpiW(classNameW, L"NATIVEFNTCTL_CLASS")) 145 | return TRUE; 146 | if (!lstrcmpiW(classNameW, L"PROGRESS_CLASS")) 147 | return TRUE; 148 | if (!lstrcmpiW(classNameW, L"REBARCLASSNAME")) 149 | return TRUE; 150 | if (!lstrcmpiW(classNameW, L"STANDARD_CLASSES")) 151 | return TRUE; 152 | if (!lstrcmpiW(classNameW, L"STATUSCLASSNAME")) 153 | return TRUE; 154 | if (!lstrcmpiW(classNameW, L"TOOLBARCLASSNAME")) 155 | return TRUE; 156 | if (!lstrcmpiW(classNameW, L"TOOLTIPS_CLASS")) 157 | return TRUE; 158 | if (!lstrcmpiW(classNameW, L"TRACKBAR_CLASS")) 159 | return TRUE; 160 | if (!lstrcmpiW(classNameW, L"UPDOWN_CLASS")) 161 | return TRUE; 162 | if (!lstrcmpiW(classNameW, L"WC_BUTTON")) 163 | return TRUE; 164 | if (!lstrcmpiW(classNameW, L"WC_COMBOBOX")) 165 | return TRUE; 166 | if (!lstrcmpiW(classNameW, L"WC_COMBOBOXEX")) 167 | return TRUE; 168 | if (!lstrcmpiW(classNameW, L"WC_EDIT")) 169 | return TRUE; 170 | if (!lstrcmpiW(classNameW, L"WC_HEADER")) 171 | return TRUE; 172 | if (!lstrcmpiW(classNameW, L"WC_LISTBOX")) 173 | return TRUE; 174 | if (!lstrcmpiW(classNameW, L"WC_IPADDRESS")) 175 | return TRUE; 176 | if (!lstrcmpiW(classNameW, L"WC_LINK")) 177 | return TRUE; 178 | if (!lstrcmpiW(classNameW, L"WC_LISTVIEW")) 179 | return TRUE; 180 | if (!lstrcmpiW(classNameW, L"WC_NATIVEFONTCTL")) 181 | return TRUE; 182 | if (!lstrcmpiW(classNameW, L"WC_PAGESCROLLER")) 183 | return TRUE; 184 | if (!lstrcmpiW(classNameW, L"WC_SCROLLBAR")) 185 | return TRUE; 186 | if (!lstrcmpiW(classNameW, L"WC_STATIC")) 187 | return TRUE; 188 | if (!lstrcmpiW(classNameW, L"WC_TABCONTROL")) 189 | return TRUE; 190 | if (!lstrcmpiW(classNameW, L"WC_TREEVIEW")) 191 | return TRUE; 192 | return FALSE; 193 | } 194 | 195 | #endif //__HELPERS_H -------------------------------------------------------------------------------- /source/dxsdk/d3dx9shape.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (C) Microsoft Corporation. All Rights Reserved. 4 | // 5 | // File: d3dx9shapes.h 6 | // Content: D3DX simple shapes 7 | // 8 | /////////////////////////////////////////////////////////////////////////// 9 | 10 | #include "d3dx9.h" 11 | 12 | #ifndef __D3DX9SHAPES_H__ 13 | #define __D3DX9SHAPES_H__ 14 | 15 | /////////////////////////////////////////////////////////////////////////// 16 | // Functions: 17 | /////////////////////////////////////////////////////////////////////////// 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif //__cplusplus 22 | 23 | 24 | //------------------------------------------------------------------------- 25 | // D3DXCreatePolygon: 26 | // ------------------ 27 | // Creates a mesh containing an n-sided polygon. The polygon is centered 28 | // at the origin. 29 | // 30 | // Parameters: 31 | // 32 | // pDevice The D3D device with which the mesh is going to be used. 33 | // Length Length of each side. 34 | // Sides Number of sides the polygon has. (Must be >= 3) 35 | // ppMesh The mesh object which will be created 36 | // ppAdjacency Returns a buffer containing adjacency info. Can be NULL. 37 | //------------------------------------------------------------------------- 38 | HRESULT WINAPI 39 | D3DXCreatePolygon( 40 | LPDIRECT3DDEVICE9 pDevice, 41 | FLOAT Length, 42 | UINT Sides, 43 | LPD3DXMESH* ppMesh, 44 | LPD3DXBUFFER* ppAdjacency); 45 | 46 | 47 | //------------------------------------------------------------------------- 48 | // D3DXCreateBox: 49 | // -------------- 50 | // Creates a mesh containing an axis-aligned box. The box is centered at 51 | // the origin. 52 | // 53 | // Parameters: 54 | // 55 | // pDevice The D3D device with which the mesh is going to be used. 56 | // Width Width of box (along X-axis) 57 | // Height Height of box (along Y-axis) 58 | // Depth Depth of box (along Z-axis) 59 | // ppMesh The mesh object which will be created 60 | // ppAdjacency Returns a buffer containing adjacency info. Can be NULL. 61 | //------------------------------------------------------------------------- 62 | HRESULT WINAPI 63 | D3DXCreateBox( 64 | LPDIRECT3DDEVICE9 pDevice, 65 | FLOAT Width, 66 | FLOAT Height, 67 | FLOAT Depth, 68 | LPD3DXMESH* ppMesh, 69 | LPD3DXBUFFER* ppAdjacency); 70 | 71 | 72 | //------------------------------------------------------------------------- 73 | // D3DXCreateCylinder: 74 | // ------------------- 75 | // Creates a mesh containing a cylinder. The generated cylinder is 76 | // centered at the origin, and its axis is aligned with the Z-axis. 77 | // 78 | // Parameters: 79 | // 80 | // pDevice The D3D device with which the mesh is going to be used. 81 | // Radius1 Radius at -Z end (should be >= 0.0f) 82 | // Radius2 Radius at +Z end (should be >= 0.0f) 83 | // Length Length of cylinder (along Z-axis) 84 | // Slices Number of slices about the main axis 85 | // Stacks Number of stacks along the main axis 86 | // ppMesh The mesh object which will be created 87 | // ppAdjacency Returns a buffer containing adjacency info. Can be NULL. 88 | //------------------------------------------------------------------------- 89 | HRESULT WINAPI 90 | D3DXCreateCylinder( 91 | LPDIRECT3DDEVICE9 pDevice, 92 | FLOAT Radius1, 93 | FLOAT Radius2, 94 | FLOAT Length, 95 | UINT Slices, 96 | UINT Stacks, 97 | LPD3DXMESH* ppMesh, 98 | LPD3DXBUFFER* ppAdjacency); 99 | 100 | 101 | //------------------------------------------------------------------------- 102 | // D3DXCreateSphere: 103 | // ----------------- 104 | // Creates a mesh containing a sphere. The sphere is centered at the 105 | // origin. 106 | // 107 | // Parameters: 108 | // 109 | // pDevice The D3D device with which the mesh is going to be used. 110 | // Radius Radius of the sphere (should be >= 0.0f) 111 | // Slices Number of slices about the main axis 112 | // Stacks Number of stacks along the main axis 113 | // ppMesh The mesh object which will be created 114 | // ppAdjacency Returns a buffer containing adjacency info. Can be NULL. 115 | //------------------------------------------------------------------------- 116 | HRESULT WINAPI 117 | D3DXCreateSphere( 118 | LPDIRECT3DDEVICE9 pDevice, 119 | FLOAT Radius, 120 | UINT Slices, 121 | UINT Stacks, 122 | LPD3DXMESH* ppMesh, 123 | LPD3DXBUFFER* ppAdjacency); 124 | 125 | 126 | //------------------------------------------------------------------------- 127 | // D3DXCreateTorus: 128 | // ---------------- 129 | // Creates a mesh containing a torus. The generated torus is centered at 130 | // the origin, and its axis is aligned with the Z-axis. 131 | // 132 | // Parameters: 133 | // 134 | // pDevice The D3D device with which the mesh is going to be used. 135 | // InnerRadius Inner radius of the torus (should be >= 0.0f) 136 | // OuterRadius Outer radius of the torue (should be >= 0.0f) 137 | // Sides Number of sides in a cross-section (must be >= 3) 138 | // Rings Number of rings making up the torus (must be >= 3) 139 | // ppMesh The mesh object which will be created 140 | // ppAdjacency Returns a buffer containing adjacency info. Can be NULL. 141 | //------------------------------------------------------------------------- 142 | HRESULT WINAPI 143 | D3DXCreateTorus( 144 | LPDIRECT3DDEVICE9 pDevice, 145 | FLOAT InnerRadius, 146 | FLOAT OuterRadius, 147 | UINT Sides, 148 | UINT Rings, 149 | LPD3DXMESH* ppMesh, 150 | LPD3DXBUFFER* ppAdjacency); 151 | 152 | 153 | //------------------------------------------------------------------------- 154 | // D3DXCreateTeapot: 155 | // ----------------- 156 | // Creates a mesh containing a teapot. 157 | // 158 | // Parameters: 159 | // 160 | // pDevice The D3D device with which the mesh is going to be used. 161 | // ppMesh The mesh object which will be created 162 | // ppAdjacency Returns a buffer containing adjacency info. Can be NULL. 163 | //------------------------------------------------------------------------- 164 | HRESULT WINAPI 165 | D3DXCreateTeapot( 166 | LPDIRECT3DDEVICE9 pDevice, 167 | LPD3DXMESH* ppMesh, 168 | LPD3DXBUFFER* ppAdjacency); 169 | 170 | 171 | //------------------------------------------------------------------------- 172 | // D3DXCreateText: 173 | // --------------- 174 | // Creates a mesh containing the specified text using the font associated 175 | // with the device context. 176 | // 177 | // Parameters: 178 | // 179 | // pDevice The D3D device with which the mesh is going to be used. 180 | // hDC Device context, with desired font selected 181 | // pText Text to generate 182 | // Deviation Maximum chordal deviation from true font outlines 183 | // Extrusion Amount to extrude text in -Z direction 184 | // ppMesh The mesh object which will be created 185 | // pGlyphMetrics Address of buffer to receive glyph metric data (or NULL) 186 | //------------------------------------------------------------------------- 187 | HRESULT WINAPI 188 | D3DXCreateTextA( 189 | LPDIRECT3DDEVICE9 pDevice, 190 | HDC hDC, 191 | LPCSTR pText, 192 | FLOAT Deviation, 193 | FLOAT Extrusion, 194 | LPD3DXMESH* ppMesh, 195 | LPD3DXBUFFER* ppAdjacency, 196 | LPGLYPHMETRICSFLOAT pGlyphMetrics); 197 | 198 | HRESULT WINAPI 199 | D3DXCreateTextW( 200 | LPDIRECT3DDEVICE9 pDevice, 201 | HDC hDC, 202 | LPCWSTR pText, 203 | FLOAT Deviation, 204 | FLOAT Extrusion, 205 | LPD3DXMESH* ppMesh, 206 | LPD3DXBUFFER* ppAdjacency, 207 | LPGLYPHMETRICSFLOAT pGlyphMetrics); 208 | 209 | #ifdef UNICODE 210 | #define D3DXCreateText D3DXCreateTextW 211 | #else 212 | #define D3DXCreateText D3DXCreateTextA 213 | #endif 214 | 215 | 216 | #ifdef __cplusplus 217 | } 218 | #endif //__cplusplus 219 | 220 | #endif //__D3DX9SHAPES_H__ 221 | 222 | -------------------------------------------------------------------------------- /source/iathook.h: -------------------------------------------------------------------------------- 1 | #ifndef __IATHOOK_H 2 | #define __IATHOOK_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | class IATHook 11 | { 12 | public: 13 | template 14 | static auto Replace(HMODULE target_module, std::string_view dll_name, Ts&& ... inputs) 15 | { 16 | std::map> originalPtrs; 17 | 18 | const DWORD_PTR instance = reinterpret_cast(target_module); 19 | const PIMAGE_NT_HEADERS ntHeader = reinterpret_cast(instance + reinterpret_cast(instance)->e_lfanew); 20 | PIMAGE_IMPORT_DESCRIPTOR pImports = reinterpret_cast(instance + ntHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress); 21 | DWORD dwProtect[2]; 22 | 23 | for (; pImports->Name != 0; pImports++) 24 | { 25 | if (_stricmp(reinterpret_cast(instance + pImports->Name), dll_name.data()) == 0) 26 | { 27 | if (pImports->OriginalFirstThunk != 0) 28 | { 29 | const PIMAGE_THUNK_DATA pThunk = reinterpret_cast(instance + pImports->OriginalFirstThunk); 30 | 31 | for (ptrdiff_t j = 0; pThunk[j].u1.AddressOfData != 0; j++) 32 | { 33 | auto pAddress = reinterpret_cast(instance + pImports->FirstThunk) + j; 34 | if (!pAddress) continue; 35 | VirtualProtect(pAddress, sizeof(pAddress), PAGE_EXECUTE_READWRITE, &dwProtect[0]); 36 | ([&] 37 | { 38 | auto name = std::string_view(std::get<0>(inputs)); 39 | auto num = std::string("-1"); 40 | if (name.contains("@")) { 41 | num = name.substr(name.find_last_of("@") + 1); 42 | name = name.substr(0, name.find_last_of("@")); 43 | } 44 | 45 | if (pThunk[j].u1.Ordinal & IMAGE_ORDINAL_FLAG) 46 | { 47 | try 48 | { 49 | if (IMAGE_ORDINAL(pThunk[j].u1.Ordinal) == std::stoi(num.data())) 50 | { 51 | originalPtrs[std::get<0>(inputs)] = std::async(std::launch::deferred, [&]() -> void* { return *pAddress; }); 52 | originalPtrs[std::get<0>(inputs)].wait(); 53 | *pAddress = std::get<1>(inputs); 54 | } 55 | } 56 | catch (...) {} 57 | } 58 | else if ((*pAddress && *pAddress == (void*)GetProcAddress(GetModuleHandleA(dll_name.data()), name.data())) || 59 | (strcmp(reinterpret_cast(instance + pThunk[j].u1.AddressOfData)->Name, name.data()) == 0)) 60 | { 61 | originalPtrs[std::get<0>(inputs)] = std::async(std::launch::deferred, [&]() -> void* { return *pAddress; }); 62 | originalPtrs[std::get<0>(inputs)].wait(); 63 | *pAddress = std::get<1>(inputs); 64 | } 65 | } (), ...); 66 | VirtualProtect(pAddress, sizeof(pAddress), dwProtect[0], &dwProtect[1]); 67 | } 68 | } 69 | else 70 | { 71 | auto pFunctions = reinterpret_cast(instance + pImports->FirstThunk); 72 | 73 | for (ptrdiff_t j = 0; pFunctions[j] != nullptr; j++) 74 | { 75 | auto pAddress = reinterpret_cast(pFunctions[j]); 76 | VirtualProtect(pAddress, sizeof(pAddress), PAGE_EXECUTE_READWRITE, &dwProtect[0]); 77 | ([&] 78 | { 79 | if (*pAddress && *pAddress == (void*)GetProcAddress(GetModuleHandleA(dll_name.data()), std::get<0>(inputs))) 80 | { 81 | originalPtrs[std::get<0>(inputs)] = std::async(std::launch::deferred, [&]() -> void* { return *pAddress; }); 82 | originalPtrs[std::get<0>(inputs)].wait(); 83 | *pAddress = std::get<1>(inputs); 84 | } 85 | } (), ...); 86 | VirtualProtect(pAddress, sizeof(pAddress), dwProtect[0], &dwProtect[1]); 87 | } 88 | } 89 | } 90 | } 91 | 92 | if (originalPtrs.empty()) 93 | { 94 | PIMAGE_DELAYLOAD_DESCRIPTOR pDelayed = reinterpret_cast(instance + ntHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT].VirtualAddress); 95 | if (pDelayed) 96 | { 97 | for (; pDelayed->DllNameRVA != 0; pDelayed++) 98 | { 99 | if (_stricmp(reinterpret_cast(instance + pDelayed->DllNameRVA), dll_name.data()) == 0) 100 | { 101 | if (pDelayed->ImportAddressTableRVA != 0) 102 | { 103 | const PIMAGE_THUNK_DATA pThunk = reinterpret_cast(instance + pDelayed->ImportNameTableRVA); 104 | const PIMAGE_THUNK_DATA pFThunk = reinterpret_cast(instance + pDelayed->ImportAddressTableRVA); 105 | 106 | for (ptrdiff_t j = 0; pThunk[j].u1.AddressOfData != 0; j++) 107 | { 108 | auto pAddress = reinterpret_cast(pFThunk[j].u1.Function); 109 | if (!pAddress) continue; 110 | if (pThunk[j].u1.Ordinal & IMAGE_ORDINAL_FLAG) 111 | pAddress = *reinterpret_cast(pFThunk[j].u1.Function + 1); // mov eax, offset * 112 | 113 | VirtualProtect(pAddress, sizeof(pAddress), PAGE_EXECUTE_READWRITE, &dwProtect[0]); 114 | ([&] 115 | { 116 | auto name = std::string_view(std::get<0>(inputs)); 117 | auto num = std::string("-1"); 118 | if (name.contains("@")) { 119 | num = name.substr(name.find_last_of("@") + 1); 120 | name = name.substr(0, name.find_last_of("@")); 121 | } 122 | 123 | if (pThunk[j].u1.Ordinal & IMAGE_ORDINAL_FLAG) 124 | { 125 | try 126 | { 127 | if (IMAGE_ORDINAL(pThunk[j].u1.Ordinal) == std::stoi(num.data())) 128 | { 129 | originalPtrs[std::get<0>(inputs)] = std::async(std::launch::async, 130 | [](void** pAddress, void* value, PVOID instance) -> void* 131 | { 132 | DWORD dwProtect[2]; 133 | VirtualProtect(pAddress, sizeof(pAddress), PAGE_EXECUTE_READWRITE, &dwProtect[0]); 134 | MEMORY_BASIC_INFORMATION mbi; 135 | mbi.AllocationBase = instance; 136 | do 137 | { 138 | VirtualQuery(*pAddress, &mbi, sizeof(MEMORY_BASIC_INFORMATION)); 139 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); 140 | } while (mbi.AllocationBase == instance); 141 | auto r = *pAddress; 142 | *pAddress = value; 143 | VirtualProtect(pAddress, sizeof(pAddress), dwProtect[0], &dwProtect[1]); 144 | return r; 145 | }, pAddress, std::get<1>(inputs), (PVOID)instance); 146 | } 147 | } 148 | catch (...) {} 149 | } 150 | else if ((*pAddress && *pAddress == (void*)GetProcAddress(GetModuleHandleA(dll_name.data()), name.data())) || 151 | (strcmp(reinterpret_cast(instance + pThunk[j].u1.AddressOfData)->Name, name.data()) == 0)) 152 | { 153 | originalPtrs[std::get<0>(inputs)] = std::async(std::launch::async, 154 | [](void** pAddress, void* value, PVOID instance) -> void* 155 | { 156 | DWORD dwProtect[2]; 157 | VirtualProtect(pAddress, sizeof(pAddress), PAGE_EXECUTE_READWRITE, &dwProtect[0]); 158 | MEMORY_BASIC_INFORMATION mbi; 159 | mbi.AllocationBase = instance; 160 | do 161 | { 162 | VirtualQuery(*pAddress, &mbi, sizeof(MEMORY_BASIC_INFORMATION)); 163 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); 164 | } while (mbi.AllocationBase == instance); 165 | auto r = *pAddress; 166 | *pAddress = value; 167 | VirtualProtect(pAddress, sizeof(pAddress), dwProtect[0], &dwProtect[1]); 168 | return r; 169 | }, pAddress, std::get<1>(inputs), (PVOID)instance); 170 | } 171 | } (), ...); 172 | VirtualProtect(pAddress, sizeof(pAddress), dwProtect[0], &dwProtect[1]); 173 | } 174 | } 175 | } 176 | } 177 | } 178 | } 179 | 180 | if (originalPtrs.empty()) // e.g. re5dx9.exe steam 181 | { 182 | static auto getSection = [](const PIMAGE_NT_HEADERS nt_headers, unsigned section) -> PIMAGE_SECTION_HEADER 183 | { 184 | return reinterpret_cast( 185 | (UCHAR*)nt_headers->OptionalHeader.DataDirectory + 186 | nt_headers->OptionalHeader.NumberOfRvaAndSizes * sizeof(IMAGE_DATA_DIRECTORY) + 187 | section * sizeof(IMAGE_SECTION_HEADER)); 188 | }; 189 | 190 | for (auto i = 0; i < ntHeader->FileHeader.NumberOfSections; i++) 191 | { 192 | auto sec = getSection(ntHeader, i); 193 | auto pFunctions = reinterpret_cast(instance + max(sec->PointerToRawData, sec->VirtualAddress)); 194 | 195 | for (ptrdiff_t j = 0; j < 300; j++) 196 | { 197 | auto pAddress = reinterpret_cast(&pFunctions[j]); 198 | VirtualProtect(pAddress, sizeof(pAddress), PAGE_EXECUTE_READWRITE, &dwProtect[0]); 199 | ([&] 200 | { 201 | auto name = std::string_view(std::get<0>(inputs)); 202 | auto num = std::string("-1"); 203 | if (name.contains("@")) { 204 | num = name.substr(name.find_last_of("@") + 1); 205 | name = name.substr(0, name.find_last_of("@")); 206 | } 207 | 208 | if (*pAddress && *pAddress == (void*)GetProcAddress(GetModuleHandleA(dll_name.data()), name.data())) 209 | { 210 | originalPtrs[std::get<0>(inputs)] = std::async(std::launch::deferred, [&]() -> void* { return *pAddress; }); 211 | originalPtrs[std::get<0>(inputs)].wait(); 212 | *pAddress = std::get<1>(inputs); 213 | } 214 | } (), ...); 215 | VirtualProtect(pAddress, sizeof(pAddress), dwProtect[0], &dwProtect[1]); 216 | } 217 | 218 | if (!originalPtrs.empty()) 219 | return originalPtrs; 220 | } 221 | } 222 | 223 | return originalPtrs; 224 | } 225 | }; 226 | 227 | #endif //__IATHOOK_H 228 | -------------------------------------------------------------------------------- /source/launcher/d3d9-wrapper-launcher.c: -------------------------------------------------------------------------------- 1 | // d3d9-wrapper-launcher.c 2 | // 3 | 4 | /* 5 | * Launcher for d3d9-wrapper 6 | * 7 | * Loads d3d9.dll to application process on launch 8 | * 9 | * Description: 10 | * Only required for applications which load d3d9.dll dynamically instead of importing it while also 11 | * loading it too late for the wrapper to hook the functions required for "ignore focus loss" option 12 | * 13 | * If the application works fine without the launcher, you don't need this 14 | * 15 | * Processor architecture must match, that means using 16 | * x64 launcher with x64 wrapper on x64 apps (64-bit) 17 | * x86 launcher with x86 wrapper on x86 apps (32-bit) 18 | * 19 | * Additional notes: 20 | * It is relatively trivial to modify this so that x64 launcher can launch both x64/x86 apps 21 | * and possible but somewhat complicated for x86 launcher (running under WOW64) to also launch both x64/x86 apps 22 | * but cba to do that for now so two launchers is what you get 23 | * 24 | */ 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #define MAX_CMDLINE_LEN 4096 // max command line length 32 | 33 | #ifdef _WIN64 34 | #define TITLE_STR "d3d9-wrapper-launcher x64" 35 | #define BIN_ARCH IMAGE_FILE_MACHINE_AMD64 36 | #else 37 | #define TITLE_STR "d3d9-wrapper-launcher x86" 38 | #define BIN_ARCH IMAGE_FILE_MACHINE_I386 39 | #endif 40 | 41 | #define ARCHSTR(a) ((a==IMAGE_FILE_MACHINE_I386)?"x86":((a==IMAGE_FILE_MACHINE_IA64)?"ia64":((a==IMAGE_FILE_MACHINE_AMD64)?"x64":"unknown"))) 42 | 43 | BOOL FileExistsA(const char* fileName) 44 | { 45 | DWORD fileAttr; 46 | fileAttr = GetFileAttributesA(fileName); 47 | if (INVALID_FILE_ATTRIBUTES == fileAttr) // 0xFFFFFFFF (-1) 48 | { 49 | switch (GetLastError()) 50 | { 51 | case ERROR_FILE_NOT_FOUND: 52 | case ERROR_PATH_NOT_FOUND: 53 | case ERROR_INVALID_NAME: 54 | case ERROR_INVALID_DRIVE: 55 | case ERROR_NOT_READY: 56 | case ERROR_INVALID_PARAMETER: 57 | case ERROR_BAD_PATHNAME: 58 | case ERROR_BAD_NETPATH: 59 | return FALSE; 60 | default: 61 | break; 62 | } 63 | } 64 | return TRUE; 65 | } 66 | 67 | char* trim(char* s) 68 | { 69 | unsigned int i,x; 70 | i = (unsigned int)strlen(s)-1; 71 | while (i > 0 && s[i] != 0 && (s[i] == ' ' || s[i] == '\t' || s[i] == '\r' || s[i] == '\n')) { 72 | i--; 73 | } 74 | if (i == 0) { 75 | s[0] = 0; 76 | return s; 77 | } 78 | s[i+1] = 0; 79 | i = 0; 80 | x = 0; 81 | while (s[x] != 0 && (s[x] == ' ' || s[x] == '\t' || s[x] == '\r' || s[x] == '\n')) { 82 | x++; 83 | } 84 | if (x == 0) { 85 | return s; 86 | } 87 | while (s[x] != 0) { 88 | s[i] = s[x]; 89 | i++; 90 | x++; 91 | } 92 | s[i] = 0; 93 | return s; 94 | } 95 | 96 | char* strip_quotes(char* s) 97 | { 98 | int i,x; 99 | i = 0; 100 | x = 0; 101 | while (s[x] != 0) { 102 | while (s[x] != 0 && s[x] == '\"') { 103 | x++; 104 | } 105 | s[i] = s[x]; 106 | i++; 107 | x++; 108 | } 109 | s[i] = 0; 110 | return s; 111 | } 112 | 113 | void print_w32error(char* cmd, char* arg, DWORD dwErr) 114 | { 115 | char* err_str = NULL; 116 | unsigned int len; 117 | DWORD_PTR pArgs[] = { (DWORD_PTR)"arg1", (DWORD_PTR)"arg2", (DWORD_PTR)"arg3", (DWORD_PTR)"arg4", (DWORD_PTR)"arg5", (DWORD_PTR)"arg6" }; 118 | if (arg) { 119 | pArgs[0] = (DWORD_PTR)arg; 120 | } 121 | if (FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY, NULL, dwErr, 0, (LPSTR)&err_str, 0, (va_list*)pArgs)) { 122 | len = (unsigned int)strlen(err_str); 123 | if (len > 1) { 124 | err_str[len-2] = 0; 125 | fprintf(stderr, TITLE_STR "\n%s() failed; error = (0x%X) \'%s\'\n", cmd, dwErr, err_str); 126 | } 127 | LocalFree(err_str); 128 | if (len > 1) { 129 | return; 130 | } 131 | } 132 | fprintf(stderr, TITLE_STR "\n%s() failed; error code = 0x%08X%s%s%s\n", cmd, dwErr, arg?"; arg = \'":"", arg?arg:"",arg?"\'":""); 133 | } 134 | 135 | int pause_on_exit(int ec) 136 | { 137 | if(_isatty(_fileno(stdin))) { 138 | puts("\nPress any key to exit ..."); 139 | _getch(); 140 | } 141 | return ec; 142 | } 143 | 144 | WORD GetFileArch(char* filePath) 145 | { 146 | HANDLE hFile = NULL; 147 | HANDLE hMapping = NULL; 148 | LPVOID img_addr_header; 149 | PIMAGE_DOS_HEADER img_dos_headers; 150 | PIMAGE_NT_HEADERS img_nt_headers; 151 | 152 | hFile = CreateFile(filePath, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); 153 | if (!hFile || hFile == (HANDLE)-1) { 154 | print_w32error("CreateFile", filePath, GetLastError()); 155 | return 0; 156 | } 157 | hMapping = CreateFileMapping(hFile, NULL, PAGE_READONLY | SEC_IMAGE, 0, 0, 0); 158 | if (!hMapping || hMapping == (HANDLE)-1) { 159 | print_w32error("CreateFileMapping", filePath, GetLastError()); 160 | CloseHandle(hFile); 161 | return 0; 162 | } 163 | img_addr_header = MapViewOfFile(hMapping, FILE_MAP_READ, 0, 0, 0); 164 | if (!img_addr_header) { 165 | print_w32error("MapViewOfFile", filePath, GetLastError()); 166 | CloseHandle(hMapping); 167 | CloseHandle(hFile); 168 | return 0; 169 | } 170 | img_dos_headers = (PIMAGE_DOS_HEADER)img_addr_header; 171 | if (img_dos_headers->e_magic != IMAGE_DOS_SIGNATURE) { 172 | fprintf(stderr, TITLE_STR "\nFile \'%s\' is not a valid Win32 application\n", filePath); 173 | CloseHandle(hMapping); 174 | CloseHandle(hFile); 175 | return 0; 176 | } 177 | img_nt_headers = (PIMAGE_NT_HEADERS)((BYTE*)img_dos_headers + img_dos_headers->e_lfanew); 178 | if (img_nt_headers->Signature != IMAGE_NT_SIGNATURE) { 179 | fprintf(stderr, TITLE_STR "\nFile \'%s\' is not a valid Win32 application\n", filePath); 180 | CloseHandle(hMapping); 181 | CloseHandle(hFile); 182 | return 0; 183 | } 184 | CloseHandle(hMapping); 185 | CloseHandle(hFile); 186 | return img_nt_headers->FileHeader.Machine; 187 | } 188 | 189 | int main(int argc, char **argv) { 190 | int i; 191 | int len; 192 | int c; 193 | void *page; 194 | STARTUPINFO si = {0}; 195 | PROCESS_INFORMATION pi = {0}; 196 | HANDLE hThread; 197 | WORD wArchApp = 0; 198 | WORD wArchDLL = 0; 199 | char dll_path[MAX_PATH+1]; 200 | char ini_path[512]; 201 | char exe_path[512]; 202 | char cmdline[MAX_CMDLINE_LEN]; 203 | 204 | if (!GetModuleFileNameA(NULL, dll_path, MAX_PATH)) { 205 | print_w32error("GetModuleFileNameA", NULL, GetLastError()); 206 | return pause_on_exit(1); 207 | } 208 | i = strrchr(dll_path, '\\')-dll_path+1; 209 | len = i+9; 210 | if (len > MAX_PATH) { 211 | fprintf(stderr, TITLE_STR "\npath length (%d) exceeds MAX_PATH (%d).\n", len, MAX_PATH); 212 | return pause_on_exit(1); 213 | } 214 | 215 | strncpy(ini_path, dll_path, i); 216 | strcpy(ini_path+i, "d3d9.ini"); 217 | strcpy(dll_path+i, "d3d9.dll"); 218 | 219 | if (!FileExistsA(dll_path)) { 220 | fprintf(stderr, TITLE_STR "\nd3d9-wrapper not found, path \'%s\' does not exist\n", dll_path); 221 | return pause_on_exit(1); 222 | } 223 | 224 | exe_path[0] = 0; 225 | if (argc < 2) { 226 | GetPrivateProfileString("LAUNCHER", "AppExe", NULL, exe_path, sizeof(exe_path)-1, ini_path); 227 | if (exe_path[0] == 0) { 228 | fprintf(stderr, TITLE_STR "\nUsage: d3d9-wrapper-launcher EXE [ARGS]\n"); 229 | return pause_on_exit(1); 230 | } 231 | } 232 | else { 233 | strncpy(exe_path, argv[1], sizeof(exe_path)-2); 234 | } 235 | 236 | exe_path[sizeof(exe_path)-1] = 0; 237 | trim(exe_path); 238 | strip_quotes(exe_path); 239 | 240 | if (!FileExistsA(exe_path)) { 241 | fprintf(stderr, TITLE_STR "\nAppExe not found, path \'%s\' does not exist\n", exe_path); 242 | return pause_on_exit(1); 243 | } 244 | 245 | wArchDLL = GetFileArch(dll_path); 246 | if (!wArchDLL) { 247 | return pause_on_exit(1); 248 | } 249 | 250 | wArchApp = GetFileArch(exe_path); 251 | if (!wArchApp) { 252 | return pause_on_exit(1); 253 | } 254 | 255 | if (wArchDLL != BIN_ARCH || wArchApp != BIN_ARCH) { 256 | fprintf(stderr, TITLE_STR "\nProcessor architecture mismatch !\n" 257 | "Launcher = \"%s\"\n" 258 | "WrapperDLL = \"%s\" (\'%s\')\n" 259 | "AppExe = \"%s\" (\'%s\')\n", 260 | ARCHSTR(BIN_ARCH), ARCHSTR(wArchDLL), dll_path, ARCHSTR(wArchApp), exe_path); 261 | return pause_on_exit(1); 262 | } 263 | 264 | cmdline[sizeof(cmdline)-1] = 0; 265 | cmdline[0] = '"'; 266 | strcpy(cmdline+1, exe_path); 267 | i = (int)strlen(cmdline); 268 | cmdline[i++] = '"'; 269 | cmdline[i] = 0; 270 | 271 | if (argc < 2) { 272 | cmdline[i++] = ' '; 273 | cmdline[i] = 0; 274 | GetPrivateProfileString("LAUNCHER", "AppArgs", NULL, cmdline+i, sizeof(cmdline)-i-1, ini_path); 275 | } 276 | else if (argc > 2) { 277 | for (c = 2; c < argc; c++) 278 | { 279 | if (sizeof(cmdline)-i < 5) { 280 | fprintf(stderr, TITLE_STR "\ncommand line length exceeds MAX_CMDLINE_LEN (%d).\n", MAX_CMDLINE_LEN); 281 | return pause_on_exit(1); 282 | } 283 | cmdline[i++] = ' '; 284 | cmdline[i] = 0; 285 | strncpy(cmdline+i, argv[c], sizeof(cmdline)-i-2); 286 | i = (int)strlen(cmdline); 287 | } 288 | } 289 | 290 | si.cb = sizeof(STARTUPINFO); 291 | if (!CreateProcess(NULL, cmdline, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &si, &pi)) { 292 | print_w32error("CreateProcess", cmdline, GetLastError()); 293 | return pause_on_exit(1); 294 | } 295 | 296 | page = VirtualAllocEx(pi.hProcess, NULL, MAX_PATH, MEM_COMMIT|MEM_RESERVE, PAGE_READWRITE); 297 | if (!page) { 298 | print_w32error("VirtualAllocEx", NULL, GetLastError()); 299 | CloseHandle(pi.hThread); 300 | CloseHandle(pi.hProcess); 301 | return pause_on_exit(1); 302 | } 303 | 304 | if (!WriteProcessMemory(pi.hProcess, page, dll_path, len, NULL)) { 305 | print_w32error("WriteProcessMemory", NULL, GetLastError()); 306 | VirtualFreeEx(pi.hProcess, page, 0, MEM_RELEASE); 307 | CloseHandle(pi.hThread); 308 | CloseHandle(pi.hProcess); 309 | return pause_on_exit(1); 310 | } 311 | 312 | hThread = CreateRemoteThread(pi.hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)LoadLibraryA, page, 0, NULL); 313 | if (!hThread) { 314 | print_w32error("CreateRemoteThread", NULL, GetLastError()); 315 | VirtualFreeEx(pi.hProcess, page, 0, MEM_RELEASE); 316 | CloseHandle(pi.hThread); 317 | CloseHandle(pi.hProcess); 318 | return pause_on_exit(1); 319 | } 320 | 321 | if (WaitForSingleObject(hThread, INFINITE) == WAIT_FAILED) { 322 | print_w32error("WaitForSingleObject", NULL, GetLastError()); 323 | CloseHandle(hThread); 324 | VirtualFreeEx(pi.hProcess, page, 0, MEM_RELEASE); 325 | CloseHandle(pi.hThread); 326 | CloseHandle(pi.hProcess); 327 | return pause_on_exit(1); 328 | } 329 | 330 | CloseHandle(hThread); 331 | 332 | if (ResumeThread(pi.hThread) == -1) { 333 | print_w32error("ResumeThread", NULL, GetLastError()); 334 | VirtualFreeEx(pi.hProcess, page, 0, MEM_RELEASE); 335 | CloseHandle(pi.hThread); 336 | CloseHandle(pi.hProcess); 337 | return pause_on_exit(1); 338 | } 339 | 340 | VirtualFreeEx(pi.hProcess, page, 0, MEM_RELEASE); 341 | CloseHandle(pi.hThread); 342 | CloseHandle(pi.hProcess); 343 | return 0; 344 | } 345 | -------------------------------------------------------------------------------- /source/dxsdk/d3dx9xof.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (C) Microsoft Corporation. All Rights Reserved. 4 | // 5 | // File: d3dx9xof.h 6 | // Content: D3DX .X File types and functions 7 | // 8 | /////////////////////////////////////////////////////////////////////////// 9 | 10 | #include "d3dx9.h" 11 | 12 | #if !defined( __D3DX9XOF_H__ ) 13 | #define __D3DX9XOF_H__ 14 | 15 | #if defined( __cplusplus ) 16 | extern "C" { 17 | #endif // defined( __cplusplus ) 18 | 19 | //---------------------------------------------------------------------------- 20 | // D3DXF_FILEFORMAT 21 | // This flag is used to specify what file type to use when saving to disk. 22 | // _BINARY, and _TEXT are mutually exclusive, while 23 | // _COMPRESSED is an optional setting that works with all file types. 24 | //---------------------------------------------------------------------------- 25 | typedef DWORD D3DXF_FILEFORMAT; 26 | 27 | #define D3DXF_FILEFORMAT_BINARY 0 28 | #define D3DXF_FILEFORMAT_TEXT 1 29 | #define D3DXF_FILEFORMAT_COMPRESSED 2 30 | 31 | //---------------------------------------------------------------------------- 32 | // D3DXF_FILESAVEOPTIONS 33 | // This flag is used to specify where to save the file to. Each flag is 34 | // mutually exclusive, indicates the data location of the file, and also 35 | // chooses which additional data will specify the location. 36 | // _TOFILE is paired with a filename (LPCSTR) 37 | // _TOWFILE is paired with a filename (LPWSTR) 38 | //---------------------------------------------------------------------------- 39 | typedef DWORD D3DXF_FILESAVEOPTIONS; 40 | 41 | #define D3DXF_FILESAVE_TOFILE 0x00L 42 | #define D3DXF_FILESAVE_TOWFILE 0x01L 43 | 44 | //---------------------------------------------------------------------------- 45 | // D3DXF_FILELOADOPTIONS 46 | // This flag is used to specify where to load the file from. Each flag is 47 | // mutually exclusive, indicates the data location of the file, and also 48 | // chooses which additional data will specify the location. 49 | // _FROMFILE is paired with a filename (LPCSTR) 50 | // _FROMWFILE is paired with a filename (LPWSTR) 51 | // _FROMRESOURCE is paired with a (D3DXF_FILELOADRESOUCE*) description. 52 | // _FROMMEMORY is paired with a (D3DXF_FILELOADMEMORY*) description. 53 | //---------------------------------------------------------------------------- 54 | typedef DWORD D3DXF_FILELOADOPTIONS; 55 | 56 | #define D3DXF_FILELOAD_FROMFILE 0x00L 57 | #define D3DXF_FILELOAD_FROMWFILE 0x01L 58 | #define D3DXF_FILELOAD_FROMRESOURCE 0x02L 59 | #define D3DXF_FILELOAD_FROMMEMORY 0x03L 60 | 61 | //---------------------------------------------------------------------------- 62 | // D3DXF_FILELOADRESOURCE: 63 | //---------------------------------------------------------------------------- 64 | 65 | typedef struct _D3DXF_FILELOADRESOURCE 66 | { 67 | HMODULE hModule; // Desc 68 | LPCSTR lpName; // Desc 69 | LPCSTR lpType; // Desc 70 | } D3DXF_FILELOADRESOURCE; 71 | 72 | //---------------------------------------------------------------------------- 73 | // D3DXF_FILELOADMEMORY: 74 | //---------------------------------------------------------------------------- 75 | 76 | typedef struct _D3DXF_FILELOADMEMORY 77 | { 78 | LPCVOID lpMemory; // Desc 79 | SIZE_T dSize; // Desc 80 | } D3DXF_FILELOADMEMORY; 81 | 82 | #if defined( _WIN32 ) && !defined( _NO_COM ) 83 | 84 | // {cef08cf9-7b4f-4429-9624-2a690a933201} 85 | DEFINE_GUID( IID_ID3DXFile, 86 | 0xcef08cf9, 0x7b4f, 0x4429, 0x96, 0x24, 0x2a, 0x69, 0x0a, 0x93, 0x32, 0x01 ); 87 | 88 | // {cef08cfa-7b4f-4429-9624-2a690a933201} 89 | DEFINE_GUID( IID_ID3DXFileSaveObject, 90 | 0xcef08cfa, 0x7b4f, 0x4429, 0x96, 0x24, 0x2a, 0x69, 0x0a, 0x93, 0x32, 0x01 ); 91 | 92 | // {cef08cfb-7b4f-4429-9624-2a690a933201} 93 | DEFINE_GUID( IID_ID3DXFileSaveData, 94 | 0xcef08cfb, 0x7b4f, 0x4429, 0x96, 0x24, 0x2a, 0x69, 0x0a, 0x93, 0x32, 0x01 ); 95 | 96 | // {cef08cfc-7b4f-4429-9624-2a690a933201} 97 | DEFINE_GUID( IID_ID3DXFileEnumObject, 98 | 0xcef08cfc, 0x7b4f, 0x4429, 0x96, 0x24, 0x2a, 0x69, 0x0a, 0x93, 0x32, 0x01 ); 99 | 100 | // {cef08cfd-7b4f-4429-9624-2a690a933201} 101 | DEFINE_GUID( IID_ID3DXFileData, 102 | 0xcef08cfd, 0x7b4f, 0x4429, 0x96, 0x24, 0x2a, 0x69, 0x0a, 0x93, 0x32, 0x01 ); 103 | 104 | #endif // defined( _WIN32 ) && !defined( _NO_COM ) 105 | 106 | #if defined( __cplusplus ) 107 | #if !defined( DECLSPEC_UUID ) 108 | #if _MSC_VER >= 1100 109 | #define DECLSPEC_UUID( x ) __declspec( uuid( x ) ) 110 | #else // !( _MSC_VER >= 1100 ) 111 | #define DECLSPEC_UUID( x ) 112 | #endif // !( _MSC_VER >= 1100 ) 113 | #endif // !defined( DECLSPEC_UUID ) 114 | 115 | interface DECLSPEC_UUID( "cef08cf9-7b4f-4429-9624-2a690a933201" ) 116 | ID3DXFile; 117 | interface DECLSPEC_UUID( "cef08cfa-7b4f-4429-9624-2a690a933201" ) 118 | ID3DXFileSaveObject; 119 | interface DECLSPEC_UUID( "cef08cfb-7b4f-4429-9624-2a690a933201" ) 120 | ID3DXFileSaveData; 121 | interface DECLSPEC_UUID( "cef08cfc-7b4f-4429-9624-2a690a933201" ) 122 | ID3DXFileEnumObject; 123 | interface DECLSPEC_UUID( "cef08cfd-7b4f-4429-9624-2a690a933201" ) 124 | ID3DXFileData; 125 | 126 | #if defined( _COM_SMARTPTR_TYPEDEF ) 127 | _COM_SMARTPTR_TYPEDEF( ID3DXFile, 128 | __uuidof( ID3DXFile ) ); 129 | _COM_SMARTPTR_TYPEDEF( ID3DXFileSaveObject, 130 | __uuidof( ID3DXFileSaveObject ) ); 131 | _COM_SMARTPTR_TYPEDEF( ID3DXFileSaveData, 132 | __uuidof( ID3DXFileSaveData ) ); 133 | _COM_SMARTPTR_TYPEDEF( ID3DXFileEnumObject, 134 | __uuidof( ID3DXFileEnumObject ) ); 135 | _COM_SMARTPTR_TYPEDEF( ID3DXFileData, 136 | __uuidof( ID3DXFileData ) ); 137 | #endif // defined( _COM_SMARTPTR_TYPEDEF ) 138 | #endif // defined( __cplusplus ) 139 | 140 | typedef interface ID3DXFile ID3DXFile; 141 | typedef interface ID3DXFileSaveObject ID3DXFileSaveObject; 142 | typedef interface ID3DXFileSaveData ID3DXFileSaveData; 143 | typedef interface ID3DXFileEnumObject ID3DXFileEnumObject; 144 | typedef interface ID3DXFileData ID3DXFileData; 145 | 146 | ////////////////////////////////////////////////////////////////////////////// 147 | // ID3DXFile ///////////////////////////////////////////////////////////////// 148 | ////////////////////////////////////////////////////////////////////////////// 149 | 150 | #undef INTERFACE 151 | #define INTERFACE ID3DXFile 152 | 153 | DECLARE_INTERFACE_( ID3DXFile, IUnknown ) 154 | { 155 | STDMETHOD( QueryInterface )( THIS_ REFIID, LPVOID* ) PURE; 156 | STDMETHOD_( ULONG, AddRef )( THIS ) PURE; 157 | STDMETHOD_( ULONG, Release )( THIS ) PURE; 158 | 159 | STDMETHOD( CreateEnumObject )( THIS_ LPCVOID, D3DXF_FILELOADOPTIONS, 160 | ID3DXFileEnumObject** ) PURE; 161 | STDMETHOD( CreateSaveObject )( THIS_ LPCVOID, D3DXF_FILESAVEOPTIONS, 162 | D3DXF_FILEFORMAT, ID3DXFileSaveObject** ) PURE; 163 | STDMETHOD( RegisterTemplates )( THIS_ LPCVOID, SIZE_T ) PURE; 164 | STDMETHOD( RegisterEnumTemplates )( THIS_ ID3DXFileEnumObject* ) PURE; 165 | }; 166 | 167 | ////////////////////////////////////////////////////////////////////////////// 168 | // ID3DXFileSaveObject /////////////////////////////////////////////////////// 169 | ////////////////////////////////////////////////////////////////////////////// 170 | 171 | #undef INTERFACE 172 | #define INTERFACE ID3DXFileSaveObject 173 | 174 | DECLARE_INTERFACE_( ID3DXFileSaveObject, IUnknown ) 175 | { 176 | STDMETHOD( QueryInterface )( THIS_ REFIID, LPVOID* ) PURE; 177 | STDMETHOD_( ULONG, AddRef )( THIS ) PURE; 178 | STDMETHOD_( ULONG, Release )( THIS ) PURE; 179 | 180 | STDMETHOD( GetFile )( THIS_ ID3DXFile** ) PURE; 181 | STDMETHOD( AddDataObject )( THIS_ REFGUID, LPCSTR, CONST GUID*, 182 | SIZE_T, LPCVOID, ID3DXFileSaveData** ) PURE; 183 | STDMETHOD( Save )( THIS ) PURE; 184 | }; 185 | 186 | ////////////////////////////////////////////////////////////////////////////// 187 | // ID3DXFileSaveData ///////////////////////////////////////////////////////// 188 | ////////////////////////////////////////////////////////////////////////////// 189 | 190 | #undef INTERFACE 191 | #define INTERFACE ID3DXFileSaveData 192 | 193 | DECLARE_INTERFACE_( ID3DXFileSaveData, IUnknown ) 194 | { 195 | STDMETHOD( QueryInterface )( THIS_ REFIID, LPVOID* ) PURE; 196 | STDMETHOD_( ULONG, AddRef )( THIS ) PURE; 197 | STDMETHOD_( ULONG, Release )( THIS ) PURE; 198 | 199 | STDMETHOD( GetSave )( THIS_ ID3DXFileSaveObject** ) PURE; 200 | STDMETHOD( GetName )( THIS_ LPSTR, SIZE_T* ) PURE; 201 | STDMETHOD( GetId )( THIS_ LPGUID ) PURE; 202 | STDMETHOD( GetType )( THIS_ GUID* ) PURE; 203 | STDMETHOD( AddDataObject )( THIS_ REFGUID, LPCSTR, CONST GUID*, 204 | SIZE_T, LPCVOID, ID3DXFileSaveData** ) PURE; 205 | STDMETHOD( AddDataReference )( THIS_ LPCSTR, CONST GUID* ) PURE; 206 | }; 207 | 208 | ////////////////////////////////////////////////////////////////////////////// 209 | // ID3DXFileEnumObject /////////////////////////////////////////////////////// 210 | ////////////////////////////////////////////////////////////////////////////// 211 | 212 | #undef INTERFACE 213 | #define INTERFACE ID3DXFileEnumObject 214 | 215 | DECLARE_INTERFACE_( ID3DXFileEnumObject, IUnknown ) 216 | { 217 | STDMETHOD( QueryInterface )( THIS_ REFIID, LPVOID* ) PURE; 218 | STDMETHOD_( ULONG, AddRef )( THIS ) PURE; 219 | STDMETHOD_( ULONG, Release )( THIS ) PURE; 220 | 221 | STDMETHOD( GetFile )( THIS_ ID3DXFile** ) PURE; 222 | STDMETHOD( GetChildren )( THIS_ SIZE_T* ) PURE; 223 | STDMETHOD( GetChild )( THIS_ SIZE_T, ID3DXFileData** ) PURE; 224 | STDMETHOD( GetDataObjectById )( THIS_ REFGUID, ID3DXFileData** ) PURE; 225 | STDMETHOD( GetDataObjectByName )( THIS_ LPCSTR, ID3DXFileData** ) PURE; 226 | }; 227 | 228 | ////////////////////////////////////////////////////////////////////////////// 229 | // ID3DXFileData ///////////////////////////////////////////////////////////// 230 | ////////////////////////////////////////////////////////////////////////////// 231 | 232 | #undef INTERFACE 233 | #define INTERFACE ID3DXFileData 234 | 235 | DECLARE_INTERFACE_( ID3DXFileData, IUnknown ) 236 | { 237 | STDMETHOD( QueryInterface )( THIS_ REFIID, LPVOID* ) PURE; 238 | STDMETHOD_( ULONG, AddRef )( THIS ) PURE; 239 | STDMETHOD_( ULONG, Release )( THIS ) PURE; 240 | 241 | STDMETHOD( GetEnum )( THIS_ ID3DXFileEnumObject** ) PURE; 242 | STDMETHOD( GetName )( THIS_ LPSTR, SIZE_T* ) PURE; 243 | STDMETHOD( GetId )( THIS_ LPGUID ) PURE; 244 | STDMETHOD( Lock )( THIS_ SIZE_T*, LPCVOID* ) PURE; 245 | STDMETHOD( Unlock )( THIS ) PURE; 246 | STDMETHOD( GetType )( THIS_ GUID* ) PURE; 247 | STDMETHOD_( BOOL, IsReference )( THIS ) PURE; 248 | STDMETHOD( GetChildren )( THIS_ SIZE_T* ) PURE; 249 | STDMETHOD( GetChild )( THIS_ SIZE_T, ID3DXFileData** ) PURE; 250 | }; 251 | 252 | STDAPI D3DXFileCreate( ID3DXFile** lplpDirectXFile ); 253 | 254 | /* 255 | * DirectX File errors. 256 | */ 257 | 258 | #define _FACD3DXF 0x876 259 | 260 | #define D3DXFERR_BADOBJECT MAKE_HRESULT( 1, _FACD3DXF, 900 ) 261 | #define D3DXFERR_BADVALUE MAKE_HRESULT( 1, _FACD3DXF, 901 ) 262 | #define D3DXFERR_BADTYPE MAKE_HRESULT( 1, _FACD3DXF, 902 ) 263 | #define D3DXFERR_NOTFOUND MAKE_HRESULT( 1, _FACD3DXF, 903 ) 264 | #define D3DXFERR_NOTDONEYET MAKE_HRESULT( 1, _FACD3DXF, 904 ) 265 | #define D3DXFERR_FILENOTFOUND MAKE_HRESULT( 1, _FACD3DXF, 905 ) 266 | #define D3DXFERR_RESOURCENOTFOUND MAKE_HRESULT( 1, _FACD3DXF, 906 ) 267 | #define D3DXFERR_BADRESOURCE MAKE_HRESULT( 1, _FACD3DXF, 907 ) 268 | #define D3DXFERR_BADFILETYPE MAKE_HRESULT( 1, _FACD3DXF, 908 ) 269 | #define D3DXFERR_BADFILEVERSION MAKE_HRESULT( 1, _FACD3DXF, 909 ) 270 | #define D3DXFERR_BADFILEFLOATSIZE MAKE_HRESULT( 1, _FACD3DXF, 910 ) 271 | #define D3DXFERR_BADFILE MAKE_HRESULT( 1, _FACD3DXF, 911 ) 272 | #define D3DXFERR_PARSEERROR MAKE_HRESULT( 1, _FACD3DXF, 912 ) 273 | #define D3DXFERR_BADARRAYSIZE MAKE_HRESULT( 1, _FACD3DXF, 913 ) 274 | #define D3DXFERR_BADDATAREFERENCE MAKE_HRESULT( 1, _FACD3DXF, 914 ) 275 | #define D3DXFERR_NOMOREOBJECTS MAKE_HRESULT( 1, _FACD3DXF, 915 ) 276 | #define D3DXFERR_NOMOREDATA MAKE_HRESULT( 1, _FACD3DXF, 916 ) 277 | #define D3DXFERR_BADCACHEFILE MAKE_HRESULT( 1, _FACD3DXF, 917 ) 278 | 279 | /* 280 | * DirectX File object types. 281 | */ 282 | 283 | #ifndef WIN_TYPES 284 | #define WIN_TYPES(itype, ptype) typedef interface itype *LP##ptype, **LPLP##ptype 285 | #endif 286 | 287 | WIN_TYPES(ID3DXFile, D3DXFILE); 288 | WIN_TYPES(ID3DXFileEnumObject, D3DXFILEENUMOBJECT); 289 | WIN_TYPES(ID3DXFileSaveObject, D3DXFILESAVEOBJECT); 290 | WIN_TYPES(ID3DXFileData, D3DXFILEDATA); 291 | WIN_TYPES(ID3DXFileSaveData, D3DXFILESAVEDATA); 292 | 293 | #if defined( __cplusplus ) 294 | } // extern "C" 295 | #endif // defined( __cplusplus ) 296 | 297 | #endif // !defined( __D3DX9XOF_H__ ) 298 | 299 | 300 | -------------------------------------------------------------------------------- /source/IDirect3DDevice9Ex.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class m_IDirect3DDevice9Ex : public IDirect3DDevice9Ex 4 | { 5 | private: 6 | LPDIRECT3DDEVICE9EX ProxyInterface; 7 | m_IDirect3D9Ex* m_pD3DEx; 8 | REFIID WrapperID; 9 | 10 | public: 11 | m_IDirect3DDevice9Ex(LPDIRECT3DDEVICE9EX pDevice, m_IDirect3D9Ex* pD3D, REFIID DeviceID = IID_IUnknown) : ProxyInterface(pDevice), m_pD3DEx(pD3D), WrapperID(DeviceID) 12 | { 13 | InitDirect3DDevice(); 14 | } 15 | void InitDirect3DDevice() 16 | { 17 | ProxyAddressLookupTable = new AddressLookupTable(this); 18 | } 19 | ~m_IDirect3DDevice9Ex() 20 | { 21 | delete ProxyAddressLookupTable; 22 | } 23 | 24 | LPDIRECT3DDEVICE9EX GetProxyInterface() { return ProxyInterface; } 25 | AddressLookupTable *ProxyAddressLookupTable; 26 | 27 | /*** IUnknown methods ***/ 28 | STDMETHOD(QueryInterface)(THIS_ REFIID riid, void** ppvObj); 29 | STDMETHOD_(ULONG, AddRef)(THIS); 30 | STDMETHOD_(ULONG, Release)(THIS); 31 | 32 | /*** IDirect3DDevice9 methods ***/ 33 | STDMETHOD(TestCooperativeLevel)(THIS); 34 | STDMETHOD_(UINT, GetAvailableTextureMem)(THIS); 35 | STDMETHOD(EvictManagedResources)(THIS); 36 | STDMETHOD(GetDirect3D)(THIS_ IDirect3D9** ppD3D9); 37 | STDMETHOD(GetDeviceCaps)(THIS_ D3DCAPS9* pCaps); 38 | STDMETHOD(GetDisplayMode)(THIS_ UINT iSwapChain, D3DDISPLAYMODE* pMode); 39 | STDMETHOD(GetCreationParameters)(THIS_ D3DDEVICE_CREATION_PARAMETERS *pParameters); 40 | STDMETHOD(SetCursorProperties)(THIS_ UINT XHotSpot, UINT YHotSpot, IDirect3DSurface9* pCursorBitmap); 41 | STDMETHOD_(void, SetCursorPosition)(THIS_ int X, int Y, DWORD Flags); 42 | STDMETHOD_(BOOL, ShowCursor)(THIS_ BOOL bShow); 43 | STDMETHOD(CreateAdditionalSwapChain)(THIS_ D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DSwapChain9** pSwapChain); 44 | STDMETHOD(GetSwapChain)(THIS_ UINT iSwapChain, IDirect3DSwapChain9** pSwapChain); 45 | STDMETHOD_(UINT, GetNumberOfSwapChains)(THIS); 46 | STDMETHOD(Reset)(THIS_ D3DPRESENT_PARAMETERS* pPresentationParameters); 47 | STDMETHOD(Present)(THIS_ CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion); 48 | STDMETHOD(GetBackBuffer)(THIS_ UINT iSwapChain, UINT iBackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface9** ppBackBuffer); 49 | STDMETHOD(GetRasterStatus)(THIS_ UINT iSwapChain, D3DRASTER_STATUS* pRasterStatus); 50 | STDMETHOD(SetDialogBoxMode)(THIS_ BOOL bEnableDialogs); 51 | STDMETHOD_(void, SetGammaRamp)(THIS_ UINT iSwapChain, DWORD Flags, CONST D3DGAMMARAMP* pRamp); 52 | STDMETHOD_(void, GetGammaRamp)(THIS_ UINT iSwapChain, D3DGAMMARAMP* pRamp); 53 | STDMETHOD(CreateTexture)(THIS_ UINT Width, UINT Height, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DTexture9** ppTexture, HANDLE* pSharedHandle); 54 | STDMETHOD(CreateVolumeTexture)(THIS_ UINT Width, UINT Height, UINT Depth, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DVolumeTexture9** ppVolumeTexture, HANDLE* pSharedHandle); 55 | STDMETHOD(CreateCubeTexture)(THIS_ UINT EdgeLength, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DCubeTexture9** ppCubeTexture, HANDLE* pSharedHandle); 56 | STDMETHOD(CreateVertexBuffer)(THIS_ UINT Length, DWORD Usage, DWORD FVF, D3DPOOL Pool, IDirect3DVertexBuffer9** ppVertexBuffer, HANDLE* pSharedHandle); 57 | STDMETHOD(CreateIndexBuffer)(THIS_ UINT Length, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DIndexBuffer9** ppIndexBuffer, HANDLE* pSharedHandle); 58 | STDMETHOD(CreateRenderTarget)(THIS_ UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Lockable, IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle); 59 | STDMETHOD(CreateDepthStencilSurface)(THIS_ UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Discard, IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle); 60 | STDMETHOD(UpdateSurface)(THIS_ IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect, IDirect3DSurface9* pDestinationSurface, CONST POINT* pDestPoint); 61 | STDMETHOD(UpdateTexture)(THIS_ IDirect3DBaseTexture9* pSourceTexture, IDirect3DBaseTexture9* pDestinationTexture); 62 | STDMETHOD(GetRenderTargetData)(THIS_ IDirect3DSurface9* pRenderTarget, IDirect3DSurface9* pDestSurface); 63 | STDMETHOD(GetFrontBufferData)(THIS_ UINT iSwapChain, IDirect3DSurface9* pDestSurface); 64 | STDMETHOD(StretchRect)(THIS_ IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect, IDirect3DSurface9* pDestSurface, CONST RECT* pDestRect, D3DTEXTUREFILTERTYPE Filter); 65 | STDMETHOD(ColorFill)(THIS_ IDirect3DSurface9* pSurface, CONST RECT* pRect, D3DCOLOR color); 66 | STDMETHOD(CreateOffscreenPlainSurface)(THIS_ UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle); 67 | STDMETHOD(SetRenderTarget)(THIS_ DWORD RenderTargetIndex, IDirect3DSurface9* pRenderTarget); 68 | STDMETHOD(GetRenderTarget)(THIS_ DWORD RenderTargetIndex, IDirect3DSurface9** ppRenderTarget); 69 | STDMETHOD(SetDepthStencilSurface)(THIS_ IDirect3DSurface9* pNewZStencil); 70 | STDMETHOD(GetDepthStencilSurface)(THIS_ IDirect3DSurface9** ppZStencilSurface); 71 | STDMETHOD(BeginScene)(THIS); 72 | STDMETHOD(EndScene)(THIS); 73 | STDMETHOD(Clear)(THIS_ DWORD Count, CONST D3DRECT* pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil); 74 | STDMETHOD(SetTransform)(THIS_ D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix); 75 | STDMETHOD(GetTransform)(THIS_ D3DTRANSFORMSTATETYPE State, D3DMATRIX* pMatrix); 76 | STDMETHOD(MultiplyTransform)(THIS_ D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX *pMatrix); 77 | STDMETHOD(SetViewport)(THIS_ CONST D3DVIEWPORT9* pViewport); 78 | STDMETHOD(GetViewport)(THIS_ D3DVIEWPORT9* pViewport); 79 | STDMETHOD(SetMaterial)(THIS_ CONST D3DMATERIAL9* pMaterial); 80 | STDMETHOD(GetMaterial)(THIS_ D3DMATERIAL9* pMaterial); 81 | STDMETHOD(SetLight)(THIS_ DWORD Index, CONST D3DLIGHT9* pLight); 82 | STDMETHOD(GetLight)(THIS_ DWORD Index, D3DLIGHT9* pLight); 83 | STDMETHOD(LightEnable)(THIS_ DWORD Index, BOOL Enable); 84 | STDMETHOD(GetLightEnable)(THIS_ DWORD Index, BOOL* pEnable); 85 | STDMETHOD(SetClipPlane)(THIS_ DWORD Index, CONST float* pPlane); 86 | STDMETHOD(GetClipPlane)(THIS_ DWORD Index, float* pPlane); 87 | STDMETHOD(SetRenderState)(THIS_ D3DRENDERSTATETYPE State, DWORD Value); 88 | STDMETHOD(GetRenderState)(THIS_ D3DRENDERSTATETYPE State, DWORD* pValue); 89 | STDMETHOD(CreateStateBlock)(THIS_ D3DSTATEBLOCKTYPE Type, IDirect3DStateBlock9** ppSB); 90 | STDMETHOD(BeginStateBlock)(THIS); 91 | STDMETHOD(EndStateBlock)(THIS_ IDirect3DStateBlock9** ppSB); 92 | STDMETHOD(SetClipStatus)(THIS_ CONST D3DCLIPSTATUS9* pClipStatus); 93 | STDMETHOD(GetClipStatus)(THIS_ D3DCLIPSTATUS9* pClipStatus); 94 | STDMETHOD(GetTexture)(THIS_ DWORD Stage, IDirect3DBaseTexture9** ppTexture); 95 | STDMETHOD(SetTexture)(THIS_ DWORD Stage, IDirect3DBaseTexture9* pTexture); 96 | STDMETHOD(GetTextureStageState)(THIS_ DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD* pValue); 97 | STDMETHOD(SetTextureStageState)(THIS_ DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value); 98 | STDMETHOD(GetSamplerState)(THIS_ DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD* pValue); 99 | STDMETHOD(SetSamplerState)(THIS_ DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value); 100 | STDMETHOD(ValidateDevice)(THIS_ DWORD* pNumPasses); 101 | STDMETHOD(SetPaletteEntries)(THIS_ UINT PaletteNumber, CONST PALETTEENTRY* pEntries); 102 | STDMETHOD(GetPaletteEntries)(THIS_ UINT PaletteNumber, PALETTEENTRY* pEntries); 103 | STDMETHOD(SetCurrentTexturePalette)(THIS_ UINT PaletteNumber); 104 | STDMETHOD(GetCurrentTexturePalette)(THIS_ UINT *PaletteNumber); 105 | STDMETHOD(SetScissorRect)(THIS_ CONST RECT* pRect); 106 | STDMETHOD(GetScissorRect)(THIS_ RECT* pRect); 107 | STDMETHOD(SetSoftwareVertexProcessing)(THIS_ BOOL bSoftware); 108 | STDMETHOD_(BOOL, GetSoftwareVertexProcessing)(THIS); 109 | STDMETHOD(SetNPatchMode)(THIS_ float nSegments); 110 | STDMETHOD_(float, GetNPatchMode)(THIS); 111 | STDMETHOD(DrawPrimitive)(THIS_ D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount); 112 | STDMETHOD(DrawIndexedPrimitive)(THIS_ D3DPRIMITIVETYPE, INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount); 113 | STDMETHOD(DrawPrimitiveUP)(THIS_ D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride); 114 | STDMETHOD(DrawIndexedPrimitiveUP)(THIS_ D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex, UINT NumVertices, UINT PrimitiveCount, CONST void* pIndexData, D3DFORMAT IndexDataFormat, CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride); 115 | STDMETHOD(ProcessVertices)(THIS_ UINT SrcStartIndex, UINT DestIndex, UINT VertexCount, IDirect3DVertexBuffer9* pDestBuffer, IDirect3DVertexDeclaration9* pVertexDecl, DWORD Flags); 116 | STDMETHOD(CreateVertexDeclaration)(THIS_ CONST D3DVERTEXELEMENT9* pVertexElements, IDirect3DVertexDeclaration9** ppDecl); 117 | STDMETHOD(SetVertexDeclaration)(THIS_ IDirect3DVertexDeclaration9* pDecl); 118 | STDMETHOD(GetVertexDeclaration)(THIS_ IDirect3DVertexDeclaration9** ppDecl); 119 | STDMETHOD(SetFVF)(THIS_ DWORD FVF); 120 | STDMETHOD(GetFVF)(THIS_ DWORD* pFVF); 121 | STDMETHOD(CreateVertexShader)(THIS_ CONST DWORD* pFunction, IDirect3DVertexShader9** ppShader); 122 | STDMETHOD(SetVertexShader)(THIS_ IDirect3DVertexShader9* pShader); 123 | STDMETHOD(GetVertexShader)(THIS_ IDirect3DVertexShader9** ppShader); 124 | STDMETHOD(SetVertexShaderConstantF)(THIS_ UINT StartRegister, CONST float* pConstantData, UINT Vector4fCount); 125 | STDMETHOD(GetVertexShaderConstantF)(THIS_ UINT StartRegister, float* pConstantData, UINT Vector4fCount); 126 | STDMETHOD(SetVertexShaderConstantI)(THIS_ UINT StartRegister, CONST int* pConstantData, UINT Vector4iCount); 127 | STDMETHOD(GetVertexShaderConstantI)(THIS_ UINT StartRegister, int* pConstantData, UINT Vector4iCount); 128 | STDMETHOD(SetVertexShaderConstantB)(THIS_ UINT StartRegister, CONST BOOL* pConstantData, UINT BoolCount); 129 | STDMETHOD(GetVertexShaderConstantB)(THIS_ UINT StartRegister, BOOL* pConstantData, UINT BoolCount); 130 | STDMETHOD(SetStreamSource)(THIS_ UINT StreamNumber, IDirect3DVertexBuffer9* pStreamData, UINT OffsetInBytes, UINT Stride); 131 | STDMETHOD(GetStreamSource)(THIS_ UINT StreamNumber, IDirect3DVertexBuffer9** ppStreamData, UINT* pOffsetInBytes, UINT* pStride); 132 | STDMETHOD(SetStreamSourceFreq)(THIS_ UINT StreamNumber, UINT Setting); 133 | STDMETHOD(GetStreamSourceFreq)(THIS_ UINT StreamNumber, UINT* pSetting); 134 | STDMETHOD(SetIndices)(THIS_ IDirect3DIndexBuffer9* pIndexData); 135 | STDMETHOD(GetIndices)(THIS_ IDirect3DIndexBuffer9** ppIndexData); 136 | STDMETHOD(CreatePixelShader)(THIS_ CONST DWORD* pFunction, IDirect3DPixelShader9** ppShader); 137 | STDMETHOD(SetPixelShader)(THIS_ IDirect3DPixelShader9* pShader); 138 | STDMETHOD(GetPixelShader)(THIS_ IDirect3DPixelShader9** ppShader); 139 | STDMETHOD(SetPixelShaderConstantF)(THIS_ UINT StartRegister, CONST float* pConstantData, UINT Vector4fCount); 140 | STDMETHOD(GetPixelShaderConstantF)(THIS_ UINT StartRegister, float* pConstantData, UINT Vector4fCount); 141 | STDMETHOD(SetPixelShaderConstantI)(THIS_ UINT StartRegister, CONST int* pConstantData, UINT Vector4iCount); 142 | STDMETHOD(GetPixelShaderConstantI)(THIS_ UINT StartRegister, int* pConstantData, UINT Vector4iCount); 143 | STDMETHOD(SetPixelShaderConstantB)(THIS_ UINT StartRegister, CONST BOOL* pConstantData, UINT BoolCount); 144 | STDMETHOD(GetPixelShaderConstantB)(THIS_ UINT StartRegister, BOOL* pConstantData, UINT BoolCount); 145 | STDMETHOD(DrawRectPatch)(THIS_ UINT Handle, CONST float* pNumSegs, CONST D3DRECTPATCH_INFO* pRectPatchInfo); 146 | STDMETHOD(DrawTriPatch)(THIS_ UINT Handle, CONST float* pNumSegs, CONST D3DTRIPATCH_INFO* pTriPatchInfo); 147 | STDMETHOD(DeletePatch)(THIS_ UINT Handle); 148 | STDMETHOD(CreateQuery)(THIS_ D3DQUERYTYPE Type, IDirect3DQuery9** ppQuery); 149 | STDMETHOD(SetConvolutionMonoKernel)(THIS_ UINT width, UINT height, float* rows, float* columns); 150 | STDMETHOD(ComposeRects)(THIS_ IDirect3DSurface9* pSrc, IDirect3DSurface9* pDst, IDirect3DVertexBuffer9* pSrcRectDescs, UINT NumRects, IDirect3DVertexBuffer9* pDstRectDescs, D3DCOMPOSERECTSOP Operation, int Xoffset, int Yoffset); 151 | STDMETHOD(PresentEx)(THIS_ CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion, DWORD dwFlags); 152 | STDMETHOD(GetGPUThreadPriority)(THIS_ INT* pPriority); 153 | STDMETHOD(SetGPUThreadPriority)(THIS_ INT Priority); 154 | STDMETHOD(WaitForVBlank)(THIS_ UINT iSwapChain); 155 | STDMETHOD(CheckResourceResidency)(THIS_ IDirect3DResource9** pResourceArray, UINT32 NumResources); 156 | STDMETHOD(SetMaximumFrameLatency)(THIS_ UINT MaxLatency); 157 | STDMETHOD(GetMaximumFrameLatency)(THIS_ UINT* pMaxLatency); 158 | STDMETHOD(CheckDeviceState)(THIS_ HWND hDestinationWindow); 159 | STDMETHOD(CreateRenderTargetEx)(THIS_ UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Lockable, IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle, DWORD Usage); 160 | STDMETHOD(CreateOffscreenPlainSurfaceEx)(THIS_ UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle, DWORD Usage); 161 | STDMETHOD(CreateDepthStencilSurfaceEx)(THIS_ UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Discard, IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle, DWORD Usage); 162 | STDMETHOD(ResetEx)(THIS_ D3DPRESENT_PARAMETERS* pPresentationParameters, D3DDISPLAYMODEEX *pFullscreenDisplayMode); 163 | STDMETHOD(GetDisplayModeEx)(THIS_ UINT iSwapChain, D3DDISPLAYMODEEX* pMode, D3DDISPLAYROTATION* pRotation); 164 | }; 165 | -------------------------------------------------------------------------------- /source/dxsdk/d3dx9core.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (C) Microsoft Corporation. All Rights Reserved. 4 | // 5 | // File: d3dx9core.h 6 | // Content: D3DX core types and functions 7 | // 8 | /////////////////////////////////////////////////////////////////////////// 9 | 10 | #include "d3dx9.h" 11 | 12 | #ifndef __D3DX9CORE_H__ 13 | #define __D3DX9CORE_H__ 14 | 15 | 16 | /////////////////////////////////////////////////////////////////////////// 17 | // D3DX_SDK_VERSION: 18 | // ----------------- 19 | // This identifier is passed to D3DXCheckVersion in order to ensure that an 20 | // application was built against the correct header files and lib files. 21 | // This number is incremented whenever a header (or other) change would 22 | // require applications to be rebuilt. If the version doesn't match, 23 | // D3DXCheckVersion will return FALSE. (The number itself has no meaning.) 24 | /////////////////////////////////////////////////////////////////////////// 25 | 26 | #define D3DX_VERSION 0x0902 27 | 28 | #define D3DX_SDK_VERSION 43 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif //__cplusplus 33 | 34 | BOOL WINAPI 35 | D3DXCheckVersion(UINT D3DSdkVersion, UINT D3DXSdkVersion); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif //__cplusplus 40 | 41 | 42 | 43 | /////////////////////////////////////////////////////////////////////////// 44 | // D3DXDebugMute 45 | // Mutes D3DX and D3D debug spew (TRUE - mute, FALSE - not mute) 46 | // 47 | // returns previous mute value 48 | // 49 | /////////////////////////////////////////////////////////////////////////// 50 | 51 | #ifdef __cplusplus 52 | extern "C" { 53 | #endif //__cplusplus 54 | 55 | BOOL WINAPI 56 | D3DXDebugMute(BOOL Mute); 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif //__cplusplus 61 | 62 | 63 | /////////////////////////////////////////////////////////////////////////// 64 | // D3DXGetDriverLevel: 65 | // Returns driver version information: 66 | // 67 | // 700 - DX7 level driver 68 | // 800 - DX8 level driver 69 | // 900 - DX9 level driver 70 | /////////////////////////////////////////////////////////////////////////// 71 | 72 | #ifdef __cplusplus 73 | extern "C" { 74 | #endif //__cplusplus 75 | 76 | UINT WINAPI 77 | D3DXGetDriverLevel(LPDIRECT3DDEVICE9 pDevice); 78 | 79 | #ifdef __cplusplus 80 | } 81 | #endif //__cplusplus 82 | 83 | 84 | /////////////////////////////////////////////////////////////////////////// 85 | // ID3DXBuffer: 86 | // ------------ 87 | // The buffer object is used by D3DX to return arbitrary size data. 88 | // 89 | // GetBufferPointer - 90 | // Returns a pointer to the beginning of the buffer. 91 | // 92 | // GetBufferSize - 93 | // Returns the size of the buffer, in bytes. 94 | /////////////////////////////////////////////////////////////////////////// 95 | 96 | typedef interface ID3DXBuffer ID3DXBuffer; 97 | typedef interface ID3DXBuffer *LPD3DXBUFFER; 98 | 99 | // {8BA5FB08-5195-40e2-AC58-0D989C3A0102} 100 | DEFINE_GUID(IID_ID3DXBuffer, 101 | 0x8ba5fb08, 0x5195, 0x40e2, 0xac, 0x58, 0xd, 0x98, 0x9c, 0x3a, 0x1, 0x2); 102 | 103 | #undef INTERFACE 104 | #define INTERFACE ID3DXBuffer 105 | 106 | DECLARE_INTERFACE_(ID3DXBuffer, IUnknown) 107 | { 108 | // IUnknown 109 | STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE; 110 | STDMETHOD_(ULONG, AddRef)(THIS) PURE; 111 | STDMETHOD_(ULONG, Release)(THIS) PURE; 112 | 113 | // ID3DXBuffer 114 | STDMETHOD_(LPVOID, GetBufferPointer)(THIS) PURE; 115 | STDMETHOD_(DWORD, GetBufferSize)(THIS) PURE; 116 | }; 117 | 118 | 119 | 120 | ////////////////////////////////////////////////////////////////////////////// 121 | // D3DXSPRITE flags: 122 | // ----------------- 123 | // D3DXSPRITE_DONOTSAVESTATE 124 | // Specifies device state is not to be saved and restored in Begin/End. 125 | // D3DXSPRITE_DONOTMODIFY_RENDERSTATE 126 | // Specifies device render state is not to be changed in Begin. The device 127 | // is assumed to be in a valid state to draw vertices containing POSITION0, 128 | // TEXCOORD0, and COLOR0 data. 129 | // D3DXSPRITE_OBJECTSPACE 130 | // The WORLD, VIEW, and PROJECTION transforms are NOT modified. The 131 | // transforms currently set to the device are used to transform the sprites 132 | // when the batch is drawn (at Flush or End). If this is not specified, 133 | // WORLD, VIEW, and PROJECTION transforms are modified so that sprites are 134 | // drawn in screenspace coordinates. 135 | // D3DXSPRITE_BILLBOARD 136 | // Rotates each sprite about its center so that it is facing the viewer. 137 | // D3DXSPRITE_ALPHABLEND 138 | // Enables ALPHABLEND(SRCALPHA, INVSRCALPHA) and ALPHATEST(alpha > 0). 139 | // ID3DXFont expects this to be set when drawing text. 140 | // D3DXSPRITE_SORT_TEXTURE 141 | // Sprites are sorted by texture prior to drawing. This is recommended when 142 | // drawing non-overlapping sprites of uniform depth. For example, drawing 143 | // screen-aligned text with ID3DXFont. 144 | // D3DXSPRITE_SORT_DEPTH_FRONTTOBACK 145 | // Sprites are sorted by depth front-to-back prior to drawing. This is 146 | // recommended when drawing opaque sprites of varying depths. 147 | // D3DXSPRITE_SORT_DEPTH_BACKTOFRONT 148 | // Sprites are sorted by depth back-to-front prior to drawing. This is 149 | // recommended when drawing transparent sprites of varying depths. 150 | // D3DXSPRITE_DO_NOT_ADDREF_TEXTURE 151 | // Disables calling AddRef() on every draw, and Release() on Flush() for 152 | // better performance. 153 | ////////////////////////////////////////////////////////////////////////////// 154 | 155 | #define D3DXSPRITE_DONOTSAVESTATE (1 << 0) 156 | #define D3DXSPRITE_DONOTMODIFY_RENDERSTATE (1 << 1) 157 | #define D3DXSPRITE_OBJECTSPACE (1 << 2) 158 | #define D3DXSPRITE_BILLBOARD (1 << 3) 159 | #define D3DXSPRITE_ALPHABLEND (1 << 4) 160 | #define D3DXSPRITE_SORT_TEXTURE (1 << 5) 161 | #define D3DXSPRITE_SORT_DEPTH_FRONTTOBACK (1 << 6) 162 | #define D3DXSPRITE_SORT_DEPTH_BACKTOFRONT (1 << 7) 163 | #define D3DXSPRITE_DO_NOT_ADDREF_TEXTURE (1 << 8) 164 | 165 | 166 | ////////////////////////////////////////////////////////////////////////////// 167 | // ID3DXSprite: 168 | // ------------ 169 | // This object intends to provide an easy way to drawing sprites using D3D. 170 | // 171 | // Begin - 172 | // Prepares device for drawing sprites. 173 | // 174 | // Draw - 175 | // Draws a sprite. Before transformation, the sprite is the size of 176 | // SrcRect, with its top-left corner specified by Position. The color 177 | // and alpha channels are modulated by Color. 178 | // 179 | // Flush - 180 | // Forces all batched sprites to submitted to the device. 181 | // 182 | // End - 183 | // Restores device state to how it was when Begin was called. 184 | // 185 | // OnLostDevice, OnResetDevice - 186 | // Call OnLostDevice() on this object before calling Reset() on the 187 | // device, so that this object can release any stateblocks and video 188 | // memory resources. After Reset(), the call OnResetDevice(). 189 | ////////////////////////////////////////////////////////////////////////////// 190 | 191 | typedef interface ID3DXSprite ID3DXSprite; 192 | typedef interface ID3DXSprite *LPD3DXSPRITE; 193 | 194 | 195 | // {BA0B762D-7D28-43ec-B9DC-2F84443B0614} 196 | DEFINE_GUID(IID_ID3DXSprite, 197 | 0xba0b762d, 0x7d28, 0x43ec, 0xb9, 0xdc, 0x2f, 0x84, 0x44, 0x3b, 0x6, 0x14); 198 | 199 | 200 | #undef INTERFACE 201 | #define INTERFACE ID3DXSprite 202 | 203 | DECLARE_INTERFACE_(ID3DXSprite, IUnknown) 204 | { 205 | // IUnknown 206 | STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE; 207 | STDMETHOD_(ULONG, AddRef)(THIS) PURE; 208 | STDMETHOD_(ULONG, Release)(THIS) PURE; 209 | 210 | // ID3DXSprite 211 | STDMETHOD(GetDevice)(THIS_ LPDIRECT3DDEVICE9* ppDevice) PURE; 212 | 213 | STDMETHOD(GetTransform)(THIS_ D3DXMATRIX *pTransform) PURE; 214 | STDMETHOD(SetTransform)(THIS_ CONST D3DXMATRIX *pTransform) PURE; 215 | 216 | STDMETHOD(SetWorldViewRH)(THIS_ CONST D3DXMATRIX *pWorld, CONST D3DXMATRIX *pView) PURE; 217 | STDMETHOD(SetWorldViewLH)(THIS_ CONST D3DXMATRIX *pWorld, CONST D3DXMATRIX *pView) PURE; 218 | 219 | STDMETHOD(Begin)(THIS_ DWORD Flags) PURE; 220 | STDMETHOD(Draw)(THIS_ LPDIRECT3DTEXTURE9 pTexture, CONST RECT *pSrcRect, CONST D3DXVECTOR3 *pCenter, CONST D3DXVECTOR3 *pPosition, D3DCOLOR Color) PURE; 221 | STDMETHOD(Flush)(THIS) PURE; 222 | STDMETHOD(End)(THIS) PURE; 223 | 224 | STDMETHOD(OnLostDevice)(THIS) PURE; 225 | STDMETHOD(OnResetDevice)(THIS) PURE; 226 | }; 227 | 228 | 229 | #ifdef __cplusplus 230 | extern "C" { 231 | #endif //__cplusplus 232 | 233 | HRESULT WINAPI 234 | D3DXCreateSprite( 235 | LPDIRECT3DDEVICE9 pDevice, 236 | LPD3DXSPRITE* ppSprite); 237 | 238 | #ifdef __cplusplus 239 | } 240 | #endif //__cplusplus 241 | 242 | 243 | 244 | ////////////////////////////////////////////////////////////////////////////// 245 | // ID3DXFont: 246 | // ---------- 247 | // Font objects contain the textures and resources needed to render a specific 248 | // font on a specific device. 249 | // 250 | // GetGlyphData - 251 | // Returns glyph cache data, for a given glyph. 252 | // 253 | // PreloadCharacters/PreloadGlyphs/PreloadText - 254 | // Preloads glyphs into the glyph cache textures. 255 | // 256 | // DrawText - 257 | // Draws formatted text on a D3D device. Some parameters are 258 | // surprisingly similar to those of GDI's DrawText function. See GDI 259 | // documentation for a detailed description of these parameters. 260 | // If pSprite is NULL, an internal sprite object will be used. 261 | // 262 | // OnLostDevice, OnResetDevice - 263 | // Call OnLostDevice() on this object before calling Reset() on the 264 | // device, so that this object can release any stateblocks and video 265 | // memory resources. After Reset(), the call OnResetDevice(). 266 | ////////////////////////////////////////////////////////////////////////////// 267 | 268 | typedef struct _D3DXFONT_DESCA 269 | { 270 | INT Height; 271 | UINT Width; 272 | UINT Weight; 273 | UINT MipLevels; 274 | BOOL Italic; 275 | BYTE CharSet; 276 | BYTE OutputPrecision; 277 | BYTE Quality; 278 | BYTE PitchAndFamily; 279 | CHAR FaceName[LF_FACESIZE]; 280 | 281 | } D3DXFONT_DESCA, *LPD3DXFONT_DESCA; 282 | 283 | typedef struct _D3DXFONT_DESCW 284 | { 285 | INT Height; 286 | UINT Width; 287 | UINT Weight; 288 | UINT MipLevels; 289 | BOOL Italic; 290 | BYTE CharSet; 291 | BYTE OutputPrecision; 292 | BYTE Quality; 293 | BYTE PitchAndFamily; 294 | WCHAR FaceName[LF_FACESIZE]; 295 | 296 | } D3DXFONT_DESCW, *LPD3DXFONT_DESCW; 297 | 298 | #ifdef UNICODE 299 | typedef D3DXFONT_DESCW D3DXFONT_DESC; 300 | typedef LPD3DXFONT_DESCW LPD3DXFONT_DESC; 301 | #else 302 | typedef D3DXFONT_DESCA D3DXFONT_DESC; 303 | typedef LPD3DXFONT_DESCA LPD3DXFONT_DESC; 304 | #endif 305 | 306 | 307 | typedef interface ID3DXFont ID3DXFont; 308 | typedef interface ID3DXFont *LPD3DXFONT; 309 | 310 | 311 | // {D79DBB70-5F21-4d36-BBC2-FF525C213CDC} 312 | DEFINE_GUID(IID_ID3DXFont, 313 | 0xd79dbb70, 0x5f21, 0x4d36, 0xbb, 0xc2, 0xff, 0x52, 0x5c, 0x21, 0x3c, 0xdc); 314 | 315 | 316 | #undef INTERFACE 317 | #define INTERFACE ID3DXFont 318 | 319 | DECLARE_INTERFACE_(ID3DXFont, IUnknown) 320 | { 321 | // IUnknown 322 | STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE; 323 | STDMETHOD_(ULONG, AddRef)(THIS) PURE; 324 | STDMETHOD_(ULONG, Release)(THIS) PURE; 325 | 326 | // ID3DXFont 327 | STDMETHOD(GetDevice)(THIS_ LPDIRECT3DDEVICE9 *ppDevice) PURE; 328 | STDMETHOD(GetDescA)(THIS_ D3DXFONT_DESCA *pDesc) PURE; 329 | STDMETHOD(GetDescW)(THIS_ D3DXFONT_DESCW *pDesc) PURE; 330 | STDMETHOD_(BOOL, GetTextMetricsA)(THIS_ TEXTMETRICA *pTextMetrics) PURE; 331 | STDMETHOD_(BOOL, GetTextMetricsW)(THIS_ TEXTMETRICW *pTextMetrics) PURE; 332 | 333 | STDMETHOD_(HDC, GetDC)(THIS) PURE; 334 | STDMETHOD(GetGlyphData)(THIS_ UINT Glyph, LPDIRECT3DTEXTURE9 *ppTexture, RECT *pBlackBox, POINT *pCellInc) PURE; 335 | 336 | STDMETHOD(PreloadCharacters)(THIS_ UINT First, UINT Last) PURE; 337 | STDMETHOD(PreloadGlyphs)(THIS_ UINT First, UINT Last) PURE; 338 | STDMETHOD(PreloadTextA)(THIS_ LPCSTR pString, INT Count) PURE; 339 | STDMETHOD(PreloadTextW)(THIS_ LPCWSTR pString, INT Count) PURE; 340 | 341 | STDMETHOD_(INT, DrawTextA)(THIS_ LPD3DXSPRITE pSprite, LPCSTR pString, INT Count, LPRECT pRect, DWORD Format, D3DCOLOR Color) PURE; 342 | STDMETHOD_(INT, DrawTextW)(THIS_ LPD3DXSPRITE pSprite, LPCWSTR pString, INT Count, LPRECT pRect, DWORD Format, D3DCOLOR Color) PURE; 343 | 344 | STDMETHOD(OnLostDevice)(THIS) PURE; 345 | STDMETHOD(OnResetDevice)(THIS) PURE; 346 | 347 | #ifdef __cplusplus 348 | #ifdef UNICODE 349 | HRESULT GetDesc(D3DXFONT_DESCW *pDesc) { return GetDescW(pDesc); } 350 | HRESULT PreloadText(LPCWSTR pString, INT Count) { return PreloadTextW(pString, Count); } 351 | #else 352 | HRESULT GetDesc(D3DXFONT_DESCA *pDesc) { return GetDescA(pDesc); } 353 | HRESULT PreloadText(LPCSTR pString, INT Count) { return PreloadTextA(pString, Count); } 354 | #endif 355 | #endif //__cplusplus 356 | }; 357 | 358 | #ifndef GetTextMetrics 359 | #ifdef UNICODE 360 | #define GetTextMetrics GetTextMetricsW 361 | #else 362 | #define GetTextMetrics GetTextMetricsA 363 | #endif 364 | #endif 365 | 366 | #ifndef DrawText 367 | #ifdef UNICODE 368 | #define DrawText DrawTextW 369 | #else 370 | #define DrawText DrawTextA 371 | #endif 372 | #endif 373 | 374 | 375 | #ifdef __cplusplus 376 | extern "C" { 377 | #endif //__cplusplus 378 | 379 | 380 | HRESULT WINAPI 381 | D3DXCreateFontA( 382 | LPDIRECT3DDEVICE9 pDevice, 383 | INT Height, 384 | UINT Width, 385 | UINT Weight, 386 | UINT MipLevels, 387 | BOOL Italic, 388 | DWORD CharSet, 389 | DWORD OutputPrecision, 390 | DWORD Quality, 391 | DWORD PitchAndFamily, 392 | LPCSTR pFaceName, 393 | LPD3DXFONT* ppFont); 394 | 395 | HRESULT WINAPI 396 | D3DXCreateFontW( 397 | LPDIRECT3DDEVICE9 pDevice, 398 | INT Height, 399 | UINT Width, 400 | UINT Weight, 401 | UINT MipLevels, 402 | BOOL Italic, 403 | DWORD CharSet, 404 | DWORD OutputPrecision, 405 | DWORD Quality, 406 | DWORD PitchAndFamily, 407 | LPCWSTR pFaceName, 408 | LPD3DXFONT* ppFont); 409 | 410 | #ifdef UNICODE 411 | #define D3DXCreateFont D3DXCreateFontW 412 | #else 413 | #define D3DXCreateFont D3DXCreateFontA 414 | #endif 415 | 416 | 417 | HRESULT WINAPI 418 | D3DXCreateFontIndirectA( 419 | LPDIRECT3DDEVICE9 pDevice, 420 | CONST D3DXFONT_DESCA* pDesc, 421 | LPD3DXFONT* ppFont); 422 | 423 | HRESULT WINAPI 424 | D3DXCreateFontIndirectW( 425 | LPDIRECT3DDEVICE9 pDevice, 426 | CONST D3DXFONT_DESCW* pDesc, 427 | LPD3DXFONT* ppFont); 428 | 429 | #ifdef UNICODE 430 | #define D3DXCreateFontIndirect D3DXCreateFontIndirectW 431 | #else 432 | #define D3DXCreateFontIndirect D3DXCreateFontIndirectA 433 | #endif 434 | 435 | 436 | #ifdef __cplusplus 437 | } 438 | #endif //__cplusplus 439 | 440 | 441 | 442 | /////////////////////////////////////////////////////////////////////////// 443 | // ID3DXRenderToSurface: 444 | // --------------------- 445 | // This object abstracts rendering to surfaces. These surfaces do not 446 | // necessarily need to be render targets. If they are not, a compatible 447 | // render target is used, and the result copied into surface at end scene. 448 | // 449 | // BeginScene, EndScene - 450 | // Call BeginScene() and EndScene() at the beginning and ending of your 451 | // scene. These calls will setup and restore render targets, viewports, 452 | // etc.. 453 | // 454 | // OnLostDevice, OnResetDevice - 455 | // Call OnLostDevice() on this object before calling Reset() on the 456 | // device, so that this object can release any stateblocks and video 457 | // memory resources. After Reset(), the call OnResetDevice(). 458 | /////////////////////////////////////////////////////////////////////////// 459 | 460 | typedef struct _D3DXRTS_DESC 461 | { 462 | UINT Width; 463 | UINT Height; 464 | D3DFORMAT Format; 465 | BOOL DepthStencil; 466 | D3DFORMAT DepthStencilFormat; 467 | 468 | } D3DXRTS_DESC, *LPD3DXRTS_DESC; 469 | 470 | 471 | typedef interface ID3DXRenderToSurface ID3DXRenderToSurface; 472 | typedef interface ID3DXRenderToSurface *LPD3DXRENDERTOSURFACE; 473 | 474 | 475 | // {6985F346-2C3D-43b3-BE8B-DAAE8A03D894} 476 | DEFINE_GUID(IID_ID3DXRenderToSurface, 477 | 0x6985f346, 0x2c3d, 0x43b3, 0xbe, 0x8b, 0xda, 0xae, 0x8a, 0x3, 0xd8, 0x94); 478 | 479 | 480 | #undef INTERFACE 481 | #define INTERFACE ID3DXRenderToSurface 482 | 483 | DECLARE_INTERFACE_(ID3DXRenderToSurface, IUnknown) 484 | { 485 | // IUnknown 486 | STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE; 487 | STDMETHOD_(ULONG, AddRef)(THIS) PURE; 488 | STDMETHOD_(ULONG, Release)(THIS) PURE; 489 | 490 | // ID3DXRenderToSurface 491 | STDMETHOD(GetDevice)(THIS_ LPDIRECT3DDEVICE9* ppDevice) PURE; 492 | STDMETHOD(GetDesc)(THIS_ D3DXRTS_DESC* pDesc) PURE; 493 | 494 | STDMETHOD(BeginScene)(THIS_ LPDIRECT3DSURFACE9 pSurface, CONST D3DVIEWPORT9* pViewport) PURE; 495 | STDMETHOD(EndScene)(THIS_ DWORD MipFilter) PURE; 496 | 497 | STDMETHOD(OnLostDevice)(THIS) PURE; 498 | STDMETHOD(OnResetDevice)(THIS) PURE; 499 | }; 500 | 501 | 502 | #ifdef __cplusplus 503 | extern "C" { 504 | #endif //__cplusplus 505 | 506 | HRESULT WINAPI 507 | D3DXCreateRenderToSurface( 508 | LPDIRECT3DDEVICE9 pDevice, 509 | UINT Width, 510 | UINT Height, 511 | D3DFORMAT Format, 512 | BOOL DepthStencil, 513 | D3DFORMAT DepthStencilFormat, 514 | LPD3DXRENDERTOSURFACE* ppRenderToSurface); 515 | 516 | #ifdef __cplusplus 517 | } 518 | #endif //__cplusplus 519 | 520 | 521 | 522 | /////////////////////////////////////////////////////////////////////////// 523 | // ID3DXRenderToEnvMap: 524 | // -------------------- 525 | // This object abstracts rendering to environment maps. These surfaces 526 | // do not necessarily need to be render targets. If they are not, a 527 | // compatible render target is used, and the result copied into the 528 | // environment map at end scene. 529 | // 530 | // BeginCube, BeginSphere, BeginHemisphere, BeginParabolic - 531 | // This function initiates the rendering of the environment map. As 532 | // parameters, you pass the textures in which will get filled in with 533 | // the resulting environment map. 534 | // 535 | // Face - 536 | // Call this function to initiate the drawing of each face. For each 537 | // environment map, you will call this six times.. once for each face 538 | // in D3DCUBEMAP_FACES. 539 | // 540 | // End - 541 | // This will restore all render targets, and if needed compose all the 542 | // rendered faces into the environment map surfaces. 543 | // 544 | // OnLostDevice, OnResetDevice - 545 | // Call OnLostDevice() on this object before calling Reset() on the 546 | // device, so that this object can release any stateblocks and video 547 | // memory resources. After Reset(), the call OnResetDevice(). 548 | /////////////////////////////////////////////////////////////////////////// 549 | 550 | typedef struct _D3DXRTE_DESC 551 | { 552 | UINT Size; 553 | UINT MipLevels; 554 | D3DFORMAT Format; 555 | BOOL DepthStencil; 556 | D3DFORMAT DepthStencilFormat; 557 | 558 | } D3DXRTE_DESC, *LPD3DXRTE_DESC; 559 | 560 | 561 | typedef interface ID3DXRenderToEnvMap ID3DXRenderToEnvMap; 562 | typedef interface ID3DXRenderToEnvMap *LPD3DXRenderToEnvMap; 563 | 564 | 565 | // {313F1B4B-C7B0-4fa2-9D9D-8D380B64385E} 566 | DEFINE_GUID(IID_ID3DXRenderToEnvMap, 567 | 0x313f1b4b, 0xc7b0, 0x4fa2, 0x9d, 0x9d, 0x8d, 0x38, 0xb, 0x64, 0x38, 0x5e); 568 | 569 | 570 | #undef INTERFACE 571 | #define INTERFACE ID3DXRenderToEnvMap 572 | 573 | DECLARE_INTERFACE_(ID3DXRenderToEnvMap, IUnknown) 574 | { 575 | // IUnknown 576 | STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE; 577 | STDMETHOD_(ULONG, AddRef)(THIS) PURE; 578 | STDMETHOD_(ULONG, Release)(THIS) PURE; 579 | 580 | // ID3DXRenderToEnvMap 581 | STDMETHOD(GetDevice)(THIS_ LPDIRECT3DDEVICE9* ppDevice) PURE; 582 | STDMETHOD(GetDesc)(THIS_ D3DXRTE_DESC* pDesc) PURE; 583 | 584 | STDMETHOD(BeginCube)(THIS_ 585 | LPDIRECT3DCUBETEXTURE9 pCubeTex) PURE; 586 | 587 | STDMETHOD(BeginSphere)(THIS_ 588 | LPDIRECT3DTEXTURE9 pTex) PURE; 589 | 590 | STDMETHOD(BeginHemisphere)(THIS_ 591 | LPDIRECT3DTEXTURE9 pTexZPos, 592 | LPDIRECT3DTEXTURE9 pTexZNeg) PURE; 593 | 594 | STDMETHOD(BeginParabolic)(THIS_ 595 | LPDIRECT3DTEXTURE9 pTexZPos, 596 | LPDIRECT3DTEXTURE9 pTexZNeg) PURE; 597 | 598 | STDMETHOD(Face)(THIS_ D3DCUBEMAP_FACES Face, DWORD MipFilter) PURE; 599 | STDMETHOD(End)(THIS_ DWORD MipFilter) PURE; 600 | 601 | STDMETHOD(OnLostDevice)(THIS) PURE; 602 | STDMETHOD(OnResetDevice)(THIS) PURE; 603 | }; 604 | 605 | 606 | #ifdef __cplusplus 607 | extern "C" { 608 | #endif //__cplusplus 609 | 610 | HRESULT WINAPI 611 | D3DXCreateRenderToEnvMap( 612 | LPDIRECT3DDEVICE9 pDevice, 613 | UINT Size, 614 | UINT MipLevels, 615 | D3DFORMAT Format, 616 | BOOL DepthStencil, 617 | D3DFORMAT DepthStencilFormat, 618 | LPD3DXRenderToEnvMap* ppRenderToEnvMap); 619 | 620 | #ifdef __cplusplus 621 | } 622 | #endif //__cplusplus 623 | 624 | 625 | 626 | /////////////////////////////////////////////////////////////////////////// 627 | // ID3DXLine: 628 | // ------------ 629 | // This object intends to provide an easy way to draw lines using D3D. 630 | // 631 | // Begin - 632 | // Prepares device for drawing lines 633 | // 634 | // Draw - 635 | // Draws a line strip in screen-space. 636 | // Input is in the form of a array defining points on the line strip. of D3DXVECTOR2 637 | // 638 | // DrawTransform - 639 | // Draws a line in screen-space with a specified input transformation matrix. 640 | // 641 | // End - 642 | // Restores device state to how it was when Begin was called. 643 | // 644 | // SetPattern - 645 | // Applies a stipple pattern to the line. Input is one 32-bit 646 | // DWORD which describes the stipple pattern. 1 is opaque, 0 is 647 | // transparent. 648 | // 649 | // SetPatternScale - 650 | // Stretches the stipple pattern in the u direction. Input is one 651 | // floating-point value. 0.0f is no scaling, whereas 1.0f doubles 652 | // the length of the stipple pattern. 653 | // 654 | // SetWidth - 655 | // Specifies the thickness of the line in the v direction. Input is 656 | // one floating-point value. 657 | // 658 | // SetAntialias - 659 | // Toggles line antialiasing. Input is a BOOL. 660 | // TRUE = Antialiasing on. 661 | // FALSE = Antialiasing off. 662 | // 663 | // SetGLLines - 664 | // Toggles non-antialiased OpenGL line emulation. Input is a BOOL. 665 | // TRUE = OpenGL line emulation on. 666 | // FALSE = OpenGL line emulation off. 667 | // 668 | // OpenGL line: Regular line: 669 | // *\ *\ 670 | // | \ / \ 671 | // | \ *\ \ 672 | // *\ \ \ \ 673 | // \ \ \ \ 674 | // \ * \ * 675 | // \ | \ / 676 | // \| * 677 | // * 678 | // 679 | // OnLostDevice, OnResetDevice - 680 | // Call OnLostDevice() on this object before calling Reset() on the 681 | // device, so that this object can release any stateblocks and video 682 | // memory resources. After Reset(), the call OnResetDevice(). 683 | /////////////////////////////////////////////////////////////////////////// 684 | 685 | 686 | typedef interface ID3DXLine ID3DXLine; 687 | typedef interface ID3DXLine *LPD3DXLINE; 688 | 689 | 690 | // {D379BA7F-9042-4ac4-9F5E-58192A4C6BD8} 691 | DEFINE_GUID(IID_ID3DXLine, 692 | 0xd379ba7f, 0x9042, 0x4ac4, 0x9f, 0x5e, 0x58, 0x19, 0x2a, 0x4c, 0x6b, 0xd8); 693 | 694 | #undef INTERFACE 695 | #define INTERFACE ID3DXLine 696 | 697 | DECLARE_INTERFACE_(ID3DXLine, IUnknown) 698 | { 699 | // IUnknown 700 | STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE; 701 | STDMETHOD_(ULONG, AddRef)(THIS) PURE; 702 | STDMETHOD_(ULONG, Release)(THIS) PURE; 703 | 704 | // ID3DXLine 705 | STDMETHOD(GetDevice)(THIS_ LPDIRECT3DDEVICE9* ppDevice) PURE; 706 | 707 | STDMETHOD(Begin)(THIS) PURE; 708 | 709 | STDMETHOD(Draw)(THIS_ CONST D3DXVECTOR2 *pVertexList, 710 | DWORD dwVertexListCount, D3DCOLOR Color) PURE; 711 | 712 | STDMETHOD(DrawTransform)(THIS_ CONST D3DXVECTOR3 *pVertexList, 713 | DWORD dwVertexListCount, CONST D3DXMATRIX* pTransform, 714 | D3DCOLOR Color) PURE; 715 | 716 | STDMETHOD(SetPattern)(THIS_ DWORD dwPattern) PURE; 717 | STDMETHOD_(DWORD, GetPattern)(THIS) PURE; 718 | 719 | STDMETHOD(SetPatternScale)(THIS_ FLOAT fPatternScale) PURE; 720 | STDMETHOD_(FLOAT, GetPatternScale)(THIS) PURE; 721 | 722 | STDMETHOD(SetWidth)(THIS_ FLOAT fWidth) PURE; 723 | STDMETHOD_(FLOAT, GetWidth)(THIS) PURE; 724 | 725 | STDMETHOD(SetAntialias)(THIS_ BOOL bAntialias) PURE; 726 | STDMETHOD_(BOOL, GetAntialias)(THIS) PURE; 727 | 728 | STDMETHOD(SetGLLines)(THIS_ BOOL bGLLines) PURE; 729 | STDMETHOD_(BOOL, GetGLLines)(THIS) PURE; 730 | 731 | STDMETHOD(End)(THIS) PURE; 732 | 733 | STDMETHOD(OnLostDevice)(THIS) PURE; 734 | STDMETHOD(OnResetDevice)(THIS) PURE; 735 | }; 736 | 737 | 738 | #ifdef __cplusplus 739 | extern "C" { 740 | #endif //__cplusplus 741 | 742 | 743 | HRESULT WINAPI 744 | D3DXCreateLine( 745 | LPDIRECT3DDEVICE9 pDevice, 746 | LPD3DXLINE* ppLine); 747 | 748 | #ifdef __cplusplus 749 | } 750 | #endif //__cplusplus 751 | 752 | #endif //__D3DX9CORE_H__ 753 | 754 | --------------------------------------------------------------------------------