//
// LevelEditorLayer::objectAtPosition from 0x1402d5050 to 0x1402d540c (956 bytes)
//
// 5 xrefs:
// > EditorUI::clickOnPosition @ 0x1400e278e
// > EditorUI::clickOnPosition @ 0x1400e27e9
// > ??> @ 0x14068e108
// > ??> @ 0x14068e12c
// > ??> @ 0x1406d2fcc
//
// 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)
{
double v4; // xmm0_8
__int64 v5; // rax
__int64 v6; // rbx
float v7; // xmm6_4
float v8; // xmm1_4
float v9; // xmm0_4
float m_sectionXFactor; // xmm0_4
float v11; // xmm1_4
int v12; // r8d
float m_sectionYFactor; // xmm0_4
std::_Vector_val *, std::allocator *>> *>>::pointer Mylast; // r11
std::_Vector_val *, std::allocator *>> *>>::pointer Myfirst; // rbx
int v16; // r9d
int v17; // r10d
__int64 v18; // rdx
int v19; // r8d
int v20; // ecx
int v21; // r10d
__int64 v22; // r13
__int64 v23; // r8
std::_Simple_types *, std::allocator *>> *>::value_type v24; // rcx
__int64 v25; // rdx
int v26; // edx
__int64 v27; // r14
std::_Simple_types *>::value_type v28; // r15
__int64 v29; // rbx
__int64 v30; // rbp
int m_currentLayer; // ecx
GameObject *v32; // rsi
int m_editorLayer2; // eax
int m_editorLayer; // r8d
bool v35; // dl
int v36; // ecx
int v37; // r8d
std::_Vector_val>::pointer v38; // r9
std::_Simple_types::value_type v39; // eax
std::_Simple_types::value_type v40; // eax
OBB2D *v41; // r8
bool X; // [rsp+20h] [rbp-78h]
cocos2d::CCRect v44; // [rsp+30h] [rbp-68h] BYREF
int v45; // [rsp+A0h] [rbp+8h] BYREF
__int64 v46; // [rsp+A8h] [rbp+10h]
__int64 v47; // [rsp+B0h] [rbp+18h]
__int64 v48; // [rsp+B8h] [rbp+20h]
v4 = cocos2d::CCRect::CCRect(&v44, **(float **)&a2, *(float *)(*(_QWORD *)&a2 + 4LL), 1.0, 1.0);
v6 = v5;
cocos2d::CCPoint::CCPoint(*(float *)&v4, *(float *)(v5 + 8) * 0.5);
cocos2d::CCPoint::operator+(v6, &v45);
v7 = 0.0;
OBB2D::calculateWithCenter(a1->m_obb2, (cocos2d::CCPoint)&v45, *(float *)(v6 + 8), *(float *)(v6 + 12), 0.0);
v8 = **(float **)&a2;
if ( **(float **)&a2 > 0.0 )
{
m_sectionXFactor = a1->m_sectionXFactor;
if ( v8 < 10000000.0 )
v9 = v8 * m_sectionXFactor;
else
v9 = m_sectionXFactor * 10000000.0;
}
else
{
v9 = 0.0;
}
v11 = *(float *)(*(_QWORD *)&a2 + 4LL);
v12 = (int)v9;
if ( v11 > 0.0 )
{
m_sectionYFactor = a1->m_sectionYFactor;
if ( v11 < 10000000.0 )
v7 = v11 * m_sectionYFactor;
else
v7 = m_sectionYFactor * 10000000.0;
}
Mylast = a1->m_sections._Mypair._Myval2._Mylast;
Myfirst = a1->m_sections._Mypair._Myval2._Myfirst;
v16 = 0;
v17 = (int)v7;
if ( v12 - 1 >= 0 )
v16 = v12 - 1;
v18 = a1->m_sections._Mypair._Myval2._Mylast - Myfirst;
v19 = v12 + 1;
if ( v19 >= (unsigned __int64)(v18 - 1) )
v19 = v18 - 1;
v20 = 0;
if ( v17 - 1 >= 0 )
v20 = v17 - 1;
v21 = v17 + 1;
v45 = v21;
if ( Myfirst == Mylast )
return nullptr;
v22 = v16;
v48 = v19;
if ( v16 > (__int64)v19 )
return nullptr;
v23 = v20;
v47 = v20;
while ( 1 )
{
v24 = a1->m_sections._Mypair._Myval2._Myfirst[v22];
if ( v24 )
{
v25 = v24->_Mypair._Myval2._Mylast - v24->_Mypair._Myval2._Myfirst;
v26 = v21 >= (unsigned __int64)(v25 - 1) ? v25 - 1 : v21;
}
else
{
v26 = -1;
}
v27 = v23;
v46 = v26;
if ( v23 <= v26 )
break;
LABEL_54:
if ( ++v22 > v48 )
return nullptr;
}
while ( 1 )
{
v28 = a1->m_sections._Mypair._Myval2._Myfirst[v22]->_Mypair._Myval2._Myfirst[v27];
if ( v28 )
{
v29 = 0;
v30 = a1->m_sectionSizes._Mypair._Myval2._Myfirst[v22]->_Mypair._Myval2._Myfirst[v27];
if ( v30 > 0 )
break;
}
LABEL_52:
if ( ++v27 > v46 )
{
v23 = v47;
v21 = v45;
goto LABEL_54;
}
}
while ( 1 )
{
m_currentLayer = a1->m_currentLayer;
v32 = v28->_Mypair._Myval2._Myfirst[v29];
m_editorLayer2 = v32->m_editorLayer2;
m_editorLayer = v32->m_editorLayer;
if ( !v32->m_editorLayer2 )
m_editorLayer2 = -1;
v35 = (_WORD)m_currentLayer == 0xFFFF || m_currentLayer == m_editorLayer || m_currentLayer == m_editorLayer2;
v36 = 9999;
if ( m_editorLayer < 9999 )
v36 = v32->m_editorLayer;
v37 = 9999;
if ( v36 < 0 )
v36 = 0;
if ( m_editorLayer2 < 9999 )
v37 = m_editorLayer2;
if ( v37 < -1 )
v37 = -1;
if ( v35 )
{
v38 = a1->m_lockedLayers._Myvec._Mypair._Myval2._Myfirst;
v39 = v38[(unsigned __int64)(unsigned int)v36 >> 5];
if ( !_bittest((const int *)&v39, v36 & 0x1F) )
{
if ( v37 == -1 || (v40 = v38[(unsigned __int64)v37 >> 5], !_bittest((const int *)&v40, v37 & 0x1F)) )
{
LevelEditorLayer::getObjectRect(
(cocos2d::CCRect *)a1,
(LevelEditorLayer *)&v44,
v28->_Mypair._Myval2._Myfirst[v29],
(bool)v38,
X);
if ( a1->m_nonSquareRotation )
goto LABEL_59;
if ( cocos2d::CCRect::containsPoint(&v44, *(const struct cocos2d::CCPoint **)&a2) )
return v32;
if ( a1->m_nonSquareRotation )
{
LABEL_59:
if ( OBB2D::overlaps1Way(a1->m_currentOBB2D) && OBB2D::overlaps1Way(v41) )
return v32;
}
}
}
}
if ( ++v29 >= v30 )
goto LABEL_52;
}
}