mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
Merge pull request #369 from tv7/feat/json2-value-access
feat(libSceJson2): implement typed construction, indexed and keyed value access, InitParameter2
This commit is contained in:
@@ -567,6 +567,7 @@ void APS5_VABI _ZN3sce4Json6Object8iteratorD1Ev(ObjectIterator* self) { (void)se
|
||||
ObjectIterator* APS5_VABI _ZN3sce4Json6Object8iteratorppEv(ObjectIterator* self) { ++self->it; return self; }
|
||||
Pair* APS5_VABI _ZNK3sce4Json6Object8iteratordeEv(const ObjectIterator* self) { return &*self->it; }
|
||||
bool APS5_VABI _ZNK3sce4Json6Object8iteratorneERKS2_(const ObjectIterator* self, const ObjectIterator* other) { return self->it != other->it; }
|
||||
std::size_t APS5_VABI _ZNK3sce4Json6Object4sizeEv(const Object* self) { return self->items->size(); }
|
||||
|
||||
void APS5_VABI _ZN3sce4Json5ValueC1Ev(Value* self) { Construct(*self); }
|
||||
void APS5_VABI _ZN3sce4Json5ValueC1Eb(Value* self, bool value) { Construct(*self); self->node->type = TypeBoolean; self->node->boolean = value; }
|
||||
@@ -691,6 +692,25 @@ const Value* APS5_VABI _ZNK3sce4Json5ValueixEm(const Value* self, std::size_t in
|
||||
}
|
||||
return &NullAccess(TypeNull, self);
|
||||
}
|
||||
void APS5_VABI _ZN3sce4Json5ValueC1ENS0_9ValueTypeE(Value* self, ValueType type) {
|
||||
Construct(*self);
|
||||
SetType(*self->node, type);
|
||||
}
|
||||
const Value* APS5_VABI _ZNK3sce4Json5Value8getValueEm(const Value* self, std::size_t index) { return _ZNK3sce4Json5ValueixEm(self, index); }
|
||||
const Value* APS5_VABI _ZNK3sce4Json5Value8getValueERKNS0_6StringE(const Value* self, const String* key) {
|
||||
const Node& n = NodeOf(*self);
|
||||
if (key != nullptr && n.type == TypeObject)
|
||||
for (const auto& pair : *n.object.items)
|
||||
if (*pair.key.text == *key->text) return &pair.value;
|
||||
return &NullAccess(TypeNull, self);
|
||||
}
|
||||
Value* APS5_VABI _ZN3sce4Json5Value10referValueEm(Value* self, std::size_t index) {
|
||||
Node& n = NodeOf(*self);
|
||||
if (n.type != TypeArray || index >= n.array.items->size()) return nullptr;
|
||||
auto it = n.array.items->begin();
|
||||
std::advance(it, static_cast<std::ptrdiff_t>(index));
|
||||
return &*it;
|
||||
}
|
||||
Value* APS5_VABI _ZN3sce4Json5Value10referValueERKNS0_6StringE(Value* self, const String* key) {
|
||||
Node& n = NodeOf(*self);
|
||||
if (key == nullptr || n.type != TypeObject) return nullptr;
|
||||
@@ -747,4 +767,31 @@ int APS5_VABI sceJson2Unknown00(void) {
|
||||
NotImplemented_nid_no_patch("6i18OJSvFWk");
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct InitParameter2 {
|
||||
void* allocator;
|
||||
void* userData;
|
||||
std::size_t fileBufferSize;
|
||||
};
|
||||
static_assert(sizeof(InitParameter2) <= 40);
|
||||
|
||||
void APS5_VABI _ZN3sce4Json14InitParameter2C1Ev(InitParameter2* self) {
|
||||
*self = {};
|
||||
}
|
||||
|
||||
void APS5_VABI _ZN3sce4Json14InitParameter212setAllocatorEPNS0_12MemAllocatorEPv(InitParameter2* self, void* allocator, void* userData) {
|
||||
self->allocator = allocator;
|
||||
self->userData = userData;
|
||||
}
|
||||
|
||||
void APS5_VABI _ZN3sce4Json14InitParameter217setFileBufferSizeEm(InitParameter2* self, std::size_t size) {
|
||||
self->fileBufferSize = size;
|
||||
}
|
||||
|
||||
int APS5_VABI _ZN3sce4Json11Initializer10initializeEPKNS0_14InitParameter2E(void* self, const InitParameter2* parameter) {
|
||||
(void)self;
|
||||
if (parameter == nullptr) throw std::invalid_argument("sce::Json::Initializer::initialize: null parameter");
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -71,6 +71,16 @@ Value* APS5_VABI _ZN3sce4Json5Value10referValueERKNS0_6StringE(Value*, const Str
|
||||
const Value* APS5_VABI _ZNK3sce4Json5ValueixEm(const Value*, std::size_t);
|
||||
int APS5_VABI _ZN3sce4Json5Value9serializeERNS0_6StringE(Value*, String*);
|
||||
int APS5_VABI _ZN3sce4Json6Parser5parseERNS0_5ValueEPKcm(Value*, const char*, std::size_t);
|
||||
std::size_t APS5_VABI _ZNK3sce4Json6Object4sizeEv(const Object*);
|
||||
const Object* APS5_VABI _ZNK3sce4Json5Value9getObjectEv(const Value*);
|
||||
void APS5_VABI _ZN3sce4Json5ValueC1ENS0_9ValueTypeE(Value*, std::int32_t);
|
||||
const Value* APS5_VABI _ZNK3sce4Json5Value8getValueEm(const Value*, std::size_t);
|
||||
const Value* APS5_VABI _ZNK3sce4Json5Value8getValueERKNS0_6StringE(const Value*, const String*);
|
||||
Value* APS5_VABI _ZN3sce4Json5Value10referValueEm(Value*, std::size_t);
|
||||
void APS5_VABI _ZN3sce4Json14InitParameter2C1Ev(void*);
|
||||
void APS5_VABI _ZN3sce4Json14InitParameter212setAllocatorEPNS0_12MemAllocatorEPv(void*, void*, void*);
|
||||
void APS5_VABI _ZN3sce4Json14InitParameter217setFileBufferSizeEm(void*, std::size_t);
|
||||
int APS5_VABI _ZN3sce4Json11Initializer10initializeEPKNS0_14InitParameter2E(void*, const void*);
|
||||
}
|
||||
|
||||
static void Check(bool value, int line) {
|
||||
@@ -275,9 +285,65 @@ static void NullAccess() {
|
||||
Require(_ZN3sce4Json11InitializerD1Ev(initializer) == 0);
|
||||
}
|
||||
|
||||
static void ValueAccess() {
|
||||
for (std::int32_t type = TypeNull; type <= TypeObject; ++type) {
|
||||
Value typed{};
|
||||
_ZN3sce4Json5ValueC1ENS0_9ValueTypeE(&typed, type);
|
||||
Require(_ZNK3sce4Json5Value7getTypeEv(&typed) == type);
|
||||
Require(_ZNK3sce4Json5Value5countEv(&typed) == 0);
|
||||
_ZN3sce4Json5ValueD1Ev(&typed);
|
||||
}
|
||||
|
||||
Value root{};
|
||||
_ZN3sce4Json5ValueC1Ev(&root);
|
||||
const char text[] = "{\"list\":[10,20,30],\"name\":\"value\",\"flag\":true}";
|
||||
Require(_ZN3sce4Json6Parser5parseERNS0_5ValueEPKcm(&root, text, sizeof(text) - 1) == 0);
|
||||
Require(_ZNK3sce4Json6Object4sizeEv(_ZNK3sce4Json5Value9getObjectEv(&root)) == 3);
|
||||
|
||||
String key{};
|
||||
_ZN3sce4Json6StringC1EPKc(&key, "list");
|
||||
const Value* list = _ZNK3sce4Json5Value8getValueERKNS0_6StringE(&root, &key);
|
||||
Require(_ZNK3sce4Json5Value7getTypeEv(list) == TypeArray);
|
||||
Require(*_ZNK3sce4Json5Value10getIntegerEv(_ZNK3sce4Json5Value8getValueEm(list, 1)) == 20);
|
||||
Require(_ZNK3sce4Json5Value8getValueEm(list, 2) == _ZNK3sce4Json5ValueixEm(list, 2));
|
||||
Require(_ZNK3sce4Json5Value7getTypeEv(_ZNK3sce4Json5Value8getValueEm(list, 3)) == TypeNull);
|
||||
|
||||
Value* mutableList = _ZN3sce4Json5Value10referValueERKNS0_6StringE(&root, &key);
|
||||
Value* element = _ZN3sce4Json5Value10referValueEm(mutableList, 0);
|
||||
Require(element != nullptr);
|
||||
Require(_ZN3sce4Json5Value3setEl(element, 15) == 0);
|
||||
Require(*_ZNK3sce4Json5Value10getIntegerEv(_ZNK3sce4Json5Value8getValueEm(list, 0)) == 15);
|
||||
Require(_ZN3sce4Json5Value10referValueEm(mutableList, 3) == nullptr);
|
||||
Require(_ZN3sce4Json5Value10referValueEm(&root, 0) == nullptr);
|
||||
_ZN3sce4Json6StringD1Ev(&key);
|
||||
|
||||
String missing{};
|
||||
_ZN3sce4Json6StringC1EPKc(&missing, "missing");
|
||||
Require(_ZNK3sce4Json5Value7getTypeEv(_ZNK3sce4Json5Value8getValueERKNS0_6StringE(&root, &missing)) == TypeNull);
|
||||
_ZN3sce4Json6StringD1Ev(&missing);
|
||||
_ZN3sce4Json5ValueD1Ev(&root);
|
||||
|
||||
alignas(16) std::uint8_t parameter[40];
|
||||
std::memset(parameter, 0xff, sizeof(parameter));
|
||||
_ZN3sce4Json14InitParameter2C1Ev(parameter);
|
||||
int allocator = 0;
|
||||
int userData = 0;
|
||||
_ZN3sce4Json14InitParameter212setAllocatorEPNS0_12MemAllocatorEPv(parameter, &allocator, &userData);
|
||||
_ZN3sce4Json14InitParameter217setFileBufferSizeEm(parameter, 4096);
|
||||
void* stored[3]{};
|
||||
std::memcpy(stored, parameter, sizeof(stored));
|
||||
Require(stored[0] == &allocator && stored[1] == &userData && reinterpret_cast<std::uintptr_t>(stored[2]) == 4096);
|
||||
alignas(16) std::uint8_t initializer[16]{};
|
||||
Require(_ZN3sce4Json11InitializerC1Ev(initializer) == 0);
|
||||
Require(_ZN3sce4Json11Initializer10initializeEPKNS0_14InitParameter2E(initializer, parameter) == 0);
|
||||
Require(_ZN3sce4Json11Initializer9terminateEv(initializer) == 0);
|
||||
Require(_ZN3sce4Json11InitializerD1Ev(initializer) == 0);
|
||||
}
|
||||
|
||||
int main() {
|
||||
ParseAndRoundTrip();
|
||||
NestingDepth();
|
||||
ObjectsAndArrays();
|
||||
NullAccess();
|
||||
ValueAccess();
|
||||
}
|
||||
|
||||
@@ -132,6 +132,7 @@ Throughout the project, every function at every stage either **does exactly what
|
||||
- [sceAgcDcbSetZPassPredicationEnableGetSize, sceAgcDcbSetPredicationDisableGetSize, sceAgcDcbSetBoolPredicationEnableGetSize](../../core/libs/prx/libSceAgc/DcbState/src/Predication.cpp) (libSceAgc) - the builders are inline in the SDK and not exported; the size is assumed to be that of the SET_PREDICATION packet `sceAgcDcbSetPredication` writes (16 bytes)
|
||||
- [Resource registration](../../core/libs/prx/libSceAgcDriver/Resource/src/Registration.cpp) (libSceAgcDriver) - registration always fails with `RESOURCE_REGISTRATION_UNAVAILABLE`, so the owner and resource queries, `sceAgcDriverSetResourceUserData`, `sceAgcDriverFindResourcesPublic` and `sceAgcDriverUnregisterAllResourcesForOwner` return the same error without reading their arguments. Their parameter lists follow the libSceGnmDriver counterparts and are unverified
|
||||
- [sceNgs2VoiceControl sampler filter](../../core/libs/prx/libSceNgs2.native/src/Voice.cpp) (libSceNgs2.native) - param `0x1000000a`, its layout and meaning follow KytyPS5 only: location 1 type 1 is an RBJ low-pass biquad at the system sample rate after resampling, scaled by `level`, a set `channel_mask` bit bypasses that channel, type 0 turns the filter off. Other locations and types throw. The voice keeps playing a filter tail after its last block until the history is zero, with outputs below 1e-20 flushed to zero (a KytyPS5 choice); the console's tail length is unknown
|
||||
- [sce::Json::InitParameter2](../../core/libs/prx/libSceJson2/Export.cpp) (libSceJson2) - layout inferred, not known: assumed to start with the allocator, its user data and the file buffer size, in that order, and the whole struct is assumed to fit in 40 bytes; `Initializer::initialize(InitParameter2)` ignores them as `initialize(InitParameter)` does
|
||||
|
||||
### Functional
|
||||
|
||||
|
||||
Reference in New Issue
Block a user