//
// sub_1800C7270 from 0x1800c7270 to 0x1800c76be (1102 bytes)
//
// 4 xrefs:
// > sub_1800C6FC0 @ 0x1800c6fc0
// > ??> @ 0x18018ad04
// > ??> @ 0x18018ad38
// > ??> @ 0x1801fe0a0
//
// 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
//
__int64 __fastcall sub_1800C7270(__int64 a1)
{
struct _RTL_CRITICAL_SECTION *v2; // rcx
unsigned int v3; // ebx
__int64 v4; // rdx
__int64 v5; // r9
__int64 v6; // r15
int v7; // r8d
__int64 v8; // rdx
int v9; // r9d
__int64 v10; // rax
_DWORD *v11; // rdx
__int64 v12; // rax
__int64 v13; // rdi
__int64 v14; // rsi
char v15; // r14
__int64 v16; // rsi
__int64 v17; // rcx
__int64 v18; // rdx
__int64 v19; // rdi
__int64 v20; // rax
__int64 v21; // rcx
__int64 v22; // rcx
__int64 v23; // rdx
__int64 v24; // rcx
__int64 v25; // rax
__int64 result; // rax
__int64 v27; // rcx
__int64 v28; // [rsp+70h] [rbp+28h] BYREF
v2 = *(struct _RTL_CRITICAL_SECTION **)(a1 + 360);
v3 = 0;
v28 = 0;
FMOD_OS_CriticalSection_Enter(v2);
v4 = *(_QWORD *)(a1 + 336);
if ( v4 != a1 + 336 )
{
v28 = *(_QWORD *)(v4 + 16);
**(_QWORD **)(v4 + 8) = *(_QWORD *)v4;
*(_QWORD *)(*(_QWORD *)v4 + 8LL) = *(_QWORD *)(v4 + 8);
*(_QWORD *)(v4 + 8) = v4;
*(_QWORD *)v4 = v4;
}
FMOD_OS_CriticalSection_Leave(*(struct _RTL_CRITICAL_SECTION **)(a1 + 360));
if ( !v28 )
return 0;
v6 = *(_QWORD *)(v28 + 216);
switch ( *(_DWORD *)(v28 + 272) )
{
case 1:
v7 = *(_DWORD *)(v28 + 44);
v8 = *(_QWORD *)(v28 + 264);
v9 = *(_DWORD *)(v8 + 8);
v10 = v8 + 56;
if ( (v7 & 0x10000800) != 0 )
{
if ( !*(_BYTE *)(v8 + 280) )
v10 = 0;
v3 = sub_1800FE610(v6, *(_QWORD *)(v8 + 48), v7, v9, *(_DWORD *)(v8 + 12), v10, 1, (__int64)&v28);
}
else
{
if ( !*(_BYTE *)(v8 + 280) )
v10 = 0;
v3 = sub_1800FE610(v6, *(_QWORD *)v8, v7, v9, *(_DWORD *)(v8 + 12), v10, 1, (__int64)&v28);
v11 = **(_DWORD ***)(v28 + 264);
if ( v11 )
{
sub_1800B6AA0(*((_QWORD *)off_1801AED20 + 52), v11);
**(_QWORD **)(v28 + 264) = 0;
}
}
if ( !v3 )
{
v12 = *(_QWORD *)(v28 + 264);
if ( *(_BYTE *)(v12 + 280) )
*(_QWORD *)(v28 + 200) = *(_QWORD *)(v12 + 160);
}
break;
case 7:
v13 = v28;
while ( (*(_DWORD *)(v13 + 88) & 0x440) == 0 )
FMOD_OS_Time_Sleep(0xAu);
if ( (*(_DWORD *)(v13 + 88) & 0x40) != 0 )
{
v14 = *(_QWORD *)(v28 + 216);
if ( v14 )
{
sub_1801021C0(*(_QWORD *)(v28 + 216), 8);
*(_DWORD *)(*(_QWORD *)(v13 + 376) + 60LL) &= ~0x4000u;
sub_180102300(v14, 8);
}
else
{
*(_DWORD *)(*(_QWORD *)(v13 + 376) + 60LL) &= ~0x4000u;
}
}
else
{
LOBYTE(v5) = 1;
v3 = (*(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, __int64))(**(_QWORD **)(v13 + 376) + 208LL))(
*(_QWORD *)(v13 + 376),
*(unsigned int *)(*(_QWORD *)(v28 + 264) + 284LL),
*(unsigned int *)(*(_QWORD *)(v28 + 264) + 288LL),
v5);
v15 = 0;
v16 = *(_QWORD *)(v28 + 216);
if ( v16 )
{
sub_1801021C0(*(_QWORD *)(v28 + 216), 8);
v15 = 1;
}
*(_DWORD *)(*(_QWORD *)(v13 + 376) + 60LL) &= ~0x4000u;
if ( v3 )
{
if ( v3 == 30 )
v3 = 0;
}
else
{
v17 = *(_QWORD *)(v13 + 376);
if ( *(_QWORD *)(v17 + 192) )
{
v18 = *(_DWORD *)(v17 + 60) >> 5;
LOBYTE(v18) = (*(_DWORD *)(v17 + 60) & 0x20) != 0;
(*(void (__fastcall **)(__int64, __int64))(*(_QWORD *)v17 + 80LL))(v17, v18);
}
}
if ( v15 && v16 )
sub_180102300(v16, 8);
}
break;
case 5:
v19 = v28;
v3 = sub_1800E1350(v28, *(unsigned int *)(v28 + 192));
if ( !v3 )
{
v3 = sub_1800DD7C0(v19, 0, 2);
if ( !v3 )
v3 = sub_1800DD5E0(v19);
}
break;
}
*(_DWORD *)(*(_QWORD *)(v28 + 264) + 292LL) = v3;
v20 = v28;
v21 = *(_QWORD *)(v28 + 184);
if ( v21 )
{
*(_BYTE *)(v21 + 92) = 1;
v20 = v28;
}
*(_BYTE *)(v20 + 92) = 1;
*(_DWORD *)(v28 + 272) = v3 != 0 ? 2 : 0;
v22 = v28;
if ( *(_QWORD *)(v28 + 184) )
{
*(_DWORD *)(*(_QWORD *)(v28 + 184) + 272LL) = *(_DWORD *)(v28 + 272);
v22 = v28;
}
if ( *(_QWORD *)(v22 + 168) )
{
v23 = *(unsigned int *)(v22 + 272);
*(_DWORD *)(*(_QWORD *)(v28 + 168) + 272LL) = v23;
LABEL_48:
v24 = v28;
goto LABEL_49;
}
if ( !(**(unsigned __int8 (__fastcall ***)(__int64))v22)(v22) )
goto LABEL_48;
v24 = v28;
if ( *(_DWORD *)(v28 + 176) == 1 && **(_QWORD **)(v28 + 160) )
{
v23 = *(unsigned int *)(v28 + 272);
*(_DWORD *)(**(_QWORD **)(v28 + 160) + 272LL) = v23;
goto LABEL_48;
}
LABEL_49:
v25 = *(_QWORD *)(v24 + 264);
if ( !*(_BYTE *)(v25 + 280) || !*(_QWORD *)(v25 + 128) )
goto LABEL_54;
LOBYTE(v23) = 1;
result = sub_180102260(v6, v23);
if ( !(_DWORD)result )
{
(*(void (__fastcall **)(__int64, _QWORD))(*(_QWORD *)(v28 + 264) + 128LL))(v28, v3);
result = sub_180102340(v6);
if ( !(_DWORD)result )
{
v24 = v28;
LABEL_54:
*(_BYTE *)(v24 + 92) = 0;
v27 = *(_QWORD *)(v28 + 184);
if ( v27 )
*(_BYTE *)(v27 + 92) = 0;
return 0;
}
}
return result;
}