//
// GJChestSprite::switchToState from 0x1001c6cbc to 0x1001c78a4 (3048 bytes)
//
// 10 xrefs:
// > RewardUnlockLayer::step2 @ 0x1001c5c80
// > RewardUnlockLayer::playRewardEffect @ 0x1001c5efc
// > GJChestSprite::init @ 0x1001c8160
// > SecretRewardsLayer::switchToOpenedState @ 0x1002e9aa4
// > SecretRewardsLayer::generateChestItems @ 0x1002eb130
// > SecretLayer3::init @ 0x10030ea24
// > SecretLayer3::init @ 0x10030ec48
// > SecretLayer4::init @ 0x1003546f4
// > FollowRewardPage::init @ 0x100425034
// > FollowRewardPage::switchToOpenedState @ 0x100425a1c
//
// 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 GJChestSprite::switchToState(GJChestSprite *a1, ChestSpriteState a2, bool a3)
{
float v6; // s8
cocos2d::CCString *v7; // x0
const char *CString; // x0
cocos2d::CCSprite *v9; // x0
cocos2d::CCString *v10; // x0
char *v11; // x0
void **v12; // x0
cocos2d::CCSprite *v13; // x0
char *v14; // x0
void **v15; // x0
cocos2d::CCSprite *v16; // x0
char *v17; // x0
void **v18; // x0
cocos2d::CCSprite *v19; // x20
void **v20; // x0
cocos2d::CCSprite *v21; // x21
float v22; // s10
__int64 v23; // x0
__n128 v24; // q0
__n128 v25; // q1
cocos2d::CCParticleSystemQuad *v26; // x20
unsigned int v27; // w8
unsigned __int32 v28; // w19
unsigned int v29; // w8
cocos2d::CCString *v30; // x0
char *v31; // x0
void **v32; // x0
cocos2d::CCSprite *v33; // x0
char *v34; // x0
void **v35; // x0
cocos2d::CCSprite *v36; // x0
char *v37; // x0
void **v38; // x0
cocos2d::CCSprite *v39; // x20
cocos2d::CCFadeTo *v40; // x0
cocos2d::CCEaseInOut *v41; // x21
cocos2d::CCFadeTo *v42; // x0
char v43; // w0
__int64 v44; // x1
__int64 v45; // x2
__int64 v46; // x3
__int64 v47; // x4
__int64 v48; // x5
__int64 v49; // x6
__int64 v50; // x7
cocos2d::CCSequence *v51; // x0
cocos2d::CCRepeatForever *v52; // x0
int m_chestType; // w8
unsigned __int32 v54; // w22
unsigned __int32 v55; // w21
int8x8_t v56; // d2
__n128 v57; // q0
__n128 v58; // q1
__int16 v59; // w8
cocos2d::CCSprite *v60; // x20
__n128 v61; // q0
__n128 v62; // q1
float v63; // s9
unsigned int v64; // w0
cocos2d::CCRotateBy *v65; // x0
cocos2d::CCRepeatForever *v66; // x0
cocos2d::CCSprite *v67; // x20
__n128 v68; // q0
__n128 v69; // q1
unsigned int v70; // w0
cocos2d::CCRotateBy *v71; // x0
cocos2d::CCRepeatForever *v72; // x0
cocos2d::CCParticleSystemQuad *v73; // x20
__n128 v74; // q0
__n128 v75; // q1
int8x8_t v76; // d1
float32x2_t v77; // d10
int8x8_t v78; // d1
cocos2d::CCSprite *v79; // x20
cocos2d::CCSprite *v80; // x20
cocos2d::CCSprite *v81; // x20
__n128 v82; // q1
__n128 v83; // q0
cocos2d::CCSprite *v84; // x20
__n128 v85; // q1
__n128 v86; // q0
_WORD v87[2]; // [xsp+1Ch] [xbp-B4h] BYREF
__int16 v88; // [xsp+20h] [xbp-B0h] BYREF
char v89; // [xsp+22h] [xbp-AEh]
__int16 v90; // [xsp+24h] [xbp-ACh] BYREF
char v91; // [xsp+26h] [xbp-AAh]
float32x2_t v92; // [xsp+28h] [xbp-A8h] BYREF
float v93; // [xsp+30h] [xbp-A0h]
int v94; // [xsp+34h] [xbp-9Ch]
void *__p[2]; // [xsp+38h] [xbp-98h] BYREF
char v96; // [xsp+4Fh] [xbp-81h]
void *v97[2]; // [xsp+50h] [xbp-80h] BYREF
char v98; // [xsp+67h] [xbp-69h]
void *v99[2]; // [xsp+68h] [xbp-68h] BYREF
char v100; // [xsp+7Fh] [xbp-51h]
if ( a1->m_spriteState == a2 )
return;
a1->m_spriteState = a2;
((void (__fastcall *)(GJChestSprite *))a1->removeAllChildren)(a1);
if ( a1->m_chestType == 1 )
v6 = 0.8;
else
v6 = 1.0;
if ( a2 != Opened )
{
if ( a2 != Opening )
{
if ( a2 == Closed )
{
v7 = (cocos2d::CCString *)sub_100268F4C("chest_%02d_%02d_001.png", a1->m_chestType, 2);
CString = cocos2d::CCString::getCString(v7);
v9 = cocos2d::CCSprite::createWithSpriteFrameName(CString);
((void (__fastcall *)(GJChestSprite *, cocos2d::CCSprite *, __int64))a1->addChild_0)(a1, v9, 3);
}
return;
}
v10 = (cocos2d::CCString *)sub_100268F4C("chest_%02d_%02d_001.png", a1->m_chestType, 3);
v11 = (char *)cocos2d::CCString::getCString(v10);
sub_100009900(v99, v11);
if ( v100 >= 0 )
v12 = v99;
else
v12 = (void **)v99[0];
v13 = cocos2d::CCSprite::createWithSpriteFrameName((const char *)v12);
((void (__fastcall *)(GJChestSprite *, cocos2d::CCSprite *, __int64))a1->addChild_0)(a1, v13, 3);
if ( v100 >= 0 )
v14 = (char *)v99;
else
v14 = (char *)v99[0];
sub_1001C82BC((__int64 *)v97, v14);
if ( v98 >= 0 )
v15 = v97;
else
v15 = (void **)v97[0];
v16 = cocos2d::CCSprite::createWithSpriteFrameName((const char *)v15);
((void (__fastcall *)(GJChestSprite *, cocos2d::CCSprite *, _QWORD))a1->addChild_0)(a1, v16, 0);
if ( a3 )
goto LABEL_72;
if ( v100 >= 0 )
v17 = (char *)v99;
else
v17 = (char *)v99[0];
sub_1001C82BC((__int64 *)__p, v17);
if ( v96 >= 0 )
v18 = __p;
else
v18 = (void **)__p[0];
v19 = cocos2d::CCSprite::createWithSpriteFrameName((const char *)v18);
((void (__fastcall *)(GJChestSprite *, cocos2d::CCSprite *, __int64))a1->addChild_0)(a1, v19, 1);
if ( v96 >= 0 )
v20 = __p;
else
v20 = (void **)__p[0];
v21 = cocos2d::CCSprite::createWithSpriteFrameName((const char *)v20);
((void (__fastcall *)(cocos2d::CCSprite *, cocos2d::CCSprite *, __int64))v19->addChild_0)(v19, v21, 1);
v22 = *(float *)((__int64 (__fastcall *)(cocos2d::CCSprite *))v19->getContentSize)(v19);
v23 = ((__int64 (__fastcall *)(cocos2d::CCSprite *))v19->getContentSize)(v19);
v24.n128_f32[0] = v22 * 0.5;
v25.n128_f32[0] = *(float *)(v23 + 4) * 0.5;
sub_100022980(v24, v25, &v92);
((void (__fastcall *)(cocos2d::CCSprite *, float32x2_t *))v21->setPosition)(v21, &v92);
((void (__fastcall *)(cocos2d::CCSprite *, float))v21->setScaleX)(v21, 0.8);
((void (__fastcall *)(cocos2d::CCSprite *, __int64))v19->setBlendFunc)(v19, 0x100000302LL);
((void (__fastcall *)(cocos2d::CCSprite *, __int64))v21->setBlendFunc)(v21, 0x100000302LL);
v26 = cocos2d::CCParticleSystemQuad::create("chestOpen.plist", 0);
((void (__fastcall *)(cocos2d::CCParticleSystemQuad *, __int64))v26->setAutoRemoveOnFinish)(v26, 1);
((void (__fastcall *)(GJChestSprite *, cocos2d::CCParticleSystemQuad *, __int64))a1->addChild_0)(a1, v26, 4);
v27 = a1->m_chestType - 1;
if ( v27 >= 4 )
{
v29 = 0xFFFFFF;
v28 = 16776960;
}
else
{
v28 = dword_100639F20[v27];
v29 = dword_100639F30[v27];
}
v92.f32[0] = (float)(unsigned __int8)v29 / 255.0;
v92.i32[1] = 1065353216;
v93 = (float)HIWORD(v29) / 255.0;
v94 = 1065353216;
((void (__fastcall *)(cocos2d::CCParticleSystemQuad *, float32x2_t *))v26->setStartColor)(v26, &v92);
v56.i32[0] = v28;
v56.i32[1] = v28 >> 8;
v92 = vdiv_f32(
vcvt_f32_u32((uint32x2_t)vand_s8(v56, (int8x8_t)0xFF000000FFLL)),
(float32x2_t)vdup_n_s32(0x437F0000u));
v93 = (float)HIWORD(v28) / 255.0;
v94 = 1065353216;
((void (__fastcall *)(cocos2d::CCParticleSystemQuad *, float32x2_t *))v26->setEndColor)(v26, &v92);
v57 = ((__n128 (__fastcall *)(cocos2d::CCParticleSystemQuad *, float))v26->setScale)(v26, v6);
v57.n128_u32[0] = 0;
v58.n128_u32[0] = 0;
sub_100022980(v57, v58, &v92);
((void (__fastcall *)(cocos2d::CCParticleSystemQuad *, float32x2_t *))v26->setPosition)(v26, &v92);
cocos2d::CCParticleSystem::resetSystem(v26);
goto LABEL_70;
}
v30 = (cocos2d::CCString *)sub_100268F4C("chest_%02d_%02d_001.png", a1->m_chestType, 4);
v31 = (char *)cocos2d::CCString::getCString(v30);
sub_100009900(v99, v31);
if ( v100 >= 0 )
v32 = v99;
else
v32 = (void **)v99[0];
v33 = cocos2d::CCSprite::createWithSpriteFrameName((const char *)v32);
((void (__fastcall *)(GJChestSprite *, cocos2d::CCSprite *, __int64))a1->addChild_0)(a1, v33, 4);
if ( v100 >= 0 )
v34 = (char *)v99;
else
v34 = (char *)v99[0];
sub_1001C82BC((__int64 *)v97, v34);
if ( v98 >= 0 )
v35 = v97;
else
v35 = (void **)v97[0];
v36 = cocos2d::CCSprite::createWithSpriteFrameName((const char *)v35);
((void (__fastcall *)(GJChestSprite *, cocos2d::CCSprite *, _QWORD))a1->addChild_0)(a1, v36, 0);
if ( !a3 )
{
if ( v100 >= 0 )
v37 = (char *)v99;
else
v37 = (char *)v99[0];
sub_1001C82BC((__int64 *)__p, v37);
if ( v96 >= 0 )
v38 = __p;
else
v38 = (void **)__p[0];
v39 = cocos2d::CCSprite::createWithSpriteFrameName((const char *)v38);
((void (__fastcall *)(GJChestSprite *, cocos2d::CCSprite *, __int64))a1->addChild_0)(a1, v39, 1);
((void (__fastcall *)(cocos2d::CCSprite *, __int64))v39->setBlendFunc)(v39, 0x100000302LL);
v40 = cocos2d::CCFadeTo::create(1.0, 0xAFu);
v41 = cocos2d::CCEaseInOut::create(v40, 2.0);
v42 = cocos2d::CCFadeTo::create(1.0, 0xFFu);
v43 = (unsigned __int8)cocos2d::CCEaseInOut::create(v42, 2.0);
v51 = sub_10018A494(v41, v44, v45, v46, v47, v48, v49, v50, v43);
v52 = cocos2d::CCRepeatForever::create(v51);
cocos2d::CCNode::runAction(v39, v52);
v91 = -1;
v90 = -27136;
v89 = -1;
v88 = -27136;
LOBYTE(v87[1]) = -103;
v87[0] = 17459;
m_chestType = a1->m_chestType;
v54 = 16776960;
v55 = 16711680;
if ( m_chestType <= 5 )
{
if ( m_chestType > 3 )
{
if ( m_chestType == 4 )
{
v91 = 0;
v55 = 65280;
v90 = -256;
v88 = -256;
v89 = 50;
v54 = 65430;
goto LABEL_66;
}
}
else
{
if ( m_chestType == 1 )
{
v91 = 0;
v90 = -14081;
v89 = 0;
v88 = -26881;
v54 = 0xFFFF;
v55 = 25855;
goto LABEL_66;
}
if ( m_chestType != 2 )
goto LABEL_66;
}
v91 = -1;
v90 = -14336;
v89 = -1;
v88 = 25600;
LABEL_66:
v60 = cocos2d::CCSprite::createWithSpriteFrameName("shineBurst_001.png");
((void (__fastcall *)(GJChestSprite *, cocos2d::CCSprite *, __int64))a1->addChild_0)(a1, v60, 1);
v61 = ((__n128 (__fastcall *)(cocos2d::CCSprite *, __int64))v60->setBlendFunc)(v60, 0x100000302LL);
v61.n128_u32[0] = 0;
v62.n128_u32[0] = -5.0;
sub_100022980(v61, v62, &v92);
((void (__fastcall *)(cocos2d::CCSprite *, float32x2_t *))v60->setPosition)(v60, &v92);
((void (__fastcall *)(cocos2d::CCSprite *, float))v60->setScale)(v60, v6 * 4.0);
((void (__fastcall *)(cocos2d::CCSprite *, __int16 *))v60->setColor)(v60, &v90);
if ( vcvts_n_f32_s32(rand(), 0x1Fu) <= 0.5 )
v63 = -1.0;
else
v63 = 1.0;
v64 = rand();
v65 = cocos2d::CCRotateBy::create_1(
1.0,
v63 * (float)((float)((float)(vcvts_n_f32_s32(v64, 0x1Fu) * 0.5) + 0.5) * 180.0));
v66 = cocos2d::CCRepeatForever::create(v65);
cocos2d::CCNode::runAction(v60, v66);
v67 = cocos2d::CCSprite::createWithSpriteFrameName("shineBurst_001.png");
((void (__fastcall *)(GJChestSprite *, cocos2d::CCSprite *, __int64))a1->addChild_0)(a1, v67, 1);
v68 = ((__n128 (__fastcall *)(cocos2d::CCSprite *, __int64))v67->setBlendFunc)(v67, 0x100000302LL);
v68.n128_u32[0] = 0;
v69.n128_u32[0] = -5.0;
sub_100022980(v68, v69, &v92);
((void (__fastcall *)(cocos2d::CCSprite *, float32x2_t *))v67->setPosition)(v67, &v92);
((void (__fastcall *)(cocos2d::CCSprite *, float))v67->setScale)(v67, v6 * 3.5);
((void (__fastcall *)(cocos2d::CCSprite *, __int16 *))v67->setColor)(v67, &v88);
v70 = rand();
v71 = cocos2d::CCRotateBy::create_1(
1.0,
(float)((float)((float)(vcvts_n_f32_s32(v70, 0x1Fu) * 0.5) + 0.5) * -180.0) * v63);
v72 = cocos2d::CCRepeatForever::create(v71);
cocos2d::CCNode::runAction(v67, v72);
v73 = cocos2d::CCParticleSystemQuad::create("chestOpened.plist", 0);
((void (__fastcall *)(cocos2d::CCParticleSystemQuad *, __int64))v73->setAutoRemoveOnFinish)(v73, 1);
v74 = ((__n128 (__fastcall *)(GJChestSprite *, cocos2d::CCParticleSystemQuad *, __int64))a1->addChild_0)(
a1,
v73,
1);
v74.n128_u32[0] = 0;
v75.n128_u32[0] = 0;
sub_100022980(v74, v75, &v92);
((void (__fastcall *)(cocos2d::CCParticleSystemQuad *, float32x2_t *))v73->setPosition)(v73, &v92);
v76.i32[0] = v54;
v76.i32[1] = v54 >> 8;
v77 = (float32x2_t)vdup_n_s32(0x437F0000u);
v92 = vdiv_f32(vcvt_f32_u32((uint32x2_t)vand_s8(v76, (int8x8_t)0xFF000000FFLL)), v77);
v93 = (float)HIWORD(v54) / 255.0;
v94 = 1065353216;
((void (__fastcall *)(cocos2d::CCParticleSystemQuad *, float32x2_t *))v73->setStartColor)(v73, &v92);
v78.i32[0] = v55;
v78.i32[1] = v55 >> 8;
v92 = vdiv_f32(vcvt_f32_u32((uint32x2_t)vand_s8(v78, (int8x8_t)0xFF000000FFLL)), v77);
v93 = (float)HIWORD(v55) / 255.0;
v94 = 1065353216;
((void (__fastcall *)(cocos2d::CCParticleSystemQuad *, float32x2_t *))v73->setEndColor)(v73, &v92);
((void (__fastcall *)(cocos2d::CCParticleSystemQuad *, float))v73->setScale)(v73, v6);
cocos2d::CCParticleSystem::resetSystem(v73);
v79 = cocos2d::CCSprite::createWithSpriteFrameName("chest_glow_bg_001.png");
((void (__fastcall *)(GJChestSprite *, cocos2d::CCSprite *, __int64))a1->addChild_0)(a1, v79, 2);
((void (__fastcall *)(cocos2d::CCSprite *, float))v79->setScale)(v79, v6);
((void (__fastcall *)(cocos2d::CCSprite *, _WORD *))v79->setColor)(v79, v87);
v80 = cocos2d::CCSprite::createWithSpriteFrameName("chest_glow_bg_001.png");
cocos2d::CCSprite::setFlipX(v80, 1);
((void (__fastcall *)(GJChestSprite *, cocos2d::CCSprite *, __int64))a1->addChild_0)(a1, v80, 2);
((void (__fastcall *)(cocos2d::CCSprite *, float))v80->setScale)(v80, v6);
((void (__fastcall *)(cocos2d::CCSprite *, _WORD *))v80->setColor)(v80, v87);
v81 = cocos2d::CCSprite::createWithSpriteFrameName("whiteSquare60_001.png");
v82.n128_f32[0] = v6 * -52.0;
v83.n128_u32[0] = 0;
sub_100022980(v83, v82, &v92);
((void (__fastcall *)(cocos2d::CCSprite *, float32x2_t *))v81->setPosition)(v81, &v92);
((void (__fastcall *)(cocos2d::CCSprite *, float))v81->setScaleX)(v81, v6 * 5.2);
((void (__fastcall *)(cocos2d::CCSprite *, float))v81->setScaleY)(v81, v6 * 2.2);
((void (__fastcall *)(cocos2d::CCSprite *, _WORD *))v81->setColor)(v81, v87);
((void (__fastcall *)(GJChestSprite *, cocos2d::CCSprite *, __int64))a1->addChild_0)(a1, v81, 2);
v84 = cocos2d::CCSprite::createWithSpriteFrameName("chest_shadow_001.png");
v85.n128_f32[0] = v6 * -48.0;
v86.n128_u32[0] = 0;
sub_100022980(v86, v85, &v92);
((void (__fastcall *)(cocos2d::CCSprite *, float32x2_t *))v84->setPosition)(v84, &v92);
((void (__fastcall *)(GJChestSprite *, cocos2d::CCSprite *, __int64))a1->addChild_0)(a1, v84, 3);
((void (__fastcall *)(cocos2d::CCSprite *, float))v84->setScale)(v84, v6 * 0.95);
((void (__fastcall *)(cocos2d::CCSprite *, __int64))v84->setOpacity)(v84, 90);
LABEL_70:
if ( v96 < 0 )
operator delete(__p[0]);
goto LABEL_72;
}
if ( m_chestType > 7 )
{
if ( m_chestType == 8 )
{
v91 = -1;
v90 = 255;
v89 = -1;
v88 = 255;
LOBYTE(v87[1]) = 75;
v59 = 6970;
v54 = 16750335;
v55 = 16711935;
}
else
{
if ( m_chestType != 9 )
goto LABEL_66;
v91 = 0;
v90 = -14081;
v89 = 0;
v88 = -26881;
LOBYTE(v87[1]) = 44;
v59 = 7463;
v54 = 0xFFFF;
v55 = 25855;
}
}
else
{
if ( m_chestType != 6 )
{
v91 = 0;
v90 = -256;
v88 = -256;
v89 = 50;
qmemcpy(v87, ")Q;", 3);
v54 = 65430;
v55 = 65380;
goto LABEL_66;
}
v91 = -1;
v90 = -14336;
v89 = -1;
v88 = 25600;
LOBYTE(v87[1]) = 83;
v59 = 13834;
}
v87[0] = v59;
goto LABEL_66;
}
LABEL_72:
if ( v98 < 0 )
operator delete(v97[0]);
if ( v100 < 0 )
operator delete(v99[0]);
}