//
// DS_Dictionary::saveRootSubDictToFile from 0x18001dbd0 to 0x18001e21d (1613 bytes)
//
// 2 xrefs:
// > ??> @ 0x1801438a8
// > ??> @ 0x1801aebf0
//
// 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
//
// Hidden C++ exception states: #wind=6
__int64 __fastcall DS_Dictionary::saveRootSubDictToFile(DS_Dictionary *this, const char *a2)
{
size_t v4; // rsi
unsigned __int64 Size; // rdi
__int64 v6; // rcx
void **v7; // rbx
char *v8; // rbx
void **v9; // rdx
char **v10; // rdx
char **v11; // rdx
const char *v12; // rcx
const char *v13; // rdx
const char *v14; // rcx
const char *v15; // rdx
const char *v16; // rcx
int v17; // eax
const char *v18; // rcx
const char *v19; // rdx
char **v20; // rdx
unsigned __int8 v21; // r13
char **v22; // rdx
char **v23; // rdx
__int64 v24; // r12
unsigned __int8 v25; // r14
__int64 v26; // rbx
int v27; // eax
char *v28; // rcx
char *v29; // rcx
void *v30; // rcx
char *v31; // rcx
__int64 v33; // [rsp+30h] [rbp-D0h]
__int128 v34; // [rsp+40h] [rbp-C0h]
__int64 v35; // [rsp+50h] [rbp-B0h] BYREF
_BYTE v36[8]; // [rsp+58h] [rbp-A8h] BYREF
_BYTE v37[152]; // [rsp+60h] [rbp-A0h] BYREF
_BYTE v38[104]; // [rsp+F8h] [rbp-8h] BYREF
_QWORD v39[2]; // [rsp+160h] [rbp+60h] BYREF
_BYTE v40[8]; // [rsp+170h] [rbp+70h] BYREF
_BYTE v41[152]; // [rsp+178h] [rbp+78h] BYREF
_BYTE v42[96]; // [rsp+210h] [rbp+110h] BYREF
char *v43[2]; // [rsp+270h] [rbp+170h] BYREF
__int64 v44; // [rsp+280h] [rbp+180h]
unsigned __int64 v45; // [rsp+288h] [rbp+188h]
char *FileName[2]; // [rsp+290h] [rbp+190h] BYREF
__m128i si128; // [rsp+2A0h] [rbp+1A0h]
char *OldFilename[2]; // [rsp+2B0h] [rbp+1B0h] BYREF
__m128i v49; // [rsp+2C0h] [rbp+1C0h]
void *Block[2]; // [rsp+2D0h] [rbp+1D0h] BYREF
__int64 v51; // [rsp+2E0h] [rbp+1E0h]
unsigned __int64 v52; // [rsp+2E8h] [rbp+1E8h]
*(_OWORD *)v43 = 0;
v44 = 0;
v45 = 15;
LOBYTE(v43[0]) = 0;
sub_18003D240(Block);
v4 = -1;
Size = -1;
do
++Size;
while ( a2[Size] );
v6 = v51;
if ( Size > v52 - v51 )
{
sub_180007900(Block, Size, 0, a2, Size);
}
else
{
v51 += Size;
v7 = Block;
if ( v52 > 0xF )
v7 = (void **)Block[0];
v8 = (char *)v7 + v6;
memmove(v8, a2, Size);
v8[Size] = 0;
}
v9 = Block;
if ( v52 > 0xF )
v9 = (void **)Block[0];
do
++v4;
while ( *((_BYTE *)v9 + v4) );
sub_180010050((void **)v43, v9, v4);
v10 = v43;
if ( v45 > 0xF )
v10 = (char **)v43[0];
sub_18001B0B0((char *)OldFilename, v10, ".dat", "2.dat");
v11 = v43;
if ( v45 > 0xF )
v11 = (char **)v43[0];
sub_18001B0B0((char *)FileName, v11, ".dat", "3.dat");
v12 = (const char *)FileName;
if ( si128.m128i_i64[1] > 0xFuLL )
v12 = FileName[0];
remove(v12);
v13 = (const char *)FileName;
if ( si128.m128i_i64[1] > 0xFuLL )
v13 = FileName[0];
v14 = (const char *)OldFilename;
if ( v49.m128i_i64[1] > 0xFuLL )
v14 = OldFilename[0];
rename(v14, v13);
v15 = (const char *)OldFilename;
if ( v49.m128i_i64[1] > 0xFuLL )
v15 = OldFilename[0];
v16 = (const char *)v43;
if ( v45 > 0xF )
v16 = v43[0];
v17 = rename(v16, v15);
v18 = (const char *)FileName;
if ( v17 )
{
if ( si128.m128i_i64[1] > 0xFuLL )
v18 = FileName[0];
v19 = (const char *)OldFilename;
if ( v49.m128i_i64[1] > 0xFuLL )
v19 = OldFilename[0];
rename(v18, v19);
}
else
{
if ( si128.m128i_i64[1] > 0xFuLL )
v18 = FileName[0];
remove(v18);
}
v20 = v43;
if ( v45 > 0xF )
v20 = (char **)v43[0];
v21 = pugi::xml_document::save_file(this, v20, "\t", 4, 0);
if ( !v21 )
{
v22 = OldFilename;
if ( v49.m128i_i64[1] > 0xFuLL )
v22 = (char **)OldFilename[0];
sub_180016A40((__int64)v39, (__int64)v22, 1, 0x40u, 1);
v23 = v43;
if ( v45 > 0xF )
v23 = (char **)v43[0];
sub_180016B60((__int64)&v35, (__int64)v23, 2, 0x40u, 1);
v33 = std::ios::rdbuf((char *)v39 + *(int *)(v39[0] + 4LL));
v24 = std::ios::rdbuf(&v36[*(int *)(v35 + 4) - 8]);
v25 = 0;
v26 = v33;
if ( v33 )
goto LABEL_42;
while ( 1 )
{
while ( 1 )
{
if ( !v26 )
{
*(_QWORD *)&v36[*(int *)(v35 + 4) - 8] = &std::ofstream::`vftable';
*(_DWORD *)((char *)&v34 + *(int *)(v35 + 4) + 12) = *(_DWORD *)(v35 + 4) - 168;
sub_1800178D0((__int64)v36);
std::ostream::~ostream>(v37);
std::ios::~ios>(v38);
*(_QWORD *)((char *)v39 + *(int *)(v39[0] + 4LL)) = &std::ifstream::`vftable';
*(_DWORD *)&v38[*(int *)(v39[0] + 4LL) + 100] = *(_DWORD *)(v39[0] + 4LL) - 176;
sub_1800178D0((__int64)v40);
std::istream::~istream>(v41);
std::ios::~ios>(v42);
goto LABEL_48;
}
if ( v24 )
std::streambuf::sputc(v24, v25);
if ( (unsigned int)std::streambuf::sbumpc(v26) != -1 )
break;
LABEL_45:
v26 = 0;
}
LABEL_42:
if ( !v26 )
goto LABEL_45;
v27 = std::streambuf::sgetc(v26);
if ( v27 == -1 )
goto LABEL_45;
v25 = v27;
}
}
LABEL_48:
if ( si128.m128i_i64[1] > 0xFuLL )
{
v28 = FileName[0];
if ( (unsigned __int64)(si128.m128i_i64[1] + 1) >= 0x1000 )
{
v28 = *((char **)FileName[0] - 1);
if ( (unsigned __int64)(FileName[0] - v28 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free_0(v28);
}
si128 = _mm_load_si128((const __m128i *)&xmmword_1800E7160);
LOBYTE(FileName[0]) = 0;
if ( v49.m128i_i64[1] > 0xFuLL )
{
v29 = OldFilename[0];
if ( (unsigned __int64)(v49.m128i_i64[1] + 1) >= 0x1000 )
{
v29 = *((char **)OldFilename[0] - 1);
if ( (unsigned __int64)(OldFilename[0] - v29 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free_0(v29);
}
v49 = _mm_load_si128((const __m128i *)&xmmword_1800E7160);
LOBYTE(OldFilename[0]) = 0;
if ( v52 > 0xF )
{
v30 = Block[0];
if ( v52 + 1 >= 0x1000 )
{
v30 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v30 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free_0(v30);
}
v51 = 0;
v52 = 15;
LOBYTE(Block[0]) = 0;
if ( v45 > 0xF )
{
v31 = v43[0];
if ( v45 + 1 >= 0x1000 )
{
v31 = *((char **)v43[0] - 1);
if ( (unsigned __int64)(v43[0] - v31 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free_0(v31);
}
return v21;
}