//
// GameStatsManager::tryFixPathBug from 0x1401d47e0 to 0x1401d4f4e (1902 bytes)
//
// 3 xrefs:
// > GameManager::dataLoaded @ 0x14018742c
// > GJAccountManager::onSyncAccountCompleted @ 0x140203672
// > ??> @ 0x1406cc36c
//
// 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
//
// Hidden C++ exception states: #wind=8
void GameStatsManager::tryFixPathBug(GameStatsManager *a1)
{
GameStatsManager *m; // r14
unsigned int *v2; // r12
GameStatsManager *v3; // rcx
int Stat; // ebx
GameStatsManager *v5; // rcx
int v6; // ecx
int v7; // eax
int v8; // ecx
int v9; // r13d
int v10; // esi
signed int v11; // edi
unsigned int *v12; // r15
const char *v13; // rax
int v14; // ebx
int v15; // ebx
const char *v16; // rax
char *v17; // rbx
int v18; // r13d
int i; // ebx
_BYTE *v20; // rax
size_t v21; // r8
void **v22; // rdx
int j; // r12d
int k; // r14d
cocos2d::CCString *v25; // rax
const char *CString; // rax
size_t v27; // r8
__int64 v28; // rdx
__int64 v29; // rcx
__int64 v30; // r8
__int64 v31; // r9
void **v32; // rsi
unsigned __int64 v33; // rdi
unsigned __int64 v34; // rbx
__int64 v35; // rcx
unsigned int *v36; // rdi
unsigned int v37; // ebx
int v38; // esi
_BYTE *v39; // rax
size_t v40; // r8
void **v41; // rdx
void *v42; // rcx
signed int n; // r15d
const char *v44; // rax
int v45; // ebx
const char *v46; // rax
int v47; // ebx
__int64 v48; // rcx
__int64 v49; // rdx
__int64 v50; // rcx
__int64 v51; // r8
__int64 v52; // r9
void **v53; // rsi
unsigned __int64 v54; // rdi
unsigned __int64 v55; // rbx
char *v56; // rax
bool m_dontNotify; // [rsp+20h] [rbp-E0h]
unsigned int *v58; // [rsp+28h] [rbp-D8h] BYREF
__int128 v59; // [rsp+30h] [rbp-D0h] BYREF
unsigned __int64 v60; // [rsp+40h] [rbp-C0h]
__int64 v61; // [rsp+48h] [rbp-B8h]
__int128 *v62; // [rsp+50h] [rbp-B0h]
void *Block[2]; // [rsp+58h] [rbp-A8h] BYREF
unsigned int *v64; // [rsp+68h] [rbp-98h]
GameStatsManager *v65; // [rsp+70h] [rbp-90h]
__int128 *v66; // [rsp+78h] [rbp-88h]
void *Src[2]; // [rsp+80h] [rbp-80h] BYREF
unsigned __int64 v68; // [rsp+90h] [rbp-70h]
unsigned __int64 v69; // [rsp+98h] [rbp-68h]
_BYTE v70[528]; // [rsp+A0h] [rbp-60h] BYREF
m = a1;
v65 = a1;
v2 = nullptr;
if ( a1->m_tryFixPathBug )
{
m_dontNotify = AchievementManager::sharedState()->m_dontNotify;
AchievementManager::sharedState()->m_dontNotify = 1;
m->m_tryFixPathBug = 0;
v3 = (GameStatsManager *)qword_1406C2EE8;
if ( !qword_1406C2EE8 )
{
v58 = (unsigned int *)operator new(0x3E0u);
qword_1406C2EE8 = sub_1401D0AE0((__int64)v58);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2EE8 + 72LL))(qword_1406C2EE8);
v3 = (GameStatsManager *)qword_1406C2EE8;
}
Stat = GameStatsManager::getStat(v3, "6");
v5 = (GameStatsManager *)qword_1406C2EE8;
if ( !qword_1406C2EE8 )
{
v58 = (unsigned int *)operator new(0x3E0u);
qword_1406C2EE8 = sub_1401D0AE0((__int64)v58);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2EE8 + 72LL))(qword_1406C2EE8);
v5 = (GameStatsManager *)qword_1406C2EE8;
}
v6 = GameStatsManager::getStat(v5, "28") - 1000;
v7 = 0;
v8 = Stat + v6;
if ( v8 >= 0 )
v7 = v8;
v9 = 5000;
if ( Stat <= 100000 )
{
if ( Stat > 30000 )
v9 = 6000;
}
else
{
v9 = 7000;
}
if ( v7 < v9 )
v9 = v7;
LODWORD(v62) = v9;
v10 = 0;
*(_OWORD *)Block = 0;
v58 = nullptr;
v64 = nullptr;
v11 = 30;
v12 = nullptr;
do
{
v13 = (const char *)GameToolbox::intToString(Src, v11);
if ( *((_QWORD *)v13 + 3) > 0xFu )
v13 = *(const char **)v13;
v14 = GameStatsManager::getStat(m, v13);
sub_14003A830((__int64)Src);
if ( v14 <= 1000 )
{
v16 = (const char *)GameToolbox::intToString(Src, v11);
if ( *((_QWORD *)v16 + 3) > 0xFu )
v16 = *(const char **)v16;
v15 = GameStatsManager::getStat(m, v16);
sub_14003A830((__int64)Src);
}
else
{
v15 = 1000;
}
v58 = (unsigned int *)__PAIR64__(v15, v11);
if ( v12 == v2 )
{
sub_14012D2A0((const void **)Block, v12, &v58);
v2 = v64;
v12 = (unsigned int *)Block[1];
}
else
{
*(_QWORD *)v12 = v58;
v12 += 2;
Block[1] = v12;
}
v10 += v15;
++v11;
}
while ( v11 <= 39 );
v58 = v2;
v17 = (char *)Block[0];
v18 = (int)v62;
if ( v10 > (int)v62 )
{
sub_1401F5320(Block[0], v12, ((char *)v12 - (char *)Block[0]) >> 3, m_dontNotify);
for ( i = 30; i <= 39; ++i )
{
fmt::BasicWriter::BasicWriter(v70);
fmt::BasicWriter::operator<<(v70, (unsigned int)i);
v20 = (_BYTE *)fmt::BasicWriter::c_str(v70);
*(_OWORD *)Src = 0;
v68 = 0;
v69 = 0;
v21 = -1;
do
++v21;
while ( v20[v21] );
sub_14003A930(Src, v20, v21);
fmt::BasicWriter::~BasicWriter(v70);
v22 = Src;
if ( v69 > 0xF )
v22 = (void **)Src[0];
GameStatsManager::setStat(m, (const char *)v22, 0);
sub_14003A830((__int64)Src);
}
for ( j = 1; j <= 10; ++j )
{
for ( k = 1; k <= 10; ++k )
{
v25 = cocos2d::CCString::createWithFormat("geometry.ach.path%02d.%02d", j, k);
CString = cocos2d::CCString::getCString(v25);
*(_OWORD *)Src = 0;
v68 = 0;
v69 = 0;
v27 = -1;
do
++v27;
while ( CString[v27] );
sub_14003A930(Src, CString, v27);
v62 = &v59;
v59 = 0;
v60 = 0;
v61 = 0;
v32 = Src;
if ( v69 > 0xF )
v32 = (void **)Src[0];
v33 = v68;
if ( v68 > 0x7FFFFFFFFFFFFFFFLL )
sub_140007B50(v29, v28, v30, v31);
v61 = 15;
if ( v68 > 0xF )
{
v34 = v68 | 0xF;
if ( (v68 | 0xF) <= 0x7FFFFFFFFFFFFFFFLL )
{
if ( v34 < 0x16 )
v34 = 22;
}
else
{
v34 = 0x7FFFFFFFFFFFFFFFLL;
}
*(_QWORD *)&v59 = sub_14003AA10(v34 + 1);
v60 = v33;
v61 = v34;
memcpy((void *)v59, v32, v33 + 1);
}
else
{
v60 = v68;
v59 = *(_OWORD *)v32;
}
v35 = qword_1406C2ED8;
if ( !qword_1406C2ED8 )
{
v66 = (__int128 *)operator new(0x668u);
qword_1406C2ED8 = sub_14017AB00((__int64)v66);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2ED8 + 72LL))(qword_1406C2ED8);
v35 = qword_1406C2ED8;
}
GameManager::resetAchievement(v35, (const char *)&v59);
sub_14003A830((__int64)Src);
}
}
v36 = (unsigned int *)Block[0];
for ( m = v65; v36 != v12; v36 += 2 )
{
v37 = *v36;
v38 = v18;
if ( v18 > 1000 )
v38 = 1000;
fmt::BasicWriter::BasicWriter(v70);
fmt::BasicWriter::operator<<(v70, v37);
v39 = (_BYTE *)fmt::BasicWriter::c_str(v70);
*(_OWORD *)Src = 0;
v68 = 0;
v69 = 0;
v40 = -1;
do
++v40;
while ( v39[v40] );
sub_14003A930(Src, v39, v40);
fmt::BasicWriter::~BasicWriter(v70);
v41 = Src;
if ( v69 > 0xF )
v41 = (void **)Src[0];
GameStatsManager::setStat(m, (const char *)v41, v38);
if ( v69 > 0xF )
{
v42 = Src[0];
if ( v69 + 1 >= 0x1000 )
{
v42 = *((void **)Src[0] - 1);
if ( (unsigned __int64)((char *)Src[0] - (char *)v42 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v42);
}
v18 -= v38;
if ( v18 <= 0 )
break;
}
for ( n = 30; n <= 39; ++n )
{
v44 = (const char *)GameToolbox::intToString(Src, n);
if ( *((_QWORD *)v44 + 3) > 0xFu )
v44 = *(const char **)v44;
v45 = GameStatsManager::getStat(m, v44);
sub_14003A830((__int64)Src);
if ( v45 <= 1000 )
{
v46 = (const char *)GameToolbox::intToString(Src, n);
if ( *((_QWORD *)v46 + 3) > 0xFu )
v46 = *(const char **)v46;
v47 = GameStatsManager::getStat(m, v46);
sub_14003A830((__int64)Src);
if ( v47 < 1000 )
{
GameStatsManager::getPathRewardKey(v48, Src, (unsigned int)(n - 29));
v59 = 0;
v60 = 0;
v61 = 0;
v53 = Src;
if ( v69 > 0xF )
v53 = (void **)Src[0];
v54 = v68;
if ( v68 > 0x7FFFFFFFFFFFFFFFLL )
sub_140007B50(v50, v49, v51, v52);
v61 = 15;
if ( v68 > 0xF )
{
v55 = v68 | 0xF;
if ( (v68 | 0xF) <= 0x7FFFFFFFFFFFFFFFLL )
{
if ( v55 < 0x16 )
v55 = 22;
}
else
{
v55 = 0x7FFFFFFFFFFFFFFFLL;
}
*(_QWORD *)&v59 = sub_14003AA10(v55 + 1);
v60 = v54;
v61 = v55;
memcpy((void *)v59, v53, v54 + 1);
}
else
{
v60 = v68;
v59 = *(_OWORD *)v53;
}
v66 = &v59;
cocos2d::CCDictionary::removeObjectForKey(m->m_miscChests, &v59);
sub_14003A830((__int64)&v59);
sub_14003A830((__int64)Src);
}
}
}
v17 = (char *)Block[0];
}
AchievementManager::sharedState()->m_dontNotify = m_dontNotify;
m->m_pathBugFixed = 1;
if ( v17 )
{
v56 = v17;
if ( (((char *)v58 - v17) & 0xFFFFFFFFFFFFFFF8uLL) >= 0x1000 )
{
v17 = *((char **)v17 - 1);
if ( (unsigned __int64)(v56 - v17 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v17);
}
}
}