//
// PurchaseItemPopup::init from 0x10014db7c to 0x10014e3b4 (2104 bytes)
//
// 1 xrefs:
// > PurchaseItemPopup::create @ 0x10014c3f4
//
// 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 PurchaseItemPopup::init(PurchaseItemPopup *a1, GJStoreItem *a2)
{
_BOOL4 v4; // w19
cocos2d::CCDirector *v5; // x0
cocos2d::CCLayer *v6; // x0
cocos2d::extension::CCScale9Sprite *v7; // x21
float v8; // s8
__n128 v9; // q0
__n128 v10; // q1
cocos2d::CCLabelBMFont *v11; // x21
__n128 v12; // q0
__n128 v13; // q1
GJStoreItem *m_storeItem; // x8
__int64 v15; // x21
int random; // w9
__int64 v17; // x22
GJItemIcon *StoreItem; // x24
int v19; // w8
bool v20; // zf
int v21; // w27
float v22; // s11
__n128 v23; // q0
__n128 v24; // q1
unsigned __int64 v25; // x8
char *v26; // x1
cocos2d::CCString *v27; // x0
const char *CString; // x0
std::string *v29; // x1
__n128 v30; // q0
__n128 v31; // q1
cocos2d::CCObject *v32; // x23
__n128 v33; // q0
__n128 v34; // q1
__int64 v35; // x0
cocos2d::CCArray *v36; // x23
ButtonSprite *v37; // x0
CCMenuItemSpriteExtra *v38; // x24
ButtonSprite *v39; // x0
CCMenuItemSpriteExtra *v40; // x24
__n128 v41; // q0
cocos2d::CCMenu *m_buttonMenu; // x24
float v43; // s9
float v44; // s10
__int64 v45; // x0
__n128 v46; // q0
__n128 v47; // q1
const std::string::value_type *v48; // x1
std::string::size_type size; // x9
char v50; // w8
__int64 v51; // x21
__n128 v52; // q0
cocos2d::CCMenu *v53; // x20
__n128 v54; // q1
cocos2d::CCPoint v56; // [xsp+18h] [xbp-178h] BYREF
std::string v57; // [xsp+20h] [xbp-170h] BYREF
void *v58[2]; // [xsp+40h] [xbp-150h] BYREF
__int64 v59; // [xsp+50h] [xbp-140h]
std::string v60; // [xsp+60h] [xbp-130h] BYREF
cocos2d::CCPoint v61; // [xsp+78h] [xbp-118h] BYREF
void *__p[2]; // [xsp+80h] [xbp-110h] BYREF
char v63; // [xsp+97h] [xbp-F9h]
std::string v64; // [xsp+98h] [xbp-F8h] BYREF
void *v65; // [xsp+B0h] [xbp-E0h] BYREF
char v66; // [xsp+C7h] [xbp-C9h]
void *v67[2]; // [xsp+C8h] [xbp-C8h] BYREF
__int64 v68; // [xsp+D8h] [xbp-B8h]
__int128 __dst; // [xsp+E0h] [xbp-B0h] BYREF
__int64 v70; // [xsp+F0h] [xbp-A0h]
__int128 v71; // [xsp+100h] [xbp-90h] BYREF
__int64 v72; // [xsp+110h] [xbp-80h]
float v73; // [xsp+118h] [xbp-78h]
float v74; // [xsp+11Ch] [xbp-74h]
cocos2d::CCPoint v75; // 0:kr10_8.8
cocos2d::SEL_MenuHandler v76; // 0:x3.16
cocos2d::SEL_MenuHandler v77; // 0:x3.16
cocos2d::CCPoint v78; // 0:s1.4,4:s2.4
cocos2d::CCRect v79; // 0:s0.4,4:s1.4,8:s2.4,12:s3.4
LODWORD(v71) = 1258291200;
v4 = cocos2d::CCLayerColor::initWithColor(a1, (const cocos2d::ccColor4B *)&v71);
if ( !v4 )
return v4;
a1->m_storeItem = a2;
cocos2d::CCObject::retain(a2);
FLAlertLayer::incrementForcePrio(a1);
((void (__fastcall *)(PurchaseItemPopup *, __int64))a1->setTouchEnabled)(a1, 1);
((void (__fastcall *)(PurchaseItemPopup *, __int64))a1->setKeypadEnabled)(a1, 1);
v5 = cocos2d::CCDirector::sharedDirector();
cocos2d::CCDirector::getWinSize(v5);
v6 = cocos2d::CCLayer::create();
a1->m_mainLayer = v6;
((void (__fastcall *)(PurchaseItemPopup *, cocos2d::CCLayer *))a1->addChild)(a1, v6);
sub_100022990((float *)&v71, 0.0, 0.0, 80.0, 80.0);
v7 = cocos2d::extension::CCScale9Sprite::create("GJ_square02.png", v79);
if ( a1->m_storeItem->m_unlockType.random - a1->m_storeItem->m_unlockType.seed == 11 )
v8 = 280.0;
else
v8 = 260.0;
sub_100022988((float *)&v71, v8, 190.0);
((void (__fastcall *)(cocos2d::extension::CCScale9Sprite *, __int128 *))v7->setContentSize)(v7, &v71);
v9 = ((__n128 (__fastcall *)(cocos2d::CCLayer *, cocos2d::extension::CCScale9Sprite *, __int64))a1->m_mainLayer->addChild_0)(
a1->m_mainLayer,
v7,
0xFFFFFFFFLL);
v9.n128_f32[0] = v73 * 0.5;
v10.n128_f32[0] = v74 * 0.5;
sub_100022980(v9, v10, &v71);
((void (__fastcall *)(cocos2d::extension::CCScale9Sprite *, __int128 *))v7->setPosition)(v7, &v71);
v11 = cocos2d::CCLabelBMFont::create_1("Buy Item", "bigFont.fnt");
v12.n128_f32[0] = v73 * 0.5;
v13.n128_f32[0] = (float)((float)(v74 * 0.5) + 95.0) + -16.0;
sub_100022980(v12, v13, &v71);
((void (__fastcall *)(cocos2d::CCLabelBMFont *, __int128 *))v11->setPosition)(v11, &v71);
((void (__fastcall *)(cocos2d::CCLayer *, cocos2d::CCLabelBMFont *))a1->m_mainLayer->addChild)(a1->m_mainLayer, v11);
((void (__fastcall *)(cocos2d::CCLabelBMFont *, float))v11->setScale)(v11, 0.6);
m_storeItem = a1->m_storeItem;
v15 = m_storeItem->m_typeID.random - (__int64)m_storeItem->m_typeID.seed;
random = m_storeItem->m_unlockType.random;
LODWORD(m_storeItem) = m_storeItem->m_unlockType.seed;
v17 = (unsigned int)(random - (_DWORD)m_storeItem);
StoreItem = GJItemIcon::createStoreItem((UnlockType)(random - (_DWORD)m_storeItem), v15, 0, (cocos2d::ccColor3B)-1);
((void (__fastcall *)(GJItemIcon *, float))StoreItem->setScale)(StoreItem, 1.2);
if ( (_DWORD)v17 == 6 )
v19 = -8;
else
v19 = 0;
v20 = (unsigned int)(v15 - 6) < 0xA && (_DWORD)v17 == 12;
v21 = v20;
if ( v20 )
v22 = flt_1006384F8[v15 - 6];
else
v22 = (float)v19;
v23 = ((__n128 (__fastcall *)(cocos2d::CCLayer *, GJItemIcon *, __int64))a1->m_mainLayer->addChild_0)(
a1->m_mainLayer,
StoreItem,
1);
v23.n128_f32[0] = v73 * 0.5;
v24.n128_f32[0] = v22 + (float)((float)(v74 * 0.5) + 22.0);
sub_100022980(v23, v24, &v71);
((void (__fastcall *)(GJItemIcon *, __int128 *))StoreItem->setPosition)(StoreItem, &v71);
ItemInfoPopup::nameForUnlockType(&v71, v15, v17);
if ( SHIBYTE(v72) < 0 )
{
sub_1000097D0(&__dst, (void *)v71, *((unsigned __int64 *)&v71 + 1));
}
else
{
__dst = v71;
v70 = v72;
}
v25 = HIBYTE(v70);
if ( v70 < 0 )
v25 = *((_QWORD *)&__dst + 1);
if ( v25 >= 8 )
{
std::operator+(v67, "\n", &__dst);
if ( SHIBYTE(v70) < 0 )
operator delete((void *)__dst);
__dst = *(_OWORD *)v67;
v70 = v68;
}
if ( a2->m_shopType == Diamond )
v26 = "Diamond Shards";
else
v26 = "Mana Orbs";
sub_100009900(v67, v26);
GameToolbox::pointsToString(
(unsigned int)(a1->m_storeItem->m_price.random - a1->m_storeItem->m_price.seed),
(__int64)&v65);
sub_100009900(&v64, "");
if ( v21 )
v27 = (cocos2d::CCString *)sub_100268F4C("Do you want to unlock%s\nfor %s %s?");
else
v27 = (cocos2d::CCString *)sub_100268F4C("Do you want to buy this %s\nfor %s %s?");
CString = cocos2d::CCString::getCString(v27);
std::string::assign(&v64, CString);
if ( (v64.__r_.__value_.__r.__words[2] & 0x8000000000000000LL) == 0LL )
v29 = &v64;
else
v29 = (std::string *)v64.__r_.__value_.__r.__words[0];
sub_100009900(__p, (char *)v29);
v30.n128_u32[0] = 0.5;
v31.n128_u32[0] = 1.0;
sub_100022980(v30, v31, &v60);
v32 = TextArea::create((__int64)__p, (__int64)"bigFont.fnt", (__int64 *)&v60, 0, 1.0, 999.0, 35.0);
if ( v63 < 0 )
operator delete(__p[0]);
((void (__fastcall *)(cocos2d::CCObject *, float))v32->__vftable[2].copyWithZone)(v32, 0.4);
v33 = ((__n128 (__fastcall *)(cocos2d::CCLayer *, cocos2d::CCObject *))a1->m_mainLayer->addChild)(
a1->m_mainLayer,
v32);
v33.n128_f32[0] = v73 * 0.5;
v34.n128_f32[0] = (float)(v74 * 0.5) + -20.0;
sub_100022980(v33, v34, &v60);
((void (__fastcall *)(cocos2d::CCObject *, std::string *))v32->__vftable[2].isEqual)(v32, &v60);
a1->m_joystickConnected = -1;
a1->m_buttonMenu = cocos2d::CCMenu::create();
v35 = ((__int64 (__fastcall *)(cocos2d::CCLayer *))a1->m_mainLayer->addChild_0)(a1->m_mainLayer);
v36 = (cocos2d::CCArray *)sub_10024A15C(v35);
v37 = ButtonSprite::create_1("Cancel", 50, 0, 0.6, 1, "bigFont.fnt", "GJ_button_06.png", 30.0);
v76.ptr = (void (__cdecl *)(cocos2d::CCObject *))PurchaseItemPopup::onClose;
v76.adj = 0;
v38 = CCMenuItemSpriteExtra::create(v37, nullptr, a1, v76);
((void (__fastcall *)(cocos2d::CCMenu *, CCMenuItemSpriteExtra *))a1->m_buttonMenu->addChild)(a1->m_buttonMenu, v38);
sub_10024A2D0(v36, v38);
v39 = ButtonSprite::create_1("Buy", 50, 0, 0.6, 1, "bigFont.fnt", "GJ_button_01.png", 30.0);
v77.ptr = (void (__cdecl *)(cocos2d::CCObject *))PurchaseItemPopup::onPurchase;
v77.adj = 0;
v40 = CCMenuItemSpriteExtra::create(v39, nullptr, a1, v77);
((void (__fastcall *)(cocos2d::CCMenu *, CCMenuItemSpriteExtra *))a1->m_buttonMenu->addChild)(a1->m_buttonMenu, v40);
v41 = sub_10024A2D0(v36, v40);
m_buttonMenu = a1->m_buttonMenu;
v43 = v73;
v44 = v74;
v45 = ((__int64 (__fastcall *)(cocos2d::CCLayer *, __n128))a1->m_mainLayer->getPosition)(a1->m_mainLayer, v41);
v46.n128_f32[0] = v43 * 0.5;
v47.n128_f32[0] = (float)((float)((float)(v44 * 0.5) + -95.0) + 22.0) + *(float *)(v45 + 4);
sub_100022980(v46, v47, &v61);
LODWORD(v78.x) = COERCE_UNSIGNED_INT(cocos2d::CCNode::convertToNodeSpace(m_buttonMenu, &v61).y);
GameToolbox::alignItemsHorisontally(v36, 15.0, v78, (bool)&v60);
if ( (_DWORD)v17 == 12 )
{
memset(&v60, 0, sizeof(v60));
if ( (_DWORD)v15 == 16 )
{
v48 = "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 ( (_DWORD)v15 == 17 )
{
v48 = "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.";
}
else
{
if ( (unsigned int)(v15 - 6) > 9 )
goto LABEL_45;
v48 = "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.";
}
std::string::assign(&v60, v48);
LABEL_45:
size = HIBYTE(v60.__r_.__value_.__r.__words[2]);
v50 = HIBYTE(v60.__r_.__value_.__r.__words[2]);
if ( (v60.__r_.__value_.__r.__words[2] & 0x8000000000000000LL) != 0LL )
size = v60.__r_.__value_.__l.__size_;
if ( !size )
goto LABEL_58;
if ( SHIBYTE(v72) < 0 )
{
sub_1000097D0(v58, (void *)v71, *((unsigned __int64 *)&v71 + 1));
if ( (*((_BYTE *)&v60.__r_.__value_.__s + 23) & 0x80) == 0 )
goto LABEL_50;
}
else
{
*(_OWORD *)v58 = v71;
v59 = v72;
if ( (*((_BYTE *)&v60.__r_.__value_.__s + 23) & 0x80) == 0 )
{
LABEL_50:
v57 = v60;
LABEL_53:
v51 = InfoAlertButton::create(v58, &v57, 1.0);
if ( SHIBYTE(v57.__r_.__value_.__r.__words[2]) < 0 )
operator delete(v57.__r_.__value_.__l.__data_);
if ( SHIBYTE(v59) < 0 )
operator delete(v58[0]);
v52 = ((__n128 (__fastcall *)(cocos2d::CCMenu *, __int64))a1->m_buttonMenu->addChild)(a1->m_buttonMenu, v51);
v52.n128_f32[0] = (float)((float)(v8 * 0.5) + (float)(v73 * 0.5)) + -20.0;
v53 = a1->m_buttonMenu;
v54.n128_f32[0] = (float)((float)(v74 * 0.5) + 95.0) + -18.0;
sub_100022980(v52, v54, &v56);
v75 = cocos2d::CCNode::convertToNodeSpace(v53, &v56);
(*(void (__fastcall **)(__int64, cocos2d::CCPoint *, float, float))(*(_QWORD *)v51 + 184LL))(
v51,
&v61,
v75.x,
v75.y);
v50 = HIBYTE(v60.__r_.__value_.__r.__words[2]);
LABEL_58:
if ( v50 < 0 )
operator delete(v60.__r_.__value_.__l.__data_);
goto LABEL_60;
}
}
sub_1000097D0(&v57, v60.__r_.__value_.__l.__data_, v60.__r_.__value_.__l.__size_);
goto LABEL_53;
}
LABEL_60:
if ( SHIBYTE(v64.__r_.__value_.__r.__words[2]) < 0 )
operator delete(v64.__r_.__value_.__l.__data_);
if ( v66 < 0 )
operator delete(v65);
if ( SHIBYTE(v68) < 0 )
operator delete(v67[0]);
if ( SHIBYTE(v70) < 0 )
operator delete((void *)__dst);
if ( SHIBYTE(v72) < 0 )
operator delete((void *)v71);
return v4;
}