Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/Core/ELF/ParamSFO.h
3187 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(const std::string &key, unsigned int value, int max_size);
32
void SetValue(const std::string &key, const std::string &value, int max_size);
33
void SetValue(const std::string &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
private:
65
enum ValueType {
66
VT_INT,
67
VT_UTF8,
68
VT_UTF8_SPE // raw data in u8
69
};
70
71
class ValueData {
72
public:
73
ValueType type = VT_INT;
74
int max_size = 0; // Is this meaningful for non-strings?
75
std::string s_value;
76
int i_value = 0;
77
78
u8* u_value = nullptr;
79
unsigned int u_size = 0;
80
81
void SetData(const u8* data, int size);
82
83
~ValueData() {
84
delete[] u_value;
85
}
86
};
87
88
std::map<std::string, ValueData, std::less<>> values;
89
};
90
91
// Utilities for parsing the information.
92
93
// Guessed from GameID, not necessarily accurate
94
// Can't change the order of these.
95
enum class GameRegion {
96
JAPAN,
97
USA,
98
EUROPE,
99
HONGKONG,
100
ASIA,
101
KOREA,
102
COUNT,
103
HOMEBREW = COUNT, // Like other but we actually know it's homebrew.
104
OTHER,
105
};
106
107
GameRegion DetectGameRegionFromID(std::string_view id_version);
108
std::string_view GameRegionToString(GameRegion region); // These strings can be looked up I18NCat::GAME.
109
110