Files
AnyPS5/core/libs/tests/GuestNpTrophy2.cpp
T
PacukaandClaude Opus 5.5 30a6e03636 fix(trophy2): accept a null data or details in sceNpTrophy2GetGameInfo
The Smurfs Dreams (Unreal Engine) asks only for the game details and
passes a null data pointer; on success it reads the trophy count from the
details, on a negative result it takes its error path. The function
already fills each output only when it is given, but rejected the call
unless both were. Only a call without either output is rejected now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 17:58:35 +02:00

37 lines
1.3 KiB
C++

#include "prx/libc/include/general/VabiMacros.hpp"
#include "prx/libSceNpTrophy2/include/NpTrophy2Types.hpp"
#include <cstdlib>
#include <stdexcept>
extern "C" {
int APS5_VABI sceNpTrophy2RegisterUnlockCallback(void*, void*);
int APS5_VABI sceNpTrophy2UnregisterUnlockCallback();
int APS5_VABI sceNpTrophy2GetGameInfo(int, int, NpTrophy2GameDetails*, NpTrophy2GameData*);
}
static void Require(bool value) { if (!value) std::abort(); }
static void APS5_VABI OnUnlock(int, int, void*) {}
int main() {
int userdata = 0;
Require(sceNpTrophy2UnregisterUnlockCallback() == 0);
Require(sceNpTrophy2RegisterUnlockCallback(reinterpret_cast<void*>(&OnUnlock), &userdata) == 0);
Require(sceNpTrophy2UnregisterUnlockCallback() == 0);
Require(sceNpTrophy2RegisterUnlockCallback(reinterpret_cast<void*>(&OnUnlock), &userdata) == 0);
Require(sceNpTrophy2UnregisterUnlockCallback() == 0);
NpTrophy2GameDetails details{};
NpTrophy2GameData data{};
Require(sceNpTrophy2GetGameInfo(1, 1, &details, nullptr) == 0);
Require(details.num_trophies != 0);
Require(sceNpTrophy2GetGameInfo(1, 1, nullptr, &data) == 0);
bool threw = false;
try {
sceNpTrophy2GetGameInfo(1, 1, nullptr, nullptr);
} catch (const std::invalid_argument&) {
threw = true;
}
Require(threw);
}