Skip to content

Commit

Permalink
Store seed string in the save, and use it for mirror mode & enemy rando
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettjoecox committed Sep 6, 2023
1 parent 644ab7f commit 5ac566e
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 3 deletions.
2 changes: 2 additions & 0 deletions soh/include/z64save.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ typedef struct {
/* */ RandomizerCheck ganonHintCheck;
/* */ RandomizerCheck gregCheck;
/* */ RandomizerCheck dampeCheck;
/* */ char inputSeed[1024];
/* */ u32 finalSeed;
/* */ u8 seedIcons[5];
/* */ u16 randomizerInf[9];
/* */ u16 adultTradeItems;
Expand Down
3 changes: 2 additions & 1 deletion soh/soh/Enhancements/enemyrandomizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "macros.h"
#include "soh/Enhancements/randomizer/3drando/random.hpp"
#include "soh/Enhancements/enhancementTypes.h"
#include "boost_custom/container_hash/hash_32.hpp"
#include "variables.h"

extern "C" {
Expand Down Expand Up @@ -234,7 +235,7 @@ extern "C" uint8_t GetRandomizedEnemy(PlayState* play, int16_t *actorId, f32 *po

EnemyEntry GetRandomizedEnemyEntry(uint32_t seed) {
if (CVarGetInteger("gRandomizedEnemies", ENEMY_RANDOMIZER_OFF) == ENEMY_RANDOMIZER_RANDOM_SEEDED) {
uint32_t finalSeed = seed + (gSaveContext.n64ddFlag ? (gSaveContext.seedIcons[0] + gSaveContext.seedIcons[1] + gSaveContext.seedIcons[2] + gSaveContext.seedIcons[3] + gSaveContext.seedIcons[4]) : gSaveContext.sohStats.fileCreatedAt);
uint32_t finalSeed = seed + (gSaveContext.n64ddFlag ? gSaveContext.finalSeed : gSaveContext.sohStats.fileCreatedAt);
Random_Init(finalSeed);
}

Expand Down
4 changes: 2 additions & 2 deletions soh/soh/Enhancements/mods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <libultraship/bridge.h>
#include "game-interactor/GameInteractor.h"
#include "soh/Enhancements/randomizer/3drando/random.hpp"
#include "boost_custom/container_hash/hash_32.hpp"
#include "tts/tts.h"
#include "soh/Enhancements/boss-rush/BossRushTypes.h"
#include "soh/Enhancements/enhancementTypes.h"
Expand Down Expand Up @@ -566,8 +567,7 @@ void UpdateMirrorModeState(int32_t sceneNum) {
(sceneNum == SCENE_GANON_BOSS);

if (mirroredMode == MIRRORED_WORLD_RANDOM_SEEDED || mirroredMode == MIRRORED_WORLD_DUNGEONS_RANDOM_SEEDED) {
uint32_t seed = sceneNum + (gSaveContext.n64ddFlag ? (gSaveContext.seedIcons[0] + gSaveContext.seedIcons[1] +
gSaveContext.seedIcons[2] + gSaveContext.seedIcons[3] + gSaveContext.seedIcons[4]) : gSaveContext.sohStats.fileCreatedAt);
uint32_t seed = sceneNum + (gSaveContext.n64ddFlag ? gSaveContext.finalSeed : gSaveContext.sohStats.fileCreatedAt);
Random_Init(seed);
}

Expand Down
1 change: 1 addition & 0 deletions soh/soh/Enhancements/randomizer/3drando/spoiler_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,7 @@ const char* SpoilerLog_Write(int language) {

jsonData["version"] = (char*) gBuildVersion;
jsonData["seed"] = Settings::seedString;
jsonData["finalSeed"] = Settings::seed;

// Write Hash
int index = 0;
Expand Down
6 changes: 6 additions & 0 deletions soh/soh/Enhancements/randomizer/randomizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1509,6 +1509,12 @@ void Randomizer::ParseItemLocationsFile(const char* spoilerFileName, bool silent
index++;
}

std::string inputSeed = spoilerFileJson["seed"].get<std::string>();
strncpy(gSaveContext.inputSeed, inputSeed.c_str(), sizeof(gSaveContext.inputSeed) - 1);
gSaveContext.inputSeed[sizeof(gSaveContext.inputSeed) - 1] = 0;

gSaveContext.finalSeed = spoilerFileJson["finalSeed"].get<uint32_t>();

for (auto it = locationsJson.begin(); it != locationsJson.end(); ++it) {
RandomizerCheck randomizerCheck = SpoilerfileCheckNameToEnum[it.key()];
if (it->is_structured()) {
Expand Down
10 changes: 10 additions & 0 deletions soh/soh/SaveManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ void SaveManager::LoadRandomizerVersion2() {
SaveManager::Instance->LoadData("", gSaveContext.seedIcons[i]);
});

std::string inputSeed;
SaveManager::Instance->LoadData("inputSeed", inputSeed);
memcpy(gSaveContext.inputSeed, inputSeed.c_str(), inputSeed.length() + 1);

SaveManager::Instance->LoadData("finalSeed", gSaveContext.finalSeed);

SaveManager::Instance->LoadArray("randoSettings", RSK_MAX, [&](size_t i) {
gSaveContext.randoSettings[i].key = RandomizerSettingKey(i);
SaveManager::Instance->LoadData("", gSaveContext.randoSettings[i].value);
Expand Down Expand Up @@ -294,6 +300,10 @@ void SaveManager::SaveRandomizer(SaveContext* saveContext, int sectionID, bool f
SaveManager::Instance->SaveData("", saveContext->seedIcons[i]);
});

SaveManager::Instance->SaveData("inputSeed", saveContext->inputSeed);

SaveManager::Instance->SaveData("finalSeed", saveContext->finalSeed);

SaveManager::Instance->SaveArray("randoSettings", RSK_MAX, [&](size_t i) {
SaveManager::Instance->SaveData("", saveContext->randoSettings[i].value);
});
Expand Down

0 comments on commit 5ac566e

Please sign in to comment.