Fix NEX DataStore uploads (nlibcurl) and stub Miiverse PostApp (#888)

This commit is contained in:
Rambo6Glaz 2023-07-05 18:59:33 +02:00 committed by GitHub
parent 9499870cc9
commit b0ae008a89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 78 additions and 10 deletions

View File

@ -504,7 +504,7 @@ void export_curl_multi_fdset(PPCInterpreter_t* hCPU)
// fd write set
for (uint32 i = 0; i < h_writeFd.fd_count; i++)
{
cemu_assert_debug(false);
hostFdSet(h_writeFd.fd_array[i], writeFd.GetPtr());
}
// fd exception set
for (uint32 i = 0; i < h_exceptionFd.fd_count; i++)
@ -906,7 +906,8 @@ int sockopt_callback(void* clientp, curl_socket_t curlfd, curlsocktype purpose)
}
size_t read_callback(char* buffer, size_t size, size_t nitems, void* instream)
{
{
nitems = std::min<uint32>(nitems, 0x4000);
CURL_t* curl = (CURL_t*)instream;
cemuLog_logDebug(LogType::Force, "read_callback(0x{}, 0x{:x}, 0x{:x}, 0x{:08x}) [func: 0x{:x}]", (void*)buffer, size, nitems, curl->in_set.GetMPTR(), curl->fread_func_set.GetMPTR());
@ -1385,4 +1386,4 @@ void load()
osLib_addFunction("nlibcurl", "curl_easy_cleanup", export_curl_easy_cleanup);
osLib_addFunction("nlibcurl", "curl_easy_pause", export_curl_easy_pause);
}
}
}

View File

