yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
oracle_progression_loader.cc
Go to the documentation of this file.
2
3#include <cstdint>
4#include <fstream>
5#include <vector>
6
7#include "absl/strings/str_format.h"
8
9namespace yaze::core {
10
11absl::StatusOr<OracleProgressionState> LoadOracleProgressionFromSrmFile(
12 const std::string& srm_path) {
13 if (srm_path.empty()) {
14 return absl::InvalidArgumentError("SRM path is empty");
15 }
16
17 std::ifstream file(srm_path, std::ios::binary);
18 if (!file.is_open()) {
19 return absl::NotFoundError(
20 absl::StrFormat("Cannot open SRM file: %s", srm_path));
21 }
22
23 file.seekg(0, std::ios::end);
24 const std::streampos end = file.tellg();
25 if (end < 0) {
26 return absl::InternalError(
27 absl::StrFormat("Failed to read SRM file size: %s", srm_path));
28 }
29
30 std::vector<uint8_t> data(static_cast<size_t>(end));
31 file.seekg(0, std::ios::beg);
32 if (!data.empty()) {
33 file.read(reinterpret_cast<char*>(data.data()),
34 static_cast<std::streamsize>(data.size()));
35 if (!file) {
36 return absl::DataLossError(
37 absl::StrFormat("Failed to read SRM file: %s", srm_path));
38 }
39 }
40
41 return OracleProgressionState::ParseFromSRAM(data.data(), data.size());
42}
43
44} // namespace yaze::core
45
absl::StatusOr< OracleProgressionState > LoadOracleProgressionFromSrmFile(const std::string &srm_path)
static OracleProgressionState ParseFromSRAM(const uint8_t *data, size_t len)
Parse progression state from raw SRAM data.