From 481f23eeeff555b63e8057c4d90918da2385d094 Mon Sep 17 00:00:00 2001 From: Inori Date: Fri, 6 Sep 2019 16:51:02 -0400 Subject: [PATCH] Add fake-api GetUserName --- README.md | 1 + binding/miniffi-binding.cpp | 1 + src/fake-api.cpp | 10 ++++++++++ src/fake-api.h | 5 ++++- 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0bb5d7f6..41bdd669 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,7 @@ mkxp-z provides limited support for some WinAPI functions that would normally br * `ReleaseCapture`: No-op. * `GetPrivateProfileString`: Emulated with MKXP's ini code. * `GetUserDefaultLangId`: Checks for JP, EN, FR, IT, DE, ES, KO, PT and ZH. Returns English (`0x09`) if the locale can't be determined. Doesn't handle sublanguages. +* `GetUserName`: Returns the `$USER` environment variable, or `Ditto` if it doesn't exist. ## Midi music diff --git a/binding/miniffi-binding.cpp b/binding/miniffi-binding.cpp index 9fddfa09..8e6c71ef 100644 --- a/binding/miniffi-binding.cpp +++ b/binding/miniffi-binding.cpp @@ -74,6 +74,7 @@ MiniFFI_GetFunctionHandle(void *libhandle, const char *func) CAPTURE(ShowCursor); CAPTURE(GetPrivateProfileString); CAPTURE(GetUserDefaultLangID); + CAPTURE(GetUserName); #endif #endif if (!libhandle) return 0; diff --git a/src/fake-api.cpp b/src/fake-api.cpp index c08fa047..dbdaebaa 100644 --- a/src/fake-api.cpp +++ b/src/fake-api.cpp @@ -460,4 +460,14 @@ MKXP_GetUserDefaultLangID(void) return 0x09; } +PREFABI BOOL +MKXP_GetUserName(LPSTR lpBuffer, LPDWORD pcbBuffer) +{ + if (*pcbBuffer < 2) return false; + char *username = getenv("USER"); + strncpy(lpBuffer, (username) ? username : "ditto", *pcbBuffer); + lpBuffer[0] = toupper(lpBuffer[0]); + return true; +} + #endif diff --git a/src/fake-api.h b/src/fake-api.h index f38757f7..0973c37a 100644 --- a/src/fake-api.h +++ b/src/fake-api.h @@ -13,7 +13,7 @@ #ifndef __WIN32__ typedef unsigned int DWORD, UINT, *LPDWORD; -typedef char BYTE, *LPCSTR, *LPCTSTR, *LPTSTR, *PBYTE; +typedef char BYTE, *LPSTR, *LPCSTR, *LPCTSTR, *LPTSTR, *PBYTE; typedef short SHORT; typedef int LONG; typedef bool BOOL; @@ -147,4 +147,7 @@ MKXP_GetPrivateProfileString(LPCTSTR lpAppName, PREFABI short MKXP_GetUserDefaultLangID(void); +PREFABI BOOL +MKXP_GetUserName(LPSTR lpBuffer, LPDWORD pcbBuffer); + #endif