//
// GJSmartTemplate::getTotalChanceForPrefab from 0x9d0d78 to 0x9d0ec4 (332 bytes)
//
// 4 xrefs:
// > GJSmartTemplate::getRandomPrefab @ 0x9d0f5c
// > BrowseSmartKeyLayer::init @ 0x9e091c
// > BrowseSmartKeyLayer::updateChanceValues @ 0x9e1b44
// > ??> @ 0x44628
//
// 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
//
__int64 __fastcall GJSmartTemplate::getTotalChanceForPrefab(__int64 a1)
{
cocos2d::CCArray *Prefabs; // x20
char *v3; // x0
__int64 result; // x0
cocos2d::ccArray *data; // x1
unsigned int num; // w2
cocos2d::CCObject **arr; // x1
cocos2d::CCObject **i; // x3
cocos2d::CCObject *v9; // x2
unsigned int *v10; // x2
int v11; // w1
std::string v12; // [xsp+40h] [xbp+40h] BYREF
sub_D18D28(&v12);
Prefabs = (cocos2d::CCArray *)GJSmartTemplate::getPrefabs(a1, &v12);
v3 = (char *)v12.m_data.m_data - 24;
if ( (__int64 *)v12.m_data.m_data - 3 != &qword_124B6B0 )
{
if ( &pthread_create )
{
v10 = (unsigned int *)((char *)v12.m_data.m_data - 8);
do
v11 = __ldaxr(v10);
while ( __stlxr(v11 - 1, v10) );
}
else
{
v11 = *((_DWORD *)v12.m_data.m_data - 2);
*((_DWORD *)v12.m_data.m_data - 2) = v11 - 1;
}
if ( v11 <= 0 )
operator delete(v3);
}
if ( !Prefabs || !(unsigned int)cocos2d::CCArray::count(Prefabs) )
return 0;
data = Prefabs->data;
result = 0;
num = data->num;
if ( data->num )
{
arr = data->arr;
for ( i = &arr[num - 1]; i >= arr; result = (unsigned int)(result + v9[1].m_uReference) )
{
v9 = *arr;
if ( !*arr )
break;
++arr;
}
}
return result;
}