mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
Merge pull request #995 from CnRJay/fix/appcontent-user-defined-params
fix(libSceAppContent): read user defined app params from param.json
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
static constexpr int SCE_APP_CONTENT_ERROR_PARAMETER = static_cast<int>(0x80D90002);
|
||||
static constexpr int SCE_APP_CONTENT_ERROR_NOT_FOUND = static_cast<int>(0x80D90005);
|
||||
static constexpr int SCE_APP_CONTENT_ERROR_DRM_NO_ENTITLEMENT = static_cast<int>(0x80D90007);
|
||||
static constexpr uint32_t APPPARAM_ID_SKU_FLAG = 1;
|
||||
static constexpr uint32_t APPPARAM_ID_SKU_FLAG = 0;
|
||||
static constexpr int32_t SKU_FLAG_FULL = 3;
|
||||
|
||||
static constexpr char TEMPORARY_MOUNT_POINT[] = "/temp0";
|
||||
@@ -65,8 +65,8 @@ int APS5_VABI sceAppContentAppParamGetInt(uint32_t param_id, int32_t* value) {
|
||||
case APPPARAM_ID_SKU_FLAG:
|
||||
*value = SKU_FLAG_FULL;
|
||||
return 0;
|
||||
case 2: case 3: case 4: case 5:
|
||||
*value = 0;
|
||||
case 1: case 2: case 3: case 4:
|
||||
*value = GetAppUserDefinedParam_nid_postfix(param_id - 1);
|
||||
return 0;
|
||||
default:
|
||||
return SCE_APP_CONTENT_ERROR_PARAMETER;
|
||||
|
||||
@@ -23,6 +23,7 @@ AppTitleId GetAppTitleId_nid_postfix();
|
||||
bool HasAppIcon_nid_postfix();
|
||||
AppIconData GetAppIconData_nid_postfix();
|
||||
std::uint64_t GetAppDownloadDataSizeMiB_nid_postfix();
|
||||
std::int32_t GetAppUserDefinedParam_nid_postfix(std::uint32_t index);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ struct ParsedParamJson {
|
||||
std::string title;
|
||||
std::string titleId;
|
||||
std::uint64_t downloadDataSizeMiB = 0;
|
||||
std::int32_t userDefinedParams[4] = {};
|
||||
};
|
||||
|
||||
ParsedParamJson parseParamJson(const std::filesystem::path& paramJsonPath);
|
||||
|
||||
@@ -18,6 +18,7 @@ bool g_iconLoaded = false;
|
||||
char g_title[128] = {};
|
||||
char g_titleId[12] = {};
|
||||
std::uint64_t g_downloadDataSizeMiB = 0;
|
||||
std::int32_t g_userDefinedParams[4] = {};
|
||||
std::vector<std::uint8_t> g_iconBytes;
|
||||
|
||||
constexpr const char* AppMetadataParamJsonGuestPath = "/app0/sce_sys/param.json";
|
||||
@@ -37,6 +38,7 @@ void ensureTitleLoaded() {
|
||||
copyToFixedBuffer(g_title, sizeof(g_title), parsed.title);
|
||||
copyToFixedBuffer(g_titleId, sizeof(g_titleId), parsed.titleId);
|
||||
g_downloadDataSizeMiB = parsed.downloadDataSizeMiB;
|
||||
std::memcpy(g_userDefinedParams, parsed.userDefinedParams, sizeof(g_userDefinedParams));
|
||||
g_titleLoaded = true;
|
||||
}
|
||||
|
||||
@@ -75,6 +77,12 @@ std::uint64_t GetAppDownloadDataSizeMiB_nid_postfix() {
|
||||
return g_downloadDataSizeMiB;
|
||||
}
|
||||
|
||||
std::int32_t GetAppUserDefinedParam_nid_postfix(std::uint32_t index) {
|
||||
if (index >= 4) throw std::out_of_range("user defined param index out of range");
|
||||
ensureTitleLoaded();
|
||||
return g_userDefinedParams[index];
|
||||
}
|
||||
|
||||
AppTitleId GetAppTitleId_nid_postfix() {
|
||||
ensureTitleLoaded();
|
||||
AppTitleId result{};
|
||||
|
||||
@@ -287,5 +287,14 @@ ParsedParamJson parseParamJson(const std::filesystem::path& paramJsonPath) {
|
||||
result.downloadDataSizeMiB = static_cast<std::uint64_t>(downloadData->numberValue);
|
||||
}
|
||||
}
|
||||
for (int index = 0; index < 4; ++index) {
|
||||
const std::string key = "userDefinedParam" + std::to_string(index + 1);
|
||||
const JsonValue* param = findObjectMember(root, key);
|
||||
if (param == nullptr) continue;
|
||||
const auto& number = param->numberText;
|
||||
if (param->type != JsonType::Number || number.find_first_of(".eE") != std::string::npos) throw std::runtime_error("param.json " + key + " is not an integer");
|
||||
const auto parsed = std::from_chars(number.data(), number.data() + number.size(), result.userDefinedParams[index]);
|
||||
if (parsed.ec != std::errc{} || parsed.ptr != number.data() + number.size()) throw std::runtime_error("param.json " + key + " exceeds int32 range");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ int APS5_VABI sceAppContentAddcontUnmount(const AppContentMountPoint*);
|
||||
int APS5_VABI sceAppContentGetAddcontInfo(uint32_t, const NpUnifiedEntitlementLabel*, void*);
|
||||
int APS5_VABI sceAppContentGetAddcontInfoList(uint32_t, void*, uint32_t, uint32_t*);
|
||||
int APS5_VABI sceAppContentDownloadDataGetAvailableSpaceKb(const AppContentMountPoint*, size_t*);
|
||||
int APS5_VABI sceAppContentAppParamGetInt(uint32_t, int32_t*);
|
||||
}
|
||||
|
||||
static constexpr int ErrorParameter = static_cast<int>(0x80D90002);
|
||||
@@ -21,7 +22,8 @@ int main() {
|
||||
std::filesystem::create_directories("app0/sce_sys");
|
||||
{
|
||||
std::ofstream param("app0/sce_sys/param.json", std::ios::binary);
|
||||
param << R"({"titleId":"PPSA00000","localizedParameters":{"en-US":{"titleName":"Example"}},"downloadDataSize":0})";
|
||||
param << R"({"titleId":"PPSA00000","localizedParameters":{"en-US":{"titleName":"Example"}},"downloadDataSize":0,)"
|
||||
R"("userDefinedParam1":23566,"userDefinedParam2":-7,"userDefinedParam3":0,"userDefinedParam4":2147483647})";
|
||||
Require(static_cast<bool>(param));
|
||||
}
|
||||
AppContentMountPoint download{};
|
||||
@@ -31,6 +33,17 @@ int main() {
|
||||
Require(availableKb == 0);
|
||||
Require(sceAppContentDownloadDataGetAvailableSpaceKb(&download, nullptr) == ErrorParameter);
|
||||
|
||||
const int32_t expectedParams[] = {3, 23566, -7, 0, 2147483647};
|
||||
for (uint32_t id = 0; id < 5; ++id) {
|
||||
int32_t value = 0x5a5a5a5a;
|
||||
Require(sceAppContentAppParamGetInt(id, &value) == 0);
|
||||
Require(value == expectedParams[id]);
|
||||
}
|
||||
int32_t paramValue = 0x5a5a5a5a;
|
||||
Require(sceAppContentAppParamGetInt(5, ¶mValue) == ErrorParameter);
|
||||
Require(paramValue == 0x5a5a5a5a);
|
||||
Require(sceAppContentAppParamGetInt(0, nullptr) == ErrorParameter);
|
||||
|
||||
NpUnifiedEntitlementLabel label{};
|
||||
std::memcpy(&label, "ADDCONT000000001", 16);
|
||||
AppContentMountPoint mountPoint{};
|
||||
|
||||
@@ -33,6 +33,22 @@ static ParsedParamJson ParseText(const std::filesystem::path& path, const std::s
|
||||
return parseParamJson(path);
|
||||
}
|
||||
|
||||
static void CheckUserDefinedParams(const std::filesystem::path& path) {
|
||||
const auto parsed = ParseText(path, R"({"titleId":"PPSA23566","localizedParameters":{"en-US":{"titleName":"Example"}},)"
|
||||
R"("userDefinedParam1":23566,"userDefinedParam3":-7,"userDefinedParam4":2147483647})");
|
||||
Require(parsed.userDefinedParams[0] == 23566 && parsed.userDefinedParams[1] == 0 && parsed.userDefinedParams[2] == -7 &&
|
||||
parsed.userDefinedParams[3] == 2147483647, "Incorrect user defined params");
|
||||
for (const auto* text : {"2147483648", "1.5", "1e3", "\"1\"", "true"}) {
|
||||
bool rejected = false;
|
||||
try {
|
||||
ParseText(path, std::string(R"({"titleId":"PPSA00000","localizedParameters":{"en-US":{"titleName":"Example"}},"userDefinedParam2":)") + text + "}");
|
||||
} catch (const std::exception&) {
|
||||
rejected = true;
|
||||
}
|
||||
Require(rejected, std::string("Accepted invalid user defined param: ") + text);
|
||||
}
|
||||
}
|
||||
|
||||
static void CheckLanguages(const std::filesystem::path& path) {
|
||||
const auto nested = ParseText(path, "{\r\n \"localizedParameters\": {\r\n \"defaultLanguage\": \"en-GB\",\r\n"
|
||||
" \"en-GB\": { \"titleName\": \"British\" }\r\n },\r\n \"titleId\": \"PPSA00001\"\r\n}\r\n");
|
||||
@@ -99,6 +115,7 @@ int main() {
|
||||
Require(rejected, std::string("Accepted invalid download size: ") + text);
|
||||
}
|
||||
CheckLanguages(path);
|
||||
CheckUserDefinedParams(path);
|
||||
} catch (const std::exception& error) {
|
||||
std::cerr << error.what() << '\n';
|
||||
result = 1;
|
||||
|
||||
Reference in New Issue
Block a user