//
// SetupTriggerPopup::toggleLimitValue from 0x9eda10 to 0x9edc18 (520 bytes)
//
// 16 xrefs:
// > SetupSongTriggerPopup::init @ 0x9aa46c
// > SetupSongTriggerPopup::init @ 0x9aa47c
// > SetupSongTriggerPopup::init @ 0x9aa604
// > SetupOptionsTriggerPopup::init @ 0x9e2bc8
// > SetupSFXPopup::init @ 0xa405f4
// > SetupSFXPopup::init @ 0xa40604
// > SetupSFXPopup::init @ 0xa40614
// > SetupSFXPopup::init @ 0xa40df8
// > SetupSFXPopup::init @ 0xa40e08
// > SetupSFXPopup::init @ 0xa40e18
// > SetupSFXEditPopup::init @ 0xa42114
// > SetupSFXEditPopup::init @ 0xa42124
// > SetupSFXEditPopup::init @ 0xa42264
// > SetupItemCompareTriggerPopup::init @ 0xa4cee0
// > SetupItemCompareTriggerPopup::init @ 0xa4d1f8
// > ??> @ 0xb2788
//
// 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 SetupTriggerPopup::toggleLimitValue(SetupTriggerPopup *a1, int a2, bool a3)
{
std::map *p_m_shouldLimitValues; // x24
std::_rb_tree_base *p_m_header; // x22
std::_rb_tree_base *m_parent; // x0
std::_rb_tree_base *v8; // x19
std::_rb_tree_base *m_right; // x20
__int64 v10; // x0
int v11; // w1
__int64 v12; // x25
int *v13; // x27
int v14; // w26
__int64 insert_unique_pos; // x0
__int64 v16; // x0
std::_rb_tree_base *v17; // x2
_BOOL8 v18; // x0
std::_rb_tree_base *v19; // x1
std::_rb_tree_base *v20; // x2
p_m_shouldLimitValues = &a1->m_shouldLimitValues;
p_m_header = &a1->m_shouldLimitValues.m_header;
m_parent = a1->m_shouldLimitValues.m_header.m_parent;
if ( !m_parent )
goto LABEL_23;
v8 = p_m_header;
do
{
while ( *(_DWORD *)&m_parent[1].m_isblack >= a2 )
{
v8 = m_parent;
m_parent = m_parent->m_left;
if ( !m_parent )
goto LABEL_5;
}
m_parent = m_parent->m_right;
}
while ( m_parent );
LABEL_5:
m_right = v8;
if ( p_m_header == v8 )
{
LABEL_23:
v12 = operator new(0x28u);
*(_DWORD *)(v12 + 32) = a2;
*(_BYTE *)(v12 + 36) = 0;
if ( a1->m_shouldLimitValues.m_nodecount )
{
m_right = a1->m_shouldLimitValues.m_header.m_right;
if ( a2 > *(_DWORD *)&m_right[1].m_isblack )
{
insert_unique_pos = 0;
goto LABEL_13;
}
}
insert_unique_pos = std::_Rb_tree,std::_Select1st>,std::less,std::allocator>>::_M_get_insert_unique_pos(
(__int64)p_m_shouldLimitValues,
(int *)(v12 + 32));
v20 = (std::_rb_tree_base *)insert_unique_pos;
m_right = v19;
LABEL_31:
if ( !v19 )
{
m_right = v20;
goto LABEL_22;
}
LABEL_13:
if ( insert_unique_pos || p_m_header == m_right )
{
v17 = m_right;
v18 = 1;
m_right = (std::_rb_tree_base *)v12;
goto LABEL_17;
}
v11 = *(_DWORD *)(v12 + 32);
v14 = *(_DWORD *)&m_right[1].m_isblack;
LABEL_16:
v17 = m_right;
v18 = v11 < v14;
m_right = (std::_rb_tree_base *)v12;
LABEL_17:
sub_CFAD74(v18, v12, v17, p_m_header);
++p_m_shouldLimitValues->m_nodecount;
goto LABEL_18;
}
if ( a2 < *(_DWORD *)&v8[1].m_isblack )
{
v10 = operator new(0x28u);
*(_BYTE *)(v10 + 36) = 0;
v11 = a2;
v12 = v10;
*(_DWORD *)(v10 + 32) = a2;
v13 = (int *)(v10 + 32);
v14 = *(_DWORD *)&v8[1].m_isblack;
if ( a2 >= v14 )
{
if ( a2 <= v14 )
{
LABEL_22:
operator delete((void *)v12);
goto LABEL_18;
}
if ( v8 == a1->m_shouldLimitValues.m_header.m_right )
goto LABEL_16;
insert_unique_pos = sub_CFAB14(v8);
v11 = a2;
if ( a2 < *(_DWORD *)(insert_unique_pos + 32) )
{
if ( !v8->m_right )
goto LABEL_16;
m_right = (std::_rb_tree_base *)insert_unique_pos;
goto LABEL_13;
}
}
else
{
insert_unique_pos = (__int64)a1->m_shouldLimitValues.m_header.m_left;
if ( v8 == (std::_rb_tree_base *)insert_unique_pos )
goto LABEL_13;
v16 = sub_CFABD4(v8);
if ( a2 > *(_DWORD *)(v16 + 32) )
{
if ( *(_QWORD *)(v16 + 24) )
{
insert_unique_pos = (__int64)v8;
}
else
{
m_right = (std::_rb_tree_base *)v16;
insert_unique_pos = 0;
}
goto LABEL_13;
}
}
insert_unique_pos = std::_Rb_tree,std::_Select1st>,std::less,std::allocator>>::_M_get_insert_unique_pos(
(__int64)p_m_shouldLimitValues,
v13);
v20 = (std::_rb_tree_base *)insert_unique_pos;
m_right = v19;
goto LABEL_31;
}
LABEL_18:
*(&m_right[1].m_isblack + 4) = a3;
}