Skip to content

Commit

Permalink
Fix UTC offset calculation (#890)
Browse files Browse the repository at this point in the history
  • Loading branch information
EpicUsername12 committed Jul 5, 2023
1 parent b0ae008 commit ea86c77
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 45 deletions.
43 changes: 17 additions & 26 deletions src/Cafe/OS/libs/nn_act/nn_act.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -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);

}

Expand Down
3 changes: 3 additions & 0 deletions src/Cafe/OS/libs/nn_act/nn_act.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 1 addition & 19 deletions src/Cafe/OS/libs/nn_olv/nn_olv_InitializeTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit ea86c77

Please sign in to comment.