Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call the functions to save/load level seeds in the SP save files #7005

Merged
merged 1 commit into from
Mar 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 29 additions & 27 deletions Source/loadsave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1759,6 +1759,33 @@ void LoadAdditionalMissiles()
}
}

void SaveLevelSeeds(SaveWriter &saveWriter)
{
SaveHelper file(saveWriter, "levelseeds", giNumberOfLevels * (sizeof(uint8_t) + sizeof(uint32_t)));

for (int i = 0; i < giNumberOfLevels; i++) {
file.WriteLE<uint8_t>(LevelSeeds[i] ? 1 : 0);
if (LevelSeeds[i]) {
file.WriteLE<uint32_t>(*LevelSeeds[i]);
}
}
}

void LoadLevelSeeds()
{
LoadHelper file(OpenSaveArchive(gSaveNumber), "levelseeds");
if (!file.IsValid())
return;

for (int i = 0; i < giNumberOfLevels; i++) {
if (file.NextLE<uint8_t>() != 0) {
LevelSeeds[i] = file.NextLE<uint32_t>();
} else {
LevelSeeds[i] = std::nullopt;
}
}
}

const int DiabloItemSaveSize = 368;
const int HellfireItemSaveSize = 372;

Expand Down Expand Up @@ -2027,21 +2054,6 @@ void SaveHotkeys(SaveWriter &saveWriter, const Player &player)
file.WriteLE<uint8_t>(static_cast<uint8_t>(player._pRSplType));
}

void LoadLevelSeeds()
{
LoadHelper file(OpenSaveArchive(gSaveNumber), "levelseeds");
if (!file.IsValid())
return;

for (int i = 0; i < giNumberOfLevels; i++) {
if (file.NextLE<uint8_t>() != 0) {
LevelSeeds[i] = file.NextLE<uint32_t>();
} else {
LevelSeeds[i] = std::nullopt;
}
}
}

void LoadHeroItems(Player &player)
{
LoadHelper file(OpenSaveArchive(gSaveNumber), "heroitems");
Expand Down Expand Up @@ -2155,6 +2167,7 @@ void LoadGame(bool firstflag)
LevelSeeds[i] = std::nullopt;
file.Skip(4); // Skip loading gnLevelTypeTbl
}
LoadLevelSeeds();

Player &myPlayer = *MyPlayer;

Expand Down Expand Up @@ -2320,18 +2333,6 @@ void LoadGame(bool firstflag)
gbIsHellfireSaveGame = gbIsHellfire;
}

void SaveLevelSeeds(SaveWriter &saveWriter)
{
SaveHelper file(saveWriter, "levelseeds", giNumberOfLevels * (sizeof(uint8_t) + sizeof(uint32_t)));

for (int i = 0; i < giNumberOfLevels; i++) {
file.WriteLE<uint8_t>(LevelSeeds[i] ? 1 : 0);
if (LevelSeeds[i]) {
file.WriteLE<uint32_t>(*LevelSeeds[i]);
}
}
}

void SaveHeroItems(SaveWriter &saveWriter, Player &player)
{
size_t itemCount = static_cast<size_t>(NUM_INVLOC) + InventoryGridCells + MaxBeltItems;
Expand Down Expand Up @@ -2566,6 +2567,7 @@ void SaveGameData(SaveWriter &saveWriter)
file.WriteBE<int32_t>(AutoMapScale);

SaveAdditionalMissiles(saveWriter);
SaveLevelSeeds(saveWriter);
}

void SaveGame()
Expand Down
Loading