//
// PurchaseItemPopup::init from 0x1402aec80 to 0x1402afb30 (3760 bytes)
//
// 2 xrefs:
// > PurchaseItemPopup::create @ 0x1402aec3f
// > ??> @ 0x1406d22a0
//
// 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=10
bool PurchaseItemPopup::init(PurchaseItemPopup *a1, GJStoreItem *a2)
{
bool result; // al
_BOOL8 v5; // rdx
__int64 v6; // rcx
__int64 v7; // rax
cocos2d::CCTouchDispatcher *v8; // rax
_BOOL8 v9; // rdx
__int64 v10; // rcx
cocos2d::CCDirector *v11; // rax
cocos2d::CCLayer *v12; // rax
struct cocos2d::CCRect *v13; // rax
struct cocos2d::extension::CCScale9Sprite *v14; // rdi
float v15; // xmm7_4
cocos2d::extension::CCScale9Sprite_vtbl *v16; // rbx
const cocos2d::CCSize *v17; // rax
float v18; // xmm0_4
cocos2d::extension::CCScale9Sprite_vtbl *v19; // rbx
double v20; // xmm0_8
const cocos2d::CCPoint *v21; // rax
struct cocos2d::CCLabelBMFont *v22; // rdi
cocos2d::CCLabelBMFont_vtbl *v23; // rbx
const cocos2d::CCPoint *v24; // rax
GJStoreItem *m_storeItem; // rax
int v26; // r12d
float width; // r15d
cocos2d::ccColor3B *v28; // r9
GJItemIcon *StoreItem; // rdi
float v30; // xmm0_4
GJItemIcon_vtbl *v31; // rbx
const cocos2d::CCPoint *v32; // rax
__int64 v33; // rdx
__int64 v34; // rcx
__int64 v35; // r8
__int64 v36; // r9
void **v37; // rsi
__int64 v38; // r13
size_t v39; // rdi
unsigned __int64 v40; // rcx
size_t v41; // rbx
void **v42; // r12
size_t v43; // r15
unsigned __int64 v44; // rbx
__int128 *v45; // rsi
void *v46; // rcx
const char *v47; // rdx
size_t v48; // r8
void **v49; // r9
__m128i *v50; // r8
void **v51; // rdx
cocos2d::CCString *v52; // rax
char *CString; // rax
size_t v54; // r8
cocos2d::CCString *v55; // rax
void **v56; // rdx
size_t v57; // r8
const struct cocos2d::CCPoint *v58; // rax
char *v59; // rdi
float v60; // xmm0_4
__int64 v61; // rbx
double v62; // xmm0_8
__int64 v63; // rax
__int64 v64; // rcx
cocos2d::CCMenu *v65; // rax
__int64 v66; // rcx
cocos2d::CCArray *v67; // rdi
ButtonSprite *v68; // rbx
CCMenuItemSpriteExtra *v69; // rbx
ButtonSprite *v70; // rbx
CCMenuItemSpriteExtra *v71; // rbx
struct cocos2d::CCPoint v72; // rax
unsigned __int64 v73; // rbx
unsigned __int64 v74; // r15
unsigned __int64 v75; // rax
unsigned __int64 v76; // rcx
char *v77; // rsi
void **v78; // rdi
__int64 v79; // rax
__int64 *v80; // rdi
float v81; // xmm0_4
__int64 v82; // rbx
struct cocos2d::CCPoint v83; // rax
char *v84; // rax
void *v85; // rcx
void *v86; // rcx
void *v87; // rcx
char v88; // [rsp+58h] [rbp-B0h]
int v89; // [rsp+5Ch] [rbp-ACh] BYREF
float v90; // [rsp+60h] [rbp-A8h]
cocos2d::CCSize v91; // [rsp+68h] [rbp-A0h] BYREF
GJStoreItem *v92; // [rsp+70h] [rbp-98h] BYREF
cocos2d::CCRect v93; // [rsp+78h] [rbp-90h] BYREF
char v94[32]; // [rsp+88h] [rbp-80h] BYREF
void *v95[2]; // [rsp+A8h] [rbp-60h] BYREF
__int128 v96; // [rsp+B8h] [rbp-50h]
__int128 v97; // [rsp+C8h] [rbp-40h] BYREF
__int128 v98; // [rsp+D8h] [rbp-30h]
void *Block[2]; // [rsp+E8h] [rbp-20h] BYREF
__int64 v100; // [rsp+F8h] [rbp-10h]
__int64 v101; // [rsp+100h] [rbp-8h]
void *v102[2]; // [rsp+108h] [rbp+0h] BYREF
__int64 v103; // [rsp+118h] [rbp+10h]
unsigned __int64 v104; // [rsp+120h] [rbp+18h]
void *v105[2]; // [rsp+128h] [rbp+20h] BYREF
__int64 v106; // [rsp+138h] [rbp+30h]
unsigned __int64 v107; // [rsp+140h] [rbp+38h]
__m128i v108; // [rsp+148h] [rbp+40h] BYREF
unsigned __int64 v109; // [rsp+160h] [rbp+58h]
void *Src[2]; // [rsp+168h] [rbp+60h] BYREF
size_t Size; // [rsp+178h] [rbp+70h]
unsigned __int64 v112; // [rsp+180h] [rbp+78h]
v92 = a2;
v89 = 1258291200;
result = cocos2d::CCLayerColor::initWithColor(a1, (const struct cocos2d::_ccColor4B *)&v89);
if ( !result )
return result;
a1->m_storeItem = a2;
cocos2d::CCObject::retain(a2);
if ( !a1->m_forcePrioRegistered )
{
a1->m_forcePrioRegistered = 1;
v7 = cocos2d::CCDirector::sharedDirector(v6);
v8 = (cocos2d::CCTouchDispatcher *)(*(__int64 (__fastcall **)(__int64))(*(_QWORD *)v7 + 144LL))(v7);
cocos2d::CCTouchDispatcher::registerForcePrio(v8, a1, 2);
}
LOBYTE(v5) = 1;
a1->setTouchEnabled(a1, v5);
LOBYTE(v9) = 1;
a1->setKeypadEnabled(a1, v9);
v11 = (cocos2d::CCDirector *)cocos2d::CCDirector::sharedDirector(v10);
cocos2d::CCDirector::getWinSize(v11);
v12 = (cocos2d::CCLayer *)cocos2d::CCLayer::create();
a1->m_mainLayer = v12;
a1->addChild_1(a1, v12);
cocos2d::CCRect::CCRect(&v93, 0.0, 0.0, 80.0, 80.0);
v14 = cocos2d::extension::CCScale9Sprite::create("GJ_square02.png", v13);
v15 = 260.0;
if ( a1->m_storeItem->m_unlockType.random - a1->m_storeItem->m_unlockType.seed == 11 )
v15 = 280.0;
v16 = v14->cocos2d::CCNodeRGBA::cocos2d::CCNode::cocos2d::CCObject::cocos2d::CCCopying::__vftable;
cocos2d::CCSize::CCSize(&v91, v15, 190.0);
v16->setContentSize(v14, v17);
v18 = ((float (__fastcall *)(cocos2d::CCLayer *, struct cocos2d::extension::CCScale9Sprite *, __int64))a1->m_mainLayer->addChild_0)(
a1->m_mainLayer,
v14,
0xFFFFFFFFLL);
v19 = v14->cocos2d::CCNodeRGBA::cocos2d::CCNode::cocos2d::CCObject::cocos2d::CCCopying::__vftable;
v20 = cocos2d::CCPoint::CCPoint(v18, v90 * 0.5);
v19->setPosition_0(v14, v21);
v22 = cocos2d::CCLabelBMFont::create("Buy Item", (const char *)&qword_14052A4D8);
v23 = v22->cocos2d::CCSpriteBatchNode::cocos2d::CCNode::cocos2d::CCObject::cocos2d::CCCopying::__vftable;
cocos2d::CCPoint::CCPoint(*(float *)&v20, v90 * 0.5);
v23->setPosition_0(v22, v24);
a1->m_mainLayer->addChild_1(a1->m_mainLayer, v22);
((void (__fastcall *)(struct cocos2d::CCLabelBMFont *))v22->setScale_0)(v22);
m_storeItem = a1->m_storeItem;
v26 = m_storeItem->m_typeID.random - m_storeItem->m_typeID.seed;
v89 = v26;
LODWORD(width) = m_storeItem->m_unlockType.random - m_storeItem->m_unlockType.seed;
v91.width = width;
StoreItem = GJItemIcon::createStoreItem(SLODWORD(width), v26, 0, v28);
((void (__fastcall *)(GJItemIcon *))StoreItem->setScale_0)(StoreItem);
if ( LODWORD(width) == 12 )
{
v88 = 1;
switch ( v26 )
{
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
break;
default:
goto LABEL_8;
}
}
else
{
LABEL_8:
v88 = 0;
}
v30 = ((float (__fastcall *)(cocos2d::CCLayer *, GJItemIcon *, __int64))a1->m_mainLayer->addChild_0)(
a1->m_mainLayer,
StoreItem,
1);
v31 = StoreItem->cocos2d::CCSprite::cocos2d::CCNodeRGBA::cocos2d::CCNode::cocos2d::CCObject::cocos2d::CCCopying::__vftable;
cocos2d::CCPoint::CCPoint(v30, v90 * 0.5);
v31->setPosition_0(StoreItem, v32);
ItemInfoPopup::nameForUnlockType((__int64)Src, v26, SLODWORD(width));
*(_OWORD *)v95 = 0;
v96 = 0u;
v37 = Src;
if ( v112 > 0xF )
v37 = (void **)Src[0];
v38 = 0x7FFFFFFFFFFFFFFFLL;
v39 = Size;
if ( Size > 0x7FFFFFFFFFFFFFFFLL )
sub_140007B50(v34, v33, v35, v36);
if ( Size > 0xF )
{
*((_QWORD *)&v96 + 1) = 15;
v41 = Size | 0xF;
if ( (Size | 0xF) <= 0x7FFFFFFFFFFFFFFFLL )
{
if ( v41 < 0x16 )
v41 = 22;
}
else
{
v41 = 0x7FFFFFFFFFFFFFFFLL;
}
v95[0] = sub_14003AA10(v41 + 1);
*(_QWORD *)&v96 = v39;
*((_QWORD *)&v96 + 1) = v41;
memcpy(v95[0], v37, v39 + 1);
v40 = *((_QWORD *)&v96 + 1);
v39 = v96;
}
else
{
*(_QWORD *)&v96 = Size;
v40 = 15;
*((_QWORD *)&v96 + 1) = 15;
*(_OWORD *)v95 = *(_OWORD *)v37;
}
if ( v39 >= 8 )
{
if ( v39 == 0x7FFFFFFFFFFFFFFFLL )
sub_140007B50(v40, 22, v35, v36);
v42 = v95;
if ( v40 > 0xF )
v42 = (void **)v95[0];
v97 = 0;
v43 = v39 + 1;
v44 = 15;
v45 = &v97;
if ( v39 + 1 > 0xF )
{
v44 = v43 | 0xF;
if ( (v43 | 0xF) <= 0x7FFFFFFFFFFFFFFFLL )
{
if ( v44 < 0x16 )
v44 = 22;
}
else
{
v44 = 0x7FFFFFFFFFFFFFFFLL;
}
v45 = (__int128 *)sub_14003AA10(v44 + 1);
*(_QWORD *)&v97 = v45;
}
*(_QWORD *)&v98 = v39 + 1;
*((_QWORD *)&v98 + 1) = v44;
*(_BYTE *)v45 = Buf2[0];
memcpy((char *)v45 + 1, v42, v39);
*((_BYTE *)v45 + v43) = 0;
if ( *((_QWORD *)&v96 + 1) > 0xFu )
{
v46 = v95[0];
if ( (unsigned __int64)(*((_QWORD *)&v96 + 1) + 1LL) >= 0x1000 )
{
v46 = *((void **)v95[0] - 1);
if ( (unsigned __int64)((char *)v95[0] - (char *)v46 - 8) > 0x1F )
LABEL_102:
invalid_parameter_noinfo_noreturn();
}
j_j_free(v46);
}
*(_OWORD *)v95 = v97;
v96 = v98;
v26 = v89;
width = v91.width;
}
v47 = "Mana Orbs";
if ( v92->m_shopType == Diamond )
v47 = "Diamond Shards";
*(_OWORD *)v102 = 0;
v103 = 0;
v104 = 0;
v48 = -1;
do
++v48;
while ( v47[v48] );
sub_14003A930(v102, v47, v48);
GameToolbox::pointsToString(&v108, a1->m_storeItem->m_price.random - a1->m_storeItem->m_price.seed);
*(_OWORD *)v105 = 0;
v106 = 0;
v107 = 15;
LOBYTE(v105[0]) = 0;
v49 = v102;
v50 = &v108;
v51 = v95;
if ( v88 )
{
if ( v104 > 0xF )
v49 = (void **)v102[0];
if ( v109 > 0xF )
v50 = (__m128i *)v108.m128i_i64[0];
if ( *((_QWORD *)&v96 + 1) > 0xFu )
v51 = (void **)v95[0];
v52 = cocos2d::CCString::createWithFormat(
"Do you want to unlock%s\nfor %s %s?",
(const char *)v51,
v50->m128i_i8,
(const char *)v49);
CString = (char *)cocos2d::CCString::getCString(v52);
v54 = -1;
do
++v54;
while ( CString[v54] );
}
else
{
if ( v104 > 0xF )
v49 = (void **)v102[0];
if ( v109 > 0xF )
v50 = (__m128i *)v108.m128i_i64[0];
if ( *((_QWORD *)&v96 + 1) > 0xFu )
v51 = (void **)v95[0];
v55 = cocos2d::CCString::createWithFormat(
"Do you want to buy this %s\nfor %s %s?",
(const char *)v51,
v50->m128i_i8,
(const char *)v49);
CString = (char *)cocos2d::CCString::getCString(v55);
v54 = -1;
do
++v54;
while ( CString[v54] );
}
sub_14003CCE0(v105, CString, v54);
v93.origin = (cocos2d::CCPoint)&v97;
v56 = v105;
if ( v107 > 0xF )
v56 = (void **)v105[0];
v97 = 0;
v98 = 0u;
v57 = -1;
do
++v57;
while ( *((_BYTE *)v56 + v57) );
sub_14003A930(&v97, v56, v57);
cocos2d::CCPoint::CCPoint(0.0, 0.5);
v59 = TextArea::create((__int64)&v97, &qword_14052A4D8, 1.0, 999.0, v58, 1108082688, 0);
(*(void (__fastcall **)(char *))(*(_QWORD *)v59 + 160LL))(v59);
v60 = ((float (__fastcall *)(cocos2d::CCLayer *, char *))a1->m_mainLayer->addChild_1)(a1->m_mainLayer, v59);
v61 = *(_QWORD *)v59;
v62 = cocos2d::CCPoint::CCPoint(v60, v90 * 0.5);
(*(void (__fastcall **)(char *, __int64))(v61 + 184))(v59, v63);
a1->m_joystickConnected = -1;
v65 = (cocos2d::CCMenu *)cocos2d::CCMenu::create(v64);
a1->m_buttonMenu = v65;
a1->m_mainLayer->addChild_0(a1->m_mainLayer, v65, 10);
v67 = (cocos2d::CCArray *)cocos2d::CCArray::create(v66);
v93.origin = (cocos2d::CCPoint)operator new(0x2C0u);
v68 = ButtonSprite::ButtonSprite(*(ButtonSprite **)&v93.origin);
if ( v68 )
{
if ( ButtonSprite::init_1(
v68,
"Cancel",
50,
0,
0.60000002,
1,
(const char *)&qword_14052A4D8,
"GJ_button_06.png",
30.0) )
{
cocos2d::CCObject::autorelease(v68);
}
else
{
((void (__fastcall *)(ButtonSprite *, __int64))v68->~ButtonSprite)(v68, 1);
v68 = nullptr;
}
}
v69 = CCMenuItemSpriteExtra::create(v68, nullptr, a1, (cocos2d::SEL_MenuHandler *)AudioAssetsBrowser::onClose);
a1->m_buttonMenu->addChild_1(a1->m_buttonMenu, v69);
cocos2d::CCArray::addObject(v67, v69);
v93.origin = (cocos2d::CCPoint)operator new(0x2C0u);
v70 = ButtonSprite::ButtonSprite(*(ButtonSprite **)&v93.origin);
if ( v70 )
{
if ( ButtonSprite::init_1(
v70,
"Buy",
50,
0,
0.60000002,
1,
(const char *)&qword_14052A4D8,
"GJ_button_01.png",
30.0) )
{
cocos2d::CCObject::autorelease(v70);
}
else
{
((void (__fastcall *)(ButtonSprite *, __int64))v70->~ButtonSprite)(v70, 1);
v70 = nullptr;
}
}
v71 = CCMenuItemSpriteExtra::create(v70, nullptr, a1, (cocos2d::SEL_MenuHandler *)PurchaseItemPopup::onPurchase);
a1->m_buttonMenu->addChild_1(a1->m_buttonMenu, v71);
cocos2d::CCArray::addObject(v67, v71);
a1->m_mainLayer->getPosition_0(a1->m_mainLayer);
cocos2d::CCPoint::CCPoint(*(float *)&v62, v90 * 0.5);
v72 = cocos2d::CCNode::convertToNodeSpace(a1->m_buttonMenu, (const struct cocos2d::CCPoint *)&v92);
GameToolbox::alignItemsHorisontally(v67, 15.0, v72, 0);
if ( LODWORD(width) == 12 )
{
*(_OWORD *)Block = 0;
v73 = 0;
v100 = 0;
v74 = 15;
v101 = 15;
LOBYTE(Block[0]) = 0;
if ( v26 == 16 )
{
v77 = (char *)sub_14003AA10(0xC0u);
v73 = 180;
v74 = 191;
strcpy(
v77,
"This item lets you customize Practice and Menu music.\n"
"After purchasing this item you will be able to change practice and menu music from the more info page on custom songs.");
}
else
{
if ( v26 != 17 )
{
v75 = 0;
v76 = 15;
if ( v26 < 6 || v26 > 15 )
{
v77 = (char *)Block[0];
LABEL_79:
if ( v75 )
{
v93.origin = (cocos2d::CCPoint)&v97;
v97 = 0;
v98 = 0u;
v78 = Block;
if ( v76 > 0xF )
v78 = (void **)v77;
*((_QWORD *)&v98 + 1) = 15;
if ( v73 > 0xF )
{
if ( (v73 | 0xF) <= 0x7FFFFFFFFFFFFFFFLL )
{
v38 = v73 | 0xF;
if ( (v73 | 0xF) < 0x16 )
v38 = 22;
}
*(_QWORD *)&v97 = sub_14003AA10(v38 + 1);
*(_QWORD *)&v98 = v73;
*((_QWORD *)&v98 + 1) = v38;
memcpy((void *)v97, v78, v73 + 1);
}
else
{
*(_QWORD *)&v98 = v73;
v97 = *(_OWORD *)v78;
}
v79 = sub_14003BDB0((__int64)v94, (__int64)Src);
v80 = (__int64 *)InfoAlertButton::create(v79, &v97);
v81 = ((float (__fastcall *)(cocos2d::CCMenu *, __int64 *))a1->m_buttonMenu->addChild_1)(
a1->m_buttonMenu,
v80);
v82 = *v80;
cocos2d::CCPoint::CCPoint(v81, (float)((float)(v90 * 0.5) + (float)(v15 * 0.5)) - 20.0);
v83 = cocos2d::CCNode::convertToNodeSpace(a1->m_buttonMenu, (const struct cocos2d::CCPoint *)&v92);
(*(void (__fastcall **)(__int64 *, struct cocos2d::CCPoint))(v82 + 184))(v80, v83);
}
if ( v74 > 0xF )
{
v84 = v77;
if ( v74 + 1 >= 0x1000 )
{
v77 = *((char **)v77 - 1);
if ( (unsigned __int64)(v84 - v77 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v77);
}
goto LABEL_94;
}
v77 = (char *)sub_14003AA10(0xD0u);
v73 = 195;
v100 = 195;
v74 = 207;
v101 = 207;
qmemcpy(
v77,
"When you activate a path, Stars and Moons you collect will level up your Path."
"\n"
"You can unlock multiple paths, but only one can be active at a time",
194);
*((_WORD *)v77 + 97) = (unsigned __int8)aWhenYouActivat_0[194];
LABEL_78:
Block[0] = v77;
v75 = v73;
v76 = v74;
goto LABEL_79;
}
v77 = (char *)sub_14003AA10(0xA0u);
v73 = 158;
v74 = 159;
strcpy(
v77,
"This item lets you play\n"
"Normal mode music in sync in Practice mode.\n"
"After purchasing this item you will be able to toggle the option in the game menu.");
}
v101 = v74;
v100 = v73;
goto LABEL_78;
}
LABEL_94:
if ( v107 > 0xF )
{
v85 = v105[0];
if ( v107 + 1 >= 0x1000 )
{
v85 = *((void **)v105[0] - 1);
if ( (unsigned __int64)((char *)v105[0] - (char *)v85 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v85);
}
sub_14003A830((__int64)&v108);
if ( v104 > 0xF )
{
v86 = v102[0];
if ( v104 + 1 >= 0x1000 )
{
v86 = *((void **)v102[0] - 1);
if ( (unsigned __int64)((char *)v102[0] - (char *)v86 - 8) > 0x1F )
goto LABEL_102;
}
j_j_free(v86);
}
v103 = 0;
v104 = 15;
LOBYTE(v102[0]) = 0;
if ( *((_QWORD *)&v96 + 1) > 0xFu )
{
v87 = v95[0];
if ( (unsigned __int64)(*((_QWORD *)&v96 + 1) + 1LL) >= 0x1000 )
{
v87 = *((void **)v95[0] - 1);
if ( (unsigned __int64)((char *)v95[0] - (char *)v87 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v87);
}
*(_QWORD *)&v96 = 0;
*((_QWORD *)&v96 + 1) = 15;
LOBYTE(v95[0]) = 0;
sub_14003A830((__int64)Src);
return 1;
}