//
// MusicDownloadManager::pathForSongFolder from 0x10058fbe0 to 0x10058fe1f (575 bytes)
//
// 3 xrefs:
// > MusicDownloadManager::pathForSong @ 0x10058eaf1
// > MusicDownloadManager::onDownloadMusicLibraryCompleted @ 0x100591ce7
// > MusicDownloadManager::parseMusicLibrary @ 0x100591f27
//
// 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
//
std::string *__fastcall MusicDownloadManager::pathForSongFolder(std::string *this, __int64 a2, int a3)
{
unsigned __int64 v4; // r9
unsigned __int64 v5; // r11
unsigned __int64 v6; // rdi
__int64 **v7; // rax
__int64 *v8; // r10
unsigned __int64 v9; // r9
const std::string::value_type *v10; // rsi
__int64 v11; // rax
unsigned __int64 v12; // rax
GameManager *v13; // rax
cocos2d::CCFileUtils *v14; // rax
cocos2d::CCFileUtils *v15; // rax
__int128 v17; // [rsp+8h] [rbp-28h] BYREF
std::string::size_type v18; // [rsp+18h] [rbp-18h]
*(_WORD *)&this->__r_.__value_.__l.0 = 0;
v4 = *(_QWORD *)(a2 + 528);
if ( v4 )
{
v5 = (0x101010101010101LL
* ((((v4 - ((v4 >> 1) & 0x5555555555555555LL)) & 0x3333333333333333LL)
+ (((v4 - ((v4 >> 1) & 0x5555555555555555LL)) >> 2) & 0x3333333333333333LL)
+ ((((v4 - ((v4 >> 1) & 0x5555555555555555LL)) & 0x3333333333333333LL)
+ (((v4 - ((v4 >> 1) & 0x5555555555555555LL)) >> 2) & 0x3333333333333333LL)) >> 4))
& 0xF0F0F0F0F0F0F0FLL)) >> 56;
if ( v5 <= 1 )
{
v6 = a3 & (v4 - 1);
v7 = *(__int64 ***)(*(_QWORD *)(a2 + 520) + 8 * v6);
if ( !v7 )
goto LABEL_29;
goto LABEL_9;
}
v6 = a3;
if ( v4 <= a3 )
{
if ( !((v4 | a3) >> 32) )
{
v6 = a3 % (unsigned int)v4;
v7 = *(__int64 ***)(*(_QWORD *)(a2 + 520) + 8 * v6);
if ( !v7 )
goto LABEL_29;
goto LABEL_9;
}
v6 = a3 % v4;
}
v7 = *(__int64 ***)(*(_QWORD *)(a2 + 520) + 8 * v6);
if ( !v7 )
goto LABEL_29;
LABEL_9:
v8 = *v7;
if ( !*v7 )
goto LABEL_29;
if ( (unsigned int)v5 < 2 )
{
v9 = v4 - 1;
v10 = "songs/";
while ( 1 )
{
v11 = v8[1];
if ( v11 == a3 )
{
if ( *((_DWORD *)v8 + 4) == a3 )
goto LABEL_33;
}
else if ( (v9 & v11) != v6 )
{
goto LABEL_29;
}
v8 = (__int64 *)*v8;
if ( !v8 )
goto LABEL_29;
}
}
v10 = "songs/";
while ( 1 )
{
v12 = v8[1];
if ( v12 == a3 )
{
if ( *((_DWORD *)v8 + 4) == a3 )
goto LABEL_33;
goto LABEL_19;
}
if ( v12 < v4 )
goto LABEL_24;
if ( (v4 | v12) >> 32 )
break;
if ( (unsigned int)v12 % (unsigned int)v4 != v6 )
goto LABEL_29;
LABEL_19:
v8 = (__int64 *)*v8;
if ( !v8 )
goto LABEL_29;
}
v12 %= v4;
LABEL_24:
if ( v12 != v6 )
goto LABEL_29;
goto LABEL_19;
}
LABEL_29:
v13 = GameManager::sharedState();
if ( GameManager::getGameVariable(v13, "0033") )
{
v14 = cocos2d::CCFileUtils::sharedFileUtils();
((void (__fastcall *)(__int128 *, cocos2d::CCFileUtils *))v14->isAbsolutePath)(&v17, v14);
if ( (*(_BYTE *)&this->__r_.__value_.__s.0 & 1) != 0 )
operator delete(this->__r_.__value_.__l.__data_);
this->__r_.__value_.__r.__words[2] = v18;
*(_OWORD *)&this->__r_.__value_.__l.0 = v17;
v10 = "Resources\\";
LABEL_33:
std::string::append(this, v10);
}
else
{
v15 = cocos2d::CCFileUtils::sharedFileUtils();
((void (__fastcall *)(__int128 *, cocos2d::CCFileUtils *))v15->init)(&v17, v15);
if ( (*(_BYTE *)&this->__r_.__value_.__s.0 & 1) != 0 )
operator delete(this->__r_.__value_.__l.__data_);
this->__r_.__value_.__r.__words[2] = v18;
*(_OWORD *)&this->__r_.__value_.__l.0 = v17;
}
return this;
}