//
// sub_1004A5860 from 0x1004a5860 to 0x1004a5b97 (823 bytes)
//
// 2 xrefs:
// > GManager::loadDataFromFile @ 0x1004a560c
// > GManager::loadDataFromFile @ 0x1004a56a0
//
// 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:30:54 +0000
//
void __fastcall sub_1004A5860(std::string *this, char *__s, char *a3)
{
size_t v4; // rax
std::string::size_type v5; // r15
char *data; // r13
size_t v7; // r14
size_t v8; // rax
size_t v9; // r15
char *v10; // r12
size_t v11; // r13
unsigned int v12; // r15d
std::string::size_type size; // r15
std::string::size_type v14; // rax
signed __int64 v15; // rdx
char *v16; // r15
int v17; // r14d
char *v18; // r13
size_t v19; // rdx
char *v20; // rax
char *v21; // r13
std::string::size_type v22; // r13
const std::string::value_type *v23; // rcx
std::string::size_type v24; // r8
size_t v25; // rax
unsigned int v26; // r15d
void *v27; // [rsp+0h] [rbp-80h]
char v28[7]; // [rsp+11h] [rbp-6Fh] BYREF
void *v29; // [rsp+20h] [rbp-60h]
int v30; // [rsp+2Ch] [rbp-54h]
void *__s2; // [rsp+30h] [rbp-50h]
std::string::pointer v32; // [rsp+38h] [rbp-48h]
__int64 __dst; // [rsp+40h] [rbp-40h] BYREF
size_t v34; // [rsp+48h] [rbp-38h]
void *__p; // [rsp+50h] [rbp-30h]
v4 = strlen(__s);
if ( v4 >= 0xFFFFFFFFFFFFFFF8LL )
sub_100003630();
v5 = v4;
if ( v4 >= 0x17 )
{
__s2 = a3;
v7 = 26;
if ( (v4 | 7) != 0x17 )
v7 = (v4 | 7) + 1;
data = (char *)operator new(v7);
this->__r_.__value_.__r.__words[2] = (std::string::size_type)data;
this->__r_.__value_.__r.__words[0] = v7 + 1;
a3 = (char *)__s2;
this->__r_.__value_.__l.__size_ = v5;
goto LABEL_8;
}
this->__r_.__value_.__s.0 = (std::string::__short::$7162EEB0FEF29CC674EFA33D0008C7E0)(2 * v4);
data = this->__r_.__value_.__s.__data_;
if ( v4 )
LABEL_8:
memcpy(data, __s, v5);
data[v5] = 0;
strcpy(v28, ".dat");
v8 = strlen(a3);
if ( v8 >= 0xFFFFFFFFFFFFFFF8LL )
sub_100003630();
v9 = v8;
if ( v8 >= 0x17 )
{
v11 = 26;
if ( (v8 | 7) != 0x17 )
v11 = (v8 | 7) + 1;
v10 = (char *)operator new(v11);
__p = v10;
__dst = v11 | 1;
v34 = v9;
}
else
{
LOBYTE(__dst) = 2 * v8;
v10 = (char *)&__dst + 1;
if ( !v8 )
goto LABEL_17;
}
memcpy(v10, a3, v9);
LABEL_17:
v10[v9] = 0;
__s2 = v28;
v30 = 8;
v27 = v29;
v12 = (unsigned int)this->__r_.__value_.__l.0;
if ( (v12 & 1) != 0 )
{
size = this->__r_.__value_.__l.__size_;
v32 = this->__r_.__value_.__l.__data_;
}
else
{
size = v12 >> 1;
v32 = this->__r_.__value_.__s.__data_;
}
v14 = 0;
while ( 2 )
{
v15 = size - v14;
if ( (__int64)(size - v14) >= 4 )
{
v16 = &v32[size];
v17 = *(char *)__s2;
v18 = &v32[v14];
while ( 1 )
{
v19 = v15 - 4 + 1;
if ( !v19 )
goto LABEL_19;
v20 = (char *)memchr(v18, v17, v19);
if ( !v20 )
goto LABEL_19;
v21 = v20;
if ( !memcmp(v20, __s2, 4u) )
break;
v18 = v21 + 1;
v15 = v16 - v18;
if ( v16 - v18 < 4 )
goto LABEL_19;
}
if ( v21 == v16 )
break;
v22 = v21 - v32;
if ( v22 == -1 )
break;
if ( (__dst & 1) != 0 )
{
v23 = (const std::string::value_type *)__p;
v24 = v34;
}
else
{
v24 = (unsigned __int8)__dst >> 1;
v23 = (char *)&__dst + 1;
}
std::string::replace(this, v22, 4u, v23, v24);
if ( (__dst & 1) != 0 )
{
v25 = v34;
v26 = (unsigned int)this->__r_.__value_.__l.0;
if ( (v26 & 1) == 0 )
goto LABEL_40;
}
else
{
v25 = (unsigned __int8)__dst >> 1;
v26 = (unsigned int)this->__r_.__value_.__l.0;
if ( (v26 & 1) == 0 )
{
LABEL_40:
size = v26 >> 1;
v32 = this->__r_.__value_.__s.__data_;
v14 = v22 + v25;
if ( size >= v14 )
continue;
break;
}
}
v32 = this->__r_.__value_.__l.__data_;
size = this->__r_.__value_.__l.__size_;
v14 = v22 + v25;
if ( size >= v14 )
continue;
}
break;
}
LABEL_19:
if ( (__dst & 1) != 0 )
operator delete(__p);
if ( (v30 & 1) != 0 )
operator delete(v27);
}