//
// GJSmartTemplate::getRandomPrefab from 0x100424630 to 0x1004247a2 (370 bytes)
//
// 3 xrefs:
// > GJSmartTemplate::scanForPrefab @ 0x100423bfb
// > GJSmartTemplate::getPrefab_1 @ 0x100425918
// > BrowseSmartTemplateLayer::addPrefabMenuItem @ 0x1004e9c07
//
// 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::getRandomPrefab(__int64 a1, __int64 a2, __m128 a3)
{
__int64 v3; // rbx
__int64 v4; // r15
int TotalChanceForPrefab; // r14d
int v6; // r15d
unsigned int v7; // r14d
int v8; // r12d
__m128 v10; // [rsp+0h] [rbp-60h] BYREF
void *__p; // [rsp+10h] [rbp-50h]
__m128 v12; // [rsp+20h] [rbp-40h] BYREF
void *v13; // [rsp+30h] [rbp-30h]
float v14; // [rsp+3Ch] [rbp-24h]
if ( (*(_BYTE *)a2 & 1) != 0 )
{
sub_100006B70(&v10, *(const void **)(a2 + 16), *(_QWORD *)(a2 + 8), *(double *)a3.i64);
}
else
{
__p = *(void **)(a2 + 16);
a3 = *(__m128 *)a2;
v10 = *(__m128 *)a2;
}
v3 = cocos2d::CCDictionary::objectForKey_1(*(_QWORD *)(a1 + 56), (char *)&v10);
if ( (v10.i8[0] & 1) != 0 )
operator delete(__p);
if ( !v3 || !(unsigned int)sub_100720070(v3) )
return 0;
if ( (unsigned int)sub_100720070(v3) < 2 )
return sub_1007200C0(v3, 0);
if ( (*(_BYTE *)a2 & 1) != 0 )
{
sub_100006B70(&v12, *(const void **)(a2 + 16), *(_QWORD *)(a2 + 8), *(double *)a3.i64);
}
else
{
v13 = *(void **)(a2 + 16);
v12 = *(__m128 *)a2;
}
TotalChanceForPrefab = GJSmartTemplate::getTotalChanceForPrefab(a1, &v12);
if ( (v12.i8[0] & 1) != 0 )
operator delete(v13);
v6 = rand();
if ( !(unsigned int)sub_100720070(v3) )
return 0;
v14 = (float)TotalChanceForPrefab * (float)((float)v6 * 4.6566129e-10);
v7 = 0;
v8 = 0;
while ( 1 )
{
v4 = sub_1007200C0(v3, v7);
v8 += *(_DWORD *)(v4 + 108);
if ( (float)v8 >= v14 || v7 == (unsigned int)sub_100720070(v3) - 1 )
break;
if ( ++v7 >= (unsigned int)sub_100720070(v3) )
return 0;
}
return v4;
}