//
// cocos2d::CCFileUtilsWin32::getWritablePath from 0x18007a6f0 to 0x18007ab10 (1056 bytes)
//
// 3 xrefs:
// > ??> @ 0x1801010e8
// > ??> @ 0x1801438a8
// > ??> @ 0x1801b4cbc
//
// 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=2
_OWORD *__fastcall cocos2d::CCFileUtilsWin32::getWritablePath(__int64 a1, _OWORD *a2)
{
char *v3; // r14
size_t v4; // r8
unsigned __int64 v5; // rdi
__m128i v6; // kr00_16
void **v7; // rbx
char *v8; // rbx
void **v9; // rcx
void **i; // r8
size_t v11; // r8
void **v12; // rdx
void *v13; // rcx
unsigned __int64 v14; // xmm1_8
void **v15; // rax
void **v16; // rdx
void *v17; // rcx
size_t v18; // r8
void **v19; // rcx
void **j; // r8
__int64 v21; // r8
size_t v22; // r8
void **v23; // rdx
void *v24; // rcx
__m128i v25; // xmm2
__int64 v27; // [rsp+38h] [rbp-C8h]
void *Block[2]; // [rsp+40h] [rbp-C0h] BYREF
__m128i v29; // [rsp+50h] [rbp-B0h]
void *v30[2]; // [rsp+60h] [rbp-A0h] BYREF
size_t v31; // [rsp+70h] [rbp-90h]
unsigned __int64 v32; // [rsp+78h] [rbp-88h]
__int128 v33; // [rsp+80h] [rbp-80h] BYREF
__m128i v34; // [rsp+90h] [rbp-70h]
CHAR Filename[272]; // [rsp+A0h] [rbp-60h] BYREF
CHAR pszPath[272]; // [rsp+1B0h] [rbp+B0h] BYREF
HIWORD(v27) = HIWORD(a2);
GetModuleFileNameA(nullptr, Filename, 0x105u);
v3 = strrchr(Filename, 92);
if ( v3 && SHGetFolderPathA(nullptr, 28, nullptr, 0, pszPath) >= 0 )
{
*(_OWORD *)Block = 0;
v29 = 0u;
v4 = -1;
do
++v4;
while ( pszPath[v4] );
sub_18000CE60(Block, pszPath, v4);
v5 = -1;
do
++v5;
while ( v3[v5] );
v6 = v29;
if ( v5 > v29.m128i_i64[1] - v29.m128i_i64[0] )
{
sub_180007900(Block, v5, 0, v3, v5);
}
else
{
v29.m128i_i64[0] += v5;
v7 = Block;
if ( v6.m128i_i64[1] > 0xFuLL )
v7 = (void **)Block[0];
v8 = (char *)v7 + v6.m128i_i64[0];
memmove(v8, v3, v5);
v8[v5] = 0;
}
v9 = Block;
if ( v29.m128i_i64[1] > 0xFuLL )
v9 = (void **)Block[0];
if ( v29.m128i_i64[0] )
{
for ( i = (void **)((char *)v9 + v29.m128i_i64[0] - 1); *(_BYTE *)i != 46; i = (void **)((char *)i - 1) )
{
if ( i == v9 )
goto LABEL_20;
}
v11 = (char *)i - (char *)v9;
}
else
{
LABEL_20:
v11 = -1;
}
v33 = 0;
v34 = 0;
if ( v29.m128i_i64[0] < v11 )
v11 = v29.m128i_i64[0];
v12 = Block;
if ( v29.m128i_i64[1] > 0xFuLL )
v12 = (void **)Block[0];
sub_18000CE60(&v33, v12, v11);
if ( v29.m128i_i64[1] > 0xFuLL )
{
v13 = Block[0];
if ( (unsigned __int64)(v29.m128i_i64[1] + 1) >= 0x1000 )
{
v13 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v13 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free_0(v13);
}
*(_OWORD *)Block = v33;
v29 = v34;
v14 = _mm_srli_si128(v34, 8).m128i_u64[0];
if ( v14 == v34.m128i_i64[0] )
{
sub_180007900(Block, 1u, 0, &unk_180101168, 1u);
}
else
{
v29.m128i_i64[0] = v34.m128i_i64[0] + 1;
v15 = Block;
if ( v14 > 0xF )
v15 = (void **)Block[0];
*(_WORD *)((char *)v15 + v34.m128i_i64[0]) = 92;
}
v16 = Block;
if ( v29.m128i_i64[1] > 0xFuLL )
v16 = (void **)Block[0];
if ( SHCreateDirectoryExA(nullptr, (LPCSTR)v16, nullptr) >= 0 )
{
*a2 = *(_OWORD *)Block;
a2[1] = v29;
return a2;
}
if ( v29.m128i_i64[1] > 0xFuLL )
{
v17 = Block[0];
if ( (unsigned __int64)(v29.m128i_i64[1] + 1) >= 0x1000 )
{
v17 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v17 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free_0(v17);
}
}
*(_OWORD *)v30 = 0;
v31 = 0;
v32 = 0;
v18 = -1;
do
++v18;
while ( Filename[v18] );
sub_18000CE60(v30, Filename, v18);
v19 = v30;
if ( v32 > 0xF )
v19 = (void **)v30[0];
if ( v31 )
{
for ( j = (void **)((char *)v19 + v31 - 1); *(_BYTE *)j != 92; j = (void **)((char *)j - 1) )
{
if ( j == v19 )
goto LABEL_54;
}
v21 = (char *)j - (char *)v19;
}
else
{
LABEL_54:
v21 = -1;
}
v33 = 0;
v34 = 0;
v22 = v21 + 1;
if ( v31 < v22 )
v22 = v31;
v23 = v30;
if ( v32 > 0xF )
v23 = (void **)v30[0];
sub_18000CE60(&v33, v23, v22);
if ( v32 > 0xF )
{
v24 = v30[0];
if ( v32 + 1 >= 0x1000 )
{
v24 = *((void **)v30[0] - 1);
if ( (unsigned __int64)((char *)v30[0] - (char *)v24 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free_0(v24);
}
v25 = v34;
*a2 = v33;
a2[1] = v25;
return a2;
}