| 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 | |
| 19 | #include "pstypes.h" |
| 20 | #include "pserror.h" |
| 21 | #include "game.h" |
| 22 | #include "game2dll.h" |
| 23 | #include "room.h" |
| 24 | #include "object.h" |
| 25 | #include "terrain.h" |
| 26 | #include "player.h" |
| 27 | #include "mono.h" |
| 28 | #include "hud.h" |
| 29 | #include "Inventory.h" |
| 30 | #include "multi_server.h" |
| 31 | #include "ship.h" |
| 32 | #include "DllWrappers.h" |
| 33 | #include "soundload.h" |
| 34 | #include "spew.h" |
| 35 | #include "objinfo.h" |
| 36 | #include "module.h" |
| 37 | #include "localization.h" |
| 38 | #include "weapon.h" |
| 39 | #include "voice.h" |
| 40 | #include "gametexture.h" |
| 41 | #include "Mission.h" |
| 42 | #include "damage.h" |
| 43 | #include "ui.h" |
| 44 | #include "newui.h" |
| 45 | #include "multi_dll_mgr.h" |
| 46 | #include "controls.h" |
| 47 | #include "gameloop.h" |
| 48 | #include "gamesequence.h" |
| 49 | #include "dedicated_server.h" |
| 50 | #include "attach.h" |
| 51 | #include "PilotPicsAPI.h" |
| 52 | #include "vclip.h" |
| 53 | #include "osiris_dll.h" |
| 54 | #include "manage.h" |
| 55 | #include "physics.h" |
| 56 | #include "collide.h" |
| 57 | #include "render.h" |
| 58 | #include "audiotaunts.h" |
| 59 | #include "polymodel.h" |
| 60 | #include "osiris_share.h" |
| 61 | #include "viseffect.h" |
| 62 | #include "ObjScript.h" |
| 63 | #include "args.h" |
| 64 | |
| 65 | #include <algorithm> |
| 66 | |
| 67 | void SelectNextCameraView(int window); |
| 68 | #define NUM_CAMERA_VIEWS 3 |
| 69 | extern int Camera_view_mode[NUM_CAMERA_VIEWS]; |
| 70 | |
| 71 | // Osiris_CreateModuleInitStruct |
| 72 | // Purpose: |
| 73 | // This function initializes a Module Init Struct with all the needed data to get sent |
| 74 | // to the module during initialization. |
| 75 | extern void Osiris_CreateModuleInitStruct(tOSIRISModuleInit *mi); |
| 76 | module GameDLLHandle = {NULL}; |
| 77 | extern ddgr_color Player_colors[]; |
| 78 | struct game_api { |
| 79 | int *objs; |
| 80 | int *rooms; |
| 81 | int *terrain; |
| 82 | int *players; |
| 83 | int *netgame; |
| 84 | int *netplayers; |
| 85 | int *ships; |
| 86 | int *weapons; |
| 87 | int *Current_mission; |
| 88 | int *GameTextures; |
| 89 | int *GameVClips; |
| 90 | int *fp[450]; // function pointers |
| 91 | int *vp[50]; // variable pointers |
| 92 | tOSIRISModuleInit *osiris_functions; |
| 93 | }; |
| 94 | // The exported DLL function call prototypes |
| 95 | #if defined(POSIX) |
| 96 | typedef void DLLFUNCCALL (*DLLGameCall_fp)(int eventnum, dllinfo *data); |
| 97 | typedef void DLLFUNCCALL (*DLLGameInit_fp)(int *api_func, uint8_t *all_ok, int num_teams_to_use); |
| 98 | typedef void DLLFUNCCALL (*DLLGameClose_fp)(); |
| 99 | typedef void DLLFUNCCALL (*DLLGameGetName_fp)(char *buffer, int maxsize); |
| 100 | typedef void DLLFUNCCALL (*DLLGameGetDesc_fp)(char **buffer, int maxsize, int lines); |
| 101 | typedef void DLLFUNCCALL (*DLLGetGameInfo_fp)(tDLLOptions *options); |
| 102 | #else |
| 103 | typedef void(DLLFUNCCALL *DLLGameCall_fp)(int eventnum, dllinfo *data); |
| 104 | typedef void(DLLFUNCCALL *DLLGameInit_fp)(int *api_func, uint8_t *all_ok, int num_teams_to_use); |
| 105 | typedef void(DLLFUNCCALL *DLLGameClose_fp)(); |
| 106 | typedef void(DLLFUNCCALL *DLLGameGetName_fp)(char *buffer, int maxsize); |
| 107 | typedef void(DLLFUNCCALL *DLLGameGetDesc_fp)(char **buffer, int maxsize, int lines); |
| 108 | typedef void(DLLFUNCCALL *DLLGetGameInfo_fp)(tDLLOptions *options); |
| 109 | #endif |
| 110 | DLLGameCall_fp DLLGameCall = NULL; |
| 111 | DLLGameInit_fp DLLGameInit = NULL; |
| 112 | DLLGameClose_fp DLLGameClose = NULL; |
| 113 | DLLGetGameInfo_fp DLLGetGameInfo = NULL; |
| 114 | dllinfo DLLInfo; |
| 115 | tOSIRISModuleInit Multi_d3m_osiris_funcs; |
| 116 | char Multi_game_dll_name[_MAX_PATH * 2]; |
| 117 | |
| 118 | static void DUMMYrend_DrawScaledBitmap(int x1, int y1, int x2, int y2, int bm, float u0, float v0, float u1, float v1, |
| 119 | float zval, int color, float *alphas) { |
| 120 | ASSERT(zval >= 0.0f && zval <= 1.0f); |
| 121 | rend_DrawScaledBitmap(x1, y1, x2, y2, bm, u0, v0, u1, v1, color, alphas); |
| 122 | } |
| 123 | |
| 124 | void GetGameAPI(game_api *api) { |
| 125 | api->objs = (int *)Objects; |
| 126 | api->rooms = (int *)Rooms; |
| 127 | api->terrain = (int *)Terrain_seg; |
| 128 | api->players = (int *)Players; |
| 129 | api->netgame = (int *)&Netgame; |
| 130 | api->netplayers = (int *)&NetPlayers; |
| 131 | api->ships = (int *)&Ships; |
| 132 | api->weapons = (int *)&Weapons; |
| 133 | api->Current_mission = (int *)&Current_mission; |
| 134 | api->GameTextures = (int *)GameTextures; |
| 135 | api->GameVClips = (int *)GameVClips; |
| 136 | |
| 137 | // Fill in function pointers here. The order here must match the order on the |
| 138 | // DLL side (dmfcbase.cpp) |
| 139 | |
| 140 | api->fp[0] = (int *)AddHUDMessage; |
| 141 | api->fp[1] = (int *)MultiSendClientExecuteDLL; |
| 142 | api->fp[2] = (int *)FindObjectIDName; |
| 143 | api->fp[3] = (int *)GetGoalRoomForTeam; |
| 144 | api->fp[4] = (int *)SetMaxTeams; |
| 145 | api->fp[5] = (int *)ComputeRoomCenter; |
| 146 | api->fp[6] = (int *)ObjCreate; |
| 147 | api->fp[7] = (int *)MultiSendObject; |
| 148 | api->fp[8] = (int *)MultiPaintGoalRooms; |
| 149 | api->fp[9] = (int *)MultiSendSpecialPacket; |
| 150 | api->fp[10] = (int *)IncTeamScore; |
| 151 | api->fp[11] = (int *)MonoPrintf; |
| 152 | api->fp[12] = (int *)ObjSetPos; |
| 153 | api->fp[13] = (int *)InvCheckItem; |
| 154 | api->fp[14] = (int *)InvAddTypeID; |
| 155 | api->fp[15] = (int *)InvRemove; |
| 156 | api->fp[16] = (int *)PlayerSetLighting; |
| 157 | api->fp[17] = (int *)FindShipName; |
| 158 | api->fp[18] = (int *)PlayerSetRotatingBall; |
| 159 | api->fp[19] = (int *)ChangePlayerShipIndex; |
| 160 | api->fp[20] = (int *)InvGetTypeIDCount; |
| 161 | api->fp[21] = (int *)D3W_Play3dSound; |
| 162 | api->fp[22] = (int *)FindSoundName; |
| 163 | api->fp[23] = (int *)SpewCreate; |
| 164 | api->fp[24] = (int *)SpewClearEvent; |
| 165 | api->fp[25] = (int *)bm_AllocLoadFileBitmap; |
| 166 | api->fp[26] = (int *)bm_FreeBitmap; |
| 167 | api->fp[27] = (int *)DUMMYrend_DrawScaledBitmap; |
| 168 | api->fp[28] = (int *)grtext_Printf; |
| 169 | api->fp[29] = (int *)grtext_Flush; |
| 170 | api->fp[30] = (int *)grtext_SetColor; |
| 171 | api->fp[31] = (int *)grtext_SetFancyColor; |
| 172 | api->fp[32] = (int *)grtext_SetAlpha; |
| 173 | api->fp[33] = (int *)grtext_GetAlpha; |
| 174 | api->fp[34] = (int *)grtext_SetFont; |
| 175 | api->fp[35] = (int *)grtext_GetFont; |
| 176 | api->fp[36] = (int *)grtext_GetTextLineWidth; |
| 177 | api->fp[37] = (int *)grfont_GetHeight; |
| 178 | api->fp[38] = (int *)grtext_CenteredPrintf; |
| 179 | api->fp[39] = (int *)AddColoredHUDMessage; |
| 180 | api->fp[40] = (int *)bm_w; |
| 181 | api->fp[41] = (int *)bm_h; |
| 182 | api->fp[42] = (int *)rend_DrawSimpleBitmap; |
| 183 | api->fp[43] = (int *)MultiClientSendSpecialPacket; |
| 184 | api->fp[44] = (int *)AddBlinkingHUDMessage; |
| 185 | api->fp[45] = (int *)InvReset; |
| 186 | api->fp[46] = (int *)AddHUDItem; |
| 187 | api->fp[47] = (int *)RenderHUDQuad; |
| 188 | api->fp[48] = (int *)RenderHUDText; |
| 189 | api->fp[49] = (int *)MultiEndLevel; |
| 190 | api->fp[50] = (int *)bm_data; |
| 191 | api->fp[51] = (int *)bm_AllocBitmap; |
| 192 | api->fp[52] = (int *)rend_FillRect; |
| 193 | api->fp[53] = (int *)bm_CreateChunkedBitmap; |
| 194 | api->fp[54] = (int *)bm_DestroyChunkedBitmap; |
| 195 | api->fp[55] = (int *)rend_DrawChunkedBitmap; |
| 196 | api->fp[56] = (int *)rend_DrawScaledChunkedBitmap; |
| 197 | api->fp[57] = (int *)OpenCFILE; |
| 198 | api->fp[58] = (int *)cfclose; |
| 199 | api->fp[59] = (int *)cfeof; |
| 200 | api->fp[60] = (int *)cfexist; |
| 201 | api->fp[61] = (int *)cf_ReadBytes; |
| 202 | api->fp[62] = (int *)cf_ReadInt; |
| 203 | api->fp[63] = (int *)cf_ReadShort; |
| 204 | api->fp[64] = (int *)cf_ReadByte; |
| 205 | api->fp[65] = (int *)cf_ReadFloat; |
| 206 | api->fp[66] = (int *)cf_ReadDouble; |
| 207 | api->fp[67] = (int *)cf_ReadString; |
| 208 | api->fp[68] = (int *)cf_WriteBytes; |
| 209 | api->fp[69] = (int *)cf_WriteString; |
| 210 | api->fp[70] = (int *)cf_WriteInt; |
| 211 | api->fp[71] = (int *)cf_WriteShort; |
| 212 | api->fp[72] = (int *)cf_WriteByte; |
| 213 | api->fp[73] = (int *)cf_WriteFloat; |
| 214 | api->fp[74] = (int *)cf_WriteDouble; |
| 215 | api->fp[75] = (int *)cf_CopyFile; |
| 216 | api->fp[76] = (int *)cf_Diff; |
| 217 | api->fp[77] = (int *)MultiDisconnectPlayer; |
| 218 | api->fp[78] = (int *)nw_GetNumbersFromHostAddress; |
| 219 | api->fp[79] = (int *)nw_GetThisIP; |
| 220 | api->fp[80] = (int *)CreateStringTable; |
| 221 | api->fp[81] = (int *)DestroyStringTable; |
| 222 | api->fp[82] = (int *)RenderHUDTextFlags; |
| 223 | api->fp[83] = (int *)PlayerSpewInventory; |
| 224 | api->fp[84] = (int *)PlayerSetHUDNameFOV; |
| 225 | api->fp[85] = (int *)GetUltimateParentForObject; |
| 226 | api->fp[86] = (int *)SetObjectDeadFlagDLL; |
| 227 | api->fp[87] = (int *)DLLFatalError; |
| 228 | api->fp[88] = (int *)assertdll; |
| 229 | api->fp[89] = (int *)MultiMatchWeapon; |
| 230 | api->fp[90] = (int *)MultiGetMatchChecksum; |
| 231 | api->fp[91] = (int *)FindWeaponName; |
| 232 | api->fp[92] = (int *)cf_OpenLibrary; |
| 233 | api->fp[93] = (int *)cf_CloseLibrary; |
| 234 | api->fp[94] = (int *)MultiSendRequestToObserve; |
| 235 | api->fp[95] = (int *)FindTextureName; |
| 236 | api->fp[96] = (int *)ApplyDamageToPlayer; |
| 237 | api->fp[97] = (int *)MultiMatchGeneric; |
| 238 | api->fp[98] = (int *)SetUITextItemText; |
| 239 | api->fp[99] = (int *)NewUIWindowCreate; |
| 240 | api->fp[100] = (int *)NewUIWindowDestroy; |
| 241 | api->fp[101] = (int *)NewUIWindowOpen; |
| 242 | api->fp[102] = (int *)NewUIWindowClose; |
| 243 | api->fp[103] = (int *)TextCreate; |
| 244 | api->fp[104] = (int *)EditCreate; |
| 245 | api->fp[105] = (int *)ButtonCreate; |
| 246 | api->fp[106] = (int *)ListCreate; |
| 247 | api->fp[107] = (int *)ListRemoveAll; |
| 248 | api->fp[108] = (int *)ListAddItem; |
| 249 | api->fp[109] = (int *)ListRemoveItem; |
| 250 | api->fp[110] = (int *)ListSelectItem; |
| 251 | api->fp[111] = (int *)ListGetItem; |
| 252 | api->fp[112] = (int *)ListGetSelectedIndex; |
| 253 | api->fp[113] = (int *)EditSetText; |
| 254 | api->fp[114] = (int *)EditGetText; |
| 255 | api->fp[115] = (int *)DoUI; |
| 256 | api->fp[116] = (int *)DoMessageBox; |
| 257 | api->fp[117] = (int *)DescentDefer; |
| 258 | api->fp[118] = (int *)NewUIGameWindowCreate; |
| 259 | api->fp[119] = (int *)NewUIGameWindowDestroy; |
| 260 | api->fp[120] = (int *)NewUIGameWindowOpen; |
| 261 | api->fp[121] = (int *)NewUIGameWindowClose; |
| 262 | api->fp[122] = (int *)HotSpotCreate; |
| 263 | api->fp[123] = (int *)PollUI; |
| 264 | api->fp[124] = (int *)RemoveUITextItem; |
| 265 | api->fp[125] = (int *)CreateNewUITextItem; |
| 266 | api->fp[126] = (int *)UIConsoleGadgetCreate; |
| 267 | api->fp[127] = (int *)UIConsoleGadgetputs; |
| 268 | api->fp[128] = (int *)NewUIWindowSetFocusOnEditGadget; |
| 269 | api->fp[129] = (int *)OldEditCreate; |
| 270 | api->fp[130] = (int *)OldListCreate; |
| 271 | api->fp[131] = (int *)OldListRemoveAll; |
| 272 | api->fp[132] = (int *)OldListAddItem; |
| 273 | api->fp[133] = (int *)OldListRemoveItem; |
| 274 | api->fp[134] = (int *)OldListSelectItem; |
| 275 | api->fp[135] = (int *)OldListGetItem; |
| 276 | api->fp[136] = (int *)OldListGetSelectedIndex; |
| 277 | api->fp[137] = (int *)OldEditSetText; |
| 278 | api->fp[138] = (int *)OldEditGetText; |
| 279 | api->fp[139] = (int *)ToggleUICallback; |
| 280 | api->fp[140] = (int *)SetOldEditBufferLen; |
| 281 | api->fp[141] = (int *)NewUIWindowLoadBackgroundImage; |
| 282 | api->fp[142] = (int *)DeleteUIItem; |
| 283 | api->fp[143] = (int *)HotSpotSetStates; |
| 284 | api->fp[144] = (int *)SetUICallback; |
| 285 | api->fp[145] = (int *)RetrieveUICallback; |
| 286 | api->fp[146] = (int *)SuspendControls; |
| 287 | api->fp[147] = (int *)ResumeControls; |
| 288 | api->fp[148] = (int *)ui_ShowCursor; |
| 289 | api->fp[149] = (int *)ui_HideCursor; |
| 290 | api->fp[150] = (int *)GameFrame; |
| 291 | api->fp[151] = (int *)PrintDedicatedMessage; |
| 292 | api->fp[152] = (int *)ddio_MakePath; |
| 293 | api->fp[153] = (int *)ddio_SplitPath; |
| 294 | api->fp[154] = (int *)D3W_Play2dSound; |
| 295 | api->fp[155] = (int *)D3W_TouchSound; |
| 296 | api->fp[156] = (int *)dDatabaseRead1; |
| 297 | api->fp[157] = (int *)dDatabaseRead2; |
| 298 | api->fp[158] = (int *)dDatabaseRead3; |
| 299 | api->fp[159] = (int *)dDatabaseWrite1; |
| 300 | api->fp[160] = (int *)dDatabaseWrite2; |
| 301 | api->fp[161] = (int *)dAttachObject; |
| 302 | api->fp[162] = (int *)dObjGet; |
| 303 | api->fp[163] = (int *)ListSetSelectedIndex; |
| 304 | api->fp[164] = (int *)RemoveUIBmpItem; |
| 305 | api->fp[165] = (int *)CreateNewUIBmpItem; |
| 306 | api->fp[166] = (int *)GetUIItemWidth; |
| 307 | api->fp[167] = (int *)GetUIItemHeight; |
| 308 | api->fp[168] = (int *)SliderCreate; |
| 309 | api->fp[169] = (int *)SliderSetRange; |
| 310 | api->fp[170] = (int *)SliderGetRange; |
| 311 | api->fp[171] = (int *)SliderSetPos; |
| 312 | api->fp[172] = (int *)SliderGetPos; |
| 313 | api->fp[173] = (int *)SliderSetSelectChangeCallback; |
| 314 | api->fp[174] = (int *)SliderSetSelectChangeCallbackWData; |
| 315 | api->fp[175] = (int *)TextSetTitle; |
| 316 | api->fp[176] = (int *)PPic_GetPilot; |
| 317 | api->fp[177] = (int *)PPic_GetBitmapHandle; |
| 318 | api->fp[178] = (int *)rend_DrawLine; |
| 319 | api->fp[179] = (int *)rend_SetFlatColor; |
| 320 | api->fp[180] = (int *)MultiSetLogoState; |
| 321 | api->fp[181] = (int *)PlayerGetRandomStartPosition; |
| 322 | api->fp[182] = (int *)InitPlayerNewShip; |
| 323 | api->fp[183] = (int *)CheckBoxCreate; |
| 324 | api->fp[184] = (int *)CheckBoxSetCheck; |
| 325 | api->fp[185] = (int *)CheckBoxIsChecked; |
| 326 | api->fp[186] = (int *)nw_GetHostAddressFromNumbers; |
| 327 | api->fp[187] = (int *)mng_ClearAddonTables; |
| 328 | api->fp[188] = (int *)mng_SetAddonTable; |
| 329 | api->fp[189] = (int *)DebugBreak_callback_stop; |
| 330 | api->fp[190] = (int *)DebugBreak_callback_resume; |
| 331 | api->fp[191] = (int *)Int3MessageBox; |
| 332 | api->fp[192] = (int *)GetUIItemPosition; |
| 333 | api->fp[193] = (int *)dAttachObjectRadius; |
| 334 | api->fp[194] = (int *)dUnattachChildren; |
| 335 | api->fp[195] = (int *)dUnattachChild; |
| 336 | api->fp[196] = (int *)dUnattachFromParent; |
| 337 | api->fp[197] = (int *)vm_GetMagnitude; |
| 338 | api->fp[198] = (int *)vm_MatrixMulVector; |
| 339 | api->fp[199] = (int *)phys_apply_force; |
| 340 | api->fp[200] = (int *)phys_apply_rot; |
| 341 | api->fp[201] = (int *)vm_TransposeMatrix; |
| 342 | api->fp[202] = (int *)vm_CrossProduct; |
| 343 | api->fp[203] = (int *)vm_NormalizeVector; |
| 344 | api->fp[204] = (int *)ConvertEulerToAxisAmount; |
| 345 | api->fp[205] = (int *)ConvertAxisAmountToEuler; |
| 346 | api->fp[206] = (int *)vm_GetMagnitudeFast; |
| 347 | api->fp[207] = (int *)vm_MakeIdentity; |
| 348 | api->fp[208] = (int *)dvm_MakeZeroVector; |
| 349 | api->fp[209] = (int *)dvm_MakeZeroAngle; |
| 350 | api->fp[210] = (int *)vm_VectorMulTMatrix; |
| 351 | api->fp[211] = (int *)vm_MatrixMul; |
| 352 | api->fp[212] = (int *)vm_MatrixMulTMatrix; |
| 353 | api->fp[213] = (int *)vm_DotProduct; |
| 354 | api->fp[214] = (int *)vm_SubVectors; |
| 355 | api->fp[215] = (int *)vm_AddVectors; |
| 356 | api->fp[216] = (int *)vm_AverageVector; |
| 357 | api->fp[217] = (int *)vm_ScaleVector; |
| 358 | api->fp[218] = (int *)vm_ScaleAddVector; |
| 359 | api->fp[219] = (int *)vm_DivVector; |
| 360 | api->fp[220] = (int *)vm_NormalizeVectorFast; |
| 361 | api->fp[221] = (int *)vm_ClearMatrix; |
| 362 | api->fp[222] = (int *)vm_AnglesToMatrix; |
| 363 | api->fp[223] = (int *)vm_Orthogonalize; |
| 364 | api->fp[224] = (int *)vm_VectorToMatrix; |
| 365 | api->fp[225] = (int *)vm_VectorAngleToMatrix; |
| 366 | api->fp[226] = (int *)vm_SinCos; |
| 367 | api->fp[227] = (int *)vm_GetSlope; |
| 368 | api->fp[228] = (int *)vm_GetPerp; |
| 369 | api->fp[229] = (int *)vm_GetNormal; |
| 370 | api->fp[230] = (int *)vm_VectorDistance; |
| 371 | api->fp[231] = (int *)vm_VectorDistanceQuick; |
| 372 | api->fp[232] = (int *)vm_GetNormalizedDir; |
| 373 | api->fp[233] = (int *)vm_GetNormalizedDirFast; |
| 374 | api->fp[234] = (int *)vm_ExtractAnglesFromMatrix; |
| 375 | api->fp[235] = (int *)vm_DeltaAngVec; |
| 376 | api->fp[236] = (int *)vm_DeltaAngVecNorm; |
| 377 | api->fp[237] = (int *)vm_DistToPlane; |
| 378 | api->fp[238] = (int *)calc_det_value; |
| 379 | api->fp[239] = (int *)vm_MakeInverseMatrix; |
| 380 | api->fp[240] = (int *)vm_SinCosToMatrix; |
| 381 | api->fp[241] = (int *)vm_GetCentroid; |
| 382 | api->fp[242] = (int *)vm_MakeRandomVector; |
| 383 | api->fp[243] = (int *)vm_ComputeBoundingSphere; |
| 384 | api->fp[244] = (int *)vm_GetCentroidFast; |
| 385 | api->fp[245] = (int *)RenderHUDGetTextLineWidth; |
| 386 | api->fp[246] = (int *)RenderHUDGetTextHeight; |
| 387 | api->fp[247] = (int *)dStartFrame; |
| 388 | api->fp[248] = (int *)EndFrame; |
| 389 | api->fp[249] = (int *)ResetFacings; |
| 390 | api->fp[250] = (int *)GameRenderWorld; |
| 391 | api->fp[251] = (int *)GetFrameParameters; |
| 392 | api->fp[252] = (int *)rend_SetZBufferState; |
| 393 | api->fp[253] = (int *)rend_SetLighting; |
| 394 | api->fp[254] = (int *)rend_SetColorModel; |
| 395 | api->fp[255] = (int *)rend_SetTextureType; |
| 396 | api->fp[256] = (int *)rend_DrawPolygon3D; |
| 397 | api->fp[257] = (int *)rend_SetMipState; |
| 398 | api->fp[258] = (int *)rend_SetFogState; |
| 399 | api->fp[259] = (int *)rend_SetFiltering; |
| 400 | api->fp[260] = (int *)rend_SetOverlayMap; |
| 401 | api->fp[261] = (int *)rend_SetOverlayType; |
| 402 | api->fp[262] = (int *)rend_ClearScreen; |
| 403 | api->fp[263] = (int *)rend_SetPixel; |
| 404 | api->fp[264] = (int *)rend_GetPixel; |
| 405 | api->fp[265] = (int *)rend_FillCircle; |
| 406 | api->fp[266] = (int *)rend_DrawCircle; |
| 407 | api->fp[267] = (int *)rend_SetAlphaType; |
| 408 | api->fp[268] = (int *)rend_SetAlphaValue; |
| 409 | api->fp[269] = (int *)rend_SetWrapType; |
| 410 | api->fp[270] = (int *)rend_SetZBias; |
| 411 | api->fp[271] = (int *)rend_SetZBufferWriteMask; |
| 412 | api->fp[272] = (int *)rend_GetLFBLock; |
| 413 | api->fp[273] = (int *)rend_ReleaseLFBLock; |
| 414 | api->fp[274] = (int *)rend_DrawLFBBitmap; |
| 415 | api->fp[275] = (int *)rend_DrawSpecialLine; |
| 416 | api->fp[276] = (int *)fvi_FindIntersection; |
| 417 | api->fp[277] = (int *)fvi_QuickDistFaceList; |
| 418 | api->fp[278] = (int *)fvi_QuickDistCellList; |
| 419 | api->fp[279] = (int *)fvi_QuickDistObjectList; |
| 420 | api->fp[280] = (int *)fvi_QuickRoomCheck; |
| 421 | api->fp[281] = (int *)ObjSetPosAndMarkMoved; |
| 422 | api->fp[282] = (int *)dSetObjectDeadFlagWDemo; |
| 423 | api->fp[283] = (int *)taunt_AreEnabled; |
| 424 | api->fp[284] = (int *)dSetAudioTaunts; |
| 425 | api->fp[285] = (int *)GetRankIndex; |
| 426 | api->fp[286] = (int *)VisEffectAllocate; |
| 427 | api->fp[287] = (int *)VisEffectFree; |
| 428 | api->fp[288] = (int *)VisEffectInitType; |
| 429 | api->fp[289] = (int *)VisEffectCreate; |
| 430 | api->fp[290] = (int *)VisEffectLink; |
| 431 | api->fp[291] = (int *)VisEffectUnlink; |
| 432 | api->fp[292] = (int *)VisEffectRelink; |
| 433 | api->fp[293] = (int *)VisEffectDelete; |
| 434 | api->fp[294] = (int *)CreateRandomSparks; |
| 435 | api->fp[295] = (int *)CreateRandomLineSparks; |
| 436 | api->fp[296] = (int *)VisEffectCreateControlled; |
| 437 | api->fp[297] = (int *)CreateRandomParticles; |
| 438 | api->fp[298] = (int *)AttachRandomNapalmEffectsToObject; |
| 439 | api->fp[299] = (int *)InitObjectScripts; |
| 440 | api->fp[300] = (int *)g3_StartFrame; |
| 441 | api->fp[301] = (int *)g3_EndFrame; |
| 442 | api->fp[302] = (int *)g3_GetViewPosition; |
| 443 | api->fp[303] = (int *)g3_GetViewMatrix; |
| 444 | api->fp[304] = (int *)g3_GetUnscaledMatrix; |
| 445 | api->fp[305] = (int *)g3_StartInstanceMatrix; |
| 446 | api->fp[306] = (int *)g3_StartInstanceAngles; |
| 447 | api->fp[307] = (int *)g3_DoneInstance; |
| 448 | api->fp[308] = (int *)g3_CheckNormalFacing; |
| 449 | api->fp[309] = (int *)g3_RotatePoint; |
| 450 | api->fp[310] = (int *)g3_ProjectPoint; |
| 451 | api->fp[311] = (int *)g3_CalcPointDepth; |
| 452 | api->fp[312] = (int *)g3_Point2Vec; |
| 453 | api->fp[313] = (int *)g3_CodePoint; |
| 454 | api->fp[314] = (int *)g3_RotateDeltaX; |
| 455 | api->fp[315] = (int *)g3_RotateDeltaY; |
| 456 | api->fp[316] = (int *)g3_RotateDeltaZ; |
| 457 | api->fp[317] = (int *)g3_RotateDeltaVec; |
| 458 | api->fp[318] = (int *)g3_AddDeltaVec; |
| 459 | api->fp[319] = (int *)g3_DrawPoly; |
| 460 | api->fp[320] = (int *)g3_DrawSphere; |
| 461 | api->fp[321] = (int *)g3_CheckAndDrawPoly; |
| 462 | api->fp[322] = (int *)g3_DrawLine; |
| 463 | api->fp[323] = (int *)g3_DrawBitmap; |
| 464 | api->fp[324] = (int *)g3_DrawRotatedBitmap; |
| 465 | api->fp[325] = (int *)g3_DrawBox; |
| 466 | api->fp[326] = (int *)g3_SetCustomClipPlane; |
| 467 | api->fp[327] = (int *)g3_SetFarClipZ; |
| 468 | api->fp[328] = (int *)g3_ClipPolygon; |
| 469 | api->fp[329] = (int *)g3_FreeTempPoints; |
| 470 | api->fp[330] = (int *)g3_GetMatrixScale; |
| 471 | api->fp[331] = (int *)g3_SetTriangulationTest; |
| 472 | api->fp[332] = (int *)g3_DrawSpecialLine; |
| 473 | api->fp[333] = (int *)g3_DrawPlanarRotatedBitmap; |
| 474 | api->fp[334] = (int *)PlayerStopSounds; |
| 475 | api->fp[335] = (int *)FindArg; |
| 476 | api->fp[336] = (int *)FireWeaponFromObject; |
| 477 | api->fp[337] = (int *)CreateAndFireWeapon; |
| 478 | api->fp[338] = (int *)SelectNextCameraView; |
| 479 | api->fp[339] = (int *)dInven_Add; |
| 480 | api->fp[340] = (int *)dInven_AddObject; |
| 481 | api->fp[341] = (int *)dInven_AddCounterMeasure; |
| 482 | api->fp[342] = (int *)dInven_Remove; |
| 483 | api->fp[343] = (int *)dInven_Use; |
| 484 | api->fp[344] = (int *)dInven_UseObjHandle; |
| 485 | api->fp[345] = (int *)dInven_Size; |
| 486 | api->fp[346] = (int *)dInven_CheckItem; |
| 487 | api->fp[347] = (int *)dInven_Reset; |
| 488 | api->fp[348] = (int *)dInven_ResetPos; |
| 489 | api->fp[349] = (int *)dInven_NextPos; |
| 490 | api->fp[350] = (int *)dInven_PrevPos; |
| 491 | api->fp[351] = (int *)dInven_GetPosTypeID; |
| 492 | api->fp[352] = (int *)dInven_GetAuxPosTypeID; |
| 493 | api->fp[353] = (int *)dInven_GetPosDescription; |
| 494 | api->fp[354] = (int *)dInven_GetPosIconName; |
| 495 | api->fp[355] = (int *)dInven_GetPosName; |
| 496 | api->fp[356] = (int *)dInven_GetPosInfo; |
| 497 | api->fp[357] = (int *)dInven_GetPosCount; |
| 498 | api->fp[358] = (int *)dInven_AtBeginning; |
| 499 | api->fp[359] = (int *)dInven_AtEnd; |
| 500 | api->fp[360] = (int *)dInven_GotoPos; |
| 501 | api->fp[361] = (int *)dInven_GotoPosTypeID; |
| 502 | api->fp[362] = (int *)dInven_UsePos; |
| 503 | api->fp[363] = (int *)dInven_GetPos; |
| 504 | api->fp[364] = (int *)dInven_ValidatePos; |
| 505 | api->fp[365] = (int *)dInven_IsSelectable; |
| 506 | api->fp[366] = (int *)dInven_IsUsable; |
| 507 | api->fp[367] = (int *)dInven_GetTypeIDCount; |
| 508 | api->fp[368] = (int *)dInven_FindPos; |
| 509 | api->fp[369] = (int *)dInven_GetInventoryItemList; |
| 510 | |
| 511 | // Variable pointers |
| 512 | api->vp[0] = (int *)&Player_num; |
| 513 | api->vp[1] = (int *)&Highest_room_index; |
| 514 | api->vp[2] = (int *)&Game_window_w; |
| 515 | api->vp[3] = (int *)&Game_window_h; |
| 516 | api->vp[4] = (int *)&Game_fonts; |
| 517 | api->vp[5] = (int *)&Frametime; |
| 518 | api->vp[6] = (int *)&Gametime; |
| 519 | api->vp[7] = (int *)&Multi_additional_damage; |
| 520 | api->vp[8] = (int *)&Game_interface_mode; |
| 521 | api->vp[9] = (int *)LocalD3Dir; |
| 522 | api->vp[10] = (int *)&Game_is_master_tracker_game; |
| 523 | api->vp[11] = (int *)Local_object_list; |
| 524 | api->vp[12] = (int *)Server_object_list; |
| 525 | api->vp[13] = (int *)&Dedicated_server; |
| 526 | api->vp[14] = (int *)Player_colors; |
| 527 | api->vp[15] = (int *)&Hud_aspect_x; |
| 528 | api->vp[16] = (int *)&Hud_aspect_y; |
| 529 | api->vp[17] = (int *)&Viewer_object; |
| 530 | api->vp[18] = (int *)&Render_zoom; |
| 531 | api->vp[19] = (int *)&Game_window_x; |
| 532 | api->vp[20] = (int *)&Game_window_y; |
| 533 | api->vp[21] = (int *)&Poly_models; |
| 534 | api->vp[22] = (int *)VisEffects; |
| 535 | api->vp[23] = (int *)&Highest_vis_effect_index; |
| 536 | api->vp[24] = (int *)&Multi_next_level; |
| 537 | api->vp[25] = (int *)&Level_info; |
| 538 | api->vp[26] = (int *)GameArgs; |
| 539 | api->vp[27] = (int *)Camera_view_mode; |
| 540 | api->vp[28] = (int *)Object_info; |
| 541 | |
| 542 | api->osiris_functions = &Multi_d3m_osiris_funcs; |
| 543 | Osiris_CreateModuleInitStruct(&Multi_d3m_osiris_funcs); |
| 544 | Multi_d3m_osiris_funcs.string_table = NULL; |
| 545 | Multi_d3m_osiris_funcs.string_count = 0; |
| 546 | Multi_d3m_osiris_funcs.module_identifier = 0xEDF7; |
| 547 | Multi_d3m_osiris_funcs.module_is_static = false; |
| 548 | Multi_d3m_osiris_funcs.game_checksum = Osiris_game_checksum; |
| 549 | Multi_d3m_osiris_funcs.script_identifier = Netgame.scriptname; |
| 550 | } |
| 551 | // Closes and deletes any tempfiles for the game module |
| 552 | void CloseGameModule(module *mod) { |
| 553 | // Clear out error queue |
| 554 | mod_GetLastError(); |
| 555 | mod_FreeModule(mod); |
| 556 | if (Multi_game_dll_name[0] != '\0') { |
| 557 | // Try deleting the file now! |
| 558 | if (!ddio_DeleteFile(Multi_game_dll_name)) { |
| 559 | mprintf(0, "Couldn't delete the tmp dll"); |
| 560 | } |
| 561 | } |
| 562 | mod->handle = NULL; |
| 563 | } |
| 564 | // this function will load up the DLL, but not get any symbols |
| 565 | bool InitGameModule(const char *name, module *mod) { |
| 566 | char lib_name[_MAX_PATH * 2]; |
| 567 | char dll_name[_MAX_PATH * 2]; |
| 568 | char tmp_dll_name[_MAX_PATH * 2]; |
| 569 | // Make the hog filename |
| 570 | ddio_MakePath(lib_name, Base_directory, "netgames", name, NULL); |
| 571 | strcat(lib_name, ".d3m"); |
| 572 | // Make the dll filename |
| 573 | #if defined(WIN32) |
| 574 | snprintf(dll_name, sizeof(dll_name), "%s.dll", name); |
| 575 | #elif defined(MACOSX) |
| 576 | snprintf(dll_name, sizeof(dll_name), "%s.dylib", name); |
| 577 | #else |
| 578 | snprintf(dll_name, sizeof(dll_name), "%s.so", name); |
| 579 | #endif |
| 580 | |
| 581 | // Open the hog file |
| 582 | if (!cf_OpenLibrary(lib_name)) { |
| 583 | ddio_MakePath(tmp_dll_name, Base_directory, "netgames", name, NULL); |
| 584 | strcat(tmp_dll_name, ".d3m"); |
| 585 | Multi_game_dll_name[0] = '\0'; |
| 586 | goto loaddll; |
| 587 | } |
| 588 | // get a temp file name |
| 589 | if (!ddio_GetTempFileName(Descent3_temp_directory, "d3m", tmp_dll_name)) { |
| 590 | return false; |
| 591 | } |
| 592 | // Copy the DLL |
| 593 | if (!cf_CopyFile(tmp_dll_name, dll_name)) { |
| 594 | mprintf(0, "DLL copy failed!\n"); |
| 595 | return false; |
| 596 | } |
| 597 | strcpy(Multi_game_dll_name, tmp_dll_name); |
| 598 | loaddll: |
| 599 | // Clear out error queue |
| 600 | mod_GetLastError(); |
| 601 | if (!mod_LoadModule(mod, tmp_dll_name)) { |
| 602 | int err = mod_GetLastError(); |
| 603 | mprintf(0, "You are missing the DLL %s!\n", name); |
| 604 | return false; |
| 605 | } |
| 606 | return true; |
| 607 | } |
| 608 | // Frees the dll if its in memory |
| 609 | void FreeGameDLL() { |
| 610 | if (!GameDLLHandle.handle) |
| 611 | return; |
| 612 | if (DLLGameClose) |
| 613 | DLLGameClose(); |
| 614 | Osiris_UnloadMissionModule(); |
| 615 | CloseGameModule(&GameDLLHandle); |
| 616 | DLLGameCall = NULL; |
| 617 | DLLGameInit = NULL; |
| 618 | DLLGameClose = NULL; |
| 619 | DLLGetGameInfo = NULL; |
| 620 | } |
| 621 | // Loads the game dll. Returns 1 on success, else 0 on failure |
| 622 | int LoadGameDLL(const char *name, int num_teams_to_use) { |
| 623 | static int first = 1; |
| 624 | // char lib_name[_MAX_PATH*2]; |
| 625 | // char dll_name[_MAX_PATH*2]; |
| 626 | // char tmp_dll_name[_MAX_PATH*2]; |
| 627 | // char dll_path_name[_MAX_PATH*2]; |
| 628 | // char fulldll[_MAX_PATH*2]; |
| 629 | // ddio_MakePath(fulldll,Base_directory,"netgames",name,NULL); |
| 630 | if (GameDLLHandle.handle) |
| 631 | FreeGameDLL(); |
| 632 | if (num_teams_to_use == -1) { |
| 633 | int mint, maxt; |
| 634 | if (GetDLLNumTeamInfo(name, &mint, &maxt)) { |
| 635 | // multi team game |
| 636 | num_teams_to_use = mint; |
| 637 | } else { |
| 638 | // non-team game |
| 639 | num_teams_to_use = 1; |
| 640 | } |
| 641 | } |
| 642 | mprintf(0, "Loading '%s', setting up for %d teams\n", name, num_teams_to_use); |
| 643 | if (!InitGameModule(name, &GameDLLHandle)) |
| 644 | return 0; |
| 645 | |
| 646 | // Clear out error queue |
| 647 | mod_GetLastError(); |
| 648 | DLLGameInit = (DLLGameInit_fp)mod_GetSymbol(&GameDLLHandle, "DLLGameInit", 12); |
| 649 | if (!DLLGameInit) { |
| 650 | int err = mod_GetLastError(); |
| 651 | mprintf(0, "Couldn't get a handle to the dll function DLLGameInit!\n"); |
| 652 | Int3(); |
| 653 | FreeGameDLL(); |
| 654 | return 0; |
| 655 | } |
| 656 | // Clear out error queue |
| 657 | mod_GetLastError(); |
| 658 | DLLGameCall = (DLLGameCall_fp)mod_GetSymbol(&GameDLLHandle, "DLLGameCall", 8); |
| 659 | if (!DLLGameCall) { |
| 660 | int err = mod_GetLastError(); |
| 661 | mprintf(0, "Couldn't get a handle to the dll function DLLGameCall!\n"); |
| 662 | Int3(); |
| 663 | FreeGameDLL(); |
| 664 | return 0; |
| 665 | } |
| 666 | // Clear out error queue |
| 667 | mod_GetLastError(); |
| 668 | DLLGameClose = (DLLGameClose_fp)mod_GetSymbol(&GameDLLHandle, "DLLGameClose", 0); |
| 669 | if (!DLLGameClose) { |
| 670 | int err = mod_GetLastError(); |
| 671 | mprintf(0, "Couldn't get a handle to the dll function DLLGameClose!\n"); |
| 672 | Int3(); |
| 673 | FreeGameDLL(); |
| 674 | return 0; |
| 675 | } |
| 676 | // Clear out error queue |
| 677 | mod_GetLastError(); |
| 678 | DLLGetGameInfo = (DLLGetGameInfo_fp)mod_GetSymbol(&GameDLLHandle, "DLLGetGameInfo", 4); |
| 679 | if (!DLLGetGameInfo) { |
| 680 | int err = mod_GetLastError(); |
| 681 | mprintf(0, "Couldn't get a handle to the dll function DLLGetGameInfo!\n"); |
| 682 | Int3(); |
| 683 | FreeGameDLL(); |
| 684 | return 0; |
| 685 | } |
| 686 | if (first) { |
| 687 | // Jeff: Linux for some reason dies if you try to |
| 688 | // free a DLL/so on atexit, they should be freed |
| 689 | // anyway during game sequencing |
| 690 | // atexit (FreeGameDLL); |
| 691 | first = 0; |
| 692 | } |
| 693 | void *api_fp; |
| 694 | uint8_t ok = 1; |
| 695 | api_fp = (void *)GetGameAPI; |
| 696 | |
| 697 | DLLGameInit((int *)api_fp, &ok, num_teams_to_use); |
| 698 | if (!ok) { |
| 699 | // The DLL said no to the load |
| 700 | mprintf(0, "DLLGameInit returned false, couldn't init DLL\n"); |
| 701 | Int3(); |
| 702 | FreeGameDLL(); |
| 703 | return 0; |
| 704 | } |
| 705 | Osiris_LoadMissionModule(&GameDLLHandle, name); |
| 706 | |
| 707 | return 1; |
| 708 | } |
| 709 | // If this function is called than the DLL is to be closed, because there was an error running it |
| 710 | // if reason is not NULL than that is the reason why |
| 711 | void DLLFatalError(const char *reason) { |
| 712 | mprintf(0, "============================\n"); |
| 713 | mprintf(0, "= DLL Fatal Error =\n"); |
| 714 | mprintf(0, "============================\n"); |
| 715 | mprintf(0, "%s\n", (reason) ? reason : "<No Reason Given>"); |
| 716 | Netgame.flags |= NF_EXIT_NOW; |
| 717 | Int3(); |
| 718 | } |
| 719 | // The chokepoint function to call the dll function |
| 720 | void CallGameDLL(int eventnum, dllinfo *data) { |
| 721 | if (GameDLLHandle.handle && DLLGameCall) { |
| 722 | data->iRet = 0; |
| 723 | DLLGameCall(eventnum, data); |
| 724 | } |
| 725 | } |
| 726 | // Call this function right after a player connects to the game to see if a player is banned |
| 727 | bool GameDLLIsAddressBanned(network_address *addr, const char *tracker_id) { |
| 728 | ASSERT(addr); |
| 729 | DLLInfo.special_data = (uint8_t *)addr; |
| 730 | // This used to be tracker_id, but storing a pointer as an int is a problem in 64 bit |
| 731 | // and no code ever was populating the tracker id that I know of. -Kevin |
| 732 | DLLInfo.iParam = 0; |
| 733 | DLLInfo.iRet = 0; |
| 734 | CallGameDLL(EVT_GAMECHECKBAN, &DLLInfo); |
| 735 | if (DLLInfo.iRet) |
| 736 | return true; |
| 737 | else |
| 738 | return false; |
| 739 | } |
| 740 | // Call this function to get the team that a connecting player should be placed on |
| 741 | // Callsign and network address of the player MUST be filled in at this point |
| 742 | // PXO id must also be set if mastertracker game |
| 743 | // |
| 744 | // Return values: |
| 745 | // -2: GameDLL can't determine a team (user specified that they want to handle), so pick a random team |
| 746 | // -1: Dedicated Server |
| 747 | // 0-4: Team |
| 748 | int GameDLLGetConnectingPlayersTeam(int slot) { |
| 749 | ASSERT(slot >= 0 && slot < MAX_PLAYERS); |
| 750 | DLLInfo.iParam = slot; |
| 751 | DLLInfo.iRet = 0; |
| 752 | CallGameDLL(EVT_GAME_GET_PLAYER_TEAM, &DLLInfo); |
| 753 | return DLLInfo.iRet; |
| 754 | } |
| 755 | // Call this function to get information/options from a unloaded mod |
| 756 | bool GetDLLGameInfo(const char *name, tDLLOptions *options) { |
| 757 | module mod = {NULL}; |
| 758 | memset(options, 0, sizeof(tDLLOptions)); |
| 759 | DLLGetGameInfo_fp modGetGameInfo; |
| 760 | if (!InitGameModule(name, &mod)) |
| 761 | return false; |
| 762 | // Clear out error queue |
| 763 | mod_GetLastError(); |
| 764 | modGetGameInfo = (DLLGetGameInfo_fp)mod_GetSymbol(&mod, "DLLGetGameInfo", 4); |
| 765 | if (!modGetGameInfo) { |
| 766 | int err = mod_GetLastError(); |
| 767 | mprintf(0, "Couldn't get a handle to the dll function DLLGetGameInfo!\n"); |
| 768 | Int3(); |
| 769 | CloseGameModule(&mod); |
| 770 | return false; |
| 771 | } |
| 772 | modGetGameInfo(options); |
| 773 | CloseGameModule(&mod); |
| 774 | return true; |
| 775 | } |
| 776 | // Call this function to get the list of requirements that the given module needs in order |
| 777 | // to be playable. Returns the number of requirements it needs...-1 on error. |
| 778 | int GetDLLRequirements(const char *name, char *requirements, int buflen) { |
| 779 | ASSERT(buflen >= 0); |
| 780 | ASSERT(requirements); |
| 781 | tDLLOptions opt; |
| 782 | if (!GetDLLGameInfo(name, &opt)) { |
| 783 | mprintf(0, "Unable to get %s's requirements\n", name); |
| 784 | return -1; |
| 785 | } |
| 786 | strncpy(requirements, opt.requirements, buflen - 1); |
| 787 | requirements[buflen - 1] = '\0'; |
| 788 | uint32_t opt_req_len = strlen(opt.requirements); |
| 789 | if (opt_req_len > strlen(requirements)) { |
| 790 | // too small of a buffer! |
| 791 | mprintf(0, "Too small of a buffer to fill in all requirements!...need %d\n", opt_req_len + 1); |
| 792 | Int3(); |
| 793 | // cut off last requirement (which is shortened) |
| 794 | char *p = strrchr(requirements, ','); |
| 795 | if (p) { |
| 796 | *p = '\0'; |
| 797 | } else { |
| 798 | *requirements = '\0'; |
| 799 | } |
| 800 | } |
| 801 | // go through requirements and count em |
| 802 | char *p = requirements; |
| 803 | int count = 0; |
| 804 | while (*p) { |
| 805 | if (*p == ',') |
| 806 | count++; |
| 807 | p++; |
| 808 | } |
| 809 | count++; |
| 810 | return count; |
| 811 | } |
| 812 | // Call this function to get information about the number of teams for the game |
| 813 | // Returns true if it's a team game...false if it's a non-team game. |
| 814 | // If it returns true, then min is filled in with the minumum number of teams needed for the game |
| 815 | // and max is filled in with the maximum number of teams for the game...if they are the same |
| 816 | // value, then it is the only number of teams supported. |
| 817 | bool GetDLLNumTeamInfo(const char *name, int *mint, int *maxt) { |
| 818 | tDLLOptions dllo; |
| 819 | if (!GetDLLGameInfo(name, &dllo)) { |
| 820 | *mint = 1; |
| 821 | *maxt = 1; |
| 822 | return false; |
| 823 | } |
| 824 | if (!(dllo.flags & DOF_MAXTEAMS)) { |
| 825 | *mint = 1; |
| 826 | *maxt = 1; |
| 827 | return false; |
| 828 | } |
| 829 | *maxt = (dllo.max_teams == 0 || dllo.max_teams == 1 || dllo.max_teams < 0) ? 1 : std::min(dllo.max_teams, 4); |
| 830 | if ((*maxt) == 1) { |
| 831 | *mint = 1; |
| 832 | } else { |
| 833 | *mint = 2; |
| 834 | } |
| 835 | if (dllo.flags & DOF_MINTEAMS && dllo.min_teams >= 0) { |
| 836 | *mint = (dllo.min_teams == 0 || dllo.min_teams == 1) ? 1 : std::min(*maxt, dllo.min_teams); |
| 837 | } |
| 838 | return ((*maxt) == 1) ? false : true; |
| 839 | } |