Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/Core/ELF/ParamSFO.h
5668 views
1
// Copyright (c) 2012- PPSSPP Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18
#pragma once
19
20
#include <string_view>
21
#include <map>
22
#include <vector>
23
24
#include "Common/CommonTypes.h"
25
#include "Common/Log.h"
26
27
class Path;
28
29
class ParamSFOData {
30
public:
31
void SetValue(std::string_view key, unsigned int value, int max_size);
32
void SetValue(std::string_view key, std::string_view value, int max_size);
33
void SetValue(std::string_view key, const u8 *value, unsigned int size, int max_size);
34
35
int GetValueInt(std::string_view key) const;
36
std::string GetValueString(std::string_view key) const; // Common keys: "TITLE", "DISC_VERSION"
37
bool HasKey(std::string_view key) const;
38
const u8 *GetValueData(std::string_view key, unsigned int *size) const;
39
40
std::vector<std::string> GetKeys() const;
41
std::string GenerateFakeID(const Path &filename) const;
42
43
std::string GetDiscID();
44
45
// This allocates a buffer (*paramsfo) using new[], whose size is zero-filled up to a multiple of 16 bytes.
46
// This is required for SavedataParam::BuildHash.
47
void WriteSFO(u8 **paramsfo, size_t *size) const;
48
49
bool ReadSFO(const u8 *paramsfo, size_t size);
50
bool ReadSFO(const std::vector<u8> &paramsfo) {
51
if (!paramsfo.empty()) {
52
return ReadSFO(&paramsfo[0], paramsfo.size());
53
} else {
54
return false;
55
}
56
}
57
58
// If not found, returns a negative value.
59
int GetDataOffset(const u8 *paramsfo, const char *dataName);
60
61
bool IsValid() const { return !values.empty(); }
62
void Clear();
63
64
enum ValueType {
65
VT_INT,
66
VT_UTF8,
67
VT_UTF8_SPE // raw data in u8
68
};
69
70
class ValueData {
71
public:
72
ValueType type = VT_INT;
73
int max_size = 0; // Is this meaningful for non-strings?
74
std::string s_value;
75
int i_value = 0;
76
77
std::vector<u8> u_value;
78
79
void SetData(const u8* data, int size) {
80
u_value = std::vector<u8>(data, data + size);
81
}
82
};
83
84
// ImDebugger access to the map.
85
const std::map<std::string, ValueData, std::less<>> &Values() {
86
return values;
87
}
88
89
static const char *ValueTypeToString(ValueType t) {
90
switch (t) {
91
case ParamSFOData::VT_INT: return "INT";
92
case ParamSFOData::VT_UTF8: return "UTF8";
93
case ParamSFOData::VT_UTF8_SPE: return "UTF8_SPE";
94
default: return "N/A";
95
}
96
}
97
98
private:
99
std::map<std::string, ValueData, std::less<>> values;
100
};
101
102
// Utilities for parsing the information.
103
104
// Guessed from GameID, not necessarily accurate
105
// Can't change the order of these.
106
enum class GameRegion {
107
JAPAN,
108
USA,
109
EUROPE,
110
HONGKONG,
111
ASIA,
112
KOREA,
113
COUNT,
114
HOMEBREW = COUNT,
115
UNKNOWN,
116
INTERNAL,
117
TEST,
118
DIAGNOSTIC,
119
};
120
121
GameRegion DetectGameRegionFromID(std::string_view id_version);
122
std::string_view GameRegionToString(GameRegion region); // These strings can be looked up I18NCat::GAME.
123
124