//
// sub_10056E200 from 0x10056e200 to 0x10056e6d4 (1236 bytes)
//
// 1 xrefs:
// > sub_10056DCE0 @ 0x10056ddca
//
// 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 sub_10056E200(__int64 a1, double a2)
{
unsigned int v2; // r12d
size_t v3; // r14
unsigned __int64 v4; // r13
char *v5; // r15
FILE *v6; // rbx
__int64 v7; // r13
size_t v8; // rbx
const void *v9; // rsi
__int64 v10; // rax
void *v11; // r12
unsigned int v13; // ebx
size_t v14; // r13
size_t v15; // rax
unsigned __int64 v16; // r14
size_t v17; // r15
char v18; // r14
char *v19; // rbx
size_t v20; // r12
const void *v21; // rsi
char *v22; // rbx
char v23; // r14
char *v24; // r15
int v25; // eax
int v26; // r15d
char *v27; // rdi
int v28; // eax
char v29; // [rsp+18h] [rbp-2328h] BYREF
unsigned __int64 v30; // [rsp+A0h] [rbp-22A0h] BYREF
const void *v31; // [rsp+B0h] [rbp-2290h]
void *v32; // [rsp+B8h] [rbp-2288h]
unsigned int v33; // [rsp+C4h] [rbp-227Ch]
unsigned __int64 v34; // [rsp+C8h] [rbp-2278h]
__int128 __dst; // [rsp+D0h] [rbp-2270h] BYREF
void *__p; // [rsp+E0h] [rbp-2260h]
__int64 v37; // [rsp+E8h] [rbp-2258h]
char v38[16]; // [rsp+F0h] [rbp-2250h] BYREF
char *__filename; // [rsp+100h] [rbp-2240h]
char __s[512]; // [rsp+110h] [rbp-2230h] BYREF
_BYTE __ptr[8192]; // [rsp+310h] [rbp-2030h] BYREF
v2 = *(unsigned __int8 *)(a1 + 8);
v37 = a1;
if ( (v2 & 1) != 0 )
v3 = *(_QWORD *)(a1 + 16);
else
v3 = v2 >> 1;
v4 = v3 + 32;
if ( v3 + 32 >= 0xFFFFFFFFFFFFFFF8LL )
sub_100006BF0(a2);
if ( v4 <= 0x16 )
{
__dst = 0;
__p = nullptr;
LOBYTE(__dst) = 2 * v4;
v5 = (char *)&__dst + 1;
v6 = (FILE *)((char *)&__dst + 1);
v7 = v37;
LABEL_10:
if ( (v2 & 1) != 0 )
v9 = *(const void **)(v7 + 24);
else
v9 = (const void *)(v7 + 9);
memmove(v5, v9, v3);
goto LABEL_14;
}
v8 = 26;
if ( (v4 | 7) != 0x17 )
v8 = (v4 | 7) + 1;
v5 = (char *)operator new(v8);
*(_QWORD *)&__dst = v8 + 1;
__p = v5;
*((_QWORD *)&__dst + 1) = v3 + 32;
v6 = (FILE *)((char *)&__dst + 1);
v7 = v37;
if ( v3 )
goto LABEL_10;
LABEL_14:
strcpy(&v5[v3], "cocos2dx-update-temp-package.zip");
if ( (__dst & 1) != 0 )
v6 = (FILE *)__p;
v10 = sub_1007C3D20(v6);
v11 = (void *)v10;
if ( !v10 )
goto LABEL_19;
if ( (unsigned int)sub_1007C3E90(v10, &v30) )
{
sub_1007C3D50(v11);
LABEL_19:
LODWORD(v6) = 0;
goto LABEL_20;
}
LOBYTE(v6) = 1;
if ( v30 )
{
v31 = (const void *)(v7 + 9);
v34 = 0;
v32 = v11;
while ( 1 )
{
if ( (unsigned int)sub_1007C4B00((_DWORD)v11, (unsigned int)&v29, (unsigned int)__s, 512, 0, 0, 0) )
{
sub_1007C3D50(v11);
goto LABEL_19;
}
v13 = *(unsigned __int8 *)(v7 + 8);
if ( (v13 & 1) != 0 )
v14 = *(_QWORD *)(v7 + 16);
else
v14 = v13 >> 1;
v15 = strlen(__s);
v16 = v15 + v14;
if ( v15 + v14 >= 0xFFFFFFFFFFFFFFF8LL )
sub_100006BF0(0.0);
v17 = v15;
v33 = v13;
if ( v16 > 0x16 )
{
v20 = (v16 | 7) + 1;
if ( (v16 | 7) == 0x17 )
v20 = 26;
v19 = (char *)operator new(v20);
*(_QWORD *)v38 = v20 | 1;
__filename = v19;
*(_QWORD *)&v38[8] = v16;
v18 = v20 | 1;
v11 = v32;
}
else
{
*(_OWORD *)v38 = 0;
__filename = nullptr;
v18 = 2 * v16;
v38[0] = v18;
v19 = nullptr;
}
if ( (v18 & 1) == 0 )
v19 = &v38[1];
if ( v14 )
{
v21 = v31;
if ( (v33 & 1) != 0 )
v21 = *(const void **)(v37 + 24);
memmove(v19, v21, v14);
}
v22 = &v19[v14];
if ( v17 )
memmove(v22, __s, v17);
v22[v17] = 0;
v7 = v37;
if ( __s[strlen(__s) - 1] != 47 )
break;
v23 = v38[0];
v24 = __filename;
LOWORD(v25) = umask(0);
LODWORD(v6) = v25;
if ( (v23 & 1) == 0 )
v24 = &v38[1];
v26 = mkdir(v24, 0x1FFu);
umask((mode_t)v6);
if ( v26 && *__error() != 17 )
goto LABEL_65;
LABEL_58:
sub_1007C3DD0(v11);
if ( ++v34 < v30 && (unsigned int)sub_1007C4DA0(v11) )
goto LABEL_65;
if ( (v38[0] & 1) != 0 )
operator delete(__filename);
LOBYTE(v6) = 1;
if ( v34 >= v30 )
goto LABEL_20;
}
if ( (unsigned int)sub_1007C59E0(v11) )
{
LABEL_65:
sub_1007C3D50(v11);
goto LABEL_63;
}
v27 = &v38[1];
if ( (v38[0] & 1) != 0 )
v27 = __filename;
v6 = fopen(v27, "wb");
if ( v6 )
{
while ( 1 )
{
v28 = sub_1007C5A60(v11, __ptr, 0x2000);
if ( v28 < 0 )
break;
if ( !v28 )
{
fclose(v6);
goto LABEL_58;
}
fwrite(__ptr, (unsigned int)v28, 1u, v6);
}
}
sub_1007C3DD0(v11);
sub_1007C3D50(v11);
LABEL_63:
if ( (v38[0] & 1) != 0 )
operator delete(__filename);
goto LABEL_19;
}
LABEL_20:
if ( (__dst & 1) != 0 )
operator delete(__p);
return (unsigned int)v6;
}