-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPlugins.cpp
More file actions
394 lines (359 loc) · 13.8 KB
/
Plugins.cpp
File metadata and controls
394 lines (359 loc) · 13.8 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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
/**************************************************************************
* *
* Copyright (C) 2000, Eclipse Productions *
* *
* Offical Source code of the Apollo Project. DO NOT DISTRIBUTE! Any *
* unauthorized distribution of these files in any way, shape, or form *
* is a direct infringement on the copyrights entitled to Eclipse *
* Productions and you will be prosecuted to the fullest extent of *
* the law. Have a nice day... ^_^ *
* *
*************************************************************************/
/**************************************************************************
*
* Revision History:
* Date: Comment:
* -----------------------------------------------------------------------
* 07-02-00 Initial Version (Andrew)
*
**************************************************************************/
/**************************************************************************
*
* Notes:
*
*
**************************************************************************/
#include <windows.h>
#include <windowsx.h>
#include <ddraw.h>
#include <commctrl.h> // For status window
#include <stdio.h>
#include <string.h>
#include <memory.h>
#include <stdlib.h>
#include <time.h>
#include <signal.h>
#include <math.h>
#include "WinMain.h"
#include "EmuMain.h"
#include "videodll.h"
#include "inputdll.h"
#include "audiodll.h"
#include "resource.h"
#define PATHSIZE 260
#define FILENAMESIZE 30
#define MAX_VIDEO 20
#define MAX_SOUND 20
#define MAX_INPUT 20
char dllpath[PATHSIZE];
char dllsearch[PATHSIZE];
int idxGFX = -1;
int idxSND = -1;
int idxINP = -1;
int maxGFX = 0;
int maxSND = 0;
int maxINP = 0;
char videoPlugins[MAX_VIDEO][FILENAMESIZE];
char soundPlugins[MAX_SOUND][FILENAMESIZE];
char inputPlugins[MAX_INPUT][FILENAMESIZE];
void CreateSearchMask () {
char path_buffer[_MAX_PATH], drive[_MAX_DRIVE], dir[_MAX_DIR];
char fname[_MAX_FNAME],ext[_MAX_EXT];
GetModuleFileName(NULL,path_buffer,sizeof(path_buffer));
_splitpath(path_buffer,drive,dir,fname,ext);
strcpy (dllpath, drive);
strcat (dllpath, dir);
strcat (dllpath, "Plugin\\"); // TR64, PJ64, 1964 compatible
strcpy (dllsearch, dllpath);
strcat (dllsearch, "*.dll");
Debug (0, "Looking for plugins as: %s", dllsearch);
}
bool CheckFilename (char *filename) {
WIN32_FIND_DATA finder;
HANDLE findHandle = FindFirstFile(dllsearch, &finder);
bool retVal = false;
if (findHandle != INVALID_HANDLE_VALUE) {
if (strcmp (filename, finder.cFileName) == 0)
retVal = true;
else
while (FindNextFile(findHandle, &finder)) {
if (strcmp (filename, finder.cFileName) == 0)
retVal = true;
}
FindClose (findHandle);
}
return retVal;
}
void AddPluginToDialog (char *filename, HWND hWnd) {
HMODULE hInstLib = NULL;
PLUGIN_INFO Plugin;
char buffer[260];
strcpy (buffer, dllpath);
strcat (buffer, filename);
hInstLib = LoadLibrary (buffer);
void (__cdecl* GetDllInfo)( PLUGIN_INFO * PluginInfo );
if (hInstLib) {
GetDllInfo = (void (__cdecl*)(PLUGIN_INFO *)) GetProcAddress(hInstLib, "GetDllInfo");
if (GetDllInfo) {
GetDllInfo (&Plugin);
switch (Plugin.Type) {
case PLUGIN_TYPE_RSP : // Type not supported...
break;
case PLUGIN_TYPE_GFX : // Graphics
if (((Plugin.Version == PLUGIN_GFX_VERSION) || (Plugin.Version == 0x0102))&& (maxGFX < MAX_VIDEO)) {
Debug (0, "%s is a Graphics Plugin...", filename);
SendMessage(GetDlgItem(hWnd, IDC_VIDEO_LIST), CB_INSERTSTRING, maxGFX, (LPARAM)Plugin.Name);
if (!strcmp(filename, RegSettings.vidDll)) {
SendMessage (GetDlgItem (hWnd, IDC_VIDEO_LIST), CB_SETCURSEL, (WPARAM)maxGFX, (LPARAM)0);
idxGFX = maxGFX;
}
strcpy (videoPlugins[maxGFX], filename);
maxGFX++;
} else {
Debug (0, "%s was Rejected Graphics Version %i", filename, Plugin.Version);
}
break;
case PLUGIN_TYPE_AUDIO : // Audio
if ((Plugin.Version == PLUGIN_SND_VERSION) && (maxSND < MAX_SOUND)) {
Debug (0, "%s is an Audio Plugin...", filename);
SendMessage(GetDlgItem(hWnd, IDC_AUDIO_LIST), CB_INSERTSTRING, maxSND, (LPARAM)Plugin.Name);
if (!strcmp(filename, RegSettings.sndDll)) {
SendMessage (GetDlgItem (hWnd, IDC_AUDIO_LIST), CB_SETCURSEL, (WPARAM)maxSND, (LPARAM)0);
idxSND = maxSND;
}
strcpy (soundPlugins[maxSND], filename);
maxSND++;
} else {
Debug (0, "%s was Rejected Sound Version %i", filename, Plugin.Version);
}
break;
case PLUGIN_TYPE_CONTROLLER : // Input
if ((Plugin.Version == PLUGIN_INP_VERSION) && (maxINP < MAX_INPUT)) { // We will accept all inputs right now
Debug (0, "%s is an Input Plugin...", filename);
SendMessage(GetDlgItem(hWnd, IDC_CONTROLLER_LIST), CB_INSERTSTRING, maxINP, (LPARAM)Plugin.Name);
if (!strcmp(filename, RegSettings.inpDll)) {
SendMessage (GetDlgItem (hWnd, IDC_CONTROLLER_LIST), CB_SETCURSEL, (WPARAM)maxINP, (LPARAM)0);
idxINP = maxINP;
}
strcpy (inputPlugins[maxINP], filename);
maxINP++;
} else {
Debug (0, "%s was Rejected Input Version %i", filename, Plugin.Version);
}
break;
default:
Debug (0, "%s is Unknown type %i...", filename, Plugin.Type);
}
}
FreeLibrary (hInstLib);
}
}
void QueryPlugins (HWND hWnd) {
char fuckyou[256];
WIN32_FIND_DATA finder;
SendMessage(GetDlgItem(hWnd,IDC_CONTROLLER_LIST), CB_RESETCONTENT, 0, 0);
SendMessage(GetDlgItem(hWnd,IDC_AUDIO_LIST), CB_RESETCONTENT, 0, 0);
SendMessage(GetDlgItem(hWnd,IDC_VIDEO_LIST), CB_RESETCONTENT, 0, 0);
maxINP = maxSND = maxGFX = 0;
HANDLE findHandle = FindFirstFile(dllsearch, &finder);
if (findHandle != INVALID_HANDLE_VALUE) {
strcpy (fuckyou, finder.cFileName);
AddPluginToDialog (fuckyou, hWnd);
while (FindNextFile(findHandle, &finder)) {
strcpy (fuckyou, finder.cFileName);
AddPluginToDialog (fuckyou, hWnd);
}
FindClose (findHandle);
}
if (idxGFX == -1) {
EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_VID_CONFIG), FALSE); EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_VID_TEST), FALSE); EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_VID_ABOUT), FALSE); EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_VID_APPLY), FALSE);
}
if (idxSND == -1) {
EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_AUD_CONFIG), FALSE); EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_AUD_TEST), FALSE); EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_AUD_ABOUT), FALSE); EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_AUD_APPLY), FALSE);
}
if (idxINP == -1) {
EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_CON_CONFIG), FALSE); EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_CON_TEST), FALSE); EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_CON_ABOUT), FALSE); EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_CON_APPLY), FALSE);
}
}
BOOL CALLBACK PluginProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
void LoadPlugins () {
bool LaunchConfig = false;
char buffer[260];
CreateSearchMask ();
if (CheckFilename (RegSettings.vidDll) == true) {
strcpy (buffer, dllpath);
strcat (buffer, RegSettings.vidDll);
gfxdll.Load (buffer);
gfxdll.Init();
Debug (0, "Graphics plugin %s INITIALIZED!", RegSettings.vidDll);
} else {
strcpy (RegSettings.vidDll, "");
Debug (1, "Failed to load Graphics plugin...");
LaunchConfig = true;
}
if (CheckFilename (RegSettings.sndDll) == true) {
strcpy (buffer, dllpath);
strcat (buffer, RegSettings.sndDll);
snddll.Load (buffer);
snddll.Init ();
Debug (0, "Audio DLL %s initialized!", RegSettings.sndDll);
} else {
strcpy (RegSettings.sndDll, "");
Debug (1, "Failed to load Audio plugin...");
LaunchConfig = true;
}
if (CheckFilename (RegSettings.inpDll) == true) {
strcpy (buffer, dllpath);
strcat (buffer, RegSettings.inpDll);
inpdll.Load (buffer);
inpdll.InitiateControllers (GhWnd, ContInfo);
Debug (0, "Input plugin %s INITIALIZED!", RegSettings.inpDll);
} else {
strcpy (RegSettings.inpDll, "");
Debug (1, "Failed to load Input plugin...");
LaunchConfig = true;
}
if (LaunchConfig)
DialogBox(GhInst,MAKEINTRESOURCE(IDD_PLUGINS),GhWnd,(DLGPROC)PluginProc);
}
void UnLoadPlugins () {
gfxdll.Close();
snddll.Close();
inpdll.Close();
}
BOOL CALLBACK PluginProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
int MenuId;
int index;
char buffer[240];
switch (message) {
case WM_INITDIALOG: {
idxGFX = -1;
idxSND = -1;
idxINP = -1;
QueryPlugins (hWnd);
break;
}
case WM_COMMAND: {
MenuId = LOWORD(wParam);
switch (MenuId) {
case IDC_CONTROLLER_LIST: {
int index = 0;
if (HIWORD (wParam) == CBN_SELCHANGE) {
index = SendMessage ((HWND)lParam, CB_GETCURSEL, 0, 0);
if (index != idxINP) {
EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_CON_CONFIG), FALSE); EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_CON_TEST), FALSE); EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_CON_ABOUT), FALSE); EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_CON_APPLY), TRUE);
} else {
EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_CON_CONFIG), TRUE); EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_CON_TEST), TRUE); EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_CON_ABOUT), TRUE); EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_CON_APPLY), FALSE);
}
}
} break;
case IDC_AUDIO_LIST: {
int index = 0;
if (HIWORD (wParam) == CBN_SELCHANGE) {
index = SendMessage ((HWND)lParam, CB_GETCURSEL, 0, 0);
if (index != idxSND) {
EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_AUD_CONFIG), FALSE); EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_AUD_TEST), FALSE); EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_AUD_ABOUT), FALSE); EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_AUD_APPLY), TRUE);
} else {
EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_AUD_CONFIG), TRUE); EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_AUD_TEST), TRUE); EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_AUD_ABOUT), TRUE); EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_AUD_APPLY), FALSE);
}
}
} break;
case IDC_VIDEO_LIST: {
int index = 0;
if (HIWORD (wParam) == CBN_SELCHANGE) {
index = SendMessage ((HWND)lParam, CB_GETCURSEL, 0, 0);
if (index != idxGFX) {
EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_VID_CONFIG), FALSE); EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_VID_TEST), FALSE); EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_VID_ABOUT), FALSE); EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_VID_APPLY), TRUE);
} else {
EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_VID_CONFIG), TRUE); EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_VID_TEST), TRUE); EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_VID_ABOUT), TRUE); EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_VID_APPLY), FALSE);
}
}
} break;
case IDCANCEL:
EndDialog(hWnd,0);
case IDOK:
case ID_APPLY_ALL:
case ID_PLUGIN_VID_APPLY:
index = SendMessage (GetDlgItem(hWnd, IDC_VIDEO_LIST), CB_GETCURSEL, 0, 0);
if ((index != CB_ERR) && (index != idxGFX)) {
EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_VID_CONFIG), TRUE); EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_VID_TEST), TRUE); EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_VID_ABOUT), TRUE); EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_VID_APPLY), FALSE);
idxGFX = index;
gfxdll.Close ();
strcpy (buffer, dllpath);
strcat (buffer, videoPlugins[index]);
gfxdll.Load (buffer);
gfxdll.Init();
strcpy (RegSettings.vidDll, videoPlugins[index]);
}
if (MenuId == ID_PLUGIN_VID_APPLY) break;
case ID_PLUGIN_AUD_APPLY:
index = SendMessage (GetDlgItem(hWnd, IDC_AUDIO_LIST), CB_GETCURSEL, 0, 0);
if ((index != CB_ERR) && (index != idxSND)) {
EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_AUD_CONFIG), TRUE); EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_AUD_TEST), TRUE); EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_AUD_ABOUT), TRUE); EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_AUD_APPLY), FALSE);
idxSND = index;
snddll.Close ();
strcpy (buffer, dllpath);
strcat (buffer, soundPlugins[index]);
snddll.Load (buffer);
snddll.Init();
strcpy (RegSettings.sndDll, soundPlugins[index]);
}
if (MenuId == ID_PLUGIN_AUD_APPLY) break;
case ID_PLUGIN_CON_APPLY:
index = SendMessage (GetDlgItem(hWnd, IDC_CONTROLLER_LIST), CB_GETCURSEL, 0, 0);
if ((index != CB_ERR) && (index != idxINP)) {
EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_CON_CONFIG), TRUE); EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_CON_TEST), TRUE); EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_CON_ABOUT), TRUE); EnableWindow (GetDlgItem(hWnd, ID_PLUGIN_CON_APPLY), FALSE);
idxINP = index;
inpdll.Close ();
strcpy (buffer, dllpath);
strcat (buffer, inputPlugins[index]);
inpdll.Load (buffer);
inpdll.InitiateControllers (GhWnd, ContInfo);
strcpy (RegSettings.inpDll, inputPlugins[index]);
}
if (MenuId == IDOK) {
GhWndPlugin = NULL;
EndDialog(hWnd, 0);
}
break;
case ID_PLUGIN_VID_CONFIG:
if (gfxdll.DllConfig)
gfxdll.DllConfig (GhWnd);
break;
case ID_PLUGIN_VID_TEST:
if (gfxdll.DllTest)
gfxdll.DllTest (GhWnd);
break;
case ID_PLUGIN_VID_ABOUT:
if (gfxdll.DllAbout)
gfxdll.DllAbout (GhWnd);
break;
case ID_PLUGIN_AUD_CONFIG:
if (snddll.DllConfig)
snddll.DllConfig (GhWnd);
break;
case ID_PLUGIN_AUD_TEST:
if (snddll.DllTest)
snddll.DllTest (GhWnd);
break;
case ID_PLUGIN_AUD_ABOUT:
if (snddll.DllAbout)
snddll.DllAbout (GhWnd);
break;
case ID_PLUGIN_CON_CONFIG:
if (inpdll.DllConfig)
inpdll.DllConfig (GhWnd);
break;
case ID_PLUGIN_CON_TEST:
if (inpdll.DllTest)
inpdll.DllTest (GhWnd);
break;
case ID_PLUGIN_CON_ABOUT:
if (inpdll.DllAbout)
inpdll.DllAbout (GhWnd);
break;
}
}
}
return FALSE;
}