Path: blob/master/RSDKv5/RSDK/User/Core/UserLeaderboards.hpp
1168 views
#ifndef USER_LEADERBOARDS_H1#define USER_LEADERBOARDS_H23namespace RSDK4{5namespace SKU6{7struct LeaderboardID {8int32 idPS4; // leaderboard id (PS4)9int32 idUnknown; // leaderboard id (unknown platform)10int32 idSwitch; // leaderboard id (switch)11const char *idXbox; // Xbox One Leaderboard id (making an assumption based on the MS docs)12const char *idPC; // Leaderboard id (as a string, used for PC platforms)13};1415struct LeaderboardAvail {16int32 start;17int32 length;18};1920struct LeaderboardEntry {21String username;22#if RETRO_REV0223String userID;24#endif25int32 globalRank;26int32 score;27bool32 isUser;28int32 status;29};3031#if RETRO_REV0232enum LeaderboardLoadTypes {33LEADERBOARD_LOAD_INIT,34LEADERBOARD_LOAD_PREV,35LEADERBOARD_LOAD_NEXT,36};3738struct UserLeaderboards;39struct LeaderboardLoadList;4041struct LeaderboardLoadInfo {42LeaderboardLoadList *parent;43int32 status;44LeaderboardAvail avail;45LeaderboardEntry entries[20];46uint8 disableLoadPrev;47uint8 disableLoadNext;48LeaderboardLoadInfo *prev;49LeaderboardLoadInfo *next;50int32 unused;51};5253struct LeaderboardLoadList {54LeaderboardLoadInfo *InitLoadInfo();55void Clear();56void AddLoadInfoPrev(LeaderboardLoadInfo *info);57void AddLoadInfoNext(LeaderboardLoadInfo *info);58void RemoveLoadInfoPrev();59void RemoveLoadInfoNext();6061UserLeaderboards *parent;62void *unused;63int32 count;64LeaderboardLoadInfo *prev;65LeaderboardLoadInfo *next;66LeaderboardLoadInfo *last;67};6869struct LeaderboardEntryInfo {70void Setup();71void HandleTimers();72void LoadLeaderboardEntries(int32 start, uint32 length, int32 type);7374UserLeaderboards *parent;75LeaderboardLoadList *loadList;76LeaderboardLoadTypes loadType;77LeaderboardAvail loadSize;78LeaderboardAvail viewSize;79LeaderboardEntry *entries[200];80};8182// This is the base struct, it serves as the base for any API-specific stats83// This struct should never be removed84struct UserLeaderboards {85UserLeaderboards()86{87memset(&loadList, 0, sizeof(loadList));88memset(&entryInfo, 0, sizeof(entryInfo));8990loadList.parent = this;91entryInfo.loadList = &loadList;92entryInfo.parent = this;93}9495virtual ~UserLeaderboards() = default;9697virtual void StageLoad()98{99this->currentLeaderboard = NULL;100this->status = STATUS_NONE;101102this->loadList.prev = NULL;103this->loadList.next = NULL;104this->loadList.last = NULL;105this->loadList.count = 0;106this->loadList.unused = 0;107108this->entryInfo.Setup();109}110virtual void FrameInit() { entryInfo.HandleTimers(); }111virtual void OnUnknownEvent() {}112#if RETRO_VER_EGS113virtual bool32 CheckLeaderboardsEnabled() { return true; }114#endif115virtual int32 InitLeaderboards() { return 0; }116virtual void FetchLeaderboard(LeaderboardID *leaderboard, bool32 isUser) {}117virtual void LoadLeaderboards(LeaderboardLoadInfo *info) {}118virtual void TrackScore(LeaderboardID *leaderboard, int32 score, void (*callback)(bool32 success, int32 rank)) {}119virtual int32 GetStatus() { return this->status; }120121LeaderboardID *currentLeaderboard;122LeaderboardLoadList loadList;123LeaderboardEntryInfo entryInfo;124int32 status = STATUS_NONE;125int32 userRank = 0;126bool32 isUser = false;127};128#endif129130// Start custom leaderboard code131// this is added because we don't have access to any store APIs that would otherwise use this feature132struct LeaderboardInfo {133char name[0x40];134int32 score;135};136137extern std::vector<LeaderboardInfo> leaderboardList;138139// End custom leaderboard code140141#if RETRO_REV02142extern UserLeaderboards *leaderboards;143144// ====================145// API Cores146// ====================147148// Dummy API149#if RETRO_USERCORE_DUMMY150#include "RSDK/User/Dummy/DummyLeaderboards.hpp"151#endif152153// Steam API154#if RETRO_USERCORE_STEAM155#include "RSDK/User/Steam/SteamLeaderboards.hpp"156#endif157158// Epic Games API159#if RETRO_USERCORE_EOS160#include "RSDK/User/EOS/EOSLeaderboards.hpp"161#endif162163// Switch API164#if RETRO_USERCORE_NX165#include "RSDK/User/NX/NXLeaderboards.hpp"166#endif167168inline void InitLeaderboards() { leaderboards->InitLeaderboards(); }169#if RETRO_VER_EGS170inline bool32 CheckLeaderboardsEnabled() { return leaderboards->CheckLeaderboardsEnabled(); }171#endif172inline void FetchLeaderboard(LeaderboardID *leaderboard, bool32 isUser) { leaderboards->FetchLeaderboard(leaderboard, isUser); }173inline void TrackScore(LeaderboardID *leaderboard, int32 score, void (*callback)(bool32 success, int32 rank))174{175leaderboards->TrackScore(leaderboard, score, callback);176}177inline int32 GetLeaderboardsStatus() { return leaderboards->GetStatus(); }178179inline LeaderboardAvail LeaderboardEntryViewSize() { return leaderboards->entryInfo.viewSize; }180inline LeaderboardAvail LeaderboardEntryLoadSize() { return leaderboards->entryInfo.loadSize; }181inline void LoadLeaderboardEntries(int32 start, uint32 length, int32 type) { leaderboards->entryInfo.LoadLeaderboardEntries(start, length, type); }182void ResetLeaderboardInfo();183LeaderboardEntry *ReadLeaderboardEntry(int32 entryID);184#endif185186} // namespace SKU187} // namespace RSDK188189#endif // USER_LEADERBOARDS_H190191192