refactor: migrate platform interface callbacks from C-style to std::function

This commit is contained in:
MatthewBeshay
2026-04-04 09:42:27 +11:00
parent f11473776c
commit 7ecb17596a
53 changed files with 671 additions and 755 deletions
+10 -12
View File
@@ -1,9 +1,9 @@
#pragma once
#include <functional>
#include "PlatformTypes.h"
// TODO: migrate C-style callbacks (int (*Func)(void*, ...), void* lpParam)
// to std::function or std::function_ref (C++26).
class IPlatformInput {
public:
enum EKeyboardMode {
@@ -53,8 +53,8 @@ public:
unsigned int uiTo) = 0;
virtual void SetKeyRepeatRate(float fRepeatDelaySecs,
float fRepeatRateSecs) = 0;
virtual void SetDebugSequence(const char* chSequenceA, int (*Func)(void*),
void* lpParam) = 0;
virtual void SetDebugSequence(const char* chSequenceA,
std::function<int()> callback) = 0;
[[nodiscard]] virtual float GetIdleSeconds(int iPad) = 0;
[[nodiscard]] virtual bool IsPadConnected(int iPad) = 0;
@@ -82,18 +82,16 @@ public:
virtual EKeyboardResult RequestKeyboard(const wchar_t* Title,
const wchar_t* Text, int iPad,
unsigned int uiMaxChars,
int (*Func)(void*, const bool),
void* lpParam,
std::function<int(bool)> callback,
EKeyboardMode eMode) = 0;
[[nodiscard]] virtual const char* GetText() = 0;
// String verification (TCR 92)
virtual bool VerifyStrings(wchar_t** pwStringA, int iStringC,
int (*Func)(void*, STRING_VERIFY_RESPONSE*),
void* lpParam) = 0;
virtual void CancelQueuedVerifyStrings(int (*Func)(void*,
STRING_VERIFY_RESPONSE*),
void* lpParam) = 0;
virtual bool VerifyStrings(
wchar_t** pwStringA, int iStringC,
std::function<int(STRING_VERIFY_RESPONSE*)> callback) = 0;
virtual void CancelQueuedVerifyStrings(
std::function<int(STRING_VERIFY_RESPONSE*)> callback) = 0;
virtual void CancelAllVerifyInProgress() = 0;
// Mouse
+6 -13
View File
@@ -1,6 +1,7 @@
#pragma once
#include <cstdint>
#include <functional>
#include <string>
#include <vector>
@@ -24,7 +25,6 @@ struct SearchForGamesData {
XOVERLAPPED* pOverlapped;
};
// TODO: migrate C-style callbacks to std::function or std::function_ref (C++26).
class IPlatformNetwork {
public:
enum eJoinFailedReason {
@@ -90,14 +90,9 @@ public:
// Callbacks
virtual void RegisterPlayerChangedCallback(
int iPad,
void (*callback)(void* callbackParam, INetworkPlayer* pPlayer,
bool leaving),
void* callbackParam) = 0;
virtual void UnRegisterPlayerChangedCallback(
int iPad,
void (*callback)(void* callbackParam, INetworkPlayer* pPlayer,
bool leaving),
void* callbackParam) = 0;
std::function<void(INetworkPlayer* pPlayer, bool leaving)>
callback) = 0;
virtual void UnRegisterPlayerChangedCallback(int iPad) = 0;
virtual void HandleSignInChange() = 0;
@@ -134,12 +129,10 @@ public:
[[nodiscard]] virtual bool GetGameSessionInfo(
int iPad, SessionID sessionId, FriendSessionInfo* foundSession) = 0;
virtual void SetSessionsUpdatedCallback(
void (*SessionsUpdatedCallback)(void* pParam),
void* pSearchParam) = 0;
std::function<void()> callback) = 0;
virtual void GetFullFriendSessionInfo(
FriendSessionInfo* foundSession,
void (*FriendSessionUpdatedFn)(bool success, void* pParam),
void* pParam) = 0;
std::function<void(bool success)> callback) = 0;
virtual void ForceFriendsSessionRefresh() = 0;
virtual void FakeLocalPlayerJoined() {}
+15 -23
View File
@@ -1,6 +1,7 @@
#pragma once
#include <cstdint>
#include <functional>
#include <string>
#include "PlatformTypes.h"
@@ -8,8 +9,6 @@
class CXuiStringTable;
// TODO: migrate C-style callbacks (int (*Func)(void*, ...), void* lpParam)
// to std::function or std::function_ref (C++26).
class IPlatformProfile {
public:
struct PROFILESETTINGS {
@@ -40,13 +39,13 @@ public:
virtual unsigned int RequestSignInUI(
bool bFromInvite, bool bLocalGame, bool bNoGuestsAllowed,
bool bMultiplayerSignIn, bool bAddUser,
int (*Func)(void*, const bool, const int iPad), void* lpParam,
std::function<int(bool, int)> callback,
int iQuadrant = XUSER_INDEX_ANY) = 0;
virtual unsigned int DisplayOfflineProfile(
int (*Func)(void*, const bool, const int iPad), void* lpParam,
std::function<int(bool, int)> callback,
int iQuadrant = XUSER_INDEX_ANY) = 0;
virtual unsigned int RequestConvertOfflineToGuestUI(
int (*Func)(void*, const bool, const int iPad), void* lpParam,
std::function<int(bool, int)> callback,
int iQuadrant = XUSER_INDEX_ANY) = 0;
virtual void SetPrimaryPlayerChanged(bool bVal) = 0;
[[nodiscard]] virtual bool QuerySigninStatus() = 0;
@@ -64,27 +63,22 @@ public:
virtual void SetPrimaryPad(int iPad) = 0;
[[nodiscard]] virtual char* GetGamertag(int iPad) = 0;
[[nodiscard]] virtual std::wstring GetDisplayName(int iPad) = 0;
virtual void SetSignInChangeCallback(void (*Func)(void*, bool,
unsigned int),
void* lpParam) = 0;
virtual void SetNotificationsCallback(void (*Func)(void*, std::uint32_t,
unsigned int),
void* lpParam) = 0;
virtual void SetSignInChangeCallback(
std::function<void(bool, unsigned int)> callback) = 0;
virtual void SetNotificationsCallback(
std::function<void(std::uint32_t, unsigned int)> callback) = 0;
[[nodiscard]] virtual bool RegionIsNorthAmerica() = 0;
[[nodiscard]] virtual bool LocaleIsUSorCanada() = 0;
[[nodiscard]] virtual int GetLiveConnectionStatus() = 0;
[[nodiscard]] virtual bool IsSystemUIDisplayed() = 0;
virtual void SetProfileReadErrorCallback(void (*Func)(void*),
void* lpParam) = 0;
virtual void SetProfileReadErrorCallback(
std::function<void()> callback) = 0;
// Profile data
virtual int SetDefaultOptionsCallback(int (*Func)(void*, PROFILESETTINGS*,
const int iPad),
void* lpParam) = 0;
virtual int SetOldProfileVersionCallback(int (*Func)(void*, unsigned char*,
const unsigned short,
const int),
void* lpParam) = 0;
virtual int SetDefaultOptionsCallback(
std::function<int(PROFILESETTINGS*, int)> callback) = 0;
virtual int SetOldProfileVersionCallback(
std::function<int(unsigned char*, unsigned short, int)> callback) = 0;
[[nodiscard]] virtual PROFILESETTINGS* GetDashboardProfileSettings(
int iPad) = 0;
virtual void WriteToProfile(int iQuadrant,
@@ -104,9 +98,7 @@ public:
virtual void ShowProfileCard(int iPad, PlayerUID targetUid) = 0;
[[nodiscard]] virtual bool GetProfileAvatar(
int iPad,
int (*Func)(void* lpParam, std::uint8_t* thumbnailData,
unsigned int thumbnailBytes),
void* lpParam) = 0;
std::function<int(std::uint8_t*, unsigned int)> callback) = 0;
virtual void CancelProfileAvatarRequest() = 0;
// Achievements
+40 -44
View File
@@ -2,6 +2,7 @@
#include <cstdint>
#include <ctime>
#include <functional>
#include <string>
#include <vector>
@@ -13,8 +14,6 @@ struct SAVE_DETAILS;
using PSAVE_DETAILS = SAVE_DETAILS*;
class C4JStringTable;
// TODO: migrate C-style callbacks (int (*Func)(void*, ...), void* lpParam)
// to std::function or std::function_ref (C++26).
class IPlatformStorage {
public:
// Enums live here so both the interface consumer and the concrete
@@ -120,21 +119,21 @@ public:
virtual void Init(unsigned int uiSaveVersion,
const wchar_t* pwchDefaultSaveName, char* pszSavePackName,
int iMinimumSaveSize,
int (*Func)(void*, const ESavingMessage, int),
void* lpParam, const char* szGroupID) = 0;
std::function<int(const ESavingMessage, int)> callback,
const char* szGroupID) = 0;
virtual void ResetSaveData() = 0;
// Messages
virtual EMessageResult RequestMessageBox(
unsigned int uiTitle, unsigned int uiText, unsigned int* uiOptionA,
unsigned int uiOptionC, unsigned int pad = XUSER_INDEX_ANY,
int (*Func)(void*, int, const EMessageResult) = nullptr,
void* lpParam = nullptr, C4JStringTable* pStringTable = nullptr,
std::function<int(int, const EMessageResult)> callback = nullptr,
C4JStringTable* pStringTable = nullptr,
wchar_t* pwchFormatString = nullptr, unsigned int focusButton = 0) = 0;
virtual EMessageResult GetMessageBoxResult() = 0;
// Save device
virtual bool SetSaveDevice(int (*Func)(void*, const bool), void* lpParam,
virtual bool SetSaveDevice(std::function<int(const bool)> callback,
bool bForceResetOfSaveDevice = false) = 0;
virtual void SetSaveDeviceSelected(unsigned int uiPad, bool bSelected) = 0;
virtual bool GetSaveDeviceSelected(unsigned int iPad) = 0;
@@ -147,7 +146,7 @@ public:
virtual bool GetSaveUniqueFilename(char* pszName) = 0;
virtual void SetSaveUniqueFilename(char* szFilename) = 0;
virtual void SetState(ESaveGameControlState eControlState,
int (*Func)(void*, const bool), void* lpParam) = 0;
std::function<int(const bool)> callback) = 0;
virtual void SetSaveDisabled(bool bDisable) = 0;
virtual bool GetSaveDisabled() = 0;
virtual unsigned int GetSaveSize() = 0;
@@ -158,64 +157,60 @@ public:
std::uint8_t* pbImage, unsigned int imageBytes,
std::uint8_t* pbTextData,
unsigned int textDataBytes) = 0;
virtual ESaveGameState SaveSaveData(int (*Func)(void*, const bool),
void* lpParam) = 0;
virtual void CopySaveDataToNewSave(std::uint8_t* pbThumbnail,
unsigned int cbThumbnail,
wchar_t* wchNewName,
int (*Func)(void* lpParam, bool),
void* lpParam) = 0;
virtual ESaveGameState SaveSaveData(
std::function<int(const bool)> callback) = 0;
virtual void CopySaveDataToNewSave(
std::uint8_t* pbThumbnail, unsigned int cbThumbnail,
wchar_t* wchNewName, std::function<int(bool)> callback) = 0;
virtual ESaveGameState DoesSaveExist(bool* pbExists) = 0;
virtual bool EnoughSpaceForAMinSaveGame() = 0;
virtual void SetSaveMessageVPosition(float fY) = 0;
virtual ESaveGameState GetSavesInfo(
int iPad,
int (*Func)(void* lpParam, SAVE_DETAILS* pSaveDetails, const bool),
void* lpParam, char* pszSavePackName) = 0;
std::function<int(SAVE_DETAILS* pSaveDetails, const bool)> callback,
char* pszSavePackName) = 0;
virtual PSAVE_DETAILS ReturnSavesInfo() = 0;
virtual void ClearSavesInfo() = 0;
virtual ESaveGameState LoadSaveDataThumbnail(
PSAVE_INFO pSaveInfo,
int (*Func)(void* lpParam, std::uint8_t* thumbnailData,
unsigned int thumbnailBytes),
void* lpParam) = 0;
std::function<int(std::uint8_t* thumbnailData,
unsigned int thumbnailBytes)>
callback) = 0;
virtual void GetSaveCacheFileInfo(unsigned int fileIndex,
XCONTENT_DATA& xContentData) = 0;
virtual void GetSaveCacheFileInfo(unsigned int fileIndex,
std::uint8_t** ppbImageData,
unsigned int* pImageBytes) = 0;
virtual ESaveGameState LoadSaveData(PSAVE_INFO pSaveInfo,
int (*Func)(void* lpParam, const bool,
const bool),
void* lpParam) = 0;
virtual ESaveGameState DeleteSaveData(PSAVE_INFO pSaveInfo,
int (*Func)(void* lpParam,
const bool),
void* lpParam) = 0;
virtual ESaveGameState LoadSaveData(
PSAVE_INFO pSaveInfo,
std::function<int(const bool, const bool)> callback) = 0;
virtual ESaveGameState DeleteSaveData(
PSAVE_INFO pSaveInfo,
std::function<int(const bool)> callback) = 0;
// DLC
virtual void RegisterMarketplaceCountsCallback(
int (*Func)(void* lpParam, DLC_TMS_DETAILS*, int), void* lpParam) = 0;
std::function<int(DLC_TMS_DETAILS*, int)> callback) = 0;
virtual void SetDLCPackageRoot(char* pszDLCRoot) = 0;
virtual EDLCStatus GetDLCOffers(int iPad,
int (*Func)(void*, int, std::uint32_t, int),
void* lpParam,
std::uint32_t dwOfferTypesBitmask =
XMARKETPLACE_OFFERING_TYPE_CONTENT) = 0;
virtual EDLCStatus GetDLCOffers(
int iPad,
std::function<int(int, std::uint32_t, int)> callback,
std::uint32_t dwOfferTypesBitmask =
XMARKETPLACE_OFFERING_TYPE_CONTENT) = 0;
virtual unsigned int CancelGetDLCOffers() = 0;
virtual void ClearDLCOffers() = 0;
virtual XMARKETPLACE_CONTENTOFFER_INFO& GetOffer(unsigned int dw) = 0;
virtual int GetOfferCount() = 0;
virtual unsigned int InstallOffer(int iOfferIDC, std::uint64_t* ullOfferIDA,
int (*Func)(void*, int, int),
void* lpParam, bool bTrial = false) = 0;
std::function<int(int, int)> callback,
bool bTrial = false) = 0;
virtual unsigned int GetAvailableDLCCount(int iPad) = 0;
virtual EDLCStatus GetInstalledDLC(int iPad, int (*Func)(void*, int, int),
void* lpParam) = 0;
virtual EDLCStatus GetInstalledDLC(
int iPad, std::function<int(int, int)> callback) = 0;
virtual XCONTENT_DATA& GetDLC(unsigned int dw) = 0;
virtual std::uint32_t MountInstalledDLC(
int iPad, std::uint32_t dwDLC,
int (*Func)(void*, int, std::uint32_t, std::uint32_t), void* lpParam,
std::function<int(int, std::uint32_t, std::uint32_t)> callback,
const char* szMountDrive = nullptr) = 0;
virtual unsigned int UnmountInstalledDLC(
const char* szMountDrive = nullptr) = 0;
@@ -228,8 +223,8 @@ public:
int iQuadrant, eGlobalStorage eStorageFacility, eTMS_FileType eFileType,
wchar_t* pwchFilename, std::uint8_t** ppBuffer,
unsigned int* pBufferSize,
int (*Func)(void*, wchar_t*, int, bool, int) = nullptr,
void* lpParam = nullptr, int iAction = 0) = 0;
std::function<int(wchar_t*, int, bool, int)> callback = nullptr,
int iAction = 0) = 0;
virtual bool WriteTMSFile(int iQuadrant, eGlobalStorage eStorageFacility,
wchar_t* pwchFilename, std::uint8_t* pBuffer,
unsigned int bufferSize) = 0;
@@ -239,8 +234,9 @@ public:
virtual ETMSStatus TMSPP_ReadFile(
int iPad, eGlobalStorage eStorageFacility,
eTMS_FILETYPEVAL eFileTypeVal, const char* szFilename,
int (*Func)(void*, int, int, PTMSPP_FILEDATA, const char*) = nullptr,
void* lpParam = nullptr, int iUserData = 0) = 0;
std::function<int(int, int, PTMSPP_FILEDATA, const char*)> callback =
nullptr,
int iUserData = 0) = 0;
// Subfile management (save splitting)
virtual int AddSubfile(int regionIndex) = 0;
@@ -249,7 +245,7 @@ public:
void** data, unsigned int* size) = 0;
virtual void ResetSubfiles() = 0;
virtual void UpdateSubfile(int index, void* data, unsigned int size) = 0;
virtual void SaveSubfiles(int (*Func)(void*, const bool), void* param) = 0;
virtual void SaveSubfiles(std::function<int(const bool)> callback) = 0;
virtual ESaveGameState GetSaveState() = 0;
// Misc
+10 -15
View File
@@ -14,6 +14,7 @@
#include <stdio.h>
#include <string.h>
#include <functional>
#include <string>
#include "../InputActions.h"
@@ -51,8 +52,7 @@ static bool s_scrollSnapTaken = false;
// Text input state (non-blocking keyboard)
static bool s_keyboardActive = false;
static std::string s_textInputBuf;
static int (*s_keyboardCallback)(void*, const bool) = nullptr;
static void* s_keyboardCallbackParam = nullptr;
static std::function<int(bool)> s_keyboardCallback;
// We set all the watched keys
// I don't know if I'll need to change this if we add chat support soon.
@@ -357,9 +357,8 @@ void C_4JInput::Tick() {
s_keysCurrent[SDL_SCANCODE_RETURN] = false;
s_keysCurrent[SDL_SCANCODE_KP_ENTER] = false;
if (s_keyboardCallback) {
s_keyboardCallback(s_keyboardCallbackParam, true);
s_keyboardCallback(true);
s_keyboardCallback = nullptr;
s_keyboardCallbackParam = nullptr;
}
} else if (KPressed(SDL_SCANCODE_ESCAPE)) {
s_keyboardActive = false;
@@ -368,9 +367,8 @@ void C_4JInput::Tick() {
// Consume the key so it doesn't also trigger ACTION_MENU_CANCEL
s_keysCurrent[SDL_SCANCODE_ESCAPE] = false;
if (s_keyboardCallback) {
s_keyboardCallback(s_keyboardCallbackParam, false);
s_keyboardCallback(false);
s_keyboardCallback = nullptr;
s_keyboardCallbackParam = nullptr;
}
}
}
@@ -642,19 +640,17 @@ void C_4JInput::SetJoypadSensitivity(int, float) {}
void C_4JInput::SetJoypadStickAxisMap(int, unsigned int, unsigned int) {}
void C_4JInput::SetJoypadStickTriggerMap(int, unsigned int, unsigned int) {}
void C_4JInput::SetKeyRepeatRate(float, float) {}
void C_4JInput::SetDebugSequence(const char*, int (*)(void*), void*) {}
void C_4JInput::SetDebugSequence(const char*, std::function<int()>) {}
float C_4JInput::GetIdleSeconds(int) { return 0.f; }
bool C_4JInput::IsPadConnected(int iPad) { return iPad == 0; }
EKeyboardResult C_4JInput::RequestKeyboard(const wchar_t*, const wchar_t*, int,
unsigned int,
int (*callback)(void*, const bool),
void* scene,
std::function<int(bool)> callback,
C_4JInput::EKeyboardMode) {
s_keyboardActive = true;
s_textInputBuf.clear();
s_keyboardCallback = callback;
s_keyboardCallbackParam = scene;
s_keyboardCallback = std::move(callback);
SDL_StartTextInput();
return EKeyboardResult::Pending;
}
@@ -664,12 +660,11 @@ bool C_4JInput::GetMenuDisplayed(int iPad) {
}
const char* C_4JInput::GetText() { return s_textInputBuf.c_str(); }
bool C_4JInput::VerifyStrings(wchar_t**, int,
int (*)(void*, STRING_VERIFY_RESPONSE*), void*) {
std::function<int(STRING_VERIFY_RESPONSE*)>) {
return true;
}
void C_4JInput::CancelQueuedVerifyStrings(int (*)(void*,
STRING_VERIFY_RESPONSE*),
void*) {}
void C_4JInput::CancelQueuedVerifyStrings(
std::function<int(STRING_VERIFY_RESPONSE*)>) {}
void C_4JInput::CancelAllVerifyInProgress() {}
// Primary pad (moved from Profile)
+6 -8
View File
@@ -75,8 +75,8 @@ public:
void SetJoypadStickTriggerMap(int iPad, unsigned int uiFrom,
unsigned int uiTo);
void SetKeyRepeatRate(float fRepeatDelaySecs, float fRepeatRateSecs);
void SetDebugSequence(const char* chSequenceA, int (*Func)(void*),
void* lpParam);
void SetDebugSequence(const char* chSequenceA,
std::function<int()> callback);
float GetIdleSeconds(int iPad);
bool IsPadConnected(int iPad);
@@ -97,8 +97,7 @@ public:
// live here. The remaining public API keeps the direct text/callback form.
EKeyboardResult RequestKeyboard(const wchar_t* Title, const wchar_t* Text,
int iPad, unsigned int uiMaxChars,
int (*Func)(void*, const bool),
void* lpParam,
std::function<int(bool)> callback,
C_4JInput::EKeyboardMode eMode);
bool GetMenuDisplayed(int);
const char* GetText();
@@ -127,10 +126,9 @@ public:
//
// Intent Protect players from inappropriate language.
bool VerifyStrings(wchar_t** pwStringA, int iStringC,
int (*Func)(void*, STRING_VERIFY_RESPONSE*),
void* lpParam);
void CancelQueuedVerifyStrings(int (*Func)(void*, STRING_VERIFY_RESPONSE*),
void* lpParam);
std::function<int(STRING_VERIFY_RESPONSE*)> callback);
void CancelQueuedVerifyStrings(
std::function<int(STRING_VERIFY_RESPONSE*)> callback);
void CancelAllVerifyInProgress(void);
int GetMouseX();
+6 -8
View File
@@ -2,6 +2,7 @@
#include <cstdio>
#include <cstring>
#include <functional>
#include "../ProfileConstants.h"
#include "../sdl2/Input.h"
@@ -49,9 +50,8 @@ C_4JProfile::PROFILESETTINGS s_dashboardSettings[XUSER_MAX_COUNT] = {};
char s_gamertags[XUSER_MAX_COUNT][16] = {};
std::wstring s_displayNames[XUSER_MAX_COUNT];
int s_lockedProfile = 0;
int (*s_defaultOptionsCallback)(void*, C_4JProfile::PROFILESETTINGS*,
const int iPad) = nullptr;
void* s_defaultOptionsCallbackParam = nullptr;
std::function<int(C_4JProfile::PROFILESETTINGS*, int)>
s_defaultOptionsCallback;
bool isValidPad(int iPad) { return iPad >= 0 && iPad < XUSER_MAX_COUNT; }
@@ -160,11 +160,9 @@ std::wstring C_4JProfile::GetDisplayName(int iPad) {
return s_displayNames[p];
}
int C_4JProfile::SetDefaultOptionsCallback(int (*Func)(void*, PROFILESETTINGS*,
const int iPad),
void* lpParam) {
s_defaultOptionsCallback = Func;
s_defaultOptionsCallbackParam = lpParam;
int C_4JProfile::SetDefaultOptionsCallback(
std::function<int(PROFILESETTINGS*, int)> callback) {
s_defaultOptionsCallback = std::move(callback);
return 0;
}
+15 -18
View File
@@ -1,6 +1,7 @@
#pragma once
#include <cstdint>
#include <functional>
#include <string>
#include "../PlatformTypes.h"
@@ -58,9 +59,8 @@ public:
bool* pbContentRestricted, int* piAge);
char* GetGamertag(int iPad);
std::wstring GetDisplayName(int iPad);
int SetDefaultOptionsCallback(int (*Func)(void*, PROFILESETTINGS*,
const int iPad),
void* lpParam);
int SetDefaultOptionsCallback(
std::function<int(PROFILESETTINGS*, int)> callback);
PROFILESETTINGS* GetDashboardProfileSettings(int iPad);
void* GetGameDefinedProfileData(int iQuadrant);
void AllowedPlayerCreatedContent(int iPad, bool thisQuadrantOnly,
@@ -72,37 +72,34 @@ public:
void Tick() {}
unsigned int RequestSignInUI(bool, bool, bool, bool, bool,
int (*)(void*, const bool, const int), void*,
std::function<int(bool, int)>,
int = XUSER_INDEX_ANY) {
return 0;
}
unsigned int DisplayOfflineProfile(int (*)(void*, const bool, const int),
void*, int = XUSER_INDEX_ANY) {
unsigned int DisplayOfflineProfile(std::function<int(bool, int)>,
int = XUSER_INDEX_ANY) {
return 0;
}
unsigned int RequestConvertOfflineToGuestUI(int (*)(void*, const bool,
const int),
void*, int = XUSER_INDEX_ANY) {
unsigned int RequestConvertOfflineToGuestUI(std::function<int(bool, int)>,
int = XUSER_INDEX_ANY) {
return 0;
}
void SetPrimaryPlayerChanged(bool) {}
void ShowProfileCard(int, PlayerUID) {}
bool GetProfileAvatar(int, int (*)(void*, std::uint8_t*, unsigned int),
void*) {
bool GetProfileAvatar(int, std::function<int(std::uint8_t*, unsigned int)>) {
return false;
}
void CancelProfileAvatarRequest() {}
void SetSignInChangeCallback(void (*)(void*, bool, unsigned int), void*) {}
void SetNotificationsCallback(void (*)(void*, std::uint32_t, unsigned int),
void*) {}
void SetSignInChangeCallback(std::function<void(bool, unsigned int)>) {}
void SetNotificationsCallback(
std::function<void(std::uint32_t, unsigned int)>) {}
bool RegionIsNorthAmerica() { return false; }
bool LocaleIsUSorCanada() { return false; }
int GetLiveConnectionStatus() { return 0; }
bool IsSystemUIDisplayed() { return false; }
void SetProfileReadErrorCallback(void (*)(void*), void*) {}
int SetOldProfileVersionCallback(int (*)(void*, unsigned char*,
const unsigned short, const int),
void*) {
void SetProfileReadErrorCallback(std::function<void()>) {}
int SetOldProfileVersionCallback(
std::function<int(unsigned char*, unsigned short, int)>) {
return 0;
}
void WriteToProfile(int, bool = false, bool = false) {}
+31 -36
View File
@@ -18,7 +18,7 @@ void C4JStorage::Tick(void) {}
C4JStorage::EMessageResult C4JStorage::RequestMessageBox(
unsigned int uiTitle, unsigned int uiText, unsigned int* uiOptionA,
unsigned int uiOptionC, unsigned int pad,
int (*Func)(void*, int, const C4JStorage::EMessageResult), void* lpParam,
std::function<int(int, const C4JStorage::EMessageResult)> callback,
C4JStringTable* pStringTable, wchar_t* pwchFormatString,
unsigned int focusButton) {
return EMessage_ResultAccept;
@@ -28,7 +28,7 @@ C4JStorage::EMessageResult C4JStorage::GetMessageBoxResult() {
return EMessage_Undefined;
}
bool C4JStorage::SetSaveDevice(int (*Func)(void*, const bool), void* lpParam,
bool C4JStorage::SetSaveDevice(std::function<int(const bool)> callback,
bool bForceResetOfSaveDevice) {
return true;
}
@@ -36,8 +36,8 @@ bool C4JStorage::SetSaveDevice(int (*Func)(void*, const bool), void* lpParam,
void C4JStorage::Init(unsigned int uiSaveVersion,
const wchar_t* pwchDefaultSaveName, char* pszSavePackName,
int iMinimumSaveSize,
int (*Func)(void*, const ESavingMessage, int),
void* lpParam, const char* szGroupID) {}
std::function<int(const ESavingMessage, int)> callback,
const char* szGroupID) {}
void C4JStorage::ResetSaveData() {}
void C4JStorage::SetDefaultSaveNameForKeyboardDisplay(
const wchar_t* pwchDefaultSaveName) {}
@@ -52,7 +52,7 @@ bool C4JStorage::GetSaveUniqueFilename(char* pszName) {
}
void C4JStorage::SetSaveUniqueFilename(char* szFilename) {}
void C4JStorage::SetState(ESaveGameControlState eControlState,
int (*Func)(void*, const bool), void* lpParam) {}
std::function<int(const bool)> callback) {}
void C4JStorage::SetSaveDisabled(bool bDisable) {}
bool C4JStorage::GetSaveDisabled(void) { return false; }
unsigned int C4JStorage::GetSaveSize() { return 0; }
@@ -67,16 +67,14 @@ void C4JStorage::SetSaveImages(std::uint8_t* pbThumbnail,
std::uint8_t* pbImage, unsigned int imageBytes,
std::uint8_t* pbTextData,
unsigned int textDataBytes) {}
C4JStorage::ESaveGameState C4JStorage::SaveSaveData(int (*Func)(void*,
const bool),
void* lpParam) {
C4JStorage::ESaveGameState C4JStorage::SaveSaveData(
std::function<int(const bool)> callback) {
return ESaveGame_Idle;
}
void C4JStorage::CopySaveDataToNewSave(std::uint8_t* pbThumbnail,
unsigned int cbThumbnail,
wchar_t* wchNewName,
int (*Func)(void* lpParam, bool),
void* lpParam) {}
std::function<int(bool)> callback) {}
void C4JStorage::SetSaveDeviceSelected(unsigned int uiPad, bool bSelected) {}
bool C4JStorage::GetSaveDeviceSelected(unsigned int iPad) { return true; }
C4JStorage::ESaveGameState C4JStorage::DoesSaveExist(bool* pbExists) {
@@ -87,17 +85,17 @@ bool C4JStorage::EnoughSpaceForAMinSaveGame() { return true; }
void C4JStorage::SetSaveMessageVPosition(float fY) {}
C4JStorage::ESaveGameState C4JStorage::GetSavesInfo(
int iPad,
int (*Func)(void* lpParam, SAVE_DETAILS* pSaveDetails, const bool),
void* lpParam, char* pszSavePackName) {
std::function<int(SAVE_DETAILS* pSaveDetails, const bool)> callback,
char* pszSavePackName) {
return ESaveGame_Idle;
}
PSAVE_DETAILS C4JStorage::ReturnSavesInfo() { return nullptr; }
void C4JStorage::ClearSavesInfo() {}
C4JStorage::ESaveGameState C4JStorage::LoadSaveDataThumbnail(
PSAVE_INFO pSaveInfo,
int (*Func)(void* lpParam, std::uint8_t* thumbnailData,
unsigned int thumbnailBytes),
void* lpParam) {
std::function<int(std::uint8_t* thumbnailData,
unsigned int thumbnailBytes)>
callback) {
return ESaveGame_Idle;
}
void C4JStorage::GetSaveCacheFileInfo(unsigned int fileIndex,
@@ -111,22 +109,20 @@ void C4JStorage::GetSaveCacheFileInfo(unsigned int fileIndex,
if (pImageBytes) *pImageBytes = 0;
}
C4JStorage::ESaveGameState C4JStorage::LoadSaveData(
PSAVE_INFO pSaveInfo, int (*Func)(void* lpParam, const bool, const bool),
void* lpParam) {
PSAVE_INFO pSaveInfo,
std::function<int(const bool, const bool)> callback) {
return ESaveGame_Idle;
}
C4JStorage::ESaveGameState C4JStorage::DeleteSaveData(PSAVE_INFO pSaveInfo,
int (*Func)(void* lpParam,
const bool),
void* lpParam) {
C4JStorage::ESaveGameState C4JStorage::DeleteSaveData(
PSAVE_INFO pSaveInfo,
std::function<int(const bool)> callback) {
return ESaveGame_Idle;
}
void C4JStorage::RegisterMarketplaceCountsCallback(
int (*Func)(void* lpParam, C4JStorage::DLC_TMS_DETAILS*, int),
void* lpParam) {}
std::function<int(C4JStorage::DLC_TMS_DETAILS*, int)> callback) {}
void C4JStorage::SetDLCPackageRoot(char* pszDLCRoot) {}
C4JStorage::EDLCStatus C4JStorage::GetDLCOffers(
int iPad, int (*Func)(void*, int, std::uint32_t, int), void* lpParam,
int iPad, std::function<int(int, std::uint32_t, int)> callback,
std::uint32_t dwOfferTypesBitmask) {
return EDLC_NoOffers;
}
@@ -137,16 +133,15 @@ XMARKETPLACE_CONTENTOFFER_INFO& C4JStorage::GetOffer(unsigned int dw) {
}
int C4JStorage::GetOfferCount() { return 0; }
unsigned int C4JStorage::InstallOffer(int iOfferIDC, std::uint64_t* ullOfferIDA,
int (*Func)(void*, int, int),
void* lpParam, bool bTrial) {
std::function<int(int, int)> callback,
bool bTrial) {
return 0;
}
unsigned int C4JStorage::GetAvailableDLCCount(int iPad) { return 0; }
C4JStorage::EDLCStatus C4JStorage::GetInstalledDLC(int iPad,
int (*Func)(void*, int, int),
void* lpParam) {
if (Func) {
Func(lpParam, 0, iPad);
C4JStorage::EDLCStatus C4JStorage::GetInstalledDLC(
int iPad, std::function<int(int, int)> callback) {
if (callback) {
callback(0, iPad);
}
return EDLC_NoInstalledDLC;
}
@@ -155,7 +150,7 @@ XCONTENT_DATA& C4JStorage::GetDLC(unsigned int dw) {
}
std::uint32_t C4JStorage::MountInstalledDLC(
int iPad, std::uint32_t dwDLC,
int (*Func)(void*, int, std::uint32_t, std::uint32_t), void* lpParam,
std::function<int(int, std::uint32_t, std::uint32_t)> callback,
const char* szMountDrive) {
return 0;
}
@@ -171,7 +166,7 @@ C4JStorage::ETMSStatus C4JStorage::ReadTMSFile(
int iQuadrant, eGlobalStorage eStorageFacility,
C4JStorage::eTMS_FileType eFileType, wchar_t* pwchFilename,
std::uint8_t** ppBuffer, unsigned int* pBufferSize,
int (*Func)(void*, wchar_t*, int, bool, int), void* lpParam, int iAction) {
std::function<int(wchar_t*, int, bool, int)> callback, int iAction) {
return ETMSStatus_Fail;
}
bool C4JStorage::WriteTMSFile(int iQuadrant, eGlobalStorage eStorageFacility,
@@ -187,7 +182,7 @@ void C4JStorage::StoreTMSPathName(wchar_t* pwchName) {}
C4JStorage::ETMSStatus C4JStorage::TMSPP_ReadFile(
int iPad, C4JStorage::eGlobalStorage eStorageFacility,
C4JStorage::eTMS_FILETYPEVAL eFileTypeVal, const char* szFilename,
int (*Func)(void*, int, int, PTMSPP_FILEDATA, const char*), void* lpParam,
std::function<int(int, int, PTMSPP_FILEDATA, const char*)> callback,
int iUserData) {
return ETMSStatus_Fail;
}
@@ -220,8 +215,8 @@ void C4JStorage::UpdateSubfile(int index, void* data, unsigned int size) {
(void)data;
(void)size;
}
void C4JStorage::SaveSubfiles(int (*Func)(void*, const bool), void* param) {
if (Func) Func(param, true);
void C4JStorage::SaveSubfiles(std::function<int(const bool)> callback) {
if (callback) callback(true);
}
C4JStorage::ESaveGameState C4JStorage::GetSaveState() { return ESaveGame_Idle; }
void C4JStorage::ContinueIncompleteOperation() {}
+37 -39
View File
@@ -2,6 +2,7 @@
#include <cstdint>
#include <ctime>
#include <functional>
#include <string>
#include <vector>
// #include <xtms.h>
@@ -111,20 +112,21 @@ public:
C4JStorage::EMessageResult RequestMessageBox(
unsigned int uiTitle, unsigned int uiText, unsigned int* uiOptionA,
unsigned int uiOptionC, unsigned int pad = XUSER_INDEX_ANY,
int (*Func)(void*, int, const C4JStorage::EMessageResult) = nullptr,
void* lpParam = nullptr, C4JStringTable* pStringTable = nullptr,
std::function<int(int, const C4JStorage::EMessageResult)> callback =
nullptr,
C4JStringTable* pStringTable = nullptr,
wchar_t* pwchFormatString = nullptr, unsigned int focusButton = 0);
C4JStorage::EMessageResult GetMessageBoxResult();
// save device
bool SetSaveDevice(int (*Func)(void*, const bool), void* lpParam,
bool SetSaveDevice(std::function<int(const bool)> callback,
bool bForceResetOfSaveDevice = false);
// savegame
void Init(unsigned int uiSaveVersion, const wchar_t* pwchDefaultSaveName,
char* pszSavePackName, int iMinimumSaveSize,
int (*Func)(void*, const ESavingMessage, int), void* lpParam,
std::function<int(const ESavingMessage, int)> callback,
const char* szGroupID);
void ResetSaveData(); // Call before a new save to clear out stored save
// file name
@@ -135,7 +137,7 @@ public:
bool GetSaveUniqueFilename(char* pszName);
void SetSaveUniqueFilename(char* szFilename);
void SetState(ESaveGameControlState eControlState,
int (*Func)(void*, const bool), void* lpParam);
std::function<int(const bool)> callback);
void SetSaveDisabled(bool bDisable);
bool GetSaveDisabled(void);
unsigned int GetSaveSize();
@@ -148,11 +150,11 @@ public:
unsigned int textDataBytes); // Sets the thumbnail & image for the
// save, optionally setting the
// metadata in the png
C4JStorage::ESaveGameState SaveSaveData(int (*Func)(void*, const bool),
void* lpParam);
C4JStorage::ESaveGameState SaveSaveData(
std::function<int(const bool)> callback);
void CopySaveDataToNewSave(std::uint8_t* pbThumbnail,
unsigned int cbThumbnail, wchar_t* wchNewName,
int (*Func)(void* lpParam, bool), void* lpParam);
std::function<int(bool)> callback);
void SetSaveDeviceSelected(unsigned int uiPad, bool bSelected);
bool GetSaveDeviceSelected(unsigned int iPad);
C4JStorage::ESaveGameState DoesSaveExist(bool* pbExists);
@@ -164,16 +166,16 @@ public:
// Get the info for the saves
C4JStorage::ESaveGameState GetSavesInfo(
int iPad,
int (*Func)(void* lpParam, SAVE_DETAILS* pSaveDetails, const bool),
void* lpParam, char* pszSavePackName);
std::function<int(SAVE_DETAILS* pSaveDetails, const bool)> callback,
char* pszSavePackName);
PSAVE_DETAILS ReturnSavesInfo();
void ClearSavesInfo(); // Clears results
C4JStorage::ESaveGameState LoadSaveDataThumbnail(
PSAVE_INFO pSaveInfo,
int (*Func)(void* lpParam, std::uint8_t* thumbnailData,
unsigned int thumbnailBytes),
void* lpParam); // Get the thumbnail for an individual save referenced
// by pSaveInfo
std::function<int(std::uint8_t* thumbnailData,
unsigned int thumbnailBytes)>
callback); // Get the thumbnail for an individual save referenced
// by pSaveInfo
void GetSaveCacheFileInfo(unsigned int fileIndex,
XCONTENT_DATA& xContentData);
@@ -182,41 +184,36 @@ public:
unsigned int* pImageBytes);
// Load the save. Need to call GetSaveData once the callback is called
C4JStorage::ESaveGameState LoadSaveData(PSAVE_INFO pSaveInfo,
int (*Func)(void* lpParam,
const bool, const bool),
void* lpParam);
C4JStorage::ESaveGameState DeleteSaveData(PSAVE_INFO pSaveInfo,
int (*Func)(void* lpParam,
const bool),
void* lpParam);
C4JStorage::ESaveGameState LoadSaveData(
PSAVE_INFO pSaveInfo,
std::function<int(const bool, const bool)> callback);
C4JStorage::ESaveGameState DeleteSaveData(
PSAVE_INFO pSaveInfo,
std::function<int(const bool)> callback);
// DLC
void RegisterMarketplaceCountsCallback(
int (*Func)(void* lpParam, C4JStorage::DLC_TMS_DETAILS*, int),
void* lpParam);
std::function<int(C4JStorage::DLC_TMS_DETAILS*, int)> callback);
void SetDLCPackageRoot(char* pszDLCRoot);
C4JStorage::EDLCStatus GetDLCOffers(
int iPad, int (*Func)(void*, int, std::uint32_t, int), void* lpParam,
int iPad, std::function<int(int, std::uint32_t, int)> callback,
std::uint32_t dwOfferTypesBitmask = XMARKETPLACE_OFFERING_TYPE_CONTENT);
unsigned int CancelGetDLCOffers();
void ClearDLCOffers();
XMARKETPLACE_CONTENTOFFER_INFO& GetOffer(unsigned int dw);
int GetOfferCount();
unsigned int InstallOffer(int iOfferIDC, std::uint64_t* ullOfferIDA,
int (*Func)(void*, int, int), void* lpParam,
std::function<int(int, int)> callback,
bool bTrial = false);
unsigned int GetAvailableDLCCount(int iPad);
C4JStorage::EDLCStatus GetInstalledDLC(int iPad,
int (*Func)(void*, int, int),
void* lpParam);
C4JStorage::EDLCStatus GetInstalledDLC(
int iPad, std::function<int(int, int)> callback);
XCONTENT_DATA& GetDLC(unsigned int dw);
std::uint32_t MountInstalledDLC(int iPad, std::uint32_t dwDLC,
int (*Func)(void*, int, std::uint32_t,
std::uint32_t),
void* lpParam,
const char* szMountDrive = nullptr);
std::uint32_t MountInstalledDLC(
int iPad, std::uint32_t dwDLC,
std::function<int(int, std::uint32_t, std::uint32_t)> callback,
const char* szMountDrive = nullptr);
unsigned int UnmountInstalledDLC(const char* szMountDrive = nullptr);
void GetMountedDLCFileList(const char* szMountDrive,
std::vector<std::string>& fileList);
@@ -227,8 +224,8 @@ public:
int iQuadrant, eGlobalStorage eStorageFacility,
C4JStorage::eTMS_FileType eFileType, wchar_t* pwchFilename,
std::uint8_t** ppBuffer, unsigned int* pBufferSize,
int (*Func)(void*, wchar_t*, int, bool, int) = nullptr,
void* lpParam = nullptr, int iAction = 0);
std::function<int(wchar_t*, int, bool, int)> callback = nullptr,
int iAction = 0);
bool WriteTMSFile(int iQuadrant, eGlobalStorage eStorageFacility,
wchar_t* pwchFilename, std::uint8_t* pBuffer,
unsigned int bufferSize);
@@ -250,8 +247,9 @@ public:
C4JStorage::ETMSStatus TMSPP_ReadFile(
int iPad, C4JStorage::eGlobalStorage eStorageFacility,
C4JStorage::eTMS_FILETYPEVAL eFileTypeVal, const char* szFilename,
int (*Func)(void*, int, int, PTMSPP_FILEDATA, const char*) = nullptr,
void* lpParam = nullptr, int iUserData = 0);
std::function<int(int, int, PTMSPP_FILEDATA, const char*)> callback =
nullptr,
int iUserData = 0);
// Older TMS++ list/delete helpers stayed platform-specific. The shared
// surface keeps the read path plus CRC/subfile helpers below.
@@ -273,7 +271,7 @@ public:
unsigned int* size);
void ResetSubfiles();
void UpdateSubfile(int index, void* data, unsigned int size);
void SaveSubfiles(int (*Func)(void*, const bool), void* param);
void SaveSubfiles(std::function<int(const bool)> callback);
ESaveGameState GetSaveState();
void ContinueIncompleteOperation();