-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmisc.cpp
More file actions
379 lines (328 loc) · 14.7 KB
/
Copy pathmisc.cpp
File metadata and controls
379 lines (328 loc) · 14.7 KB
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
// Misc.cpp
//
#include <dsound.h>
#include <ddraw.h>
#include <stdio.h>
#include <stdlib.h>
#include "def.h"
#pragma warning (disable : 4996)
// Global Variables
HINSTANCE g_hInstance;
int g_lastSprite = 0;
extern BOOL g_bFullScreen;
extern int g_mouseType;
extern char g_CDPath[MAX_PATH];
//Initalize HInstance.
void InitHInstance(HINSTANCE hInstance)
{
g_hInstance = hInstance;
}
void OutputDebug(const char *pMessage)
{
#ifdef _DEBUG
OutputDebugStringA(pMessage);
#endif
}
void LoadString(UINT nID, char *pBuffer, int lgBuffer)
{
LoadStringA(g_hInstance, nID, pBuffer, lgBuffer);
}
void ChangeSprite(int sprite)
{
HCURSOR hCursor = nullptr;
if ( g_mouseType == MOUSETYPEGRA ) return;
if ( g_lastSprite == sprite ) return;
if ( sprite == SPRITE_ARROW ) hCursor = LoadCursorA(g_hInstance, "IDC_ARROW");
if ( sprite == SPRITE_POINTER ) hCursor = LoadCursorA(g_hInstance, "IDC_POINTER");
if ( sprite == SPRITE_MAP ) hCursor = LoadCursorA(g_hInstance, "IDC_MAP");
if ( sprite == SPRITE_ARROWU ) hCursor = LoadCursorA(g_hInstance, "IDC_ARROWU");
if ( sprite == SPRITE_ARROWD ) hCursor = LoadCursorA(g_hInstance, "IDC_ARROWD");
if ( sprite == SPRITE_ARROWL ) hCursor = LoadCursorA(g_hInstance, "IDC_ARROWL");
if ( sprite == SPRITE_ARROWR ) hCursor = LoadCursorA(g_hInstance, "IDC_ARROWR");
if ( sprite == SPRITE_ARROWUL ) hCursor = LoadCursorA(g_hInstance, "IDC_ARROWUL");
if ( sprite == SPRITE_ARROWUR ) hCursor = LoadCursorA(g_hInstance, "IDC_ARROWUR");
if ( sprite == SPRITE_ARROWDL ) hCursor = LoadCursorA(g_hInstance, "IDC_ARROWDL");
if ( sprite == SPRITE_ARROWDR ) hCursor = LoadCursorA(g_hInstance, "IDC_ARROWDR");
if ( sprite == SPRITE_WAIT ) hCursor = LoadCursorA(g_hInstance, "IDC_WAIT");
if ( sprite == SPRITE_EMPTY ) hCursor = LoadCursorA(g_hInstance, "IDC_EMPTY");
if ( sprite == SPRITE_FILL ) hCursor = LoadCursorA(g_hInstance, "IDC_FILL");
SetCursor(hCursor);
g_lastSprite = sprite;
}
POINT ConvLongToPos(LPARAM lParam)
{
POINT pos;
pos.x = LOWORD(lParam);
pos.y = HIWORD(lParam);
return pos;
}
void InitRandom()
{
srand(1);
}
int Random(int min, int max)
{
long n;
n = rand();
n = min+(n%(max-min+1));
return (int)n;
}
/*
BOOL IntersectRect(RECT dst, RECT src1, RECT src2)
{
dst.left = max(src1.left, src2.left);
dst.right = min(src1.right, src2.right);
dst.top = max(src1.top, src2.top);
dst.bottom = min(src1.bottom, src2.bottom);
return IsRectEmpty(dst);
}
BOOL IsRectEmpty(RECT rect)
{
return rect.left >= rect.right || rect.top >= rect.bottom;
}
*/
void GetCurrentDir(char *pName, int lg)
{
int i;
strncpy(pName, _pgmptr, lg-1);
pName[lg-1] = 0;
lg = strlen(pName);
if ( lg == 0 ) return;
for ( i=0 ; i<lg ; i++ )
{
pName[i] = tolower(pName[i]);
}
while ( lg > 0 )
{
lg --;
if ( pName[lg] == '\\' )
{
pName[lg+1] = 0;
break;
}
}
if ( lg > 6 && strcmp(pName+lg-6, "\\debug\\") == 0 )
{
pName[lg-5] = 0; // ignore le dossier \debug !
}
}
int Speed(double speed, int max)
{
if (speed > 0.0)
{
return max((int)(speed * (double)max), 1);
}
if (speed < 0.0)
{
return min((int)(speed * (double)max), -1);
}
return 0;
}
void AddCDPath(char *pFilename)
{
char temp[MAX_PATH];
int lg;
BOOL bDaniel = FALSE;
if ( g_CDPath[0] == 0 ) return;
lg = strlen(g_CDPath);
if ( lg > 14 && strstr(g_CDPath+lg-14, "\\daniel\\blupi\\") )
{
bDaniel = TRUE;
}
#if _DEMO
strcpy(temp, g_CDPath);
strcat(temp, pFilename);
#else
if ( !bDaniel &&
(strstr(pFilename, "image08\\") == pFilename ||
strstr(pFilename, "data\\") == pFilename ||
strstr(pFilename, "image16\\") == pFilename ||
strstr(pFilename, "sound\\")) )
{
strcpy(temp, g_CDPath);
strcat(temp, "..\\");
strcat(temp, pFilename);
}
else
{
strcpy(temp, g_CDPath);
strcat(temp, pFilename);
}
#endif
strcpy(pFilename, temp);
}
void AddUserPath(char *pFilename)
{
char temp[MAX_PATH];
char* pText;
int pos;
char last;
SECURITY_ATTRIBUTES att;
if ( g_CDPath[0] != 0 ) return;
strcpy(temp, "c:\\Speedy_Blupi\\");
att.nLength = sizeof(SECURITY_ATTRIBUTES);
att.lpSecurityDescriptor = NULL;
att.bInheritHandle = FALSE;
CreateDirectoryA(temp, &att);
pText = strstr(pFilename, "\\");
if ( pText != NULL )
{
pos = strlen(temp)+(pText-pFilename)+1;
strcat(temp, pFilename);
last = temp[pos];
temp[pos] = 0;
CreateDirectoryA(temp, &att);
temp[pos] = last;
}
else
{
strcat(temp, pFilename);
}
strcpy(pFilename, temp);
}
void TraceErrorDD(HRESULT hErr, const char *sFile, int nLine)
{
char dderr[256];
char err[1024];
switch (hErr)
{
case DD_OK : sprintf(dderr, "DD_OK"); break;
case DDERR_ALREADYINITIALIZED : sprintf(dderr, "DDERR_ALREADYINITIALIZED"); break;
case DDERR_CANNOTATTACHSURFACE : sprintf(dderr, "DDERR_CANNOTATTACHSURFACE"); break;
case DDERR_CANNOTDETACHSURFACE : sprintf(dderr, "DDERR_CANNOTDETACHSURFACE"); break;
case DDERR_CURRENTLYNOTAVAIL : sprintf(dderr, "DDERR_CURRENTLYNOTAVAIL"); break;
case DDERR_EXCEPTION : sprintf(dderr, "DDERR_EXCEPTION"); break;
case DDERR_GENERIC : sprintf(dderr, "DDERR_GENERIC"); break;
case DDERR_HEIGHTALIGN : sprintf(dderr, "DDERR_HEIGHTALIGN"); break;
case DDERR_INCOMPATIBLEPRIMARY : sprintf(dderr, "DDERR_INCOMPATIBLEPRIMARY"); break;
case DDERR_INVALIDCAPS : sprintf(dderr, "DDERR_INVALIDCAPS"); break;
case DDERR_INVALIDCLIPLIST : sprintf(dderr, "DDERR_INVALIDCLIPLIST"); break;
case DDERR_INVALIDMODE : sprintf(dderr, "DDERR_INVALIDMODE"); break;
case DDERR_INVALIDOBJECT : sprintf(dderr, "DDERR_INVALIDOBJECT"); break;
case DDERR_INVALIDPARAMS : sprintf(dderr, "DDERR_INVALIDPARAMS"); break;
case DDERR_INVALIDPIXELFORMAT : sprintf(dderr, "DDERR_INVALIDPIXELFORMAT"); break;
case DDERR_INVALIDRECT : sprintf(dderr, "DDERR_INVALIDRECT"); break;
case DDERR_LOCKEDSURFACES : sprintf(dderr, "DDERR_LOCKEDSURFACES"); break;
case DDERR_NO3D : sprintf(dderr, "DDERR_NO3D"); break;
case DDERR_NOALPHAHW : sprintf(dderr, "DDERR_NOALPHAHW"); break;
case DDERR_NOCLIPLIST : sprintf(dderr, "DDERR_NOCLIPLIST"); break;
case DDERR_NOCOLORCONVHW : sprintf(dderr, "DDERR_NOCOLORCONVHW"); break;
case DDERR_NOCOOPERATIVELEVELSET : sprintf(dderr, "DDERR_NOCOOPERATIVELEVELSET"); break;
case DDERR_NOCOLORKEY : sprintf(dderr, "DDERR_NOCOLORKEY"); break;
case DDERR_NOCOLORKEYHW : sprintf(dderr, "DDERR_NOCOLORKEYHW"); break;
case DDERR_NODIRECTDRAWSUPPORT : sprintf(dderr, "DDERR_NODIRECTDRAWSUPPORT"); break;
case DDERR_NOEXCLUSIVEMODE : sprintf(dderr, "DDERR_NOEXCLUSIVEMODE"); break;
case DDERR_NOFLIPHW : sprintf(dderr, "DDERR_NOFLIPHW"); break;
case DDERR_NOGDI : sprintf(dderr, "DDERR_NOGDI"); break;
case DDERR_NOMIRRORHW : sprintf(dderr, "DDERR_NOMIRRORHW"); break;
case DDERR_NOTFOUND : sprintf(dderr, "DDERR_NOTFOUND"); break;
case DDERR_NOOVERLAYHW : sprintf(dderr, "DDERR_NOOVERLAYHW"); break;
case DDERR_NORASTEROPHW : sprintf(dderr, "DDERR_NORASTEROPHW"); break;
case DDERR_NOROTATIONHW : sprintf(dderr, "DDERR_NOROTATIONHW"); break;
case DDERR_NOSTRETCHHW : sprintf(dderr, "DDERR_NOSTRETCHHW"); break;
case DDERR_NOT4BITCOLOR : sprintf(dderr, "DDERR_NOT4BITCOLOR"); break;
case DDERR_NOT4BITCOLORINDEX : sprintf(dderr, "DDERR_NOT4BITCOLORINDEX"); break;
case DDERR_NOT8BITCOLOR : sprintf(dderr, "DDERR_NOT8BITCOLOR"); break;
case DDERR_NOTEXTUREHW : sprintf(dderr, "DDERR_NOTEXTUREHW"); break;
case DDERR_NOVSYNCHW : sprintf(dderr, "DDERR_NOVSYNCHW"); break;
case DDERR_NOZBUFFERHW : sprintf(dderr, "DDERR_NOZBUFFERHW"); break;
case DDERR_NOZOVERLAYHW : sprintf(dderr, "DDERR_NOZOVERLAYHW"); break;
case DDERR_OUTOFCAPS : sprintf(dderr, "DDERR_OUTOFCAPS"); break;
case DDERR_OUTOFMEMORY : sprintf(dderr, "DDERR_OUTOFMEMORY"); break;
case DDERR_OUTOFVIDEOMEMORY : sprintf(dderr, "DDERR_OUTOFVIDEOMEMORY"); break;
case DDERR_OVERLAYCANTCLIP : sprintf(dderr, "DDERR_OVERLAYCANTCLIP"); break;
case DDERR_OVERLAYCOLORKEYONLYONEACTIVE : sprintf(dderr, "DDERR_OVERLAYCOLORKEYONLYONEACTIVE"); break;
case DDERR_PALETTEBUSY : sprintf(dderr, "DDERR_PALETTEBUSY"); break;
case DDERR_COLORKEYNOTSET : sprintf(dderr, "DDERR_COLORKEYNOTSET"); break;
case DDERR_SURFACEALREADYATTACHED : sprintf(dderr, "DDERR_SURFACEALREADYATTACHED"); break;
case DDERR_SURFACEALREADYDEPENDENT : sprintf(dderr, "DDERR_SURFACEALREADYDEPENDENT"); break;
case DDERR_SURFACEBUSY : sprintf(dderr, "DDERR_SURFACEBUSY"); break;
case DDERR_CANTLOCKSURFACE : sprintf(dderr, "DDERR_CANTLOCKSURFACE"); break;
case DDERR_SURFACEISOBSCURED : sprintf(dderr, "DDERR_SURFACEISOBSCURED"); break;
case DDERR_SURFACELOST : sprintf(dderr, "DDERR_SURFACELOST"); break;
case DDERR_SURFACENOTATTACHED : sprintf(dderr, "DDERR_SURFACENOTATTACHED"); break;
case DDERR_TOOBIGHEIGHT : sprintf(dderr, "DDERR_TOOBIGHEIGHT"); break;
case DDERR_TOOBIGSIZE : sprintf(dderr, "DDERR_TOOBIGSIZE"); break;
case DDERR_TOOBIGWIDTH : sprintf(dderr, "DDERR_TOOBIGWIDTH"); break;
case DDERR_UNSUPPORTED : sprintf(dderr, "DDERR_UNSUPPORTED"); break;
case DDERR_UNSUPPORTEDFORMAT : sprintf(dderr, "DDERR_UNSUPPORTEDFORMAT"); break;
case DDERR_UNSUPPORTEDMASK : sprintf(dderr, "DDERR_UNSUPPORTEDMASK"); break;
case DDERR_VERTICALBLANKINPROGRESS : sprintf(dderr, "DDERR_VERTICALBLANKINPROGRESS"); break;
case DDERR_WASSTILLDRAWING : sprintf(dderr, "DDERR_WASSTILLDRAWING"); break;
case DDERR_XALIGN : sprintf(dderr, "DDERR_XALIGN"); break;
case DDERR_INVALIDDIRECTDRAWGUID : sprintf(dderr, "DDERR_INVALIDDIRECTDRAWGUID"); break;
case DDERR_DIRECTDRAWALREADYCREATED : sprintf(dderr, "DDERR_DIRECTDRAWALREADYCREATED"); break;
case DDERR_NODIRECTDRAWHW : sprintf(dderr, "DDERR_NODIRECTDRAWHW"); break;
case DDERR_PRIMARYSURFACEALREADYEXISTS : sprintf(dderr, "DDERR_PRIMARYSURFACEALREADYEXISTS"); break;
case DDERR_NOEMULATION : sprintf(dderr, "DDERR_NOEMULATION"); break;
case DDERR_REGIONTOOSMALL : sprintf(dderr, "DDERR_REGIONTOOSMALL"); break;
case DDERR_CLIPPERISUSINGHWND : sprintf(dderr, "DDERR_CLIPPERISUSINGHWND"); break;
case DDERR_NOCLIPPERATTACHED : sprintf(dderr, "DDERR_NOCLIPPERATTACHED"); break;
case DDERR_NOHWND : sprintf(dderr, "DDERR_NOHWND"); break;
case DDERR_HWNDSUBCLASSED : sprintf(dderr, "DDERR_HWNDSUBCLASSED"); break;
case DDERR_HWNDALREADYSET : sprintf(dderr, "DDERR_HWNDALREADYSET"); break;
case DDERR_NOPALETTEATTACHED : sprintf(dderr, "DDERR_NOPALETTEATTACHED"); break;
case DDERR_NOPALETTEHW : sprintf(dderr, "DDERR_NOPALETTEHW"); break;
case DDERR_BLTFASTCANTCLIP : sprintf(dderr, "DDERR_BLTFASTCANTCLIP"); break;
case DDERR_NOBLTHW : sprintf(dderr, "DDERR_NOBLTHW"); break;
case DDERR_NODDROPSHW : sprintf(dderr, "DDERR_NODDROPSHW"); break;
case DDERR_OVERLAYNOTVISIBLE : sprintf(dderr, "DDERR_OVERLAYNOTVISIBLE"); break;
case DDERR_NOOVERLAYDEST : sprintf(dderr, "DDERR_NOOVERLAYDEST"); break;
case DDERR_INVALIDPOSITION : sprintf(dderr, "DDERR_INVALIDPOSITION"); break;
case DDERR_NOTAOVERLAYSURFACE : sprintf(dderr, "DDERR_NOTAOVERLAYSURFACE"); break;
case DDERR_EXCLUSIVEMODEALREADYSET : sprintf(dderr, "DDERR_EXCLUSIVEMODEALREADYSET"); break;
case DDERR_NOTFLIPPABLE : sprintf(dderr, "DDERR_NOTFLIPPABLE"); break;
case DDERR_CANTDUPLICATE : sprintf(dderr, "DDERR_CANTDUPLICATE"); break;
case DDERR_NOTLOCKED : sprintf(dderr, "DDERR_NOTLOCKED"); break;
case DDERR_CANTCREATEDC : sprintf(dderr, "DDERR_CANTCREATEDC"); break;
case DDERR_NODC : sprintf(dderr, "DDERR_NODC"); break;
case DDERR_WRONGMODE : sprintf(dderr, "DDERR_WRONGMODE"); break;
case DDERR_IMPLICITLYCREATED : sprintf(dderr, "DDERR_IMPLICITLYCREATED"); break;
case DDERR_NOTPALETTIZED : sprintf(dderr, "DDERR_NOTPALETTIZED"); break;
case DDERR_UNSUPPORTEDMODE : sprintf(dderr, "DDERR_UNSUPPORTEDMODE"); break;
case DDERR_NOMIPMAPHW : sprintf(dderr, "DDERR_NOMIPMAPHW"); break;
case DDERR_INVALIDSURFACETYPE : sprintf(dderr, "DDERR_INVALIDSURFACETYPE"); break;
case DDERR_DCALREADYCREATED : sprintf(dderr, "DDERR_DCALREADYCREATED"); break;
case DDERR_CANTPAGELOCK : sprintf(dderr, "DDERR_CANTPAGELOCK"); break;
case DDERR_CANTPAGEUNLOCK : sprintf(dderr, "DDERR_CANTPAGEUNLOCK"); break;
case DDERR_NOTPAGELOCKED : sprintf(dderr, "DDERR_NOTPAGELOCKED"); break;
case DDERR_NOTINITIALIZED : sprintf(dderr, "DDERR_NOTINITIALIZED"); break;
default : sprintf(dderr, "Unknown Error"); break;
}
sprintf(err, "DirectDraw Error %s in file %s at line %d\n", dderr, sFile, nLine);
OutputDebug(err);
}
//----------------------------------------------------------------------
//
// Function : TraceErrorDS()
//
// Purpose : Traces an error (DirectSound)
//
//----------------------------------------------------------------------
void TraceErrorDS(HRESULT hErr, const char *sFile, int nLine)
{
char dserr[256];
char err[1024];
switch (hErr)
{
case DS_OK : sprintf(dserr, "DD_OK"); break;
case DSERR_ALLOCATED : sprintf(dserr, "DSERR_ALLOCATED"); break;
case DSERR_CONTROLUNAVAIL : sprintf(dserr, "DSERR_CONTROLUNAVAIL"); break;
case DSERR_INVALIDPARAM : sprintf(dserr, "DSERR_INVALIDPARAM"); break;
case DSERR_INVALIDCALL : sprintf(dserr, "DSERR_INVALIDCALL"); break;
case DSERR_GENERIC : sprintf(dserr, "DSERR_GENERIC"); break;
case DSERR_PRIOLEVELNEEDED : sprintf(dserr, "DSERR_PRIOLEVELNEEDED"); break;
case DSERR_OUTOFMEMORY : sprintf(dserr, "DSERR_OUTOFMEMORY"); break;
case DSERR_BADFORMAT : sprintf(dserr, "DSERR_BADFORMAT"); break;
case DSERR_UNSUPPORTED : sprintf(dserr, "DSERR_UNSUPPORTED"); break;
case DSERR_NODRIVER : sprintf(dserr, "DSERR_NODRIVER"); break;
case DSERR_ALREADYINITIALIZED : sprintf(dserr, "DSERR_ALREADYINITIALIZED"); break;
case DSERR_NOAGGREGATION : sprintf(dserr, "DSERR_NOAGGREGATION"); break;
case DSERR_BUFFERLOST : sprintf(dserr, "DSERR_BUFFERLOST"); break;
case DSERR_OTHERAPPHASPRIO : sprintf(dserr, "DSERR_OTHERAPPHASPRIO"); break;
case DSERR_UNINITIALIZED : sprintf(dserr, "DSERR_UNINITIALIZED"); break;
default : sprintf(dserr, "Unknown Error"); break;
}
sprintf(err, "DirectSound Error %s in file %s at line %d\n", dserr, sFile, nLine);
OutputDebug(err);
}