bool CGE2Engine::loadGame(int slotNumber) { Common::MemoryReadStream *readStream; // Open up the savegame file Common::String slotName = generateSaveName(slotNumber); Common::InSaveFile *saveFile = g_system->getSavefileManager()->openForLoading(slotName); // Read the data into a data buffer int size = saveFile->size(); byte *dataBuffer = (byte *)malloc(size); saveFile->read(dataBuffer, size); readStream = new Common::MemoryReadStream(dataBuffer, size, DisposeAfterUse::YES); delete saveFile; // Check to see if it's a ScummVM savegame or not char buffer[kSavegameStrSize + 1]; readStream->read(buffer, kSavegameStrSize + 1); if (strncmp(buffer, kSavegameStr, kSavegameStrSize + 1) != 0) { delete readStream; return false; } else { SavegameHeader saveHeader; if (!readSavegameHeader(readStream, saveHeader)) { delete readStream; return false; } // Delete the thumbnail saveHeader.thumbnail->free(); delete saveHeader.thumbnail; } resetGame(); // Get in the savegame syncGame(readStream, nullptr); delete readStream; loadHeroes(); return true; }
int main() { cout << "Welcome to... THE THUNDERDOME!\n" << endl; bool cont = true; do { //create menu cout << "Choose one of the following: " << endl; cout << "\t1. Load heroes\n\t2. Print roster\n\t3. Fight!\n\t4. Quit" << endl; int choice; cin >> choice; if (choice == 1) { cout << "\n\nEnter the name of the file containing your heroes' information: "; cin >> filename; loadHeroes(filename, heroes); for (int i = 0; i < heroes.size(); i++) { heroes[i]->setPowers(); } cout << "\n\n" << heroes.size() << " heroes loaded!\n\n" << endl; } else if (choice == 2) { printRoster(heroes); } else if (choice == 3) { cout << "Let's get ready to rumble!!!" << endl; heroCombat(); } else if (choice == 4) { for (int i = 0; i < heroes.size(); i++) { delete heroes[i]; } break; } } while (cont = true);