//
// GJSmartTemplate::scanForPrefab from 0x53c35c to 0x53c7a8 (1100 bytes)
//
// 2 xrefs:
// > EditorUI::createSmartObjectsFromTemplate @ 0x3a516a
// > GJSmartTemplate::getTemplateState @ 0x53caf2
//
// 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
//
SmartPrefabResult *__fastcall GJSmartTemplate::scanForPrefab(SmartPrefabResult *a1, int a2, int a3)
{
_DWORD *v3; // r7
int *v7; // r9
const SmartPrefabResult *v8; // r0
int v9; // r3
bool v10; // zf
int v11; // r3
int v12; // r3
int v13; // r3
_BOOL4 v14; // r8
int j; // r3
int v16; // r3
int k; // r3
int v18; // r3
int v19; // r9
int v20; // r4
stl::StringData::Internal *m_data; // r2
GJSmartPrefab *m_smartPrefab; // r3
int i; // [sp+4h] [bp-78h]
int v25; // [sp+8h] [bp-74h]
int v26; // [sp+Ch] [bp-70h]
int v27; // [sp+10h] [bp-6Ch]
int v28; // [sp+18h] [bp-64h]
char v29[4]; // [sp+20h] [bp-5Ch] BYREF
int v30; // [sp+24h] [bp-58h] BYREF
int v31; // [sp+28h] [bp-54h] BYREF
char v32[4]; // [sp+2Ch] [bp-50h] BYREF
int v33; // [sp+30h] [bp-4Ch] BYREF
int v34; // [sp+34h] [bp-48h] BYREF
char v35[4]; // [sp+38h] [bp-44h] BYREF
int v36; // [sp+3Ch] [bp-40h] BYREF
int v37; // [sp+40h] [bp-3Ch] BYREF
char v38[4]; // [sp+44h] [bp-38h] BYREF
int v39; // [sp+48h] [bp-34h] BYREF
int v40; // [sp+4Ch] [bp-30h] BYREF
int v41; // [sp+50h] [bp-2Ch] BYREF
int v42; // [sp+54h] [bp-28h] BYREF
SmartPrefabResult v43; // [sp+58h] [bp-24h] BYREF
v3 = (_DWORD *)(a2 + 80);
if ( *(_DWORD *)(*(_DWORD *)(std::map::operator[]((_DWORD *)(a2 + 80), a3) + 4) - 12) )
{
if ( *(_DWORD *)std::map::operator[](v3, a3) )
{
v7 = (int *)std::map::operator[](v3, a3);
std::map::operator[](v3, a3);
sub_775C20(&v43);
*v7 = GJSmartTemplate::getRandomPrefab((stl::StringData::Internal *)a2);
sub_774008(&v43);
}
v8 = (const SmartPrefabResult *)std::map::operator[](v3, a3);
SmartPrefabResult::SmartPrefabResult(a1, v8);
}
else
{
SmartPrefabResult::SmartPrefabResult(&v43);
sub_775D40(&v43.m_binaryKey, a3);
v25 = *(unsigned __int8 *)(a2 + 105);
v9 = *(unsigned __int8 *)(a2 + 104);
if ( *(_BYTE *)(a2 + 106) )
{
v10 = v9 == 0;
v11 = *(unsigned __int8 *)(a2 + 105);
if ( !v10 )
v11 = 0;
v25 = v11;
v12 = 1;
}
else
{
v10 = v9 == 0;
v12 = *(unsigned __int8 *)(a2 + 105);
if ( !v10 )
v12 = 1;
}
v28 = v12;
for ( i = 0; ; ++i )
{
v13 = *(_BYTE *)(a2 + 107) ? 2 : 1;
if ( i >= v13 )
break;
sub_775C20(v29);
if ( i == 1 )
{
v43.m_ignoreCorners = 1;
sub_775C20(&v30);
GJSmartTemplate::getNoCornerKey(&v42, a2, &v30);
sub_774008(&v30);
if ( *(_DWORD *)(v42 - 12) )
sub_775D40(v29, &v42);
v14 = 1;
sub_774008(&v42);
}
else
{
v14 = 0;
}
for ( j = 0; ; j = v26 + 1 )
{
v26 = j;
v16 = v28 ? 2 : 1;
if ( v26 >= v16 )
break;
for ( k = 0; ; k = v27 + 1 )
{
v27 = k;
v18 = *(_BYTE *)(a2 + 106) ? 4 : 1;
if ( v27 >= v18 )
break;
if ( v26 )
v19 = 0;
else
v19 = v28;
v43.m_rotation = 90 * v27;
sub_775C20(&v31);
GJSmartTemplate::rotateKey(&v30, &v31, v43.m_rotation);
sub_774008(&v31);
sub_775D40(&v43.m_prefabKey, &v30);
sub_775C20(v32);
v43.m_smartPrefab = (GJSmartPrefab *)GJSmartTemplate::getPrefab(
(stl::StringData::Internal *)a2,
(int)v32,
v19,
v14);
sub_774008(v32);
if ( v43.m_smartPrefab )
goto LABEL_44;
if ( *(_BYTE *)(a2 + 104) )
{
sub_775C20(&v33);
GJSmartTemplate::flipKey(&v34, &v33, 1, 0);
sub_774794(&v43.m_prefabKey, &v34);
sub_774008(&v34);
sub_774008(&v33);
sub_775C20(v35);
v43.m_smartPrefab = (GJSmartPrefab *)GJSmartTemplate::getPrefab(
(stl::StringData::Internal *)a2,
(int)v35,
v19,
v14);
sub_774008(v35);
if ( v43.m_smartPrefab )
{
v43.m_flipX = 1;
goto LABEL_44;
}
}
if ( v25 )
{
sub_775C20(&v36);
GJSmartTemplate::flipKey(&v37, &v36, 0, 1);
sub_774794(&v43.m_prefabKey, &v37);
sub_774008(&v37);
sub_774008(&v36);
sub_775C20(v38);
v43.m_smartPrefab = (GJSmartPrefab *)GJSmartTemplate::getPrefab(
(stl::StringData::Internal *)a2,
(int)v38,
v19,
v14);
sub_774008(v38);
if ( v43.m_smartPrefab )
goto LABEL_42;
}
if ( *(_BYTE *)(a2 + 104) )
{
if ( v25 )
{
sub_775C20(&v39);
GJSmartTemplate::flipKey(&v40, &v39, 1, 0);
GJSmartTemplate::flipKey(&v41, &v40, 0, 1);
sub_774794(&v43.m_prefabKey, &v41);
sub_774008(&v41);
sub_774008(&v40);
sub_774008(&v39);
sub_775C20(&v42);
v43.m_smartPrefab = (GJSmartPrefab *)GJSmartTemplate::getPrefab(
(stl::StringData::Internal *)a2,
(int)&v42,
v19,
v14);
sub_774008(&v42);
if ( v43.m_smartPrefab )
{
v43.m_flipX = 1;
LABEL_42:
v43.m_flipY = 1;
LABEL_44:
sub_774008(&v30);
break;
}
}
}
sub_774008(&v30);
}
if ( v43.m_smartPrefab )
break;
}
if ( v43.m_smartPrefab )
{
sub_774008(v29);
break;
}
sub_774008(v29);
}
if ( v43.m_smartPrefab )
sub_775D40(&v43.m_prefabKey, &v43.m_smartPrefab->m_prefabKey);
v20 = std::map::operator[](v3, a3);
*(_DWORD *)v20 = v43.m_smartPrefab;
sub_775D40(v20 + 4, &v43.m_binaryKey);
sub_775D40(v20 + 8, &v43.m_prefabKey);
m_data = v43.m_prefabKey.m_data.m_data;
*(_DWORD *)(v20 + 12) = v43.m_prefabCount;
*(_BYTE *)(v20 + 16) = v43.m_unrequired;
*(_DWORD *)(v20 + 20) = v43.m_rotation;
*(_BYTE *)(v20 + 24) = v43.m_flipX;
*(_BYTE *)(v20 + 25) = v43.m_flipY;
*(_BYTE *)(v20 + 26) = v43.m_ignoreCorners;
m_smartPrefab = v43.m_smartPrefab;
a1->m_prefabKey.m_data.m_data = m_data;
a1->m_smartPrefab = m_smartPrefab;
a1->m_binaryKey.m_data.m_data = v43.m_binaryKey.m_data.m_data;
v43.m_binaryKey.m_data.m_data = (stl::StringData::Internal *)&unk_ACDDA8;
v43.m_prefabKey.m_data.m_data = (stl::StringData::Internal *)&unk_ACDDA8;
a1->m_prefabCount = v43.m_prefabCount;
a1->m_unrequired = v43.m_unrequired;
a1->m_rotation = v43.m_rotation;
a1->m_flipX = v43.m_flipX;
a1->m_flipY = v43.m_flipY;
a1->m_ignoreCorners = v43.m_ignoreCorners;
SmartPrefabResult::~SmartPrefabResult(&v43);
}
return a1;
}