//
// GJChestSprite::switchToState from 0x1403d17e0 to 0x1403d2434 (3156 bytes)
//
// 11 xrefs:
// > FollowRewardPage::init @ 0x14013b5fd
// > FollowRewardPage::switchToOpenedState @ 0x14013d184
// > RewardUnlockLayer::step2 @ 0x1403ced70
// > RewardUnlockLayer::playRewardEffect @ 0x1403cf068
// > GJChestSprite::create @ 0x1403d1670
// > SecretRewardsLayer::generateChestItems @ 0x1403d5e56
// > SecretRewardsLayer::switchToOpenedState @ 0x1403d6f1d
// > SecretLayer3::init @ 0x1403eae5c
// > SecretLayer3::init @ 0x1403eb168
// > SecretLayer4::init @ 0x1403f0a54
// > ??> @ 0x1406d7c94
//
// 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
//
// Hidden C++ exception states: #wind=3
void GJChestSprite::switchToState(GJChestSprite *a1, ChestSpriteState a2, bool a3)
{
float v3; // xmm3_4
int m_chestType; // edx
__int32 v8; // ebx
__int32 v9; // ebx
cocos2d::CCString *v10; // rax
const char *v11; // rax
size_t v12; // r8
const char *v13; // rcx
struct cocos2d::CCSprite *v14; // rax
__int64 v15; // r8
void **v16; // rdx
const char *v17; // rcx
struct cocos2d::CCSprite *v18; // rax
__int64 v19; // r8
void **v20; // rdx
const char *v21; // rcx
struct cocos2d::CCSprite *v22; // rsi
struct cocos2d::CCFadeTo *v23; // rax
struct cocos2d::CCEaseInOut *v24; // rdi
struct cocos2d::CCFadeTo *v25; // rax
struct cocos2d::CCEaseInOut *v26; // rax
struct cocos2d::CCSequence *v27; // rax
struct cocos2d::CCRepeatForever *v28; // rax
cocos2d::ccColor3B *v29; // r8
int v30; // r12d
int v31; // r13d
int v32; // esi
int v33; // r15d
int v34; // kr08_4
float v35; // xmm0_4
__int64 v36; // rdi
__int64 v37; // rax
__int64 v38; // rdi
float v39; // xmm9_4
int v40; // eax
struct cocos2d::CCRotateBy *v41; // rax
struct cocos2d::CCRepeatForever *v42; // rax
cocos2d::ccColor3B *v43; // r8
struct cocos2d::CCSprite *v44; // rdi
float v45; // xmm0_4
cocos2d::CCSprite_vtbl *v46; // rbx
const cocos2d::CCPoint *v47; // rax
int v48; // eax
struct cocos2d::CCRotateBy *v49; // rax
struct cocos2d::CCRepeatForever *v50; // rax
cocos2d::ccColor3B *v51; // r8
struct cocos2d::CCParticleSystemQuad *v52; // rdi
_BOOL8 v53; // rdx
float v54; // xmm0_4
cocos2d::CCParticleSystemQuad_vtbl *v55; // rbx
const cocos2d::CCPoint *v56; // rax
struct cocos2d::CCSprite *v57; // rbx
struct cocos2d::CCSprite *v58; // rbx
double v59; // xmm0_8
struct cocos2d::CCSprite *v60; // rdi
cocos2d::CCSprite_vtbl *v61; // rbx
const cocos2d::CCPoint *v62; // rax
double v63; // xmm0_8
struct cocos2d::CCSprite *v64; // rdi
cocos2d::CCSprite_vtbl *v65; // rbx
const cocos2d::CCPoint *v66; // rax
__int64 v67; // rdx
cocos2d::CCString *v68; // rax
const char *v69; // rax
size_t v70; // r8
const char *v71; // rcx
struct cocos2d::CCSprite *v72; // rax
__int64 v73; // r8
void **v74; // rdx
const char *v75; // rcx
struct cocos2d::CCSprite *v76; // rax
__int64 v77; // r8
void **v78; // rdx
const char *v79; // rcx
struct cocos2d::CCSprite *v80; // rsi
const char *v81; // rcx
struct cocos2d::CCSprite *v82; // rdi
cocos2d::CCSprite_vtbl *v83; // rbx
float *v84; // rax
const cocos2d::CCPoint *v85; // rax
struct cocos2d::CCParticleSystemQuad *v86; // r15
_BOOL8 v87; // rdx
int v88; // ecx
int v89; // edi
int v90; // esi
int v91; // eax
int v92; // ebx
int v93; // r14d
float v94; // xmm0_4
cocos2d::CCParticleSystemQuad_vtbl *v95; // rbx
const cocos2d::CCPoint *v96; // rax
void *v97; // rcx
cocos2d::CCString *v98; // rax
const char *CString; // rax
struct cocos2d::CCSprite *v100; // rax
float v101; // [rsp+28h] [rbp-E0h] BYREF
_WORD v102[2]; // [rsp+2Ch] [rbp-DCh] BYREF
__int64 v103; // [rsp+30h] [rbp-D8h] BYREF
__int64 v104; // [rsp+38h] [rbp-D0h]
__int64 v105; // [rsp+40h] [rbp-C8h]
float v106; // [rsp+48h] [rbp-C0h] BYREF
float v107; // [rsp+4Ch] [rbp-BCh]
float Block; // [rsp+50h] [rbp-B8h]
int Block_4; // [rsp+54h] [rbp-B4h]
void *Block_8[2]; // [rsp+58h] [rbp-B0h] BYREF
__int128 v111; // [rsp+68h] [rbp-A0h]
char v112[24]; // [rsp+78h] [rbp-90h] BYREF
unsigned __int64 v113; // [rsp+90h] [rbp-78h]
char v114[24]; // [rsp+98h] [rbp-70h] BYREF
unsigned __int64 v115; // [rsp+B0h] [rbp-58h]
if ( a1->m_spriteState == a2 )
return;
a1->m_spriteState = a2;
a1->removeAllChildren(a1);
m_chestType = a1->m_chestType;
v8 = a2 - 2;
if ( !v8 )
{
v98 = cocos2d::CCString::createWithFormat("chest_%02d_%02d_001.png", m_chestType, 2);
CString = cocos2d::CCString::getCString(v98);
v100 = cocos2d::CCSprite::createWithSpriteFrameName(CString);
a1->addChild_0(a1, v100, 3);
return;
}
v9 = v8 - 1;
if ( v9 )
{
if ( v9 == 1 )
{
v10 = cocos2d::CCString::createWithFormat("chest_%02d_%02d_001.png", m_chestType, 4);
v11 = cocos2d::CCString::getCString(v10);
*(_OWORD *)Block_8 = 0;
v111 = 0;
v12 = -1;
do
++v12;
while ( v11[v12] );
sub_14003A930(Block_8, v11, v12);
v13 = (const char *)Block_8;
if ( *((_QWORD *)&v111 + 1) > 0xFu )
v13 = (const char *)Block_8[0];
v14 = cocos2d::CCSprite::createWithSpriteFrameName(v13);
a1->addChild_0(a1, v14, 4);
v16 = Block_8;
if ( *((_QWORD *)&v111 + 1) > 0xFu )
v16 = (void **)Block_8[0];
sub_1403CBFE0(v114, v16, v15, "_back_001");
v17 = v114;
if ( v115 > 0xF )
v17 = *(const char **)v114;
v18 = cocos2d::CCSprite::createWithSpriteFrameName(v17);
a1->addChild_0(a1, v18, 0);
if ( !a3 )
{
v20 = Block_8;
if ( *((_QWORD *)&v111 + 1) > 0xFu )
v20 = (void **)Block_8[0];
sub_1403CBFE0(v112, v20, v19, "_glow_001");
v21 = v112;
if ( v113 > 0xF )
v21 = *(const char **)v112;
v22 = cocos2d::CCSprite::createWithSpriteFrameName(v21);
a1->addChild_0(a1, v22, 1);
v104 = 0x100000302LL;
((void (__fastcall *)(cocos2d::CCTextureProtocol *, __int64))v22->setBlendFunc)(
&v22->cocos2d::CCTextureProtocol,
0x100000302LL);
v23 = cocos2d::CCFadeTo::create(1.0, 0xAFu);
v24 = cocos2d::CCEaseInOut::create(v23, 2.0);
v25 = cocos2d::CCFadeTo::create(1.0, 0xFFu);
v26 = cocos2d::CCEaseInOut::create(v25, 2.0);
v27 = cocos2d::CCSequence::create(v24, v26, 0);
v28 = cocos2d::CCRepeatForever::create(v27);
cocos2d::CCNode::runAction((CCLightFlash *)v22, (cocos2d::CCPoint)v28, v29, v3, v101);
LOWORD(v101) = -27136;
BYTE2(v101) = -1;
LOWORD(v103) = -27136;
BYTE2(v103) = -1;
v102[0] = 17459;
LOBYTE(v102[1]) = -103;
v30 = 255;
v31 = 0;
v32 = 255;
v33 = 0;
v34 = a1->m_chestType - 1;
LODWORD(v104) = 0;
switch ( v34 )
{
case 0:
goto LABEL_26;
case 1:
case 4:
BYTE1(v101) = -56;
BYTE1(v103) = 100;
goto LABEL_20;
case 2:
LABEL_20:
LODWORD(v104) = 0;
break;
case 3:
*(_WORD *)((char *)&v101 + 1) = 255;
*(_WORD *)((char *)&v103 + 1) = 13055;
v30 = 0;
v31 = 150;
LODWORD(v104) = 0;
v33 = 255;
break;
case 5:
BYTE1(v101) = -56;
BYTE1(v103) = 100;
qmemcpy(v102, "\n6S", 3);
LODWORD(v104) = 0;
break;
case 6:
*(_WORD *)((char *)&v101 + 1) = 255;
*(_WORD *)((char *)&v103 + 1) = 13055;
qmemcpy(v102, ")Q;", 3);
v31 = 150;
LODWORD(v104) = 100;
v33 = 255;
goto LABEL_27;
case 7:
LOWORD(v101) = 255;
LOWORD(v103) = 255;
v102[0] = 6970;
LOBYTE(v102[1]) = 75;
v31 = 255;
v32 = 150;
LODWORD(v104) = 255;
break;
case 8:
v102[0] = 7463;
LOBYTE(v102[1]) = 44;
LABEL_26:
BYTE2(v101) = 0;
BYTE2(v103) = 0;
v33 = 100;
LODWORD(v104) = 255;
v31 = 255;
LOBYTE(v103) = -1;
LOWORD(v101) = -14081;
LABEL_27:
v30 = 0;
break;
default:
break;
}
v105 = (__int64)cocos2d::CCSprite::createWithSpriteFrameName("shineBurst_001.png");
a1->addChild_0(a1, (cocos2d::CCNode *)v105, 1);
v35 = (**(float (__fastcall ***)(__int64, __int64))(v105 + 344))(v105 + 344, 0x100000302LL);
v36 = *(_QWORD *)v105;
cocos2d::CCPoint::CCPoint(v35, 0.0);
(*(void (__fastcall **)(__int64, __int64))(v36 + 184))(v105, v37);
v38 = v105;
(*(void (__fastcall **)(__int64))(*(_QWORD *)v105 + 160LL))(v105);
(**(void (__fastcall ***)(__int64, float *))(v38 + 320))(v38 + 320, &v101);
if ( (float)((float)rand() / 32767.0) <= 0.5 )
v39 = -1.0;
else
v39 = 1.0;
v40 = rand();
v41 = cocos2d::CCRotateBy::create(
1.0,
(float)((float)((float)((float)((float)v40 / 32767.0) * 0.5) + 0.5) * 180.0) * v39);
v42 = cocos2d::CCRepeatForever::create(v41);
cocos2d::CCNode::runAction((CCLightFlash *)v38, (cocos2d::CCPoint)v42, v43, v3, v101);
v44 = cocos2d::CCSprite::createWithSpriteFrameName("shineBurst_001.png");
a1->addChild_0(a1, v44, 1);
v45 = ((float (__fastcall *)(cocos2d::CCTextureProtocol *, __int64))v44->setBlendFunc)(
&v44->cocos2d::CCTextureProtocol,
0x100000302LL);
v46 = v44->cocos2d::CCNodeRGBA::cocos2d::CCNode::cocos2d::CCObject::cocos2d::CCCopying::__vftable;
cocos2d::CCPoint::CCPoint(v45, 0.0);
v46->setPosition_0(v44, v47);
((void (__fastcall *)(struct cocos2d::CCSprite *))v44->setScale_0)(v44);
v44->setColor(&v44->cocos2d::CCRGBAProtocol, (const cocos2d::ccColor3B *)&v103);
v48 = rand();
v49 = cocos2d::CCRotateBy::create(
1.0,
(float)((float)((float)((float)((float)v48 / 32767.0) * 0.5) + 0.5) * 180.0) * (float)-v39);
v50 = cocos2d::CCRepeatForever::create(v49);
cocos2d::CCNode::runAction((CCLightFlash *)v44, (cocos2d::CCPoint)v50, v51, v3, v101);
v52 = cocos2d::CCParticleSystemQuad::create("chestOpened.plist", 0);
LOBYTE(v53) = 1;
v52->setAutoRemoveOnFinish(v52, v53);
v54 = ((float (__fastcall *)(GJChestSprite *, struct cocos2d::CCParticleSystemQuad *, __int64))a1->addChild_0)(
a1,
v52,
1);
v55 = v52->cocos2d::CCParticleSystem::cocos2d::CCNode::cocos2d::CCObject::cocos2d::CCCopying::__vftable;
cocos2d::CCPoint::CCPoint(v54, 0.0);
v55->setPosition_0(v52, v56);
v106 = (float)v31 / 255.0;
v107 = (float)v32 / 255.0;
Block = (float)v30 / 255.0;
Block_4 = 1065353216;
v52->setStartColor(v52, (const cocos2d::ccColor4F *)&v106);
v106 = (float)(int)v104 / 255.0;
v107 = (float)v33 / 255.0;
Block = (float)v30 / 255.0;
Block_4 = 1065353216;
v52->setEndColor(v52, (const cocos2d::ccColor4F *)&v106);
((void (__fastcall *)(struct cocos2d::CCParticleSystemQuad *))v52->setScale_0)(v52);
cocos2d::CCParticleSystem::resetSystem(v52);
v57 = cocos2d::CCSprite::createWithSpriteFrameName("chest_glow_bg_001.png");
a1->addChild_0(a1, v57, 2);
((void (__fastcall *)(struct cocos2d::CCSprite *))v57->setScale_0)(v57);
v57->setColor(&v57->cocos2d::CCRGBAProtocol, (const cocos2d::ccColor3B *)v102);
v58 = cocos2d::CCSprite::createWithSpriteFrameName("chest_glow_bg_001.png");
cocos2d::CCSprite::setFlipX(v58, 1);
v59 = ((double (__fastcall *)(GJChestSprite *, struct cocos2d::CCSprite *, __int64))a1->addChild_0)(a1, v58, 2);
((void (__fastcall *)(struct cocos2d::CCSprite *))v58->setScale_0)(v58);
v58->setColor(&v58->cocos2d::CCRGBAProtocol, (const cocos2d::ccColor3B *)v102);
v60 = cocos2d::CCSprite::createWithSpriteFrameName("whiteSquare60_001.png");
v61 = v60->cocos2d::CCNodeRGBA::cocos2d::CCNode::cocos2d::CCObject::cocos2d::CCCopying::__vftable;
cocos2d::CCPoint::CCPoint(*(float *)&v59, 0.0);
v61->setPosition_0(v60, v62);
v63 = ((double (__fastcall *)(struct cocos2d::CCSprite *))v60->setScaleX)(v60);
((void (__fastcall *)(struct cocos2d::CCSprite *))v60->setScaleY)(v60);
v60->setColor(&v60->cocos2d::CCRGBAProtocol, (const cocos2d::ccColor3B *)v102);
a1->addChild_0(a1, v60, 2);
v64 = cocos2d::CCSprite::createWithSpriteFrameName("chest_shadow_001.png");
v65 = v64->cocos2d::CCNodeRGBA::cocos2d::CCNode::cocos2d::CCObject::cocos2d::CCCopying::__vftable;
cocos2d::CCPoint::CCPoint(*(float *)&v63, 0.0);
v65->setPosition_0(v64, v66);
a1->addChild_0(a1, v64, 3);
((void (__fastcall *)(struct cocos2d::CCSprite *))v64->setScale_0)(v64);
LOBYTE(v67) = 90;
v64->setOpacity(&v64->cocos2d::CCRGBAProtocol, v67);
sub_14003A830((__int64)v112);
}
sub_14003A830((__int64)v114);
sub_14003A830((__int64)Block_8);
}
return;
}
v68 = cocos2d::CCString::createWithFormat("chest_%02d_%02d_001.png", m_chestType, 3);
v69 = cocos2d::CCString::getCString(v68);
*(_OWORD *)Block_8 = 0;
v111 = 0;
v70 = -1;
do
++v70;
while ( v69[v70] );
sub_14003A930(Block_8, v69, v70);
v71 = (const char *)Block_8;
if ( *((_QWORD *)&v111 + 1) > 0xFu )
v71 = (const char *)Block_8[0];
v72 = cocos2d::CCSprite::createWithSpriteFrameName(v71);
a1->addChild_0(a1, v72, 3);
v74 = Block_8;
if ( *((_QWORD *)&v111 + 1) > 0xFu )
v74 = (void **)Block_8[0];
sub_1403CBFE0(v114, v74, v73, "_back_001");
v75 = v114;
if ( v115 > 0xF )
v75 = *(const char **)v114;
v76 = cocos2d::CCSprite::createWithSpriteFrameName(v75);
a1->addChild_0(a1, v76, 0);
if ( !a3 )
{
v78 = Block_8;
if ( *((_QWORD *)&v111 + 1) > 0xFu )
v78 = (void **)Block_8[0];
sub_1403CBFE0(v112, v78, v77, "_glow_001");
v79 = v112;
if ( v113 > 0xF )
v79 = *(const char **)v112;
v80 = cocos2d::CCSprite::createWithSpriteFrameName(v79);
a1->addChild_0(a1, v80, 1);
v81 = v112;
if ( v113 > 0xF )
v81 = *(const char **)v112;
v82 = cocos2d::CCSprite::createWithSpriteFrameName(v81);
v80->addChild_0(v80, v82, 1);
v83 = v82->cocos2d::CCNodeRGBA::cocos2d::CCNode::cocos2d::CCObject::cocos2d::CCCopying::__vftable;
v80->getContentSize(v80);
v84 = (float *)v80->getContentSize(v80);
cocos2d::CCPoint::CCPoint(0.0, *v84 * 0.5);
v83->setPosition_0(v82, v85);
((void (__fastcall *)(struct cocos2d::CCSprite *))v82->setScaleX)(v82);
v105 = 0x100000302LL;
((void (__fastcall *)(cocos2d::CCTextureProtocol *, __int64))v80->setBlendFunc)(
&v80->cocos2d::CCTextureProtocol,
0x100000302LL);
((void (__fastcall *)(cocos2d::CCTextureProtocol *, __int64))v82->setBlendFunc)(
&v82->cocos2d::CCTextureProtocol,
0x100000302LL);
v86 = cocos2d::CCParticleSystemQuad::create("chestOpen.plist", 0);
LOBYTE(v87) = 1;
v86->setAutoRemoveOnFinish(v86, v87);
a1->addChild_0(a1, v86, 4);
v88 = a1->m_chestType;
v89 = 255;
if ( v88 == 1 )
{
v90 = 255;
v91 = 50;
v92 = 255;
v93 = 0;
LABEL_54:
v89 = 0;
goto LABEL_55;
}
v92 = 0;
v91 = 255;
if ( v88 == 3 )
{
v90 = 0;
v93 = 0;
}
else
{
v90 = 255;
v93 = 255;
if ( v88 == 4 )
{
v90 = 150;
v91 = 0;
goto LABEL_54;
}
}
LABEL_55:
v106 = (float)v90 / 255.0;
v107 = 1.0;
Block = (float)v91 / 255.0;
Block_4 = 1065353216;
v86->setStartColor(v86, (const cocos2d::ccColor4F *)&v106);
v106 = (float)v92 / 255.0;
v107 = (float)v93 / 255.0;
Block = (float)v89 / 255.0;
Block_4 = 1065353216;
v86->setEndColor(v86, (const cocos2d::ccColor4F *)&v106);
v94 = ((float (__fastcall *)(struct cocos2d::CCParticleSystemQuad *))v86->setScale_0)(v86);
v95 = v86->cocos2d::CCParticleSystem::cocos2d::CCNode::cocos2d::CCObject::cocos2d::CCCopying::__vftable;
cocos2d::CCPoint::CCPoint(v94, 0.0);
v95->setPosition_0(v86, v96);
cocos2d::CCParticleSystem::resetSystem(v86);
sub_14003A830((__int64)v112);
}
sub_14003A830((__int64)v114);
if ( *((_QWORD *)&v111 + 1) > 0xFu )
{
v97 = Block_8[0];
if ( (unsigned __int64)(*((_QWORD *)&v111 + 1) + 1LL) >= 0x1000 )
{
v97 = *((void **)Block_8[0] - 1);
if ( (unsigned __int64)((char *)Block_8[0] - (char *)v97 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v97);
}
}