Source code of Windows XP (NT5)
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.

143 lines
2.9 KiB

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