//
// PlayLayer::writePersistentSave from 0x140517f10 to 0x1405182a2 (914 bytes)
//
// 7 xrefs:
// > GameManager::encodeDataTo @ 0x140285970
// > LocalLevelManager::encodeDataTo @ 0x14046b7ea
// > PauseLayer::onPracticeMode @ 0x1404dab25
// > PlayLayer::removeAllCheckpoints @ 0x140517219
// > PlayLayer::togglePracticeMode @ 0x14051a010
// > PlayLayer::onQuit @ 0x14051b0b9
// > ??> @ 0x14092adc4
//
// 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:33:34 +0000
//
// Hidden C++ exception states: #wind=2
void __fastcall PlayLayer::writePersistentSave(_BYTE *a1)
{
__int64 v1; // rbp
__int64 v2; // rcx
__int64 v3; // r14
_QWORD *v4; // r15
_QWORD *v5; // r12
_QWORD *v6; // rbx
__int64 v7; // r8
__int64 v8; // rcx
__int64 v9; // rsi
__int64 v10; // r8
int v11; // eax
__int64 v12; // rdi
__int64 v13; // rax
__int64 RecordString; // rax
void *v15; // [rsp+30h] [rbp-88h]
_BYTE v17[32]; // [rsp+40h] [rbp-78h] BYREF
_BYTE v18[32]; // [rsp+60h] [rbp-58h] BYREF
v1 = (__int64)a1;
if ( !a1[12670] || a1[13024] || a1[13096] )
return;
v2 = qword_14090BFD0;
if ( !qword_14090BFD0 )
{
v15 = operator new(0x6E8u);
qword_14090BFD0 = GameManager::GameManager((__int64)v15);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_14090BFD0 + 72LL))(qword_14090BFD0);
v2 = qword_14090BFD0;
}
if ( GameManager::getGameVariable(v2, "0192") && !*(_BYTE *)(*(_QWORD *)(v1 + 2168) + 1704LL) )
return;
v3 = *(_QWORD *)(v1 + 14832);
if ( !v3 )
return;
*(_DWORD *)(v3 + 4700) = *(_DWORD *)(v1 + 12644);
*(_QWORD *)(v3 + 4704) = *(_QWORD *)(v1 + 15384);
*(_QWORD *)(v3 + 4712) = *(_QWORD *)(v1 + 15392);
*(_DWORD *)(v3 + 4720) = *(_DWORD *)(v1 + 12640);
*(_QWORD *)(v3 + 4728) = *(_QWORD *)(v1 + 13920);
*(_DWORD *)(v3 + 4736) = *(_DWORD *)(v1 + 13928);
*(_DWORD *)(v3 + 4740) = *(_DWORD *)(v1 + 13932);
*(_DWORD *)(v3 + 4744) = *(_DWORD *)(v1 + 15304);
v4 = *(_QWORD **)(v1 + 2408);
sub_14036F9A0((_QWORD *)(v3 + 4880));
sub_140069360((_QWORD *)(v3 + 4752), v4 + 110);
sub_140373340((_QWORD *)(v3 + 4816), v4 + 118);
v5 = (_QWORD *)v4[119];
v6 = (_QWORD *)*v5;
if ( (_QWORD *)*v5 == v5 )
goto LABEL_22;
do
{
v7 = v4[146];
v8 = *(_QWORD *)(v7
+ 16
* (v4[149]
& (0x100000001B3LL
* (*((unsigned __int8 *)v6 + 19)
^ (0x100000001B3LL
* (*((unsigned __int8 *)v6 + 18)
^ (0x100000001B3LL
* (*((unsigned __int8 *)v6 + 17)
^ (0x100000001B3LL * (*((unsigned __int8 *)v6 + 16) ^ 0xCBF29CE484222325uLL)))))))))
+ 8);
v9 = v4[144];
if ( v8 != v9 )
{
v10 = *(_QWORD *)(v7
+ 16
* (v4[149]
& (0x100000001B3LL
* (*((unsigned __int8 *)v6 + 19)
^ (0x100000001B3LL
* (*((unsigned __int8 *)v6 + 18)
^ (0x100000001B3LL
* (*((unsigned __int8 *)v6 + 17)
^ (0x100000001B3LL * (*((unsigned __int8 *)v6 + 16) ^ 0xCBF29CE484222325uLL))))))))));
v11 = *((_DWORD *)v6 + 4);
if ( v11 == *(_DWORD *)(v8 + 16) )
goto LABEL_16;
while ( v8 != v10 )
{
v8 = *(_QWORD *)(v8 + 8);
if ( v11 == *(_DWORD *)(v8 + 16) )
goto LABEL_16;
}
}
v8 = 0;
LABEL_16:
if ( v8 )
v9 = v8;
if ( v9 != v4[144] )
{
v12 = *(_QWORD *)sub_140370710((_QWORD *)(v3 + 4880), (__int64)v17, (unsigned __int8 *)(v9 + 16));
*(_DWORD *)(v12 + 24) = *(_DWORD *)(v9 + 24);
*(_QWORD *)(v12 + 32) = *(_QWORD *)(v9 + 32);
*(_BYTE *)(v12 + 40) = *(_BYTE *)(v9 + 40);
*(_DWORD *)(v12 + 44) = *(_DWORD *)(v9 + 44);
*(_BYTE *)(v12 + 48) = *(_BYTE *)(v9 + 48);
*(_QWORD *)(v12 + 56) = *(_QWORD *)(v9 + 56);
*(_BYTE *)(v12 + 64) = *(_BYTE *)(v9 + 64);
*(_DWORD *)(v12 + 68) = *(_DWORD *)(v9 + 68);
*(_DWORD *)(v12 + 72) = *(_DWORD *)(v9 + 72);
*(_DWORD *)(v12 + 76) = *(_DWORD *)(v9 + 76);
sub_140099FC0((void **)(v12 + 80), (char **)(v9 + 80));
*(_BYTE *)(v12 + 104) = *(_BYTE *)(v9 + 104);
}
v6 = (_QWORD *)*v6;
}
while ( v6 != v5 );
v1 = (__int64)a1;
LABEL_22:
serializeCheckpoint(v18, v3);
v13 = cocos2d::ZipUtils::compressString(v17, v18, 0, 0xFFFFFFFFLL, 11);
sub_140059C40(*(_QWORD *)(v1 + 2168) + 1632LL, v13);
sub_14003D310((__int64)v17);
*(_DWORD *)(*(_QWORD *)(v1 + 2168) + 1696LL) = *(_DWORD *)(*(_QWORD *)(v1 + 2168) + 860LL);
*(_DWORD *)(*(_QWORD *)(v1 + 2168) + 1700LL) = 4;
RecordString = GJBaseGameLayer::getRecordString(v1, (__int64)v17);
sub_140059C40(*(_QWORD *)(v1 + 2168) + 1664LL, RecordString);
sub_14003D310((__int64)v17);
sub_14003D310((__int64)v18);
}