0x00441FC9
| 331 | |
| 332 | // 0x00441FC9 |
| 333 | std::unique_ptr<S5File> loadSave(Stream& stream) |
| 334 | { |
| 335 | SawyerStreamReader fs(stream); |
| 336 | if (!fs.validateChecksum()) |
| 337 | { |
| 338 | throw Exception::RuntimeError("Invalid checksum"); |
| 339 | } |
| 340 | |
| 341 | auto file = std::make_unique<S5File>(); |
| 342 | |
| 343 | // Read header |
| 344 | fs.readChunk(&file->header, sizeof(file->header)); |
| 345 | |
| 346 | // Read saved details 0x00442087 |
| 347 | if (file->header.hasFlags(HeaderFlags::hasSaveDetails)) |
| 348 | { |
| 349 | file->saveDetails = std::make_unique<SaveDetails>(); |
| 350 | fs.readChunk(file->saveDetails.get(), sizeof(SaveDetails)); |
| 351 | } |
| 352 | if (file->header.type == S5Type::scenario) |
| 353 | { |
| 354 | file->scenarioOptions = std::make_unique<S5::Options>(); |
| 355 | fs.readChunk(&*file->scenarioOptions, sizeof(S5::Options)); |
| 356 | } |
| 357 | // Read packed objects |
| 358 | if (file->header.numPackedObjects > 0) |
| 359 | { |
| 360 | for (auto i = 0; i < file->header.numPackedObjects; ++i) |
| 361 | { |
| 362 | ObjectHeader object; |
| 363 | fs.read(&object, sizeof(ObjectHeader)); |
| 364 | auto unownedObjectData = fs.readChunk(); |
| 365 | std::vector<std::byte> objectData; |
| 366 | objectData.resize(unownedObjectData.size()); |
| 367 | std::copy(std::begin(unownedObjectData), std::end(unownedObjectData), std::begin(objectData)); |
| 368 | file->packedObjects.push_back(std::make_pair(object, std::move(objectData))); |
| 369 | } |
| 370 | // 0x004420B2 |
| 371 | } |
| 372 | |
| 373 | if (file->header.type == S5Type::scenario) |
| 374 | { |
| 375 | // Load required objects |
| 376 | fs.readChunk(file->requiredObjects, sizeof(file->requiredObjects)); |
| 377 | |
| 378 | // Load game state up to just before companies |
| 379 | fs.readChunk(&file->gameState, sizeof(file->gameState)); |
| 380 | // Load game state towns industry and stations |
| 381 | fs.readChunk(&file->gameState.towns, sizeof(file->gameState)); |
| 382 | // Load the rest of gamestate after animations |
| 383 | fs.readChunk(&file->gameState.animations, sizeof(file->gameState)); |
| 384 | file->gameState.general.fixFlags |= enumValue(S5FixFlags::fixFlag1); |
| 385 | // fixState(file->gameState); this doesn't do anything as we have set fixFlag1 |
| 386 | |
| 387 | if ((static_cast<GameStateFlags>(file->gameState.general.flags) & GameStateFlags::tileManagerLoaded) != GameStateFlags::none) |
| 388 | { |
| 389 | // Load tile elements |
| 390 | auto tileElements = fs.readChunk(); |
no test coverage detected