//
// GameToolbox::stringSetupToMap from 0x1004f0aa0 to 0x1004f0d9e (766 bytes)
//
// 4 xrefs:
// > ColorAction::setupFromString @ 0x1002db9fc
// > GJEffectManager::loadPersistentStateString @ 0x1002ebb46
// > GJEffectManager::loadPersistentStateString @ 0x1002ebcc0
// > GJEffectManager::setupFromString @ 0x1002ee825
//
// 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
//
void __fastcall GameToolbox::stringSetupToMap(
std::string *const a1,
const char *a2,
std::map *a3)
{
std::size_t v4; // r12
std::size_t size; // rbx
std::array *longStorage; // r15
size_t v7; // rax
__int64 v8; // rcx
std::array *v9; // rcx
std::array *v10; // rdx
__int64 v11; // rdi
bool v12; // zf
std::size_t v13; // r13
__int64 v14; // rdx
__int64 v15; // r13
std::string::size_type v16; // rbx
char *data; // r12
size_t v18; // r15
std::string *v19; // rax
std::size_t v20; // r12
std::array *v21; // r15
size_t v22; // rax
char *v23; // rcx
char *v24; // r12
__int64 v25; // rsi
std::string *v26; // [rsp+0h] [rbp-A0h] BYREF
__int64 v27; // [rsp+8h] [rbp-98h]
std::string *v28; // [rsp+10h] [rbp-90h]
std::map *v29; // [rsp+18h] [rbp-88h]
std::array *p_shortStorage; // [rsp+20h] [rbp-80h]
std::string __dst; // [rsp+28h] [rbp-78h] BYREF
std::string v32; // [rsp+40h] [rbp-60h] BYREF
std::array *v33; // [rsp+58h] [rbp-48h]
int sizex2; // [rsp+64h] [rbp-3Ch]
__int64 v35; // [rsp+68h] [rbp-38h]
char v36; // [rsp+76h] [rbp-2Ah] BYREF
char v37; // [rsp+77h] [rbp-29h]
v29 = a3;
v4 = a1->m_data.m_short.sizex2 >> 1;
sizex2 = a1->m_data.m_short.sizex2;
size = a1->m_data.m_long.size;
v28 = a1;
longStorage = (std::array *)a1->m_data.m_long.longStorage;
v33 = longStorage;
p_shortStorage = &a1->m_data.m_short.shortStorage;
if ( (sizex2 & 1) != 0 )
v4 = size;
else
longStorage = &a1->m_data.m_short.shortStorage;
v7 = strlen(a2);
v8 = -1;
if ( v4 != 0 && v7 != 0 )
{
v9 = (std::array *)((char *)longStorage + v4);
v10 = longStorage;
LABEL_6:
v11 = 0;
while ( v10->__elems_[0] != a2[v11] )
{
if ( v7 == ++v11 )
{
v10 = (std::array *)((char *)v10 + 1);
if ( v10 != v9 )
goto LABEL_6;
v10 = (std::array *)((char *)longStorage + v4);
break;
}
}
v12 = v10 == v9;
v8 = -1;
if ( !v12 )
v8 = (char *)v10 - (char *)longStorage;
}
v35 = v8;
memset(&v32, 0, sizeof(v32));
v27 = (int)v4;
v37 = 1;
v13 = 0;
while ( v13 == v27 )
{
v15 = v35;
if ( v35 == -1 )
goto LABEL_54;
LABEL_44:
v13 = v15 + 1;
v20 = v28->m_data.m_short.sizex2 >> 1;
sizex2 = v28->m_data.m_short.sizex2;
size = v28->m_data.m_long.size;
v21 = (std::array *)v28->m_data.m_long.longStorage;
v33 = v21;
if ( (sizex2 & 1) != 0 )
v20 = size;
else
v21 = p_shortStorage;
v22 = strlen(a2);
v35 = -1;
if ( v20 > v13 && v22 != 0 )
{
v23 = &v21->__elems_[v13];
v24 = &v21->__elems_[v20];
LABEL_49:
v25 = 0;
while ( *v23 != a2[v25] )
{
if ( v22 == ++v25 )
{
if ( ++v23 != v24 )
goto LABEL_49;
v23 = v24;
break;
}
}
v14 = v23 - (char *)v21;
if ( v23 == v24 )
v14 = -1;
v35 = v14;
}
}
if ( (sizex2 & 1) != 0 )
{
if ( size < v13 )
LABEL_58:
sub_1000547C0();
}
else
{
size = (unsigned __int8)sizex2 >> 1;
v33 = p_shortStorage;
if ( v13 > size )
goto LABEL_58;
}
v16 = size - v13;
if ( v16 >= v35 - v13 )
v16 = v35 - v13;
if ( v16 >= 0xFFFFFFFFFFFFFFF8LL )
sub_100006BF0(0.0);
if ( v16 >= 0x17 )
{
v18 = (v16 | 7) + 1;
if ( (v16 | 7) == 0x17 )
v18 = 26;
data = (char *)operator new(v18);
__dst.__r_.__value_.__r.__words[2] = (std::string::size_type)data;
__dst.__r_.__value_.__r.__words[0] = v18 | 1;
__dst.__r_.__value_.__l.__size_ = v16;
goto LABEL_33;
}
__dst.__r_.__value_.__s.0 = (std::string::__short::$7162EEB0FEF29CC674EFA33D0008C7E0)(2 * v16);
data = __dst.__r_.__value_.__s.__data_;
if ( v16 )
LABEL_33:
memmove(data, &v33->__elems_[v13], v16);
data[v16] = 0;
v19 = &v32;
v15 = v35;
if ( (v37 & 1) != 0 )
{
LABEL_40:
std::string::operator=(v19, &__dst);
goto LABEL_41;
}
if ( (*(_BYTE *)&v32.__r_.__value_.__s.0 & 1) == 0 )
{
if ( !(*(_BYTE *)&v32.__r_.__value_.__l.0 >> 1) )
goto LABEL_41;
goto LABEL_39;
}
if ( v32.__r_.__value_.__l.__size_ )
{
LABEL_39:
v26 = &v32;
v19 = (std::string *)(sub_1004F7DD0(v29, &v32, &unk_10081DE38, &v26, &v36) + 56);
goto LABEL_40;
}
LABEL_41:
if ( (*(_BYTE *)&__dst.__r_.__value_.__s.0 & 1) != 0 )
operator delete(__dst.__r_.__value_.__l.__data_);
v37 ^= 1u;
if ( v15 != -1 )
goto LABEL_44;
LABEL_54:
if ( (*(_BYTE *)&v32.__r_.__value_.__s.0 & 1) != 0 )
operator delete(v32.__r_.__value_.__l.__data_);
}