//
// GJBaseGameLayer::resetRecord from 0x483e98 to 0x48421e (902 bytes)
//
// 2 xrefs:
// > PlayLayer::resetLevel @ 0x31fb52
// > PlayLayer::resetLevel @ 0x31fb82
//
// 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 GJBaseGameLayer::resetRecord(GJBaseGameLayer *a1, int a2, bool a3)
{
RecordButtonCommand *m_start; // r6
RecordButtonCommand *m_finish; // r1
RecordButtonCommand *v7; // r0
RecordButtonCommand *v8; // r3
PlayerButton m_button; // t1
int v10; // r3
int v11; // r5
int v12; // r2
int v13; // r3
int v14; // r11
int v15; // r1
unsigned int v16; // r5
int m_step; // r3
unsigned int v18; // r2
float v19; // s15
std::unordered_map *p_m_unk3330; // r7
std::__detail::_Hash_node_base *M_nxt; // r6
RecordButtonCommand *v22; // r3
unsigned int v23; // r1
int m_unk3370; // r3
int v25; // r1
RecordButtonCommand *v26; // r5
RecordButtonCommand *m_reserveEnd; // r3
int v28; // r1
int v29; // r2
int v30; // r3
__int64 v31; // r0
unsigned int v32; // r9
std::_Hashtable, std::allocator>, std::__detail::_Select1st, std::equal_to, std::hash, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits>::size_type v33; // r11
_DWORD **v34; // r0
_DWORD *inserted; // r0
_DWORD *v36; // r0
int v37; // r3
_DWORD *v38; // r10
_QWORD *v39; // r0
std::_Hashtable, std::allocator>, std::__detail::_Select1st, std::equal_to, std::hash, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits>::size_type M_bucket_count; // r2
int v41; // r10
std::__detail::_Hash_node_base *j; // r9
std::__detail::_Hash_node_base *v43; // r12
int v44; // r1
std::_Hashtable, std::allocator>, std::__detail::_Select1st, std::equal_to, std::hash, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits>::__bucket_type *M_buckets; // r3
int v46; // r1
std::__detail::_Hash_node_base *v47; // r9
int i; // [sp+4h] [bp-60h]
_DWORD v49[4]; // [sp+18h] [bp-4Ch] BYREF
_QWORD v50[6]; // [sp+28h] [bp-3Ch] BYREF
if ( !a1->m_recordInputs || a1->m_useReplay )
return;
m_start = a1->m_queuedRecordedButtons.m_start;
m_finish = a1->m_queuedRecordedButtons.m_finish;
v7 = m_start;
v8 = m_start;
while ( m_finish != v8 )
{
m_button = v8->m_button;
++v8;
if ( m_button == 98 )
{
v10 = 1;
goto LABEL_8;
}
}
v10 = 0;
LABEL_8:
if ( a2 <= 0 )
{
if ( !a3 )
{
if ( !v10 )
{
GJBaseGameLayer::resetRecordFull(a1);
return;
}
goto LABEL_14;
}
LABEL_13:
v11 = 98;
goto LABEL_33;
}
if ( a3 )
goto LABEL_13;
LABEL_14:
v12 = (char *)m_finish - (char *)m_start;
v13 = 1;
v14 = 0;
v15 = m_finish - m_start;
do
{
if ( v13 - 1 >= v15 )
break;
v14 = v15 - v13++;
}
while ( *(PlayerButton *)((char *)&m_start[1].m_button + v12 - 16 * v13) != 98 );
v16 = 0;
for ( i = 0; v16 != v15; i = (int)v19 )
{
m_step = v7->m_step;
v18 = v7->m_button - 98;
if ( v18 > 1 )
m_step += i;
v19 = (float)m_step;
if ( (int)v16 >= v14 && (v19 > (float)a2 || v19 == (float)a2 && v18 <= 1) )
break;
++v16;
++v7;
}
p_m_unk3330 = &a1->m_unk3330;
M_nxt = a1->m_unk3330._M_h._M_before_begin._M_nxt;
while ( M_nxt )
{
if ( (int)M_nxt[5]._M_nxt <= a2 )
{
M_nxt = M_nxt->_M_nxt;
}
else
{
M_bucket_count = a1->m_unk3330._M_h._M_bucket_count;
v41 = (unsigned int)M_nxt[2]._M_nxt % M_bucket_count;
for ( j = p_m_unk3330->_M_h._M_buckets[v41]; j->_M_nxt != M_nxt; j = j->_M_nxt )
;
if ( j == p_m_unk3330->_M_h._M_buckets[v41] )
{
v43 = M_nxt->_M_nxt;
if ( M_nxt->_M_nxt )
{
v44 = (unsigned int)v43[2]._M_nxt % M_bucket_count;
if ( v44 == v41 )
goto LABEL_60;
p_m_unk3330->_M_h._M_buckets[v44] = j;
}
M_buckets = p_m_unk3330->_M_h._M_buckets;
if ( p_m_unk3330->_M_h._M_buckets[v41] == &a1->m_unk3330._M_h._M_before_begin )
a1->m_unk3330._M_h._M_before_begin._M_nxt = v43;
M_buckets[v41] = nullptr;
}
else if ( M_nxt->_M_nxt )
{
v46 = (unsigned int)M_nxt->_M_nxt[2]._M_nxt % M_bucket_count;
if ( v46 != v41 )
p_m_unk3330->_M_h._M_buckets[v46] = j;
}
LABEL_60:
j->_M_nxt = M_nxt->_M_nxt;
v47 = M_nxt->_M_nxt;
sub_774008(&M_nxt[14]);
operator delete(M_nxt);
M_nxt = v47;
--a1->m_unk3330._M_h._M_element_count;
}
}
v22 = a1->m_queuedRecordedButtons.m_start;
v23 = a1->m_queuedRecordedButtons.m_finish - v22;
if ( v16 <= v23 )
{
if ( v16 < v23 )
a1->m_queuedRecordedButtons.m_finish = &v22[v16];
}
else
{
std::vector::_M_default_append((const void **)&a1->m_queuedRecordedButtons.m_start, v16 - v23);
}
a1->m_queuedRecordedButtonsSize = v16;
if ( !a1->m_isPlatformer )
a1->m_currentStep = i;
if ( v16 )
{
if ( v16 == v14 )
v11 = 98;
else
v11 = 99;
}
else
{
v11 = 99;
}
LABEL_33:
if ( a1->m_recordInputs )
{
memset(v49, 0, sizeof(v49));
m_unk3370 = a1->m_unk3370;
v49[0] = v11;
v25 = m_unk3370 + 1;
v26 = a1->m_queuedRecordedButtons.m_finish;
v49[3] = m_unk3370;
m_reserveEnd = a1->m_queuedRecordedButtons.m_reserveEnd;
v49[2] = a2;
a1->m_unk3370 = v25;
if ( v26 == m_reserveEnd )
{
std::vector::_M_emplace_back_aux(
(const void **)&a1->m_queuedRecordedButtons.m_start,
v49);
}
else
{
if ( v26 )
{
v28 = v49[1];
v29 = v49[2];
v30 = v49[3];
v26->m_button = v49[0];
*(_DWORD *)&v26->m_isPush = v28;
v26->m_step = v29;
v26->m_unk00c = v30;
}
a1->m_queuedRecordedButtons.m_finish = v26 + 1;
}
memset(v50, 0, sizeof(v50));
LODWORD(v50[5]) = &unk_ACDDA8;
v50[0] = __PAIR64__(a2, v49[3]);
v50[1] = a1->m_randomSeed;
LODWORD(v50[2]) = a1->m_attempts;
HIDWORD(v50[2]) = a1->m_tickIndex;
LODWORD(v50[4]) = a1->m_clickIndex;
HIDWORD(v50[4]) = a1->m_gameState.m_points;
LODWORD(v31) = llround();
v50[3] = v31;
sub_775D40(&v50[5], &a1->m_persistentStateString);
v32 = v50[0];
v33 = LODWORD(v50[0]) % a1->m_unk3330._M_h._M_bucket_count;
v34 = sub_46C890(&a1->m_unk3330._M_h._M_buckets, v33, v50);
if ( !v34 || (inserted = *v34) == nullptr )
{
v36 = (_DWORD *)operator new(0x40u);
v37 = v50[0];
v38 = v36;
*v36 = 0;
v36 += 4;
*(v36 - 2) = v37;
memset(v36, 0, 0x30u);
v38[14] = &unk_ACDDA8;
inserted = std::_Hashtable,std::allocator>,std::__detail::_Select1st,std::equal_to,std::hash,std::__detail::_Mod_range_hashing,std::__detail::_Default_ranged_hash,std::__detail::_Prime_rehash_policy,std::__detail::_Hashtable_traits>::_M_insert_unique_node(
(int)&a1->m_unk3330,
v33,
v32,
v38);
}
v39 = inserted + 4;
*v39 = v50[0];
v39[1] = v50[1];
v39[2] = v50[2];
v39[3] = v50[3];
v39[4] = v50[4];
sub_775D40(v39 + 5, &v50[5]);
a1->m_currentStep = a2;
++a1->m_queuedRecordedButtonsSize;
sub_774008(&v50[5]);
}
}