//
// GJBaseGameLayer::activatePersistentItemTrigger from 0x10014d2f0 to 0x10014d6b9 (969 bytes)
//
// 1 xrefs:
// > ItemTriggerGameObject::triggerObject @ 0x1001e53d4
//
// 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::activatePersistentItemTrigger(GJBaseGameLayer *a1, ItemTriggerGameObject *a2)
{
ItemTriggerGameObject *v2; // r15
GJBaseGameLayer *v3; // r14
bool m_targetAll; // al
_DWORD *v5; // rbx
GJEffectManager *m_effectManager; // rbx
unsigned __int64 value; // r14
int *v8; // r13
int *v9; // rdx
std::__hash_node_base, void *> *>::__next_pointer next; // r14
int *v11; // r15
signed __int64 v12; // r15
__int64 v13; // r12
unsigned __int64 v14; // rax
__int64 v15; // rdx
unsigned __int64 v16; // rbx
int *v17; // rbx
_QWORD *v18; // rdi
_QWORD *v19; // rbx
void *v20; // rdi
void *v21; // [rsp+0h] [rbp-70h] BYREF
void *__p; // [rsp+10h] [rbp-60h]
int *v23; // [rsp+28h] [rbp-48h]
ItemTriggerGameObject *v24; // [rsp+30h] [rbp-40h]
GJBaseGameLayer *v25; // [rsp+38h] [rbp-38h]
void *__src; // [rsp+40h] [rbp-30h]
v2 = a2;
v3 = a1;
m_targetAll = a2->m_targetAll;
if ( a2->m_timer )
{
if ( m_targetAll )
{
if ( a2->m_reset )
{
sub_100171D40(&v21, &a1->m_effectManager->m_persistentTimerItemSet);
v5 = __p;
if ( __p )
{
do
{
if ( GJEffectManager::timerExists(a1->m_effectManager, v5[4]) )
GJEffectManager::updateTimer(a1->m_effectManager, v5[4], 0.0);
v5 = *(_DWORD **)v5;
}
while ( v5 );
v18 = __p;
if ( __p )
{
do
{
v19 = (_QWORD *)*v18;
operator delete(v18);
v18 = v19;
}
while ( v19 );
}
}
v20 = v21;
v21 = nullptr;
if ( v20 )
operator delete(v20);
}
if ( !a2->m_persistent )
GJEffectManager::removePersistentFromAllTimers(v3->m_effectManager);
}
else
{
GJEffectManager::toggleTimerPersistent(a1->m_effectManager, a2->m_itemID, a2->m_persistent);
if ( a2->m_reset && GJEffectManager::timerExists(a1->m_effectManager, a2->m_itemID) )
GJEffectManager::updateTimer(a1->m_effectManager, a2->m_itemID, 0.0);
}
return;
}
if ( m_targetAll )
{
if ( !a2->m_reset )
goto LABEL_48;
v25 = a1;
m_effectManager = a1->m_effectManager;
value = m_effectManager->m_persistentItemCountMap.__table_.__p2_.__value_;
if ( value )
{
if ( value > 0x3FFFFFFFFFFFFFFFLL )
sub_1000C40D0();
v8 = (int *)operator new(4 * value);
v9 = &v8[value];
next = m_effectManager->m_persistentItemCountMap.__table_.__p1_.__value_.__next_;
if ( next )
goto LABEL_14;
}
else
{
v8 = nullptr;
v9 = nullptr;
next = m_effectManager->m_persistentItemCountMap.__table_.__p1_.__value_.__next_;
if ( next )
{
LABEL_14:
v24 = a2;
v11 = v8;
do
{
while ( v11 < v9 )
{
*v11++ = (int)next[2].__next_;
next = next->__next_;
if ( !next )
goto LABEL_29;
}
v12 = (char *)v11 - (char *)v8;
v13 = v12 >> 2;
v14 = (v12 >> 2) + 1;
__src = v8;
if ( v14 > 0x3FFFFFFFFFFFFFFFLL )
sub_1000C40D0();
v15 = (char *)v9 - (char *)v8;
v16 = v15 >> 1;
if ( v15 >> 1 <= v14 )
v16 = (v12 >> 2) + 1;
if ( (unsigned __int64)v15 >= 0x7FFFFFFFFFFFFFFCLL )
v16 = 0x3FFFFFFFFFFFFFFFLL;
if ( v16 )
{
if ( v16 > 0x3FFFFFFFFFFFFFFFLL )
sub_100054850();
v8 = (int *)operator new(4 * v16);
}
else
{
v8 = nullptr;
}
v23 = &v8[v16];
v8[v13] = (int)next[2].__next_;
memcpy(v8, __src, v12);
if ( __src )
operator delete(__src);
v11 = &v8[v13 + 1];
v9 = v23;
next = next->__next_;
}
while ( next );
LABEL_29:
if ( v8 == v11 )
{
v3 = v25;
v2 = v24;
if ( !v8 )
goto LABEL_48;
}
else
{
v17 = v8;
v3 = v25;
do
{
GJEffectManager::updateCountForItem(v25->m_effectManager, *v17, 0);
GJBaseGameLayer::updateCounters(v25, *v17++, 0);
}
while ( v17 != v11 );
v2 = v24;
if ( !v8 )
{
LABEL_48:
if ( !v2->m_persistent )
GJEffectManager::removePersistentFromAllItems(v3->m_effectManager);
return;
}
}
LABEL_47:
operator delete(v8);
goto LABEL_48;
}
}
v3 = v25;
if ( !v8 )
goto LABEL_48;
goto LABEL_47;
}
GJEffectManager::toggleItemPersistent(a1->m_effectManager, a2->m_itemID, a2->m_persistent);
if ( a2->m_reset )
{
GJEffectManager::updateCountForItem(a1->m_effectManager, a2->m_itemID, 0);
GJBaseGameLayer::updateCounters(a1, a2->m_itemID, 0);
}
}