//
// PurchaseItemPopup::init from 0x1003279f0 to 0x100328407 (2583 bytes)
//
// 1 xrefs:
// > PurchaseItemPopup::create @ 0x10032554b
//
// 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)
{
bool v3; // al
bool v4; // r12
cocos2d::CCLayer *v5; // rax
cocos2d::extension::CCScale9Sprite *v6; // rbx
cocos2d::CCLabelBMFont *v7; // rbx
GJStoreItem *m_storeItem; // rax
__int64 v9; // r15
UnlockType v10; // r12d
GJItemIcon *StoreItem; // rbx
int v12; // eax
__int64 v13; // rcx
bool v14; // r12
float v15; // xmm0_4
double v16; // xmm0_8
_BOOL8 v17; // rbx
const char *v18; // rsi
size_t v19; // rdx
char *v20; // rdi
cocos2d::CCString *v21; // rax
const char *CString; // rax
const char *data; // rbx
size_t v24; // rax
size_t v25; // r13
char *v26; // r15
size_t v27; // r12
char *v28; // rbx
cocos2d::CCMenu *v29; // rax
cocos2d::CCLayer *m_mainLayer; // rdi
cocos2d::CCMenu *v31; // rsi
cocos2d::CCArray *v32; // r13
ButtonSprite *v33; // rax
int v34; // r15d
CCMenuItemSpriteExtra *v35; // rbx
ButtonSprite *v36; // rax
CCMenuItemSpriteExtra *v37; // rbx
cocos2d::CCMenu *m_buttonMenu; // rbx
__int64 v39; // rax
cocos2d::CCPoint v40; // xmm1_8
double v41; // xmm0_8
const std::string::value_type *v42; // rsi
char v43; // cl
__int64 v44; // r15
cocos2d::CCMenu *v45; // rbx
float v47; // [rsp+0h] [rbp-160h] BYREF
char v48; // [rsp+8h] [rbp-158h] BYREF
void *v49; // [rsp+18h] [rbp-148h]
__int128 v50; // [rsp+20h] [rbp-140h] BYREF
void *v51; // [rsp+30h] [rbp-130h]
__int128 v52; // [rsp+40h] [rbp-120h] BYREF
void *v53; // [rsp+50h] [rbp-110h]
std::string v54; // [rsp+60h] [rbp-100h] BYREF
__int128 v55; // [rsp+78h] [rbp-E8h] BYREF
void *v56; // [rsp+88h] [rbp-D8h]
float v57; // [rsp+94h] [rbp-CCh] BYREF
float v58; // [rsp+9Ch] [rbp-C4h]
float v59; // [rsp+A0h] [rbp-C0h]
unsigned int v60; // [rsp+A4h] [rbp-BCh]
__int128 __dst; // [rsp+A8h] [rbp-B8h] BYREF
void *v62; // [rsp+B8h] [rbp-A8h]
GJStoreItem *v63; // [rsp+C0h] [rbp-A0h]
__int64 v64; // [rsp+C8h] [rbp-98h]
__int128 v65; // [rsp+D0h] [rbp-90h] BYREF
void *__p; // [rsp+E0h] [rbp-80h]
UnlockType v67; // [rsp+ECh] [rbp-74h]
std::string v68; // [rsp+F0h] [rbp-70h] BYREF
__int128 v69; // [rsp+110h] [rbp-50h] BYREF
void *v70; // [rsp+120h] [rbp-40h]
float v71; // [rsp+12Ch] [rbp-34h] BYREF
float v72; // [rsp+130h] [rbp-30h]
bool v73; // [rsp+137h] [rbp-29h]
double v74; // 0:xmm0_8.8
double v75; // 0:xmm0_8.8
cocos2d::CCRect v76; // 0:xmm0_8.8,8:xmm1_8.8
LODWORD(v69) = 1258291200;
v3 = cocos2d::CCLayerColor::initWithColor(a1, (const cocos2d::ccColor4B *)&v69);
v4 = v3;
if ( !v3 )
return v4;
v73 = v3;
a1->m_storeItem = a2;
v63 = a2;
cocos2d::CCObject::retain(a2);
FLAlertLayer::incrementForcePrio(a1);
((void (__fastcall *)(PurchaseItemPopup *, __int64))a1->setTouchEnabled)(a1, 1);
((void (__fastcall *)(PurchaseItemPopup *, __int64))a1->setKeypadEnabled)(a1, 1);
cocos2d::CCDirector::sharedDirector();
*(cocos2d::CCSize *)&v74 = cocos2d::CCDirector::getWinSize((cocos2d::CCDirector *)&v71);
v5 = cocos2d::CCLayer::create();
a1->m_mainLayer = v5;
((void (__fastcall *)(PurchaseItemPopup *, cocos2d::CCLayer *, double))a1->addChild)(a1, v5, v74);
v76.origin = 0;
v76.size = 0;
sub_10028CC00((__int64)&v69, 0.0, 0.0, (__m128)0x42A00000u, (__m128)0x42A00000u);
v6 = cocos2d::extension::CCScale9Sprite::create_2("GJ_square02.png", v76);
v59 = flt_100819A38[a1->m_storeItem->m_unlockType.random - a1->m_storeItem->m_unlockType.seed == 11];
sub_10028CBF0((float *)&v69, v59, 190.0);
((void (__fastcall *)(cocos2d::extension::CCScale9Sprite *, __int128 *))v6->setContentSize)(v6, &v69);
((void (__fastcall *)(cocos2d::CCLayer *, cocos2d::extension::CCScale9Sprite *, __int64))a1->m_mainLayer->addChild_0)(
a1->m_mainLayer,
v6,
0xFFFFFFFFLL);
sub_10028CBE0((float *)&v69, v71 * 0.5, v72 * 0.5);
((void (__fastcall *)(cocos2d::extension::CCScale9Sprite *, __int128 *))v6->setPosition)(v6, &v69);
v7 = cocos2d::CCLabelBMFont::create_3("Buy Item", "bigFont.fnt");
sub_10028CBE0((float *)&v69, v71 * 0.5, (float)((float)(v72 * 0.5) + 95.0) + -16.0);
((void (__fastcall *)(cocos2d::CCLabelBMFont *, __int128 *))v7->setPosition)(v7, &v69);
((void (__fastcall *)(cocos2d::CCLayer *, cocos2d::CCLabelBMFont *))a1->m_mainLayer->addChild)(a1->m_mainLayer, v7);
((void (__fastcall *)(cocos2d::CCLabelBMFont *, float))v7->setScale)(v7, 0.60000002);
m_storeItem = a1->m_storeItem;
v9 = m_storeItem->m_typeID.random - (__int64)m_storeItem->m_typeID.seed;
v10 = m_storeItem->m_unlockType.random - m_storeItem->m_unlockType.seed;
StoreItem = GJItemIcon::createStoreItem(
v10,
m_storeItem->m_typeID.random - m_storeItem->m_typeID.seed,
0,
(cocos2d::ccColor3B)-1);
((void (__fastcall *)(GJItemIcon *, float))StoreItem->setScale)(StoreItem, 1.2);
v12 = 0;
LOBYTE(v13) = v10 != Bird;
v67 = v10;
v60 = v9 - 6;
v14 = v10 == GJItem && (unsigned int)(v9 - 6) < 0xA;
if ( v14 )
{
v15 = flt_100819A94[v9 - 6];
}
else
{
LOBYTE(v12) = v13;
v15 = (float)(8 * v12 - 8);
}
*(float *)&v64 = v15;
((void (__fastcall *)(cocos2d::CCLayer *, GJItemIcon *, __int64, __int64))a1->m_mainLayer->addChild_0)(
a1->m_mainLayer,
StoreItem,
1,
v13);
*(_QWORD *)&v16 = LODWORD(v71);
*(float *)&v16 = v71 * 0.5;
sub_10028CBE0((float *)&v69, v71 * 0.5, (float)((float)(0.5 * v72) + 22.0) + *(float *)&v64);
((void (__fastcall *)(GJItemIcon *, __int128 *))StoreItem->setPosition)(StoreItem, &v69);
ItemInfoPopup::nameForUnlockType(&v69, (unsigned int)v9, (unsigned int)v67);
if ( (v69 & 1) != 0 )
{
sub_100006B70(&v65, v70, *((unsigned __int64 *)&v69 + 1), v16);
}
else
{
__p = v70;
v16 = *(double *)&v69;
v65 = v69;
}
if ( (v65 & 1) != 0 )
{
if ( *((_QWORD *)&v65 + 1) < 8u )
goto LABEL_15;
}
else if ( (unsigned __int8)v65 >> 1 < 8uLL )
{
goto LABEL_15;
}
std::operator+(&__dst, "\n", &v65);
if ( (v65 & 1) != 0 )
operator delete(__p);
__p = v62;
v16 = *(double *)&__dst;
v65 = __dst;
LABEL_15:
v17 = v63->m_shopType == Diamond;
v18 = "Mana Orbs";
if ( v63->m_shopType == Diamond )
v18 = "Diamond Shards";
v19 = 5 * v17 + 17;
LOBYTE(__dst) = 2 * v19;
memcpy((char *)&__dst + 1, v18, v19);
*((_BYTE *)&v62 + 5 * v17 + 2) = 0;
GameToolbox::pointsToString(&v48);
*(_WORD *)&v54.__r_.__value_.__l.0 = 0;
v20 = "Do you want to buy this %s\nfor %s %s?";
if ( v14 )
v20 = "Do you want to unlock%s\nfor %s %s?";
v21 = (cocos2d::CCString *)sub_1007AB580(v20, SLOBYTE(v47));
CString = cocos2d::CCString::getCString(v21);
std::string::assign(&v54, CString);
if ( (*(_BYTE *)&v54.__r_.__value_.__s.0 & 1) != 0 )
data = v54.__r_.__value_.__l.__data_;
else
data = v54.__r_.__value_.__s.__data_;
v24 = strlen(data);
if ( v24 >= 0xFFFFFFFFFFFFFFF8LL )
sub_100006BF0(v16);
v25 = v24;
v64 = v9;
if ( v24 >= 0x17 )
{
v27 = 26;
if ( (v24 | 7) != 0x17 )
v27 = (v24 | 7) + 1;
v26 = (char *)operator new(v27);
v56 = v26;
*(_QWORD *)&v55 = v27 | 1;
*((_QWORD *)&v55 + 1) = v25;
goto LABEL_29;
}
LOBYTE(v55) = 2 * v24;
v26 = (char *)&v55 + 1;
if ( v24 )
LABEL_29:
memmove(v26, data, v25);
v26[v25] = 0;
sub_10028CBE0((float *)&v68, 0.5, 1.0);
v28 = TextArea::create(&v55, (__int64)"bigFont.fnt", (double *)&v68, 0, 1.0, 999.0, 35.0);
if ( (v55 & 1) != 0 )
operator delete(v56);
(*(void (__fastcall **)(char *, float))(*(_QWORD *)v28 + 160LL))(v28, 0.40000001);
((void (__fastcall *)(cocos2d::CCLayer *, char *))a1->m_mainLayer->addChild)(a1->m_mainLayer, v28);
sub_10028CBE0((float *)&v68, v71 * 0.5, (float)(v72 * 0.5) + -20.0);
(*(void (__fastcall **)(char *, std::string *))(*(_QWORD *)v28 + 184LL))(v28, &v68);
a1->m_joystickConnected = -1;
v29 = cocos2d::CCMenu::create();
a1->m_buttonMenu = v29;
m_mainLayer = a1->m_mainLayer;
v31 = v29;
((void (__fastcall *)(cocos2d::CCLayer *, cocos2d::CCMenu *, __int64))m_mainLayer->addChild_0)(m_mainLayer, v29, 10);
v32 = (cocos2d::CCArray *)sub_10071F9E0(m_mainLayer, v31);
v33 = ButtonSprite::create_1("Cancel", 50, 0, 0.60000002, 1, "bigFont.fnt", "GJ_button_06.png", 30.0);
v4 = v73;
v34 = v64;
v35 = CCMenuItemSpriteExtra::create(
v33,
nullptr,
a1,
(cocos2d::SEL_MenuHandler)(unsigned __int64)PurchaseItemPopup::onClose);
((void (__fastcall *)(cocos2d::CCMenu *, CCMenuItemSpriteExtra *))a1->m_buttonMenu->addChild)(a1->m_buttonMenu, v35);
sub_10071FCD0(v32, v35);
v36 = ButtonSprite::create_1("Buy", 50, 0, 0.60000002, 1, "bigFont.fnt", "GJ_button_01.png", 30.0);
v37 = CCMenuItemSpriteExtra::create(
v36,
nullptr,
a1,
(cocos2d::SEL_MenuHandler)(unsigned __int64)PurchaseItemPopup::onPurchase);
((void (__fastcall *)(cocos2d::CCMenu *, CCMenuItemSpriteExtra *))a1->m_buttonMenu->addChild)(a1->m_buttonMenu, v37);
sub_10071FCD0(v32, v37);
m_buttonMenu = a1->m_buttonMenu;
v58 = v71;
*(float *)&v63 = v72;
v39 = ((__int64 (__fastcall *)(cocos2d::CCLayer *))a1->m_mainLayer->getPosition)(a1->m_mainLayer);
v40 = (cocos2d::CCPoint)(unsigned int)v63;
v40.x = (float)((float)((float)(*(float *)&v63 * 0.5) + -95.0) + 22.0) + *(float *)(v39 + 4);
sub_10028CBE0(&v57, v58 * 0.5, v40.x);
cocos2d::CCNode::convertToNodeSpace((cocos2d::CCNode *)&v68, (const cocos2d::CCPoint *)m_buttonMenu);
GameToolbox::alignItemsHorisontally(v32, 15.0, v40, (bool)&v68);
if ( v67 == GJItem )
{
v41 = 0.0;
memset(&v68, 0, sizeof(v68));
if ( v34 == 16 )
{
v42 = "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 ( v34 == 17 )
{
v42 = "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 ( v60 > 9 )
goto LABEL_40;
v42 = "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(&v68, v42);
LABEL_40:
v43 = *(_BYTE *)&v68.__r_.__value_.__s.0 & 1;
if ( (*(_BYTE *)&v68.__r_.__value_.__s.0 & 1) != 0 )
{
if ( !v68.__r_.__value_.__l.__size_ )
{
LABEL_54:
if ( v43 )
operator delete(v68.__r_.__value_.__l.__data_);
goto LABEL_56;
}
}
else if ( !(*(_BYTE *)&v68.__r_.__value_.__l.0 >> 1) )
{
goto LABEL_54;
}
if ( (v69 & 1) != 0 )
{
sub_100006B70(&v50, v70, *((unsigned __int64 *)&v69 + 1), 0.0);
if ( (*(_BYTE *)&v68.__r_.__value_.__s.0 & 1) == 0 )
goto LABEL_46;
}
else
{
v51 = v70;
v41 = *(double *)&v69;
v50 = v69;
if ( (*(_BYTE *)&v68.__r_.__value_.__s.0 & 1) == 0 )
{
LABEL_46:
v53 = v68.__r_.__value_.__l.__data_;
v52 = *(_OWORD *)&v68.__r_.__value_.__l.0;
LABEL_49:
v44 = InfoAlertButton::create(&v50, &v52, 1.0);
if ( (v52 & 1) != 0 )
operator delete(v53);
if ( (v50 & 1) != 0 )
operator delete(v51);
((void (__fastcall *)(cocos2d::CCMenu *, __int64))a1->m_buttonMenu->addChild)(a1->m_buttonMenu, v44);
v45 = a1->m_buttonMenu;
sub_10028CBE0(
&v47,
(float)((float)(v59 * 0.5) + (float)(v71 * 0.5)) + -20.0,
(float)((float)(0.5 * v72) + 95.0) + -18.0);
*(cocos2d::CCPoint *)&v75 = cocos2d::CCNode::convertToNodeSpace(
(cocos2d::CCNode *)&v57,
(const cocos2d::CCPoint *)v45);
(*(void (__fastcall **)(__int64, float *, double))(*(_QWORD *)v44 + 184LL))(v44, &v57, v75);
v43 = *(_BYTE *)&v68.__r_.__value_.__s.0 & 1;
goto LABEL_54;
}
}
sub_100006B70(&v52, v68.__r_.__value_.__l.__data_, v68.__r_.__value_.__l.__size_, v41);
goto LABEL_49;
}
LABEL_56:
if ( (*(_BYTE *)&v54.__r_.__value_.__s.0 & 1) != 0 )
{
operator delete(v54.__r_.__value_.__l.__data_);
if ( (v48 & 1) == 0 )
{
LABEL_58:
if ( (__dst & 1) == 0 )
goto LABEL_59;
goto LABEL_65;
}
}
else if ( (v48 & 1) == 0 )
{
goto LABEL_58;
}
operator delete(v49);
if ( (__dst & 1) == 0 )
{
LABEL_59:
if ( (v65 & 1) == 0 )
goto LABEL_60;
LABEL_66:
operator delete(__p);
if ( (v69 & 1) == 0 )
return v4;
goto LABEL_61;
}
LABEL_65:
operator delete(v62);
if ( (v65 & 1) != 0 )
goto LABEL_66;
LABEL_60:
if ( (v69 & 1) != 0 )
LABEL_61:
operator delete(v70);
return v4;
}