//
// EditorUI::onCreateObject from 0x3a3afc to 0x3a4010 (1300 bytes)
//
// 1 xrefs:
// > EditorUI::onCreate @ 0x3a40b0
//
// 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
//
void EditorUI::onCreateObject(EditorUI *a1, int a2)
{
cocos2d::CCPoint v4; // r2
float v5; // s13
float x; // s15
float y; // s14
int v8; // r3
GameObject *m_selectedObject; // r0
float v10; // r10
bool v11; // r9
char v12; // r11
int v13; // r2
bool v14; // r3
int v15; // r2
bool v16; // r3
cocos2d::CCPoint v17; // r2
int v18; // r2
bool v19; // r3
cocos2d::CCPoint v20; // r1
cocos2d::CCPoint v21; // r1
cocos2d::CCArray *v22; // r0
cocos2d::CCPoint v23; // r2
GameObject *Object; // r0
GameObject *v25; // r3
GameObject *v26; // r7
cocos2d::CCArray *NewKeyframeAnim; // r0
int v28; // r0
cocos2d::CCArray *v29; // r0
GameObject *v30; // r1
GameManager *v31; // r0
cocos2d::CCArray *v32; // r6
unsigned int i; // r11
_BYTE *v34; // r7
int v35; // r0
int v36; // r2
bool v37; // r3
int v38; // r5
unsigned int j; // r5
int v40; // r7
unsigned int k; // r5
int v42; // r0
int v43; // r8
float v44; // s16
int v45; // r2
bool v46; // r3
LevelEditorLayer *v47; // r2
float v48; // s16
int v49; // s16
unsigned int m; // r5
GameObject *v51; // r0
bool v52; // [sp+0h] [bp-14h]
LevelEditorLayer *m_editorLayer; // [sp+8h] [bp-Ch]
cocos2d::CCArray *v54; // [sp+8h] [bp-Ch]
char *v55; // [sp+10h] [bp-4h] BYREF
cocos2d::CCPoint v56; // [sp+14h] [bp+0h] BYREF
cocos2d::CCPoint v57; // [sp+1Ch] [bp+8h] BYREF
cocos2d::CCPoint v58; // [sp+24h] [bp+10h] BYREF
cocos2d::CCPoint v59; // [sp+2Ch] [bp+18h] BYREF
cocos2d::CCPoint v60; // [sp+34h] [bp+20h] BYREF
cocos2d::CCPoint v61; // [sp+3Ch] [bp+28h] BYREF
cocos2d::CCPoint v62; // [sp+44h] [bp+30h] BYREF
cocos2d::CCPoint v63; // [sp+4Ch] [bp+38h] BYREF
cocos2d::CCPoint v64; // 0:r3.4,4:^0.4
cocos2d::CCPoint::CCPoint(&v63, &a1->m_clickAtPosition);
LODWORD(v4.x) = &v63;
EditorUI::getGridSnappedPos(&v56, a1, v4);
cocos2d::CCPoint::CCPoint(&v57, &v56);
v5 = a1->m_gridSize * 0.5;
x = v5 - 3000.0;
if ( v56.x >= (float)(v5 - 3000.0) )
x = v56.x;
y = v56.y;
if ( v56.y < -3000.0 )
y = -3000.0;
if ( (float)(240000.0 - v5) <= x )
x = 240000.0 - v5;
if ( a1->m_editorLayer->m_levelSettings->m_dynamicLevelHeight )
v8 = 1000;
else
v8 = 80;
v56.x = x;
if ( (float)((float)((float)((float)v8 * 30.0) + 90.0) - v5) <= y )
y = (float)((float)((float)v8 * 30.0) + 90.0) - v5;
v56.y = y;
EditorUI::offsetForKey(&v58, a1, a2);
cocos2d::CCPoint::CCPoint(&v59);
m_selectedObject = a1->m_selectedObject;
if ( m_selectedObject && m_selectedObject->m_objectID == a2 )
{
v10 = COERCE_FLOAT(((int (__fastcall *)(GameObject *))m_selectedObject->isFlipX)(m_selectedObject));
v11 = a1->m_selectedObject->isFlipY(a1->m_selectedObject);
v12 = ((int (__fastcall *)(GameObject *))a1->m_selectedObject->getRotation)(a1->m_selectedObject);
EditorUI::getRelativeOffset(&v62, a1, a1->m_selectedObject);
cocos2d::CCPoint::operator+(&v63, &v56, &v62);
cocos2d::CCPoint::operator=((PlayerObject *)&v59, COERCE_FLOAT(&v63), v13, v14);
}
else
{
v11 = 0;
cocos2d::CCPoint::operator+(&v63, &v56, &v58);
v12 = 0;
cocos2d::CCPoint::operator=((PlayerObject *)&v59, COERCE_FLOAT(&v63), v45, v46);
v10 = 0.0;
}
cocos2d::CCPoint::operator+(&v63, &v56, &v58);
cocos2d::CCPoint::operator=((PlayerObject *)&v56, COERCE_FLOAT(&v63), v15, v16);
m_editorLayer = a1->m_editorLayer;
cocos2d::CCPoint::CCPoint(&v62, &v59);
LODWORD(v17.x) = &v62;
v17.y = v10;
if ( LevelEditorLayer::typeExistsAtPosition(m_editorLayer, a2, v17, v11, v12, *(float *)&m_editorLayer)
|| a2 < 0 && (cocos2d::CCPoint::CCPoint(&v63, &v57), LODWORD(v20.x) = &v63, EditorUI::positionIsInSnapped(a1, v20)) )
{
cocos2d::CCPoint::operator=((PlayerObject *)&a1->m_createPosition, COERCE_FLOAT(&flt_AC5D38), v18, v19);
}
else
{
cocos2d::CCPoint::CCPoint(&v63, &v57);
LODWORD(v21.x) = &v63;
EditorUI::addSnapPosition(a1, v21);
if ( a2 <= 0 )
{
v29 = (cocos2d::CCArray *)cocos2d::CCArray::create(v22);
v30 = a1->m_selectedObject;
v54 = v29;
if ( v30 )
cocos2d::CCArray::addObject(v29, v30);
else
cocos2d::CCArray::addObjectsFromArray(v29, a1->m_selectedObjects);
v31 = GameManager::sharedState();
GameManager::stringForCustomObject((GameManager *)&v55, (int)v31, (const char *)a2);
sub_776584((int)&v63, v55);
v32 = EditorUI::pasteObjects(a1, &v63, 0, 0);
sub_774008(&v63);
if ( v32 && cocos2d::CCArray::count(v32) )
{
for ( i = 0; i < cocos2d::CCArray::count(v32); ++i )
{
v34 = (_BYTE *)cocos2d::CCArray::objectAtIndex(v32, i);
if ( v34[998] )
goto LABEL_42;
}
v34 = nullptr;
LABEL_42:
cocos2d::CCPoint::CCPoint(&v60, &v57);
if ( v34 )
{
EditorUI::getGroupCenter(&v61, a1, v32, 0);
v35 = (*(int (__fastcall **)(_BYTE *))(*(_DWORD *)v34 + 96))(v34);
cocos2d::CCPoint::operator-(&v62, &v61, v35);
cocos2d::CCPoint::operator+(&v63, &v60, &v62);
cocos2d::CCPoint::operator=((PlayerObject *)&v60, COERCE_FLOAT(&v63), v36, v37);
}
cocos2d::CCPoint::CCPoint(&v63, &v60);
EditorUI::repositionObjectsToCenter(a1, v32, (cocos2d::CCPoint)(unsigned int)&v63, v52);
v38 = cocos2d::CCArray::count(v32);
if ( v38 == cocos2d::CCArray::count(v54) )
{
for ( j = 0; j < cocos2d::CCArray::count(v54); ++j )
{
v40 = cocos2d::CCArray::objectAtIndex(v54, j);
if ( *(_BYTE *)(v40 + 998) )
goto LABEL_50;
}
v40 = 0;
LABEL_50:
for ( k = 0; k < cocos2d::CCArray::count(v32); ++k )
{
v42 = cocos2d::CCArray::objectAtIndex(v32, k);
v43 = v42;
if ( *(_BYTE *)(v42 + 998) )
{
if ( v40 )
{
if ( *(_DWORD *)(v40 + 884) == *(_DWORD *)(v42 + 884) )
{
v44 = COERCE_FLOAT((*(int (__fastcall **)(int))(*(_DWORD *)v40 + 176))(v40));
if ( v44 != (*(float (__fastcall **)(int))(*(_DWORD *)v43 + 176))(v43) )
{
v48 = COERCE_FLOAT((*(int (__fastcall **)(int))(*(_DWORD *)v40 + 176))(v40));
v49 = (int)(float)(v48 - (*(float (__fastcall **)(int))(*(_DWORD *)v43 + 176))(v43));
if ( v49 % 90 )
{
for ( m = 0; m < cocos2d::CCArray::count(v32); ++m )
{
v51 = (GameObject *)cocos2d::CCArray::objectAtIndex(v32, m);
if ( !GameObject::canRotateFree(v51) )
goto LABEL_58;
}
}
cocos2d::CCPoint::CCPoint(&v63, (const cocos2d::CCPoint *)&flt_AC5D38);
LODWORD(v64.x) = &v63;
EditorUI::rotateObjects(a1, v32, (float)v49, v64);
}
}
}
break;
}
}
}
}
LABEL_58:
sub_774008(&v55);
}
else
{
cocos2d::CCPoint::CCPoint(&v63, &v56);
LODWORD(v23.x) = &v63;
Object = EditorUI::createObject(a1, a2, v23);
v25 = a1->m_selectedObject;
v26 = Object;
if ( v25 && Object->m_objectID == v25->m_objectID )
{
EditorUI::removeOffset(a1, Object);
GameObject::duplicateValues(v26);
EditorUI::applyOffset(a1, v26);
}
if ( a2 == 914 )
{
sub_776584((int)&v63, "A");
TextGameObject::updateTextObject((int *)v26, (const char **)&v63, 0);
sub_774008(&v63);
}
else if ( a2 == 3032 )
{
LevelEditorLayer::removeSpecial(a1->m_editorLayer, v26);
NewKeyframeAnim = GJBaseGameLayer::createNewKeyframeAnim(a1->m_editorLayer);
v28 = NewKeyframeAnim->getTag(NewKeyframeAnim);
v26[1].m_fBrVertexMod = 0.0;
LODWORD(v26[1].m_fBlVertexMod) = v28;
LevelEditorLayer::addSpecial(a1->m_editorLayer, v26);
}
EditorUI::selectObject(a1, v26, 0);
if ( v26
&& v26->m_classType == Effect
&& (GameObject::isSpeedObject(v26)
|| ((int (__fastcall *)(GameObject *))v26->canReverse)(v26) && LOBYTE(v26[1].m_sQuad.tr.vertices.z)) )
{
v47 = a1->m_editorLayer;
LOBYTE(v26[1].m_sQuad.bl.texCoords.v) = 1;
DrawGridLayer::addToSpeedObjects(v47->m_drawGridLayer, (EffectGameObject *)v26);
}
EditorUI::updateSlider(a1);
}
}
}