From ea86c77088e49195dc20c3b5c5ad8f960389a7df Mon Sep 17 00:00:00 2001 From: Rambo6Glaz <39063367+EpicUsername12@users.noreply.github.com> Date: Wed, 5 Jul 2023 20:20:01 +0200 Subject: [PATCH] Fix UTC offset calculation (#890) --- src/Cafe/OS/libs/nn_act/nn_act.cpp | 43 ++++++++----------- src/Cafe/OS/libs/nn_act/nn_act.h | 3 ++ .../OS/libs/nn_olv/nn_olv_InitializeTypes.cpp | 20 +-------- 3 files changed, 21 insertions(+), 45 deletions(-) diff --git a/src/Cafe/OS/libs/nn_act/nn_act.cpp b/src/Cafe/OS/libs/nn_act/nn_act.cpp index 51cd8ba1..fb1d4d14 100644 --- a/src/Cafe/OS/libs/nn_act/nn_act.cpp +++ b/src/Cafe/OS/libs/nn_act/nn_act.cpp @@ -125,6 +125,21 @@ namespace act return getNNReturnCode(resultCode, actRequest); } + sint64 GetUtcOffset() + { + return ((ppcCyclesSince2000 / ESPRESSO_CORE_CLOCK) - (ppcCyclesSince2000_UTC / ESPRESSO_CORE_CLOCK)) * 1'000'000; + } + + sint32 GetUtcOffsetEx(sint64be* pOutOffset, uint8 slotNo) + { + + if (!pOutOffset) + return 0xc0712c80; + + *pOutOffset = GetUtcOffset(); + return 0; + } + sint32 g_initializeCount = 0; // inc in Initialize and dec in Finalize uint32 Initialize() { @@ -649,30 +664,6 @@ void nnActExport_AcquirePrincipalIdByAccountId(PPCInterpreter_t* hCPU) osLib_returnFromFunction(hCPU, result); } -void nnActExport_GetUtcOffsetEx(PPCInterpreter_t* hCPU) -{ - // GetUtcOffsetEx__Q2_2nn3actFPLUc - ppcDefineParamU32BEPtr(utcOffsetOut, 0); - ppcDefineParamU32(uknParam, 1); - - cemuLog_logDebug(LogType::Force, "Called nn_act.GetUtcOffsetEx"); - - *utcOffsetOut = 0; - - cemuLog_logDebug(LogType::Force, "GetUtcOffsetEx stub"); - - osLib_returnFromFunction(hCPU, 0); -} - -void nnActExport_GetUtcOffset(PPCInterpreter_t* hCPU) -{ - uint64 utcOffset = 0; - - uint64 utcDifferenceInSeconds = (ppcCyclesSince2000_UTC / ESPRESSO_CORE_CLOCK) - (ppcCyclesSince2000 / ESPRESSO_CORE_CLOCK); - - osLib_returnFromFunction64(hCPU, utcDifferenceInSeconds * 1000000ULL); -} - // register account functions void nnAct_load() { @@ -737,8 +728,8 @@ void nnAct_load() // placeholders / incomplete implementations osLib_addFunction("nn_act", "HasNfsAccount__Q2_2nn3actFv", nnActExport_HasNfsAccount); osLib_addFunction("nn_act", "GetHostServerSettings__Q2_2nn3actFPcT1Uc", nnActExport_GetHostServerSettings); - osLib_addFunction("nn_act", "GetUtcOffset__Q2_2nn3actFv", nnActExport_GetUtcOffset); - osLib_addFunction("nn_act", "GetUtcOffsetEx__Q2_2nn3actFPLUc", nnActExport_GetUtcOffsetEx); + cafeExportRegisterFunc(nn::act::GetUtcOffset, "nn_act", "GetUtcOffset__Q2_2nn3actFv", LogType::Placeholder); + cafeExportRegisterFunc(nn::act::GetUtcOffsetEx, "nn_act", "GetUtcOffsetEx__Q2_2nn3actFPLUc", LogType::Placeholder); } diff --git a/src/Cafe/OS/libs/nn_act/nn_act.h b/src/Cafe/OS/libs/nn_act/nn_act.h index d0610a0f..6b0a1236 100644 --- a/src/Cafe/OS/libs/nn_act/nn_act.h +++ b/src/Cafe/OS/libs/nn_act/nn_act.h @@ -19,6 +19,9 @@ namespace act uint32 GetSimpleAddressIdEx(uint32be* simpleAddressId, uint8 slot); uint32 GetTransferableIdEx(uint64* transferableId, uint32 unique, uint8 slot); + sint64 GetUtcOffset(); + sint32 GetUtcOffsetEx(sint64be* pOutOffset, uint8 slotNo); + uint32 AcquireIndependentServiceToken(independentServiceToken_t* token, const char* clientId, uint32 cacheDurationInSeconds); static uint32 getCountryCodeFromSimpleAddress(uint32 simpleAddressId) diff --git a/src/Cafe/OS/libs/nn_olv/nn_olv_InitializeTypes.cpp b/src/Cafe/OS/libs/nn_olv/nn_olv_InitializeTypes.cpp index b71c931a..62a2654d 100644 --- a/src/Cafe/OS/libs/nn_olv/nn_olv_InitializeTypes.cpp +++ b/src/Cafe/OS/libs/nn_olv/nn_olv_InitializeTypes.cpp @@ -16,24 +16,6 @@ namespace nn ParamPackStorage g_ParamPack; DiscoveryResultStorage g_DiscoveryResults; - uint64 get_utc_offset() - { - time_t gmt, rawtime = time(NULL); - struct tm* ptm; - -#if !defined(WIN32) - struct tm gbuf; - ptm = gmtime_r(&rawtime, &gbuf); -#else - ptm = gmtime(&rawtime); -#endif - - ptm->tm_isdst = -1; - gmt = mktime(ptm); - - return (uint64)difftime(rawtime, gmt); - } - sint32 GetOlvAccessKey(uint32_t* pOutKey) { *pOutKey = 0; @@ -77,7 +59,7 @@ namespace nn g_ParamPack.transferableId = transferrableId; strcpy(g_ParamPack.tzName, "CEMU/Olive"); // Should be nn::act::GetTimeZoneId - g_ParamPack.utcOffset = get_utc_offset(); + g_ParamPack.utcOffset = (uint64_t)nn::act::GetUtcOffset() / 1'000'000; char paramPackStr[1024]; snprintf(