//
// sub_1004BEBC0 from 0x1004bebc0 to 0x1004bef5b (923 bytes)
//
// 1 xrefs:
// > sub_1004BEB10 @ 0x1004beb73
//
// 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 12:31:04 +0000
//
__int64 __fastcall sub_1004BEBC0(__int64 a1)
{
NSOpenPanel *v1; // r14
id v2; // rax
NSString *v3; // rax
NSString *v4; // rbx
id v5; // rax
id v6; // rax
void *i; // rbx
id v8; // rax
const char *v9; // r14
size_t v10; // rax
size_t v11; // r12
char *v12; // r13
__int64 v13; // rax
size_t v14; // r15
__int128 v16; // [rsp+0h] [rbp-140h] BYREF
__int128 v17; // [rsp+10h] [rbp-130h]
__int128 v18; // [rsp+20h] [rbp-120h]
__int128 v19; // [rsp+30h] [rbp-110h]
__int64 v20; // [rsp+40h] [rbp-100h]
SEL v21; // [rsp+48h] [rbp-F8h]
__int64 v22; // [rsp+50h] [rbp-F0h]
SEL v23; // [rsp+58h] [rbp-E8h]
__int64 v24; // [rsp+60h] [rbp-E0h]
id obj; // [rsp+68h] [rbp-D8h]
_QWORD __dst[2]; // [rsp+70h] [rbp-D0h] BYREF
void *__p; // [rsp+80h] [rbp-C0h]
id v28; // [rsp+88h] [rbp-B8h]
_BYTE v29[128]; // [rsp+90h] [rbp-B0h] BYREF
v1 = +[NSOpenPanel openPanel](&OBJC_CLASS___NSOpenPanel, "openPanel");
v2 = sub_1004BE490(*(char **)(a1 + 32));
-[NSOpenPanel setAllowedFileTypes:](v1, "setAllowedFileTypes:", v2);
-[NSOpenPanel setCanChooseFiles:](v1, "setCanChooseFiles:", 1);
-[NSOpenPanel setCanChooseDirectories:](v1, "setCanChooseDirectories:", 0);
-[NSOpenPanel setAllowsMultipleSelection:](v1, "setAllowsMultipleSelection:", 1);
v24 = a1;
if ( *(_QWORD *)(a1 + 40) )
{
v3 = +[NSString stringWithUTF8String:](&OBJC_CLASS___NSString, "stringWithUTF8String:");
if ( v3 )
{
v4 = v3;
-[NSOpenPanel setTitle:](v1, "setTitle:", v3);
-[NSOpenPanel setMessage:](v1, "setMessage:", v4);
}
}
v5 = +[EAGLView sharedEGLView](&OBJC_CLASS___EAGLView, "sharedEGLView");
v6 = objc_msgSend(v5, "window");
if ( v6 )
{
-[NSOpenPanel beginSheetModalForWindow:completionHandler:](
v1,
"beginSheetModalForWindow:completionHandler:",
v6,
&stru_100B5AA78);
if ( objc_msgSend(NSApp, "runModalForWindow:", v1) != (id)1 )
return __stack_chk_guard;
}
else if ( -[NSOpenPanel runModal](v1, "runModal") != (id)1 )
{
return __stack_chk_guard;
}
v19 = 0;
v18 = 0;
v17 = 0;
v16 = 0;
obj = -[NSOpenPanel URLs](v1, "URLs");
v28 = objc_msgSend(obj, "countByEnumeratingWithState:objects:count:", &v16, v29, 16);
if ( v28 )
{
v22 = *(_QWORD *)v17;
do
{
v21 = "path";
v23 = "UTF8String";
for ( i = nullptr; i != v28; i = (char *)i + 1 )
{
if ( *(_QWORD *)v17 != v22 )
objc_enumerationMutation(obj);
v8 = objc_msgSend(*(id *)(*((_QWORD *)&v16 + 1) + 8LL * (_QWORD)i), v21);
if ( v8 )
{
v20 = *(_QWORD *)(v24 + 48);
v9 = (const char *)objc_msgSend(v8, v23);
v10 = strlen(v9);
if ( v10 >= 0xFFFFFFFFFFFFFFF8LL )
sub_100003630();
v11 = v10;
if ( v10 >= 0x17 )
{
v13 = v10 | 7;
v14 = 26;
if ( (v11 | 7) != 0x17 )
v14 = v13 + 1;
v12 = (char *)operator new(v14);
__p = v12;
__dst[0] = v14 | 1;
__dst[1] = v11;
}
else
{
LOBYTE(__dst[0]) = 2 * v10;
v12 = (char *)__dst + 1;
if ( !v10 )
{
LABEL_23:
v12[v11] = 0;
sub_1001593B0(v20, (__int64)__dst);
if ( (__dst[0] & 1) != 0 )
operator delete(__p);
continue;
}
}
memmove(v12, v9, v11);
goto LABEL_23;
}
}
v28 = objc_msgSend(obj, "countByEnumeratingWithState:objects:count:", &v16, v29, 16);
}
while ( v28 );
}
return __stack_chk_guard;
}