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.

206 lines
4.1 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. Ultima9.cpp
  5. Abstract:
  6. Clean up bad ddraw CreateSurface caps.
  7. Notes:
  8. This is an app specific shim.
  9. History:
  10. 03/04/2000 linstev Created
  11. --*/
  12. #include "precomp.h"
  13. IMPLEMENT_SHIM_BEGIN(Ultima9)
  14. #include "ShimHookMacro.h"
  15. APIHOOK_ENUM_BEGIN
  16. APIHOOK_ENUM_ENTRY_DIRECTX_COMSERVER()
  17. APIHOOK_ENUM_END
  18. IMPLEMENT_DIRECTX_COMSERVER_HOOKS()
  19. VOID FixCaps(LPDDSURFACEDESC lpDDSurfaceDesc)
  20. {
  21. if (lpDDSurfaceDesc->dwFlags & DDSD_CAPS)
  22. {
  23. if ((lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_COMPLEX) &&
  24. (lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_MIPMAP))
  25. {
  26. lpDDSurfaceDesc->ddsCaps.dwCaps |= DDSCAPS_TEXTURE;
  27. }
  28. }
  29. }
  30. VOID FixCaps2(LPDDSURFACEDESC2 lpDDSurfaceDesc)
  31. {
  32. if (lpDDSurfaceDesc->dwFlags & DDSD_CAPS)
  33. {
  34. if ((lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_COMPLEX) &&
  35. (lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_MIPMAP))
  36. {
  37. lpDDSurfaceDesc->ddsCaps.dwCaps |= DDSCAPS_TEXTURE;
  38. }
  39. }
  40. }
  41. /*++
  42. Hook create surface and fix parameters
  43. --*/
  44. HRESULT
  45. COMHOOK(IDirectDraw, CreateSurface)(
  46. PVOID pThis,
  47. LPDDSURFACEDESC lpDDSurfaceDesc,
  48. LPDIRECTDRAWSURFACE* lplpDDSurface,
  49. IUnknown* pUnkOuter
  50. )
  51. {
  52. FixCaps(lpDDSurfaceDesc);
  53. _pfn_IDirectDraw_CreateSurface pfnOld =
  54. ORIGINAL_COM(IDirectDraw, CreateSurface, pThis);
  55. HRESULT hRet = (*pfnOld)(
  56. pThis,
  57. lpDDSurfaceDesc,
  58. lplpDDSurface,
  59. pUnkOuter);
  60. return hRet;
  61. }
  62. /*++
  63. Hook create surface and fix parameters
  64. --*/
  65. HRESULT
  66. COMHOOK(IDirectDraw2, CreateSurface)(
  67. PVOID pThis,
  68. LPDDSURFACEDESC lpDDSurfaceDesc,
  69. LPDIRECTDRAWSURFACE* lplpDDSurface,
  70. IUnknown* pUnkOuter
  71. )
  72. {
  73. FixCaps(lpDDSurfaceDesc);
  74. _pfn_IDirectDraw2_CreateSurface pfnOld =
  75. ORIGINAL_COM(IDirectDraw2, CreateSurface, pThis);
  76. HRESULT hRet = (*pfnOld)(
  77. pThis,
  78. lpDDSurfaceDesc,
  79. lplpDDSurface,
  80. pUnkOuter);
  81. return hRet;
  82. }
  83. /*++
  84. Hook create surface and fix parameters
  85. --*/
  86. HRESULT
  87. COMHOOK(IDirectDraw4, CreateSurface)(
  88. PVOID pThis,
  89. LPDDSURFACEDESC2 lpDDSurfaceDesc,
  90. LPDIRECTDRAWSURFACE* lplpDDSurface,
  91. IUnknown* pUnkOuter
  92. )
  93. {
  94. FixCaps2(lpDDSurfaceDesc);
  95. _pfn_IDirectDraw4_CreateSurface pfnOld =
  96. ORIGINAL_COM(IDirectDraw4, CreateSurface, pThis);
  97. Retry:
  98. HRESULT hRet = (*pfnOld)(
  99. pThis,
  100. lpDDSurfaceDesc,
  101. lplpDDSurface,
  102. pUnkOuter);
  103. if ((hRet == DDERR_INVALIDCAPS) && (lpDDSurfaceDesc->ddsCaps.dwCaps2))
  104. {
  105. lpDDSurfaceDesc->ddsCaps.dwCaps2 = 0;
  106. lpDDSurfaceDesc->ddsCaps.dwCaps3 = 0;
  107. lpDDSurfaceDesc->ddsCaps.dwCaps4 = 0;
  108. goto Retry;
  109. }
  110. return hRet;
  111. }
  112. /*++
  113. Hook create surface and fix parameters
  114. --*/
  115. HRESULT
  116. COMHOOK(IDirectDraw7, CreateSurface)(
  117. PVOID pThis,
  118. LPDDSURFACEDESC2 lpDDSurfaceDesc,
  119. LPDIRECTDRAWSURFACE* lplpDDSurface,
  120. IUnknown* pUnkOuter
  121. )
  122. {
  123. FixCaps2(lpDDSurfaceDesc);
  124. _pfn_IDirectDraw7_CreateSurface pfnOld =
  125. ORIGINAL_COM(IDirectDraw7, CreateSurface, pThis);
  126. Retry:
  127. HRESULT hRet = (*pfnOld)(
  128. pThis,
  129. lpDDSurfaceDesc,
  130. lplpDDSurface,
  131. pUnkOuter);
  132. if ((hRet == DDERR_INVALIDCAPS) && (lpDDSurfaceDesc->ddsCaps.dwCaps2))
  133. {
  134. lpDDSurfaceDesc->ddsCaps.dwCaps2 = 0;
  135. lpDDSurfaceDesc->ddsCaps.dwCaps3 = 0;
  136. lpDDSurfaceDesc->ddsCaps.dwCaps4 = 0;
  137. goto Retry;
  138. }
  139. return hRet;
  140. }
  141. /*++
  142. Register hooked functions
  143. --*/
  144. HOOK_BEGIN
  145. APIHOOK_ENTRY_DIRECTX_COMSERVER()
  146. COMHOOK_ENTRY(DirectDraw, IDirectDraw, CreateSurface, 6)
  147. COMHOOK_ENTRY(DirectDraw, IDirectDraw2, CreateSurface, 6)
  148. COMHOOK_ENTRY(DirectDraw, IDirectDraw4, CreateSurface, 6)
  149. COMHOOK_ENTRY(DirectDraw, IDirectDraw7, CreateSurface, 6)
  150. HOOK_END
  151. IMPLEMENT_SHIM_END