//
// GJAccountManager::linkToAccount from 0x847cc4 to 0x847e48 (388 bytes)
//
// 2 xrefs:
// > AccountLoginLayer::loginAccountFinished @ 0x852270
// > ??> @ 0x5ea58
//
// 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
//
__int64 __fastcall GJAccountManager::linkToAccount(__int64 a1, __int64 a2, __int64 a3, int a4, int a5)
{
GameManager *v8; // x24
void *v9; // x0
GameManager *v10; // x0
GameManager *v11; // x22
int v12; // w0
void (__fastcall ***v13)(_QWORD); // x1
int v14; // w0
GameManager *v15; // x0
unsigned int *v17; // x2
int v18; // w1
__int64 v20; // [xsp+60h] [xbp+60h] BYREF
sub_D18EA8(a1 + 352, a3);
sub_D18EA8(a1 + 328, a2);
*(_DWORD *)(a1 + 336) = a4;
v8 = GameManager::sharedState();
sub_D18D28(&v20);
sub_D18EA8(&v8->m_playerName, &v20);
v9 = (void *)(v20 - 24);
if ( (__int64 *)(v20 - 24) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v17 = (unsigned int *)(v20 - 8);
do
v18 = __ldaxr(v17);
while ( __stlxr(v18 - 1, v17) );
}
else
{
v18 = *(_DWORD *)(v20 - 8);
*(_DWORD *)(v20 - 8) = v18 - 1;
}
if ( v18 <= 0 )
operator delete(v9);
}
v10 = GameManager::sharedState();
v10->m_playerUserID.value = a5;
v11 = v10;
v12 = rand();
v13 = *(void (__fastcall ****)(_QWORD))(a1 + 376);
v14 = (int)(float)((float)((float)v12 * 4.6566e-10) * 1000.0);
v11->m_playerUserID.seed = v14;
v11->m_playerUserID.random = a5 + v14;
if ( v13 )
(**v13)(v13);
v15 = GameManager::sharedState();
GameManager::accountStatusChanged(v15);
return _stack_chk_guard;
}