aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


commit fadd291e41d77297aae72a25dc213c94a5fc0c30
parent 01a6d9172f0b9628dad5693955c6db3e9e1af06f
Author: anon <anon@example.com>
Date:   Thu, 15 Oct 2026 04:35:27 +0000

Support initial Linux cursor and modifier queries

Diffstat:
Mdecompiled/runtime/linux_window.c | 28++++++++++++++++++++++++++++
Mdecompiled/tests/window.c | 73+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 101 insertions(+), 0 deletions(-)

diff --git a/decompiled/runtime/linux_window.c b/decompiled/runtime/linux_window.c @@ -653,6 +653,32 @@ static void client_to_screen(void) g_esp += 12; } +static void cursor_position(void) +{ + uint32_t output = MEM32(g_esp + 4); + g_esp += 8; + g_eax = 0; + if (!output) { MEM32(g_fs_base + 0x34) = 998; return; } + if (!linux_graphics_window()) { MEM32(g_fs_base + 0x34) = 8; return; } + int x, y; + SDL_GetGlobalMouseState(&x, &y); + MEM32(output) = x; MEM32(output + 4) = y; + g_eax = 1; +} + +static void key_state(void) +{ + uint32_t key = MEM32(g_esp + 4); + SDL_Keymod mask; + if (key == 0x10) mask = KMOD_SHIFT; + else if (key == 0x11) mask = KMOD_CTRL; + else if (key == 0x12) mask = KMOD_ALT; + else { unsupported("virtual key", key); return; } + /* Read the cached modifier snapshot without pumping later input events. */ + g_eax = SDL_GetModState() & mask ? 0xffffff80u : 0; + g_esp += 8; +} + static void desktop_window(void) { g_eax = 0xf4200000u; g_esp += 4; } static void get_dc(void) @@ -739,6 +765,8 @@ recomp_func_t linux_window_lookup(const char *dll, const char *name) if (!strcmp(name, "GetClientRect")) return client_rect; if (!strcmp(name, "GetWindowRect")) return window_rect; if (!strcmp(name, "ClientToScreen")) return client_to_screen; + if (!strcmp(name, "GetCursorPos")) return cursor_position; + if (!strcmp(name, "GetKeyState")) return key_state; if (!strcmp(name, "GetDesktopWindow")) return desktop_window; if (!strcmp(name, "GetDC")) return get_dc; if (!strcmp(name, "ReleaseDC")) return release_dc; diff --git a/decompiled/tests/window.c b/decompiled/tests/window.c @@ -489,6 +489,77 @@ static void class_release_invalidates_its_atom(void) assert(!window && create_error == 6); } +static void cursor_query_writes_a_guest_point(void) +{ + uint32_t output = workspace() + 256, null = 0; + memset(memory(output - 4), 0xa5, 16); +#ifdef _WIN32 + SetLastError(77); +#else + MEM32(g_fs_base + 0x34) = 77; + SDL_SysWMinfo info; + SDL_VERSION(&info.version); + assert(SDL_GetWindowWMInfo(linux_graphics_window(), &info) && info.subsystem == SDL_SYSWM_X11); + Window root, child; + int before_x, before_y, after_x, after_y, window_x, window_y; + unsigned buttons; + assert(XQueryPointer(info.info.x11.display, info.info.x11.window, &root, &child, + &before_x, &before_y, &window_x, &window_y, &buttons)); +#endif + + uint32_t result = call("GetCursorPos", 1, &output); + + assert(result && error() == 77); + assert(memory(output)[0] != 0xa5a5a5a5 && memory(output)[1] != 0xa5a5a5a5); + assert(*memory(output - 4) == 0xa5a5a5a5 && *memory(output + 8) == 0xa5a5a5a5); +#ifndef _WIN32 + assert(XQueryPointer(info.info.x11.display, info.info.x11.window, &root, &child, + &after_x, &after_y, &window_x, &window_y, &buttons)); + /* A physical mouse movement during the two queries is not an adapter failure. */ + if (before_x == after_x && before_y == after_y) + assert((int32_t)memory(output)[0] == before_x && (int32_t)memory(output)[1] == before_y); +#endif + assert(!call("GetCursorPos", 1, &null) && error() == 998); +} + +static void modifier_queries_combine_left_and_right_keys(void) +{ +#ifdef _WIN32 + BYTE original[256], state[256] = {0}; + assert(GetKeyboardState(original)); +#else + SDL_Keymod original = SDL_GetModState(); + const SDL_Keymod modifiers[] = {KMOD_LSHIFT, KMOD_RSHIFT, KMOD_LCTRL, KMOD_RCTRL, KMOD_LALT, KMOD_RALT}; +#endif + for (unsigned pressed = 0; pressed < 64; ++pressed) { +#ifdef _WIN32 + state[VK_SHIFT] = pressed & 3 ? 0x80 : 0; + state[VK_CONTROL] = pressed & 12 ? 0x80 : 0; + state[VK_MENU] = pressed & 48 ? 0x80 : 0; + assert(SetKeyboardState(state)); +#else + SDL_Keymod state = KMOD_NONE; + for (unsigned i = 0; i < 6; ++i) if (pressed & (1u << i)) state |= modifiers[i]; + SDL_SetModState(state); +#endif + + uint32_t key = 0x10, shift = call("GetKeyState", 1, &key); + key = 0x11; + uint32_t control = call("GetKeyState", 1, &key); + key = 0x12; + uint32_t alt = call("GetKeyState", 1, &key); + + assert((uint16_t)shift == (pressed & 3 ? 0xff80 : 0)); + assert((uint16_t)control == (pressed & 12 ? 0xff80 : 0)); + assert((uint16_t)alt == (pressed & 48 ? 0xff80 : 0)); + } +#ifdef _WIN32 + assert(SetKeyboardState(original)); +#else + SDL_SetModState(original); +#endif +} + static void desktop_context_reports_native_pixel_storage(void) { uint32_t desktop = call("GetDesktopWindow", 0, NULL), none = 0; @@ -565,6 +636,8 @@ int main(void) } wide = 0; desktop_context_reports_native_pixel_storage(); + cursor_query_writes_a_guest_point(); + modifier_queries_combine_left_and_right_keys(); #ifndef _WIN32 screensaver_inhibition_is_process_scoped(); #endif