//
// write_text_utf8_nolock from 0x1801400f0 to 0x180140260 (368 bytes)
//
// 2 xrefs:
// > _write_nolock @ 0x180140546
// > ??> @ 0x180203bfc
//
// 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 10:55:04 +0000
//
__int64 __fastcall write_text_utf8_nolock(__int64 a1, int a2, WCHAR *a3, unsigned int a4)
{
unsigned __int64 v5; // r14
int v6; // r15d
WCHAR *v7; // rdi
void *v8; // r12
bool v9; // cf
WCHAR *v10; // rax
WCHAR v11; // cx
unsigned int v12; // ebp
unsigned int v13; // esi
DWORD NumberOfBytesWritten; // [rsp+40h] [rbp-1458h] BYREF
WCHAR v16[852]; // [rsp+50h] [rbp-1448h] BYREF
char v17; // [rsp+6F8h] [rbp-DA0h] BYREF
struct _OVERLAPPED Overlapped; // [rsp+700h] [rbp-D98h] BYREF
v5 = (unsigned __int64)a3 + a4;
v6 = (int)a3;
v7 = a3;
v8 = *(void **)(qword_1801F5160[(__int64)a2 >> 6] + 72LL * (a2 & 0x3F) + 40);
*(_QWORD *)a1 = 0;
v9 = (unsigned __int64)a3 < v5;
*(_DWORD *)(a1 + 8) = 0;
LABEL_2:
if ( v9 )
{
v10 = v16;
do
{
if ( (unsigned __int64)v7 >= v5 )
break;
v11 = *v7++;
if ( v11 == 10 )
*v10++ = 13;
*v10++ = v11;
}
while ( v10 < (WCHAR *)&v17 );
v12 = _acrt_WideCharToMultiByte(0xFDE9u, 0, v16, v10 - v16, (CHAR *)&Overlapped, 3413, nullptr, nullptr);
if ( v12 )
{
v13 = 0;
while ( WriteFile(v8, (char *)&Overlapped + v13, v12 - v13, &NumberOfBytesWritten, nullptr) )
{
v13 += NumberOfBytesWritten;
if ( v13 >= v12 )
{
*(_DWORD *)(a1 + 4) = (_DWORD)v7 - v6;
v9 = (unsigned __int64)v7 < v5;
goto LABEL_2;
}
}
}
*(_DWORD *)a1 = GetLastError();
}
return a1;
}