forked from aqrit/ddwrapper
-
Notifications
You must be signed in to change notification settings - Fork 1
/
dllmain.cpp
430 lines (401 loc) · 14.1 KB
/
dllmain.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
#include "header.h"
#define D3DERR_COMMAND_UNPARSED 0x88760BB8
typedef HRESULT (__stdcall* DllGetClassObject_t )( REFCLSID, REFIID, LPVOID* );
typedef HRESULT (__stdcall* DirectDrawCreate_t )( GUID*, LPDIRECTDRAW*, IUnknown* );
typedef HRESULT (__stdcall* DirectDrawCreateEx_t )( GUID*, LPVOID*, REFIID, IUnknown* );
typedef HRESULT (__stdcall* DirectDrawCreateClipper_t )( DWORD dwFlags, LPDIRECTDRAWCLIPPER FAR *lplpDDClipper, IUnknown FAR *pUnkOuter );
typedef HRESULT (__stdcall* DirectDrawEnumerateA_t )( LPDDENUMCALLBACK lpCallback, LPVOID lpContext );
typedef HRESULT (__stdcall* DirectDrawEnumerateW_t )( LPDDENUMCALLBACK lpCallback, LPVOID lpContext );
typedef HRESULT (__stdcall* DirectDrawEnumerateExA_t )( LPDDENUMCALLBACKEX lpCallback, LPVOID lpContext, DWORD dwFlags );
typedef HRESULT (__stdcall* DirectDrawEnumerateExW_t )( LPDDENUMCALLBACKEX lpCallback, LPVOID lpContext, DWORD dwFlags );
typedef HRESULT (__stdcall* D3DParseUnknownCommand_t )( LPVOID lpCmd, LPVOID *lpRetCmd );
typedef HRESULT (__stdcall* DllCanUnloadNow_t)();
//
// undocumented
typedef HRESULT (__stdcall* AcquireDDThreadLock_t )();
typedef HRESULT (__stdcall* ReleaseDDThreadLock_t )();
typedef DWORD (__stdcall* GetOLEThunkData_t )( DWORD index );
typedef DWORD (__stdcall* SetAppCompatData_t )( DWORD index, DWORD data );
typedef DWORD (__stdcall* CompleteCreateSysmemSurface_t )( DWORD );
typedef HRESULT (__stdcall* DDGetAttachedSurfaceLcl_t )( DWORD, DWORD, DWORD );
typedef HRESULT (__stdcall* DDInternalLock_t )( DWORD, DWORD );
typedef HRESULT (__stdcall* DDInternalUnlock_t )( DWORD );
typedef HRESULT (__stdcall* DSoundHelp_t )( DWORD, DWORD, DWORD );
typedef HRESULT (__stdcall* GetDDSurfaceLocal_t )( DWORD, DWORD, DWORD );
typedef HRESULT (__stdcall* GetSurfaceFromDC_t )( DWORD, DWORD, DWORD );
typedef HRESULT (__stdcall* RegisterSpecialCase_t )( DWORD, DWORD, DWORD, DWORD );
HMODULE hRealDDraw;
DirectDrawCreate_t pDirectDrawCreate;
DirectDrawCreateEx_t pDirectDrawCreateEx;
DirectDrawCreateClipper_t pDirectDrawCreateClipper;
DirectDrawEnumerateA_t pDirectDrawEnumerateA;
DirectDrawEnumerateExA_t pDirectDrawEnumerateExA;
DirectDrawEnumerateExW_t pDirectDrawEnumerateExW;
DirectDrawEnumerateW_t pDirectDrawEnumerateW;
D3DParseUnknownCommand_t pD3DParseUnknownCommand;
DllGetClassObject_t pDllGetClassObject;
DllCanUnloadNow_t pDllCanUnloadNow;
AcquireDDThreadLock_t pAcquireDDThreadLock;
ReleaseDDThreadLock_t pReleaseDDThreadLock;
GetOLEThunkData_t pGetOLEThunkData;
SetAppCompatData_t pSetAppCompatData;
CompleteCreateSysmemSurface_t pCompleteCreateSysmemSurface;
DDGetAttachedSurfaceLcl_t pDDGetAttachedSurfaceLcl;
DDInternalLock_t pDDInternalLock;
DDInternalUnlock_t pDDInternalUnlock;
DSoundHelp_t pDSoundHelp;
GetDDSurfaceLocal_t pGetDDSurfaceLocal;
GetSurfaceFromDC_t pGetSurfaceFromDC;
RegisterSpecialCase_t pRegisterSpecialCase;
BOOL WINAPI DllMain(HINSTANCE hDll, DWORD dwReason, LPVOID lpvReserved)
{
PROLOGUE;
UNREFERENCED_PARAMETER( lpvReserved );
switch(dwReason)
{
case DLL_PROCESS_ATTACH:
{
InitializeCriticalSection(&cs);
GetSystemInfo(&sSysInfo);
// load ddraw.dll from system32 dir
char szPath[ MAX_PATH ];
if( GetSystemDirectory( szPath, MAX_PATH - 10 ))
{
strcat( szPath, "\\ddraw.dll" );
TRACE( szPath );
hRealDDraw = LoadLibrary( szPath );
if( hRealDDraw == hDll ) // this dll is NOT the real dll...
{
FreeLibrary( hRealDDraw );
}
else
{
pDirectDrawCreate = (DirectDrawCreate_t) GetProcAddress( hRealDDraw, "DirectDrawCreate");
pDirectDrawCreateEx = (DirectDrawCreateEx_t) GetProcAddress( hRealDDraw, "DirectDrawCreateEx");
pDirectDrawCreateClipper = (DirectDrawCreateClipper_t) GetProcAddress( hRealDDraw, "DirectDrawCreateClipper");
pDirectDrawEnumerateA = (DirectDrawEnumerateA_t) GetProcAddress( hRealDDraw, "DirectDrawEnumerateA");
pDirectDrawEnumerateExA = (DirectDrawEnumerateExA_t) GetProcAddress( hRealDDraw, "DirectDrawEnumerateExA");
//pDirectDrawEnumerateExW = (DirectDrawEnumerateExW_t) GetProcAddress( hRealDDraw, "DirectDrawEnumerateExW");
//pDirectDrawEnumerateW = (DirectDrawEnumerateW_t) GetProcAddress( hRealDDraw, "DirectDrawEnumerateW");
pD3DParseUnknownCommand = (D3DParseUnknownCommand_t) GetProcAddress( hRealDDraw, "D3DParseUnknownCommand");
pDllGetClassObject = (DllGetClassObject_t) GetProcAddress( hRealDDraw, "DllGetClassObject");
pDllCanUnloadNow = (DllCanUnloadNow_t) GetProcAddress( hRealDDraw, "DllCanUnloadNow");
pAcquireDDThreadLock = (AcquireDDThreadLock_t) GetProcAddress( hRealDDraw, "AcquireDDThreadLock");
pReleaseDDThreadLock = (ReleaseDDThreadLock_t) GetProcAddress( hRealDDraw, "ReleaseDDThreadLock");
//pGetOLEThunkData = (GetOLEThunkData_t) GetProcAddress( hRealDDraw, "GetOLEThunkData");
//pSetAppCompatData = (SetAppCompatData_t) GetProcAddress( hRealDDraw, "SetAppCompatData");
pCompleteCreateSysmemSurface = (CompleteCreateSysmemSurface_t) GetProcAddress( hRealDDraw, "CompleteCreateSysmemSurface");
//pDDGetAttachedSurfaceLcl = (DDGetAttachedSurfaceLcl_t) GetProcAddress( hRealDDraw, "DDGetAttachedSurfaceLcl");
pDDInternalLock = (DDInternalLock_t) GetProcAddress( hRealDDraw, "DDInternalLock");
pDDInternalUnlock = (DDInternalUnlock_t) GetProcAddress( hRealDDraw, "DDInternalUnlock");
//pDSoundHelp = (DSoundHelp_t) GetProcAddress( hRealDDraw, "DSoundHelp" );
//pGetDDSurfaceLocal = (GetDDSurfaceLocal_t) GetProcAddress( hRealDDraw, "GetDDSurfaceLocal" );
//pGetSurfaceFromDC = (GetSurfaceFromDC_t) GetProcAddress( hRealDDraw, "GetSurfaceFromDC" );
//pRegisterSpecialCase = (RegisterSpecialCase_t) GetProcAddress( hRealDDraw, "RegisterSpecialCase" );
}
}
GetModuleFileName(hDll, szPath, MAX_PATH);
char *last = strrchr(szPath, '.');
if (last) {
strcpy(last, ".ini");
dx::NoBuffer = GetPrivateProfileInt("PAL-DDRAW", "NoBuffer", 0, szPath);
dx::UseFlip = GetPrivateProfileInt("PAL-DDRAW", "UseFlip", 0, szPath);
dx::UseThrottle = GetPrivateProfileInt("PAL-DDRAW", "UseThrottle", 0, szPath);
dx::BPP = GetPrivateProfileInt("PAL-DDRAW", "BPP", 0, szPath);
}
break;
}
case DLL_THREAD_ATTACH:
TRACE( "DLL_THREAD_ATTACH" );
break;
case DLL_THREAD_DETACH:
TRACE( "DLL_THREAD_DETACH" );
break;
case DLL_PROCESS_DETACH:
TRACE( "DLL_PROCESS_DETACH" );
FreeLibrary( hRealDDraw );
break;
}
EPILOGUE( TRUE );
}
HRESULT __stdcall DirectDrawCreate( GUID* lpGUID, LPDIRECTDRAW* lplpDD, IUnknown* pUnkOuter )
{
PROLOGUE;
HRESULT hResult = E_NOTIMPL;
if( pDirectDrawCreate != NULL )
{
hResult = pDirectDrawCreate( lpGUID, lplpDD, pUnkOuter );
INFO("DirectDrawCreate GUID %08X -> DD %08X\n", lpGUID, *lplpDD);
if( SUCCEEDED( hResult) )
{
Wrap( NULL, iid_to_vtbl( IID_IDirectDraw ), (void**)lplpDD );
}
}
EPILOGUE( hResult );
}
HRESULT __stdcall DirectDrawCreateEx( GUID* lpGUID, LPVOID* lplpDD, REFIID iid, IUnknown* pUnkOuter )
{
PROLOGUE;
HRESULT hResult = E_NOTIMPL;
if( pDirectDrawCreateEx != NULL )
{
hResult = pDirectDrawCreateEx( lpGUID, lplpDD, iid, pUnkOuter );
INFO("DirectDrawCreateEx GUID %08X -> DD %08X\n", lpGUID, *lplpDD);
if( SUCCEEDED( hResult) )
{
Wrap( NULL, iid_to_vtbl( iid ), (void**)lplpDD );
}
}
EPILOGUE( hResult );
}
HRESULT __stdcall DirectDrawCreateClipper( DWORD dwFlags, LPDIRECTDRAWCLIPPER FAR *lplpDDClipper, IUnknown FAR *pUnkOuter )
{
PROLOGUE;
HRESULT hResult = E_NOTIMPL;
if( pDirectDrawCreateClipper != NULL )
{
hResult = pDirectDrawCreateClipper( dwFlags, lplpDDClipper, pUnkOuter );
INFO("DirectDrawCreateClipper dwFlags %08X -> %08X\n", dwFlags, *lplpDDClipper);
if( SUCCEEDED( hResult) )
{
Wrap( NULL, iid_to_vtbl( IID_IDirectDrawClipper ), (void**)lplpDDClipper );
}
}
EPILOGUE( hResult );
}
// do we care what the CLSID is ?? or do we just look at riid...
// CLSID_DirectDraw, CLSID_DirectDraw7, CLSID_DirectDrawClipper
HRESULT __stdcall DllGetClassObject( REFCLSID rclsid, REFIID riid, LPVOID* ppvObject )
{
PROLOGUE;
HRESULT hResult = E_NOTIMPL;
if( pDllGetClassObject != NULL )
{
hResult = pDllGetClassObject( rclsid, riid, ppvObject );
if( SUCCEEDED( hResult) )
{
Wrap( NULL, iid_to_vtbl( riid ), ppvObject );
}
}
EPILOGUE( hResult );
}
////////////////////////////////////////////
//
// Every thing below here is just pass-thru
//
////////////////////////////////////////////
// returns void / no return value
HRESULT __stdcall AcquireDDThreadLock()
{
PROLOGUE;
HRESULT hResult = E_NOTIMPL;
if( pAcquireDDThreadLock != NULL )
{
hResult = pAcquireDDThreadLock();
}
INFO("AcquireDDThreadLock() = %08X\n", hResult);
EPILOGUE( hResult );
}
// returns void / no return value
HRESULT __stdcall ReleaseDDThreadLock()
{
PROLOGUE;
HRESULT hResult = E_NOTIMPL;
if( pReleaseDDThreadLock != NULL )
{
hResult = pReleaseDDThreadLock();
}
INFO("ReleaseDDThreadLock() = %08X\n", hResult);
EPILOGUE( hResult );
}
HRESULT __stdcall DirectDrawEnumerateA( LPDDENUMCALLBACK lpCallback, LPVOID lpContext )
{
PROLOGUE;
HRESULT hResult = E_NOTIMPL;
if( pDirectDrawEnumerateA != NULL )
{
hResult = pDirectDrawEnumerateA( lpCallback, lpContext );
}
EPILOGUE( hResult );
}
HRESULT __stdcall DirectDrawEnumerateW( LPDDENUMCALLBACK lpCallback, LPVOID lpContext )
{
PROLOGUE;
HRESULT hResult = E_NOTIMPL;
if( pDirectDrawEnumerateW != NULL )
{
hResult = pDirectDrawEnumerateW( lpCallback, lpContext );
}
EPILOGUE( hResult );
}
HRESULT __stdcall DirectDrawEnumerateExA( LPDDENUMCALLBACKEX lpCallback, LPVOID lpContext, DWORD dwFlags )
{
PROLOGUE;
HRESULT hResult = E_NOTIMPL;
if( pDirectDrawEnumerateExA != NULL )
{
hResult = pDirectDrawEnumerateExA( lpCallback, lpContext, dwFlags );
}
EPILOGUE( hResult );
}
HRESULT __stdcall DirectDrawEnumerateExW( LPDDENUMCALLBACKEX lpCallback, LPVOID lpContext, DWORD dwFlags )
{
PROLOGUE;
HRESULT hResult = E_NOTIMPL;
if( pDirectDrawEnumerateExW != NULL )
{
hResult = pDirectDrawEnumerateExW( lpCallback, lpContext, dwFlags );
}
EPILOGUE( hResult );
}
HRESULT __stdcall D3DParseUnknownCommand( LPVOID lpCmd, LPVOID *lpRetCmd )
{
PROLOGUE;
HRESULT hResult = D3DERR_COMMAND_UNPARSED;
if( pD3DParseUnknownCommand != NULL )
{
hResult = pD3DParseUnknownCommand( lpCmd, lpRetCmd );
}
INFO("D3DParseUnknownCommand(%08X, %08X) = %08X\n", lpCmd, lpRetCmd, hResult);
EPILOGUE( hResult );
}
HRESULT __stdcall DllCanUnloadNow()
{
PROLOGUE;
HRESULT hResult = S_FALSE;
if( pDllCanUnloadNow != NULL )
{
hResult = pDllCanUnloadNow();
}
EPILOGUE( hResult );
}
DWORD __stdcall GetOLEThunkData( DWORD index )
{
// switch( index )
// {
// case 1: return _dwLastFrameRate;
// case 2: return _lpDriverObjectList;
// case 3: return _lpAttachedProcesses;
// case 4: return 0; // does nothing?
// case 5: return _CheckExclusiveMode;
// case 6: return 0; // ReleaseExclusiveModeMutex
// }
PROLOGUE;
DWORD dwResult = 0;
if( pGetOLEThunkData != NULL )
{
dwResult = pGetOLEThunkData( index );
}
EPILOGUE( dwResult );
}
DWORD __stdcall SetAppCompatData( DWORD index, DWORD data )
{
// switch( index )
// {
// case 1: _g_bDWMOffForPrimaryLock = 0; return 0;
// case 2: _g_bDWMOffForPrimaryBlt = 0; return 0;
// case 3: _g_bForceFullscreenSprite = 1; return 0;
// case 4: _g_bForceBltToPrimary = 1; return 0;
// case 5: _g_crShadowBuf = data; return 0;
// case 6: _g_bDWMOffForFullscreen = 0; return 0;
// }
PROLOGUE;
DWORD dwResult = 0;
if( pSetAppCompatData != NULL )
{
dwResult = pSetAppCompatData( index, data );
}
EPILOGUE( dwResult );
}
HRESULT __stdcall CompleteCreateSysmemSurface( DWORD arg1 )
{
PROLOGUE;
DWORD dwResult = 0;
if( pCompleteCreateSysmemSurface != NULL )
{
dwResult = pCompleteCreateSysmemSurface( arg1 );
}
EPILOGUE( dwResult );
}
HRESULT __stdcall DDGetAttachedSurfaceLcl( DWORD arg1, DWORD arg2, DWORD arg3 )
{
PROLOGUE;
HRESULT hResult = E_NOTIMPL;
if( pDDGetAttachedSurfaceLcl != NULL )
{
hResult = pDDGetAttachedSurfaceLcl( arg1, arg2, arg3 );
}
EPILOGUE( hResult );
}
HRESULT __stdcall DDInternalLock( DWORD arg1, DWORD arg2 )
{
PROLOGUE;
HRESULT hResult = E_NOTIMPL;
if( pDDInternalLock != NULL )
{
hResult = pDDInternalLock( arg1, arg2 );
}
INFO("DDInternalLock(%08X, %08X) = %08X\n", arg1, arg2, hResult);
EPILOGUE( hResult );
}
HRESULT __stdcall DDInternalUnlock( DWORD arg1 )
{
PROLOGUE;
HRESULT hResult = E_NOTIMPL;
if( pDDInternalUnlock != NULL )
{
hResult = pDDInternalUnlock( arg1 );
}
INFO("DDInternalUnlock(%08X) = %08X\n", arg1, hResult);
EPILOGUE( hResult );
}
/*
If SetCooperativeLevel is called once in a process, a binding is established between the process and the window.
If it is called again in the same process with a different non-null window handle, it returns the DDERR_HWNDALREADYSET
error value. Some applications may receive this error value when DirectSound(R) specifies a different window handle than
DirectDraw(R)they should specify the same, top-level application window handle.
*/
HRESULT __stdcall DSoundHelp( DWORD arg1, DWORD arg2, DWORD arg3 )
{
// _internalSetAppHWnd( 0, arg1, 0, 0, arg2, arg3 );
PROLOGUE;
HRESULT hResult = E_NOTIMPL;
if( pDSoundHelp != NULL )
{
hResult = pDSoundHelp( arg1, arg2, arg3 );
}
EPILOGUE( hResult );
}
// assume HRESULT...
HRESULT __stdcall GetDDSurfaceLocal( DWORD arg1, DWORD arg2, DWORD arg3 )
{
PROLOGUE;
HRESULT hResult = E_NOTIMPL;
if( pGetDDSurfaceLocal != NULL )
{
hResult = pGetDDSurfaceLocal( arg1, arg2, arg3 );
}
EPILOGUE( hResult );
}
// assume HRESULT...
HRESULT __stdcall GetSurfaceFromDC_export( DWORD arg1, DWORD arg2, DWORD arg3 )
{
PROLOGUE;
HRESULT hResult = E_NOTIMPL;
if( pGetSurfaceFromDC != NULL )
{
hResult = pGetSurfaceFromDC( arg1, arg2, arg3 );
}
EPILOGUE( hResult );
}
// setup for HEL BLT ???
HRESULT __stdcall RegisterSpecialCase( DWORD arg1, DWORD arg2, DWORD arg3, DWORD arg4 )
{
PROLOGUE;
HRESULT hResult = E_NOTIMPL;
if( pRegisterSpecialCase != NULL )
{
hResult = pRegisterSpecialCase( arg1, arg2, arg3, arg4 );
}
EPILOGUE( hResult );
}