Osiris_LoadGameModule Purpose: Given a module name, 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'
| 1152 | // the module. Returns -1 if the module does not exist. Returns -2 if the module couldn't initialize. |
| 1153 | // Returns -3 if the module is not a game module. Returns -4 if no module slots are available. |
| 1154 | int Osiris_LoadGameModule(char *module_name) { |
| 1155 | if (module_name[0] == '\0') { |
| 1156 | return -1; |
| 1157 | } |
| 1158 | |
| 1159 | int loaded_id; |
| 1160 | loaded_id = Osiris_FindLoadedModule(module_name); |
| 1161 | if (loaded_id != -1) { |
| 1162 | // the module is already loaded |
| 1163 | OSIRIS_loaded_modules[loaded_id].reference_count++; |
| 1164 | if (Show_osiris_debug) { |
| 1165 | mprintf(0, "OSIRIS: Game Module (%s) reference count increased to %d\n", module_name, |
| 1166 | OSIRIS_loaded_modules[loaded_id].reference_count); |
| 1167 | } |
| 1168 | return loaded_id; |
| 1169 | } |
| 1170 | |
| 1171 | // the module hasn't been loaded yet, find an available slot. |
| 1172 | for (loaded_id = 0; loaded_id < MAX_LOADED_MODULES; loaded_id++) { |
| 1173 | if (!(OSIRIS_loaded_modules[loaded_id].flags & OSIMF_INUSE)) { |
| 1174 | // we found a free slot |
| 1175 | break; |
| 1176 | } |
| 1177 | } |
| 1178 | |
| 1179 | if (loaded_id >= MAX_LOADED_MODULES) { |
| 1180 | // no slots available |
| 1181 | mprintf(0, "OSIRIS: Osiris_LoadGameModule(%s): No available slots\n", module_name); |
| 1182 | Int3(); |
| 1183 | return -4; |
| 1184 | } |
| 1185 | |
| 1186 | OSIRIS_loaded_modules[loaded_id].flags = 0; // set this to 0 as we fill in the data |
| 1187 | |
| 1188 | char fullpath[_MAX_PATH], basename[_MAX_PATH]; |
| 1189 | int ret_val = _get_full_path_to_module(module_name, fullpath, basename); |
| 1190 | switch (ret_val) { |
| 1191 | case -2: |
| 1192 | // the module does not exist |
| 1193 | mprintf(0, "OSIRIS: Osiris_LoadLevelModule(%s): Module doesn't exist\n", module_name); |
| 1194 | return -1; |
| 1195 | break; |
| 1196 | case -1: |
| 1197 | // the module is in data\scripts |
| 1198 | break; |
| 1199 | default: |
| 1200 | // the module was an extracted file |
| 1201 | mprintf(0, "OSIRIS: Found module (%s) in a temp file\n", basename); |
| 1202 | OSIRIS_loaded_modules[loaded_id].flags |= OSIMF_INTEMPDIR; |
| 1203 | OSIRIS_loaded_modules[loaded_id].extracted_id = ret_val; |
| 1204 | break; |
| 1205 | } |
| 1206 | |
| 1207 | // the module exists, now attempt to load it |
| 1208 | if (!mod_LoadModule(&OSIRIS_loaded_modules[loaded_id].mod, fullpath)) { |
| 1209 | // there was an error trying to load the module |
| 1210 | mprintf(0, "OSIRIS: Osiris_LoadGameModule(%s): Unable to load module\n", module_name); |
| 1211 | Int3(); |
no test coverage detected