//
// MusicDownloadManager::exportCustomSFXToFile from 0x140489310 to 0x140489618 (776 bytes)
//
// 3 xrefs:
// > SFXBrowser::onExportFile @ 0x14061e0e6
// > ??> @ 0x140928cdc
// > ??> @ 0x140928ce8
//
// This function is hookable on this platform (idp: pc, 32 bit: False, 64 bit: True!
//
// Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings
// Generated at Fri, 27 Nov 2026 11:32:48 +0000
//
// Hidden C++ exception states: #wind=5
__int64 __fastcall MusicDownloadManager::exportCustomSFXToFile(__int64 a1)
{
_QWORD *v2; // rax
unsigned __int8 v3; // bl
__int64 v4; // rdx
__int64 v5; // rcx
__int64 v6; // r8
__int64 v7; // r9
__int64 v8; // rax
BOOL SaveFileNameA; // ebx
__int64 v10; // rdx
__int64 v11; // rcx
__int64 v12; // r8
__int64 v13; // r9
cocos2d::CCEGLView *v14; // rax
char v15; // bl
size_t v16; // r8
void *v17; // rcx
const char *v18; // rcx
FILE *v19; // rax
FILE *v20; // rbx
void **v21; // rcx
char *v22; // rcx
struct tagOFNA v24; // [rsp+30h] [rbp-D0h] BYREF
char Source[16]; // [rsp+D0h] [rbp-30h] BYREF
__m128i si128; // [rsp+E0h] [rbp-20h]
char *FileName[2]; // [rsp+F0h] [rbp-10h] BYREF
__int64 v28; // [rsp+100h] [rbp+0h]
unsigned __int64 v29; // [rsp+108h] [rbp+8h]
void *Buffer[2]; // [rsp+110h] [rbp+10h] BYREF
size_t ElementCount; // [rsp+120h] [rbp+20h]
unsigned __int64 v32; // [rsp+128h] [rbp+28h]
char Destination[272]; // [rsp+130h] [rbp+30h] BYREF
*(_OWORD *)Source = 0;
v2 = operator new(0x20u);
*v2 = v2;
v2[1] = v2;
v2[2] = v2;
*((_WORD *)v2 + 12) = 257;
*(_QWORD *)Source = v2;
MusicDownloadManager::encodeCustomSFX(a1, Buffer, Source);
sub_1400BD560((void **)Source, (__int64)Source);
if ( ElementCount )
{
*(_OWORD *)FileName = 0;
v29 = 15;
si128 = _mm_load_si128((const __m128i *)&xmmword_140836600);
strcpy(Source, "customsfx.gdsfx");
v28 = 0;
LOBYTE(FileName[0]) = 0;
memset(Destination, 0, 0x104u);
strncpy(Destination, Source, 0x103u);
memset(&v24.lStructSize + 1, 0, 148);
v24.lStructSize = 152;
v8 = cocos2d::CCEGLView::sharedOpenGLView(v5, v4, v6, v7);
v24.hwndOwner = (HWND)sub_140675620(*(_QWORD *)(v8 + 200));
v24.lpstrFilter = "GD SFX Folder Files (*.gdsfx)";
v24.lpstrFile = Destination;
v24.nMaxFile = 260;
v24.lpstrTitle = "Export SFX Folders";
v24.Flags = 10;
v24.lpstrDefExt = "gdsfx";
SaveFileNameA = GetSaveFileNameA(&v24);
v14 = (cocos2d::CCEGLView *)cocos2d::CCEGLView::sharedOpenGLView(v11, v10, v12, v13);
cocos2d::CCEGLView::clearQueuedInput(v14);
if ( SaveFileNameA )
{
v16 = -1;
do
++v16;
while ( Destination[v16] );
sub_1400405A0((void **)FileName, Destination, v16);
v15 = 0;
}
else
{
v15 = 1;
}
if ( si128.m128i_i64[1] > 0xFuLL )
{
v17 = *(void **)Source;
if ( (unsigned __int64)(si128.m128i_i64[1] + 1) >= 0x1000 )
{
v17 = *(void **)(*(_QWORD *)Source - 8LL);
if ( (unsigned __int64)(*(_QWORD *)Source - (_QWORD)v17 - 8LL) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v17);
}
if ( v15 )
goto LABEL_20;
v18 = (const char *)FileName;
if ( v29 > 0xF )
v18 = FileName[0];
v19 = fopen(v18, "w");
v20 = v19;
if ( !v19 )
{
LABEL_20:
v3 = 0;
}
else
{
v21 = Buffer;
if ( v32 > 0xF )
v21 = (void **)Buffer[0];
fwrite(v21, 1u, ElementCount, v19);
fclose(v20);
v3 = 1;
}
if ( v29 > 0xF )
{
v22 = FileName[0];
if ( v29 + 1 >= 0x1000 )
{
v22 = *((char **)FileName[0] - 1);
if ( (unsigned __int64)(FileName[0] - v22 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v22);
}
v28 = 0;
v29 = 15;
LOBYTE(FileName[0]) = 0;
}
else
{
v3 = 0;
}
sub_14003D310((__int64)Buffer);
return v3;
}