//
// sub_10054D820 from 0x10054d820 to 0x10054da38 (536 bytes)
//
// 2 xrefs:
// > GameManager::didEncodeForSave @ 0x10037630e
// > LocalLevelManager::didEncodeForSave @ 0x1006cae63
//
// 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:32:01 +0000
//
__int64 __fastcall sub_10054D820(__int64 a1, __int64 a2, int a3)
{
std::mutex *v3; // r12
_QWORD *v4; // r15
char *v5; // r13
char *v6; // r12
char *v7; // rsi
int IntegerForKey; // r14d
int v9; // ebx
void *v10; // rdi
void **v11; // rbx
void **v12; // r14
void *v13; // rdi
void *v14; // rdi
__int128 v16; // [rsp+0h] [rbp-80h] BYREF
void *__p; // [rsp+10h] [rbp-70h]
int v18; // [rsp+18h] [rbp-68h]
void *v19; // [rsp+28h] [rbp-58h] BYREF
void **v20; // [rsp+30h] [rbp-50h]
__int64 v21; // [rsp+40h] [rbp-40h]
std::mutex *v22; // [rsp+48h] [rbp-38h]
int v23; // [rsp+54h] [rbp-2Ch]
v23 = a3;
v3 = qword_100BE5588;
std::mutex::lock(qword_100BE5588);
*(_OWORD *)a1 = 0;
v21 = a1;
*(_QWORD *)(a1 + 16) = 0;
v4 = operator new(0xF0u);
sub_100158EB0((__int64)v4);
if ( !(unsigned __int8)sub_10054C9E0((__int64)v4, a2) )
{
v14 = (void *)v4[26];
if ( v14 )
{
v4[27] = v14;
operator delete(v14);
}
pugi::xml_document::dxml_document(v4);
v13 = v4;
goto LABEL_30;
}
v22 = v3;
DS_Dictionary::getAllKeys((__int64)&v19, (__int64)v4);
v5 = (char *)v19;
v6 = (char *)v20;
if ( v19 != v20 )
{
do
{
while ( 1 )
{
v7 = (*v5 & 1) != 0 ? *((char **)v5 + 2) : v5 + 1;
if ( DS_Dictionary::stepIntoSubDictWithKey((__int64)v4, v7) )
break;
v9 = 0;
if ( !(_BYTE)v23 )
goto LABEL_12;
LABEL_4:
v5 += 24;
if ( v5 == v6 )
goto LABEL_17;
}
IntegerForKey = DS_Dictionary::getIntegerForKey((__int64)v4, "t");
v9 = DS_Dictionary::getIntegerForKey((__int64)v4, "sq");
DS_Dictionary::stepOutOfSubDict((__int64)v4);
if ( (IntegerForKey != 2) == (_BYTE)v23 )
goto LABEL_4;
LABEL_12:
if ( (*v5 & 1) != 0 )
{
sub_10001AD30(&v16, *((const void **)v5 + 2), *((_QWORD *)v5 + 1));
}
else
{
__p = *((void **)v5 + 2);
v16 = *(_OWORD *)v5;
}
v18 = v9;
sub_10054DAA0(v21, &v16);
if ( (v16 & 1) == 0 )
goto LABEL_4;
operator delete(__p);
v5 += 24;
}
while ( v5 != v6 );
}
LABEL_17:
v10 = (void *)v4[26];
v3 = v22;
if ( v10 )
{
v4[27] = v10;
operator delete(v10);
}
pugi::xml_document::dxml_document(v4);
operator delete(v4);
v11 = (void **)v19;
if ( v19 )
{
v12 = v20;
v13 = v19;
if ( v20 != v19 )
{
do
{
if ( (*(_BYTE *)(v12 - 3) & 1) != 0 )
operator delete(*(v12 - 1));
v12 -= 3;
}
while ( v12 != v11 );
v13 = v19;
}
v20 = v11;
LABEL_30:
operator delete(v13);
}
std::mutex::unlock(v3);
return v21;
}