//
// GJSmartTemplate::scanForPrefab from 0x100423a90 to 0x100424479 (2537 bytes)
//
// 2 xrefs:
// > EditorUI::createSmartObjectsFromTemplate @ 0x100042f0b
// > GJSmartTemplate::getTemplateState @ 0x100427ca0
//
// 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::scanForPrefab(__int64 a1, _BYTE *a2, std::string::size_type a3, __m128 a4)
{
const std::string *v4; // r15
_BYTE *v6; // rbx
__int64 v7; // rax
unsigned int v8; // ecx
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rax
std::string *v12; // r14
std::string::pointer data; // rsi
unsigned __int8 v14; // dl
bool v15; // zf
unsigned __int8 v16; // cl
__int64 RandomPrefab; // r14
__int64 v18; // r14
__int64 v19; // rcx
_QWORD *v20; // rdi
__int64 v21; // rdx
__int64 result; // rax
char v23; // al
std::string *v24; // r13
int v25; // eax
char v26; // bl
std::string::size_type v27; // rax
unsigned int v28; // r14d
unsigned int v29; // ebx
__int64 v30; // rdx
__int64 Prefab_1; // rax
__int64 v32; // rax
__int64 v33; // rax
__int64 v34; // rax
__int64 v36; // rbx
char v37; // al
__int64 v38; // r14
__int64 v39; // rax
_BYTE v40[16]; // [rsp+8h] [rbp-228h] BYREF
void *v41; // [rsp+18h] [rbp-218h]
const std::string *v42; // [rsp+20h] [rbp-210h]
_BYTE *v43; // [rsp+28h] [rbp-208h]
std::string *v44; // [rsp+30h] [rbp-200h]
__int64 *v45; // [rsp+38h] [rbp-1F8h]
__m128 v46; // [rsp+40h] [rbp-1F0h] BYREF
void *__p; // [rsp+50h] [rbp-1E0h]
__int128 v48; // [rsp+60h] [rbp-1D0h] BYREF
void *v49; // [rsp+70h] [rbp-1C0h]
__int128 v50; // [rsp+80h] [rbp-1B0h] BYREF
void *v51; // [rsp+90h] [rbp-1A0h]
__int128 v52; // [rsp+A0h] [rbp-190h] BYREF
void *v53; // [rsp+B0h] [rbp-180h]
__int128 v54; // [rsp+C0h] [rbp-170h] BYREF
void *v55; // [rsp+D0h] [rbp-160h]
__int128 v56; // [rsp+E0h] [rbp-150h] BYREF
void *v57; // [rsp+F0h] [rbp-140h]
__int128 v58; // [rsp+100h] [rbp-130h] BYREF
void *v59; // [rsp+110h] [rbp-120h]
__int128 v60; // [rsp+120h] [rbp-110h] BYREF
void *v61; // [rsp+130h] [rbp-100h]
__int128 v62; // [rsp+140h] [rbp-F0h] BYREF
void *v63; // [rsp+150h] [rbp-E0h]
__int128 v64; // [rsp+160h] [rbp-D0h] BYREF
void *v65; // [rsp+170h] [rbp-C0h]
unsigned int *v66; // [rsp+180h] [rbp-B0h]
int v67; // [rsp+18Ch] [rbp-A4h]
__int128 v68; // [rsp+190h] [rbp-A0h] BYREF
std::string::size_type v69; // [rsp+1A0h] [rbp-90h]
int v70; // [rsp+1ACh] [rbp-84h]
_BYTE *v71; // [rsp+1B0h] [rbp-80h]
unsigned int v72; // [rsp+1B8h] [rbp-78h]
unsigned int v73; // [rsp+1BCh] [rbp-74h]
std::string v74; // [rsp+1C0h] [rbp-70h] BYREF
std::string __str; // [rsp+1D8h] [rbp-58h] BYREF
char v76; // [rsp+1F7h] [rbp-39h]
__int64 v77; // [rsp+1F8h] [rbp-38h]
unsigned __int8 v78; // [rsp+207h] [rbp-29h]
v4 = (const std::string *)a3;
v77 = a1;
v6 = a2 + 112;
v74.__r_.__value_.__r.__words[0] = a3;
v7 = sub_100429990(a2 + 112, a3, &unk_10081B952, &v74, &__str);
v8 = *(unsigned __int8 *)(v7 + 64);
if ( (v8 & 1) != 0 )
{
if ( *(_QWORD *)(v7 + 72) )
{
LABEL_3:
v74.__r_.__value_.__r.__words[0] = (std::string::size_type)v4;
if ( *(_QWORD *)(sub_100429990(v6, v4, &unk_10081B952, &v74, &__str) + 56) )
{
v74.__r_.__value_.__r.__words[0] = (std::string::size_type)v4;
v9 = sub_100429990(v6, v4, &unk_10081B952, &v74, &__str);
if ( (*(_BYTE *)(v9 + 88) & 1) != 0 )
{
sub_100006B70(&v46, *(const void **)(v9 + 104), *(_QWORD *)(v9 + 96), *(double *)a4.i64);
}
else
{
v10 = v9 + 88;
__p = *(void **)(v10 + 16);
a4 = *(__m128 *)v10;
v46 = *(__m128 *)v10;
}
RandomPrefab = GJSmartTemplate::getRandomPrefab(a2, &v46);
v74.__r_.__value_.__r.__words[0] = (std::string::size_type)v4;
*(_QWORD *)(sub_100429990(v6, v4, &unk_10081B952, &v74, &__str) + 56) = RandomPrefab;
if ( (v46.i8[0] & 1) != 0 )
operator delete(__p);
}
v74.__r_.__value_.__r.__words[0] = (std::string::size_type)v4;
v18 = sub_100429990(v6, v4, &unk_10081B952, &v74, &__str);
v19 = v77;
*(_QWORD *)v77 = *(_QWORD *)(v18 + 56);
if ( (*(_BYTE *)(v18 + 64) & 1) != 0 )
{
sub_100006B70((_QWORD *)(v19 + 8), *(const void **)(v18 + 80), *(_QWORD *)(v18 + 72), *(double *)a4.i64);
v20 = (_QWORD *)(v77 + 32);
if ( (*(_BYTE *)(v18 + 88) & 1) != 0 )
goto LABEL_16;
}
else
{
*(_QWORD *)(v19 + 24) = *(_QWORD *)(v18 + 80);
a4 = *(__m128 *)(v18 + 64);
*(__m128 *)(v19 + 8) = a4;
v20 = (_QWORD *)(v77 + 32);
if ( (*(_BYTE *)(v18 + 88) & 1) != 0 )
{
LABEL_16:
sub_100006B70(v20, *(const void **)(v18 + 104), *(_QWORD *)(v18 + 96), *(double *)a4.i64);
LABEL_19:
v21 = *(_QWORD *)(v18 + 112);
result = v77;
*(_QWORD *)(v77 + 63) = *(_QWORD *)(v18 + 119);
*(_QWORD *)(result + 56) = v21;
return result;
}
}
v20[2] = *(_QWORD *)(v18 + 104);
*(_OWORD *)v20 = *(_OWORD *)(v18 + 88);
goto LABEL_19;
}
}
else if ( v8 >> 1 )
{
goto LABEL_3;
}
v11 = v77;
*(_QWORD *)v77 = 0;
v12 = (std::string *)(v11 + 8);
*(_WORD *)(v11 + 8) = 0;
*(_WORD *)(v11 + 32) = 0;
*(_DWORD *)(v11 + 56) = 0;
*(_BYTE *)(v11 + 60) = 0;
*(_DWORD *)(v11 + 64) = 0;
*(_DWORD *)(v11 + 67) = 0;
data = (std::string::pointer)v4;
std::string::operator=((std::string *)(v11 + 8), v4);
v14 = a2[137];
v15 = a2[138] == 1;
v43 = v6;
v44 = v12;
v71 = a2;
if ( v15 )
{
v16 = 0;
if ( (v14 & a2[136]) == 0 )
v16 = v14;
v76 = 1;
v78 = v16;
}
else
{
v23 = a2[136];
v78 = v14;
v76 = v14 | v23;
}
v24 = (std::string *)(v77 + 32);
v45 = (__int64 *)(v77 + 56);
v25 = v77 + 64;
v66 = (unsigned int *)(v77 + 64);
LOBYTE(v25) = 1;
v70 = v25;
v26 = 0;
v42 = v4;
do
{
if ( (*(_BYTE *)&v4->__r_.__value_.__s.0 & 1) != 0 )
{
data = v4->__r_.__value_.__l.__data_;
v27 = (std::string::size_type)sub_100006B70(&v74, data, v4->__r_.__value_.__l.__size_, *(double *)a4.i64);
}
else
{
v27 = v4->__r_.__value_.__r.__words[2];
v74.__r_.__value_.__r.__words[2] = v27;
a4 = *(__m128 *)&v4->__r_.__value_.__l.0;
*(_OWORD *)&v74.__r_.__value_.__l.0 = *(_OWORD *)&v4->__r_.__value_.__l.0;
}
if ( (v26 & 1) != 0 )
{
*(_BYTE *)(v77 + 70) = 1;
if ( (*(_BYTE *)&v74.__r_.__value_.__s.0 & 1) != 0 )
{
data = v74.__r_.__value_.__l.__data_;
sub_100006B70(&v48, v74.__r_.__value_.__l.__data_, v74.__r_.__value_.__l.__size_, *(double *)a4.i64);
}
else
{
v49 = v74.__r_.__value_.__l.__data_;
a4.i64[0] = v74.__r_.__value_.__r.__words[0];
v48 = *(_OWORD *)&v74.__r_.__value_.__l.0;
}
GJSmartTemplate::getNoCornerKey(&__str, (__int64)data, (unsigned __int8 *)&v48);
if ( (v48 & 1) != 0 )
operator delete(v49);
LODWORD(v27) = __str.__r_.__value_.__l.0;
LOBYTE(v27) = *(_BYTE *)&__str.__r_.__value_.__s.0 & 1;
if ( (*(_BYTE *)&__str.__r_.__value_.__s.0 & 1) != 0 )
{
if ( !__str.__r_.__value_.__l.__size_ )
{
LABEL_36:
if ( (_BYTE)v27 )
operator delete(__str.__r_.__value_.__l.__data_);
goto LABEL_38;
}
}
else if ( !(*(_BYTE *)&__str.__r_.__value_.__l.0 >> 1) )
{
goto LABEL_36;
}
std::string::operator=(&v74, &__str);
LODWORD(v27) = __str.__r_.__value_.__l.0;
LOBYTE(v27) = *(_BYTE *)&__str.__r_.__value_.__s.0 & 1;
goto LABEL_36;
}
LABEL_38:
LOBYTE(v27) = 1;
v73 = v26 & 1;
do
{
LOBYTE(v27) = v76 & v27;
v28 = 0;
v67 = v27;
v72 = v27 & 1;
v29 = 0;
while ( 1 )
{
*v66 = v28;
if ( (*(_BYTE *)&v74.__r_.__value_.__s.0 & 1) != 0 )
{
sub_100006B70(&v50, v74.__r_.__value_.__l.__data_, v74.__r_.__value_.__l.__size_, *(double *)a4.i64);
v30 = *v66;
}
else
{
v51 = v74.__r_.__value_.__l.__data_;
a4.i64[0] = v74.__r_.__value_.__r.__words[0];
v50 = *(_OWORD *)&v74.__r_.__value_.__l.0;
v30 = v28;
}
GJSmartTemplate::rotateKey(&__str, &v50, v30);
if ( (v50 & 1) != 0 )
operator delete(v51);
std::string::operator=(v24, &__str);
if ( (*(_BYTE *)&v24->__r_.__value_.__s.0 & 1) != 0 )
{
sub_100006B70(&v52, *(const void **)(v77 + 48), *(_QWORD *)(v77 + 40), *(double *)a4.i64);
}
else
{
v53 = v24->__r_.__value_.__l.__data_;
a4 = *(__m128 *)&v24->__r_.__value_.__l.0;
v52 = *(_OWORD *)&v24->__r_.__value_.__l.0;
}
data = (std::string::pointer)&v52;
Prefab_1 = GJSmartTemplate::getPrefab_1(v71, &v52, v72, v73);
*(_QWORD *)v77 = Prefab_1;
if ( (v52 & 1) != 0 )
{
operator delete(v53);
Prefab_1 = *(_QWORD *)v77;
}
if ( Prefab_1 )
goto LABEL_103;
if ( v71[136] == 1 )
{
if ( (*(_BYTE *)&__str.__r_.__value_.__s.0 & 1) != 0 )
{
sub_100006B70(&v54, __str.__r_.__value_.__l.__data_, __str.__r_.__value_.__l.__size_, *(double *)a4.i64);
}
else
{
v55 = __str.__r_.__value_.__l.__data_;
v54 = *(_OWORD *)&__str.__r_.__value_.__l.0;
}
GJSmartTemplate::flipKey(&v68, &v54, 1, 0);
if ( (*(_BYTE *)&v24->__r_.__value_.__s.0 & 1) != 0 )
operator delete(*(void **)(v77 + 48));
v24->__r_.__value_.__r.__words[2] = v69;
a4.i64[0] = v68;
*(_OWORD *)&v24->__r_.__value_.__l.0 = v68;
LOWORD(v68) = 0;
if ( (v54 & 1) != 0 )
operator delete(v55);
if ( (*(_BYTE *)&v24->__r_.__value_.__s.0 & 1) != 0 )
{
sub_100006B70(&v56, *(const void **)(v77 + 48), *(_QWORD *)(v77 + 40), *(double *)a4.i64);
}
else
{
v57 = v24->__r_.__value_.__l.__data_;
a4 = *(__m128 *)&v24->__r_.__value_.__l.0;
v56 = *(_OWORD *)&v24->__r_.__value_.__l.0;
}
data = (std::string::pointer)&v56;
v32 = GJSmartTemplate::getPrefab_1(v71, &v56, v72, v73);
*(_QWORD *)v77 = v32;
if ( (v56 & 1) != 0 )
{
operator delete(v57);
v32 = *(_QWORD *)v77;
}
if ( v32 )
{
*(_BYTE *)(v77 + 68) = 1;
if ( (*(_BYTE *)&__str.__r_.__value_.__s.0 & 1) == 0 )
goto LABEL_105;
goto LABEL_104;
}
}
if ( (v78 & 1) != 0 )
{
if ( (*(_BYTE *)&__str.__r_.__value_.__s.0 & 1) != 0 )
{
sub_100006B70(&v58, __str.__r_.__value_.__l.__data_, __str.__r_.__value_.__l.__size_, *(double *)a4.i64);
}
else
{
v59 = __str.__r_.__value_.__l.__data_;
v58 = *(_OWORD *)&__str.__r_.__value_.__l.0;
}
GJSmartTemplate::flipKey(&v68, &v58, 0, 1);
if ( (*(_BYTE *)&v24->__r_.__value_.__s.0 & 1) != 0 )
operator delete(*(void **)(v77 + 48));
v24->__r_.__value_.__r.__words[2] = v69;
a4.i64[0] = v68;
*(_OWORD *)&v24->__r_.__value_.__l.0 = v68;
LOWORD(v68) = 0;
if ( (v58 & 1) != 0 )
operator delete(v59);
if ( (*(_BYTE *)&v24->__r_.__value_.__s.0 & 1) != 0 )
{
sub_100006B70(&v60, *(const void **)(v77 + 48), *(_QWORD *)(v77 + 40), *(double *)a4.i64);
}
else
{
v61 = v24->__r_.__value_.__l.__data_;
a4 = *(__m128 *)&v24->__r_.__value_.__l.0;
v60 = *(_OWORD *)&v24->__r_.__value_.__l.0;
}
data = (std::string::pointer)&v60;
v33 = GJSmartTemplate::getPrefab_1(v71, &v60, v72, v73);
*(_QWORD *)v77 = v33;
if ( (v60 & 1) != 0 )
{
operator delete(v61);
v33 = *(_QWORD *)v77;
}
if ( v33 )
{
*(_BYTE *)(v77 + 69) = 1;
LABEL_103:
if ( (*(_BYTE *)&__str.__r_.__value_.__s.0 & 1) == 0 )
goto LABEL_105;
LABEL_104:
operator delete(__str.__r_.__value_.__l.__data_);
goto LABEL_105;
}
if ( (v78 & v71[136]) == 1 )
break;
}
LABEL_95:
if ( (*(_BYTE *)&__str.__r_.__value_.__s.0 & 1) != 0 )
operator delete(__str.__r_.__value_.__l.__data_);
if ( v71[138] == 1 )
{
v28 += 90;
if ( v29++ < 3 )
continue;
}
goto LABEL_105;
}
if ( (*(_BYTE *)&__str.__r_.__value_.__s.0 & 1) != 0 )
{
sub_100006B70(&v62, __str.__r_.__value_.__l.__data_, __str.__r_.__value_.__l.__size_, *(double *)a4.i64);
}
else
{
v63 = __str.__r_.__value_.__l.__data_;
v62 = *(_OWORD *)&__str.__r_.__value_.__l.0;
}
GJSmartTemplate::flipKey(v40, &v62, 1, 0);
GJSmartTemplate::flipKey(&v68, v40, 0, 1);
if ( (*(_BYTE *)&v24->__r_.__value_.__s.0 & 1) != 0 )
operator delete(*(void **)(v77 + 48));
v24->__r_.__value_.__r.__words[2] = v69;
a4.i64[0] = v68;
*(_OWORD *)&v24->__r_.__value_.__l.0 = v68;
LOWORD(v68) = 0;
if ( (v40[0] & 1) != 0 )
{
operator delete(v41);
if ( (v62 & 1) == 0 )
{
LABEL_87:
if ( (*(_BYTE *)&v24->__r_.__value_.__s.0 & 1) == 0 )
goto LABEL_88;
goto LABEL_91;
}
}
else if ( (v62 & 1) == 0 )
{
goto LABEL_87;
}
operator delete(v63);
if ( (*(_BYTE *)&v24->__r_.__value_.__s.0 & 1) == 0 )
{
LABEL_88:
v65 = v24->__r_.__value_.__l.__data_;
a4 = *(__m128 *)&v24->__r_.__value_.__l.0;
v64 = *(_OWORD *)&v24->__r_.__value_.__l.0;
goto LABEL_92;
}
LABEL_91:
sub_100006B70(&v64, *(const void **)(v77 + 48), *(_QWORD *)(v77 + 40), *(double *)a4.i64);
LABEL_92:
data = (std::string::pointer)&v64;
v34 = GJSmartTemplate::getPrefab_1(v71, &v64, v72, v73);
*(_QWORD *)v77 = v34;
if ( (v64 & 1) != 0 )
{
operator delete(v65);
v34 = *(_QWORD *)v77;
}
if ( !v34 )
goto LABEL_95;
*(_WORD *)(v77 + 68) = 257;
if ( (*(_BYTE *)&__str.__r_.__value_.__s.0 & 1) != 0 )
goto LABEL_104;
LABEL_105:
v36 = *(_QWORD *)v77;
if ( *(_QWORD *)v77 )
break;
LODWORD(v27) = 0;
}
while ( (v67 & 1) != 0 );
if ( (*(_BYTE *)&v74.__r_.__value_.__s.0 & 1) != 0 )
operator delete(v74.__r_.__value_.__l.__data_);
v4 = v42;
if ( v36 )
break;
v37 = v71[139] & v70;
v26 = 1;
v70 = 0;
}
while ( v37 == 1 );
if ( *(_QWORD *)v77 )
std::string::operator=(v24, (const std::string *)(*(_QWORD *)v77 + 56LL));
v74.__r_.__value_.__r.__words[0] = (std::string::size_type)v4;
v38 = sub_100429990(v43, v4, &unk_10081B952, &v74, &__str);
*(_QWORD *)(v38 + 56) = *(_QWORD *)v77;
std::string::operator=((std::string *)(v38 + 64), v44);
std::string::operator=((std::string *)(v38 + 88), v24);
v39 = *v45;
*(_QWORD *)(v38 + 119) = *(__int64 *)((char *)v45 + 7);
*(_QWORD *)(v38 + 112) = v39;
return v77;
}