From 1f695e144f99d340b029ba0b6d07d97153de15ed Mon Sep 17 00:00:00 2001 From: Hat Kid <6624576+Hat-Kid@users.noreply.github.com> Date: Sun, 3 Jul 2022 23:27:23 +0200 Subject: [PATCH] game: read current date correctly for save data (#1590) --- game/sce/libscf.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/game/sce/libscf.cpp b/game/sce/libscf.cpp index 1243696149..427f064f28 100644 --- a/game/sce/libscf.cpp +++ b/game/sce/libscf.cpp @@ -1,5 +1,7 @@ #include "libscf.h" +#include + namespace ee { int sceScfGetAspect() { return SCE_ASPECT_43; @@ -10,13 +12,20 @@ int sceScfGetLanguage() { } void sceCdReadClock(sceCdCLOCK* result) { + time_t t = time(0); + std::tm* date = localtime(&t); + + // convert decimal value into hex value with identical digit representation + // e.g. 60 -> 0x60 + auto convert = [](u8 val) -> u8 { return ((val % 10) * 0x01) + ((val / 10) * 0x10); }; + result->stat = 0; // ?? - result->second = 1; - result->minute = 0x92; - result->hour = 0x76; - result->week = 13; - result->day = 0x99; - result->month = 0x16; - result->year = 0x19; + result->second = convert(date->tm_sec); + result->minute = convert(date->tm_min); + result->hour = convert(date->tm_hour); + result->week = convert((date->tm_yday - date->tm_wday + 7) / 7); + result->day = convert(date->tm_mday); + result->month = convert(date->tm_mon + 1); + result->year = convert(date->tm_year - 100); } } // namespace ee \ No newline at end of file