//
// GJChestSprite::switchToState from 0x10021e2a0 to 0x10021ef1f (3199 bytes)
//
// 18 xrefs:
// > GJChestSprite::create @ 0x10021cd07
// > RewardUnlockLayer::step2 @ 0x10021ce10
// > RewardUnlockLayer::playRewardEffect @ 0x10021d100
// > GJChestSprite::init @ 0x10021f88d
// > SecretLayer4::init @ 0x1003b16d2
// > FollowRewardPage::init @ 0x1004203a5
// > FollowRewardPage::init @ 0x1004205f2
// > FollowRewardPage::onSpecialItem @ 0x100420dec
// > FollowRewardPage::switchToOpenedState @ 0x100421014
// > SecretLayer3::init @ 0x1004a464f
// > SecretLayer3::init @ 0x1004a48b2
// > SecretRewardsLayer::init @ 0x100630f91
// > SecretRewardsLayer::init @ 0x1006315dd
// > SecretRewardsLayer::switchToOpenedState @ 0x1006321bd
// > SecretRewardsLayer::onSpecialItem @ 0x100632e25
// > SecretRewardsLayer::generateChestItems @ 0x100634446
// > SecretRewardsLayer::generateChestItems @ 0x10063466c
// > SecretRewardsLayer::onSelectItem @ 0x1006348eb
//
// 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)
{
__m128 v3; // xmm2
size_t v4; // r14
_BOOL8 v6; // rax
double v7; // xmm0_8
cocos2d::CCString *v8; // rax
const char *v9; // rax
cocos2d::CCSprite *v10; // rax
cocos2d::CCString *v11; // rax
const char *v12; // r15
size_t v13; // rax
size_t v14; // r12
char *v15; // r13
cocos2d::CCString *v16; // rax
const char *CString; // r12
size_t v18; // rax
size_t v19; // r15
char *v20; // r13
char *v21; // r15
char *v22; // rdi
cocos2d::CCSprite *v23; // rax
char *v24; // rsi
const char *v25; // rdi
char *v26; // r15
char *v27; // rdi
cocos2d::CCSprite *v28; // rax
char *v29; // rsi
const char *data; // rdi
cocos2d::CCSprite *v31; // rax
const char *v32; // r15
const char *v33; // rdi
cocos2d::CCSprite *v34; // r14
cocos2d::CCSprite *v35; // r15
__int64 v36; // rax
cocos2d::CCParticleSystemQuad *v37; // r14
int v38; // eax
unsigned int v39; // eax
unsigned int v40; // ebx
cocos2d::CCSprite *v41; // rax
const char *v42; // rdi
cocos2d::CCSprite *v43; // r14
cocos2d::CCFadeTo *v44; // rax
unsigned int v45; // r15d
cocos2d::CCFadeTo *v46; // rax
unsigned int v47; // eax
int v48; // ecx
int v49; // r8d
int v50; // r9d
cocos2d::CCActionInterval *v51; // rax
cocos2d::CCRepeatForever *v52; // rax
int m_chestType; // eax
unsigned int v54; // r13d
__m128 v55; // xmm0
__m128 v56; // xmm0
__m128 v57; // xmm1
__m128 v58; // xmm2
cocos2d::CCSprite *v59; // r14
bool v60; // r12
int v61; // eax
__m128 v62; // xmm2
cocos2d::CCRotateBy *v63; // rax
cocos2d::CCRepeatForever *v64; // rax
cocos2d::CCSprite *v65; // r14
int v66; // eax
cocos2d::CCRotateBy *v67; // rax
cocos2d::CCRepeatForever *v68; // rax
cocos2d::CCParticleSystemQuad *v69; // r14
__m128 v70; // xmm0
__m128 v71; // xmm1
__m128 v72; // xmm0
__m128 v73; // xmm1
__m128 v74; // xmm2
cocos2d::CCSprite *v75; // r14
cocos2d::CCSprite *v76; // r14
cocos2d::CCSprite *v77; // r14
cocos2d::CCSprite *v78; // r14
char v79; // [rsp+0h] [rbp-A0h]
float v80; // [rsp+4h] [rbp-9Ch]
std::string v81; // [rsp+8h] [rbp-98h] BYREF
std::string v82; // [rsp+20h] [rbp-80h] BYREF
size_t __dst; // [rsp+38h] [rbp-68h] BYREF
size_t v84; // [rsp+40h] [rbp-60h]
char *__s; // [rsp+48h] [rbp-58h]
__m128 v86; // [rsp+50h] [rbp-50h] BYREF
float v87; // [rsp+64h] [rbp-3Ch]
unsigned int v88; // [rsp+68h] [rbp-38h]
_WORD v89[2]; // [rsp+6Ch] [rbp-34h] BYREF
__int16 v90; // [rsp+70h] [rbp-30h] BYREF
char v91; // [rsp+72h] [rbp-2Eh]
__int16 v92; // [rsp+74h] [rbp-2Ch] BYREF
char v93; // [rsp+76h] [rbp-2Ah]
if ( a1->m_spriteState == a2 )
return;
LODWORD(v4) = a3;
a1->m_spriteState = a2;
((void (__fastcall *)(GJChestSprite *))a1->removeAllChildren)(a1);
v6 = a1->m_chestType == 1;
*(_QWORD *)&v7 = (unsigned int)dword_100817B28[v6];
v87 = *(float *)&dword_100817B28[v6];
if ( a2 == Opened )
{
v16 = (cocos2d::CCString *)sub_1007AB580("chest_%02d_%02d_001.png", v79);
CString = cocos2d::CCString::getCString(v16);
v18 = strlen(CString);
if ( v18 >= 0xFFFFFFFFFFFFFFF8LL )
goto LABEL_74;
v19 = v18;
if ( v18 >= 0x17 )
{
v88 = v4;
v4 = 26;
if ( (v18 | 7) != 0x17 )
v4 = (v18 | 7) + 1;
v20 = (char *)operator new(v4);
__s = v20;
__dst = v4 + 1;
LOBYTE(v4) = v88;
v84 = v19;
}
else
{
LOBYTE(__dst) = 2 * v18;
v20 = (char *)&__dst + 1;
if ( !v18 )
goto LABEL_29;
}
memmove(v20, CString, v19);
LABEL_29:
v20[v19] = 0;
v26 = (char *)&__dst + 1;
v27 = (char *)&__dst + 1;
if ( (__dst & 1) != 0 )
v27 = __s;
v28 = cocos2d::CCSprite::createWithSpriteFrameName(v27);
((void (__fastcall *)(GJChestSprite *, cocos2d::CCSprite *, __int64))a1->addChild_0)(a1, v28, 4);
v29 = (char *)&__dst + 1;
if ( (__dst & 1) != 0 )
v29 = __s;
sub_10021FA70(&v81, v29, "_back_001");
if ( (*(_BYTE *)&v81.__r_.__value_.__s.0 & 1) != 0 )
data = v81.__r_.__value_.__l.__data_;
else
data = v81.__r_.__value_.__s.__data_;
v41 = cocos2d::CCSprite::createWithSpriteFrameName(data);
((void (__fastcall *)(GJChestSprite *, cocos2d::CCSprite *, _QWORD))a1->addChild_0)(a1, v41, 0);
if ( (_BYTE)v4 )
goto LABEL_70;
if ( (__dst & 1) != 0 )
v26 = __s;
sub_10021FA70(&v82, v26, "_glow_001");
if ( (*(_BYTE *)&v82.__r_.__value_.__s.0 & 1) != 0 )
v42 = v82.__r_.__value_.__l.__data_;
else
v42 = v82.__r_.__value_.__s.__data_;
v43 = cocos2d::CCSprite::createWithSpriteFrameName(v42);
((void (__fastcall *)(GJChestSprite *, cocos2d::CCSprite *, __int64))a1->addChild_0)(a1, v43, 1);
((void (__fastcall *)(cocos2d::CCSprite *, __int64))v43->setBlendFunc)(v43, 0x100000302LL);
v44 = cocos2d::CCFadeTo::create(1.0, 0xAFu);
v45 = (unsigned int)cocos2d::CCEaseInOut::create(v44, 2.0);
v46 = cocos2d::CCFadeTo::create(1.0, 0xFFu);
v47 = (unsigned int)cocos2d::CCEaseInOut::create(v46, 2.0);
v51 = (cocos2d::CCActionInterval *)sub_1003B5760(v45, v47, 0, v48, v49, v50);
v52 = cocos2d::CCRepeatForever::create(v51);
cocos2d::CCNode::runAction(v43, v52);
v91 = -1;
v90 = -27136;
v93 = -1;
v92 = -27136;
LOBYTE(v89[1]) = -103;
v89[0] = 17459;
m_chestType = a1->m_chestType;
v54 = 16776960;
*(float *)&v88 = 2.3418052e-38;
switch ( m_chestType )
{
case 1:
v91 = 0;
v90 = -14081;
v93 = 0;
v92 = -26881;
goto LABEL_64;
case 2:
case 5:
v91 = -1;
v90 = -14336;
v93 = -1;
v92 = 25600;
break;
case 4:
v91 = 0;
v90 = -256;
v93 = 50;
v92 = -256;
v54 = 65430;
v88 = 65280;
break;
case 6:
v91 = -1;
v90 = -14336;
v93 = -1;
v92 = 25600;
qmemcpy(v89, "\n6S", 3);
break;
case 7:
v91 = 0;
v90 = -256;
v93 = 50;
v92 = -256;
qmemcpy(v89, ")Q;", 3);
v54 = 65430;
v88 = 65380;
break;
case 8:
v91 = -1;
v90 = 255;
v93 = -1;
v92 = 255;
LOBYTE(v89[1]) = 75;
v89[0] = 6970;
v54 = 16750335;
*(float *)&v88 = 2.3418409e-38;
break;
case 9:
v91 = 0;
v90 = -14081;
v93 = 0;
v92 = -26881;
LOBYTE(v89[1]) = 44;
v89[0] = 7463;
LABEL_64:
v54 = 0xFFFF;
v88 = 25855;
break;
default:
break;
}
v59 = cocos2d::CCSprite::createWithSpriteFrameName("shineBurst_001.png");
((void (__fastcall *)(GJChestSprite *, cocos2d::CCSprite *, __int64))a1->addChild_0)(a1, v59, 1);
((void (__fastcall *)(cocos2d::CCSprite *, __int64))v59->setBlendFunc)(v59, 0x100000302LL);
sub_10028CBE0(&v86, 0.0, -5.0);
((void (__fastcall *)(cocos2d::CCSprite *, __m128 *))v59->setPosition)(v59, &v86);
((void (__fastcall *)(cocos2d::CCSprite *, float))v59->setScale)(v59, 4.0 * v87);
((void (__fastcall *)(cocos2d::CCSprite *, __int16 *))v59->setColor)(v59, &v90);
v60 = (float)((float)rand() * 4.6566129e-10) > 0.5;
v61 = rand();
v62 = (__m128)0x3F000000u;
v80 = flt_100817B30[v60];
v63 = cocos2d::CCRotateBy::create_1(
1.0,
(float)((float)((float)((float)((float)v61 * 4.6566129e-10) * 0.5) + 0.5) * 180.0) * v80);
v64 = cocos2d::CCRepeatForever::create(v63);
cocos2d::CCNode::runAction(v59, v64);
v65 = cocos2d::CCSprite::createWithSpriteFrameName("shineBurst_001.png");
((void (__fastcall *)(GJChestSprite *, cocos2d::CCSprite *, __int64))a1->addChild_0)(a1, v65, 1);
((void (__fastcall *)(cocos2d::CCSprite *, __int64))v65->setBlendFunc)(v65, 0x100000302LL);
sub_10028CBE0(&v86, 0.0, -5.0);
((void (__fastcall *)(cocos2d::CCSprite *, __m128 *))v65->setPosition)(v65, &v86);
((void (__fastcall *)(cocos2d::CCSprite *, float))v65->setScale)(v65, 3.5 * v87);
((void (__fastcall *)(cocos2d::CCSprite *, __int16 *))v65->setColor)(v65, &v92);
v66 = rand();
v67 = cocos2d::CCRotateBy::create_1(
1.0,
(float)((float)((float)((float)((float)v66 * 4.6566129e-10) * 0.5) + 0.5) * -180.0) * v80);
v68 = cocos2d::CCRepeatForever::create(v67);
cocos2d::CCNode::runAction(v65, v68);
v69 = cocos2d::CCParticleSystemQuad::create("chestOpened.plist", 0);
((void (__fastcall *)(cocos2d::CCParticleSystemQuad *, __int64))v69->setAutoRemoveOnFinish)(v69, 1);
((void (__fastcall *)(GJChestSprite *, cocos2d::CCParticleSystemQuad *, __int64))a1->addChild_0)(a1, v69, 1);
sub_10028CBE0(&v86, 0.0, 0.0);
((void (__fastcall *)(cocos2d::CCParticleSystemQuad *, __m128 *))v69->setPosition)(v69, &v86);
v70 = 0;
v71 = 0;
v70.f32[0] = (float)(unsigned __int8)v54 / 255.0;
v71.f32[0] = (float)BYTE1(v54) / 255.0;
v62.f32[0] = (float)HIWORD(v54) / 255.0;
v86 = _mm_movelh_ps(_mm_insert_ps(v70, v71, 16), _mm_blend_ps(v62, (__m128)xmmword_1008150D0, 14));
((void (__fastcall *)(cocos2d::CCParticleSystemQuad *, __m128 *))v69->setStartColor)(v69, &v86);
v72 = 0;
v73 = 0;
v72.f32[0] = (float)(unsigned __int8)v88 / 255.0;
v74 = 0;
v73.f32[0] = (float)BYTE1(v88) / 255.0;
v74.f32[0] = (float)HIWORD(v88) / 255.0;
v86 = _mm_movelh_ps(_mm_insert_ps(v72, v73, 16), _mm_blend_ps(v74, (__m128)xmmword_1008150D0, 14));
((void (__fastcall *)(cocos2d::CCParticleSystemQuad *, __m128 *))v69->setEndColor)(v69, &v86);
((void (__fastcall *)(cocos2d::CCParticleSystemQuad *, float))v69->setScale)(v69, v87);
cocos2d::CCParticleSystem::resetSystem(v69);
v75 = cocos2d::CCSprite::createWithSpriteFrameName("chest_glow_bg_001.png");
((void (__fastcall *)(GJChestSprite *, cocos2d::CCSprite *, __int64))a1->addChild_0)(a1, v75, 2);
((void (__fastcall *)(cocos2d::CCSprite *, float))v75->setScale)(v75, v87);
((void (__fastcall *)(cocos2d::CCSprite *, _WORD *))v75->setColor)(v75, v89);
v76 = cocos2d::CCSprite::createWithSpriteFrameName("chest_glow_bg_001.png");
cocos2d::CCSprite::setFlipX(v76, 1);
((void (__fastcall *)(GJChestSprite *, cocos2d::CCSprite *, __int64))a1->addChild_0)(a1, v76, 2);
((void (__fastcall *)(cocos2d::CCSprite *, float))v76->setScale)(v76, v87);
((void (__fastcall *)(cocos2d::CCSprite *, _WORD *))v76->setColor)(v76, v89);
v77 = cocos2d::CCSprite::createWithSpriteFrameName("whiteSquare60_001.png");
sub_10028CBE0(&v86, 0.0, -52.0 * v87);
((void (__fastcall *)(cocos2d::CCSprite *, __m128 *))v77->setPosition)(v77, &v86);
((void (__fastcall *)(cocos2d::CCSprite *, float))v77->setScaleX)(v77, 5.1999998 * v87);
((void (__fastcall *)(cocos2d::CCSprite *, float))v77->setScaleY)(v77, 2.2 * v87);
((void (__fastcall *)(cocos2d::CCSprite *, _WORD *))v77->setColor)(v77, v89);
((void (__fastcall *)(GJChestSprite *, cocos2d::CCSprite *, __int64))a1->addChild_0)(a1, v77, 2);
v78 = cocos2d::CCSprite::createWithSpriteFrameName("chest_shadow_001.png");
sub_10028CBE0(&v86, 0.0, -48.0 * v87);
((void (__fastcall *)(cocos2d::CCSprite *, __m128 *))v78->setPosition)(v78, &v86);
((void (__fastcall *)(GJChestSprite *, cocos2d::CCSprite *, __int64))a1->addChild_0)(a1, v78, 3);
((void (__fastcall *)(cocos2d::CCSprite *, float))v78->setScale)(v78, v87 * 0.94999999);
((void (__fastcall *)(cocos2d::CCSprite *, __int64))v78->setOpacity)(v78, 90);
goto LABEL_68;
}
if ( a2 != Opening )
{
if ( a2 == Closed )
{
v8 = (cocos2d::CCString *)sub_1007AB580("chest_%02d_%02d_001.png", v79);
v9 = cocos2d::CCString::getCString(v8);
v10 = cocos2d::CCSprite::createWithSpriteFrameName(v9);
((void (__fastcall *)(GJChestSprite *, cocos2d::CCSprite *, __int64))a1->addChild_0)(a1, v10, 3);
}
return;
}
v11 = (cocos2d::CCString *)sub_1007AB580("chest_%02d_%02d_001.png", v79);
v12 = cocos2d::CCString::getCString(v11);
v13 = strlen(v12);
if ( v13 >= 0xFFFFFFFFFFFFFFF8LL )
LABEL_74:
sub_100006BF0(v7);
v14 = v13;
if ( v13 >= 0x17 )
{
v88 = v4;
v4 = 26;
if ( (v13 | 7) != 0x17 )
v4 = (v13 | 7) + 1;
v15 = (char *)operator new(v4);
__s = v15;
__dst = v4 + 1;
LOBYTE(v4) = v88;
v84 = v14;
}
else
{
LOBYTE(__dst) = 2 * v13;
v15 = (char *)&__dst + 1;
if ( !v13 )
goto LABEL_19;
}
memmove(v15, v12, v14);
LABEL_19:
v21 = (char *)&__dst + 1;
v15[v14] = 0;
v22 = (char *)&__dst + 1;
if ( (__dst & 1) != 0 )
v22 = __s;
v23 = cocos2d::CCSprite::createWithSpriteFrameName(v22);
((void (__fastcall *)(GJChestSprite *, cocos2d::CCSprite *, __int64))a1->addChild_0)(a1, v23, 3);
v24 = (char *)&__dst + 1;
if ( (__dst & 1) != 0 )
v24 = __s;
sub_10021FA70(&v81, v24, "_back_001");
if ( (*(_BYTE *)&v81.__r_.__value_.__s.0 & 1) != 0 )
v25 = v81.__r_.__value_.__l.__data_;
else
v25 = v81.__r_.__value_.__s.__data_;
v31 = cocos2d::CCSprite::createWithSpriteFrameName(v25);
((void (__fastcall *)(GJChestSprite *, cocos2d::CCSprite *, _QWORD))a1->addChild_0)(a1, v31, 0);
if ( (_BYTE)v4 )
goto LABEL_70;
if ( (__dst & 1) != 0 )
v21 = __s;
sub_10021FA70(&v82, v21, "_glow_001");
v32 = v82.__r_.__value_.__s.__data_;
v33 = v82.__r_.__value_.__s.__data_;
if ( (*(_BYTE *)&v82.__r_.__value_.__s.0 & 1) != 0 )
v33 = v82.__r_.__value_.__l.__data_;
v34 = cocos2d::CCSprite::createWithSpriteFrameName(v33);
((void (__fastcall *)(GJChestSprite *, cocos2d::CCSprite *, __int64))a1->addChild_0)(a1, v34, 1);
if ( (*(_BYTE *)&v82.__r_.__value_.__s.0 & 1) != 0 )
v32 = v82.__r_.__value_.__l.__data_;
v35 = cocos2d::CCSprite::createWithSpriteFrameName(v32);
((void (__fastcall *)(cocos2d::CCSprite *, cocos2d::CCSprite *, __int64))v34->addChild_0)(v34, v35, 1);
v88 = *(unsigned int *)((__int64 (__fastcall *)(cocos2d::CCSprite *))v34->getContentSize)(v34);
v36 = ((__int64 (__fastcall *)(cocos2d::CCSprite *))v34->getContentSize)(v34);
sub_10028CBE0(&v86, *(float *)&v88 * 0.5, 0.5 * *(float *)(v36 + 4));
((void (__fastcall *)(cocos2d::CCSprite *, __m128 *))v35->setPosition)(v35, &v86);
((void (__fastcall *)(cocos2d::CCSprite *, float))v35->setScaleX)(v35, 0.80000001);
((void (__fastcall *)(cocos2d::CCSprite *, __int64))v34->setBlendFunc)(v34, 0x100000302LL);
((void (__fastcall *)(cocos2d::CCSprite *, __int64))v35->setBlendFunc)(v35, 0x100000302LL);
v37 = cocos2d::CCParticleSystemQuad::create("chestOpen.plist", 0);
((void (__fastcall *)(cocos2d::CCParticleSystemQuad *, __int64))v37->setAutoRemoveOnFinish)(v37, 1);
((void (__fastcall *)(GJChestSprite *, cocos2d::CCParticleSystemQuad *, __int64))a1->addChild_0)(a1, v37, 4);
v38 = a1->m_chestType;
switch ( v38 )
{
case 4:
v39 = 65430;
v40 = 65280;
break;
case 3:
v39 = 16776960;
v40 = 16711680;
break;
case 1:
v39 = 3342335;
v40 = 255;
break;
default:
v39 = 0xFFFFFF;
v40 = 16776960;
break;
}
v55 = 0;
v55.f32[0] = (float)(unsigned __int8)v39 / 255.0;
v3.f32[0] = (float)HIWORD(v39) / 255.0;
v86 = _mm_movelh_ps(_mm_blend_ps(v55, (__m128)xmmword_1008150D0, 14), _mm_blend_ps(v3, (__m128)xmmword_1008150D0, 14));
((void (__fastcall *)(cocos2d::CCParticleSystemQuad *, __m128 *))v37->setStartColor)(v37, &v86);
v56 = 0;
v57 = 0;
v56.f32[0] = (float)(unsigned __int8)v40 / 255.0;
v58 = 0;
v57.f32[0] = (float)BYTE1(v40) / 255.0;
v58.f32[0] = (float)HIWORD(v40) / 255.0;
v86 = _mm_movelh_ps(_mm_insert_ps(v56, v57, 16), _mm_blend_ps(v58, (__m128)xmmword_1008150D0, 14));
((void (__fastcall *)(cocos2d::CCParticleSystemQuad *, __m128 *))v37->setEndColor)(v37, &v86);
((void (__fastcall *)(cocos2d::CCParticleSystemQuad *, float))v37->setScale)(v37, v87);
sub_10028CBE0(&v86, 0.0, 0.0);
((void (__fastcall *)(cocos2d::CCParticleSystemQuad *, __m128 *))v37->setPosition)(v37, &v86);
cocos2d::CCParticleSystem::resetSystem(v37);
LABEL_68:
if ( (*(_BYTE *)&v82.__r_.__value_.__s.0 & 1) != 0 )
operator delete(v82.__r_.__value_.__l.__data_);
LABEL_70:
if ( (*(_BYTE *)&v81.__r_.__value_.__s.0 & 1) != 0 )
operator delete(v81.__r_.__value_.__l.__data_);
if ( (__dst & 1) != 0 )
operator delete(__s);
}