//
// LevelEditorLayer::updateCustomSFXMappings from 0x1403f3c30 to 0x1403f403c (1036 bytes)
//
// 4 xrefs:
// > LevelEditorLayer::saveLevel @ 0x1403ff22d
// > LevelEditorLayer::doAutoSave @ 0x14040921d
// > LevelEditorLayer::doAutoBackup @ 0x140409675
// > ??> @ 0x140925478
//
// 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:31:49 +0000
//
// Hidden C++ exception states: #wind=8
void __fastcall LevelEditorLayer::updateCustomSFXMappings(__int64 a1)
{
__int64 v1; // rsi
_QWORD *v2; // rdi
__int64 v3; // rcx
_QWORD *v4; // rbx
void *v5; // rcx
bool GameVariable; // bl
__int64 v7; // rcx
void **v8; // r9
__int64 v9; // rdx
__int64 v10; // rcx
__int64 v11; // r14
int CustomSFXCount; // eax
__int64 v13; // rcx
__int64 v14; // rax
_QWORD *v15; // rax
_QWORD *v16; // rdi
_QWORD *v17; // rbx
void *v18; // rcx
void *v19; // rcx
void *v20; // [rsp+30h] [rbp-19h]
void *v21; // [rsp+30h] [rbp-19h]
void *v22; // [rsp+30h] [rbp-19h]
void *v23; // [rsp+30h] [rbp-19h]
void *v24; // [rsp+30h] [rbp-19h]
void *v25; // [rsp+30h] [rbp-19h]
_QWORD *v26; // [rsp+38h] [rbp-11h] BYREF
__int64 v27; // [rsp+40h] [rbp-9h]
void *Block[2]; // [rsp+48h] [rbp-1h] BYREF
__int64 v29; // [rsp+58h] [rbp+Fh]
_BYTE v30[32]; // [rsp+60h] [rbp+17h] BYREF
v1 = *(_QWORD *)(a1 + 3528);
if ( v1 )
{
*(_OWORD *)Block = 0;
v29 = 0;
LevelEditorLayer::getSFXUsagePairs(a1, (__int64)Block);
v27 = 0;
v2 = operator new(0x20u);
*v2 = v2;
v2[1] = v2;
v2[2] = v2;
*((_WORD *)v2 + 12) = 257;
v26 = v2;
v3 = qword_14090BFD0;
if ( *(_DWORD *)(v1 + 696) )
{
if ( !qword_14090BFD0 )
{
v20 = operator new(0x6E8u);
qword_14090BFD0 = GameManager::GameManager((__int64)v20);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_14090BFD0 + 72LL))(qword_14090BFD0);
v2 = v26;
v3 = qword_14090BFD0;
}
if ( *(_DWORD *)(v1 + 696) == *(_DWORD *)(v3 + 692) - *(_DWORD *)(v3 + 696) && &v26 != (_QWORD **)(v1 + 704) )
{
v4 = (_QWORD *)v2[1];
while ( !*((_BYTE *)v4 + 25) )
{
sub_1400BD500((__int64)&v26, (__int64)&v26, v4[2]);
v5 = v4;
v4 = (_QWORD *)*v4;
j_j_free(v5);
}
v2[1] = v2;
*v2 = v2;
v2[2] = v2;
v27 = 0;
sub_1400BD880(&v26, (_QWORD *)(v1 + 704));
v3 = qword_14090BFD0;
}
}
if ( !v3 )
{
v21 = operator new(0x6E8u);
qword_14090BFD0 = GameManager::GameManager((__int64)v21);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_14090BFD0 + 72LL))(qword_14090BFD0);
v3 = qword_14090BFD0;
}
GameVariable = GameManager::getGameVariable(v3, "0233");
v7 = qword_14090C070;
if ( !qword_14090C070 )
{
v22 = operator new(0x3D0u);
qword_14090C070 = MusicDownloadManager::MusicDownloadManager(v22);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_14090C070 + 72LL))(qword_14090C070);
v7 = qword_14090C070;
}
v8 = (void **)&v26;
if ( !GameVariable )
v8 = nullptr;
MusicDownloadManager::rebuildCustomSFXMappings(v7, Block, v1 + 648, v8);
if ( *(_DWORD *)(v1 + 696) )
{
v9 = qword_14090BFD0;
if ( !qword_14090BFD0 )
{
v23 = operator new(0x6E8u);
qword_14090BFD0 = GameManager::GameManager((__int64)v23);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_14090BFD0 + 72LL))(qword_14090BFD0);
v9 = qword_14090BFD0;
}
if ( *(_DWORD *)(v1 + 696) == *(_DWORD *)(v9 + 692) - *(_DWORD *)(v9 + 696) && *(_QWORD *)(v1 + 712) )
{
v10 = qword_14090C070;
if ( !qword_14090C070 )
{
v24 = operator new(0x3D0u);
qword_14090C070 = MusicDownloadManager::MusicDownloadManager(v24);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_14090C070 + 72LL))(qword_14090C070);
v10 = qword_14090C070;
}
v11 = v1 + 704;
CustomSFXCount = MusicDownloadManager::getCustomSFXCount(v10, v1 + 704);
if ( CustomSFXCount <= 0 || CustomSFXCount > 1000 )
{
*(_DWORD *)(v1 + 720) = (CustomSFXCount <= 1000) + 1;
v15 = (_QWORD *)(v1 + 664);
*(_QWORD *)(v1 + 680) = 0;
if ( *(_QWORD *)(v1 + 688) > 0xFu )
v15 = (_QWORD *)*v15;
*(_BYTE *)v15 = 0;
*(_DWORD *)(v1 + 696) = 0;
v16 = *(_QWORD **)v11;
v17 = *(_QWORD **)(*(_QWORD *)v11 + 8LL);
while ( !*((_BYTE *)v17 + 25) )
{
sub_1400BD500(v1 + 704, v1 + 704, v17[2]);
v18 = v17;
v17 = (_QWORD *)*v17;
j_j_free(v18);
}
v16[1] = v16;
*v16 = v16;
v16[2] = v16;
*(_QWORD *)(v1 + 712) = 0;
}
else
{
v13 = qword_14090C070;
if ( !qword_14090C070 )
{
v25 = operator new(0x3D0u);
qword_14090C070 = MusicDownloadManager::MusicDownloadManager(v25);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_14090C070 + 72LL))(qword_14090C070);
v13 = qword_14090C070;
}
v14 = MusicDownloadManager::encodeCustomSFX(v13, v30, v1 + 704);
sub_140059C40(v1 + 664, v14);
sub_14003D310((__int64)v30);
}
}
}
sub_1400BD560((void **)&v26, (__int64)&v26);
v19 = Block[0];
if ( Block[0] )
{
if ( ((v29 - (unsigned __int64)Block[0]) & 0xFFFFFFFFFFFFFFF8uLL) >= 0x1000 )
{
v19 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v19 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v19);
}
}
}