//
// GJSmartTemplate::getRandomPrefab from 0x1402b2a30 to 0x1402b2b9b (363 bytes)
//
// 5 xrefs:
// > GJSmartTemplate::scanForPrefab @ 0x1402b1c0b
// > GJSmartTemplate::getPrefab @ 0x1402b2c2b
// > BrowseSmartTemplateLayer::addPrefabMenuItem @ 0x14045a5ad
// > ??> @ 0x1406d2384
// > ??> @ 0x1406d2390
//
// 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
//
// Hidden C++ exception states: #wind=2
struct cocos2d::CCObject *__fastcall GJSmartTemplate::getRandomPrefab(__int64 a1, __int64 a2)
{
cocos2d::CCArray *v4; // rdi
__int64 v5; // rax
int TotalChanceForPrefab; // ebx
int v7; // esi
float v8; // xmm6_4
unsigned int v9; // ebx
struct cocos2d::CCObject *v10; // rbp
struct cocos2d::CCObject *v12; // rbx
__int64 v13; // [rsp+20h] [rbp-88h]
__int64 v14; // [rsp+28h] [rbp-80h] BYREF
_BYTE v15[32]; // [rsp+48h] [rbp-60h] BYREF
__int64 v16; // [rsp+68h] [rbp-40h]
v16 = a2;
v13 = sub_14003BDB0((__int64)&v14, a2);
v4 = (cocos2d::CCArray *)cocos2d::CCDictionary::objectForKey(*(_QWORD *)(a1 + 56), v13);
sub_14003A830(v13);
if ( !v4 || !cocos2d::CCArray::count(v4) )
goto LABEL_8;
if ( cocos2d::CCArray::count(v4) <= 1 )
{
v12 = cocos2d::CCArray::objectAtIndex(v4, 0);
sub_14003A830(a2);
return v12;
}
v5 = sub_14003BDB0((__int64)v15, a2);
TotalChanceForPrefab = GJSmartTemplate::getTotalChanceForPrefab(a1, v5);
v7 = 0;
v8 = (float)((float)rand() / 32767.0) * (float)TotalChanceForPrefab;
v9 = 0;
if ( !cocos2d::CCArray::count(v4) )
{
LABEL_8:
sub_14003A830(a2);
return nullptr;
}
while ( 1 )
{
v10 = cocos2d::CCArray::objectAtIndex(v4, v9);
v7 += v10[2].m_nLuaID;
if ( (float)v7 >= v8 || v9 == cocos2d::CCArray::count(v4) - 1 )
break;
if ( ++v9 >= cocos2d::CCArray::count(v4) )
goto LABEL_8;
}
sub_14003A830(a2);
return v10;
}