//
// GameLevelManager::updateLevelRewards from 0x14021dde0 to 0x14021e12e (846 bytes)
//
// 5 xrefs:
// > GameLevelManager::saveFetchedLevels @ 0x14021e5d9
// > GameLevelManager::onGetLevelSaveDataCompleted @ 0x14022c66e
// > GameLevelManager::processOnDownloadLevelCompleted @ 0x1402333d9
// > GameLevelManager::processOnDownloadLevelCompleted @ 0x140233646
// > ??> @ 0x14091bac4
//
// 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:28:23 +0000
//
// Hidden C++ exception states: #wind=6
__int64 __fastcall GameLevelManager::updateLevelRewards(__int64 a1, _DWORD *a2)
{
__int64 v3; // rcx
float v4; // xmm0_4
__int64 v5; // rcx
__int64 v6; // rcx
__int64 v7; // rsi
int i; // ebp
_BYTE *CoinKey; // rbx
size_t v10; // r8
void *v11; // rcx
__int64 result; // rax
void *v13; // [rsp+30h] [rbp-48h]
void *v14; // [rsp+30h] [rbp-48h]
void *v15; // [rsp+30h] [rbp-48h]
void *v16; // [rsp+30h] [rbp-48h]
void *v17; // [rsp+30h] [rbp-48h]
__int128 v18; // [rsp+38h] [rbp-40h] BYREF
__int64 v19; // [rsp+48h] [rbp-30h]
unsigned __int64 v20; // [rsp+50h] [rbp-28h]
v3 = qword_14090BFE0;
if ( !qword_14090BFE0 )
{
v13 = operator new(0x3E8u);
qword_14090BFE0 = sub_1402D6480(v13);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_14090BFE0 + 72LL))(qword_14090BFE0);
v3 = qword_14090BFE0;
}
if ( !(unsigned __int8)GameStatsManager::hasCompletedLevel(v3, a2) )
goto LABEL_28;
a2[231] = 100;
v4 = (float)((float)rand() / 32767.0) * 1000.0;
a2[232] = (int)v4;
a2[233] = (int)v4 + 100;
if ( a2[251] - a2[252] == 1 )
{
v5 = qword_14090BFE0;
if ( !qword_14090BFE0 )
{
v14 = operator new(0x3E8u);
qword_14090BFE0 = sub_1402D6480(v14);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_14090BFE0 + 72LL))(qword_14090BFE0);
v5 = qword_14090BFE0;
}
GameStatsManager::completedDemonLevel(v5, a2);
}
if ( a2[255] - a2[256] > 0 )
{
v6 = qword_14090BFE0;
if ( !qword_14090BFE0 )
{
v15 = operator new(0x3E8u);
qword_14090BFE0 = sub_1402D6480(v15);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_14090BFE0 + 72LL))(qword_14090BFE0);
v6 = qword_14090BFE0;
}
GameStatsManager::completedStarLevel(v6, a2);
}
v7 = qword_14090BFE0;
if ( !qword_14090BFE0 )
{
v16 = operator new(0x3E8u);
qword_14090BFE0 = sub_1402D6480(v16);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_14090BFE0 + 72LL))(qword_14090BFE0);
v7 = qword_14090BFE0;
}
if ( (int)a2[259] > 0 && a2[260] - a2[261] == 1 )
{
for ( i = 1; i <= 3; ++i )
{
CoinKey = (_BYTE *)GJGameLevel::getCoinKey(a2, (unsigned int)i, (unsigned int)(a2[248] - a2[249]));
if ( (unsigned __int8)GameStatsManager::hasPendingUserCoin(v7, CoinKey) )
{
if ( !(unsigned __int8)GameStatsManager::hasUserCoin(v7, CoinKey) )
{
GameStatsManager::storeUserCoin(v7, CoinKey);
GameStatsManager::incrementStat(v7, "12", 1);
}
v18 = 0;
v19 = 0;
v20 = 0;
v10 = -1;
do
++v10;
while ( CoinKey[v10] );
sub_14003D230(&v18, CoinKey, v10);
cocos2d::CCDictionary::removeObjectForKey(*(_QWORD *)(v7 + 728), &v18);
if ( v20 > 0xF )
{
v11 = (void *)v18;
if ( v20 + 1 >= 0x1000 )
{
v11 = *(void **)(v18 - 8);
if ( (unsigned __int64)(v18 - (_QWORD)v11 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v11);
}
v19 = 0;
v20 = 15;
LOBYTE(v18) = 0;
}
}
LABEL_28:
v7 = qword_14090BFE0;
}
result = (unsigned int)(a2[255] - a2[256]);
if ( a2[255] - a2[256] > 0 )
{
if ( !v7 )
{
v17 = operator new(0x3E8u);
qword_14090BFE0 = sub_1402D6480(v17);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_14090BFE0 + 72LL))(qword_14090BFE0);
v7 = qword_14090BFE0;
}
return GameStatsManager::awardCurrencyForLevel(v7, a2);
}
return result;
}