//
// LevelEditorLayer::objectAtPosition from 0x1000e11f0 to 0x1000e1522 (818 bytes)
//
// 2 xrefs:
// > EditorUI::clickOnPosition @ 0x10002db26
// > EditorUI::clickOnPosition @ 0x10002db6e
//
// 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; // rsi
float v4; // xmm2_4
float v5; // xmm0_4
float v6; // xmm1_4
float m_sectionXFactor; // xmm1_4
int v8; // edx
float v9; // xmm1_4
float m_sectionYFactor; // xmm0_4
int v11; // ecx
unsigned int v12; // r9d
unsigned int v13; // eax
unsigned __int64 v14; // r10
std::vector *, std::allocator *>> **begin; // rsi
__int64 v16; // rdi
unsigned __int64 v17; // r8
int v18; // edi
GameObject *v19; // r12
__int64 v20; // r11
std::vector *, std::allocator *>> *v21; // rax
__int64 v22; // rdx
unsigned __int64 v23; // rax
__int64 v24; // rdx
__int64 v25; // r10
std::vector *v26; // rbx
__int64 v27; // r13
__int64 v28; // r15
std::__vector_base::pointer v29; // rsi
__int64 v30; // rdi
unsigned __int64 m_editorLayer; // rcx
int v32; // eax
__int16 m_currentLayer; // dx
bool v34; // si
bool v35; // di
bool v36; // r8
unsigned __int16 v37; // dx
__int64 v38; // rcx
bool m_nonSquareRotation; // al
_BYTE v41[16]; // [rsp+8h] [rbp-78h] BYREF
__int64 v42; // [rsp+18h] [rbp-68h]
__int64 v43; // [rsp+20h] [rbp-60h]
__int64 v44; // [rsp+28h] [rbp-58h]
unsigned __int64 v45; // [rsp+30h] [rbp-50h]
__int64 v46; // [rsp+38h] [rbp-48h]
float *v47; // [rsp+40h] [rbp-40h]
int v48; // [rsp+4Ch] [rbp-34h]
__int64 v49; // [rsp+50h] [rbp-30h]
cocos2d::CCRect ObjectRect; // 0:kr00_16.16
cocos2d::CCRect v51; // 0:xmm0_8.8,8:xmm1_8.8
v51.origin = (cocos2d::CCPoint)*(unsigned int *)v2;
v51.size = (cocos2d::CCSize)*((unsigned int *)v2 + 1);
sub_10028CC00(v41, *(double *)&v51.origin, *(double *)&v51.size, 1.0, 1.0);
GJBaseGameLayer::updateOBB2(a1, v51);
v47 = v2;
v4 = *v2;
v5 = 0.0;
v6 = 0.0;
if ( *v2 > 0.0 )
{
m_sectionXFactor = a1->m_sectionXFactor;
if ( v4 >= 10000000.0 )
v6 = m_sectionXFactor * 10000000.0;
else
v6 = m_sectionXFactor * v4;
}
v8 = (int)v6;
v9 = v47[1];
if ( v9 > 0.0 )
{
m_sectionYFactor = a1->m_sectionYFactor;
if ( v9 >= 10000000.0 )
v5 = m_sectionYFactor * 10000000.0;
else
v5 = m_sectionYFactor * v9;
}
v11 = (int)v5;
v12 = 1;
v13 = 1;
if ( v8 >= 2 )
v13 = v8;
v14 = v8 + 1;
begin = a1->m_sections.__begin_;
v16 = a1->m_sections.__end_ - begin;
v17 = v16 - 1;
v18 = v16 - 1;
if ( v17 < v14 )
LODWORD(v14) = v18;
if ( v11 >= 2 )
v12 = (int)v5;
v19 = nullptr;
if ( a1->m_sections.__end_ != begin && (int)(v13 - 1) <= (int)v14 )
{
v45 = v11 + 1;
v48 = v12 - 1;
v46 = v12 - 1LL;
v20 = v13 - 1LL;
v44 = (unsigned int)(v14 + 1);
while ( 1 )
{
v21 = a1->m_sections.__begin_[v20];
if ( v21 )
{
v22 = v21->__end_ - v21->__begin_;
v23 = v22 - 1;
v24 = (unsigned int)(v22 - 1);
if ( v23 >= v45 )
v24 = (unsigned int)v45;
v49 = v24;
if ( v48 <= (int)v24 )
break;
}
LABEL_18:
if ( ++v20 == v44 )
return nullptr;
}
v49 = (unsigned int)(v49 + 1);
v25 = v46;
v43 = v20;
while ( 1 )
{
v26 = a1->m_sections.__begin_[v20]->__begin_[v25];
if ( v26 )
{
v27 = a1->m_sectionSizes.__begin_[v20]->__begin_[v25];
if ( v27 > 0 )
break;
}
LABEL_24:
if ( ++v25 == v49 )
goto LABEL_18;
}
v28 = 0;
v42 = v25;
while ( 1 )
{
v19 = v26->__begin_[v28];
m_editorLayer = (unsigned __int16)v19->m_editorLayer;
v32 = (unsigned __int16)*(_DWORD *)&v19->m_editorLayer2 == 0 ? -1 : *(_DWORD *)&v19->m_editorLayer2;
m_currentLayer = a1->m_currentLayer;
v34 = m_currentLayer == -1;
v35 = m_currentLayer == (__int16)m_editorLayer;
v36 = m_currentLayer == (__int16)((unsigned __int16)*(_DWORD *)&v19->m_editorLayer2 == 0 ? -1 : v19->m_editorLayer2);
v37 = v32;
if ( (__int16)((unsigned __int16)*(_DWORD *)&v19->m_editorLayer2 == 0 ? -1 : v19->m_editorLayer2) >= 9999 )
break;
if ( (v32 & 0x8000u) == 0 )
goto LABEL_32;
v37 = -1;
if ( !v36 && !v35 && !v34 )
goto LABEL_29;
LABEL_36:
if ( (__int16)m_editorLayer >= 9999 )
m_editorLayer = 9999;
if ( (__int16)m_editorLayer <= 0 )
m_editorLayer = 0;
v29 = a1->m_lockedLayers.__begin_;
v30 = *(_QWORD *)&v29[((unsigned int)m_editorLayer >> 3) & 0x7F8];
if ( !_bittest64(&v30, m_editorLayer) )
{
if ( (v32 & 0x8000u) != 0 || (v38 = *(_QWORD *)&v29[8 * ((unsigned __int64)v37 >> 6)], !_bittest64(&v38, v37)) )
{
ObjectRect = LevelEditorLayer::getObjectRect(
(LevelEditorLayer *)v41,
(GameObject *)a1,
(bool)v26->__begin_[v28],
0);
m_nonSquareRotation = a1->m_nonSquareRotation;
if ( !m_nonSquareRotation )
{
if ( (unsigned __int8)sub_10028D2D0(
v41,
v47,
COERCE_DOUBLE(ObjectRect.origin),
COERCE_DOUBLE(ObjectRect.size)) )
return v19;
m_nonSquareRotation = a1->m_nonSquareRotation;
}
if ( m_nonSquareRotation && OBB2D::overlaps(a1->m_currentOBB2D) )
return v19;
v20 = v43;
v25 = v42;
}
}
LABEL_29:
if ( v27 == ++v28 )
goto LABEL_24;
}
v37 = 9999;
LABEL_32:
if ( !v36 && !v35 && !v34 )
goto LABEL_29;
goto LABEL_36;
}
return v19;
}