//
// EmoteSprite::replaceTokens from 0x6e115c to 0x6e1540 (996 bytes)
//
// 8 xrefs:
// > MultilineBitmapFont::readEmoteInfo @ 0x6abda0
// > CCTextInputNode::updateLabel @ 0x6c3174
// > CommentCell::loadFromComment @ 0x74c034
// > NewsPopup::rebuildPage @ 0xb8b238
// > InvitesPopup::buildRows @ 0xc81d6c
// > EditorSoundConfigUploadPopup::init @ 0xcd4d1c
// > ReportPopup::init @ 0xd00bac
// > ??> @ 0x59e00
//
// This function is hookable on this platform (idp: arm, 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 12:51:39 +0000
//
__int64 *__usercall EmoteSprite::replaceTokens@(__int64 a1@, __int64 *a2@, __int64 *a3@, float a4@)
{
unsigned __int64 v8; // x1
__int64 v9; // x1
__int64 v10; // x20
unsigned __int64 v11; // x25
unsigned __int64 v12; // x19
size_t v13; // x3
unsigned __int64 v14; // x2
__int64 v15; // x1
size_t v16; // x2
void *v17; // x1
__int64 *v18; // x0
__int64 v19; // x2
__int64 v20; // x24
unsigned __int8 v21; // w0
__int64 *v22; // x0
int v23; // w2
__int64 *v24; // x3
cocos2d::CCString *v25; // x0
const char *CString; // x0
__int64 v27; // x0
__int64 v28; // x0
float v29; // s8
__int64 v30; // x2
float v31; // s8
int v32; // w1
int v33; // w0
bool v34; // cc
__int64 v35; // x0
int v36; // w0
char v37; // w1
__int64 v39; // x2
__int64 *v40; // x1
__int64 v41; // [xsp+80h] [xbp+80h]
cocos2d::CCSpriteFrameCache *obja; // [xsp+88h] [xbp+88h]
__int64 *obj; // [xsp+88h] [xbp+88h]
__int64 *v44; // [xsp+90h] [xbp+90h]
a3[1] = 0;
a3[2] = 0;
*a3 = 0;
v8 = *(_BYTE *)a1 >> 1;
if ( (*(_BYTE *)a1 & 1) != 0 )
v8 = *(_QWORD *)(a1 + 8);
std::string::reserve(a3, v8);
v9 = *a2;
if ( 0xAAAAAAAAAAAAAAABLL * ((a2[1] - *a2) >> 3) )
{
v10 = 0;
v11 = 0;
v12 = 0;
while ( 1 )
{
v13 = *(_QWORD *)(v9 + v10) - v12;
if ( (*(_BYTE *)a1 & 1) != 0 )
{
v14 = *(_QWORD *)(a1 + 8);
if ( v14 < v12 )
goto LABEL_51;
v15 = *(_QWORD *)(a1 + 16);
}
else
{
v14 = *(_BYTE *)a1 >> 1;
if ( v14 < v12 )
LABEL_51:
sub_62BB24();
v15 = a1 + 1;
}
v16 = v14 - v12;
v17 = (void *)(v15 + v12);
if ( v16 > v13 )
v16 = v13;
std::string::append((__int64)a3, v17, v16);
v18 = (__int64 *)(*a2 + v10);
v19 = *(_BYTE *)a3 >> 1;
v12 = v18[1] + *v18;
if ( (*(_BYTE *)a3 & 1) != 0 )
v19 = a3[1];
*v18 = v19;
*(_QWORD *)(*a2 + v10 + 8) = 1;
v20 = *(_QWORD *)(*a2 + v10 + 16);
v21 = atomic_load((unsigned __int8 *)&byte_155C328);
if ( (v21 & 1) == 0 && _cxa_guard_acquire(&byte_155C328) )
{
qword_155C310 = (__int64)&qword_155C318;
qword_155C318 = 0;
qword_155C320 = 0;
_cxa_guard_release(&byte_155C328);
__cxa_atexit((void (*)(void *))std::map::~map, &qword_155C310, &unk_1548000);
}
v22 = (__int64 *)qword_155C318;
if ( qword_155C318 )
{
v23 = *(_DWORD *)(v20 + 8);
v24 = &qword_155C318;
do
{
while ( *((_DWORD *)v22 + 7) >= v23 )
{
v24 = v22;
v22 = (__int64 *)*v22;
if ( !v22 )
goto LABEL_17;
}
v22 = (__int64 *)v22[1];
}
while ( v22 );
LABEL_17:
v22 = &qword_155C318;
if ( v24 != &qword_155C318 )
{
v22 = (__int64 *)*((unsigned int *)v24 + 7);
if ( v23 >= (int)v22 )
{
v31 = *((float *)v24 + 8);
goto LABEL_29;
}
}
}
obja = (cocos2d::CCSpriteFrameCache *)cocos2d::CCSpriteFrameCache::sharedSpriteFrameCache((cocos2d::CCSpriteFrameCache *)v22);
v25 = (cocos2d::CCString *)cocos2d::CCString::createWithFormat(
(cocos2d::CCString *)"particle_%02d_001.png",
(const char *)*(unsigned int *)(v20 + 8));
CString = (const char *)cocos2d::CCString::getCString(v25);
v27 = cocos2d::CCSpriteFrameCache::spriteFrameByName(obja, CString);
if ( v27 && (v28 = v27 + 92, v29 = *(float *)(v28 + 12), v29 > 0.0) )
{
v30 = qword_155C318;
v31 = *(float *)(v28 + 8) / v29;
if ( !qword_155C318 )
goto LABEL_49;
}
else
{
v30 = qword_155C318;
v31 = 1.0;
if ( !qword_155C318 )
{
LABEL_49:
v44 = &qword_155C318;
obj = &qword_155C318;
goto LABEL_38;
}
}
v32 = *(_DWORD *)(v20 + 8);
v33 = *(_DWORD *)(v30 + 28);
v34 = v32 <= v33;
if ( v32 < v33 )
{
LABEL_23:
v35 = *(_QWORD *)v30;
if ( *(_QWORD *)v30 )
goto LABEL_24;
v44 = (__int64 *)v30;
obj = (__int64 *)v30;
LABEL_38:
v39 = operator new(0x28u);
*(_DWORD *)(v39 + 28) = *(_DWORD *)(v20 + 8);
*(_QWORD *)(v39 + 16) = v44;
*(_QWORD *)v39 = 0;
*(_DWORD *)(v39 + 32) = 0;
*(_QWORD *)(v39 + 8) = 0;
*obj = v39;
if ( *(_QWORD *)qword_155C310 )
{
qword_155C310 = *(_QWORD *)qword_155C310;
v40 = (__int64 *)*obj;
}
else
{
v40 = (__int64 *)v39;
}
v41 = v39;
std::__tree_balance_after_insert *>((__int64 *)qword_155C318, v40);
v30 = v41;
++qword_155C320;
goto LABEL_41;
}
while ( !v34 )
{
v35 = *(_QWORD *)(v30 + 8);
if ( !v35 )
{
v44 = (__int64 *)v30;
obj = (__int64 *)(v30 + 8);
goto LABEL_38;
}
LABEL_24:
v30 = v35;
v36 = *(_DWORD *)(v35 + 28);
v34 = v32 <= v36;
if ( v32 < v36 )
goto LABEL_23;
}
LABEL_41:
*(float *)(v30 + 32) = v31;
LABEL_29:
if ( a4 < v31 && a4 > 0.0 )
v31 = a4;
if ( (float)(v31 * *(float *)(v20 + 12)) <= 1.1 )
v37 = 127;
else
v37 = 30;
std::string::push_back(a3, v37);
v9 = *a2;
++v11;
v10 += 24;
if ( v11 >= 0xAAAAAAAAAAAAAAABLL * ((a2[1] - *a2) >> 3) )
goto LABEL_36;
}
}
v12 = 0;
LABEL_36:
std::string::append((__int64)a3, a1, v12, 0xFFFFFFFFFFFFFFFFLL);
return a3;
}