//
// LevelEditorLayer::objectAtPosition from 0x3668b0 to 0x366a9e (494 bytes)
//
// 2 xrefs:
// > EditorUI::clickOnPosition @ 0x3a4a94
// > EditorUI::clickOnPosition @ 0x3a4ad2
//
// 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)
{
cocos2d::CCRect *v2; // r6
float x; // r8
float v5; // s15
float m_sectionXFactor; // s14
float v7; // s14
int v8; // r2
float v9; // s15
float v10; // s14
float *p_m_sectionYFactor; // r3
int v12; // r3
std::vector *, std::allocator *>> *, std::allocator *, std::allocator *>> *>> *p_m_sections; // r9
std::vector *, std::allocator *>> **m_finish; // r1
std::vector *, std::allocator *>> **m_start; // r0
int v16; // r5
int v17; // r2
cocos2d::CCRect *v19; // r7
bool *p_m_nonSquareRotation; // r11
std::vector *, std::allocator *>> *v21; // r2
unsigned int v22; // r3
int v23; // r5
int v24; // r10
signed int i; // [sp+8h] [bp-4Ch]
int v26; // [sp+Ch] [bp-48h]
int v27; // [sp+10h] [bp-44h]
GameObject *v28; // [sp+14h] [bp-40h]
signed int v29; // [sp+1Ch] [bp-38h]
_DWORD *v30; // [sp+20h] [bp-34h]
unsigned int v31; // [sp+24h] [bp-30h]
int v32; // [sp+28h] [bp-2Ch]
int v33; // [sp+2Ch] [bp-28h]
cocos2d::CCRect v34; // [sp+3Ch] [bp-18h] BYREF
cocos2d::CCRect v35; // 0:r1.12,12:^0.4
v2 = &v34;
x = a2.x;
cocos2d::CCRect::CCRect(&v34, *(float *)LODWORD(a2.x), *(float *)(LODWORD(a2.x) + 4), 1.0, 1.0);
LODWORD(v35.origin.x) = &v34;
GJBaseGameLayer::updateOBB2(a1, v35);
v5 = *(float *)LODWORD(x);
if ( *(float *)LODWORD(x) <= 0.0 )
{
v8 = 0;
}
else
{
m_sectionXFactor = a1->m_sectionXFactor;
if ( v5 < 10000000.0 )
v7 = v5 * m_sectionXFactor;
else
v7 = m_sectionXFactor * 10000000.0;
v8 = (int)v7;
}
v9 = *(float *)(LODWORD(x) + 4);
if ( v9 <= 0.0 )
{
v12 = 0;
}
else
{
v10 = 10000000.0;
p_m_sectionYFactor = &a1->m_sectionYFactor;
if ( v9 < 10000000.0 )
v10 = *p_m_sectionYFactor;
else
v9 = *p_m_sectionYFactor;
v12 = (int)(float)(v9 * v10);
}
p_m_sections = &a1->m_sections;
if ( v8 > 1 )
v2 = (cocos2d::CCRect *)(v8 - 1);
m_finish = a1->m_sections.m_finish;
m_start = a1->m_sections.m_start;
if ( v8 <= 1 )
v2 = nullptr;
v16 = v8 + 1;
if ( v8 + 1 >= (unsigned int)(m_finish - m_start - 1) )
v16 = m_finish - m_start - 1;
if ( v12 <= 1 )
v17 = 0;
else
v17 = v12 - 1;
v26 = v16;
v27 = v17;
v31 = v12 + 1;
if ( m_start != m_finish )
{
v19 = (cocos2d::CCRect *)(4 * (_DWORD)v2);
p_m_nonSquareRotation = &a1->m_nonSquareRotation;
v33 = 4 * v17;
while ( (int)v2 <= v26 )
{
v21 = *(std::vector *, std::allocator *>> **)((char *)p_m_sections->m_start + (unsigned int)v19);
if ( v21 )
{
v22 = v21->m_finish - v21->m_start - 1;
if ( v22 >= v31 )
v22 = v31;
}
else
{
v22 = -1;
}
v29 = v22;
v23 = v33;
for ( i = v27; i <= v29; ++i )
{
v30 = *(_DWORD **)(**(_DWORD **)((char *)p_m_sections->m_start + (unsigned int)v19) + v23);
if ( v30 )
{
v24 = 0;
v32 = *(_DWORD *)(**(_DWORD **)((char *)a1->m_sectionSizes.m_start + (unsigned int)v19) + v23);
while ( v24 < v32 )
{
v28 = *(GameObject **)(*v30 + 4 * v24);
if ( LevelEditorLayer::validGroup(a1, v28, 1) )
{
LevelEditorLayer::getObjectRect(&v34, a1, v28, 0, 0);
if ( !*p_m_nonSquareRotation )
{
if ( cocos2d::CCRect::containsPoint(&v34, (const cocos2d::CCPoint *)LODWORD(x)) )
return v28;
}
if ( *p_m_nonSquareRotation && OBB2D::overlaps(a1->m_currentOBB2D) )
return v28;
}
++v24;
}
}
v23 += 4;
}
v2 = (cocos2d::CCRect *)((char *)v2 + 1);
v19 = (cocos2d::CCRect *)((char *)v19 + 4);
}
}
return nullptr;
}