//
// GameStatsManager::preSaveGameStats from 0x1402f87b0 to 0x1402f89ab (507 bytes)
//
// 3 xrefs:
// > GameStatsManager::encodeDataTo @ 0x1402f6dd0
// > GJAccountManager::onSyncAccountCompleted @ 0x140308b07
// > ??> @ 0x14091e1b8
//
// This function is hookable on this platform (idp: pc, 32 bit: False, 64 bit: True!
//
// Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings
// Generated at Fri, 27 Nov 2026 11:30:05 +0000
//
// Hidden C++ exception states: #wind=2
__int64 __fastcall GameStatsManager::preSaveGameStats(__int64 a1, __int64 a2, __int64 a3)
{
char v4; // bp
__int64 v5; // rdx
__int64 v6; // rcx
__int64 v7; // r8
int i; // edi
cocos2d::CCString *v9; // rax
const char *CString; // rax
size_t v11; // r8
__int128 *v12; // rdx
size_t v13; // r8
__int128 *v14; // rdx
__int64 v15; // rbx
unsigned int Stat; // eax
struct cocos2d::CCString *v17; // rax
__int64 v18; // rcx
__int64 v19; // r8
void *v20; // rcx
__int64 v21; // rdx
void *v22; // rcx
__int64 result; // rax
__int128 v24; // [rsp+30h] [rbp-58h] BYREF
__int128 v25; // [rsp+40h] [rbp-48h]
__int128 v26; // [rsp+50h] [rbp-38h] BYREF
__int128 v27; // [rsp+60h] [rbp-28h]
v4 = *(_BYTE *)(AchievementManager::sharedState(a1, a2, a3) + 360);
*(_BYTE *)(AchievementManager::sharedState(v6, v5, v7) + 360) = 1;
for ( i = 1; i <= 44; ++i )
{
v9 = cocos2d::CCString::createWithFormat((const char *)&word_1406ED6F8, (unsigned int)i);
CString = cocos2d::CCString::getCString(v9);
v24 = 0;
v25 = 0;
v11 = -1;
do
++v11;
while ( CString[v11] );
sub_14003D230(&v24, CString, v11);
v12 = &v24;
if ( *((_QWORD *)&v25 + 1) > 0xFu )
v12 = (__int128 *)v24;
v26 = 0;
v27 = 0;
v13 = -1;
do
++v13;
while ( *((_BYTE *)v12 + v13) );
sub_14003D230(&v26, v12, v13);
v14 = &v24;
if ( *((_QWORD *)&v25 + 1) > 0xFu )
v14 = (__int128 *)v24;
v15 = *(_QWORD *)(a1 + 576);
Stat = GameStatsManager::getStat(a1, v14);
v17 = cocos2d::CCString::createWithFormat((const char *)&word_1406ED6F8, Stat);
cocos2d::CCDictionary::setObject(v15, v17, &v26);
if ( *((_QWORD *)&v27 + 1) > 0xFu )
{
v20 = (void *)v26;
if ( (unsigned __int64)(*((_QWORD *)&v27 + 1) + 1LL) >= 0x1000 )
{
v20 = *(void **)(v26 - 8);
if ( (unsigned __int64)(v26 - (_QWORD)v20 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v20);
}
v21 = *((_QWORD *)&v25 + 1);
if ( *((_QWORD *)&v25 + 1) > 0xFu )
{
v22 = (void *)v24;
if ( (unsigned __int64)(*((_QWORD *)&v25 + 1) + 1LL) >= 0x1000 )
{
v22 = *(void **)(v24 - 8);
if ( (unsigned __int64)(v24 - (_QWORD)v22 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v22);
}
}
result = AchievementManager::sharedState(v18, v21, v19);
*(_BYTE *)(result + 360) = v4;
return result;
}