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.

131 lines
2.7 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. ThreeDJungleTrain.cpp
  5. Abstract:
  6. ThreedJungleTrain created a new DirectSound object every time
  7. it entered the "3D Train Ride" part of the game, and destroyed
  8. the object every time it went to a "2D interior" part. It was
  9. keeping and using an old pointer to the first DirectSound object
  10. it ever created even after it was destroyed. It was only luck that
  11. Win9x would continue to allocate new objects in the same place that
  12. allowed the game to work. This shim never allows the release of
  13. that first object and then continues to hand back pointers to the
  14. first object when new objects are requested so that the old pointer
  15. the app uses always points to a (the) valid DirectSound object.
  16. History:
  17. 08/09/2000 t-adams Created
  18. --*/
  19. #include "precomp.h"
  20. IMPLEMENT_SHIM_BEGIN(ThreeDJungleTrain)
  21. #include "ShimHookMacro.h"
  22. APIHOOK_ENUM_BEGIN
  23. APIHOOK_ENUM_ENTRY(DirectSoundCreate)
  24. APIHOOK_ENUM_END
  25. // Pointer to the first DirectSound object created.
  26. LPDIRECTSOUND g_pDS = NULL;
  27. /*++
  28. Hook DirectSoundCreate to remeber the first DS object created and afterwards
  29. return a pointer to that object when new DS objects are requested.
  30. --*/
  31. HRESULT
  32. APIHOOK(DirectSoundCreate)(
  33. LPCGUID lpcGuid,
  34. LPDIRECTSOUND *ppDS,
  35. LPUNKNOWN pUnkOuter)
  36. {
  37. HRESULT hRet = DS_OK;
  38. // Check to see if we have an old DS yet.
  39. if( NULL == g_pDS ) {
  40. // If not, then get a new DS
  41. hRet = ORIGINAL_API(DirectSoundCreate)(lpcGuid, ppDS, pUnkOuter);
  42. if ( DS_OK == hRet )
  43. {
  44. HookObject(
  45. NULL,
  46. IID_IDirectSound,
  47. (PVOID*)ppDS,
  48. NULL,
  49. FALSE);
  50. g_pDS = *ppDS;
  51. }
  52. goto exit;
  53. } else {
  54. // If so, then give back the old DS
  55. *ppDS = g_pDS;
  56. goto exit;
  57. }
  58. exit:
  59. return hRet;
  60. }
  61. /*++
  62. Hook IDirectSound_Release so DirectSound object isn't released.
  63. --*/
  64. HRESULT
  65. COMHOOK(IDirectSound, Release)(
  66. PVOID pThis)
  67. {
  68. // Don't release.
  69. return 0;
  70. }
  71. /*++
  72. Release global DirectSound object.
  73. --*/
  74. BOOL
  75. NOTIFY_FUNCTION(
  76. DWORD fdwReason)
  77. {
  78. if (fdwReason == DLL_PROCESS_DETACH) {
  79. if (NULL != g_pDS) {
  80. ORIGINAL_COM(IDirectSound, Release, g_pDS)(g_pDS);
  81. }
  82. }
  83. return TRUE;
  84. }
  85. /*++
  86. Register hooked functions
  87. --*/
  88. HOOK_BEGIN
  89. APIHOOK_ENTRY(DSOUND.DLL, DirectSoundCreate)
  90. COMHOOK_ENTRY(DirectSound, IDirectSound, Release, 2)
  91. CALL_NOTIFY_FUNCTION
  92. HOOK_END
  93. IMPLEMENT_SHIM_END