//
// GJGameLevel::savePercentage from 0x3d5484 to 0x3d561a (406 bytes)
//
// 2 xrefs:
// > PlayLayer::levelComplete @ 0x313604
// > PlayLayer::destroyPlayer @ 0x313f00
//
// 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 GJGameLevel::savePercentage(GJGameLevel *a1, int a2, bool a3, int a4, int a5, bool a6)
{
int v8; // r5
_BOOL4 v9; // r9
int m_practicePercent; // r3
int NormalPercent; // r0
int v12; // r10
int v13; // r9
int v14; // r10
char *v15; // r0
int v16; // [sp+0h] [bp-214h] BYREF
_DWORD v17[2]; // [sp+4h] [bp-210h] BYREF
unsigned int v18[3]; // [sp+Ch] [bp-208h] BYREF
char v19; // [sp+18h] [bp-1FCh] BYREF
if ( a2 >= 100 )
a2 = 100;
v8 = a2 & ~(a2 >> 31);
v9 = a3;
if ( a3 )
{
m_practicePercent = a1->m_practicePercent;
if ( m_practicePercent < v8 )
{
LABEL_12:
a1->m_practicePercent = v8;
return;
}
if ( m_practicePercent != v8 )
return;
LABEL_9:
if ( a4 <= 0 || a1->m_clicks.random - a1->m_clicks.seed > 0 )
{
if ( v9 )
return;
goto LABEL_15;
}
if ( v9 )
goto LABEL_12;
goto LABEL_13;
}
NormalPercent = GJGameLevel::getNormalPercent(a1);
if ( NormalPercent >= v8 )
{
if ( NormalPercent != v8 )
goto LABEL_15;
goto LABEL_9;
}
LABEL_13:
GJGameLevel::setNormalPercent(a1, v8);
LABEL_15:
v12 = a1->m_newNormalPercent2.random - a1->m_newNormalPercent2.seed;
if ( v12 < v8 )
{
GJGameLevel::setNewNormalPercent2(a1, v8);
GJGameLevel::setClicks(a1, a4);
GJGameLevel::setAttemptTime(a1, a5);
a1->m_isChkValid = a6;
v13 = 1482;
if ( !a6 )
v13 = 0;
a1->m_chk = (a5 + 4085) * (a5 + 4085) + (a4 + 3991) * (v8 + 8354) + v13 - 50028039;
v14 = v8 - v12;
sub_775C20(&v16);
v18[1] = 500;
v18[2] = (unsigned int)&v19;
v18[0] = 0;
if ( *(_DWORD *)(v16 - 12) )
{
v17[0] = ",";
v17[1] = 0;
fmt::BasicWriter::operator<<(v18, ",", 0);
}
fmt::BasicWriter::operator<<(v18, v14);
v15 = (char *)fmt::BasicWriter::c_str((int *)v18);
sub_774544((int)&v16, v15);
sub_775C20(v17);
sub_775D40(&a1->m_personalBests, v17);
sub_774008(v17);
fmt::internal::Array::free((int)v18);
sub_774008(&v16);
}
if ( a1->m_orbCompletion.random - a1->m_orbCompletion.seed < v8 )
GJGameLevel::setNewNormalPercent(a1, v8);
}