//
// GJEffectManager::countForItem from 0x1002ea0b0 to 0x1002ea205 (341 bytes)
//
// 12 xrefs:
// > GJBaseGameLayer::testInstantCountTrigger @ 0x10014baa6
// > GJBaseGameLayer::collectedObject @ 0x10014bb4a
// > GJBaseGameLayer::addPickupTrigger @ 0x10014c043
// > GJBaseGameLayer::addPickupTrigger @ 0x10014c07e
// > GJBaseGameLayer::addPickupTrigger @ 0x10014c0f1
// > GJBaseGameLayer::getItemValue @ 0x10014c2a4
// > GJBaseGameLayer::activateItemEditTrigger @ 0x10014c56b
// > GJBaseGameLayer::activateItemEditTrigger @ 0x10014c63a
// > GJBaseGameLayer::activateItemEditTrigger @ 0x10014c812
// > GJBaseGameLayer::activateItemCompareTrigger @ 0x10014cd65
// > GJBaseGameLayer::activateItemCompareTrigger @ 0x10014cfb9
// > GJBaseGameLayer::refreshCounterLabels @ 0x10014dfe4
//
// 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
//
int __fastcall GJEffectManager::countForItem(GJEffectManager *a1, int a2)
{
int result; // eax
unsigned __int64 v3; // rcx
unsigned __int64 value; // rsi
unsigned __int64 v5; // r9
unsigned __int64 v6; // r8
std::__hash_node_base, void *> *> *v7; // rdx
std::__hash_node_base, void *> *>::__next_pointer next; // rdi
unsigned __int64 v9; // rsi
unsigned __int64 v10; // rax
std::__hash_node_base, void *> *>::__next_pointer v11; // rdx
result = 0;
if ( a2 <= 0 )
a2 = 0;
v3 = 9999;
if ( a2 < 9999 )
v3 = (unsigned int)a2;
value = a1->m_itemCountMap.__table_.__bucket_list_.__ptr_.__value_.__data_.__value_;
if ( value )
{
v5 = (0x101010101010101LL
* ((((value - ((value >> 1) & 0x5555555555555555LL)) & 0x3333333333333333LL)
+ (((value - ((value >> 1) & 0x5555555555555555LL)) >> 2) & 0x3333333333333333LL)
+ ((((value - ((value >> 1) & 0x5555555555555555LL)) & 0x3333333333333333LL)
+ (((value - ((value >> 1) & 0x5555555555555555LL)) >> 2) & 0x3333333333333333LL)) >> 4))
& 0xF0F0F0F0F0F0F0FLL)) >> 56;
if ( v5 > 1 )
{
v6 = v3;
if ( value <= v3 )
{
result = 0;
v6 = (unsigned __int16)((unsigned __int16)v3 % (unsigned __int16)value);
}
}
else
{
v6 = ((_DWORD)value + 0x3FFF) & (unsigned int)v3;
}
v7 = a1->m_itemCountMap.__table_.__bucket_list_.__ptr_.__value_[v6];
if ( v7 )
{
next = v7->__next_;
if ( v7->__next_ )
{
if ( (unsigned int)v5 < 2 )
{
v9 = value - 1;
while ( 1 )
{
v11 = next[1].__next_;
if ( v11 == (std::__hash_node_base, void *> *>::__next_pointer)v3 )
{
if ( LODWORD(next[2].__next_) == (_DWORD)v3 )
return HIDWORD(next[2].__next_);
}
else if ( (v9 & (unsigned __int64)v11) != v6 )
{
return result;
}
next = next->__next_;
if ( !next )
return result;
}
}
while ( 1 )
{
v10 = (unsigned __int64)next[1].__next_;
if ( v10 == v3 )
{
if ( LODWORD(next[2].__next_) == (_DWORD)v3 )
return HIDWORD(next[2].__next_);
}
else
{
if ( v10 < value )
goto LABEL_20;
if ( (value | v10) >> 32 )
{
v10 %= value;
LABEL_20:
if ( v10 != v6 )
return 0;
goto LABEL_15;
}
if ( (unsigned int)v10 % (unsigned int)value != v6 )
return 0;
}
LABEL_15:
next = next->__next_;
if ( !next )
return 0;
}
}
}
}
return result;
}