Repository navigation
Expand file tree
/
Copy pathExport.cpp
More file actions
190 lines (160 loc) · 6.7 KB
/
Copy pathExport.cpp
File metadata and controls
190 lines (160 loc) · 6.7 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#include <cstdint>
#include <cstddef>
#include "SceTypes.hpp"
#include "prx/libc/include/General.hpp"
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <filesystem>
#include <fstream>
#include <stdexcept>
#include <string>
#include <vector>
#ifdef _WIN32
#include <windows.h>
#elif defined(__APPLE__)
#include <mach-o/dyld.h>
#endif
static constexpr int SCE_NP_ENTITLEMENT_ACCESS_ERROR_PARAMETER = static_cast<int>(0x80558003);
static constexpr int SCE_NP_ENTITLEMENT_ACCESS_ERROR_NOT_FOUND = static_cast<int>(0x80558007);
static constexpr int SCE_NP_ERROR_SIGNED_OUT = static_cast<int>(0x80550006);
static constexpr uint32_t SKU_FLAG_FULL = 3;
namespace {
std::filesystem::path EntitlementsPath() {
if (const char* configured = std::getenv("ANYPS5_ENTITLEMENTS"); configured != nullptr && configured[0] != '\0') return configured;
#ifdef _WIN32
wchar_t module[MAX_PATH];
const auto length = GetModuleFileNameW(nullptr, module, MAX_PATH);
if (length == 0 || length == MAX_PATH) throw std::runtime_error("NpEntitlementAccess: cannot locate the executable");
return std::filesystem::path(module).parent_path() / "anyps5-entitlements.ini";
#elif defined(__APPLE__)
std::uint32_t size = 0;
_NSGetExecutablePath(nullptr, &size);
std::vector<char> executable(size);
std::error_code error;
std::filesystem::path path;
if (_NSGetExecutablePath(executable.data(), &size) == 0) path = std::filesystem::canonical(executable.data(), error);
if (path.empty()) throw std::runtime_error("NpEntitlementAccess: cannot locate the executable");
return path.parent_path() / "anyps5-entitlements.ini";
#else
return std::filesystem::read_symlink("/proc/self/exe").parent_path() / "anyps5-entitlements.ini";
#endif
}
const std::vector<NpEntitlementAccessAddcontEntitlementInfo>& OwnedAddons() {
static const auto owned = [] {
std::vector<NpEntitlementAccessAddcontEntitlementInfo> addons;
const auto path = EntitlementsPath();
std::ifstream file(path);
if (!file) {
if (std::getenv("ANYPS5_ENTITLEMENTS") != nullptr || std::filesystem::exists(path)) throw std::runtime_error("NpEntitlementAccess: cannot read " + path.string());
return addons;
}
std::string line;
while (std::getline(file, line)) {
line.erase(std::min(line.find_first_of("#;"), line.size()));
const auto first = line.find_first_not_of(" \t\r");
if (first == std::string::npos) continue;
const auto label = line.substr(first, line.find_last_not_of(" \t\r") + 1 - first);
NpEntitlementAccessAddcontEntitlementInfo info{};
if (label.size() >= sizeof(info.entitlement_label.data)) throw std::runtime_error("NpEntitlementAccess: entitlement label '" + label + "' in " + path.string() + " is longer than 16 characters");
std::memcpy(info.entitlement_label.data, label.data(), label.size());
info.package_type = 3;
info.download_status = 4;
addons.push_back(info);
}
return addons;
}();
return owned;
}
}
extern "C" {
int APS5_VABI sceNpEntitlementAccessGetAddcontEntitlementInfo(uint32_t service_label, const NpUnifiedEntitlementLabel* entitlement_label, NpEntitlementAccessAddcontEntitlementInfo* info) {
(void)service_label;
if (!entitlement_label || !info) return SCE_NP_ENTITLEMENT_ACCESS_ERROR_PARAMETER;
for (const auto& addon : OwnedAddons()) {
if (std::strncmp(addon.entitlement_label.data, entitlement_label->data, sizeof(entitlement_label->data)) == 0) {
*info = addon;
return 0;
}
}
return SCE_NP_ENTITLEMENT_ACCESS_ERROR_NOT_FOUND;
}
int APS5_VABI sceNpEntitlementAccessGetAddcontEntitlementInfoList(uint32_t service_label, NpEntitlementAccessAddcontEntitlementInfo* list, uint32_t list_num, uint32_t* hit_num) {
(void)service_label;
if (!hit_num || (!list && list_num != 0)) return SCE_NP_ENTITLEMENT_ACCESS_ERROR_PARAMETER;
const auto& owned = OwnedAddons();
*hit_num = static_cast<uint32_t>(owned.size());
std::copy_n(owned.begin(), std::min<std::size_t>(list_num, owned.size()), list);
return 0;
}
int APS5_VABI sceNpEntitlementAccessGetSkuFlag(uint32_t* sku_flag) {
if (!sku_flag) return SCE_NP_ENTITLEMENT_ACCESS_ERROR_PARAMETER;
*sku_flag = SKU_FLAG_FULL;
return 0;
}
int APS5_VABI sceNpEntitlementAccessGetEntitlementKey(
uint32_t serviceLabel, const NpUnifiedEntitlementLabel* entitlementLabel,
NpEntitlementAccessEntitlementKey* key) {
(void)serviceLabel;
constexpr int errorParameter = static_cast<int>(0x817D0002);
constexpr int errorNoEntitlement = static_cast<int>(0x817D0007);
if (!entitlementLabel || !key) return errorParameter;
return errorNoEntitlement;
}
int APS5_VABI sceNpEntitlementAccessInitialize(const NpEntitlementAccessInitParam* init_param, NpEntitlementAccessBootParam* boot_param) {
(void)init_param;
(void)boot_param;
return 0;
}
int APS5_VABI sceNpEntitlementAccessAbortRequest(void) {
return 0;
}
int APS5_VABI sceNpEntitlementAccessDeleteRequest(void) {
return 0;
}
int APS5_VABI sceNpEntitlementAccessGenerateTransactionId(void* transaction_id) {
if (!transaction_id) return SCE_NP_ENTITLEMENT_ACCESS_ERROR_PARAMETER;
return SCE_NP_ERROR_SIGNED_OUT;
}
int APS5_VABI sceNpEntitlementAccessPollConsumeEntitlement(void) {
return SCE_NP_ERROR_SIGNED_OUT;
}
int APS5_VABI sceNpEntitlementAccessRequestConsumeUnifiedEntitlement(void) {
return SCE_NP_ERROR_SIGNED_OUT;
}
int APS5_VABI sceNpEntitlementAccessRequestConsumeServiceEntitlement(void) {
return SCE_NP_ERROR_SIGNED_OUT;
}
int APS5_VABI sceNpEntitlementAccessPollServiceEntitlementInfo(void) {
return SCE_NP_ERROR_SIGNED_OUT;
}
int APS5_VABI sceNpEntitlementAccessPollUnifiedEntitlementInfo(void) {
return SCE_NP_ERROR_SIGNED_OUT;
}
int APS5_VABI sceNpEntitlementAccessRequestServiceEntitlementInfo(void) {
return SCE_NP_ERROR_SIGNED_OUT;
}
int APS5_VABI sceNpEntitlementAccessRequestUnifiedEntitlementInfo(void) {
return SCE_NP_ERROR_SIGNED_OUT;
}
int APS5_VABI sceNpEntitlementAccessGetPftFlag(void) {
NotImplemented_nid_no_patch(__func__);
return 0;
}
int APS5_VABI sceNpEntitlementAccessGetGameTrialsFlag(void) {
NotImplemented_nid_no_patch(__func__);
return 0;
}
int APS5_VABI sceNpEntitlementAccessPollServiceEntitlementInfoList() {
return SCE_NP_ERROR_SIGNED_OUT;
}
int APS5_VABI sceNpEntitlementAccessPollUnifiedEntitlementInfoList() {
return SCE_NP_ERROR_SIGNED_OUT;
}
int APS5_VABI sceNpEntitlementAccessRequestServiceEntitlementInfoList() {
return SCE_NP_ERROR_SIGNED_OUT;
}
int APS5_VABI sceNpEntitlementAccessRequestUnifiedEntitlementInfoList() {
return SCE_NP_ERROR_SIGNED_OUT;
}
}