//
// GJBaseGameLayer::resetRecord from 0x1002014b4 to 0x100201788 (724 bytes)
//
// 2 xrefs:
// > PlayLayer::resetLevel @ 0x100122020
// > PlayLayer::resetLevel @ 0x10012203c
//
// 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 __fastcall GJBaseGameLayer::resetRecord(GJBaseGameLayer *a1, int a2, bool a3)
{
__n128 v3; // q0
bool *p_m_isPlatformer; // x21
RecordButtonCommand *begin; // x8
std::__vector_base::pointer end; // x9
std::__vector_base::pointer v9; // x10
unsigned int v10; // w8
unsigned __int64 v11; // x10
__int64 v12; // x11
int v13; // w23
RecordButtonCommand *v14; // x12
PlayerButton m_button; // t1
__int64 v16; // x24
int v17; // w25
int *p_m_step; // x8
unsigned int v19; // w11
int v20; // w13
float v21; // s1
bool v22; // cc
std::__hash_node_base, void *> *>::__next_pointer i; // x1
int m_unk3370; // w8
int m_tickIndex; // w9
int m_points; // w9
__int64 v28; // x0
__int64 v29; // x8
__int128 v30; // q0
__int128 v31; // [xsp+0h] [xbp-A0h] BYREF
__int128 v32; // [xsp+10h] [xbp-90h]
__int64 v33; // [xsp+20h] [xbp-80h]
std::string __p; // [xsp+28h] [xbp-78h] BYREF
__int128 v35; // [xsp+44h] [xbp-5Ch] BYREF
char v36; // [xsp+57h] [xbp-49h] BYREF
__int128 *v37; // [xsp+58h] [xbp-48h] BYREF
p_m_isPlatformer = &a1->m_isPlatformer;
if ( a1->m_recordInputs && !a1->m_useReplay )
{
begin = a1->m_queuedRecordedButtons.__begin_;
end = a1->m_queuedRecordedButtons.__end_;
if ( begin == end )
{
LABEL_7:
if ( a2 <= 0 && !a3 )
{
a1->m_queuedRecordedButtons.__end_ = begin;
sub_1002122F8(&a1->m_unk3330);
a1->m_unk3370 = 0;
a1->m_queuedRecordedButtonsSize = 0;
a1->m_currentStep = 0;
return;
}
}
else
{
v9 = a1->m_queuedRecordedButtons.__begin_;
while ( v9->m_button != 98 )
{
if ( ++v9 == end )
goto LABEL_7;
}
}
if ( a3 )
{
v10 = 98;
LABEL_48:
*(_QWORD *)&v35 = v10;
m_unk3370 = a1->m_unk3370;
a1->m_unk3370 = m_unk3370 + 1;
*((_QWORD *)&v35 + 1) = __PAIR64__(m_unk3370, a2);
sub_1002013E0((__int64)&a1->m_queuedRecordedButtons, &v35);
memset(&__p, 0, sizeof(__p));
*((_QWORD *)&v31 + 1) = a1->m_randomSeed;
*(_QWORD *)&v31 = __PAIR64__(a2, HIDWORD(v35));
m_tickIndex = a1->m_tickIndex;
LODWORD(v32) = a1->m_attempts;
DWORD1(v32) = m_tickIndex;
m_points = a1->m_gameState.m_points;
LODWORD(v33) = a1->m_clickIndex;
HIDWORD(v33) = m_points;
*((_QWORD *)&v32 + 1) = llround(a1->m_timePlayed * 100000.0);
std::string::operator=(&__p, (const std::string *)&a1->m_persistentStateString);
v37 = &v31;
v28 = sub_1002124E4(&a1->m_unk3330, &v31, &unk_10063A31C, &v37, &v36);
v29 = v33;
v30 = v32;
*(_OWORD *)(v28 + 24) = v31;
*(_OWORD *)(v28 + 40) = v30;
*(_QWORD *)(v28 + 56) = v29;
std::string::operator=((std::string *)(v28 + 64), &__p);
a1->m_currentStep = a2;
++a1->m_queuedRecordedButtonsSize;
if ( SHIBYTE(__p.__r_.__value_.__r.__words[2]) < 0 )
operator delete(__p.__r_.__value_.__l.__data_);
return;
}
v11 = end - begin;
if ( (int)v11 < 1 )
{
LABEL_16:
v13 = 0;
}
else
{
v12 = (end - begin) & 0x7FFFFFFF;
v13 = (v11 & 0x7FFFFFFF) - 1;
v14 = &begin[v12 - 1];
while ( 1 )
{
m_button = v14->m_button;
--v14;
if ( m_button == 98 )
break;
--v13;
if ( !--v12 )
goto LABEL_16;
}
}
if ( begin == end )
{
LODWORD(v16) = 0;
v17 = 0;
}
else
{
v16 = 0;
v17 = 0;
v3.n128_f32[0] = (float)a2;
if ( v11 <= 1 )
v11 = 1;
p_m_step = &begin->m_step;
while ( 1 )
{
v19 = *(p_m_step - 2) & 0xFFFFFFFE;
v20 = v19 == 98 ? 0 : v17;
v21 = (float)(*p_m_step + v20);
if ( v16 >= v13 && v21 > v3.n128_f32[0] )
break;
v22 = v19 != 98 || v16 < v13;
if ( !v22 && v21 == v3.n128_f32[0] )
break;
p_m_step += 4;
v17 = (int)v21;
if ( v11 == ++v16 )
{
LODWORD(v16) = v11;
break;
}
}
}
for ( i = a1->m_unk3330.__table_.__p1_.__value_.__next_; i; i = i->__next_ )
{
while ( SHIDWORD(i[3].__next_) > a2 )
{
i = (std::__hash_node_base, void *> *>::__next_pointer)sub_10021234C(&a1->m_unk3330, v3);
if ( !i )
goto LABEL_39;
}
}
LABEL_39:
sub_1002017A4(&a1->m_queuedRecordedButtons, (unsigned int)v16, v3);
a1->m_queuedRecordedButtonsSize = v16;
if ( !*p_m_isPlatformer )
a1->m_currentStep = v17;
if ( (_DWORD)v16 != v13 || (_DWORD)v16 == 0 )
v10 = 99;
else
v10 = 98;
if ( p_m_isPlatformer[474] )
goto LABEL_48;
}
}