Counter Strike : Global Offensive Source Code
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.

363 lines
8.9 KiB

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