//
// sub_140222BE0 from 0x140222be0 to 0x1402230f7 (1303 bytes)
//
// 3 xrefs:
// > GameLevelManager::writePlatformerSaveJournal @ 0x14022343a
// > GJGameLevel::clearPlatformerSave @ 0x14026417a
// > ??> @ 0x14091bc80
//
// 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 11:28:25 +0000
//
// Hidden C++ exception states: #wind=3
__int64 __fastcall sub_140222BE0(__int64 a1, __int64 a2)
{
void **v4; // rax
__int64 v5; // rdx
void *v6; // rcx
int v7; // edx
cocos2d::CCString *v8; // rax
char *v9; // rax
size_t v10; // rbx
size_t v11; // r8
__m128i *v12; // rax
__m128i *v13; // rax
cocos2d::CCString *v14; // rax
char *v15; // rax
_QWORD *v16; // rax
void *v17; // rcx
__m128i v18; // xmm0
void *v19; // rcx
void *v20; // rcx
int v21; // edx
int v22; // eax
cocos2d::CCString *v23; // rax
char *CString; // rax
size_t v25; // rbx
_QWORD *v26; // rax
cocos2d::CCString *v27; // rax
char *v28; // rax
size_t v29; // rbx
_QWORD *v30; // rax
void *Src[2]; // [rsp+40h] [rbp-29h] BYREF
__m128i v33; // [rsp+50h] [rbp-19h]
void *Block[2]; // [rsp+60h] [rbp-9h] BYREF
__m128i si128; // [rsp+70h] [rbp+7h]
void *v36[2]; // [rsp+80h] [rbp+17h] BYREF
__m128i v37; // [rsp+90h] [rbp+27h]
if ( *(_DWORD *)(a2 + 1220) == 2 )
{
if ( !*(_QWORD *)(a2 + 1608) )
{
v4 = GameToolbox::gen_random(Src, 0x10u);
sub_140059C40(a2 + 1592, (__int64)v4);
sub_14003D310((__int64)Src);
}
sub_14003F4F0((__int64)Src, a2 + 1592);
*(_OWORD *)Block = 0;
si128 = _mm_load_si128((const __m128i *)&xmmword_140836520);
LOWORD(Block[0]) = 108;
sub_140076160((char *)a1, v5, Block, Src);
if ( si128.m128i_i64[1] > 0xFuLL )
{
v6 = Block[0];
if ( (unsigned __int64)(si128.m128i_i64[1] + 1) >= 0x1000 )
{
v6 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v6 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v6);
}
sub_14003D310((__int64)Src);
return a1;
}
v7 = *(_DWORD *)(a2 + 992) - *(_DWORD *)(a2 + 996);
*(_OWORD *)Src = 0;
v33 = _mm_load_si128((const __m128i *)&xmmword_140836520);
if ( v7 <= 0 )
{
v21 = *(_DWORD *)(a2 + 328);
v22 = *(_DWORD *)(a2 + 332);
if ( *(_BYTE *)(a2 + 721) )
{
LOWORD(Src[0]) = 103;
v23 = cocos2d::CCString::createWithFormat((const char *)&word_1406ED6F8, (unsigned int)(v21 - v22));
CString = (char *)cocos2d::CCString::getCString(v23);
v25 = -1;
do
++v25;
while ( CString[v25] );
v26 = sub_140044D80(Src, CString, v25);
*(_OWORD *)a1 = 0;
*(_QWORD *)(a1 + 16) = 0;
*(_QWORD *)(a1 + 24) = 0;
*(_OWORD *)a1 = *(_OWORD *)v26;
*(_OWORD *)(a1 + 16) = *((_OWORD *)v26 + 1);
v26[2] = 0;
v26[3] = 15;
*(_BYTE *)v26 = 0;
if ( v33.m128i_i64[1] <= 0xFuLL )
return a1;
v20 = Src[0];
if ( (unsigned __int64)(v33.m128i_i64[1] + 1) >= 0x1000 )
{
v20 = *((void **)Src[0] - 1);
if ( (unsigned __int64)((char *)Src[0] - (char *)v20 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
}
else
{
LOWORD(Src[0]) = 111;
v27 = cocos2d::CCString::createWithFormat((const char *)&word_1406ED6F8, (unsigned int)(v21 - v22));
v28 = (char *)cocos2d::CCString::getCString(v27);
v29 = -1;
do
++v29;
while ( v28[v29] );
v30 = sub_140044D80(Src, v28, v29);
*(_OWORD *)a1 = 0;
*(_QWORD *)(a1 + 16) = 0;
*(_QWORD *)(a1 + 24) = 0;
*(_OWORD *)a1 = *(_OWORD *)v30;
*(_OWORD *)(a1 + 16) = *((_OWORD *)v30 + 1);
v30[2] = 0;
v30[3] = 15;
*(_BYTE *)v30 = 0;
if ( v33.m128i_i64[1] <= 0xFuLL )
return a1;
v20 = Src[0];
if ( (unsigned __int64)(v33.m128i_i64[1] + 1) >= 0x1000 )
{
v20 = *((void **)Src[0] - 1);
if ( (unsigned __int64)((char *)Src[0] - (char *)v20 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
}
LABEL_42:
j_j_free(v20);
return a1;
}
LOWORD(Src[0]) = 100;
v8 = cocos2d::CCString::createWithFormat((const char *)&word_1406ED6F8);
v9 = (char *)cocos2d::CCString::getCString(v8);
v10 = -1;
v11 = -1;
do
++v11;
while ( v9[v11] );
v12 = (__m128i *)sub_140044D80(Src, v9, v11);
*(_OWORD *)Block = 0;
si128 = 0;
*(__m128i *)Block = *v12;
si128 = v12[1];
v12[1].m128i_i64[0] = 0;
v12[1].m128i_i64[1] = 15;
v12->m128i_i8[0] = 0;
v13 = (__m128i *)sub_140044D80(Block, "_", 1u);
*(_OWORD *)v36 = 0;
v37 = 0;
*(__m128i *)v36 = *v13;
v37 = v13[1];
v13[1].m128i_i64[0] = 0;
v13[1].m128i_i64[1] = 15;
v13->m128i_i8[0] = 0;
v14 = cocos2d::CCString::createWithFormat(
(const char *)&word_1406ED6F8,
(unsigned int)(*(_DWORD *)(a2 + 328) - *(_DWORD *)(a2 + 332)));
v15 = (char *)cocos2d::CCString::getCString(v14);
do
++v10;
while ( v15[v10] );
v16 = sub_140044D80(v36, v15, v10);
*(_OWORD *)a1 = 0;
*(_QWORD *)(a1 + 16) = 0;
*(_QWORD *)(a1 + 24) = 0;
*(_OWORD *)a1 = *(_OWORD *)v16;
*(_OWORD *)(a1 + 16) = *((_OWORD *)v16 + 1);
v16[2] = 0;
v16[3] = 15;
*(_BYTE *)v16 = 0;
if ( v37.m128i_i64[1] > 0xFuLL )
{
v17 = v36[0];
if ( (unsigned __int64)(v37.m128i_i64[1] + 1) >= 0x1000 )
{
v17 = *((void **)v36[0] - 1);
if ( (unsigned __int64)((char *)v36[0] - (char *)v17 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v17);
}
v18 = _mm_load_si128((const __m128i *)&Size);
v37 = v18;
LOBYTE(v36[0]) = 0;
if ( si128.m128i_i64[1] > 0xFuLL )
{
v19 = Block[0];
if ( (unsigned __int64)(si128.m128i_i64[1] + 1) >= 0x1000 )
{
v19 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v19 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v19);
v18 = _mm_load_si128((const __m128i *)&Size);
}
si128 = v18;
LOBYTE(Block[0]) = 0;
if ( v33.m128i_i64[1] > 0xFuLL )
{
v20 = Src[0];
if ( (unsigned __int64)(v33.m128i_i64[1] + 1) >= 0x1000 )
{
v20 = *((void **)Src[0] - 1);
if ( (unsigned __int64)((char *)Src[0] - (char *)v20 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
goto LABEL_42;
}
return a1;
}