//
// MultilineBitmapFont::stringWithMaxWidth from 0x589924 to 0x58a020 (1788 bytes)
//
// 2 xrefs:
// > MultilineBitmapFont::initWithFont @ 0x58abe8
// > ??> @ 0x45480
//
// 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 __usercall MultilineBitmapFont::stringWithMaxWidth@(
__int64 a1@,
_QWORD *a2@,
__int64 a3@,
float a4@,
float a5@)
{
__int64 v8; // x19
int v9; // w26
unsigned __int64 v10; // x20
int v11; // w28
float v12; // s8
int v13; // w24
size_t v14; // x0
__int64 v15; // x0
char *v16; // x0
void *v17; // x0
__int64 v18; // x0
unsigned __int64 v19; // x3
int v20; // w19
int v21; // w0
const char *v22; // x1
__int64 v23; // x0
unsigned __int64 v24; // x2
unsigned int *v25; // x1
int v26; // w2
int v27; // w0
int v28; // w24
unsigned int *v29; // x1
int v30; // w2
__int64 v31; // x0
char *v32; // x0
void *v33; // x0
unsigned int *v34; // x1
unsigned __int64 v35; // x19
int v36; // w22
unsigned __int64 v37; // x20
int v38; // w19
int v39; // w24
unsigned int *v40; // x0
unsigned __int64 v41; // x2
char *v42; // x0
cocos2d::CCString *v43; // x0
char *CString; // x0
unsigned int *v45; // x20
unsigned int *v47; // x19
int v48; // w0
int v49; // w2
unsigned int *v50; // x1
int v51; // w2
unsigned int *v52; // x1
int v53; // w2
int v54; // [xsp+88h] [xbp+88h]
unsigned int v56; // [xsp+98h] [xbp+98h]
int v57; // [xsp+9Ch] [xbp+9Ch]
const char *v59; // [xsp+B8h] [xbp+B8h]
unsigned int *v60; // [xsp+D0h] [xbp+D0h] BYREF
__int64 v61; // [xsp+D8h] [xbp+D8h] BYREF
const char *v62; // [xsp+E0h] [xbp+E0h] BYREF
v8 = *(_QWORD *)(*a2 - 24LL);
v54 = v8;
sub_D153B8((int)&v60, &byte_F288A0);
if ( (int)v8 > 0 && (float)(a4 + a4) > 0.0 )
{
v9 = v8;
v10 = 0;
v56 = 0;
v11 = 0;
v57 = 0;
v12 = 0.0;
v13 = 0;
while ( 1 )
{
sub_D18D28(&v61, a2);
v18 = v61;
v19 = *(_QWORD *)(v61 - 24);
if ( v10 >= v19 )
sub_D13C5C("basic_string::at: __n (which is %zu) >= this->size() (which is %zu)", v10, *(_QWORD *)(v61 - 24));
if ( (*(_DWORD *)(v61 - 8) & 0x80000000) == 0 )
{
sub_D176A8(&v61);
v18 = v61;
v19 = *(_QWORD *)(v61 - 24);
}
v20 = (int)(float)(v12 + (float)((float)*(unsigned int *)(a1 + 4LL * *(unsigned __int8 *)(v18 + v10) + 596) * a5));
if ( v10 > v19 )
sub_D13C5C("%s: __pos (which is %zu) > this->size() (which is %zu)", "basic_string::substr", v10, v19);
sub_D14F84(&v62, &v61, v10, 1);
if ( !(unsigned int)sub_D171E0((int)&v62, &byte_F1AB78) )
{
v31 = sub_D15FD4(&v60, " ", 1);
sub_D18EA8(&v60, v31);
v32 = (char *)(v62 - 24);
if ( v62 - 24 != (const char *)&qword_124B6B0 )
{
if ( &pthread_create )
{
v50 = (unsigned int *)(v62 - 8);
do
v51 = __ldaxr(v50);
while ( __stlxr(v51 - 1, v50) );
}
else
{
v51 = *((_DWORD *)v62 - 2);
*((_DWORD *)v62 - 2) = v51 - 1;
}
if ( v51 <= 0 )
operator delete(v32);
}
v33 = (void *)(v61 - 24);
if ( (__int64 *)(v61 - 24) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v52 = (unsigned int *)(v61 - 8);
do
v53 = __ldaxr(v52);
while ( __stlxr(v53 - 1, v52) );
}
else
{
v53 = *(_DWORD *)(v61 - 8);
*(_DWORD *)(v61 - 8) = v53 - 1;
}
if ( v53 <= 0 )
operator delete(v33);
}
v9 = 1000;
v27 = v57 / 2;
goto LABEL_40;
}
v21 = sub_D171E0((int)&v62, byte_E9F998);
v22 = v62;
if ( v21 )
{
if ( !*((_QWORD *)v62 - 3) )
sub_D13C5C("basic_string::at: __n (which is %zu) >= this->size() (which is %zu)", 0, 0);
if ( (*((_DWORD *)v62 - 2) & 0x80000000) == 0 )
{
sub_D176A8(&v62);
v22 = v62;
}
if ( *v22 == 32 )
{
v23 = v61;
v24 = *(_QWORD *)(v61 - 24);
if ( v10 >= v24 )
sub_D13C5C("basic_string::at: __n (which is %zu) >= this->size() (which is %zu)", v10, v24);
if ( (*(_DWORD *)(v61 - 8) & 0x80000000) == 0 )
{
sub_D176A8(&v61);
v23 = v61;
v22 = v62;
}
v57 = v11;
v56 = (unsigned int)(float)((float)*(unsigned int *)(a1 + 4LL * *(unsigned __int8 *)(v23 + v10) + 596) * a5);
}
}
v59 = v22;
v14 = strlen(v22);
v15 = sub_D15FD4(&v60, v59, v14);
sub_D18EA8(&v60, v15);
v16 = (char *)(v62 - 24);
if ( v62 - 24 != (const char *)&qword_124B6B0 )
{
if ( &pthread_create )
{
v29 = (unsigned int *)(v62 - 8);
do
v30 = __ldaxr(v29);
while ( __stlxr(v30 - 1, v29) );
}
else
{
v30 = *((_DWORD *)v62 - 2);
*((_DWORD *)v62 - 2) = v30 - 1;
}
if ( v30 <= 0 )
operator delete(v16);
}
v17 = (void *)(v61 - 24);
if ( (__int64 *)(v61 - 24) == &qword_124B6B0 )
goto LABEL_6;
if ( &pthread_create )
{
v25 = (unsigned int *)(v61 - 8);
do
v26 = __ldaxr(v25);
while ( __stlxr(v26 - 1, v25) );
}
else
{
v26 = *(_DWORD *)(v61 - 8);
*(_DWORD *)(v61 - 8) = v26 - 1;
}
if ( v26 > 0 )
{
LABEL_6:
if ( ++v13 == v9 )
goto LABEL_28;
}
else
{
++v13;
operator delete(v17);
if ( v13 == v9 )
{
LABEL_28:
v27 = v57 / 2;
if ( !*(_BYTE *)(a1 + 1828) )
goto LABEL_41;
goto LABEL_29;
}
}
v12 = (float)v20;
++v10;
if ( (float)(a4 + a4) <= (float)v20 )
{
v9 = v13;
v27 = v57 / 2;
goto LABEL_40;
}
v11 = v20;
}
}
v27 = 0;
v56 = 0;
v20 = 0;
v9 = 0;
LABEL_40:
if ( *(_BYTE *)(a1 + 1828) )
{
LABEL_29:
v28 = *(_DWORD *)(a1 + 1824);
}
else
{
LABEL_41:
if ( (float)v20 >= (float)(a4 + a4) )
goto LABEL_29;
v28 = v20 / 2 - v56;
*(_DWORD *)(a1 + 1824) = v28;
}
v34 = (unsigned int *)(&dword_0 + 1);
*(_BYTE *)(a1 + 1828) = 1;
if ( v28 < v27 )
*(_DWORD *)(a1 + 1824) = v27;
if ( v9 < v54 )
{
v34 = v60;
v35 = *((_QWORD *)v60 - 3);
v36 = v9 - v35;
if ( v9 <= v35 )
v36 = 0;
v37 = v9 - 1LL - v36;
v38 = v9 - v36;
while ( 1 )
{
v39 = v38;
if ( v38 <= 0 )
break;
v40 = v60;
v41 = *((_QWORD *)v60 - 3);
if ( v41 <= v37 )
sub_D13C5C("basic_string::at: __n (which is %zu) >= this->size() (which is %zu)", v37, v41);
v34 = (unsigned int *)*(v60 - 2);
if ( ((unsigned int)v34 & 0x80000000) == 0 )
{
sub_D176A8(&v60);
v40 = v60;
}
if ( *((_BYTE *)v40 + v37) == 32 )
break;
++v36;
--v38;
--v37;
if ( v9 < v36 )
{
v39 = v9 - v36;
break;
}
}
if ( v39 > 1 )
{
sub_D14F84(&v62, &v60, 0, *((_QWORD *)v60 - 3) - v36);
sub_D163D4(&v60, &v62);
v34 = (unsigned int *)v62;
v42 = (char *)(v62 - 24);
if ( v62 - 24 != (const char *)&qword_124B6B0 )
{
if ( &pthread_create )
{
v34 = (unsigned int *)(v62 - 8);
do
v49 = __ldaxr(v34);
while ( __stlxr(v49 - 1, v34) );
}
else
{
v49 = *((_DWORD *)v62 - 2);
*((_DWORD *)v62 - 2) = v49 - 1;
}
if ( v49 <= 0 )
operator delete(v42);
}
}
}
v43 = (cocos2d::CCString *)cocos2d::CCString::create((cocos2d::CCString *)&v60, (const std::string *)v34);
CString = (char *)cocos2d::CCString::getCString(v43);
sub_D153B8(a3, CString);
v45 = v60 - 6;
if ( v60 - 6 != (unsigned int *)&qword_124B6B0 )
{
if ( &pthread_create )
{
v47 = v60 - 2;
do
v48 = __ldaxr(v47);
while ( __stlxr(v48 - 1, v47) );
}
else
{
v48 = *(v60 - 2);
*(v60 - 2) = v48 - 1;
}
if ( v48 <= 0 )
operator delete(v45);
}
return a3;
}