//
// PlayLayer::createObjectsFromSetupFinished from 0x5d7cb0 to 0x5d808c (988 bytes)
//
// 2 xrefs:
// > PlayLayer::processCreateObjectsFromSetup @ 0x5dd9e0
// > ??> @ 0x5a150
//
// 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 PlayLayer::createObjectsFromSetupFinished(PlayLayer *a1)
{
cocos2d::CCArray *m_coinArray; // x0
int v3; // w19
unsigned int v4; // w1
__int64 v5; // x0
std::string *m_start; // x25
std::string *m_finish; // x23
std::string *i; // x19
stl::StringData::Internal *m_data; // x1
__int64 *v10; // x0
unsigned int *v11; // x1
int v12; // w2
cocos2d::CCArray *v13; // x0
cocos2d::_ccColor3B *v14; // x2
signed __int64 v15; // x1
int v16; // w0
unsigned __int64 v17; // x1
unsigned __int64 m_nextColorKey; // x3
float *v19; // x2
unsigned __int64 v20; // x0
bool v21; // cc
unsigned __int64 v22; // x0
unsigned int *v23; // x2
unsigned int *v24; // x3
unsigned __int64 v25; // x0
unsigned __int64 v26; // x4
bool v27; // cf
float *v28; // x1
unsigned __int64 v29; // x1
unsigned __int64 v30; // x2
unsigned int *v31; // x0
cocos2d::CCDirector *v32; // x0
float v33; // s0
float v34; // s1
EndPortalObject *v35; // x23
void (__fastcall *setStartPos)(GameObject *__hidden, cocos2d::CCPoint); // x19
void (__fastcall *addToSection)(GJBaseGameLayer *__hidden, GameObject *); // x3
EndPortalObject *m_endPortal; // x1
PlayerObject *m_player1; // x1
EndPortalObject *v40; // x0
GLubyte g; // w3
GLubyte b; // w2
float v43; // s0
float v44; // s1
cocos2d::CCDirector *v45; // x0
float v46; // s0
cocos2d::CCPoint v47; // [xsp+80h] [xbp+80h] BYREF
m_coinArray = a1->m_coinArray;
if ( m_coinArray && (unsigned int)cocos2d::CCArray::count(m_coinArray) )
{
v3 = 0;
qsort(a1->m_coinArray->data->arr, a1->m_coinArray->data->num, 8u, (int (*)(const void *, const void *))xCompRealPos);
while ( v3 < (unsigned int)cocos2d::CCArray::count(a1->m_coinArray) && v3 <= 2 )
{
v4 = v3++;
v5 = cocos2d::CCArray::objectAtIndex(a1->m_coinArray, v4);
*(_DWORD *)(v5 + 1776) = v3;
EnhancedGameObject::updateUserCoin((EnhancedGameObject *)v5);
}
}
if ( !a1->m_isPlatformer )
{
v32 = cocos2d::CCDirector::sharedDirector();
cocos2d::CCDirector::getScreenRight(v32);
v34 = a1->m_maxObjectX + 340.0;
if ( (float)(v33 + 300.0) >= v34 )
{
v45 = cocos2d::CCDirector::sharedDirector();
cocos2d::CCDirector::getScreenRight(v45);
v34 = v46 + 300.0;
}
a1->m_levelLength = v34;
a1->m_endXPosition = v34;
v35 = EndPortalObject::create();
a1->m_endPortal = v35;
setStartPos = v35->setStartPos;
cocos2d::CCPoint::CCPoint(&v47, a1->m_levelLength, 225.0);
((void (__fastcall *)(EndPortalObject *, cocos2d::CCPoint *))setStartPos)(v35, &v47);
addToSection = a1->addToSection;
m_endPortal = a1->m_endPortal;
m_endPortal->m_defaultZOrder = 11;
addToSection(a1, m_endPortal);
cocos2d::CCArray::addObject(a1->m_objects, a1->m_endPortal);
m_player1 = a1->m_player1;
v40 = a1->m_endPortal;
g = m_player1->m_playerColor1.g;
b = m_player1->m_playerColor1.b;
LOBYTE(v47.x) = m_player1->m_playerColor1.r;
BYTE1(v47.x) = g;
BYTE2(v47.x) = b;
EndPortalObject::updateColors(v40, *(cocos2d::ccColor3B *)&v47.x);
a1->m_endPortal->setVisible(a1->m_endPortal, 0);
v43 = ((float (__fastcall *)(EndPortalObject *))a1->m_endPortal->getPosition)(a1->m_endPortal);
cocos2d::CCPoint::operator=(&a1->m_endPosition, v43, v44);
}
LevelTools::sortSpeedObjects(a1->m_speedObjects, a1);
GJBaseGameLayer::orderSpawnObjects(a1);
GJBaseGameLayer::updateMaxGameplayY(a1);
m_start = a1->m_objectStrings.m_start;
m_finish = a1->m_objectStrings.m_finish;
for ( i = m_start; m_finish != i; ++i )
{
while ( 1 )
{
m_data = i->m_data.m_data;
v10 = (__int64 *)((char *)i->m_data.m_data - 24);
if ( v10 != &qword_124B6B0 )
{
if ( &pthread_create )
{
v11 = (unsigned int *)((char *)m_data - 8);
do
v12 = __ldaxr(v11);
while ( __stlxr(v12 - 1, v11) );
}
else
{
v12 = *((_DWORD *)m_data - 2);
*((_DWORD *)m_data - 2) = v12 - 1;
}
if ( v12 <= 0 )
break;
}
if ( m_finish == ++i )
goto LABEL_17;
}
operator delete(v10);
}
LABEL_17:
v13 = a1->m_coinArray;
a1->m_objectStrings.m_finish = m_start;
cocos2d::CCArray::removeAllObjects(v13);
cocos2d::CCObject::release(a1->m_coinArray);
a1->m_coinArray = nullptr;
v14 = a1->m_keyColors.m_start;
v15 = (char *)a1->m_keyColors.m_finish - (char *)v14;
v16 = a1->m_nextColorKey + 1;
a1->m_nextColorKey = v16;
v17 = 0xAAAAAAAAAAAAAAABLL * v15;
m_nextColorKey = v16;
if ( v16 > v17 )
{
std::vector::_M_default_append((__int64)&a1->m_keyColors, v16 - v17);
m_nextColorKey = a1->m_nextColorKey;
LABEL_19:
v19 = a1->m_keyOpacities.m_start;
v20 = a1->m_keyOpacities.m_finish - v19;
v21 = v20 > m_nextColorKey;
if ( v20 >= m_nextColorKey )
goto LABEL_20;
goto LABEL_28;
}
if ( v16 >= v17 )
goto LABEL_19;
v28 = a1->m_keyOpacities.m_finish;
a1->m_keyColors.m_finish = &v14[v16];
v19 = a1->m_keyOpacities.m_start;
v20 = v28 - v19;
v21 = v20 > m_nextColorKey;
if ( v20 >= m_nextColorKey )
{
LABEL_20:
if ( v21 )
a1->m_keyOpacities.m_finish = &v19[m_nextColorKey];
v22 = m_nextColorKey >> 5;
v23 = a1->m_keyPulses.m_bits.m_start;
v24 = a1->m_keyPulses.m_bits.m_finish;
v25 = v22 + 1;
v26 = ((char *)v24 - (char *)v23) >> 3;
v27 = v25 >= v26;
if ( v25 <= v26 )
goto LABEL_24;
goto LABEL_29;
}
LABEL_28:
std::vector::_M_default_append((__int64)&a1->m_keyOpacities, m_nextColorKey - v20);
v23 = a1->m_keyPulses.m_bits.m_start;
v24 = a1->m_keyPulses.m_bits.m_finish;
v25 = ((unsigned __int64)a1->m_nextColorKey >> 5) + 1;
v26 = ((char *)v24 - (char *)v23) >> 3;
v27 = v25 >= v26;
if ( v25 <= v26 )
{
LABEL_24:
if ( !v27 )
a1->m_keyPulses.m_bits.m_finish = &v23[2 * v25];
return;
}
LABEL_29:
v29 = v25 - v26;
if ( v25 != v26 )
{
if ( v29 > ((char *)a1->m_keyPulses.m_bits.m_reserveEnd - (char *)v24) >> 3 )
{
sub_5C9630((__int64)&a1->m_keyPulses, v29);
}
else
{
v30 = v25 - v26;
v31 = v24;
do
{
if ( v31 )
*(_QWORD *)v31 = 0;
--v30;
v31 += 2;
}
while ( v30 );
a1->m_keyPulses.m_bits.m_finish = &v24[2 * v29];
}
}
}