//
// GJEffectManager::countForItem from 0x1002d4b60 to 0x1002d4cb5 (341 bytes)
//
// 14 xrefs:
// > GJBaseGameLayer::activateProgressTrigger @ 0x100107a3b
// > GJBaseGameLayer::activateProgressTrigger @ 0x100107aa8
// > GJBaseGameLayer::testInstantCountTrigger @ 0x100129dc6
// > GJBaseGameLayer::collectedObject @ 0x100129e6a
// > GJBaseGameLayer::addPickupTrigger @ 0x100129eb3
// > GJBaseGameLayer::addPickupTrigger @ 0x100129eee
// > GJBaseGameLayer::addPickupTrigger @ 0x100129f61
// > GJBaseGameLayer::getItemValue @ 0x10012a114
// > GJBaseGameLayer::activateItemEditTrigger @ 0x10012a3db
// > GJBaseGameLayer::activateItemEditTrigger @ 0x10012a4aa
// > GJBaseGameLayer::activateItemEditTrigger @ 0x10012a682
// > GJBaseGameLayer::activateItemCompareTrigger @ 0x10012abd5
// > GJBaseGameLayer::activateItemCompareTrigger @ 0x10012ae29
// > GJBaseGameLayer::refreshCounterLabels @ 0x10012be54
//
// This function is hookable on this platform (idp: pc, 32 bit: False, 64 bit: True!
//
// Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings
// Generated at Fri, 27 Nov 2026 12:28:14 +0000
//
__int64 __fastcall GJEffectManager::countForItem(__int64 a1, int a2)
{
__int64 result; // rax
unsigned __int64 v3; // rcx
unsigned __int64 v4; // rsi
unsigned __int64 v5; // r9
unsigned __int64 v6; // r8
__int64 **v7; // rdx
__int64 *v8; // rdi
unsigned __int64 v9; // rsi
unsigned __int64 v10; // rax
__int64 v11; // rdx
result = 0;
if ( a2 <= 0 )
a2 = 0;
v3 = 9999;
if ( a2 < 9999 )
v3 = (unsigned int)a2;
v4 = *(_QWORD *)(a1 + 720);
if ( v4 )
{
v5 = (0x101010101010101LL
* ((((v4 - ((v4 >> 1) & 0x5555555555555555LL)) & 0x3333333333333333LL)
+ (((v4 - ((v4 >> 1) & 0x5555555555555555LL)) >> 2) & 0x3333333333333333LL)
+ ((((v4 - ((v4 >> 1) & 0x5555555555555555LL)) & 0x3333333333333333LL)
+ (((v4 - ((v4 >> 1) & 0x5555555555555555LL)) >> 2) & 0x3333333333333333LL)) >> 4))
& 0xF0F0F0F0F0F0F0FLL)) >> 56;
if ( v5 > 1 )
{
v6 = v3;
if ( v4 <= v3 )
{
result = 0;
v6 = (unsigned __int16)((unsigned __int16)v3 % (unsigned __int16)v4);
}
}
else
{
v6 = ((_DWORD)v4 + 0x3FFF) & (unsigned int)v3;
}
v7 = *(__int64 ***)(*(_QWORD *)(a1 + 712) + 8 * v6);
if ( v7 )
{
v8 = *v7;
if ( *v7 )
{
if ( (unsigned int)v5 < 2 )
{
v9 = v4 - 1;
while ( 1 )
{
v11 = v8[1];
if ( v11 == v3 )
{
if ( *((_DWORD *)v8 + 4) == (_DWORD)v3 )
return *((unsigned int *)v8 + 5);
}
else if ( (v9 & v11) != v6 )
{
return result;
}
v8 = (__int64 *)*v8;
if ( !v8 )
return result;
}
}
while ( 1 )
{
v10 = v8[1];
if ( v10 == v3 )
{
if ( *((_DWORD *)v8 + 4) == (_DWORD)v3 )
return *((unsigned int *)v8 + 5);
}
else
{
if ( v10 < v4 )
goto LABEL_20;
if ( (v4 | v10) >> 32 )
{
v10 %= v4;
LABEL_20:
if ( v10 != v6 )
return 0;
goto LABEL_15;
}
if ( (unsigned int)v10 % (unsigned int)v4 != v6 )
return 0;
}
LABEL_15:
v8 = (__int64 *)*v8;
if ( !v8 )
return 0;
}
}
}
}
return result;
}