//
// LevelEditorLayer::objectAtPosition from 0x65dfbc to 0x65e34c (912 bytes)
//
// 3 xrefs:
// > EditorUI::clickOnPosition @ 0x6c1794
// > EditorUI::clickOnPosition @ 0x6c17cc
// > ??> @ 0x997b0
//
// 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
//
GameObject *LevelEditorLayer::objectAtPosition(LevelEditorLayer *a1, cocos2d::CCPoint a2)
{
float *v2; // x1
const cocos2d::CCPoint *v4; // x25
float x; // s0
int v6; // w19
float y; // s0
int v8; // w0
unsigned __int64 v9; // x26
int v10; // w23
int v11; // w1
std::vector *, std::allocator *>> **m_start; // x19
std::vector *, std::allocator *>> **m_finish; // x1
__int64 v14; // x0
unsigned __int64 v15; // x2
int v16; // w0
bool *p_m_nonSquareRotation; // x23
std::vector *, std::allocator *>> *v18; // x19
__int64 v19; // x0
unsigned __int64 v20; // x1
int v21; // w0
__int64 v22; // x27
__int64 v23; // x26
std::vector *v24; // x22
int v25; // w21
unsigned __int64 v26; // x28
__int64 v27; // x21
GameObject *v28; // x19
int v30; // [xsp+80h] [xbp+80h]
int v31; // [xsp+84h] [xbp+84h]
int v32; // [xsp+88h] [xbp+88h]
int v33; // [xsp+8Ch] [xbp+8Ch]
int v34; // [xsp+90h] [xbp+90h]
int v35; // [xsp+90h] [xbp+90h]
int v36; // [xsp+94h] [xbp+94h]
__int64 v37; // [xsp+98h] [xbp+98h]
cocos2d::CCRect v38; // [xsp+A8h] [xbp+A8h] BYREF
cocos2d::CCRect v39; // 0:s0.4,4:s1.4,8:s2.4,12:s3.4
v4 = (const cocos2d::CCPoint *)v2;
cocos2d::CCRect::CCRect(&v38, *v2, v2[1], 1.0, 1.0);
GJBaseGameLayer::updateOBB2(a1, v39);
x = v4->x;
if ( v4->x > 0.0 )
{
if ( x < 10000000.0 )
{
v6 = (int)(float)(x * a1->m_sectionXFactor);
y = v4->y;
v8 = v6 + 1;
v9 = v6 + 1;
if ( y > 0.0 )
goto LABEL_4;
LABEL_29:
v11 = 1;
v10 = 0;
v9 = v8;
if ( v6 > 1 )
{
LABEL_7:
v32 = v11;
v30 = v6 - 1;
v34 = v8;
goto LABEL_8;
}
goto LABEL_30;
}
v6 = (int)(float)(a1->m_sectionXFactor * 10000000.0);
y = v4->y;
v8 = v6 + 1;
v9 = v6 + 1;
if ( y <= 0.0 )
goto LABEL_29;
LABEL_4:
if ( y < 10000000.0 )
v10 = (int)(float)(y * a1->m_sectionYFactor);
else
v10 = (int)(float)(a1->m_sectionYFactor * 10000000.0);
v11 = v10 + 1;
if ( v6 > 1 )
goto LABEL_7;
LABEL_30:
v32 = v11;
v34 = v8;
v30 = 0;
goto LABEL_8;
}
y = v4->y;
v9 = 1;
if ( y > 0.0 )
{
v6 = 0;
v8 = 1;
goto LABEL_4;
}
v34 = 1;
v32 = 1;
v10 = 0;
v30 = 0;
LABEL_8:
m_start = a1->m_sections.m_start;
m_finish = a1->m_sections.m_finish;
v14 = m_finish - m_start;
v15 = v14 - 1;
v16 = v14 - 1;
if ( v15 >= v9 )
v16 = v34;
v35 = v16;
if ( v10 <= 1 )
v31 = 0;
else
v31 = v10 - 1;
if ( m_start != m_finish && v30 <= v16 )
{
v37 = v30;
p_m_nonSquareRotation = &a1->m_nonSquareRotation;
while ( 1 )
{
v18 = m_start[v37];
if ( v18 )
{
v19 = v18->m_finish - v18->m_start;
v20 = v19 - 1;
v21 = v19 - 1;
if ( v32 <= v20 )
v21 = v32;
v33 = v21;
if ( v31 <= v21 )
break;
}
LABEL_41:
++v37;
if ( v35 < ++v30 )
return nullptr;
m_start = a1->m_sections.m_start;
}
v22 = v31;
v23 = v31;
v36 = v31;
while ( 1 )
{
v24 = v18->m_start[v23];
if ( v24 )
{
v25 = a1->m_sectionSizes.m_start[v37]->m_start[v22];
if ( v25 > 0 )
break;
}
LABEL_34:
++v23;
++v22;
if ( v33 < ++v36 )
goto LABEL_41;
v18 = a1->m_sections.m_start[v37];
}
v26 = 0;
v27 = 8 * ((unsigned int)(v25 - 1) + 1LL);
while ( 1 )
{
v28 = v24->m_start[v26 / 8];
if ( !LevelEditorLayer::validGroup(a1, v28, 1) )
goto LABEL_23;
LevelEditorLayer::getObjectRect(a1, v28, 0, 0);
if ( *p_m_nonSquareRotation )
goto LABEL_46;
if ( (unsigned __int8)cocos2d::CCRect::containsPoint(&v38, v4) )
return v28;
if ( *p_m_nonSquareRotation )
{
LABEL_46:
if ( OBB2D::overlaps(a1->m_currentOBB2D) )
return v28;
LABEL_23:
v26 += 8LL;
if ( v26 == v27 )
goto LABEL_34;
}
else
{
v26 += 8LL;
if ( v26 == v27 )
goto LABEL_34;
}
}
}
return nullptr;
}