//
// GameLevelManager::tryGetUsername from 0x140146070 to 0x1401463bb (843 bytes)
//
// 11 xrefs:
// > CommentCell::loadFromComment @ 0x1400b5dee
// > GJGameLevel::create @ 0x14016bfe8
// > FriendRequestPopup::init @ 0x140295d9f
// > FriendRequestPopup::onBlock @ 0x140296dc9
// > GJWriteMessagePopup::init @ 0x140299561
// > LevelBrowserLayer::getSearchTitle @ 0x1402cc16e
// > ProfilePage::init @ 0x1403bed05
// > ProfilePage::onCopyName @ 0x1403c3337
// > ProfilePage::onInfo @ 0x1403c3572
// > ShareCommentLayer::init @ 0x14048d316
// > ??> @ 0x1406ca5a8
//
// 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=4
__int64 __fastcall GameLevelManager::tryGetUsername(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rsi
cocos2d::CCString *v5; // rax
int v6; // edi
__int64 v7; // rcx
unsigned __int64 v8; // rdi
__int64 v9; // rcx
struct cocos2d::CCObject *v10; // rax
int *p_m_unknown2; // rdx
__int64 v12; // rax
__int64 *v13; // rcx
__int64 *v14; // rax
__int64 *v15; // rdx
void *v17; // rcx
void **v18; // rcx
_QWORD *v19; // r14
void *v21; // [rsp+20h] [rbp-60h]
void *v22; // [rsp+20h] [rbp-60h]
void *v23; // [rsp+20h] [rbp-60h]
void *Block[2]; // [rsp+30h] [rbp-50h] BYREF
__int128 v25; // [rsp+40h] [rbp-40h]
__int128 v26; // [rsp+50h] [rbp-30h] BYREF
__int128 v27; // [rsp+60h] [rbp-20h]
v3 = a3;
if ( a3 )
{
v5 = (cocos2d::CCString *)cocos2d::CCDictionary::valueForKey(*(cocos2d::CCDictionary **)(a1 + 528), a3);
v6 = cocos2d::CCString::intValue(v5);
v7 = qword_1406C2EC0;
if ( !qword_1406C2EC0 )
{
v21 = operator new(0x3D0u);
qword_1406C2EC0 = sub_140141280((__int64)v21);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2EC0 + 72LL))(qword_1406C2EC0);
v7 = qword_1406C2EC0;
}
GameLevelManager::userNameForUserID(v7, Block, v6);
v8 = v25;
if ( (unsigned __int64)v25 < 2 )
{
v9 = qword_1406C2EC0;
if ( !qword_1406C2EC0 )
{
v22 = operator new(0x3D0u);
qword_1406C2EC0 = sub_140141280((__int64)v22);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2EC0 + 72LL))(qword_1406C2EC0);
v9 = qword_1406C2EC0;
}
v10 = cocos2d::CCDictionary::objectForKey(*(cocos2d::CCDictionary **)(v9 + 600), v3);
if ( v10 && Block != (void **)&v10[5].m_unknown2 )
{
p_m_unknown2 = &v10[5].m_unknown2;
if ( *(_QWORD *)&v10[6].m_uID > 0xFu )
p_m_unknown2 = *(int **)&v10[5].m_unknown2;
sub_14003CCE0(Block, p_m_unknown2, (size_t)v10[6].__vftable);
v8 = v25;
}
if ( v8 < 2 )
{
v12 = qword_1406C2EE8;
if ( !qword_1406C2EE8 )
{
v23 = operator new(0x3E0u);
qword_1406C2EE8 = sub_1401D0AE0(v23);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2EE8 + 72LL))(qword_1406C2EE8);
v12 = qword_1406C2EE8;
}
v13 = *(__int64 **)(v12 + 952);
v14 = (__int64 *)v13[1];
v15 = v13;
while ( !*((_BYTE *)v14 + 25) )
{
if ( *((_DWORD *)v14 + 8) >= (int)v3 )
{
v15 = v14;
v14 = (__int64 *)*v14;
}
else
{
v14 = (__int64 *)v14[2];
}
}
if ( *((_BYTE *)v15 + 25) || (int)v3 < *((_DWORD *)v15 + 8) )
v15 = v13;
if ( v15 == v13 )
{
v26 = 0;
*(_QWORD *)&v27 = 0;
*((_QWORD *)&v27 + 1) = 15;
LOBYTE(v26) = 0;
}
else
{
sub_14003BDB0((__int64)&v26, (__int64)(v15 + 5));
}
if ( *((_QWORD *)&v25 + 1) > 0xFu )
{
v17 = Block[0];
if ( (unsigned __int64)(*((_QWORD *)&v25 + 1) + 1LL) >= 0x1000 )
{
v17 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v17 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v17);
}
*(_OWORD *)Block = v26;
v25 = v27;
v8 = v27;
}
}
if ( !v8 )
{
if ( *((_QWORD *)&v25 + 1) )
{
v18 = Block;
if ( *((_QWORD *)&v25 + 1) > 0xFu )
v18 = (void **)Block[0];
*(_QWORD *)&v25 = 1;
*(_WORD *)v18 = 45;
}
else
{
v19 = sub_14003AA10(0x10u);
*(_QWORD *)&v25 = 1;
*((_QWORD *)&v25 + 1) = 15;
*(_WORD *)v19 = 45;
Block[0] = v19;
}
}
*(_OWORD *)a2 = *(_OWORD *)Block;
*(_OWORD *)(a2 + 16) = v25;
}
else
{
*(_OWORD *)a2 = 0;
*(_QWORD *)(a2 + 16) = 1;
*(_QWORD *)(a2 + 24) = 15;
*(_BYTE *)a2 = 45;
*(_BYTE *)(a2 + 1) = 0;
}
return a2;
}