//
// cocos2d::CCFileUtils::getNewFilename from 0x10043aff0 to 0x10043b156 (358 bytes)
//
// 2 xrefs:
// > ??> @ 0x100938050
// > ??> @ 0x1009805f0
//
// 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
//
_QWORD *__fastcall cocos2d::CCFileUtils::getNewFilename(_QWORD *a1, __int64 a2, const char *a3, double a4)
{
const char *CString; // r14
__int64 v5; // r15
size_t v6; // rax
size_t v7; // r12
char *v8; // r13
size_t v9; // r14
cocos2d::CCString *v10; // r15
size_t v11; // rax
size_t v12; // r15
void *v13; // r12
const char *v14; // r13
size_t v15; // r14
const char *v17; // [rsp+8h] [rbp-48h]
_QWORD __dst[2]; // [rsp+10h] [rbp-40h] BYREF
void *__p; // [rsp+20h] [rbp-30h]
CString = a3;
v5 = *(_QWORD *)(a2 + 8);
if ( !v5 )
goto LABEL_15;
v6 = strlen(a3);
if ( v6 >= 0xFFFFFFFFFFFFFFF8LL )
goto LABEL_24;
v7 = v6;
if ( v6 >= 0x17 )
{
v17 = CString;
v9 = 26;
if ( (v6 | 7) != 0x17 )
v9 = (v6 | 7) + 1;
v8 = (char *)operator new(v9);
__p = v8;
__dst[0] = v9 + 1;
CString = v17;
__dst[1] = v7;
}
else
{
LOBYTE(__dst[0]) = 2 * v6;
v8 = (char *)__dst + 1;
if ( !v6 )
goto LABEL_10;
}
memcpy(v8, CString, v7);
LABEL_10:
v8[v7] = 0;
v10 = (cocos2d::CCString *)cocos2d::CCDictionary::objectForKey_1(v5, (char *)__dst);
if ( (__dst[0] & 1) != 0 )
operator delete(__p);
if ( v10 && cocos2d::CCString::length(v10) )
CString = cocos2d::CCString::getCString(v10);
LABEL_15:
v11 = strlen(CString);
if ( v11 >= 0xFFFFFFFFFFFFFFF8LL )
LABEL_24:
sub_100006BF0(a4);
v12 = v11;
if ( v11 >= 0x17 )
{
v14 = CString;
v15 = 26;
if ( (v11 | 7) != 0x17 )
v15 = (v11 | 7) + 1;
v13 = operator new(v15);
a1[2] = v13;
*a1 = v15 + 1;
CString = v14;
a1[1] = v12;
}
else
{
*(_BYTE *)a1 = 2 * v11;
v13 = (char *)a1 + 1;
if ( !v11 )
goto LABEL_23;
}
memmove(v13, CString, v12);
LABEL_23:
*((_BYTE *)v13 + v12) = 0;
return a1;
}