//
// GJSmartTemplate::getPrefab from 0x1403b9000 to 0x1403b996c (2412 bytes)
//
// 7 xrefs:
// > GJSmartTemplate::scanForPrefab @ 0x1403b83f3
// > GJSmartTemplate::scanForPrefab @ 0x1403b8608
// > GJSmartTemplate::scanForPrefab @ 0x1403b882b
// > GJSmartTemplate::scanForPrefab @ 0x1403b8a52
// > GJSmartTemplate::getPrefab @ 0x1403b95f5
// > GJSmartTemplate::getPrefab @ 0x1403b9703
// > ??> @ 0x140923d5c
//
// 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:26 +0000
//
// Hidden C++ exception states: #wind=4
struct cocos2d::CCObject *__fastcall GJSmartTemplate::getPrefab(_QWORD *a1, __int64 a2, char a3, unsigned __int8 a4)
{
cocos2d::CCArray *v8; // rdi
__int64 v9; // rax
struct cocos2d::CCObject *RandomPrefab; // rbx
struct cocos2d::CCObject *result; // rax
int v12; // eax
__int64 v13; // rcx
unsigned int v14; // ebx
int v15; // esi
unsigned __int64 v16; // r8
__int64 v17; // rdi
int v18; // r12d
int v19; // r15d
unsigned __int64 *v20; // rax
__int64 v21; // r8
__int64 v22; // r9
void **SimplifiedKey; // rbx
void *v24; // rcx
_QWORD *v25; // rax
__int64 VerySimplifiedKey; // rbx
void *v27; // rcx
unsigned __int64 *v28; // rax
__int64 v29; // r8
__int64 v30; // r9
void **v31; // rax
__int64 v32; // rbx
void *v33; // rcx
unsigned __int64 *v34; // rax
__int64 v35; // r8
__int64 v36; // r9
void **v37; // rax
__int64 v38; // rcx
_QWORD *v39; // rax
const void **v40; // rax
__int64 v41; // rcx
unsigned __int64 *v42; // rax
__int64 v43; // r8
__int64 v44; // r9
void **v45; // rax
const void **v46; // rax
__int64 v47; // rcx
__int64 NoCornerKey; // rbx
void *v49; // rcx
void *v50; // rdx
void **v51; // rsi
__int64 v52; // rdi
unsigned __int64 v53; // rbx
__int64 Prefab; // rbx
void *v55; // rcx
cocos2d::CCArray *v56; // rax
cocos2d::CCArray *v57; // rdi
cocos2d::CCString *v58; // rax
const char *CString; // rax
size_t v60; // r8
__int64 v61; // rax
__int64 v62; // r8
__int64 v63; // rsi
void *v64; // rcx
void *v65; // rcx
void *v66; // rcx
void *v67; // rcx
__int64 v69; // [rsp+38h] [rbp-A1h]
__int64 v70; // [rsp+38h] [rbp-A1h]
int v71; // [rsp+48h] [rbp-91h]
int v72; // [rsp+4Ch] [rbp-8Dh]
void *Src[2]; // [rsp+58h] [rbp-81h] BYREF
__int128 v74; // [rsp+68h] [rbp-71h]
void *Block[2]; // [rsp+78h] [rbp-61h] BYREF
__int128 v76; // [rsp+88h] [rbp-51h]
void *v77[4]; // [rsp+98h] [rbp-41h] BYREF
_BYTE v78[32]; // [rsp+B8h] [rbp-21h] BYREF
_BYTE v79[32]; // [rsp+D8h] [rbp-1h] BYREF
v69 = sub_14003F4F0((__int64)Block, a2);
v8 = (cocos2d::CCArray *)cocos2d::CCDictionary::objectForKey(a1[7], v69);
sub_14003D310(v69);
if ( v8 && cocos2d::CCArray::count(v8) )
{
v9 = sub_14003F4F0((__int64)Block, a2);
RandomPrefab = GJSmartTemplate::getRandomPrefab((__int64)a1, v9);
sub_14003D310(a2);
return RandomPrefab;
}
if ( a3 )
goto LABEL_98;
v12 = 4;
v13 = 7;
if ( a4 )
v12 = 7;
v72 = v12;
v14 = 0;
v15 = 0;
v71 = 0;
LABEL_8:
v16 = 0x140000000uLL;
if ( (unsigned int)(v15 - 1) > 5 )
{
v17 = a1[7];
}
else
{
v13 = v15 - 1;
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;
}
}
v70 = v17;
v18 = 0;
v19 = -1;
while ( 1 )
{
*(_OWORD *)Src = 0;
*(_QWORD *)&v74 = 0;
*((_QWORD *)&v74 + 1) = 15;
LOBYTE(Src[0]) = 0;
switch ( v19 )
{
case 0:
v20 = (unsigned __int64 *)sub_14003F4F0((__int64)Block, a2);
SimplifiedKey = GJSmartTemplate::getSimplifiedKey(v77, v20, v21, v22);
if ( Src != SimplifiedKey )
{
if ( *((_QWORD *)&v74 + 1) > 0xFu )
{
v24 = Src[0];
if ( (unsigned __int64)(*((_QWORD *)&v74 + 1) + 1LL) >= 0x1000 )
{
v24 = *((void **)Src[0] - 1);
if ( (unsigned __int64)((char *)Src[0] - (char *)v24 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v24);
}
*(_QWORD *)&v74 = 0;
*((_QWORD *)&v74 + 1) = 15;
LOBYTE(Src[0]) = 0;
*(_OWORD *)Src = *(_OWORD *)SimplifiedKey;
v74 = *((_OWORD *)SimplifiedKey + 1);
SimplifiedKey[2] = nullptr;
SimplifiedKey[3] = (void *)15;
*(_BYTE *)SimplifiedKey = 0;
}
sub_14003D310((__int64)v77);
v14 = 0;
goto LABEL_61;
case 1:
v25 = (_QWORD *)sub_14003F4F0((__int64)v77, a2);
VerySimplifiedKey = GJSmartTemplate::getVerySimplifiedKey((__int64)Block, v25);
if ( Src == (void **)VerySimplifiedKey )
goto LABEL_32;
if ( *((_QWORD *)&v74 + 1) <= 0xFu )
goto LABEL_31;
v27 = Src[0];
if ( (unsigned __int64)(*((_QWORD *)&v74 + 1) + 1LL) >= 0x1000 )
{
v27 = *((void **)Src[0] - 1);
if ( (unsigned __int64)((char *)Src[0] - (char *)v27 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
break;
case 2:
v28 = (unsigned __int64 *)sub_14003F4F0((__int64)v77, a2);
v31 = GJSmartTemplate::getSimplifiedKey(Block, v28, v29, v30);
v32 = GJSmartTemplate::getVerySimplifiedKey((__int64)v78, v31);
if ( Src != (void **)v32 )
{
if ( *((_QWORD *)&v74 + 1) > 0xFu )
{
v33 = Src[0];
if ( (unsigned __int64)(*((_QWORD *)&v74 + 1) + 1LL) >= 0x1000 )
{
v33 = *((void **)Src[0] - 1);
if ( (unsigned __int64)((char *)Src[0] - (char *)v33 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v33);
}
*(_QWORD *)&v74 = 0;
*((_QWORD *)&v74 + 1) = 15;
LOBYTE(Src[0]) = 0;
*(_OWORD *)Src = *(_OWORD *)v32;
v74 = *(_OWORD *)(v32 + 16);
*(_QWORD *)(v32 + 16) = 0;
*(_QWORD *)(v32 + 24) = 15;
*(_BYTE *)v32 = 0;
}
sub_14003D310((__int64)v78);
v14 = 0;
goto LABEL_61;
case 3:
v34 = (unsigned __int64 *)sub_14003F4F0((__int64)v78, a2);
v37 = GJSmartTemplate::getSimplifiedKey(v77, v34, v35, v36);
VerySimplifiedKey = GJSmartTemplate::getNoCornerKey(v38, (__int64)Block, (const void **)v37);
if ( Src == (void **)VerySimplifiedKey )
goto LABEL_32;
if ( *((_QWORD *)&v74 + 1) <= 0xFu )
goto LABEL_31;
v27 = Src[0];
if ( (unsigned __int64)(*((_QWORD *)&v74 + 1) + 1LL) >= 0x1000 )
{
v27 = *((void **)Src[0] - 1);
if ( (unsigned __int64)((char *)Src[0] - (char *)v27 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
return result;
case 4:
v39 = (_QWORD *)sub_14003F4F0((__int64)v78, a2);
v40 = (const void **)GJSmartTemplate::getVerySimplifiedKey((__int64)v77, v39);
VerySimplifiedKey = GJSmartTemplate::getNoCornerKey(v41, (__int64)Block, v40);
if ( Src == (void **)VerySimplifiedKey )
goto LABEL_32;
if ( *((_QWORD *)&v74 + 1) <= 0xFu )
goto LABEL_31;
v27 = Src[0];
if ( (unsigned __int64)(*((_QWORD *)&v74 + 1) + 1LL) >= 0x1000 )
{
v27 = *((void **)Src[0] - 1);
if ( (unsigned __int64)((char *)Src[0] - (char *)v27 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
return result;
case 5:
v42 = (unsigned __int64 *)sub_14003F4F0((__int64)v78, a2);
v45 = GJSmartTemplate::getSimplifiedKey(v77, v42, v43, v44);
v46 = (const void **)GJSmartTemplate::getVerySimplifiedKey((__int64)Block, v45);
NoCornerKey = GJSmartTemplate::getNoCornerKey(v47, (__int64)v79, v46);
if ( Src != (void **)NoCornerKey )
{
if ( *((_QWORD *)&v74 + 1) > 0xFu )
{
v49 = Src[0];
if ( (unsigned __int64)(*((_QWORD *)&v74 + 1) + 1LL) >= 0x1000 )
{
v49 = *((void **)Src[0] - 1);
if ( (unsigned __int64)((char *)Src[0] - (char *)v49 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v49);
}
*(_QWORD *)&v74 = 0;
*((_QWORD *)&v74 + 1) = 15;
LOBYTE(Src[0]) = 0;
*(_OWORD *)Src = *(_OWORD *)NoCornerKey;
v74 = *(_OWORD *)(NoCornerKey + 16);
*(_QWORD *)(NoCornerKey + 16) = 0;
*(_QWORD *)(NoCornerKey + 24) = 15;
*(_BYTE *)NoCornerKey = 0;
}
sub_14003D310((__int64)v79);
v14 = 0;
goto LABEL_61;
default:
if ( Src != (void **)a2 )
{
v50 = (void *)a2;
if ( *(_QWORD *)(a2 + 24) > 0xFu )
v50 = *(void **)a2;
sub_1400405A0(Src, v50, *(_QWORD *)(a2 + 16));
}
goto LABEL_61;
}
j_j_free(v27);
LABEL_31:
*(_QWORD *)&v74 = 0;
*((_QWORD *)&v74 + 1) = 15;
LOBYTE(Src[0]) = 0;
*(_OWORD *)Src = *(_OWORD *)VerySimplifiedKey;
v74 = *(_OWORD *)(VerySimplifiedKey + 16);
*(_QWORD *)(VerySimplifiedKey + 16) = 0;
*(_QWORD *)(VerySimplifiedKey + 24) = 15;
*(_BYTE *)VerySimplifiedKey = 0;
LABEL_32:
sub_14003D310((__int64)Block);
v14 = 0;
LABEL_61:
if ( !v15 )
{
*(_OWORD *)Block = 0;
v76 = 0u;
v51 = Src;
if ( *((_QWORD *)&v74 + 1) > 0xFu )
v51 = (void **)Src[0];
v52 = v74;
if ( (unsigned __int64)v74 > 0x7FFFFFFFFFFFFFFFLL )
sub_140009D90(v13);
if ( (unsigned __int64)v74 > 0xF )
{
v53 = v74 | 0xF;
if ( ((unsigned __int64)v74 | 0xF) <= 0x7FFFFFFFFFFFFFFFLL )
{
if ( v53 < 0x16 )
v53 = 22;
}
else
{
v53 = 0x7FFFFFFFFFFFFFFFLL;
}
Block[0] = sub_14003D460(v53 + 1);
*(_QWORD *)&v76 = v52;
*((_QWORD *)&v76 + 1) = v53;
memcpy(Block[0], v51, v52 + 1);
}
else
{
*(_QWORD *)&v76 = v74;
*((_QWORD *)&v76 + 1) = 15;
*(_OWORD *)Block = *(_OWORD *)v51;
}
LOBYTE(v16) = 1;
Prefab = GJSmartTemplate::getPrefab(a1, Block, v16, a4);
if ( Prefab )
{
if ( *((_QWORD *)&v74 + 1) <= 0xFu )
{
LABEL_77:
*(_QWORD *)&v74 = 0;
*((_QWORD *)&v74 + 1) = 15;
LOBYTE(Src[0]) = 0;
sub_14003D310(a2);
return (struct cocos2d::CCObject *)Prefab;
}
v55 = Src[0];
if ( (unsigned __int64)(*((_QWORD *)&v74 + 1) + 1LL) < 0x1000
|| (v55 = *((void **)Src[0] - 1), (unsigned __int64)((char *)Src[0] - (char *)v55 - 8) <= 0x1F) )
{
j_j_free(v55);
goto LABEL_77;
}
LABEL_113:
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
LABEL_90:
v15 = v71;
goto LABEL_91;
}
if ( !v17 || !(_QWORD)v74 )
goto LABEL_92;
v56 = (cocos2d::CCArray *)cocos2d::CCDictionary::objectForKey(v17, Src);
v57 = v56;
if ( v56 )
{
if ( cocos2d::CCArray::count(v56) )
break;
}
LABEL_91:
v17 = v70;
LABEL_92:
if ( *((_QWORD *)&v74 + 1) > 0xFu )
{
v65 = Src[0];
if ( (unsigned __int64)(*((_QWORD *)&v74 + 1) + 1LL) >= 0x1000 )
{
v65 = *((void **)Src[0] - 1);
if ( (unsigned __int64)((char *)Src[0] - (char *)v65 - 8) > 0x1F )
goto LABEL_113;
}
j_j_free(v65);
}
++v18;
++v19;
v13 = (unsigned int)v72;
v14 = 0;
v16 = 0x140000000uLL;
if ( v18 >= v72 )
{
v71 = ++v15;
if ( v15 >= v72 )
{
LABEL_98:
sub_14003D310(a2);
return nullptr;
}
goto LABEL_8;
}
}
while ( 1 )
{
v58 = cocos2d::CCArray::stringAtIndex(v57, v14);
CString = cocos2d::CCString::getCString(v58);
*(_OWORD *)Block = 0;
v76 = 0;
v60 = -1;
do
++v60;
while ( CString[v60] );
sub_14003D230(Block, CString, v60);
v61 = sub_14003F4F0((__int64)v79, (__int64)Block);
LOBYTE(v62) = 1;
v63 = GJSmartTemplate::getPrefab(a1, v61, v62, a4);
if ( v63 )
break;
if ( *((_QWORD *)&v76 + 1) > 0xFu )
{
v64 = Block[0];
if ( (unsigned __int64)(*((_QWORD *)&v76 + 1) + 1LL) >= 0x1000 )
{
v64 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v64 - 8) > 0x1F )
goto LABEL_106;
}
j_j_free(v64);
}
if ( ++v14 >= cocos2d::CCArray::count(v57) )
goto LABEL_90;
}
if ( *((_QWORD *)&v76 + 1) > 0xFu )
{
v66 = Block[0];
if ( (unsigned __int64)(*((_QWORD *)&v76 + 1) + 1LL) >= 0x1000 )
{
v66 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v66 - 8) > 0x1F )
LABEL_106:
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v66);
}
if ( *((_QWORD *)&v74 + 1) > 0xFu )
{
v67 = Src[0];
if ( (unsigned __int64)(*((_QWORD *)&v74 + 1) + 1LL) >= 0x1000 )
{
v67 = *((void **)Src[0] - 1);
if ( (unsigned __int64)((char *)Src[0] - (char *)v67 - 8) > 0x1F )
goto LABEL_113;
}
j_j_free(v67);
}
*(_QWORD *)&v74 = 0;
*((_QWORD *)&v74 + 1) = 15;
LOBYTE(Src[0]) = 0;
sub_14003D310(a2);
return (struct cocos2d::CCObject *)v63;
}