Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

380 lines
9.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Proxy for D3DX routines
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. //
  9. #include <windows.h>
  10. #include <vector>
  11. // Aux function prototype
  12. const char * WINAPI GetDllVersion( void );
  13. #ifdef _DEBUG
  14. #define D3D_DEBUG_INFO 1
  15. #endif
  16. //
  17. // DX9_V00_PC
  18. //
  19. // D3DX static library
  20. // MSFT file version: 5.3.0000001.0904
  21. //
  22. #ifdef DX9_V00_PC
  23. #ifdef DX_PROXY_INC_CONFIG
  24. # error "DX9_V00_PC: Multiple DX_PROXY configurations disallowed!"
  25. #endif
  26. #define DX_PROXY_INC_CONFIG
  27. #pragma message ( "Compiling DX_PROXY for DX9_V00_PC" )
  28. #if _MSC_VER >= 1900
  29. #pragma comment ( lib, "../../lib/common/win32/2015/release/d3dx9" )
  30. #else
  31. #pragma comment ( lib, "../../dx9sdk/lib/d3dx9" )
  32. #endif
  33. #include "../../dx9sdk/include/d3dx9shader.h"
  34. #endif // #ifdef DX9_V00_PC
  35. //
  36. // DX9_X360
  37. //
  38. // D3DX win32 static library
  39. // MSFT X360 SDK
  40. //
  41. #ifdef DX9_V00_X360
  42. #ifdef DX_PROXY_INC_CONFIG
  43. # error "DX9_V00_X360: Multiple DX_PROXY configurations disallowed!"
  44. #endif
  45. #define DX_PROXY_INC_CONFIG
  46. #pragma message ( "Compiling DX_PROXY for DX9_V00_X360" )
  47. // Avoid including XBOX math stuff
  48. #define _NO_XBOXMATH
  49. #define __D3DX9MATH_INL__
  50. /*#ifdef _DEBUG
  51. #pragma comment ( lib, "../../x360xdk/lib/win32/vs2005/d3d9d" )
  52. #pragma comment ( lib, "../../x360xdk/lib/win32/vs2005/d3dx9d" )
  53. #pragma comment ( lib, "../../x360xdk/lib/win32/vs2005/xgraphicsd" )
  54. #else*/
  55. #if _MSC_VER >= 1900
  56. #pragma comment ( lib, "../../x360xdk/lib/win32/vs2005/d3d9" )
  57. #pragma comment ( lib, "../../lib/common/win32/2015/release/d3dx9" )
  58. #else
  59. #pragma comment ( lib, "../../x360xdk/lib/win32/vs2005/d3d9" )
  60. #pragma comment ( lib, "../../x360xdk/lib/win32/vs2005/d3dx9" )
  61. #pragma comment ( lib, "../../x360xdk/lib/win32/vs2005/xgraphics" )
  62. #endif
  63. #include "../../x360xdk/include/win32/vs2005/d3dx9shader.h"
  64. #endif // #ifdef DX9_V00_X360
  65. //
  66. // DX9_V30_PC
  67. //
  68. // 1. D3DX static import library
  69. // 2. resource dynamic library d3dx9_33.dll
  70. //
  71. // MSFT file version: 9.16.843.0000
  72. // Distribution: Dec 2006 DirectX SDK
  73. //
  74. // Implementation note: need to delayload d3dx9_33
  75. // because the module should be extracted from resources first.
  76. // Make sure "/DELAYLOAD:d3dx9_33.dll" is passed to linker.
  77. //
  78. #ifdef DX9_V30_PC
  79. #ifdef DX_PROXY_INC_CONFIG
  80. # error "DX9_V30_PC: Multiple DX_PROXY configurations disallowed!"
  81. #endif
  82. #define DX_PROXY_INC_CONFIG
  83. #pragma message ( "Compiling DX_PROXY for DX9_V30_PC" )
  84. #pragma comment( lib, "delayimp" )
  85. #pragma comment ( lib, "../../dx10sdk/lib/x86/d3dx9" )
  86. #include "../../dx10sdk/include/d3dx9shader.h"
  87. #endif // #ifdef DX9_V30_PC
  88. //
  89. // DX10_V00_PC
  90. //
  91. // 1. D3DX static import library
  92. // 2. resource dynamic library d3dx10.dll
  93. //
  94. // MSFT file version: 9.16.843.0000
  95. // Distribution: Dec 2006 DirectX SDK
  96. //
  97. // Implementation note: need to delayload d3dx10
  98. // because the module should be extracted from resources first.
  99. // Make sure "/DELAYLOAD:d3dx10.dll" is passed to linker.
  100. //
  101. #ifdef DX10_V00_PC
  102. #ifdef DX_PROXY_INC_CONFIG
  103. # error "DX10_V00_PC: Multiple DX_PROXY configurations disallowed!"
  104. #endif
  105. #define DX_PROXY_INC_CONFIG
  106. #pragma message ( "Compiling DX_PROXY for DX10_V00_PC" )
  107. #pragma comment( lib, "delayimp" )
  108. #pragma comment ( lib, "../../dx10sdk/lib/x86/d3dx10" )
  109. #include "../../dx10sdk/include/d3dx10.h"
  110. typedef D3D10_SHADER_MACRO D3DXMACRO;
  111. typedef LPD3D10INCLUDE LPD3DXINCLUDE;
  112. typedef ID3D10Include ID3DXInclude;
  113. typedef D3D10_INCLUDE_TYPE D3DXINCLUDE_TYPE;
  114. typedef ID3D10Blob* LPD3DXBUFFER;
  115. typedef void* LPD3DXCONSTANTTABLE;
  116. #endif // #ifdef DX10_V00_PC
  117. //
  118. // No DX configuration
  119. #ifndef DX_PROXY_INC_CONFIG
  120. # error "DX9_PC or DX9_X360 must be defined!"
  121. #endif // #ifndef DX_PROXY_INC_CONFIG
  122. //
  123. // ExtractDependencies
  124. //
  125. // Retrieves all the additional required binaries from the resources and
  126. // places them to a temporary location. Then the binaries are mapped into
  127. // the address space of the calling process.
  128. //
  129. static BOOL ExtractDependencies( void )
  130. {
  131. return TRUE;
  132. /*
  133. BOOL bResult = TRUE;
  134. char chSyncName[0x30];
  135. char const *szDllVersion = GetDllVersion();
  136. sprintf( chSyncName, "%s_MTX", szDllVersion );
  137. HANDLE hMutex = ::CreateMutex( NULL, FALSE, chSyncName );
  138. if ( !hMutex )
  139. return FALSE;
  140. DWORD dwWaitResult = ::WaitForSingleObject( hMutex, INFINITE );
  141. if ( dwWaitResult != WAIT_OBJECT_0 )
  142. return FALSE;
  143. // Now we own the mutex
  144. char chExtractPath[0x100] = { 0 };
  145. if ( char const *pszTemp = getenv( "TEMP" ) )
  146. sprintf( chExtractPath, "%s\\", pszTemp );
  147. else if ( char const *pszTmp = getenv( "TMP" ) )
  148. sprintf( chExtractPath, "%s\\", pszTmp );
  149. else
  150. bResult = FALSE;
  151. if ( bResult )
  152. {
  153. sprintf( chExtractPath + strlen( chExtractPath ), "%s", szDllVersion );
  154. bResult = ::CreateDirectory( chExtractPath, NULL );
  155. if ( bResult )
  156. {
  157. sprintf( chExtractPath + strlen( chExtractPath ), "\\" );
  158. char const * const arrNames[] = {
  159. #ifdef DX9_V33_PC
  160. "d3dx9_33.dll", MAKEINTRESOURCE( 1 ),
  161. #else
  162. #endif
  163. NULL
  164. };
  165. // Now loop over the names
  166. for ( int k = 0; k < sizeof( arrNames ) / ( 2 * sizeof( arrNames[0] ) ); ++ k )
  167. {
  168. char const * const &szName = arrNames[ 2 * k ];
  169. char const * const &szResource = 1[ &szName ];
  170. char chCreateFileName[0x200];
  171. sprintf( chCreateFileName, "%s%s", chExtractPath, szName );
  172. HANDLE hFile = CreateFile( chCreateFileName, FILE_ALL_ACCESS, FILE_SHARE_READ, NULL, CREATE_NEW,
  173. FILE_ATTRIBUTE_HIDDEN | FILE_FLAG_DELETE_ON_CLOSE, NULL );
  174. #error "This is how you can create temp needed resources"
  175. }
  176. }
  177. }
  178. ::ReleaseMutex( hMutex );
  179. ::CloseHandle( hMutex );
  180. return bResult;
  181. */
  182. }
  183. // DLL entry point: DllMain
  184. BOOL WINAPI DllMain(
  185. HINSTANCE hinstDLL,
  186. DWORD fdwReason,
  187. LPVOID lpvReserved
  188. )
  189. {
  190. /*UNUSED_ALWAYS*/( hinstDLL );
  191. /*UNUSED_ALWAYS*/( lpvReserved );
  192. switch ( fdwReason )
  193. {
  194. case DLL_PROCESS_ATTACH:
  195. // Process is attaching - make sure it can find the dependencies
  196. return ExtractDependencies();
  197. }
  198. return TRUE;
  199. }
  200. // Obtain DLL version
  201. #pragma comment(linker, "/EXPORT:GetDllVersionLong=?GetDllVersionLong@@YGPBDXZ")
  202. const char * WINAPI GetDllVersionLong( void )
  203. {
  204. #if defined( DX9_V00_PC ) && defined( _DEBUG )
  205. return "{DX_PROXY for DX9_V00_PC DEBUG}";
  206. #endif
  207. #if defined( DX9_V00_PC ) && defined( NDEBUG )
  208. return "{DX_PROXY for DX9_V00_PC RELEASE}";
  209. #endif
  210. #if defined( DX9_V00_X360 ) && defined( _DEBUG )
  211. return "{DX_PROXY for DX9_V00_X360 DEBUG}";
  212. #endif
  213. #if defined( DX9_V00_X360 ) && defined( NDEBUG )
  214. return "{DX_PROXY for DX9_V00_X360 RELEASE}";
  215. #endif
  216. #if defined( DX9_V30_PC ) && defined( _DEBUG )
  217. return "{DX_PROXY for DX9_V30_PC DEBUG}";
  218. #endif
  219. #if defined( DX9_V30_PC ) && defined( NDEBUG )
  220. return "{DX_PROXY for DX9_V30_PC RELEASE}";
  221. #endif
  222. #if defined( DX10_V00_PC ) && defined( _DEBUG )
  223. return "{DX_PROXY for DX10_V00_PC DEBUG}";
  224. #endif
  225. #if defined( DX10_V00_PC ) && defined( NDEBUG )
  226. return "{DX_PROXY for DX10_V00_PC RELEASE}";
  227. #endif
  228. }
  229. #pragma comment(linker, "/EXPORT:GetDllVersion=?GetDllVersion@@YGPBDXZ")
  230. const char * WINAPI GetDllVersion( void )
  231. {
  232. #if defined( DX9_V00_PC ) && defined( _DEBUG )
  233. return "DXPRX_DX9_V00_PC_d";
  234. #endif
  235. #if defined( DX9_V00_PC ) && defined( NDEBUG )
  236. return "DXPRX_DX9_V00_PC_r";
  237. #endif
  238. #if defined( DX9_V00_X360 ) && defined( _DEBUG )
  239. return "DXPRX_DX9_V00_X360_d";
  240. #endif
  241. #if defined( DX9_V00_X360 ) && defined( NDEBUG )
  242. return "DXPRX_DX9_V00_X360_r";
  243. #endif
  244. #if defined( DX9_V30_PC ) && defined( _DEBUG )
  245. return "DXPRX_DX9_V30_PC_d";
  246. #endif
  247. #if defined( DX9_V30_PC ) && defined( NDEBUG )
  248. return "DXPRX_DX9_V30_PC_r";
  249. #endif
  250. #if defined( DX10_V00_PC ) && defined( _DEBUG )
  251. return "DXPRX_DX10_V00_PC_d";
  252. #endif
  253. #if defined( DX10_V00_PC ) && defined( NDEBUG )
  254. return "DXPRX_DX10_V00_PC_r";
  255. #endif
  256. }
  257. #include "filememcache.h"
  258. #include "dxincludeimpl.h"
  259. char s_dummyBuffer[ 512 ];
  260. // Proxied routines
  261. HRESULT WINAPI
  262. Proxy_D3DXCompileShaderFromFile(
  263. LPCSTR pSrcFile,
  264. CONST D3DXMACRO* pDefines,
  265. LPD3DXINCLUDE pInclude,
  266. LPCSTR pFunctionName,
  267. LPCSTR pProfile,
  268. DWORD Flags,
  269. LPD3DXBUFFER* ppShader,
  270. LPD3DXBUFFER* ppErrorMsgs,
  271. LPD3DXCONSTANTTABLE* ppConstantTable )
  272. {
  273. if ( !pInclude )
  274. pInclude = &s_incDxImpl;
  275. // Open the top-level file via our include interface
  276. LPCVOID lpcvData;
  277. UINT numBytes;
  278. HRESULT hr = pInclude->Open( ( D3DXINCLUDE_TYPE ) 0, pSrcFile, NULL, &lpcvData, &numBytes
  279. #if defined( DX9_V00_X360 )
  280. , s_dummyBuffer, sizeof( s_dummyBuffer )
  281. #endif
  282. );
  283. if ( FAILED( hr ) )
  284. return hr;
  285. LPCSTR pShaderData = ( LPCSTR ) lpcvData;
  286. #if defined( DX9_V00_PC ) || defined( DX9_V30_PC ) || defined( DX9_V00_X360 )
  287. #pragma comment(linker, "/EXPORT:Proxy_D3DXCompileShaderFromFile=?Proxy_D3DXCompileShaderFromFile@@YGJPBDPBU_D3DXMACRO@@PAUID3DXInclude@@00KPAPAUID3DXBuffer@@3PAPAUID3DXConstantTable@@@Z")
  288. hr = D3DXCompileShader( pShaderData, numBytes, pDefines, pInclude, pFunctionName, pProfile, Flags, ppShader, ppErrorMsgs, ppConstantTable );
  289. #endif
  290. #if defined( DX10_V00_PC )
  291. #pragma comment(linker, "/EXPORT:Proxy_D3DXCompileShaderFromFile=?Proxy_D3DXCompileShaderFromFile@@YGJPBDPBU_D3D10_SHADER_MACRO@@PAUID3D10Include@@00KPAPAUID3D10Blob@@3PAPAX@Z")
  292. hr = D3DX10CompileFromMemory( pShaderData, numBytes, pSrcFile, pDefines, pInclude, pFunctionName, pProfile, Flags, 0, NULL, ppShader, ppErrorMsgs, NULL );
  293. #endif
  294. // Close the file
  295. pInclude->Close( lpcvData );
  296. return hr;
  297. }