//
// LevelEditorLayer::objectAtPosition from 0x10035ac30 to 0x10035ae90 (608 bytes)
//
// 2 xrefs:
// > EditorUI::clickOnPosition @ 0x1003e678c
// > EditorUI::clickOnPosition @ 0x1003e67c4
//
// 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 *__fastcall LevelEditorLayer::objectAtPosition(LevelEditorLayer *a1, cocos2d::CCPoint a2)
{
float *v2; // x1
float *v3; // x19
float v5; // s1
float v6; // s0
float v7; // s2
float m_sectionXFactor; // s2
int v9; // w8
float v10; // s1
float m_sectionYFactor; // s0
GameObject *v12; // x21
int v13; // w10
__int64 v14; // x9
std::__vector_base *, std::allocator *>> *, std::allocator *, std::allocator *>> *>>::pointer end; // x12
std::__vector_base *, std::allocator *>> *, std::allocator *, std::allocator *>> *>>::pointer begin; // x13
__int64 v17; // x14
int v18; // w8
__int64 v19; // x11
__int64 v20; // x27
std::vector *, std::allocator *>> *v21; // x8
__int64 v22; // x8
unsigned __int64 v23; // x9
int v24; // w8
__int64 v25; // x26
__int64 v26; // x22
std::vector *v27; // x24
__int64 v28; // x8
unsigned __int64 v29; // x28
__int64 v30; // x23
__int64 v32; // [xsp+8h] [xbp-88h]
int v33; // [xsp+18h] [xbp-78h]
int v34; // [xsp+24h] [xbp-6Ch]
__int64 v35; // [xsp+28h] [xbp-68h]
float v36[4]; // [xsp+30h] [xbp-60h] BYREF
cocos2d::CCRect v37; // 0:s0.4,4:s1.4,8:s2.4,12:s3.4
v3 = v2;
sub_100022990(v36, *v2, v2[1], 1.0, 1.0);
GJBaseGameLayer::updateOBB2(a1, v37);
v5 = *v3;
v6 = 0.0;
v7 = 0.0;
if ( *v3 > 0.0 )
{
m_sectionXFactor = a1->m_sectionXFactor;
if ( v5 >= 10000000.0 )
v7 = m_sectionXFactor * 10000000.0;
else
v7 = v5 * m_sectionXFactor;
}
v9 = (int)v7;
v10 = v3[1];
if ( v10 > 0.0 )
{
m_sectionYFactor = a1->m_sectionYFactor;
if ( v10 >= 10000000.0 )
v6 = m_sectionYFactor * 10000000.0;
else
v6 = v10 * m_sectionYFactor;
}
v12 = nullptr;
v13 = (int)v6;
if ( v9 <= 1 )
v14 = 1;
else
v14 = (unsigned int)v9;
end = a1->m_sections.__end_;
begin = a1->m_sections.__begin_;
v17 = end - begin;
if ( v17 - 1 >= (unsigned __int64)(v9 + 1) )
v18 = v9 + 1;
else
v18 = v17 - 1;
if ( v13 <= 1 )
v19 = 1;
else
v19 = (unsigned int)v13;
if ( end != begin && (int)v14 - 1 <= v18 )
{
v34 = v19 - 1;
v33 = v13 + 1;
v32 = v19 - 1;
v20 = v14 - 1;
v35 = (unsigned int)(v18 + 1);
while ( 1 )
{
v21 = a1->m_sections.__begin_[v20];
if ( v21 )
{
v22 = v21->__end_ - v21->__begin_;
v23 = v22 - 1;
v24 = v22 - 1;
if ( v23 >= v33 )
v24 = v33;
if ( v34 <= v24 )
break;
}
LABEL_25:
if ( ++v20 == v35 )
return nullptr;
}
v25 = (unsigned int)(v24 + 1);
v26 = v32;
while ( 1 )
{
v27 = a1->m_sections.__begin_[v20]->__begin_[v26];
if ( v27 )
{
v28 = (unsigned int)a1->m_sectionSizes.__begin_[v20]->__begin_[v26];
if ( (int)v28 >= 1 )
break;
}
LABEL_37:
if ( ++v26 == v25 )
goto LABEL_25;
}
v29 = 0;
v30 = 8 * v28;
while ( 1 )
{
v12 = v27->__begin_[v29 / 8];
if ( LevelEditorLayer::validGroup(a1, v12, 1) )
{
LevelEditorLayer::getObjectRect(a1, v12, 0, 0);
if ( a1->m_nonSquareRotation )
goto LABEL_35;
if ( sub_100022C60(v36, v3) )
return v12;
if ( a1->m_nonSquareRotation )
{
LABEL_35:
if ( OBB2D::overlaps(a1->m_currentOBB2D) )
break;
}
}
v29 += 8LL;
if ( v30 == v29 )
goto LABEL_37;
}
}
return v12;
}