//
// GJKeybindManager::exportBindingsToFile from 0x14038bfb0 to 0x14038c58e (1502 bytes)
//
// 2 xrefs:
// > KeybindingsSettingsPopup::onExport @ 0x1403d949a
// > ??> @ 0x140922d78
//
// 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:09 +0000
//
// Hidden C++ exception states: #wind=15
__int64 __fastcall GJKeybindManager::exportBindingsToFile(__int64 a1)
{
_BYTE *v2; // r9
unsigned int v3; // r8d
_QWORD *v4; // rbx
_BYTE *v5; // r9
unsigned int v6; // r8d
_QWORD *v7; // rax
__int64 v8; // rdx
_QWORD *v9; // rax
__int64 v10; // rdx
void *v11; // rcx
void *v12; // rcx
void *v13; // rcx
void *v14; // rcx
__int64 v15; // rdx
__int64 v16; // rcx
__int64 v17; // r8
__int64 v18; // r9
__int64 v19; // rax
BOOL SaveFileNameA; // ebx
__int64 v21; // rdx
__int64 v22; // rcx
__int64 v23; // r8
__int64 v24; // r9
cocos2d::CCEGLView *v25; // rax
unsigned int v26; // edi
char v27; // bl
size_t v28; // r8
void *v29; // rcx
const char *v30; // rcx
FILE *v31; // rax
FILE *v32; // rsi
void **v33; // rcx
size_t v34; // rax
bool v35; // bl
char *v36; // rcx
struct tagOFNA v38; // [rsp+40h] [rbp-C0h] BYREF
void *Src[2]; // [rsp+E0h] [rbp-20h] BYREF
__m128i v40; // [rsp+F0h] [rbp-10h]
char *FileName[2]; // [rsp+100h] [rbp+0h] BYREF
__int64 v42; // [rsp+110h] [rbp+10h]
unsigned __int64 v43; // [rsp+118h] [rbp+18h]
void *v44[2]; // [rsp+120h] [rbp+20h] BYREF
__m128i si128; // [rsp+130h] [rbp+30h]
void *Buffer[2]; // [rsp+140h] [rbp+40h] BYREF
size_t ElementCount; // [rsp+150h] [rbp+50h]
unsigned __int64 v48; // [rsp+158h] [rbp+58h]
void *Block[2]; // [rsp+160h] [rbp+60h] BYREF
__int128 v50; // [rsp+170h] [rbp+70h]
void *v51[2]; // [rsp+180h] [rbp+80h] BYREF
__int128 v52; // [rsp+190h] [rbp+90h]
_QWORD v53[4]; // [rsp+1A0h] [rbp+A0h] BYREF
_BYTE v54[53]; // [rsp+1C0h] [rbp+C0h] BYREF
_BYTE v55[24]; // [rsp+1F5h] [rbp+F5h] BYREF
_BYTE v56[3]; // [rsp+20Dh] [rbp+10Dh] BYREF
char Destination[272]; // [rsp+210h] [rbp+110h] BYREF
v2 = v55;
v3 = 2;
do
{
*--v2 = v3 % 0xA + 48;
v3 /= 0xAu;
}
while ( v3 );
*(_OWORD *)v44 = 0;
si128 = 0;
if ( v2 == v55 )
{
si128 = _mm_load_si128((const __m128i *)&Size);
LOBYTE(v44[0]) = 0;
}
else
{
sub_14003D230(v44, v2, v55 - v2);
}
v4 = (_QWORD *)GJKeybindManager::buildBindsBlob(a1, (__int64)v54);
v5 = v56;
v6 = 1;
do
{
*--v5 = v6 % 0xA + 48;
v6 /= 0xAu;
}
while ( v6 );
*(_OWORD *)Src = 0;
v40 = 0;
if ( v5 == v56 )
{
v40 = _mm_load_si128((const __m128i *)&Size);
LOBYTE(Src[0]) = 0;
}
else
{
sub_14003D230(Src, v5, v56 - v5);
}
v7 = sub_140044D80(Src, byte_140752308, 1u);
*(_OWORD *)v51 = *(_OWORD *)v7;
v52 = *((_OWORD *)v7 + 1);
v7[2] = 0;
v7[3] = 15;
*(_BYTE *)v7 = 0;
sub_140076160((char *)v53, v8, v51, v4);
v9 = sub_140044D80(v53, byte_140752308, 1u);
*(_OWORD *)Block = *(_OWORD *)v9;
v50 = *((_OWORD *)v9 + 1);
v9[2] = 0;
v9[3] = 15;
*(_BYTE *)v9 = 0;
sub_140076160((char *)Buffer, v10, Block, v44);
if ( *((_QWORD *)&v50 + 1) > 0xFu )
{
v11 = Block[0];
if ( (unsigned __int64)(*((_QWORD *)&v50 + 1) + 1LL) >= 0x1000 )
{
v11 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v11 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v11);
}
sub_14003D310((__int64)v53);
if ( *((_QWORD *)&v52 + 1) > 0xFu )
{
v12 = v51[0];
if ( (unsigned __int64)(*((_QWORD *)&v52 + 1) + 1LL) >= 0x1000 )
{
v12 = *((void **)v51[0] - 1);
if ( (unsigned __int64)((char *)v51[0] - (char *)v12 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v12);
}
if ( v40.m128i_i64[1] > 0xFuLL )
{
v13 = Src[0];
if ( (unsigned __int64)(v40.m128i_i64[1] + 1) >= 0x1000 )
{
v13 = *((void **)Src[0] - 1);
if ( (unsigned __int64)((char *)Src[0] - (char *)v13 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v13);
}
v40 = _mm_load_si128((const __m128i *)&Size);
LOBYTE(Src[0]) = 0;
sub_14003D310((__int64)v54);
if ( si128.m128i_i64[1] > 0xFuLL )
{
v14 = v44[0];
if ( (unsigned __int64)(si128.m128i_i64[1] + 1) >= 0x1000 )
{
v14 = *((void **)v44[0] - 1);
if ( (unsigned __int64)((char *)v44[0] - (char *)v14 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v14);
}
*(_OWORD *)FileName = 0;
v43 = 15;
v40 = _mm_load_si128((const __m128i *)&xmmword_1408365E0);
strcpy((char *)Src, "keybinds.gdkb");
HIWORD(Src[1]) = 0;
v42 = 0;
LOBYTE(FileName[0]) = 0;
memset(Destination, 0, 0x104u);
strncpy(Destination, (const char *)Src, 0x103u);
memset(&v38.lStructSize + 1, 0, 148);
v38.lStructSize = 152;
v19 = cocos2d::CCEGLView::sharedOpenGLView(v16, v15, v17, v18);
v38.hwndOwner = (HWND)sub_140675620(*(_QWORD *)(v19 + 200));
v38.lpstrFilter = "GD Keybind Files (*.gdkb)";
v38.lpstrFile = Destination;
v38.nMaxFile = 260;
v38.lpstrTitle = "Export Keybinds";
v38.Flags = 10;
v38.lpstrDefExt = "gdkb";
SaveFileNameA = GetSaveFileNameA(&v38);
v25 = (cocos2d::CCEGLView *)cocos2d::CCEGLView::sharedOpenGLView(v22, v21, v23, v24);
cocos2d::CCEGLView::clearQueuedInput(v25);
v26 = -1;
if ( SaveFileNameA )
{
v28 = -1;
do
++v28;
while ( Destination[v28] );
sub_1400405A0((void **)FileName, Destination, v28);
v27 = 0;
}
else
{
v27 = 1;
}
if ( v40.m128i_i64[1] > 0xFuLL )
{
v29 = Src[0];
if ( (unsigned __int64)(v40.m128i_i64[1] + 1) >= 0x1000 )
{
v29 = *((void **)Src[0] - 1);
if ( (unsigned __int64)((char *)Src[0] - (char *)v29 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v29);
}
if ( v27 )
{
v26 = 0;
}
else
{
v30 = (const char *)FileName;
if ( v43 > 0xF )
v30 = FileName[0];
v31 = fopen(v30, "w");
v32 = v31;
if ( v31 )
{
v33 = Buffer;
if ( v48 > 0xF )
v33 = (void **)Buffer[0];
v34 = fwrite(v33, 1u, ElementCount, v31);
v35 = v34 == ElementCount;
fclose(v32);
v26 = 2 * v35 - 1;
}
}
if ( v43 > 0xF )
{
v36 = FileName[0];
if ( v43 + 1 >= 0x1000 )
{
v36 = *((char **)FileName[0] - 1);
if ( (unsigned __int64)(FileName[0] - v36 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v36);
}
v42 = 0;
v43 = 15;
LOBYTE(FileName[0]) = 0;
sub_14003D310((__int64)Buffer);
return v26;
}