mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-08-03 16:02:26 +00:00
nptrophy: GetTrophyUnlockState
This commit is contained in:
parent
625fa2651d
commit
49253fa92a
@ -35,6 +35,45 @@ static Common::SlotVector<OrbisNpTrophyHandle> trophy_handles{};
|
|||||||
static Common::SlotVector<ContextKey> trophy_contexts{};
|
static Common::SlotVector<ContextKey> trophy_contexts{};
|
||||||
static std::unordered_map<ContextKey, TrophyContext, ContextKeyHash> contexts_internal{};
|
static std::unordered_map<ContextKey, TrophyContext, ContextKeyHash> contexts_internal{};
|
||||||
|
|
||||||
|
void ORBIS_NP_TROPHY_FLAG_ZERO(OrbisNpTrophyFlagArray* p) {
|
||||||
|
for (int i = 0; i < ORBIS_NP_TROPHY_NUM_MAX; i++) {
|
||||||
|
uint32_t array_index = i / 32;
|
||||||
|
uint32_t bit_position = i % 32;
|
||||||
|
|
||||||
|
p->flag_bits[array_index] &= ~(1U << bit_position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ORBIS_NP_TROPHY_FLAG_SET(int32_t trophyId, OrbisNpTrophyFlagArray* p) {
|
||||||
|
uint32_t array_index = trophyId / 32;
|
||||||
|
uint32_t bit_position = trophyId % 32;
|
||||||
|
|
||||||
|
p->flag_bits[array_index] |= (1U << bit_position);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ORBIS_NP_TROPHY_FLAG_SET_ALL(OrbisNpTrophyFlagArray* p) {
|
||||||
|
for (int i = 0; i < ORBIS_NP_TROPHY_NUM_MAX; i++) {
|
||||||
|
uint32_t array_index = i / 32;
|
||||||
|
uint32_t bit_position = i % 32;
|
||||||
|
|
||||||
|
p->flag_bits[array_index] |= (1U << bit_position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ORBIS_NP_TROPHY_FLAG_CLR(int32_t trophyId, OrbisNpTrophyFlagArray* p) {
|
||||||
|
uint32_t array_index = trophyId / 32;
|
||||||
|
uint32_t bit_position = trophyId % 32;
|
||||||
|
|
||||||
|
p->flag_bits[array_index] &= ~(1U << bit_position);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ORBIS_NP_TROPHY_FLAG_ISSET(int32_t trophyId, OrbisNpTrophyFlagArray* p) {
|
||||||
|
uint32_t array_index = trophyId / 32;
|
||||||
|
uint32_t bit_position = trophyId % 32;
|
||||||
|
|
||||||
|
return (p->flag_bits[array_index] & (1U << bit_position)) ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
int PS4_SYSV_ABI sceNpTrophyAbortHandle(OrbisNpTrophyHandle handle) {
|
int PS4_SYSV_ABI sceNpTrophyAbortHandle(OrbisNpTrophyHandle handle) {
|
||||||
LOG_ERROR(Lib_NpTrophy, "(STUBBED) called");
|
LOG_ERROR(Lib_NpTrophy, "(STUBBED) called");
|
||||||
return ORBIS_OK;
|
return ORBIS_OK;
|
||||||
@ -201,7 +240,7 @@ int PS4_SYSV_ABI sceNpTrophyGetTrophyInfo(OrbisNpTrophyContext context, OrbisNpT
|
|||||||
s32 PS4_SYSV_ABI sceNpTrophyGetTrophyUnlockState(OrbisNpTrophyContext context,
|
s32 PS4_SYSV_ABI sceNpTrophyGetTrophyUnlockState(OrbisNpTrophyContext context,
|
||||||
OrbisNpTrophyHandle handle,
|
OrbisNpTrophyHandle handle,
|
||||||
OrbisNpTrophyFlagArray* flags, u32* count) {
|
OrbisNpTrophyFlagArray* flags, u32* count) {
|
||||||
LOG_ERROR(Lib_NpTrophy, "(STUBBED) called");
|
LOG_INFO(Lib_NpTrophy, "GetTrophyUnlockState called");
|
||||||
|
|
||||||
if (context == ORBIS_NP_TROPHY_INVALID_CONTEXT)
|
if (context == ORBIS_NP_TROPHY_INVALID_CONTEXT)
|
||||||
return ORBIS_NP_TROPHY_ERROR_INVALID_CONTEXT;
|
return ORBIS_NP_TROPHY_ERROR_INVALID_CONTEXT;
|
||||||
@ -212,11 +251,37 @@ s32 PS4_SYSV_ABI sceNpTrophyGetTrophyUnlockState(OrbisNpTrophyContext context,
|
|||||||
if (flags == nullptr || count == nullptr)
|
if (flags == nullptr || count == nullptr)
|
||||||
return ORBIS_NP_TROPHY_ERROR_INVALID_ARGUMENT;
|
return ORBIS_NP_TROPHY_ERROR_INVALID_ARGUMENT;
|
||||||
|
|
||||||
// flags->flag_bits = 0u;
|
ORBIS_NP_TROPHY_FLAG_ZERO(flags);
|
||||||
// temporary workaround till i implement this properly
|
|
||||||
uint32_t* flagTemp = reinterpret_cast<uint32_t*>(flags);
|
const auto trophyDir =
|
||||||
*flagTemp = 0u;
|
Common::FS::GetUserPath(Common::FS::PathType::MetaDataDir) / game_serial / "TrophyFiles";
|
||||||
*count = 0;
|
|
||||||
|
pugi::xml_document doc;
|
||||||
|
pugi::xml_parse_result result =
|
||||||
|
doc.load_file((trophyDir.string() + "/trophy00/Xml/TROP.XML").c_str());
|
||||||
|
|
||||||
|
int numTrophies = 0;
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
auto trophyconf = doc.child("trophyconf");
|
||||||
|
for (pugi::xml_node_iterator it = trophyconf.children().begin();
|
||||||
|
it != trophyconf.children().end(); ++it) {
|
||||||
|
|
||||||
|
std::string currentTrophyId = it->attribute("id").value();
|
||||||
|
std::string currentTrophyUnlockState = it->attribute("unlockstate").value();
|
||||||
|
|
||||||
|
if (std::string(it->name()) == "trophy") {
|
||||||
|
numTrophies++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentTrophyUnlockState == "unlocked") {
|
||||||
|
ORBIS_NP_TROPHY_FLAG_SET(std::stoi(currentTrophyId), flags);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
LOG_INFO(Lib_NpTrophy, "couldnt parse xml : {}", result.description());
|
||||||
|
|
||||||
|
*count = numTrophies;
|
||||||
return ORBIS_OK;
|
return ORBIS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,6 +39,12 @@ struct OrbisNpTrophyFlagArray {
|
|||||||
flag_bits[ORBIS_NP_TROPHY_FLAG_SETSIZE >> ORBIS_NP_TROPHY_FLAG_BITS_SHIFT];
|
flag_bits[ORBIS_NP_TROPHY_FLAG_SETSIZE >> ORBIS_NP_TROPHY_FLAG_BITS_SHIFT];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void ORBIS_NP_TROPHY_FLAG_ZERO(OrbisNpTrophyFlagArray* p);
|
||||||
|
void ORBIS_NP_TROPHY_FLAG_SET(int32_t trophyId, OrbisNpTrophyFlagArray* p);
|
||||||
|
void ORBIS_NP_TROPHY_FLAG_SET_ALL(OrbisNpTrophyFlagArray* p);
|
||||||
|
void ORBIS_NP_TROPHY_FLAG_CLR(int32_t trophyId, OrbisNpTrophyFlagArray* p);
|
||||||
|
bool ORBIS_NP_TROPHY_FLAG_ISSET(int32_t trophyId, OrbisNpTrophyFlagArray* p);
|
||||||
|
|
||||||
struct OrbisNpTrophyData {
|
struct OrbisNpTrophyData {
|
||||||
size_t size;
|
size_t size;
|
||||||
OrbisNpTrophyId trophyId;
|
OrbisNpTrophyId trophyId;
|
||||||
|
Loading…
Reference in New Issue
Block a user