MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / tryLoadIndex

Function tryLoadIndex

src/OpenLoco/src/Scenario/ScenarioManager.cpp:166–213  ·  view source on GitHub ↗

0x00444611

Source from the content-addressed store, hash-verified

164
165 // 0x00444611
166 static bool tryLoadIndex(const ScenarioFolderState& currentState)
167 {
168 const auto scorePath = Environment::getPath(Environment::PathId::scores);
169 if (!fs::exists(scorePath))
170 {
171 return false;
172 }
173 std::ifstream stream;
174 stream.open(scorePath, std::ios::in | std::ios::binary);
175 if (!stream.is_open())
176 {
177 return false;
178 }
179 // 0x00112A14C -> 160
180 _scenarioHeader = ScoreHeader{};
181 Utility::readData(stream, _scenarioHeader);
182 if (stream.gcount() != sizeof(ScoreHeader))
183 {
184 return false;
185 }
186
187 const auto scenarioListSize = _scenarioHeader.numScenarios * sizeof(ScenarioIndexEntry);
188 _scenarioList.clear();
189 _scenarioList.resize(_scenarioHeader.numScenarios);
190 if (_scenarioList.empty())
191 {
192 exitWithError(StringIds::unable_to_allocate_enough_memory, StringIds::game_init_failure);
193 return false;
194 }
195 Utility::readData(stream, _scenarioList.data(), _scenarioHeader.numScenarios);
196 if (stream.gcount() != static_cast<int32_t>(scenarioListSize))
197 {
198 _scenarioHeader = ScoreHeader{};
199 _scenarioList.clear();
200 return false;
201 }
202 if (currentState != _scenarioHeader.state)
203 {
204 return false;
205 }
206 // version?
207 if ((_scenarioHeader.state.numFiles >> 24) != 1)
208 {
209 return false;
210 }
211
212 return true;
213 }
214
215 static bool loadScenarioDetails(ScenarioIndexEntry& entry, Scenario::Options& options)
216 {

Callers 1

loadIndexFunction · 0.70

Calls 7

getPathFunction · 0.85
exitWithErrorFunction · 0.85
openMethod · 0.80
clearMethod · 0.45
resizeMethod · 0.45
emptyMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected