//
// cocos2d::CCSpriteBatchNode::insertChild from 0x100177c00 to 0x100177f41 (833 bytes)
//
// 2 xrefs:
// > cocos2d::CCSpriteBatchNode::insertChild @ 0x100177cfa
// > cocos2d::CCSpriteBatchNode::insertChild @ 0x100177f26
//
// 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 __fastcall cocos2d::CCSpriteBatchNode::insertChild(
cocos2d::CCSpriteBatchNode *a1,
cocos2d::CCSprite *a2,
unsigned int a3)
{
cocos2d::CCSprite **v5; // r15
__int64 v6; // r12
unsigned __int64 i; // r12
cocos2d::CCSprite *v8; // r14
int v9; // eax
unsigned int v10; // eax
int v11; // r12d
unsigned int v12; // r12d
__int128 v13; // xmm0
__int128 v14; // xmm1
__int128 v15; // xmm2
cocos2d::ccArray *data; // r12
unsigned int num; // eax
__int64 v18; // rcx
cocos2d::CCObject **arr; // rdx
unsigned int v20; // esi
int j; // r15d
__int64 v22; // rdx
int v23; // eax
__int64 v24; // rcx
cocos2d::CCSprite **v25; // r15
__int64 v26; // r12
unsigned __int64 k; // r12
cocos2d::CCSprite *v28; // r14
int v29; // eax
unsigned int v30; // eax
cocos2d::ccV3F_C4B_T2F_Quad v31; // [rsp+0h] [rbp-80h] BYREF
((void (__fastcall *)(cocos2d::CCSprite *, cocos2d::CCSpriteBatchNode *))a2->setBatchNode)(a2, a1);
a2->m_uAtlasIndex = a3;
((void (__fastcall *)(cocos2d::CCSprite *, __int64))a2->setDirty)(a2, 1);
if ( a2->m_bDontDraw )
{
if ( ((__int64 (__fastcall *)(cocos2d::CCSprite *))a2->getChildren)(a2) )
{
if ( **(_DWORD **)(((__int64 (__fastcall *)(cocos2d::CCSprite *))a2->getChildren)(a2) + 56) )
{
v5 = *(cocos2d::CCSprite ***)(*(_QWORD *)(((__int64 (__fastcall *)(cocos2d::CCSprite *))a2->getChildren)(a2) + 56)
+ 16LL);
v6 = *(_QWORD *)(*(_QWORD *)(((__int64 (__fastcall *)(cocos2d::CCSprite *))a2->getChildren)(a2) + 56) + 16LL);
for ( i = v6
+ 8LL * **(unsigned int **)(((__int64 (__fastcall *)(cocos2d::CCSprite *))a2->getChildren)(a2) + 56)
- 8; (unsigned __int64)v5 <= i; ++v5 )
{
v8 = *v5;
if ( !*v5 )
break;
v9 = ((__int64 (__fastcall *)(cocos2d::CCSprite *))v8->getZOrder)(*v5);
v10 = cocos2d::CCSpriteBatchNode::atlasIndexForChild(a1, v8, v9);
cocos2d::CCSpriteBatchNode::insertChild(a1, v8, v10);
}
}
}
}
else
{
v11 = ((__int64 (__fastcall *)(cocos2d::CCTextureAtlas *))a1->m_pobTextureAtlas->getTotalQuads)(a1->m_pobTextureAtlas);
if ( v11 == ((unsigned int (__fastcall *)(cocos2d::CCTextureAtlas *))a1->m_pobTextureAtlas->getCapacity)(a1->m_pobTextureAtlas) )
{
v12 = (4
* ((unsigned int (__fastcall *)(cocos2d::CCTextureAtlas *))a1->m_pobTextureAtlas->getCapacity)(a1->m_pobTextureAtlas)
+ 4)
/ 3;
if ( ((unsigned int (__fastcall *)(cocos2d::CCTextureAtlas *))a1->m_pobTextureAtlas->getCapacity)(a1->m_pobTextureAtlas) < v12 )
cocos2d::CCTextureAtlas::resizeCapacity(a1->m_pobTextureAtlas, v12);
}
*(_OWORD *)&v31.br.vertices.z = *(_OWORD *)&a2->m_sQuad.br.vertices.z;
*(_OWORD *)&v31.tr.texCoords.u = *(_OWORD *)&a2->m_sQuad.tr.texCoords.u;
v13 = *(_OWORD *)&a2->m_sQuad.tl.vertices.x;
v14 = *(_OWORD *)&a2->m_sQuad.tl.texCoords.u;
v15 = *(_OWORD *)&a2->m_sQuad.bl.vertices.z;
*(_OWORD *)&v31.tr.vertices.x = *(_OWORD *)&a2->m_sQuad.tr.vertices.x;
*(_OWORD *)&v31.bl.vertices.z = v15;
*(_OWORD *)&v31.tl.texCoords.u = v14;
*(_OWORD *)&v31.tl.vertices.x = v13;
cocos2d::CCTextureAtlas::insertQuad(a1->m_pobTextureAtlas, &v31, a3);
data = a1->m_pobDescendants->data;
sub_100667A40(data, a2, a3);
num = data->num;
LODWORD(v18) = a3 + 1;
if ( a3 + 1 < data->num )
{
arr = data->arr;
v18 = (unsigned int)v18;
v20 = num - a3 - 2;
for ( j = ((_BYTE)num + ~(_BYTE)a3) & 3; j; --j )
++arr[v18++][6].m_uAutoReleaseCount;
if ( v20 >= 3 )
{
v22 = (__int64)&arr[v18 + 3];
v23 = num - v18;
v24 = 0;
do
{
++*(_DWORD *)(*(_QWORD *)(v22 + 8 * v24 - 24) + 360LL);
++*(_DWORD *)(*(_QWORD *)(v22 + 8 * v24 - 16) + 360LL);
++*(_DWORD *)(*(_QWORD *)(v22 + 8 * v24 - 8) + 360LL);
++*(_DWORD *)(*(_QWORD *)(v22 + 8 * v24) + 360LL);
v24 += 4;
}
while ( v23 != (_DWORD)v24 );
}
}
if ( ((__int64 (__fastcall *)(cocos2d::CCSprite *))a2->getChildren)(a2) )
{
if ( **(_DWORD **)(((__int64 (__fastcall *)(cocos2d::CCSprite *))a2->getChildren)(a2) + 56) )
{
v25 = *(cocos2d::CCSprite ***)(*(_QWORD *)(((__int64 (__fastcall *)(cocos2d::CCSprite *))a2->getChildren)(a2)
+ 56)
+ 16LL);
v26 = *(_QWORD *)(*(_QWORD *)(((__int64 (__fastcall *)(cocos2d::CCSprite *))a2->getChildren)(a2) + 56) + 16LL);
for ( k = v26
+ 8LL * **(unsigned int **)(((__int64 (__fastcall *)(cocos2d::CCSprite *))a2->getChildren)(a2) + 56)
- 8; (unsigned __int64)v25 <= k; ++v25 )
{
v28 = *v25;
if ( !*v25 )
break;
v29 = ((__int64 (__fastcall *)(cocos2d::CCSprite *))v28->getZOrder)(*v25);
v30 = cocos2d::CCSpriteBatchNode::atlasIndexForChild(a1, v28, v29);
cocos2d::CCSpriteBatchNode::insertChild(a1, v28, v30);
}
}
}
}
}