////////////////////////////////////////////////////////////////////////// loads a game from a given slot.
| 262 | /////////////////////////////////////////////////////////////////////////////// |
| 263 | // loads a game from a given slot. |
| 264 | int LoadGameState(const char *pathname) { |
| 265 | CFILE *fp; |
| 266 | int retval = LGS_OK; |
| 267 | char desc[GAMESAVE_DESCLEN + 1]; |
| 268 | char path[_MAX_PATH]; |
| 269 | uint16_t version; |
| 270 | uint16_t curlevel; |
| 271 | int16_t pending_music_region; |
| 272 | IsRestoredGame = true; |
| 273 | // load in stuff |
| 274 | fp = cfopen(pathname, "rb"); |
| 275 | if (!fp) { |
| 276 | Int3(); |
| 277 | return LGS_FILENOTFOUND; |
| 278 | } |
| 279 | |
| 280 | START_VERIFY_SAVEFILE(fp); |
| 281 | gs_Xlates = new gs_tables; |
| 282 | |
| 283 | // read in header and do version check. |
| 284 | cf_ReadBytes((uint8_t *)desc, sizeof(desc), fp); |
| 285 | version = (uint16_t)cf_ReadShort(fp); |
| 286 | if (version < GAMESAVE_OLDVER) { |
| 287 | Int3(); |
| 288 | retval = LGS_OUTDATEDVER; |
| 289 | goto loadsg_error; |
| 290 | } |
| 291 | |
| 292 | retval = LGSSnapshot(fp); // read and clear snapshot. |
| 293 | if (retval > 0) { |
| 294 | bm_FreeBitmap(retval); |
| 295 | } |
| 296 | |
| 297 | // Gamesave_read_version=version; |
| 298 | |
| 299 | // read translation tables |
| 300 | retval = LGSXlateTables(fp); |
| 301 | if (retval != LGS_OK) |
| 302 | goto loadsg_error; |
| 303 | // read in gamemode info. |
| 304 | |
| 305 | // read in mission level info. |
| 306 | curlevel = (uint16_t)cf_ReadShort(fp); |
| 307 | cf_ReadString(path, sizeof(path), fp); |
| 308 | |
| 309 | if ((curlevel > 4) && (stricmp(path, "d3.mn3") == 0)) { |
| 310 | strcpy(path, "d3_2.mn3"); |
| 311 | } |
| 312 | |
| 313 | // must load mission and initialize level before reading in other data. |
| 314 | retval = LGSMission(path, curlevel); |
| 315 | if (retval != LGS_OK) |
| 316 | goto loadsg_error; |
| 317 | |
| 318 | Current_mission.game_state_flags = cf_ReadInt(fp); |
| 319 | // Increase count for how many times this file was restored |
| 320 | IncreaseRestoreCount(pathname); |
| 321 |
no test coverage detected