//
// GJSmartTemplate::getPrefab from 0x1402b2ba0 to 0x1402b3484 (2276 bytes)
//
// 7 xrefs:
// > GJSmartTemplate::scanForPrefab @ 0x1402b1faf
// > GJSmartTemplate::scanForPrefab @ 0x1402b21c8
// > GJSmartTemplate::scanForPrefab @ 0x1402b23f0
// > GJSmartTemplate::scanForPrefab @ 0x1402b2615
// > GJSmartTemplate::getPrefab @ 0x1402b3175
// > GJSmartTemplate::getPrefab @ 0x1402b3280
// > ??> @ 0x1406d239c
//
// 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=4
struct cocos2d::CCObject *__fastcall GJSmartTemplate::getPrefab(_QWORD *a1, __int64 a2, char a3, unsigned __int8 a4)
{
cocos2d::CCArray *v7; // rdi
__int64 v8; // rax
struct cocos2d::CCObject *RandomPrefab; // rbx
struct cocos2d::CCObject *result; // rax
int v11; // eax
__int64 v12; // rcx
unsigned __int8 v13; // si
unsigned int v14; // ebx
int v15; // eax
unsigned __int64 v16; // r8
__int64 v17; // rdi
int v18; // r12d
int v19; // r15d
_QWORD *v20; // rax
void **SimplifiedKey; // rbx
void *v22; // rcx
_QWORD *v23; // rax
__int64 VerySimplifiedKey; // rbx
void *v25; // rcx
_QWORD *v26; // rax
void **v27; // rax
__int64 v28; // rbx
void *v29; // rcx
_QWORD *v30; // rax
void **v31; // rax
__int64 v32; // rcx
_QWORD *v33; // rax
const void **v34; // rax
__int64 v35; // rcx
_QWORD *v36; // rax
void **v37; // rax
const void **v38; // rax
__int64 v39; // rcx
__int64 NoCornerKey; // rbx
void *v41; // rcx
void *v42; // rdx
void **v43; // rsi
__int64 v44; // rdi
unsigned __int64 v45; // rbx
__int64 Prefab; // rbx
void *v47; // rcx
cocos2d::CCArray *v48; // rax
cocos2d::CCArray *v49; // rdi
cocos2d::CCString *v50; // rax
const char *CString; // rax
size_t v52; // r8
__int64 v53; // rax
__int64 v54; // r8
__int64 v55; // rsi
void *v56; // rcx
void *v57; // rcx
void *v58; // rcx
void *v59; // rcx
__int64 v61; // [rsp+28h] [rbp-A1h]
__int64 v62; // [rsp+28h] [rbp-A1h]
int v63; // [rsp+38h] [rbp-91h]
int v64; // [rsp+3Ch] [rbp-8Dh]
void *Src[2]; // [rsp+48h] [rbp-81h] BYREF
__int128 v66; // [rsp+58h] [rbp-71h]
void *Block[2]; // [rsp+68h] [rbp-61h] BYREF
__int64 v68; // [rsp+78h] [rbp-51h]
unsigned __int64 v69; // [rsp+80h] [rbp-49h]
void *v70[4]; // [rsp+88h] [rbp-41h] BYREF
_BYTE v71[32]; // [rsp+A8h] [rbp-21h] BYREF
_BYTE v72[32]; // [rsp+C8h] [rbp-1h] BYREF
v61 = sub_14003BDB0((__int64)Block, a2);
v7 = (cocos2d::CCArray *)cocos2d::CCDictionary::objectForKey(a1[7], v61);
sub_14003A830(v61);
if ( v7 && cocos2d::CCArray::count(v7) )
{
v8 = sub_14003BDB0((__int64)Block, a2);
RandomPrefab = GJSmartTemplate::getRandomPrefab((__int64)a1, v8);
sub_14003A830(a2);
return RandomPrefab;
}
if ( a3 )
goto LABEL_95;
v11 = 4;
v12 = 7;
v13 = a4;
if ( a4 )
v11 = 7;
v64 = v11;
v14 = 0;
v15 = 0;
v63 = 0;
LABEL_8:
v16 = 0x140000000uLL;
switch ( v15 )
{
case 1:
v17 = a1[8];
break;
case 2:
v17 = a1[10];
break;
case 3:
v17 = a1[12];
break;
case 4:
v17 = a1[9];
break;
case 5:
v17 = a1[11];
break;
case 6:
v17 = a1[13];
break;
default:
v17 = a1[7];
break;
}
v62 = v17;
v18 = 0;
v19 = -1;
while ( 1 )
{
*(_OWORD *)Src = 0;
*(_QWORD *)&v66 = 0;
*((_QWORD *)&v66 + 1) = 15;
LOBYTE(Src[0]) = 0;
switch ( v19 )
{
case 0:
v20 = (_QWORD *)sub_14003BDB0((__int64)Block, a2);
SimplifiedKey = GJSmartTemplate::getSimplifiedKey(v70, v20);
if ( Src != SimplifiedKey )
{
if ( *((_QWORD *)&v66 + 1) > 0xFu )
{
v22 = Src[0];
if ( (unsigned __int64)(*((_QWORD *)&v66 + 1) + 1LL) >= 0x1000 )
{
v22 = *((void **)Src[0] - 1);
if ( (unsigned __int64)((char *)Src[0] - (char *)v22 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v22);
}
*(_QWORD *)&v66 = 0;
*((_QWORD *)&v66 + 1) = 15;
LOBYTE(Src[0]) = 0;
*(_OWORD *)Src = *(_OWORD *)SimplifiedKey;
v66 = *((_OWORD *)SimplifiedKey + 1);
SimplifiedKey[2] = nullptr;
SimplifiedKey[3] = (void *)15;
*(_BYTE *)SimplifiedKey = 0;
}
sub_14003A830((__int64)v70);
v14 = 0;
goto LABEL_59;
case 1:
v23 = (_QWORD *)sub_14003BDB0((__int64)v70, a2);
VerySimplifiedKey = GJSmartTemplate::getVerySimplifiedKey((__int64)Block, v23);
if ( Src == (void **)VerySimplifiedKey )
goto LABEL_30;
if ( *((_QWORD *)&v66 + 1) <= 0xFu )
goto LABEL_29;
v25 = Src[0];
if ( (unsigned __int64)(*((_QWORD *)&v66 + 1) + 1LL) >= 0x1000 )
{
v25 = *((void **)Src[0] - 1);
if ( (unsigned __int64)((char *)Src[0] - (char *)v25 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
break;
case 2:
v26 = (_QWORD *)sub_14003BDB0((__int64)v70, a2);
v27 = GJSmartTemplate::getSimplifiedKey(Block, v26);
v28 = GJSmartTemplate::getVerySimplifiedKey((__int64)v71, v27);
if ( Src != (void **)v28 )
{
if ( *((_QWORD *)&v66 + 1) > 0xFu )
{
v29 = Src[0];
if ( (unsigned __int64)(*((_QWORD *)&v66 + 1) + 1LL) >= 0x1000 )
{
v29 = *((void **)Src[0] - 1);
if ( (unsigned __int64)((char *)Src[0] - (char *)v29 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v29);
}
*(_QWORD *)&v66 = 0;
*((_QWORD *)&v66 + 1) = 15;
LOBYTE(Src[0]) = 0;
*(_OWORD *)Src = *(_OWORD *)v28;
v66 = *(_OWORD *)(v28 + 16);
*(_QWORD *)(v28 + 16) = 0;
*(_QWORD *)(v28 + 24) = 15;
*(_BYTE *)v28 = 0;
}
sub_14003A830((__int64)v71);
v14 = 0;
goto LABEL_59;
case 3:
v30 = (_QWORD *)sub_14003BDB0((__int64)v71, a2);
v31 = GJSmartTemplate::getSimplifiedKey(v70, v30);
VerySimplifiedKey = GJSmartTemplate::getNoCornerKey(v32, (__int64)Block, (const void **)v31);
if ( Src == (void **)VerySimplifiedKey )
goto LABEL_30;
if ( *((_QWORD *)&v66 + 1) <= 0xFu )
goto LABEL_29;
v25 = Src[0];
if ( (unsigned __int64)(*((_QWORD *)&v66 + 1) + 1LL) >= 0x1000 )
{
v25 = *((void **)Src[0] - 1);
if ( (unsigned __int64)((char *)Src[0] - (char *)v25 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
return result;
case 4:
v33 = (_QWORD *)sub_14003BDB0((__int64)v71, a2);
v34 = (const void **)GJSmartTemplate::getVerySimplifiedKey((__int64)v70, v33);
VerySimplifiedKey = GJSmartTemplate::getNoCornerKey(v35, (__int64)Block, v34);
if ( Src == (void **)VerySimplifiedKey )
goto LABEL_30;
if ( *((_QWORD *)&v66 + 1) <= 0xFu )
goto LABEL_29;
v25 = Src[0];
if ( (unsigned __int64)(*((_QWORD *)&v66 + 1) + 1LL) >= 0x1000 )
{
v25 = *((void **)Src[0] - 1);
if ( (unsigned __int64)((char *)Src[0] - (char *)v25 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
return result;
case 5:
v36 = (_QWORD *)sub_14003BDB0((__int64)v71, a2);
v37 = GJSmartTemplate::getSimplifiedKey(v70, v36);
v38 = (const void **)GJSmartTemplate::getVerySimplifiedKey((__int64)Block, v37);
NoCornerKey = GJSmartTemplate::getNoCornerKey(v39, (__int64)v72, v38);
if ( Src != (void **)NoCornerKey )
{
if ( *((_QWORD *)&v66 + 1) > 0xFu )
{
v41 = Src[0];
if ( (unsigned __int64)(*((_QWORD *)&v66 + 1) + 1LL) >= 0x1000 )
{
v41 = *((void **)Src[0] - 1);
if ( (unsigned __int64)((char *)Src[0] - (char *)v41 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v41);
}
*(_QWORD *)&v66 = 0;
*((_QWORD *)&v66 + 1) = 15;
LOBYTE(Src[0]) = 0;
*(_OWORD *)Src = *(_OWORD *)NoCornerKey;
v66 = *(_OWORD *)(NoCornerKey + 16);
*(_QWORD *)(NoCornerKey + 16) = 0;
*(_QWORD *)(NoCornerKey + 24) = 15;
*(_BYTE *)NoCornerKey = 0;
}
sub_14003A830((__int64)v72);
v14 = 0;
goto LABEL_59;
default:
if ( Src != (void **)a2 )
{
v42 = (void *)a2;
if ( *(_QWORD *)(a2 + 24) > 0xFu )
v42 = *(void **)a2;
sub_14003CCE0(Src, v42, *(_QWORD *)(a2 + 16));
}
goto LABEL_59;
}
j_j_free(v25);
LABEL_29:
*(_QWORD *)&v66 = 0;
*((_QWORD *)&v66 + 1) = 15;
LOBYTE(Src[0]) = 0;
*(_OWORD *)Src = *(_OWORD *)VerySimplifiedKey;
v66 = *(_OWORD *)(VerySimplifiedKey + 16);
*(_QWORD *)(VerySimplifiedKey + 16) = 0;
*(_QWORD *)(VerySimplifiedKey + 24) = 15;
*(_BYTE *)VerySimplifiedKey = 0;
LABEL_30:
sub_14003A830((__int64)Block);
v14 = 0;
LABEL_59:
if ( !v63 )
{
*(_OWORD *)Block = 0;
v68 = 0;
v69 = 0;
v43 = Src;
if ( *((_QWORD *)&v66 + 1) > 0xFu )
v43 = (void **)Src[0];
v44 = v66;
if ( (unsigned __int64)v66 > 0x7FFFFFFFFFFFFFFFLL )
sub_140007B50(v12, 0x7FFFFFFFFFFFFFFFLL, v16, 22);
v69 = 15;
if ( (unsigned __int64)v66 > 0xF )
{
v45 = v66 | 0xF;
if ( ((unsigned __int64)v66 | 0xF) <= 0x7FFFFFFFFFFFFFFFLL )
{
if ( v45 < 0x16 )
v45 = 22;
}
else
{
v45 = 0x7FFFFFFFFFFFFFFFLL;
}
Block[0] = sub_14003AA10(v45 + 1);
v68 = v44;
v69 = v45;
memcpy(Block[0], v43, v44 + 1);
}
else
{
v68 = v66;
*(_OWORD *)Block = *(_OWORD *)v43;
}
v13 = a4;
LOBYTE(v16) = 1;
Prefab = GJSmartTemplate::getPrefab(a1, Block, v16, a4);
if ( Prefab )
{
if ( *((_QWORD *)&v66 + 1) <= 0xFu )
{
LABEL_75:
*(_QWORD *)&v66 = 0;
*((_QWORD *)&v66 + 1) = 15;
LOBYTE(Src[0]) = 0;
sub_14003A830(a2);
return (struct cocos2d::CCObject *)Prefab;
}
v47 = Src[0];
if ( (unsigned __int64)(*((_QWORD *)&v66 + 1) + 1LL) < 0x1000
|| (v47 = *((void **)Src[0] - 1), (unsigned __int64)((char *)Src[0] - (char *)v47 - 8) <= 0x1F) )
{
j_j_free(v47);
goto LABEL_75;
}
LABEL_110:
invalid_parameter_noinfo_noreturn();
}
goto LABEL_88;
}
if ( !v17 || !(_QWORD)v66 )
goto LABEL_89;
v48 = (cocos2d::CCArray *)cocos2d::CCDictionary::objectForKey(v17, Src);
v49 = v48;
if ( v48 )
{
if ( cocos2d::CCArray::count(v48) )
break;
}
LABEL_88:
v17 = v62;
LABEL_89:
if ( *((_QWORD *)&v66 + 1) > 0xFu )
{
v57 = Src[0];
if ( (unsigned __int64)(*((_QWORD *)&v66 + 1) + 1LL) >= 0x1000 )
{
v57 = *((void **)Src[0] - 1);
if ( (unsigned __int64)((char *)Src[0] - (char *)v57 - 8) > 0x1F )
goto LABEL_110;
}
j_j_free(v57);
}
++v18;
++v19;
v12 = (unsigned int)v64;
v14 = 0;
v16 = 0x140000000uLL;
if ( v18 >= v64 )
{
v15 = v63 + 1;
v63 = v15;
if ( v15 >= v64 )
{
LABEL_95:
sub_14003A830(a2);
return nullptr;
}
goto LABEL_8;
}
}
while ( 1 )
{
v50 = cocos2d::CCArray::stringAtIndex(v49, v14);
CString = cocos2d::CCString::getCString(v50);
*(_OWORD *)Block = 0;
v68 = 0;
v69 = 0;
v52 = -1;
do
++v52;
while ( CString[v52] );
sub_14003A930(Block, CString, v52);
v53 = sub_14003BDB0((__int64)v72, (__int64)Block);
LOBYTE(v54) = 1;
v55 = GJSmartTemplate::getPrefab(a1, v53, v54, v13);
if ( v55 )
break;
if ( v69 > 0xF )
{
v56 = Block[0];
if ( v69 + 1 >= 0x1000 )
{
v56 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v56 - 8) > 0x1F )
goto LABEL_103;
}
j_j_free(v56);
}
++v14;
v13 = a4;
if ( v14 >= cocos2d::CCArray::count(v49) )
goto LABEL_88;
}
if ( v69 > 0xF )
{
v58 = Block[0];
if ( v69 + 1 >= 0x1000 )
{
v58 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v58 - 8) > 0x1F )
LABEL_103:
invalid_parameter_noinfo_noreturn();
}
j_j_free(v58);
}
if ( *((_QWORD *)&v66 + 1) > 0xFu )
{
v59 = Src[0];
if ( (unsigned __int64)(*((_QWORD *)&v66 + 1) + 1LL) >= 0x1000 )
{
v59 = *((void **)Src[0] - 1);
if ( (unsigned __int64)((char *)Src[0] - (char *)v59 - 8) > 0x1F )
goto LABEL_110;
}
j_j_free(v59);
}
*(_QWORD *)&v66 = 0;
*((_QWORD *)&v66 + 1) = 15;
LOBYTE(Src[0]) = 0;
sub_14003A830(a2);
return (struct cocos2d::CCObject *)v55;
}