@ -5,6 +5,9 @@
#include "nn_olv_DownloadCommunityTypes.h"
#include "nn_olv_UploadFavoriteTypes.h"
#include "Cafe/OS/libs/proc_ui/proc_ui.h"
#include "Cafe/OS/libs/coreinit/coreinit_Time.h"
namespace nn
{
namespace olv
@ -198,10 +201,35 @@ namespace nn
osLib_returnFromFunction(hCPU, memory_getVirtualOffsetFromPointer(&portalAppParam->serviceToken));
}
uint32 UploadPostDataByPostApp(void *postParam)
static SysAllocator<OSThread_t> s_OlvReleaseBgThread;
SysAllocator<uint8, 1024> s_OlvReleaseBgThreadStack;
SysAllocator<char, 32> s_OlvReleaseBgThreadName;
void StubPostAppReleaseBackground(PPCInterpreter_t* hCPU)
{
cemuLog_log(LogType::Force, "UploadPostDataByPostApp() called. Returning error");
return BUILD_NN_RESULT(NN_RESULT_LEVEL_STATUS, NN_RESULT_MODULE_NN_OLV, 0); // undefined error
coreinit::OSSleepTicks(ESPRESSO_TIMER_CLOCK * 2); // Sleep 2s
ProcUI_SendForegroundMessage();
}
sint32 StubPostApp(void* pAnyPostParam)
{
coreinit::OSCreateThreadType(s_OlvReleaseBgThread.GetPtr(), RPLLoader_MakePPCCallable(StubPostAppReleaseBackground), 0, nullptr, s_OlvReleaseBgThreadStack.GetPtr() + s_OlvReleaseBgThreadStack.GetByteSize(), (sint32)s_OlvReleaseBgThreadStack.GetByteSize(), 0, (1 << 1) | (1 << 3), OSThread_t::THREAD_TYPE::TYPE_APP);
coreinit::OSResumeThread(s_OlvReleaseBgThread.GetPtr());
strcpy(s_OlvReleaseBgThreadName.GetPtr(), "StubPostApp!");
coreinit::OSSetThreadName(s_OlvReleaseBgThread.GetPtr(),s_OlvReleaseBgThreadName.GetPtr());
return OLV_RESULT_SUCCESS;
}
sint32 StubPostAppResult()
{
return OLV_RESULT_STATUS(301); // Cancelled post app
}
// Somehow required, MK8 doesn't even seem to care about the error codes lol
char* UploadedPostData_GetPostId(char* pPostData)
{
pPostData[4] = '\0';
return &pPostData[4];
}
// https://github.com/kinnay/NintendoClients/wiki/Wii-U-Error-Codes#act-error-codes
@ -272,8 +300,17 @@ namespace nn
osLib_addFunction("nn_olv", "GetServiceToken__Q4_2nn3olv6hidden14PortalAppParamCFv", exportPortalAppParam_GetServiceToken);
cafeExportRegisterFunc(UploadPostDataByPostApp, "nn_olv", "UploadPostDataByPostApp__Q2_2nn3olvFPCQ3_2nn3olv28UploadPostDataByPostAppParam", LogType::Placeholder);
cafeExportRegisterFunc(StubPostApp, "nn_olv", "UploadPostDataByPostApp__Q2_2nn3olvFPCQ3_2nn3olv28UploadPostDataByPostAppParam", LogType::Force);
cafeExportRegisterFunc(StubPostApp, "nn_olv", "UploadCommentDataByPostApp__Q2_2nn3olvFPCQ3_2nn3olv31UploadCommentDataByPostAppParam", LogType::Force);
cafeExportRegisterFunc(StubPostApp, "nn_olv", "UploadDirectMessageDataByPostApp__Q2_2nn3olvFPCQ3_2nn3olv37UploadDirectMessageDataByPostAppParam", LogType::Force);
cafeExportRegisterFunc(StubPostAppResult, "nn_olv", "GetResultByPostApp__Q2_2nn3olvFv", LogType::Force);
cafeExportRegisterFunc(StubPostAppResult, "nn_olv", "GetResultWithUploadedPostDataByPostApp__Q2_2nn3olvFPQ3_2nn3olv16UploadedPostData", LogType::Force);
cafeExportRegisterFunc(StubPostAppResult, "nn_olv", "GetResultWithUploadedDirectMessageDataByPostApp__Q2_2nn3olvFPQ3_2nn3olv25UploadedDirectMessageData", LogType::Force);
cafeExportRegisterFunc(StubPostAppResult, "nn_olv", "GetResultWithUploadedCommentDataByPostApp__Q2_2nn3olvFPQ3_2nn3olv19UploadedCommentData", LogType::Force);
cafeExportRegisterFunc(UploadedPostData_GetPostId, "nn_olv", "GetPostId__Q3_2nn3olv16UploadedPostDataCFv", LogType::Force);
}
}
}
}

View File

@ -17,11 +17,38 @@ uint32 ProcUIInForeground(PPCInterpreter_t* hCPU)
return 1; // true means application is in foreground
}
uint32 ProcUIRegisterCallback(uint32 message, MPTR callback, void* data, sint32 ukn)
struct ProcUICallback
{
MPTR callback;
void* data;
sint32 priority;
};
std::unordered_map<uint32, ProcUICallback> g_Callbacks;
uint32 ProcUIRegisterCallback(uint32 message, MPTR callback, void* data, sint32 priority)
{
g_Callbacks.insert_or_assign(message, ProcUICallback{ .callback = callback, .data = data, .priority = priority });
return 0;
}
void ProcUI_SendBackgroundMessage()
{
if (g_Callbacks.contains(PROCUI_STATUS_BACKGROUND))
{
ProcUICallback& callback = g_Callbacks[PROCUI_STATUS_BACKGROUND];
PPCCoreCallback(callback.callback, callback.data);
}
}
void ProcUI_SendForegroundMessage()
{
if (g_Callbacks.contains(PROCUI_STATUS_FOREGROUND))
{
ProcUICallback& callback = g_Callbacks[PROCUI_STATUS_FOREGROUND];
PPCCoreCallback(callback.callback, callback.data);
}
}
void procui_load()
{
cafeExportRegister("proc_ui", ProcUIRegisterCallback, LogType::ProcUi);

View File

@ -1,2 +1,5 @@
void procui_load();
void procui_load();
void ProcUI_SendForegroundMessage();
void ProcUI_SendBackgroundMessage();