Osiris_LoadMissionModule Purpose: It will attempt to load the module as a game module. If it succeeds it will return the id of the module where it has been loaded. If the module was already loaded before calling this function, it will return the id to where the module is, and will not reload the module. Returns -1 if the module does not exist. Returns -2 if the module couldn't initialize. Retu
| 1320 | // This technically doesn't load a mission module, as it should already be loaded by |
| 1321 | // Descent 3 prior. |
| 1322 | int Osiris_LoadMissionModule(module *module_handle, const char *filename) { |
| 1323 | if ((Game_mode & GM_MULTI) && (Netgame.local_role != LR_SERVER)) { |
| 1324 | // no scripts for a client! |
| 1325 | return -1; |
| 1326 | } |
| 1327 | |
| 1328 | if (!module_handle) { |
| 1329 | return -1; |
| 1330 | } |
| 1331 | |
| 1332 | int loaded_id; |
| 1333 | |
| 1334 | // find an available slot. |
| 1335 | for (loaded_id = 0; loaded_id < MAX_LOADED_MODULES; loaded_id++) { |
| 1336 | if (!(OSIRIS_loaded_modules[loaded_id].flags & OSIMF_INUSE)) { |
| 1337 | // we found a free slot |
| 1338 | break; |
| 1339 | } |
| 1340 | } |
| 1341 | |
| 1342 | if (loaded_id >= MAX_LOADED_MODULES) { |
| 1343 | // no slots available |
| 1344 | mprintf(0, "OSIRIS: Osiris_LoadMissionModule(%s): No available slots\n", filename); |
| 1345 | Int3(); |
| 1346 | return -4; |
| 1347 | } |
| 1348 | |
| 1349 | // make sure the module exists so we can load it |
| 1350 | if (!module_handle->handle) { |
| 1351 | // the module does not exist |
| 1352 | mprintf(0, "OSIRIS: Osiris_LoadMissionModule(%s): Module doesn't exist\n", filename); |
| 1353 | // Int3(); |
| 1354 | return -1; |
| 1355 | } |
| 1356 | |
| 1357 | // the module has loaded, attempt to import all the game functions |
| 1358 | tOSIRISModule *osm = &OSIRIS_loaded_modules[loaded_id]; |
| 1359 | memcpy(&osm->mod, module_handle, sizeof(module)); |
| 1360 | module *mod = &osm->mod; |
| 1361 | |
| 1362 | // there are 5 functions we need to import |
| 1363 | // GetGOScriptID@4 |
| 1364 | // CreateInstance@4 |
| 1365 | // DestroyInstance@8 |
| 1366 | // CallInstanceEvent@16 |
| 1367 | // SaveRestoreState@8 |
| 1368 | |
| 1369 | osm->InitializeDLL = NULL; |
| 1370 | osm->ShutdownDLL = NULL; |
| 1371 | osm->GetTriggerScriptID = NULL; |
| 1372 | osm->GetCOScriptList = NULL; |
| 1373 | osm->GetGOScriptID = (GetGOScriptID_fp)mod_GetSymbol(mod, "GetGOScriptID", 8); |
| 1374 | osm->CreateInstance = (CreateInstance_fp)mod_GetSymbol(mod, "CreateInstance", 4); |
| 1375 | osm->DestroyInstance = (DestroyInstance_fp)mod_GetSymbol(mod, "DestroyInstance", 8); |
| 1376 | osm->CallInstanceEvent = (CallInstanceEvent_fp)mod_GetSymbol(mod, "CallInstanceEvent", 16); |
| 1377 | osm->SaveRestoreState = (SaveRestoreState_fp)mod_GetSymbol(mod, "SaveRestoreState", 8); |
| 1378 | |
| 1379 | osm->flags = OSIMF_INUSE | OSIMF_DLLELSEWHERE; |
no test coverage detected