diff --git a/binding/miniffi-binding.cpp b/binding/miniffi-binding.cpp index b749eeba..cc7c3a6f 100644 --- a/binding/miniffi-binding.cpp +++ b/binding/miniffi-binding.cpp @@ -64,6 +64,10 @@ MiniFFI_GetFunctionHandle(void *libhandle, const char *func) CAPTURE(LoadLibrary); CAPTURE(FreeLibrary); CAPTURE(GetAsyncKeyState); + CAPTURE(GetSystemPowerStatus); + CAPTURE(ShowWindow); + CAPTURE(SetWindowLong); + CAPTURE(GetSystemMetrics); #endif #endif if (!libhandle) return 0; diff --git a/src/fake-api.cpp b/src/fake-api.cpp index 4b4e8132..2d6dd54a 100644 --- a/src/fake-api.cpp +++ b/src/fake-api.cpp @@ -428,5 +428,111 @@ MKXP_GetAsyncKeyState(int vKey) return result; } +PREFABI BOOL +MKXP_GetSystemPowerStatus(LPSYSTEM_POWER_STATUS lpSystemPowerStatus) +{ + int seconds, percent; + SDL_PowerState ps; + ps = SDL_GetPowerInfo(&seconds, &percent); + + // Setting ACLineStatus + if (ps == SDL_POWERSTATE_UNKNOWN) + { + lpSystemPowerStatus->ACLineStatus = 0xFF; + } + else + { + lpSystemPowerStatus->ACLineStatus = + (ps == SDL_POWERSTATE_ON_BATTERY) ? 1 : 0; + } + + // Setting BatteryFlag + if (ps == SDL_POWERSTATE_ON_BATTERY) + { + if (percent == -1) + { + lpSystemPowerStatus->BatteryFlag = 0xFF; + } + else if (percent >= 33) + { + lpSystemPowerStatus->BatteryFlag = 1; + } + else if (4 < percent && percent < 33) + { + lpSystemPowerStatus->BatteryFlag = 2; + } + else + { + lpSystemPowerStatus->BatteryFlag = 4; + } + } + else if (ps == SDL_POWERSTATE_CHARGING) + { + lpSystemPowerStatus->BatteryFlag = 8; + } + else if (ps == SDL_POWERSTATE_NO_BATTERY) + { + lpSystemPowerStatus->BatteryFlag = (BYTE)128; + } + else + { + lpSystemPowerStatus->BatteryFlag = 0xFF; + } + + // Setting BatteryLifePercent + lpSystemPowerStatus->BatteryLifePercent = (percent != -1) ? (BYTE)percent : 0xFF; + + // Setting SystemStatusFlag + lpSystemPowerStatus->SystemStatusFlag = 0; + + // Setting BatteryLifeTime + lpSystemPowerStatus->BatteryLifeTime = seconds; + + // Setting BatteryFullLifeTime + lpSystemPowerStatus->BatteryFullLifeTime = -1; + + return true; +} + +PREFABI BOOL +MKXP_ShowWindow(HWND hWnd, int nCmdShow) +NOP_VAL(true); + +PREFABI LONG +MKXP_SetWindowLong(HWND hWnd, int nIndex, LONG dwNewLong) +NOP_VAL(DUMMY_VAL); + + +// This only currently supports getting screen width/height +// Not really motivated to do the other ones when I'll be +// extending Ruby at a later time anyway +PREFABI int +MKXP_GetSystemMetrics(int nIndex) +{ + SDL_DisplayMode dm; + int rc = SDL_GetDesktopDisplayMode( + SDL_GetWindowDisplayIndex(shState->sdlWindow()), + &dm + ); + if (rc) + { + switch (nIndex) { + case 0: + return dm.w; + break; + + case 1: + return dm.h; + break; + + default: + return -1; + break; + } + } + + return -1; +} + #endif diff --git a/src/fake-api.h b/src/fake-api.h index 69fafb78..554d2279 100644 --- a/src/fake-api.h +++ b/src/fake-api.h @@ -15,22 +15,33 @@ #ifndef __WIN32__ typedef unsigned int DWORD, UINT, *LPDWORD; -typedef char *LPCSTR, *PBYTE; +typedef char BYTE, *LPCSTR, *PBYTE; typedef short SHORT; typedef int LONG; typedef bool BOOL; +typedef void VOID, *LPVOID, *HANDLE, *HMODULE, *HWND; +typedef size_t SIZE_T; + typedef struct { LONG x; LONG y; } POINT, *LPPOINT; + typedef struct { LONG left; LONG top; LONG right; LONG bottom; } RECT, *PRECT, *NPRECT, *LPRECT; -typedef void VOID, *LPVOID, *HANDLE, *HMODULE, *HWND; -typedef size_t SIZE_T; + +typedef struct { + BYTE ACLineStatus; + BYTE BatteryFlag; + BYTE BatteryLifePercent; + BYTE SystemStatusFlag; + DWORD BatteryLifeTime; + DWORD BatteryFullLifeTime; +} SYSTEM_POWER_STATUS, *LPSYSTEM_POWER_STATUS; extern std::map vKeyToScancode; #endif @@ -108,4 +119,16 @@ MKXP_FreeLibrary(HMODULE hLibModule); PREFABI SHORT MKXP_GetAsyncKeyState(int vKey); +PREFABI BOOL +MKXP_GetSystemPowerStatus(LPSYSTEM_POWER_STATUS lpSystemPowerStatus); + +PREFABI BOOL +MKXP_ShowWindow(HWND hWnd, int nCmdShow); + +PREFABI LONG +MKXP_SetWindowLong(HWND hWnd, int nIndex, LONG dwNewLong); + +PREFABI int +MKXP_GetSystemMetrics(int nIndex); + #endif