//
// GameStatsManager::tryFixPathBug from 0x10006c060 to 0x10006c876 (2070 bytes)
//
// 2 xrefs:
// > GJAccountManager::onSyncAccountCompleted @ 0x1000d11e3
// > GameManager::dataLoaded @ 0x1003899a6
//
// This function is hookable on this platform!
//
// Using BromaIDA 8.0.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit ba9f177b at Thu Jul 16 22:52:06 2026 from https://github.com/geode-sdk/bindings
//
void __fastcall GameStatsManager::tryFixPathBug(GameStatsManager *a1)
{
double v1; // xmm0_8
GameStatsManager *v2; // rax
int Stat; // ebx
GameStatsManager *v4; // rax
int v5; // eax
int v6; // ecx
unsigned int v7; // ecx
int v8; // edx
unsigned int v9; // eax
__int64 v10; // r13
__int64 v11; // r12
const char *v12; // rsi
int v13; // r14d
__int64 v14; // rdi
const char *v15; // rsi
unsigned int v16; // eax
__int64 v17; // rbx
__int64 v18; // rbx
size_t v19; // r15
__int64 v20; // r15
unsigned __int64 v21; // r13
_QWORD *v22; // r14
unsigned __int64 v23; // rax
__int64 v24; // rax
__int64 v25; // rdx
const char *v26; // r12
const char *v27; // rsi
const char *v28; // rsi
const char *v29; // rsi
const char *v30; // rsi
const char *v31; // rsi
const char *v32; // rsi
const char *v33; // rsi
const char *v34; // rsi
const char *v35; // rsi
int i; // r14d
cocos2d::CCString *v37; // rax
const char *CString; // r15
size_t v39; // rax
size_t v40; // r13
char *v41; // rbx
__int64 v42; // rax
size_t v43; // r12
GameManager *v44; // r15
char v45; // bl
char *v46; // r12
int v47; // r14d
const char *v48; // rsi
bool v49; // cc
bool v50; // zf
unsigned int j; // ebx
const char *v52; // rsi
int v53; // r12d
const char *v54; // rsi
int v55; // r12d
__int128 v56; // [rsp+0h] [rbp-C0h] BYREF
void *v57; // [rsp+10h] [rbp-B0h]
__int128 v58; // [rsp+20h] [rbp-A0h] BYREF
void *v59; // [rsp+30h] [rbp-90h]
__int64 v60; // [rsp+40h] [rbp-80h]
__int64 v61; // [rsp+48h] [rbp-78h]
int v62; // [rsp+54h] [rbp-6Ch]
size_t __n; // [rsp+58h] [rbp-68h]
void *__src; // [rsp+60h] [rbp-60h]
size_t v65; // [rsp+68h] [rbp-58h]
bool m_dontNotify; // [rsp+77h] [rbp-49h]
GameStatsManager *v67; // [rsp+78h] [rbp-48h]
__int128 __dst; // [rsp+80h] [rbp-40h] BYREF
void *__p; // [rsp+90h] [rbp-30h]
if ( !a1->m_tryFixPathBug )
return;
m_dontNotify = AchievementManager::sharedState()->m_dontNotify;
AchievementManager::sharedState()->m_dontNotify = 1;
v67 = a1;
a1->m_tryFixPathBug = 0;
v2 = GameStatsManager::sharedState();
Stat = GameStatsManager::getStat(v2, "6");
v4 = GameStatsManager::sharedState();
v5 = Stat + GameStatsManager::getStat(v4, "28");
v6 = 1000;
if ( v5 >= 1001 )
v6 = v5;
v7 = v6 - 1000;
v8 = 5000;
if ( Stat >= 30001 )
v8 = 6000;
v9 = 7000;
if ( Stat < 100001 )
v9 = v8;
if ( v7 < v9 )
v9 = v7;
v62 = v9;
v10 = 0;
v11 = 30;
__src = nullptr;
__n = 0;
v65 = 0;
do
{
while ( 1 )
{
GameToolbox::intToString(&__dst, (unsigned int)v11);
v12 = (char *)&__dst + 1;
if ( (__dst & 1) != 0 )
v12 = (const char *)__p;
v13 = GameStatsManager::getStat(v67, v12);
if ( (__dst & 1) != 0 )
operator delete(__p);
v14 = 1000;
if ( v13 <= 999 )
{
GameToolbox::intToString(&__dst, (unsigned int)v11);
v15 = (char *)&__dst + 1;
if ( (__dst & 1) != 0 )
v15 = (const char *)__p;
v16 = GameStatsManager::getStat(v67, v15);
v14 = v16;
if ( (__dst & 1) != 0 )
{
v17 = v16;
operator delete(__p);
v14 = v17;
}
}
v18 = v11 + (v14 << 32);
v19 = __n;
if ( __n >= v65 )
break;
*(_QWORD *)__n = v18;
__n = v19 + 8;
v10 = (unsigned int)(v14 + v10);
if ( ++v11 == 40 )
goto LABEL_34;
}
v60 = v10;
__n -= (unsigned __int64)__src;
v20 = (__int64)(v19 - (_QWORD)__src) >> 3;
if ( (unsigned __int64)(v20 + 1) > 0x1FFFFFFFFFFFFFFFLL )
sub_10008FD70();
v21 = (__int64)(v65 - (_QWORD)__src) >> 2;
if ( v21 <= v20 + 1 )
v21 = v20 + 1;
if ( v65 - (unsigned __int64)__src >= 0x7FFFFFFFFFFFFFF8LL )
v21 = 0x1FFFFFFFFFFFFFFFLL;
v61 = v14;
if ( v21 )
{
if ( v21 > 0x1FFFFFFFFFFFFFFFLL )
sub_100054850();
v22 = operator new(8 * v21);
}
else
{
v22 = nullptr;
}
v65 = (size_t)&v22[v21];
v22[v20] = v18;
memcpy(v22, __src, __n);
if ( __src )
operator delete(__src);
__src = v22;
__n = (size_t)&v22[v20 + 1];
v10 = (unsigned int)(v61 + v60);
++v11;
}
while ( v11 != 40 );
LABEL_34:
if ( (int)v10 <= v62 )
goto LABEL_126;
_BitScanReverse64(&v23, (__int64)(__n - (_QWORD)__src) >> 3);
v24 = (2 * ((unsigned int)v23 ^ 0x3F)) ^ 0x7ELL;
v25 = 0;
if ( (void *)__n != __src )
v25 = v24;
sub_10008FD80(__src, __n, v25, 1);
GameToolbox::intToString(&__dst, 30);
v26 = (char *)&__dst + 1;
v27 = (char *)&__dst + 1;
if ( (__dst & 1) != 0 )
v27 = (const char *)__p;
GameStatsManager::setStat(v67, v27, 0);
if ( (__dst & 1) != 0 )
operator delete(__p);
GameToolbox::intToString(&__dst, 31);
v28 = (char *)&__dst + 1;
if ( (__dst & 1) != 0 )
v28 = (const char *)__p;
GameStatsManager::setStat(v67, v28, 0);
if ( (__dst & 1) != 0 )
operator delete(__p);
GameToolbox::intToString(&__dst, 32);
v29 = (char *)&__dst + 1;
if ( (__dst & 1) != 0 )
v29 = (const char *)__p;
GameStatsManager::setStat(v67, v29, 0);
if ( (__dst & 1) != 0 )
operator delete(__p);
GameToolbox::intToString(&__dst, 33);
v30 = (char *)&__dst + 1;
if ( (__dst & 1) != 0 )
v30 = (const char *)__p;
GameStatsManager::setStat(v67, v30, 0);
if ( (__dst & 1) != 0 )
operator delete(__p);
GameToolbox::intToString(&__dst, 34);
v31 = (char *)&__dst + 1;
if ( (__dst & 1) != 0 )
v31 = (const char *)__p;
GameStatsManager::setStat(v67, v31, 0);
if ( (__dst & 1) != 0 )
operator delete(__p);
GameToolbox::intToString(&__dst, 35);
v32 = (char *)&__dst + 1;
if ( (__dst & 1) != 0 )
v32 = (const char *)__p;
GameStatsManager::setStat(v67, v32, 0);
if ( (__dst & 1) != 0 )
operator delete(__p);
GameToolbox::intToString(&__dst, 36);
v33 = (char *)&__dst + 1;
if ( (__dst & 1) != 0 )
v33 = (const char *)__p;
GameStatsManager::setStat(v67, v33, 0);
if ( (__dst & 1) != 0 )
operator delete(__p);
GameToolbox::intToString(&__dst, 37);
v34 = (char *)&__dst + 1;
if ( (__dst & 1) != 0 )
v34 = (const char *)__p;
GameStatsManager::setStat(v67, v34, 0);
if ( (__dst & 1) != 0 )
operator delete(__p);
GameToolbox::intToString(&__dst, 38);
v35 = (char *)&__dst + 1;
if ( (__dst & 1) != 0 )
v35 = (const char *)__p;
GameStatsManager::setStat(v67, v35, 0);
if ( (__dst & 1) != 0 )
operator delete(__p);
GameToolbox::intToString(&__dst, 39);
if ( (__dst & 1) != 0 )
v26 = (const char *)__p;
GameStatsManager::setStat(v67, v26, 0);
if ( (__dst & 1) != 0 )
operator delete(__p);
LODWORD(v65) = 1;
while ( 2 )
{
for ( i = 1; i != 11; ++i )
{
v37 = (cocos2d::CCString *)sub_1007AB580("geometry.ach.path%02d.%02d", v56);
CString = cocos2d::CCString::getCString(v37);
v39 = strlen(CString);
if ( v39 >= 0xFFFFFFFFFFFFFFF8LL )
sub_100006BF0(v1);
v40 = v39;
if ( v39 >= 0x17 )
{
v42 = v39 | 7;
v43 = 26;
if ( (v40 | 7) != 0x17 )
v43 = v42 + 1;
v41 = (char *)operator new(v43);
__p = v41;
*(_QWORD *)&__dst = v43 | 1;
*((_QWORD *)&__dst + 1) = v40;
LABEL_88:
memmove(v41, CString, v40);
goto LABEL_89;
}
LOBYTE(__dst) = 2 * v39;
v41 = (char *)&__dst + 1;
if ( v39 )
goto LABEL_88;
LABEL_89:
v41[v40] = 0;
v44 = GameManager::sharedState();
v45 = __dst & 1;
if ( (__dst & 1) != 0 )
{
sub_100006B70(&v56, __p, *((unsigned __int64 *)&__dst + 1), v1);
}
else
{
v57 = __p;
v1 = *(double *)&__dst;
v56 = __dst;
}
GameManager::resetAchievement(v44, &v56);
if ( (v56 & 1) != 0 )
{
operator delete(v57);
if ( !v45 )
continue;
}
else if ( !v45 )
{
continue;
}
operator delete(__p);
}
LODWORD(v65) = v65 + 1;
if ( (_DWORD)v65 != 11 )
continue;
break;
}
if ( (void *)__n != __src )
{
v46 = (char *)__src + 8;
do
{
v47 = 1000;
if ( v62 < 1000 )
v47 = v62;
GameToolbox::intToString(&__dst, *((unsigned int *)v46 - 2));
v48 = (char *)&__dst + 1;
if ( (__dst & 1) != 0 )
v48 = (const char *)__p;
GameStatsManager::setStat(v67, v48, v47);
if ( (__dst & 1) != 0 )
operator delete(__p);
v49 = v62 <= v47;
v62 -= v47;
if ( v49 )
break;
v50 = v46 == (char *)__n;
v46 += 8;
}
while ( !v50 );
}
for ( j = 30; j != 40; ++j )
{
GameToolbox::intToString(&__dst, j);
v52 = (char *)&__dst + 1;
if ( (__dst & 1) != 0 )
v52 = (const char *)__p;
v53 = GameStatsManager::getStat(v67, v52);
if ( (__dst & 1) != 0 )
operator delete(__p);
if ( v53 <= 999 )
{
GameToolbox::intToString(&__dst, j);
v54 = (char *)&__dst + 1;
if ( (__dst & 1) != 0 )
v54 = (const char *)__p;
v55 = GameStatsManager::getStat(v67, v54);
if ( (__dst & 1) != 0 )
operator delete(__p);
if ( v55 <= 999 )
{
GameStatsManager::getPathRewardKey(&__dst, v54, j - 29);
LOBYTE(v65) = __dst;
if ( (__dst & 1) != 0 )
{
sub_100006B70(&v58, __p, *((unsigned __int64 *)&__dst + 1), v1);
}
else
{
v59 = __p;
v1 = *(double *)&__dst;
v58 = __dst;
}
cocos2d::CCDictionary::removeObjectForKey_1(v67->m_miscChests, &v58);
if ( (v58 & 1) != 0 )
operator delete(v59);
if ( (v65 & 1) != 0 )
operator delete(__p);
}
}
}
LABEL_126:
AchievementManager::sharedState()->m_dontNotify = m_dontNotify;
v67->m_pathBugFixed = 1;
if ( __src )
operator delete(__src);
}