//
// sub_1002E3DA0 from 0x1002e3da0 to 0x1002e3ef5 (341 bytes)
//
// 3 xrefs:
// > GJEffectManager::saveToState @ 0x1002d97d7
// > GJEffectManager::loadFromState @ 0x1002d9ddd
// > sub_1002E3F00 @ 0x1002e3f7a
//
// This function is hookable on this platform (idp: pc, 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:28:20 +0000
//
unsigned __int64 __fastcall sub_1002E3DA0(unsigned __int64 *a1, char *a2, __int64 a3, unsigned __int64 a4)
{
char *v6; // rdi
__int64 v7; // rax
unsigned __int64 v8; // r12
unsigned __int64 v9; // rax
__int64 v10; // r13
unsigned __int64 result; // rax
char *v12; // r12
size_t v13; // r14
size_t v14; // rdx
char *v15; // r13
size_t v16; // r14
v6 = (char *)*a1;
v7 = a1[2];
if ( 0x8E38E38E38E38E39LL * ((v7 - (__int64)v6) >> 3) < a4 )
{
if ( v6 )
{
a1[1] = (unsigned __int64)v6;
v8 = a4;
operator delete(v6);
a4 = v8;
*(_OWORD *)a1 = 0;
a1[2] = 0;
v7 = 0;
}
if ( a4 > 0x38E38E38E38E38ELL )
goto LABEL_22;
v9 = 0x8E38E38E38E38E39LL * (v7 >> 3);
if ( 2 * v9 > a4 )
a4 = 2 * v9;
if ( v9 >= 0x1C71C71C71C71C7LL )
a4 = 0x38E38E38E38E38ELL;
if ( a4 > 0x38E38E38E38E38ELL )
LABEL_22:
sub_1002DED40();
v10 = 72 * a4;
result = (unsigned __int64)operator new(72 * a4);
v12 = (char *)result;
*a1 = result;
a1[1] = result;
a1[2] = result + v10;
v13 = a3 - (_QWORD)a2;
if ( v13 )
result = (unsigned __int64)memcpy((void *)result, a2, v13);
LABEL_17:
a1[1] = (unsigned __int64)&v12[v13];
return result;
}
v12 = (char *)a1[1];
v14 = v12 - v6;
result = 0x8E38E38E38E38E39LL * ((v12 - v6) >> 3);
if ( result < a4 )
{
v15 = &a2[v14];
if ( v12 != v6 )
{
result = (unsigned __int64)memmove(v6, a2, v14);
v12 = (char *)a1[1];
}
v13 = a3 - (_QWORD)v15;
if ( v13 )
result = (unsigned __int64)memmove(v12, v15, v13);
goto LABEL_17;
}
v16 = a3 - (_QWORD)a2;
if ( v16 )
result = (unsigned __int64)memmove(v6, a2, v16);
a1[1] = (unsigned __int64)&v6[v16];
return result;
}