//
// SetupSFXPopup::createSFXWidget from 0xa3fdd4 to 0xa40154 (896 bytes)
//
// 3 xrefs:
// > SetupSFXPopup::valueDidChange @ 0xa40230
// > SetupSFXPopup::init @ 0xa40f58
// > ??> @ 0xc6ba0
//
// 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 SetupSFXPopup::createSFXWidget(SetupSFXPopup *a1)
{
CustomSFXWidget *m_sfxWidget; // x0
MusicDownloadManager *v3; // x0
SFXInfoObject *SFXObject; // x0
CustomSFXWidget *v5; // x0
cocos2d::CCLayer *m_mainLayer; // x3
cocos2d::CCDirector *v7; // x0
MusicDownloadManager *v8; // x0
FMODAudioEngine *v9; // x24
char *v10; // x0
FMODAudioEngine *v11; // x25
unsigned int m_sfxLength; // w0
char *v13; // x2
void *v14; // x0
unsigned int *v15; // x19
int v16; // w1
unsigned int *v17; // x1
int v18; // w0
unsigned int *v19; // x1
int v20; // w2
float v21; // [xsp+70h] [xbp+70h]
float v22; // [xsp+74h] [xbp+74h]
cocos2d::CCPoint v23; // [xsp+78h] [xbp+78h] BYREF
__int64 v24; // [xsp+80h] [xbp+80h] BYREF
_DWORD *v25; // [xsp+88h] [xbp+88h] BYREF
_DWORD *v26; // [xsp+90h] [xbp+90h] BYREF
m_sfxWidget = a1->m_sfxWidget;
if ( m_sfxWidget )
{
m_sfxWidget->removeMeAndCleanup(m_sfxWidget);
a1->m_sfxWidget = nullptr;
}
if ( a1->m_sfxID > 0 )
{
v3 = MusicDownloadManager::sharedState();
SFXObject = MusicDownloadManager::getSFXObject(v3, a1->m_sfxID);
a1->m_sfxLength = 0;
if ( SFXObject )
{
if ( !SFXObject->m_folder )
{
v5 = CustomSFXWidget::create(SFXObject, &a1->CustomSFXDelegate, 0, 1, 1, 0, 0);
m_mainLayer = a1->m_mainLayer;
a1->m_sfxWidget = v5;
m_mainLayer->addChild_0(m_mainLayer, v5, 2);
v7 = cocos2d::CCDirector::sharedDirector();
cocos2d::CCDirector::getWinSize(v7);
cocos2d::CCPoint::CCPoint(&v23, v21 * 0.5, (float)(v22 * 0.5) + 70.0);
a1->m_sfxWidget->setPosition(a1->m_sfxWidget, &v23);
v8 = MusicDownloadManager::sharedState();
MusicDownloadManager::pathForSFX(&v24, v8, a1->m_sfxID);
v9 = FMODAudioEngine::sharedEngine();
sub_D18D28(&v25);
FMODAudioEngine::preloadEffect((__int64)v9, (const void **)&v25);
v10 = (char *)(v25 - 6);
if ( v25 - 6 != (_DWORD *)&qword_124B6B0 )
{
if ( &pthread_create )
{
v19 = v25 - 2;
do
v20 = __ldaxr(v19);
while ( __stlxr(v20 - 1, v19) );
}
else
{
v20 = *(v25 - 2);
*(v25 - 2) = v20 - 1;
}
if ( v20 <= 0 )
operator delete(v10);
}
v11 = FMODAudioEngine::sharedEngine();
sub_D18D28(&v26);
m_sfxLength = FMODAudioEngine::lengthForSound((__int64)v11, (const void **)&v26);
a1->m_sfxLength = m_sfxLength;
v13 = (char *)(v26 - 6);
if ( v26 - 6 == (_DWORD *)&qword_124B6B0 )
{
if ( !m_sfxLength )
goto LABEL_11;
}
else
{
if ( &pthread_create )
{
v17 = v26 - 2;
do
v18 = __ldaxr(v17);
while ( __stlxr(v18 - 1, v17) );
}
else
{
v18 = *(v26 - 2);
*(v26 - 2) = v18 - 1;
}
if ( v18 <= 0 )
operator delete(v13);
m_sfxLength = a1->m_sfxLength;
if ( !m_sfxLength )
goto LABEL_11;
}
SetupTriggerPopup::setMaxSliderValue(a1, (float)m_sfxLength, 408);
SetupTriggerPopup::setMaxSliderValue(a1, (float)(unsigned int)a1->m_sfxLength, 410);
SetupTriggerPopup::updateSlider(a1, 408);
SetupTriggerPopup::updateSlider(a1, 410);
LABEL_11:
SetupSFXPopup::updateLength(a1);
a1->m_sfxWidget->setVisible(a1->m_sfxWidget, a1->m_page <= 1);
v14 = (void *)(v24 - 24);
if ( (__int64 *)(v24 - 24) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v15 = (unsigned int *)(v24 - 8);
do
v16 = __ldaxr(v15);
while ( __stlxr(v16 - 1, v15) );
}
else
{
v16 = *(_DWORD *)(v24 - 8);
*(_DWORD *)(v24 - 8) = v16 - 1;
}
if ( v16 <= 0 )
operator delete(v14);
}
}
}
}
}