//
// cocos2d::CCParticleSystemQuad::initWithTotalParticles from 0x100602090 to 0x1006023e6 (854 bytes)
//
// 23 xrefs:
// > cocos2d::CCParticleFire::initWithTotalParticles @ 0x100485042
// > cocos2d::CCParticleFireworks::initWithTotalParticles @ 0x100485392
// > cocos2d::CCParticleSun::initWithTotalParticles @ 0x100485602
// > cocos2d::CCParticleGalaxy::initWithTotalParticles @ 0x1004858b2
// > cocos2d::CCParticleFlower::initWithTotalParticles @ 0x100485b92
// > cocos2d::CCParticleMeteor::initWithTotalParticles @ 0x100485e82
// > cocos2d::CCParticleSpiral::initWithTotalParticles @ 0x100486172
// > cocos2d::CCParticleExplosion::initWithTotalParticles @ 0x100486442
// > cocos2d::CCParticleSmoke::initWithTotalParticles @ 0x100486712
// > cocos2d::CCParticleSnow::initWithTotalParticles @ 0x1004869e2
// > cocos2d::CCParticleRain::initWithTotalParticles @ 0x100486cd2
// > ??> @ 0x10093da00
// > ??> @ 0x10093e0c0
// > ??> @ 0x10093e780
// > ??> @ 0x10093ee40
// > ??> @ 0x10093f500
// > ??> @ 0x10093fbc0
// > ??> @ 0x100940280
// > ??> @ 0x100940940
// > ??> @ 0x100941000
// > ??> @ 0x1009416c0
// > ??> @ 0x100941d80
// > ??> @ 0x10097e8a0
//
// 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
//
bool __fastcall cocos2d::CCParticleSystemQuad::initWithTotalParticles(
cocos2d::CCParticleSystemQuad *a1,
unsigned int a2,
bool a3)
{
__int64 m_uTotalParticles; // rcx
GLushort *m_pIndices; // rsi
__int64 v6; // rdx
__int64 v7; // rcx
int v8; // eax
int v9; // edx
cocos2d::CCShaderCache *v10; // rax
cocos2d::CCGLProgram *v11; // rax
__int64 v13; // rax
__m128i v14; // xmm0
__int64 v15; // rdi
__m128i v16; // xmm3
__m128i v17; // xmm4
__m128i v18; // xmm5
__m128i v19; // xmm9
__m128i v20; // xmm6
__m128i v21; // xmm7
__m128i v22; // xmm11
__m128i v23; // xmm10
__m128i v24; // xmm5
__m128i v25; // xmm2
__int64 v26; // r8
if ( cocos2d::CCParticleSystem::initWithTotalParticles(a1, a2, a3) )
{
if ( cocos2d::CCParticleSystemQuad::allocMemory(a1) )
{
m_uTotalParticles = a1->m_uTotalParticles;
if ( a1->m_uTotalParticles )
{
m_pIndices = a1->m_pIndices;
if ( (unsigned int)m_uTotalParticles >= 0x20 )
{
v6 = 0;
if ( (unsigned int)(6 * (m_uTotalParticles - 1)) <= 0xFFFFFFFB && is_mul_ok(6u, m_uTotalParticles - 1) )
{
v13 = 3 * (4 * m_uTotalParticles - 4);
if ( (GLushort *)((char *)m_pIndices + v13 + 8) >= m_pIndices + 4
&& (GLushort *)((char *)m_pIndices + v13 + 6) >= m_pIndices + 3
&& (GLushort *)((char *)m_pIndices + v13 + 10) >= m_pIndices + 5
&& (GLushort *)((char *)m_pIndices + v13 + 4) >= m_pIndices + 2
&& (GLushort *)((char *)m_pIndices + v13 + 2) >= m_pIndices + 1
&& (GLushort *)((char *)m_pIndices + v13) >= m_pIndices )
{
v6 = (unsigned int)m_uTotalParticles & 0xFFFFFFF8;
v14 = _mm_cvtepi8_epi16((__m64)0x706050403020100LL);
v15 = 0;
v16 = _mm_cvtepi8_epi16((__m64)0x303030303030303LL);
v17 = _mm_cvtepi8_epi16((__m64)0x808080808080808LL);
do
{
v18 = _mm_slli_epi16(v14, 2u);
v19 = _mm_or_si128(v18, (__m128i)xmmword_10081D520);
v20 = _mm_or_si128(v18, (__m128i)xmmword_10081D530);
v21 = _mm_or_si128(v18, v16);
v22 = _mm_unpacklo_epi16(v20, v21);
v23 = _mm_unpacklo_epi16(v18, v19);
v24 = _mm_unpackhi_epi16(v18, v19);
v25 = _mm_unpackhi_epi16(v20, v21);
v26 = (unsigned int)v15 & 0xFFFFFFF0;
*(__m128i *)&m_pIndices[v26 + 40] = _mm_blend_epi16(
_mm_shuffle_epi32(_mm_shufflehi_epi16(v19, 232), 230),
_mm_blend_epi16(
_mm_shuffle_epi32(_mm_shufflehi_epi16(v20, 246), 230),
_mm_unpackhi_epi64(v24, _mm_shuffle_epi32(v25, 250)),
60),
125);
*(__m128i *)&m_pIndices[v26 + 32] = _mm_blend_epi16(
_mm_shuffle_epi32(v19, 250),
_mm_blend_epi16(
_mm_srli_si128(v20, 6),
_mm_blend_epi16(_mm_shuffle_epi32(v25, 165), v24, 48),
243),
247);
*(__m128i *)&m_pIndices[v26 + 24] = _mm_blend_epi16(
_mm_slli_epi32(v19, 0x10u),
_mm_blend_epi16(
_mm_blend_epi16(
_mm_shuffle_epi32(v24, 68),
_mm_shuffle_epi32(v25, 80),
12),
v20,
48),
223);
*(__m128i *)&m_pIndices[v26 + 16] = _mm_blend_epi16(
_mm_shuffle_epi32(_mm_shufflelo_epi16(v19, 232), 100),
_mm_blend_epi16(
_mm_shuffle_epi32(_mm_shufflelo_epi16(v20, 246), 100),
_mm_unpackhi_epi64(v23, _mm_shuffle_epi32(v22, 250)),
60),
125);
*(__m128i *)&m_pIndices[v26 + 8] = _mm_blend_epi16(
_mm_shuffle_epi32(v19, 80),
_mm_blend_epi16(
_mm_cvtepu16_epi32(v20),
_mm_blend_epi16(_mm_shuffle_epi32(v22, 165), v23, 48),
243),
247);
*(__m128i *)&m_pIndices[v26] = _mm_blend_epi16(
_mm_slli_si128(v19, 10),
_mm_blend_epi16(
_mm_shuffle_epi32(v20, 68),
_mm_blend_epi16(
_mm_shuffle_epi32(v23, 68),
_mm_shuffle_epi32(v22, 80),
12),
207),
223);
v14 = _mm_add_epi16(v14, v17);
v15 += 48;
}
while ( 48LL * ((unsigned int)m_uTotalParticles >> 3) != v15 );
if ( (_DWORD)v6 == (_DWORD)m_uTotalParticles )
goto LABEL_8;
}
}
}
else
{
v6 = 0;
}
v7 = m_uTotalParticles - v6;
v8 = 4 * v6;
v9 = 6 * v6 + 5;
do
{
m_pIndices[v9 - 5] = v8;
m_pIndices[v9 - 4] = v8 + 1;
m_pIndices[v9 - 3] = v8 + 2;
m_pIndices[v9] = v8 + 1;
m_pIndices[v9 - 1] = v8 + 2;
m_pIndices[v9 - 2] = v8 + 3;
v8 += 4;
v9 += 6;
--v7;
}
while ( v7 );
}
LABEL_8:
cocos2d::CCParticleSystemQuad::setupVBOandVAO(a1);
v10 = cocos2d::CCShaderCache::sharedShaderCache();
v11 = cocos2d::CCShaderCache::programForKey(v10, "ShaderPositionTextureColor");
((void (__fastcall *)(cocos2d::CCParticleSystemQuad *, cocos2d::CCGLProgram *))a1->setShaderProgram)(a1, v11);
return 1;
}
cocos2d::CCObject::release(a1);
}
return 0;
}