Leaked source code of windows server 2003
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.

144 lines
3.1 KiB

  1. /*++
  2. Copyright (c) 2001-2002 Microsoft Corporation
  3. Module Name:
  4. BaseBall2000.cpp
  5. Abstract:
  6. If you use a video card that supports more than 10 texture formats the
  7. app will AV writing passed the end of their SURFACEDESC array.
  8. History:
  9. 01/04/2001 maonis Created
  10. 03/07/2002 robkenny Security changes
  11. --*/
  12. #include "precomp.h"
  13. #include "d3d.h"
  14. IMPLEMENT_SHIM_BEGIN(BaseBall2000)
  15. #include "ShimHookMacro.h"
  16. APIHOOK_ENUM_BEGIN
  17. APIHOOK_ENUM_ENTRY_DIRECTX_COMSERVER()
  18. APIHOOK_ENUM_END
  19. IMPLEMENT_DIRECTX_COMSERVER_HOOKS()
  20. typedef HRESULT (*_pfn_IDirect3D3_CreateDevice)(PVOID pThis, REFCLSID rclsid, LPDIRECTDRAWSURFACE4, LPDIRECT3DDEVICE3*, LPUNKNOWN);
  21. typedef HRESULT (*_pfn_IDirect3DDevice3_EnumTextureFormats)(PVOID pThis, LPD3DENUMPIXELFORMATSCALLBACK, LPVOID);
  22. typedef HRESULT (*_pfn_EnumPixelFormatsCallback)(LPDDPIXELFORMAT lpDDPixFmt, LPVOID lpContext);
  23. _pfn_EnumPixelFormatsCallback g_pfnEnumPixelFormatsCallback = NULL;
  24. int g_cD3DEnumPixelFormatsCallbacks = 0;
  25. /*++
  26. Hook this call so we can make sure that calling methods on the
  27. IDirect3DDevice3 interface is hooked.
  28. --*/
  29. HRESULT
  30. COMHOOK(IDirect3D3, CreateDevice)(
  31. PVOID pThis,
  32. REFCLSID rclsid,
  33. LPDIRECTDRAWSURFACE4 lpDDS,
  34. LPDIRECT3DDEVICE3* lplpD3DDevice,
  35. LPUNKNOWN /*lpUnkOuter*/
  36. )
  37. {
  38. HRESULT hReturn;
  39. _pfn_IDirect3D3_CreateDevice pfnOld =
  40. ORIGINAL_COM(IDirect3D3, CreateDevice, pThis);
  41. if (SUCCEEDED(hReturn = (*pfnOld)(
  42. pThis,
  43. rclsid,
  44. lpDDS,
  45. lplpD3DDevice,
  46. NULL)))
  47. {
  48. HookObject(
  49. NULL,
  50. IID_IDirect3DDevice3,
  51. (PVOID*)lplpD3DDevice,
  52. NULL,
  53. FALSE);
  54. }
  55. return hReturn;
  56. }
  57. /*++
  58. Restrict to returning at most 10 texture formats.
  59. --*/
  60. HRESULT
  61. CALLBACK
  62. EnumPixelFormatsCallback(
  63. LPDDPIXELFORMAT lpDDPixFmt,
  64. LPVOID lpContext
  65. )
  66. {
  67. // The app only supports up to 10 texture formats.
  68. if (++g_cD3DEnumPixelFormatsCallbacks >= 11)
  69. {
  70. return D3DENUMRET_CANCEL;
  71. }
  72. else
  73. {
  74. return g_pfnEnumPixelFormatsCallback(lpDDPixFmt, lpContext);
  75. }
  76. }
  77. /*++
  78. Call our private callback instead.
  79. --*/
  80. HRESULT
  81. COMHOOK(IDirect3DDevice3, EnumTextureFormats)(
  82. PVOID pThis,
  83. LPD3DENUMPIXELFORMATSCALLBACK lpd3dEnumPixelProc,
  84. LPVOID lpArg
  85. )
  86. {
  87. DPFN( eDbgLevelError, "it IS getting called");
  88. g_pfnEnumPixelFormatsCallback = lpd3dEnumPixelProc;
  89. _pfn_IDirect3DDevice3_EnumTextureFormats EnumTextureFormats = ORIGINAL_COM(IDirect3DDevice3, EnumTextureFormats, pThis);
  90. return EnumTextureFormats(pThis, EnumPixelFormatsCallback, lpArg);
  91. }
  92. /*++
  93. Register hooked functions
  94. --*/
  95. HOOK_BEGIN
  96. APIHOOK_ENTRY_DIRECTX_COMSERVER()
  97. COMHOOK_ENTRY(DirectDraw, IDirect3D3, CreateDevice, 8)
  98. COMHOOK_ENTRY(DirectDraw, IDirect3DDevice3, EnumTextureFormats, 8)
  99. HOOK_END
  100. IMPLEMENT_SHIM_END