Updates in cellL10n and sceNpTrophy

* UTF16stoUTF8s updated.
* Added missing return in sceNpTrophyRegisterContext.
* Added sceNpTrophyGetGameInfo.
This commit is contained in:
Alexandro Sánchez Bach 2014-03-09 04:57:19 +01:00
parent 2f65e84562
commit 8461bee32e
3 changed files with 61 additions and 19 deletions

View file

@ -2,6 +2,8 @@
#include "Emu/SysCalls/SysCalls.h"
#include "Emu/SysCalls/SC_FUNC.h"
#include <codecvt>
void cellL10n_init();
Module cellL10n(0x001e, cellL10n_init);
@ -22,24 +24,18 @@ int UTF16stoUTF8s(mem16_ptr_t utf16, mem64_t utf16_len, mem8_ptr_t utf8, mem64_t
if (!utf16.IsGood() || !utf16_len.IsGood() || !utf8_len.IsGood())
return SRCIllegal;
std::wstring wstr = (wchar_t*)Memory.VirtualToRealAddr(utf16);
std::string str;
std::u16string wstr =(char16_t*)Memory.VirtualToRealAddr(utf16);
wstr.resize(utf16_len.GetValue()); // TODO: Is this really the role of utf16_len in this function?
int len = min((int)utf16_len.GetValue(), (int)wstr.size());
int size = (int)WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), len, 0, 0, NULL, NULL);
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>,char16_t> convert;
std::string str = convert.to_bytes(wstr);
if (!utf8.IsGood())
utf8_len = size;
if (utf8_len.GetValue() < size)
if (!utf8.IsGood() || utf8_len.GetValue() < str.size())
utf8_len = str.size();
return DSTExhausted;
#ifdef WIN32
WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), len, &str[0], size, NULL, NULL);
#else
// TODO
#endif
Memory.WriteString(utf8, str);
utf8_len = str.size();
Memory.WriteString(utf8, str.c_str());
return ConversionOK;
}

View file

@ -110,7 +110,7 @@ int sceNpTrophyRegisterContext(u32 context, u32 handle, u32 statusCb_addr, u32 a
if (!Memory.IsGoodAddr(statusCb_addr))
return SCE_NP_TROPHY_ERROR_INVALID_ARGUMENT;
if (options & (~(u64)1))
SCE_NP_TROPHY_ERROR_NOT_SUPPORTED;
return SCE_NP_TROPHY_ERROR_NOT_SUPPORTED;
if (context >= s_npTrophyInstance.contexts.size())
return SCE_NP_TROPHY_ERROR_UNKNOWN_CONTEXT;
// TODO: There are other possible errors
@ -181,9 +181,32 @@ int sceNpTrophyAbortHandle()
return CELL_OK;
}
int sceNpTrophyGetGameInfo()
int sceNpTrophyGetGameInfo(u32 context, u32 handle, mem_ptr_t<SceNpTrophyGameDetails> details, mem_ptr_t<SceNpTrophyGameData> data)
{
UNIMPLEMENTED_FUNC(sceNpTrophy);
sceNpTrophy.Warning("sceNpTrophyGetGameInfo(context=%d, handle=%d, details_addr=0x%x, data_addr=0x%x)",
context, handle, details.GetAddr(), data.GetAddr());
if (!s_npTrophyInstance.m_bInitialized)
return SCE_NP_TROPHY_ERROR_NOT_INITIALIZED;
if (!details.IsGood() || !data.IsGood())
return SCE_NP_TROPHY_ERROR_INVALID_ARGUMENT;
// TODO: There are other possible errors
// sceNpTrophyInternalContext& ctxt = s_npTrophyInstance.contexts[context];
// TODO: This data is faked, implement a XML reader and get it from TROP.SFM
memcpy(details->title, "Trophy Set", SCE_NP_TROPHY_NAME_MAX_SIZE);
memcpy(details->description, "Hey! Implement a XML reader, and load the description from TROP.SFM", SCE_NP_TROPHY_DESCR_MAX_SIZE);
details->numTrophies = 0;
details->numPlatinum = 0;
details->numGold = 0;
details->numSilver = 0;
details->numBronze = 0;
data->unlockedTrophies = 0;
data->unlockedPlatinum = 0;
data->unlockedGold = 0;
data->unlockedSilver = 0;
data->unlockedBronze = 0;
return CELL_OK;
}
@ -229,6 +252,8 @@ int sceNpTrophyGetTrophyInfo(u32 context, u32 handle, s32 trophyId, mem_ptr_t<Sc
// TODO: There are other possible errors
// sceNpTrophyInternalContext& ctxt = s_npTrophyInstance.contexts[context];
// TODO: This data is faked, implement a XML reader and get it from TROP.SFM
memcpy(details->name, "Some Trophy", SCE_NP_TROPHY_NAME_MAX_SIZE);
memcpy(details->description, "Hey! Implement a XML reader, and load the description from TROP.SFM", SCE_NP_TROPHY_DESCR_MAX_SIZE);
details->hidden = false;

View file

@ -57,7 +57,7 @@ enum
SCE_NP_TROPHY_DESCR_MAX_SIZE = 1024,
};
enum
enum SceNpTrophyGrade
{
SCE_NP_TROPHY_GRADE_UNKNOWN = 0,
SCE_NP_TROPHY_GRADE_PLATINUM = 1,
@ -66,6 +66,27 @@ enum
SCE_NP_TROPHY_GRADE_BRONZE = 4,
};
struct SceNpTrophyGameDetails
{
u32 numTrophies;
u32 numPlatinum;
u32 numGold;
u32 numSilver;
u32 numBronze;
u8 title[SCE_NP_TROPHY_TITLE_MAX_SIZE];
u8 description[SCE_NP_TROPHY_GAME_DESCR_MAX_SIZE];
u8 reserved[4];
};
struct SceNpTrophyGameData
{
u32 unlockedTrophies;
u32 unlockedPlatinum;
u32 unlockedGold;
u32 unlockedSilver;
u32 unlockedBronze;
};
struct SceNpTrophyDetails
{
s32 trophyId; // SceNpTrophyId