Debian Codegraph @

Descent3/multi_dll_mgr.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/Main/multi_dll_mgr.cpp $
21 * $Revision: 82 $
22 * $Date: 10/03/01 12:45a $
23 * $Author: Kevin $
24 *
25 * Multi player DLL interface manager
26 *
27 * $Log: /DescentIII/Main/multi_dll_mgr.cpp $
28 *
29 * 82 10/03/01 12:45a Kevin
30 * Smaller version of pxo packets
31 *
32 * 81 3/26/00 10:29p Kevin
33 * MOD Downloader for 1.4 patch.
34 *
35 * 80 7/28/99 3:55p Kevin
36 * Mac!
37 *
38 * 79 7/12/99 4:15p Kevin
39 * Changed the way we determine if we should report stats or not in PXO
40 *
41 * 78 7/06/99 5:52p Kevin
42 * PXO & multiplayer fixes for the patch
43 *
44 * 77 5/12/99 2:24p Jeff
45 * Descent3 now has a setable temp directory for all temp files
46 *
47 * 76 5/10/99 10:22p Ardussi
48 * changes to compile on Mac
49 *
50 * 75 5/10/99 5:35p Kevin
51 * New command line options for heat and scoring API enhancements
52 *
53 * 74 5/08/99 11:25a Kevin
54 *
55 * 73 5/08/99 10:15a Kevin
56 * A bunch of heat scoring stuff
57 *
58 * 72 5/02/99 2:47p Jeff
59 * made linux friendly when extracting d3cs
60 *
61 * 71 4/28/99 2:24p Kevin
62 * added some heat scoring api code
63 *
64 * 70 4/25/99 5:02p Kevin
65 * Bunches of multiplayer UI improvements
66 *
67 * 69 4/25/99 12:18p Matt
68 * Use the briefing font instead of the HUD font for the PXO chat window.
69 *
70 * 68 4/24/99 11:58p Kevin
71 * Game info list (hit I in the pxo game list)
72 *
73 * 67 4/23/99 3:33p Kevin
74 * mission file/multiplayer mod keyword system
75 *
76 * 66 4/22/99 3:43p Kevin
77 * Training missions show controls on screen
78 *
79 * 65 4/19/99 10:23p Kevin
80 * A bunch of little things for the new demo
81 *
82 * 64 4/19/99 4:49p Jeff
83 * removed call to atexit to free DLL (Linux doesn't like that)
84 *
85 * 63 4/19/99 3:46a Jeff
86 * pass in variable for directplay in use for Linux
87 *
88 * 62 4/16/99 3:17p Kevin
89 * More mouselook support
90 *
91 * 61 4/16/99 11:56a Matt
92 * Changed directplay code to be "ifdef _WIN32" instead of "ifndef
93 * __LINUX__" so it will work on the Mac.
94 *
95 * 60 4/16/99 12:15a Jeff
96 * linux wants stdcall modifiers before parens, unlike windows
97 *
98 * 59 4/15/99 3:04a Jeff
99 * oops messed up some order of includes
100 *
101 * 58 4/15/99 1:41a Jeff
102 * changes for linux compile
103 *
104 * 57 4/14/99 4:19a Jeff
105 * more case mismatch fixes in #includes
106 *
107 * 56 4/14/99 2:51a Jeff
108 * fixed some case mismatched #includes
109 *
110 * 55 4/08/99 4:54p Kevin
111 * Display level warp dialog for multiplayer
112 *
113 * 54 4/08/99 3:41p Kevin
114 * Added some stuff for the scoring API. Not functional yet.
115 *
116 * 53 3/25/99 3:26p Kevin
117 * Made PXO games be based on your chat channel
118 *
119 * 52 3/17/99 4:08p Kevin
120 * Changed the way games appear and timeout in the game list.
121 *
122 * 51 3/05/99 1:24p Kevin
123 * Fixed Stupid Direct serial bug where it would try to join the game
124 * again and crash
125 *
126 * 50 2/15/99 7:49p Jeff
127 * new pilot file class and read/write system checked in...should be more
128 * robust than old
129 *
130 * 49 2/08/99 2:50p Kevin
131 * Locked PollUI to 30 FPS MAX
132 *
133 * 48 1/21/99 11:15p Jeff
134 * pulled out some structs and defines from header files and moved them
135 * into seperate header files so that multiplayer dlls don't require major
136 * game headers, just those new headers. Side effect is a shorter build
137 * time. Also cleaned up some header file #includes that weren't needed.
138 * This affected polymodel.h, object.h, player.h, vecmat.h, room.h,
139 * manage.h and multi.h
140 *
141 * 47 1/12/99 2:55p Jeff
142 * added/finished the waiting for player's to join dialog
143 *
144 * 46 1/11/99 12:29p Jeff
145 * changes made not to call the module library directly
146 *
147 * 45 1/07/99 11:51a Kevin
148 * Added support for joining servers on alternate ports and hosting behind
149 * a proxy/firewall
150 *
151 * 44 12/30/98 5:24p Kevin
152 * Added +name to specify a default pilot (for gamespy) fixed a gamespy
153 * bug, and improved the pxo dll game list screen
154 *
155 * 43 12/30/98 3:49p Kevin
156 * Moved multiplayer options out of DLL and into main app
157 *
158 * 42 12/30/98 12:15p Kevin
159 * Auto Mission Download system
160 *
161 * 41 12/23/98 6:38p Kevin
162 * All UDP data (except gamespy) now uses one (registered) port number
163 *
164 * 40 12/08/98 3:28p Jeff
165 * created and exported UI Checkbox wrappers
166 *
167 * 39 12/07/98 11:30a Kevin
168 * Added some features from the 1.1 demo patch
169 *
170 * 38 11/19/98 5:56p Jeff
171 * created Slider wrappers
172 *
173 * 37 10/29/98 7:00p Jeff
174 * create some new UI function wrappers
175 *
176 * 36 10/19/98 8:12p Jason
177 * flush all incoming buffers
178 *
179 * 35 10/16/98 11:55a Kevin
180 * Made dlls loadable in a hog
181 *
182 * 34 10/15/98 3:29p Kevin
183 * Fixed dlls to not require runtime debug libraries in release builds
184 *
185 * 33 10/13/98 5:19p Kevin
186 *
187 * 32 10/12/98 11:13a Kevin
188 * doh! changed mem_free to mem_free_sub
189 *
190 * 31 10/01/98 11:36a Kevin
191 * UI fixes and stuff
192 *
193 * 30 9/28/98 4:21p Kevin
194 * Redesigned game list menus
195 *
196 * 29 9/23/98 2:54p Kevin
197 * Saved multi config and changed UI to conform
198 *
199 * 28 9/22/98 2:29p Kevin
200 * moved ships allowed code out of dll and into main app. Also added
201 * powerup exclusions
202 *
203 * 27 9/21/98 11:19a Kevin
204 * check protocol before entering multiplayer screens
205 *
206 * 26 9/16/98 8:06p Jason
207 * got mastertracker working with the dedicated server
208 *
209 * 25 9/14/98 2:36p Kevin
210 * fixed some UI issues
211 *
212 * 24 9/09/98 12:41p Kevin
213 * Fixed up some UI issues
214 *
215 * 23 9/04/98 1:51p Kevin
216 * implemented asyncronous gethostbyname
217 *
218 * 22 9/02/98 6:54p Kevin
219 * Fixed general directplay support up, and got modem-modem working
220 *
221 * 21 8/31/98 10:14a Kevin
222 * Misc. multi-UI fixes
223 *
224 * 20 8/27/98 5:03p Kevin
225 * Prettied up multiplayer screens and fixed some bugs.
226 *
227 * 19 8/25/98 6:33p Kevin
228 * pxo
229 *
230 * 18 8/24/98 5:04p Kevin
231 * Made msn files have the option to not be playable in multiplayer
232 *
233 * 17 8/24/98 10:55a Kevin
234 * new directplay stuff
235 *
236 * 16 8/19/98 11:49a Kevin
237 * Got DirectPlay IPX working, and localized connection DLLs
238 *
239 * 15 8/15/98 5:16p Matt
240 * Added new Base_directory variable. Got rid of D3_LOCAL check and
241 * 'local directory' registry variable.
242 *
243 * 14 8/07/98 12:40p Jeff
244 * added some functions
245 *
246 * 13 7/21/98 1:49p Kevin
247 * IPX support and peer-peer option for multi
248 *
249 * 12 7/20/98 2:34p Kevin
250 * Re-wrote the DLL wrapper, to allow for better expandability
251 *
252 * 9 6/24/98 6:40p Kevin
253 * Added help to main dll menu
254 *
255 * 8 6/24/98 3:24p Kevin
256 * Updated PXO screens with chat, etc.
257 *
258 * 7 6/18/98 5:37p Kevin
259 *
260 * 6 6/18/98 4:49p Kevin
261 * Updated multiplayer menus
262 *
263 * 5 6/05/98 2:16p Jeff
264 * Changes made so Dynamic loading of DLLs done through module library
265 *
266 * 4 6/01/98 11:56a Kevin
267 * Fixed lame listbox bug
268 *
269 * 3 6/01/98 10:09a Kevin
270 * Added DLL connection interface and auto update DLL
271 *
272 * 2 5/18/98 12:16p Kevin
273 * Initial version
274 *
275 * 1 5/18/98 12:07p Kevin
276 *
277 * $NoKeywords: $
278 */
279 #include "ui.h"
280 #include "newui.h"
281 #include "game.h"
282 #include "gamefont.h"
283 #include "multi.h"
284 #include "multi_client.h"
285 #include "manage.h"
286 #include "Mission.h"
287 #include "pilot.h"
288 #include "pstypes.h"
289 #include "pserror.h"
290 #include "descent.h"
291 #include "room.h"
292 #include "object.h"
293 #include "terrain.h"
294 #include "player.h"
295 #include "mono.h"
296 #include "hud.h"
297 #include "Inventory.h"
298 #include "multi_server.h"
299 #include "multi_ui.h"
300 #include "ship.h"
301 #include "soundload.h"
302 #include "spew.h"
303 #include "DllWrappers.h"
304 #include "appdatabase.h"
305 #include "module.h"
306 #include "localization.h"
307 #include "stringtable.h"
308 #include "dedicated_server.h"
309 #include "multi_save_settings.h"
310 #include "multi_dll_mgr.h"
311 #include "mission_download.h"
312 #include "mem.h"
313 #include "args.h"
314 // #define USE_DIRECTPLAY
315
316 #ifdef USE_DIRECTPLAY
317 #include "directplay.h"
318 #endif
319
320 void *callback = NULL;
321 module MultiDLLHandle = {NULL};
322 int SearchForLocalGamesTCP(uint32_t ask, uint16_t port);
323 int SearchForGamesPXO(uint32_t ask, uint16_t port);
324 extern uint8_t NewUIWindow_alpha;
325 extern void DoScreenshot();
326 extern void UpdateAndPackGameList(void);
327 extern bool Multi_Gamelist_changed;
328 int CheckMissionForScript(char *mission, char *script, int dedicated_server_num_teams);
329 void ShowNetgameInfo(network_game *game);
330 // The exported DLL function call prototypes
331 #if defined(POSIX)
332 typedef void DLLFUNCCALL (*DLLMultiCall_fp)(int eventnum);
333 typedef void DLLFUNCCALL (*DLLMultiScoreCall_fp)(int eventnum, void *data);
334 typedef void DLLFUNCCALL (*DLLMultiInit_fp)(int *api_fp);
335 typedef void DLLFUNCCALL (*DLLMultiClose_fp)();
336 #else
337 typedef void(DLLFUNCCALL *DLLMultiCall_fp)(int eventnum);
338 typedef void(DLLFUNCCALL *DLLMultiScoreCall_fp)(int eventnum, void *data);
339 typedef void(DLLFUNCCALL *DLLMultiInit_fp)(int *api_fp);
340 typedef void(DLLFUNCCALL *DLLMultiClose_fp)();
341 #endif
342 DLLMultiScoreCall_fp DLLMultiScoreCall = NULL;
343 DLLMultiCall_fp DLLMultiCall = NULL;
344 DLLMultiInit_fp DLLMultiInit = NULL;
345 DLLMultiClose_fp DLLMultiClose = NULL;
346 // dllmultiiInfo DLLMultiInfo;
347 // The DLL needs these too.
348 #define MAXTEXTITEMS 100
349 #define MAXNEWWINDOWS 5
350 #define MAXNEWGAMEWINDOWS 5
351 #define MAXUIBUTTONS 20
352 #define MAXUITEXTS 20
353 #define MAXEDITS 20
354 #define MAXLISTS 20
355 #define MAXHOTSPOTS 20
356 #define MAXCONSOLES 5
357 #define MAXPARENTS 5
358 NewUIMessageBox messageb;
359 // Stuff for the splash
360 UITextItem ti_msg("", UICOL_TEXT_NORMAL);
361 UITextItem ti_tmp("", UICOL_TEXT_NORMAL);
362 UITextItem ti_cancel_on("", UICOL_HOTSPOT_HI);
363 UITextItem ti_cancel_off("", UICOL_HOTSPOT_LO);
364 UIHotspot uih;
365 UIHotspot uihcancel;
366 UIText ti;
367 extern char HelpText1[];
368 extern char HelpText2[];
369 extern char HelpText3[];
370 extern char HelpText4[];
371 char Auto_login_name[MAX_AUTO_LOGIN_STUFF_LEN];
372 char Auto_login_pass[MAX_AUTO_LOGIN_STUFF_LEN];
373 char Auto_login_addr[MAX_AUTO_LOGIN_STUFF_LEN];
374 char Auto_login_port[MAX_AUTO_LOGIN_STUFF_LEN];
375 char Multi_conn_dll_name[_MAX_PATH * 2] = "";
376 char PXO_hosted_lobby_name[100] = "global";
377 bool Supports_score_api = false;
378 #ifdef USE_DIRECTPLAY
379 extern modem_list Modems_found[MAX_MODEMS];
380 extern int Num_modems_found;
381 #endif
382 #define DLL_BRIEFING_FONT 1
383 #define DLL_BIG_BRIEFING_FONT 2
384 extern uint16_t nw_ListenPort;
385 extern uint16_t PXOPort;
386
387 void GetMultiAPI(multi_api *api) {
388 // make the compiler happy
389 bool (*fp_PlayerIsShipAllowed)(int, int) = PlayerIsShipAllowed;
390 api->objs = (int *)Objects;
391 api->rooms = (int *)Rooms;
392 api->terrain = (int *)Terrain_seg;
393 api->players = (int *)Players;
394 api->netgame = (int *)&Netgame;
395 api->netplayers = (int *)&NetPlayers;
396 api->ships = (int *)Ships;
397 // Fill in function pointers here. The order here must match the order on the
398 // DLL side (netcon/includes/mdllinit.h)
399
400 api->fp[0] = (int *)SetUITextItemText;
401 api->fp[1] = (int *)NewUIWindowCreate;
402 api->fp[2] = (int *)NewUIWindowDestroy;
403 api->fp[3] = (int *)NewUIWindowOpen;
404 api->fp[4] = (int *)NewUIWindowClose;
405 api->fp[5] = (int *)TextCreate;
406 api->fp[6] = (int *)EditCreate;
407 api->fp[7] = (int *)ButtonCreate;
408 api->fp[8] = (int *)ListCreate;
409 api->fp[9] = (int *)ListRemoveAll;
410 api->fp[10] = (int *)ListAddItem;
411 api->fp[11] = (int *)ListRemoveItem;
412 api->fp[12] = (int *)ListSelectItem;
413 api->fp[13] = (int *)ListGetItem;
414 api->fp[14] = (int *)ListGetSelectedIndex;
415 api->fp[15] = (int *)EditSetText;
416 api->fp[16] = (int *)EditGetText;
417 api->fp[17] = (int *)DatabaseWrite;
418 api->fp[18] = (int *)DatabaseRead;
419 api->fp[19] = (int *)DoUI;
420 api->fp[20] = (int *)DoMessageBox;
421 api->fp[21] = (int *)DescentDefer;
422 api->fp[22] = (int *)MonoPrintf;
423 api->fp[23] = (int *)DestroyStringTable;
424 api->fp[24] = (int *)CreateStringTable;
425 api->fp[25] = (int *)NewUIGameWindowCreate;
426 api->fp[26] = (int *)NewUIGameWindowDestroy;
427 api->fp[27] = (int *)NewUIGameWindowOpen;
428 api->fp[28] = (int *)NewUIGameWindowClose;
429 api->fp[29] = (int *)SetScreenMode;
430 api->fp[30] = (int *)timer_GetTime;
431 api->fp[31] = (int *)TryToJoinServer;
432 api->fp[32] = (int *)MultiStartClient;
433 api->fp[33] = (int *)rend_GetRenderState;
434 api->fp[34] = (int *)LoadMission;
435 api->fp[35] = (int *)ddio_MakePath;
436 api->fp[36] = (int *)ddio_FindFileStart;
437 api->fp[37] = (int *)ddio_FindFileClose;
438 api->fp[38] = (int *)ddio_FindNextFile;
439 api->fp[39] = (int *)MultiStartServer;
440 api->fp[40] = (int *)ShowProgressScreen;
441 api->fp[41] = (int *)SearchForLocalGamesTCP;
442 api->fp[42] = (int *)nw_GetHostAddressFromNumbers;
443 api->fp[43] = (int *)NULL; // nw_GetProtocolType;
444 api->fp[44] = (int *)HotSpotCreate;
445 api->fp[45] = (int *)PollUI;
446 api->fp[46] = (int *)GetMissionName;
447 api->fp[47] = (int *)RemoveUITextItem;
448 api->fp[48] = (int *)CreateNewUITextItem;
449 api->fp[49] = (int *)mem_malloc_sub;
450 api->fp[50] = (int *)mem_free_sub;
451 api->fp[51] = (int *)CreateSplashScreen;
452 api->fp[52] = (int *)CloseSplashScreen;
453 api->fp[53] = (int *)UIConsoleGadgetCreate;
454 api->fp[54] = (int *)UIConsoleGadgetputs;
455 api->fp[55] = (int *)NewUIWindowSetFocusOnEditGadget;
456 api->fp[56] = (int *)OldEditCreate;
457 api->fp[57] = (int *)OldListCreate;
458 api->fp[58] = (int *)OldListRemoveAll;
459 api->fp[59] = (int *)OldListAddItem;
460 api->fp[60] = (int *)OldListRemoveItem;
461 api->fp[61] = (int *)OldListSelectItem;
462 api->fp[62] = (int *)OldListGetItem;
463 api->fp[63] = (int *)OldListGetSelectedIndex;
464 api->fp[64] = (int *)OldEditSetText;
465 api->fp[65] = (int *)OldEditGetText;
466 api->fp[66] = (int *)ToggleUICallback;
467 api->fp[67] = (int *)SearchForGamesPXO;
468 api->fp[68] = (int *)SetOldEditBufferLen;
469 api->fp[69] = (int *)NewUIWindowLoadBackgroundImage;
470 api->fp[70] = (int *)DeleteUIItem;
471 api->fp[71] = (int *)NULL; // was SearchForLocalGamesIPX
472 api->fp[72] = (int *)HotSpotSetStates;
473 api->fp[73] = (int *)PlayerSetShipPermission;
474 api->fp[74] = (int *)fp_PlayerIsShipAllowed;
475 #ifdef USE_DIRECTPLAY
476 api->fp[75] = (int *)dp_InitDirectPlay;
477 api->fp[76] = (int *)dp_ListDirectPlayGames;
478 api->fp[77] = (int *)dp_GetModemChoices;
479 #else
480 api->fp[75] = (int *)NULL;
481 api->fp[76] = (int *)NULL;
482 api->fp[77] = (int *)NULL;
483 #endif
484 api->fp[78] = (int *)DatabaseReadInt;
485 api->fp[79] = (int *)DatabaseWriteInt;
486 api->fp[80] = (int *)DoScreenshot;
487 api->fp[81] = (int *)IsMissionMultiPlayable;
488 api->fp[82] = (int *)grtext_GetTextLineWidth;
489 api->fp[83] = (int *)GadgetDestroy;
490 #ifdef USE_DIRECTPLAY
491 api->fp[84] = (int *)dp_StartGame;
492 api->fp[85] = (int *)dp_EndGame;
493 #else
494 api->fp[84] = (int *)NULL;
495 api->fp[85] = (int *)NULL;
496 #endif
497 api->fp[86] = (int *)nw_Asyncgethostbyname;
498 api->fp[87] = (int *)PrintDedicatedMessage;
499 api->fp[88] = (int *)nw_ReccomendPPS;
500 api->fp[89] = (int *)DoMultiAllowed;
501 api->fp[90] = (int *)MultiDoConfigSave;
502 api->fp[91] = (int *)MultiDoConfigLoad;
503 api->fp[92] = (int *)MultiLoadSettings;
504 api->fp[93] = (int *)nw_DoReceiveCallbacks;
505 api->fp[94] = (int *)nw_SendWithID;
506 api->fp[95] = (int *)nw_UnRegisterCallback;
507 api->fp[96] = (int *)nw_RegisterCallback;
508 api->fp[97] = (int *)msn_CheckGetMission;
509 api->fp[98] = (int *)MultiGameOptionsMenu;
510 api->fp[99] = (int *)mod_FreeModule;
511 api->fp[100] = (int *)mod_GetLastError;
512 api->fp[101] = (int *)mod_GetSymbol;
513 api->fp[102] = (int *)mod_LoadModule;
514 api->fp[103] = (int *)dCurrentPilotName;
515 api->fp[104] = (int *)UpdateAndPackGameList;
516 api->fp[105] = (int *)MultiLevelSelection;
517 api->fp[106] = (int *)DoPlayerMouselookCheck;
518 api->fp[107] = (int *)CheckMissionForScript;
519 api->fp[108] = (int *)ShowNetgameInfo;
520 api->fp[109] = (int *)GetRankIndex;
521 api->fp[110] = (int *)CheckGetD3M;
522
523 // Variable pointers
524 api->vp[0] = (int *)&Player_num;
525 api->vp[1] = (int *)Tracker_id;
526 api->vp[2] = (int *)&Game_is_master_tracker_game;
527 api->vp[3] = (int *)&Game_mode;
528 api->vp[4] = (int *)NULL; // Current_pilot; no longer a struct
529 api->vp[5] = (int *)Base_directory;
530 api->vp[6] = (int *)&MultiDLLGameStarting;
531 api->vp[7] = (int *)MTPilotinfo;
532 api->vp[8] = (int *)&Num_network_games_known;
533 api->vp[9] = (int *)&Network_games;
534 api->vp[10] = (int *)&NewUIWindow_alpha;
535 api->vp[11] = (int *)HelpText1;
536 api->vp[12] = (int *)HelpText2;
537 api->vp[13] = (int *)HelpText3;
538 api->vp[14] = (int *)HelpText4;
539 api->vp[15] = (int *)Auto_login_name;
540 api->vp[16] = (int *)Auto_login_pass;
541 api->vp[17] = (int *)Auto_login_addr;
542 api->vp[18] = (int *)Auto_login_port;
543 #ifdef USE_DIRECTPLAY
544 api->vp[19] = (int *)&Num_directplay_games;
545 api->vp[20] = (int *)Directplay_sessions;
546 api->vp[21] = (int *)&DP_active;
547 api->vp[22] = (int *)&Use_DirectPlay;
548 api->vp[23] = (int *)&Modems_found;
549 api->vp[24] = (int *)&Num_modems_found;
550 #else
551 static bool _dummyUse_DirectPlay = false;
552 api->vp[19] = (int *)NULL;
553 api->vp[20] = (int *)NULL;
554 api->vp[21] = (int *)NULL;
555 api->vp[22] = (int *)&_dummyUse_DirectPlay;
556 api->vp[23] = (int *)NULL;
557 api->vp[24] = (int *)NULL;
558 #endif
559 api->vp[25] = (int *)&Dedicated_server;
560 api->vp[26] = (int *)&TCP_active;
561 api->vp[27] = (int *)&IPX_active;
562 api->vp[28] = (int *)(size_t)nw_ListenPort;
563 api->vp[29] = (int *)&Multi_Gamelist_changed;
564 api->vp[30] = (int *)PXO_hosted_lobby_name;
565 api->vp[31] = (int *)&Supports_score_api;
566 api->vp[32] = (int *)(size_t)PXOPort;
567 // Jeff: Linux dies if you try to free a DLL/so on
568 // atexit, these should be freed during game sequencing
569 // anyway.
570 // atexit(FreeMultiDLL);
571 }
572 // Frees the dll if its in memory
573 void FreeMultiDLL() {
574 if (!MultiDLLHandle.handle)
575 return;
576 if (DLLMultiClose)
577 DLLMultiClose();
578 mod_FreeModule(&MultiDLLHandle);
579 // Try deleting the file now!
580 if (!ddio_DeleteFile(Multi_conn_dll_name)) {
581 mprintf(0, "Couldn't delete the tmp dll");
582 }
583 DLLMultiCall = NULL;
584 DLLMultiInit = NULL;
585 DLLMultiClose = NULL;
586 }
587 // Loads the Multi dll. Returns 1 on success, else 0 on failure
588 int LoadMultiDLL(const char *name) {
589 static int first = 1;
590 char lib_name[_MAX_PATH * 2];
591 char dll_name[_MAX_PATH * 2];
592 char tmp_dll_name[_MAX_PATH * 2];
593 char dll_path_name[_MAX_PATH * 2];
594 MultiFlushAllIncomingBuffers();
595
596 // Delete old dlls
597 if (MultiDLLHandle.handle)
598 FreeMultiDLL();
599
600 ddio_MakePath(dll_path_name, Base_directory, "online", "*.tmp", NULL);
601 ddio_DeleteFile(dll_path_name);
602 // Make the hog filename
603 ddio_MakePath(lib_name, Base_directory, "online", name, NULL);
604 strcat(lib_name, ".d3c");
605 // Make the dll filename
606 #if defined(WIN32)
607 snprintf(dll_name, sizeof(dll_name), "%s.dll", name);
608 #elif defined(MACOSX)
609 snprintf(dll_name, sizeof(dll_name), "%s.dylib", name);
610 #else
611 snprintf(dll_name, sizeof(dll_name), "%s.so", name);
612 #endif
613
614 // Open the hog file
615 if (!cf_OpenLibrary(lib_name)) {
616 ddio_MakePath(tmp_dll_name, Base_directory, "online", name, NULL);
617 strcat(tmp_dll_name, ".d3c");
618 Multi_conn_dll_name[0] = 0;
619 goto loaddll;
620 }
621 // get a temp file name
622 if (!ddio_GetTempFileName(Descent3_temp_directory, "d3c", tmp_dll_name)) {
623 return 0;
624 }
625 // Copy the DLL
626 // ddio_MakePath(dll_path_name,Base_directory,"online",tmp_dll_name,NULL);
627 if (!cf_CopyFile(tmp_dll_name, dll_name)) {
628 mprintf(0, "DLL copy failed!\n");
629 return 0;
630 }
631 strcpy(Multi_conn_dll_name, tmp_dll_name);
632 loaddll:
633
634 if (!mod_LoadModule(&MultiDLLHandle, tmp_dll_name)) {
635 int err = mod_GetLastError();
636 mprintf(0, "You are missing the DLL %s!\n", name);
637 return 0;
638 }
639
640 DLLMultiInit = (DLLMultiInit_fp)mod_GetSymbol(&MultiDLLHandle, "DLLMultiInit", 4);
641 if (!DLLMultiInit) {
642 int err = mod_GetLastError();
643 mprintf(0, "Couldn't get a handle to the dll function DLLMultiInit!\n");
644 Int3();
645 FreeMultiDLL();
646 return 0;
647 }
648 DLLMultiCall = (DLLMultiCall_fp)mod_GetSymbol(&MultiDLLHandle, "DLLMultiCall", 4);
649 if (!DLLMultiCall) {
650 int err = mod_GetLastError();
651 mprintf(0, "Couldn't get a handle to the dll function DLLMultiCall!\n");
652 Int3();
653 FreeMultiDLL();
654 return 0;
655 }
656 DLLMultiClose = (DLLMultiClose_fp)mod_GetSymbol(&MultiDLLHandle, "DLLMultiClose", 0);
657 if (!DLLMultiClose) {
658 int err = mod_GetLastError();
659 mprintf(0, "Couldn't get a handle to the dll function DLLMultiClose!\n");
660 Int3();
661 FreeMultiDLL();
662 return 0;
663 }
664
665 if (first) {
666 // Jeff: Linux dies if you try to free a DLL/so during atexit
667 // for some reason. The dll/so should be freed during
668 // game sequencing anyway.
669 // atexit (FreeMultiDLL);
670 first = 0;
671 }
672 void *api_fp;
673 api_fp = (void *)GetMultiAPI;
674
675 if (Auto_login_name[0]) {
676 Database->write("TrackerLogin", Auto_login_name, strlen(Auto_login_name) + 1);
677 }
678 if (Auto_login_pass[0]) {
679 Database->write("TrackerPassword", Auto_login_pass, strlen(Auto_login_pass) + 1);
680 }
681 if (!Dedicated_server) {
682 strcpy(PXO_hosted_lobby_name, "global");
683 }
684 DLLMultiInit((int *)api_fp);
685
686 if (Supports_score_api) {
687 DLLMultiScoreCall = (DLLMultiScoreCall_fp)mod_GetSymbol(&MultiDLLHandle, "DLLMultiScoreEvent", 8);
688
689 if (!DLLMultiScoreCall) {
690 int err = mod_GetLastError();
691 mprintf(0, "Couldn't get a handle to the dll function DLLMultiScoreCall!\n");
692 Int3();
693 Supports_score_api = false;
694 }
695 }
696 return 1;
697 }
698 // The chokepoint function to call the dll function
699 void CallMultiDLL(int eventnum) {
700 if (MultiDLLHandle.handle && DLLMultiCall)
701 DLLMultiCall(eventnum);
702 }
703 void SetUITextItemText(UITextItem *uit, char *newtext, uint32_t color) {
704 // This function is currently broken!
705 strcpy(uit->m_Text, newtext);
706 uit->set_color(color);
707 }
708 void *NewUIWindowCreate(int x, int y, int w, int h, int flags) {
709 NewUIWindow *newwin;
710 newwin = new NewUIWindow;
711 newwin->Create(x, y, w, h, flags);
712 return newwin;
713 }
714 void NewUIWindowDestroy(NewUIWindow *deswin) { deswin->Destroy(); }
715 void NewUIWindowOpen(NewUIWindow *deswin) { deswin->Open(); }
716 void NewUIWindowClose(NewUIWindow *deswin) { deswin->Close(); }
717 void *TextCreate(UIWindow *parentwin, UITextItem *textitem, int x, int y, int flags) {
718 UIText *newtext;
719 newtext = new UIText;
720 newtext->Create(parentwin, textitem, x, y, flags);
721 return newtext;
722 }
723 void TextSetTitle(UIText *text, UITextItem *textitem) { text->SetTitle(textitem); }
724 void *EditCreate(UIWindow *parentwin, int id, int x, int y, int w, int h, int flags) {
725 NewUIEdit *newedit;
726 newedit = new NewUIEdit;
727 newedit->Create(parentwin, id, x, y, w, h, flags);
728 return newedit;
729 }
730 void EditSetText(NewUIEdit *item, const char *newtext) { item->SetText(newtext); }
731 void EditGetText(NewUIEdit *item, char *buff, int len) { item->GetText(buff, len); }
732 void *ButtonCreate(UIWindow *parentwin, int id, UITextItem *titleitem, int x, int y, int w, int h, int flags) {
733 UIButton *newbutt;
734 newbutt = new UIButton;
735 newbutt->Create(parentwin, id, titleitem, x, y, w, h, flags);
736 return newbutt;
737 }
738 void *ListCreate(UIWindow *parentwin, int id, int x, int y, int w, int h, int flags) {
739 NewUIListBox *newlist;
740 newlist = new NewUIListBox;
741 newlist->Create(parentwin, id, x, y, w, h, flags);
742 newlist->SetSelectedColor(UICOL_LISTBOX_HI);
743 newlist->SetHiliteColor(UICOL_LISTBOX_HI);
744 return newlist;
745 }
746 void ListRemoveAll(UIListBox *item) { item->RemoveAll(); }
747 void ListAddItem(UIListBox *item, UITextItem *uitext) { item->AddItem(uitext); }
748 void ListRemoveItem(UIListBox *item, UITextItem *txtitem) { item->RemoveItem(txtitem); }
749 void ListSelectItem(UIListBox *item, UITextItem *txtitem) { item->SelectItem(txtitem); }
750 const char *ListGetItem(UIListBox *item, int index) {
751 UITextItem *ui_item;
752 ui_item = (UITextItem *)item->GetItem(index);
753 if (ui_item)
754 return ui_item->GetBuffer();
755 else {
756 mprintf(0, "No listbox item found for index %d\n", index);
757 return "";
758 }
759 }
760 int ListGetSelectedIndex(UIListBox *item) { return item->GetSelectedIndex(); }
761 void ListSetSelectedIndex(UIListBox *item, int index) { item->SetSelectedIndex(index); }
762 void DatabaseRead(const char *label, char *entry, int *entrylen) { Database->read(label, entry, entrylen); }
763 void DatabaseWrite(const char *label, const char *entry, int entrylen) { Database->write(label, entry, entrylen); }
764 void DatabaseReadInt(const char *label, int *val) {
765 Database->read_int(label, val);
766 mprintf(0, "Read int: %s:%d\n", label, *val);
767 }
768 void DatabaseWriteInt(const char *label, int val) {
769 mprintf(0, "Writing int: %s:%d\n", label, val);
770 Database->write(label, val);
771 }
772 void DescentDefer(void) { Descent->defer(); }
773 void *NewUIGameWindowCreate(int x, int y, int w, int h, int flags) {
774 NewUIGameWindow *newgamewin;
775 newgamewin = new NewUIGameWindow;
776 newgamewin->Create(x, y, w, h, flags);
777 return newgamewin;
778 }
779 void NewUIGameWindowDestroy(NewUIGameWindow *item) { item->Destroy(); }
780 void NewUIGameWindowOpen(NewUIGameWindow *item) { item->Open(); }
781 void NewUIGameWindowClose(NewUIGameWindow *item) { item->Close(); }
782 void *HotSpotCreate(UIWindow *parentwin, int id, int key, UIItem *txtitemoff, UIItem *txtitemon, int x, int y, int w,
783 int h, int flags) {
784 UIHotspot *newhs;
785 newhs = new UIHotspot;
786 if (newhs)
787 newhs->Create(parentwin, id, key, txtitemoff, txtitemon, x, y, w, h, flags);
788 return newhs;
789 }
790 void HotSpotSetStates(UIHotspot *hs, UIItem *texton, UIItem *textoff) { hs->SetStates(textoff, texton); }
791 void *CheckBoxCreate(UIWindow *parent, int id, UIItem *title, int x, int y, int w, int h, int flags) {
792 UICheckBox *newcb;
793 newcb = new UICheckBox;
794 if (newcb)
795 newcb->Create(parent, id, title, x, y, w, h, flags);
796 return newcb;
797 }
798 void CheckBoxSetCheck(UICheckBox *cb, bool state) { cb->SetCheck(state); }
799 bool CheckBoxIsChecked(UICheckBox *cb) { return cb->IsChecked(); }
800 float UI_LastPoll = 0l;
801 #define MIN_FRAMETIME .033
802 int PollUI(void) {
803 // this should poll UI_frame_result.
804 int result = -1;
805
806 ui_ShowCursor();
807
808 // Limit this to a fixed framerate
809 if (UI_LastPoll) {
810 if ((timer_GetTime() - UI_LastPoll) < MIN_FRAMETIME)
811 Sleep((timer_GetTime() - UI_LastPoll) * 1000);
812 }
813
814 UI_LastPoll = timer_GetTime();
815
816 Descent->defer();
817 DoUIFrame();
818 rend_Flip();
819 result = GetUIFrameResult();
820 if (result != -1) {
821 ui_HideCursor();
822 ui_Flush();
823 ddio_KeyFlush();
824 }
825 return result;
826 }
827 void *CreateNewUITextItem(const char *newtext, uint32_t color, int font) {
828 UITextItem *new_text_item;
829 if (font == -1) {
830 new_text_item = new UITextItem(newtext);
831 } else {
832 switch (font) {
833 case DLL_BRIEFING_FONT:
834 new_text_item = new UITextItem(BRIEFING_FONT, newtext);
835 break;
836 case DLL_BIG_BRIEFING_FONT:
837 new_text_item = new UITextItem(BIG_BRIEFING_FONT, newtext);
838 break;
839 default:
840 new_text_item = new UITextItem(BRIEFING_FONT, newtext);
841 }
842 }
843 if (new_text_item)
844 new_text_item->set_color(color);
845 return new_text_item;
846 }
847 void RemoveUITextItem(void *item) {
848 UITextItem *old_text_item = (UITextItem *)item;
849 delete old_text_item;
850 }
851 void *CreateNewUIBmpItem(int handle, uint8_t alpha) {
852 UIBitmapItem *new_bmp_item;
853 new_bmp_item = new UIBitmapItem(handle, alpha);
854 return new_bmp_item;
855 }
856 int GetUIItemWidth(void *item) {
857 UIItem *i = (UIItem *)item;
858 return i->width();
859 }
860 int GetUIItemHeight(void *item) {
861 UIItem *i = (UIItem *)item;
862 return i->height();
863 }
864 void RemoveUIBmpItem(void *item) {
865 UIBitmapItem *old_bmp_item = (UIBitmapItem *)item;
866 delete old_bmp_item;
867 }
868 void NewUIMessageBoxCreate(int x, int y, int w, int flags) { messageb.Create(x, y, w, flags); }
869 void NewUIMessageBoxDestroy() {}
870 void NewUIMessageBoxOpen() { messageb.Open(); }
871 void NewUIMessageBoxClose() {}
872 static bool splash_screen_up = false;
873 void CreateSplashScreen(const char *msg, int usecancel) {
874 if (splash_screen_up)
875 return;
876 splash_screen_up = true;
877 ti_cancel_on = UITextItem(TXT_CANCEL, UICOL_HOTSPOT_HI);
878 ti_cancel_off = UITextItem(TXT_CANCEL, UICOL_HOTSPOT_LO);
879 ti_msg = UITextItem(msg);
880 messageb.Create(0, 0, 384, UIF_CENTER);
881 ti.Create(&messageb, &ti_msg, 20, 50, UIF_CENTER);
882
883 if (usecancel) {
884 uihcancel.Create(&messageb, 99, KEY_ESC, &ti_cancel_off, &ti_cancel_on, 1, 75, 100, 15, UIF_CENTER);
885 }
886 messageb.Open();
887 }
888 void CloseSplashScreen(void) {
889 if (splash_screen_up) {
890 messageb.Close();
891 messageb.Destroy();
892 splash_screen_up = false;
893 } else
894 return;
895 }
896 void *UIConsoleGadgetCreate(UIWindow *parentid, int id, int x, int y, int font, int cols, int rows, int flags) {
897 UIConsoleGadget *newconsole;
898 newconsole = new UIConsoleGadget;
899 newconsole->Create(parentid, id, x, y, BRIEFING_FONT, cols, rows, flags);
900 return newconsole;
901 }
902 void UIConsoleGadgetputs(UIConsoleGadget *item, const char *str) {
903 uint8_t r = 0;
904 uint8_t g = 230;
905 uint8_t b = 0;
906 if (*str == 1) {
907 str++;
908 r = *str;
909 str++;
910 g = *str;
911 str++;
912 b = *str;
913 str++;
914 }
915 item->puts(GR_RGB(r, g, b), str);
916 }
917 void NewUIWindowSetFocusOnEditGadget(UIEdit *item, UIWindow *parent) { item->Activate(); }
918 void *OldListCreate(UIWindow *parentitem, int id, int x, int y, int w, int h, int flags) {
919 UIListBox *newoldlist;
920 newoldlist = new UIListBox;
921 newoldlist->Create(parentitem, id, x, y, w, h, flags);
922 newoldlist->SetSelectedColor(UICOL_LISTBOX_HI);
923 newoldlist->SetHiliteColor(UICOL_LISTBOX_HI);
924 return newoldlist;
925 }
926 void OldListRemoveAll(UIListBox *item) { item->RemoveAll(); }
927 void OldListAddItem(UIListBox *item, UITextItem *uitext) { item->AddItem(uitext); }
928 void OldListRemoveItem(UIListBox *item, UITextItem *txtitem) { item->RemoveItem(txtitem); }
929 void OldListSelectItem(UIListBox *item, UITextItem *txtitem) { item->SelectItem(txtitem); }
930 const char *OldListGetItem(UIListBox *item, int index) {
931 UITextItem *ti = (UITextItem *)item->GetItem(index);
932 if (ti)
933 return ti->GetBuffer();
934 else {
935 mprintf(0, "No listbox item found for index %d\n", index);
936 return "";
937 }
938 }
939 int OldListGetSelectedIndex(UIListBox *item) { return item->GetSelectedIndex(); }
940 void *OldEditCreate(UIWindow *parentitem, int id, int x, int y, int w, int h, int flags) {
941 UIEdit *newoldedit;
942 newoldedit = new UIEdit;
943 newoldedit->Create(parentitem, id, x, y, w, h, flags);
944 return newoldedit;
945 }
946 void OldEditSetText(UIEdit *item, const char *newtext) { item->SetText(newtext); }
947 void OldEditGetText(UIEdit *item, char *buff, int len) { item->GetText(buff, len); }
948 static void (*DLLInit_old_ui_callback)() = NULL;
949 void ToggleUICallback(int state) {
950
951 if (state == 0) {
952 if (DLLInit_old_ui_callback == NULL) {
953 DLLInit_old_ui_callback = GetUICallback();
954 SetUICallback(NULL);
955 }
956 } else {
957 if (DLLInit_old_ui_callback != NULL) {
958 SetUICallback(DLLInit_old_ui_callback);
959 DLLInit_old_ui_callback = NULL;
960 }
961 }
962 }
963 void SetOldEditBufferLen(UIEdit *item, int len) { item->SetBufferLen(len); }
964 void NewUIWindowLoadBackgroundImage(NewUIWindow *item, const char *image_name) {
965 item->LoadBackgroundImage(image_name);
966 }
967 void DeleteUIItem(void *delitem) { delete delitem; } // !!! FIXME: this needs to change, but this deletes a lot of different things...
968 void GadgetDestroy(UIGadget *item) { item->Destroy(); }
969 void *SliderCreate(UIWindow *parent, int id, int x, int y, int flags) {
970 NewUISlider *slid;
971 slid = new NewUISlider;
972 slid->Create(parent, id, x, y, flags);
973 return (void *)slid;
974 }
975 void SliderSetRange(UISlider *slider, int range) { slider->SetRange(range); }
976 int SliderGetRange(UISlider *slider) { return slider->GetRange(); }
977 void SliderSetPos(UISlider *slider, int pos) { slider->SetPos(pos); }
978 int SliderGetPos(UISlider *slider) { return slider->GetPos(); }
979 void SliderSetSelectChangeCallback(UISlider *slider, void (*fn)(int)) { slider->SetSelectChangeCallback(fn); }
980 void SliderSetSelectChangeCallbackWData(UISlider *slider, void (*fn)(int, void *), void *ptr) {
981 slider->SetSelectChangeCallback(fn, ptr);
982 }
983 void GetUIItemPosition(UIObject *item, int *x, int *y, int *w, int *h) {
984 if (x)
985 *x = item->X();
986 if (y)
987 *y = item->Y();
988 if (w)
989 *w = item->W();
990 if (h)
991 *h = item->H();
992 }
993 #define CDT_EVT_PLAYERKILLED 1
994 #define CDT_EVT_CONNECT 2
995 #define CDT_EVT_GAME_OVER 3
996 #define CDT_EVT_GAME_STARTING 4
997 #define CDT_EVT_FRAME 5
998 #define CDT_EVT_PLAYER_DIED 6
999 #define CDT_EVT_PLAYER_JOINS 7
1000 #define CDT_EVT_PLAYER_LEFT 8
1001 #define CDT_EVT_SET_SCORE_IP 9
1002 #define CDT_EVT_SET_GAMEID 10
1003 #define CALLSIGN_LEN 19
1004 struct player_killed {
1005 char killer_name[CALLSIGN_LEN + 1];
1006 char killed_name[CALLSIGN_LEN + 1];
1007 };
1008 struct player_score_matrix {
1009 int num_players;
1010 char name[MAX_NET_PLAYERS][CALLSIGN_LEN + 1];
1011 int16_t deaths[MAX_NET_PLAYERS];
1012 int16_t kills[MAX_NET_PLAYERS];
1013 };
1014 // The chokepoint function to call the dll function
1015 void CallMultiScoreDLL(int eventnum, void *data) {
1016 if (MultiDLLHandle.handle && DLLMultiCall)
1017 DLLMultiScoreCall(eventnum, data);
1018 }
1019 // Determine if the Score API functions should run
1020 bool ScoreAPIShouldBail() {
1021 if (!(Game_mode & GM_MULTI))
1022 return true;
1023 if (Supports_score_api)
1024 return false;
1025 return true;
1026 }
1027 void ScoreAPIPlayerKilled(int killer, int killed) {
1028 if (ScoreAPIShouldBail())
1029 return;
1030 player_killed pk;
1031 strcpy(pk.killed_name, Players[killed].callsign);
1032 strcpy(pk.killer_name, Players[killer].callsign);
1033
1034 CallMultiScoreDLL(CDT_EVT_PLAYERKILLED, &pk);
1035 }
1036 void ScoreAPIPlayerEntered(int playernum) {
1037 if (ScoreAPIShouldBail())
1038 return;
1039 CallMultiScoreDLL(CDT_EVT_CONNECT, Players[playernum].callsign);
1040 }
1041 void ScoreAPIPlayerLeft(int playernum) {
1042 if (ScoreAPIShouldBail())
1043 return;
1044 CallMultiScoreDLL(CDT_EVT_PLAYER_LEFT, Players[playernum].callsign);
1045 }
1046 void ScoreAPIPlayerJoin(int playernum) {
1047 if (ScoreAPIShouldBail())
1048 return;
1049 CallMultiScoreDLL(CDT_EVT_PLAYER_JOINS, Players[playernum].callsign);
1050 }
1051 void ScoreAPIGameOver() {
1052 player_score_matrix sm;
1053
1054 if (ScoreAPIShouldBail())
1055 return;
1056
1057 int counted = 0;
1058 for (int i = 0; i < MAX_NET_PLAYERS; i++) {
1059 if (Players[i].callsign[0]) {
1060 strcpy(sm.name[counted], Players[i].callsign);
1061 sm.kills[counted] = Players[i].num_kills_level;
1062 sm.deaths[counted] = Players[i].num_deaths_level;
1063 counted++;
1064 }
1065 }
1066 sm.num_players = counted;
1067 // Create a matrix of all the players with their scores and send a pointer to it.
1068 CallMultiScoreDLL(CDT_EVT_GAME_OVER, &sm);
1069 }
1070 bool Set_score_server_ip = false;
1071 void ScoreAPIFrameInterval() {
1072 if (ScoreAPIShouldBail())
1073 return;
1074 if (!Set_score_server_ip) {
1075 Set_score_server_ip = true;
1076 // Look for a score server on the command line..
1077 int ss_arg = FindArg("-scoreserver");
1078 if (ss_arg) {
1079 CallMultiScoreDLL(CDT_EVT_SET_SCORE_IP, GameArgs[ss_arg + 1]);
1080 }
1081 int gi_arg = FindArg("-gameid");
1082 if (gi_arg) {
1083 CallMultiScoreDLL(CDT_EVT_SET_GAMEID, GameArgs[gi_arg + 1]);
1084 }
1085 }
1086 CallMultiScoreDLL(CDT_EVT_FRAME, NULL);
1087 }