forked from HarbourMasters/Ghostship
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOnFileLoad.cpp
More file actions
106 lines (92 loc) · 4.4 KB
/
Copy pathOnFileLoad.cpp
File metadata and controls
106 lines (92 loc) · 4.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "MiscBehavior.h"
#include "port/Rando/Logic/Logic.h"
#include "port/Rando/Spoiler/Spoiler.h"
#include "port/ui/Notification.h"
extern "C" {
extern struct SaveBuffer gSaveBuffer;
}
bool SpoilerExistsForFileName(std::string fileName) {
nlohmann::json spoilerCheck = Rando::Spoiler::LoadFromFile(fileName);
if (spoilerCheck.empty()) {
Notification::Emit({ .message = "Error: No Spoiler Log found.", .messageColor = ImVec4(0.85f, 0.3f, 0, 1) });
return false;
} else {
return true;
}
}
void Rando::MiscBehavior::OnFileLoad() {
REGISTER_LISTENER(OnGameFileLoad, EVENT_PRIORITY_NORMAL, [](IEvent* event) {
OnGameFileLoad* ev = (OnGameFileLoad*)event;
selectedFileNum = ev->fileNum - 1;
bool loadedFromSpoiler = false;
if (!CVarGetInteger("gRandoSettings.Enabled", 0)) {
gSaveBuffer.files[selectedFileNum]->shipSaveData.saveType = SAVETYPE_VANILLA;
Rando::Logic::shuffledPool.clear();
return;
}
if (!IS_RANDO(selectedFileNum)) {
gSaveBuffer.files[selectedFileNum]->shipSaveData.saveType = SAVETYPE_RANDO;
Rando::Logic::InitializeSaveChecks();
Rando::Logic::InitializeSaveEntrances();
Rando::Logic::InitializeSaveOptions();
if (CVarGetInteger("gRandoSettings.ManualSeedEntry", 0)) {
Rando::Logic::GenerateShuffleList();
} else if (CVarGetInteger("gRandoSettings.UseExistingLog", 0)) {
std::string fileName =
Rando::Spoiler::spoilerLogs.at(CVarGetInteger("gRandoSettings.SpoilerFileIndex", 0));
bool logExists = SpoilerExistsForFileName(fileName);
if (!logExists) {
Rando::Logic::GenerateShuffleList();
} else {
nlohmann::json loadedSpoiler = Rando::Spoiler::LoadFromFile(fileName);
Rando::Spoiler::GenerateFromSpoiler(loadedSpoiler);
loadedFromSpoiler = true;
}
} else {
Rando::Logic::GenerateShuffleList();
}
for (auto& pool : Rando::Logic::shuffledPool) {
RandoSaveCheck randoSaveCheck;
randoSaveCheck.randoItemId = pool.randoItemId;
randoSaveCheck.randoAct = pool.randoAct;
randoSaveCheck.obtained = pool.obtained;
randoSaveCheck.skipped = pool.skipped;
RANDO_SAVE_CHECKS(selectedFileNum)[pool.randoCheckId] = randoSaveCheck;
}
if (!Rando::Logic::shuffledEntrances.empty()) {
for (auto& entrance : Rando::Logic::shuffledEntrances) {
RandoSaveEntrance randoSaveEntrance;
randoSaveEntrance.randoEntranceId = entrance.randoEntranceId;
randoSaveEntrance.destinationId = entrance.destinationId;
RANDO_SAVE_ENTRANCES(selectedFileNum)[entrance.randoEntranceId] = randoSaveEntrance;
}
}
if (!loadedFromSpoiler) {
for (auto& [randoOptionId, optionData] : Rando::StaticData::Options) {
RANDO_SAVE_OPTIONS(selectedFileNum)
[randoOptionId] = CVarGetInteger(optionData.cvar, optionData.defaultValue);
}
}
Notification::Emit(
{ .message = "Spoiler written to Save File.", .messageColor = ImVec4(0, 0.85f, 0.3f, 1) });
save_file_do_save(selectedFileNum);
} else {
Rando::Logic::shuffledPool.clear();
for (size_t i = 0; i < RC_MAX; i++) {
RandoSaveCheck randoSaveCheck = RANDO_SAVE_CHECKS(selectedFileNum)[i];
LevelShuffleEntry entry;
entry.randoCheckId = (RandoCheckId)i;
entry.randoItemId = randoSaveCheck.randoItemId;
entry.randoAct = randoSaveCheck.randoAct;
entry.obtained = randoSaveCheck.obtained;
entry.skipped = randoSaveCheck.skipped;
Rando::Logic::shuffledPool.push_back(entry);
}
Rando::Logic::shuffledEntrances.clear();
for (size_t e = 0; e < RE_MAX; e++) {
RandoSaveEntrance randoSaveEntrance = RANDO_SAVE_ENTRANCES(selectedFileNum)[e];
Rando::Logic::shuffledEntrances.push_back(randoSaveEntrance);
}
}
});
}