//
// GJSmartTemplate::getRandomPrefab from 0x1403b8e90 to 0x1403b8ffb (363 bytes)
//
// 5 xrefs:
// > GJSmartTemplate::scanForPrefab @ 0x1403b8051
// > GJSmartTemplate::getPrefab @ 0x1403b908f
// > BrowseSmartTemplateLayer::addPrefabMenuItem @ 0x1405f007a
// > ??> @ 0x140923d44
// > ??> @ 0x140923d50
//
// 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 11:31:25 +0000
//
// 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_14003F4F0((__int64)&v14, a2);
v4 = (cocos2d::CCArray *)cocos2d::CCDictionary::objectForKey(*(_QWORD *)(a1 + 56), v13);
sub_14003D310(v13);
if ( !v4 || !cocos2d::CCArray::count(v4) )
goto LABEL_8;
if ( cocos2d::CCArray::count(v4) <= 1 )
{
v12 = cocos2d::CCArray::objectAtIndex(v4, 0);
sub_14003D310(a2);
return v12;
}
v5 = sub_14003F4F0((__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_14003D310(a2);
return nullptr;
}
while ( 1 )
{
v10 = cocos2d::CCArray::objectAtIndex(v4, v9);
v7 += *((_DWORD *)v10 + 31);
if ( (float)v7 >= v8 || v9 == cocos2d::CCArray::count(v4) - 1 )
break;
if ( ++v9 >= cocos2d::CCArray::count(v4) )
goto LABEL_8;
}
sub_14003D310(a2);
return v10;
}