MCPcopy Create free account
hub / github.com/EasyRPG/Player / Load

Method Load

src/game_dynrpg.cpp:412–477  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

410}
411
412void Game_DynRpg::Load(int slot) {
413 if (!Player::IsPatchDynRpg()) {
414 return;
415 }
416
417 InitPlugins();
418
419 std::string filename = get_filename(slot);
420
421 auto in = FileFinder::Save().OpenInputStream(filename);
422
423 if (!in) {
424 Output::Warning("Couldn't read DynRPG save: {}", filename);
425 }
426
427 std::vector<uint8_t> in_buffer;
428 in_buffer.resize(8);
429
430 in.read((char*)in_buffer.data(), 8);
431
432 if (strncmp((char*)in_buffer.data(), "DYNSAVE1", 8) != 0) {
433 Output::Warning("Corrupted DynRPG save: {}", filename);
434 return;
435 }
436
437 while (!(in.eof() || in.fail())) {
438 // Read header length followed by header (Plugin Identifier)
439
440 uint32_t len;
441 in.read((char *) &len, 4);
442 Utils::SwapByteOrder(len);
443
444 in_buffer.resize(len);
445 in.read((char*)in_buffer.data(), len);
446
447 // Find a plugin that feels responsible
448 bool have_one = false;
449
450 for (auto &plugin : plugins) {
451 if (strncmp((char*)in_buffer.data(), plugin->GetIdentifier().data(), len) == 0) {
452 // Chunk length
453 in.read((char *) &len, 4);
454 Utils::SwapByteOrder(len);
455
456 if (len > 0) {
457 // Read chunk
458 in_buffer.resize(len);
459 in.read((char*)in_buffer.data(), len);
460
461 plugin->Load(in_buffer);
462 }
463
464 have_one = true;
465 break;
466 }
467 }
468
469 if (!have_one) {

Callers 2

StartMethod · 0.45
CreateGameObjectsMethod · 0.45

Calls 4

get_filenameFunction · 0.85
OpenInputStreamMethod · 0.80
dataMethod · 0.80
GetIdentifierMethod · 0.80

Tested by

no test coverage detected