Osiris_LoadLevelModule Purpose: Given a module name, it will attempt to load the module as a level 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 could
| 951 | // the module. Returns -1 if the module does not exist. Returns -2 if the module couldn't initialize. |
| 952 | // Returns -3 if the module is not a level module. Returns -4 if no module slots are available. |
| 953 | int Osiris_LoadLevelModule(char *module_name) { |
| 954 | if ((Game_mode & GM_MULTI) && (Netgame.local_role != LR_SERVER)) { |
| 955 | // no scripts for a client! |
| 956 | return -2; |
| 957 | } |
| 958 | |
| 959 | ASSERT(!tOSIRISCurrentLevel.level_loaded); |
| 960 | if (tOSIRISCurrentLevel.level_loaded) { |
| 961 | mprintf(0, "OSIRIS: Trying to load a level dll, when one has already been loaded\n"); |
| 962 | return tOSIRISCurrentLevel.dll_id; |
| 963 | } |
| 964 | |
| 965 | int loaded_id; |
| 966 | loaded_id = Osiris_FindLoadedModule(module_name); |
| 967 | if (loaded_id != -1) { |
| 968 | // the module is already loaded |
| 969 | OSIRIS_loaded_modules[loaded_id].reference_count++; |
| 970 | if (Show_osiris_debug) { |
| 971 | mprintf(0, "OSIRIS: Level Module (%s) reference count increased to %d\n", module_name, |
| 972 | OSIRIS_loaded_modules[loaded_id].reference_count); |
| 973 | } |
| 974 | return loaded_id; |
| 975 | } |
| 976 | |
| 977 | // the module hasn't been loaded yet, find an available slot. |
| 978 | for (loaded_id = 0; loaded_id < MAX_LOADED_MODULES; loaded_id++) { |
| 979 | if (!(OSIRIS_loaded_modules[loaded_id].flags & OSIMF_INUSE)) { |
| 980 | // we found a free slot |
| 981 | break; |
| 982 | } |
| 983 | } |
| 984 | |
| 985 | if (loaded_id >= MAX_LOADED_MODULES) { |
| 986 | // no slots available |
| 987 | mprintf(0, "OSIRIS: Osiris_LoadLevelModule(%s): No available slots\n", module_name); |
| 988 | Int3(); |
| 989 | return -4; |
| 990 | } |
| 991 | |
| 992 | OSIRIS_loaded_modules[loaded_id].flags = 0; // set this to 0 as we fill in the data |
| 993 | |
| 994 | char fullpath[_MAX_PATH], basename[_MAX_PATH]; |
| 995 | int ret_val = _get_full_path_to_module(module_name, fullpath, basename); |
| 996 | switch (ret_val) { |
| 997 | case -2: |
| 998 | // the module does not exist |
| 999 | mprintf(0, "OSIRIS: Osiris_LoadLevelModule(%s): Module doesn't exist\n", module_name); |
| 1000 | return -1; |
| 1001 | break; |
| 1002 | case -1: |
| 1003 | // the module is in data\scripts |
| 1004 | break; |
| 1005 | default: |
| 1006 | // the module was an extracted file |
| 1007 | mprintf(0, "OSIRIS: Found module (%s) in a temp file\n", basename); |
| 1008 | OSIRIS_loaded_modules[loaded_id].flags |= OSIMF_INTEMPDIR; |
| 1009 | OSIRIS_loaded_modules[loaded_id].extracted_id = ret_val; |
| 1010 | break; |
no test coverage detected