//
// CustomSongLayer::onSearch from 0x1400c39a0 to 0x1400c3d74 (980 bytes)
//
// 2 xrefs:
// > CustomSongLayer::init @ 0x1400c3730
// > ??> @ 0x1406c8040
//
// 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=6
void CustomSongLayer::onSearch(CustomSongLayer *a1, cocos2d::CCObject *a2)
{
int m_songID; // esi
GameManager *v4; // rcx
GameManager *v5; // rcx
_QWORD *v6; // r8
_OWORD *v7; // rcx
const char *v8; // rax
__int64 v9; // rdx
__int64 v10; // rax
FLAlertLayer *v11; // rbx
__int64 v12; // rbx
cocos2d::CCLabelProtocol *v13; // rcx
const char *v14; // rax
size_t v15; // r8
const char *v16; // rcx
int v17; // eax
SongInfoObject *v18; // rdi
CustomSongWidget *m_songWidget; // rbx
cocos2d::extension::CCScale9Sprite *m_bgSpr; // rcx
SongInfoObject *m_songInfoObject; // rax
cocos2d::CCObject *v22; // rcx
char *v23; // rcx
void *v24; // [rsp+50h] [rbp-39h]
void *v25; // [rsp+50h] [rbp-39h]
__int128 v26; // [rsp+58h] [rbp-31h] BYREF
__int64 v27; // [rsp+68h] [rbp-21h]
__int64 v28; // [rsp+70h] [rbp-19h]
FMODAudioEngine *v29; // [rsp+78h] [rbp-11h]
char v30[32]; // [rsp+80h] [rbp-9h] BYREF
char *String[2]; // [rsp+A0h] [rbp+17h] BYREF
__int64 v32; // [rsp+B0h] [rbp+27h]
unsigned __int64 v33; // [rsp+B8h] [rbp+2Fh]
m_songID = 0;
v4 = (GameManager *)qword_1406C2ED8;
if ( !qword_1406C2ED8 )
{
v24 = operator new(0x668u);
qword_1406C2ED8 = sub_14017AB00(v24);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2ED8 + 72LL))(qword_1406C2ED8);
v4 = (GameManager *)qword_1406C2ED8;
}
if ( GameManager::getGameVariable(v4, "0051") )
{
v12 = qword_1406C2E88;
if ( !qword_1406C2E88 )
{
v29 = (FMODAudioEngine *)operator new(0x888u);
qword_1406C2E88 = (__int64)FMODAudioEngine::FMODAudioEngine(v29);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2E88 + 72LL))(qword_1406C2E88);
v12 = qword_1406C2E88;
}
if ( *(_QWORD *)(v12 + 552) )
FMOD::ChannelControl::stop(*(FMOD::ChannelControl **)(v12 + 552));
sub_14005E0D0((_QWORD *)(v12 + 1064));
sub_14005E0D0((_QWORD *)(v12 + 1128));
sub_14005E0D0((_QWORD *)(v12 + 1192));
a1->m_songIDInput->onClickTrackNode(a1->m_songIDInput, 0);
v13 = &a1->m_songIDInput->m_textField->cocos2d::CCLabelProtocol;
v14 = v13->getString(v13);
*(_OWORD *)String = 0;
v32 = 0;
v33 = 0;
v15 = -1;
do
++v15;
while ( v14[v15] );
sub_14003A930(String, v14, v15);
v16 = (const char *)String;
if ( v33 > 0xF )
v16 = String[0];
v17 = atoi(v16);
v18 = SongInfoObject::create_1(v17);
m_songWidget = a1->m_songWidget;
m_songWidget->m_errorLabel->setVisible(m_songWidget->m_errorLabel, 0);
m_bgSpr = m_songWidget->m_bgSpr;
if ( m_bgSpr )
m_bgSpr->setVisible(m_bgSpr, 0);
m_songInfoObject = m_songWidget->m_songInfoObject;
if ( m_songInfoObject != v18 )
{
if ( v18 )
cocos2d::CCObject::retain(v18);
v22 = m_songWidget->m_songInfoObject;
if ( v22 )
cocos2d::CCObject::release(v22);
m_songWidget->m_songInfoObject = v18;
m_songInfoObject = v18;
}
if ( m_songInfoObject )
m_songID = m_songInfoObject->m_songID;
m_songWidget->m_customSongID = m_songID;
CustomSongWidget::updateSongInfo(m_songWidget);
CustomSongWidget::getSongInfoIfUnloaded(a1->m_songWidget);
if ( v33 > 0xF )
{
v23 = String[0];
if ( v33 + 1 >= 0x1000 )
{
v23 = *((char **)String[0] - 1);
if ( (unsigned __int64)(String[0] - v23 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v23);
}
}
else
{
v5 = (GameManager *)qword_1406C2ED8;
if ( !qword_1406C2ED8 )
{
v25 = operator new(0x668u);
qword_1406C2ED8 = sub_14017AB00(v25);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2ED8 + 72LL))(qword_1406C2ED8);
v5 = (GameManager *)qword_1406C2ED8;
}
GameManager::setGameVariable(v5, "0051", 1);
v26 = 0;
v6 = sub_14003AA10(0x120u);
*(_QWORD *)&v26 = v6;
v27 = 273;
v28 = 287;
v7 = v6;
v8 = "There are thousands of great custom songs for you to choose from Newgrounds. Please do not upload music you did"
" not create. You are only allowed to use songs from artists that have been scouted on Newgrounds. For more info"
"rmation, please check the Audio Guidelines.";
v9 = 2;
do
{
*v7 = *(_OWORD *)v8;
v7[1] = *((_OWORD *)v8 + 1);
v7[2] = *((_OWORD *)v8 + 2);
v7[3] = *((_OWORD *)v8 + 3);
v7[4] = *((_OWORD *)v8 + 4);
v7[5] = *((_OWORD *)v8 + 5);
v7[6] = *((_OWORD *)v8 + 6);
v7 += 8;
*(v7 - 1) = *((_OWORD *)v8 + 7);
v8 += 128;
--v9;
}
while ( v9 );
*v7 = *(_OWORD *)v8;
*((_BYTE *)v7 + 16) = v8[16];
*((_BYTE *)v6 + 273) = 0;
v10 = sub_14003BDB0((__int64)v30, (__int64)&v26);
v11 = FLAlertLayer::create(0, (int)"Newgrounds Info", v10, (__int64)"OK", 0, 1136525312, 0, 0, 1065353216);
sub_14003A830((__int64)&v26);
v11->show(v11);
}
}