From f4b02b815c33406260fe69e50f01b0c07f74f3f8 Mon Sep 17 00:00:00 2001 From: Piktrip <119789656+Piktrip@users.noreply.github.com> Date: Sun, 15 Nov 2026 11:58:34 +0100 Subject: [PATCH 01/13] Platform: a window at a place the caller chooses platform.h gets display_work_area, place_window, window_rect and set_window_focusable, in their own file (platform_place.cpp), plus WindowDesc::focusable and InitOptions::place_windows. Split screen (#684) needs them: each of its two windows sits without a frame in its half of the work area, and the second must not take the keyboard focus when it appears. place_window asks first whether the window system lets a window choose its position (Wayland does not), and sets position and size in two passes: KWin fits each request to the window as it is at that moment, so one pass left the window on the wrong display's width or pushed out of the lower half. With place_windows set, X11 is asked for before Wayland on Linux. Co-Authored-By: Claude --- runtime/include/nxrt/platform.h | 16 ++++++ runtime/src/gfx/platform.cpp | 4 +- runtime/src/gfx/platform_place.cpp | 78 ++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 runtime/src/gfx/platform_place.cpp diff --git a/runtime/include/nxrt/platform.h b/runtime/include/nxrt/platform.h index 7387991a..65057a8b 100644 --- a/runtime/include/nxrt/platform.h +++ b/runtime/include/nxrt/platform.h @@ -10,6 +10,8 @@ namespace nxrt::platform { struct InitOptions { bool gamepads = true; // init the joystick/gamepad subsystems and open pads as they are plugged in + bool place_windows = false; // the caller puts its window at a screen position (place_window): on Linux X11 is asked for first, since + // a Wayland window cannot choose where it is }; bool init(const InitOptions& opt = {}); // idempotent; sets the SDL hints (raw mouse), SDL_Init(VIDEO|EVENTS|JOYSTICK|GAMEPAD) void shutdown(); // closes the window and every opened gamepad, SDL_Quit @@ -20,6 +22,7 @@ struct WindowDesc { int width = 1280, height = 720; // client size in screen coordinates at creation bool resizable = true; bool hidden = false; // also forced by [gfx] hidden / NXRT_GFX_HIDDEN + bool focusable = true; // false: the window appears without taking the keyboard focus from the one that has it }; bool create_window(const WindowDesc& desc); // Vulkan-capable window (SDL_WINDOW_VULKAN, high pixel density) void destroy_window(); @@ -55,6 +58,19 @@ int window_display(); // the number of the display the w // Moves the window to the centre of that display, keeping its mode (a fullscreen window leaves fullscreen, moves and goes back). bool move_to_display(int number); +// A rectangle of the desktop, in screen coordinates. +struct Rect { + int x = 0, y = 0, w = 0, h = 0; + bool operator==(const Rect&) const = default; +}; +// The part of that display windows may cover (without the taskbar or panels); number 0 = the primary display. False for a bad number. +bool display_work_area(int number, Rect* out); +// Puts the window at that rectangle, without a frame (a fullscreen or maximised window leaves that state first). Synchronous, like +// set_fullscreen. False when the window system gives a window no say in its position (Wayland): the window is then left as it was. +bool place_window(const Rect& r); +bool window_rect(Rect* out); // where the window is now (client area); false without a window +void set_window_focusable(bool on); // whether the window can take the keyboard focus (WindowDesc::focusable, changed later) + // Relative mouse mode: raw, unaccelerated deltas (SDL_SetWindowRelativeMouseMode with SDL_HINT_MOUSE_RELATIVE_SYSTEM_SCALE // forced to "0" and SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE to "1"). The cursor is hidden and confined while it is on. bool set_relative_mouse(bool on); diff --git a/runtime/src/gfx/platform.cpp b/runtime/src/gfx/platform.cpp index 6f15401d..8f93ab97 100644 --- a/runtime/src/gfx/platform.cpp +++ b/runtime/src/gfx/platform.cpp @@ -406,7 +406,8 @@ bool init(const InitOptions& opt) { // it can through X11 (XWayland) but not on a native Wayland surface; SDL 3 picks Wayland first on a compositor such as // KDE Plasma 6, and the pad goes silent. Steam sets SteamGameId // for its own games and non-Steam shortcuts alike. A hint only: SDL_VIDEO_DRIVER from the player still wins. - if (std::getenv("SteamGameId") || std::getenv("SteamAppId")) SDL_SetHint(SDL_HINT_VIDEO_DRIVER, "x11,wayland"); + // The same order for a caller that places its window (place_window): Wayland has no protocol for a window to set its position. + if (opt.place_windows || std::getenv("SteamGameId") || std::getenv("SteamAppId")) SDL_SetHint(SDL_HINT_VIDEO_DRIVER, "x11,wayland"); #endif // Hints must be set before SDL_Init. Raw, unaccelerated relative mouse; gamepads keep reporting when the window is // in the background. @@ -463,6 +464,7 @@ bool create_window(const WindowDesc& desc) { SDL_WindowFlags flags = SDL_WINDOW_VULKAN | SDL_WINDOW_HIGH_PIXEL_DENSITY; if (desc.resizable) flags |= SDL_WINDOW_RESIZABLE; if (desc.hidden || config_get_bool("gfx", "hidden", false)) flags |= SDL_WINDOW_HIDDEN; + if (!desc.focusable) flags |= SDL_WINDOW_NOT_FOCUSABLE; g_window = SDL_CreateWindow(desc.title ? desc.title : "nxrt", desc.width, desc.height, flags); if (!g_window) { diff --git a/runtime/src/gfx/platform_place.cpp b/runtime/src/gfx/platform_place.cpp new file mode 100644 index 00000000..7a227d84 --- /dev/null +++ b/runtime/src/gfx/platform_place.cpp @@ -0,0 +1,78 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// SDL3 platform layer: a window at a place the caller chooses (platform.h: display_work_area, place_window, window_rect, +// set_window_focusable). Split screen keeps its windows this way (src/gfx/play/play_split.cpp). The window is platform.cpp's, reached +// through native_window(); same thread as everything else in the platform layer. +#include "nxrt/platform.h" + +#include + +#include "nxrt/log.h" + +namespace nxrt::platform { +namespace { + +constexpr const char* kTag = "platform"; + +SDL_Window* window() { return static_cast(native_window()); } + +} // namespace + +bool display_work_area(int number, Rect* out) { + if (!out) return false; + SDL_DisplayID id = 0; + if (number == 0) { + id = SDL_GetPrimaryDisplay(); + } else if (number >= 1) { + int n = 0; + if (SDL_DisplayID* ids = SDL_GetDisplays(&n)) { // the system's order, as display_count and display_name number them + if (number <= n) id = ids[number - 1]; + SDL_free(ids); + } + } + SDL_Rect r{}; + if (!id || !SDL_GetDisplayUsableBounds(id, &r) || r.w <= 0 || r.h <= 0) return false; + *out = {r.x, r.y, r.w, r.h}; + return true; +} + +bool place_window(const Rect& r) { + SDL_Window* w = window(); + if (!w || r.w <= 0 || r.h <= 0) return false; + if (fullscreen_mode() != FullscreenMode::Windowed && !set_fullscreen(FullscreenMode::Windowed)) return false; + if (SDL_GetWindowFlags(w) & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED)) SDL_RestoreWindow(w); + // Whether this window system lets a window choose its position is asked with the position it has, before anything changes (SDL's + // Wayland back end refuses every position). + int x = 0, y = 0; + if (!SDL_GetWindowPosition(w, &x, &y) || !SDL_SetWindowPosition(w, x, y)) { + NXLOG_W(kTag, "place_window(%d,%d %dx%d): the window system places windows itself: %s", r.x, r.y, r.w, r.h, SDL_GetError()); + return false; + } + SDL_SetWindowBordered(w, false); + // A window manager fits each request to the window as it is at that moment: KWin keeps a window that still has its old, larger size + // inside the work area (so it left the lower half), and limits a new size to the display the window is on (so a window coming from + // a narrower display stayed narrower). One pass gets the display and the size right, the second the position. + for (int pass = 0; pass < 2; ++pass) { + if (!SDL_SetWindowPosition(w, r.x, r.y)) NXLOG_W(kTag, "place_window: position %d,%d refused: %s", r.x, r.y, SDL_GetError()); + if (!SDL_SetWindowSize(w, r.w, r.h)) NXLOG_W(kTag, "place_window: size %dx%d refused: %s", r.w, r.h, SDL_GetError()); + SDL_SyncWindow(w); + Rect now; + if (window_rect(&now) && now == r) break; + } + return true; +} + +bool window_rect(Rect* out) { + SDL_Window* w = window(); + if (!w || !out) return false; + Rect r; + if (!SDL_GetWindowPosition(w, &r.x, &r.y) || !SDL_GetWindowSize(w, &r.w, &r.h)) return false; + *out = r; + return true; +} + +void set_window_focusable(bool on) { + SDL_Window* w = window(); + if (w && !SDL_SetWindowFocusable(w, on)) NXLOG_W(kTag, "set_window_focusable(%d) failed: %s", on ? 1 : 0, SDL_GetError()); +} + +} // namespace nxrt::platform From 7625eb28ad32bf44451065cd98e70cd0eb6e829d Mon Sep 17 00:00:00 2001 From: Piktrip <119789656+Piktrip@users.noreply.github.com> Date: Sun, 15 Nov 2026 11:58:34 +0100 Subject: [PATCH 02/13] Play mode: split screen windows Split screen (#684) runs the game twice on one PC, the two processes meeting through Link Play on 127.0.0.1, after pokopia-native's design. Whoever starts the pair says which window a process is with the new [split] keys (window, layout, pad, mute, first_account; nxrt/split.h and CONFIG.md); nothing is a player setting, so no file is written. play_split.cpp keeps the window in its half of the work area and puts it back when anything moves it; the settings' window mode, monitor move, window size and Alt+Enter do nothing there. A window plays one controller, by its place in connection order, or none: poll_pads, the prompts and the status read the pads through own_pads. One of the two windows never has the focus, so [audio] mute_unfocused does not apply and a window is silent only when [split] mute says so. play::display() tells the game's start-up that the window is placed by play mode and whether it may take the focus, so pkp_main.cpp needs no knowledge of split screen. Co-Authored-By: Claude --- game-build/src/pkp_main.cpp | 5 +- runtime/docs/CONFIG.md | 5 + runtime/include/nxrt/play.h | 4 + runtime/include/nxrt/split.h | 24 +++++ runtime/src/gfx/play/play_events.cpp | 11 +- runtime/src/gfx/play/play_frame.cpp | 20 ++-- runtime/src/gfx/play/play_hosts.cpp | 6 +- runtime/src/gfx/play/play_split.cpp | 149 ++++++++++++++++++++++++++ runtime/src/gfx/play/play_startup.cpp | 11 +- runtime/src/gfx/play/play_state.h | 10 ++ runtime/src/gfx/play/play_window.cpp | 4 +- 11 files changed, 229 insertions(+), 20 deletions(-) create mode 100644 runtime/include/nxrt/split.h create mode 100644 runtime/src/gfx/play/play_split.cpp diff --git a/game-build/src/pkp_main.cpp b/game-build/src/pkp_main.cpp index 4615c66b..8c1d6ea4 100644 --- a/game-build/src/pkp_main.cpp +++ b/game-build/src/pkp_main.cpp @@ -447,11 +447,14 @@ int main(int argc, char** argv) { nxrt::play::DisplayConfig disp; if (!headless) { disp = nxrt::play::display(); // controls.ini: window size, present mode, frame cap - nxrt::platform::init(); + nxrt::platform::InitOptions po; + po.place_windows = disp.places_window; + nxrt::platform::init(po); nxrt::platform::WindowDesc wd; wd.title = nxrt::game::info().title; wd.width = disp.width; wd.height = disp.height; + wd.focusable = disp.takes_focus; if (!nxrt::platform::create_window(wd)) die("cannot create the game window. The game needs a graphics driver with Vulkan 1.3: update the driver for your graphics card and try again. The reason is in pkp.log."); } nxrt::gfx::DeviceDesc dd; diff --git a/runtime/docs/CONFIG.md b/runtime/docs/CONFIG.md index 94c2fb48..f31d0e8c 100644 --- a/runtime/docs/CONFIG.md +++ b/runtime/docs/CONFIG.md @@ -284,6 +284,11 @@ Rules: | `play` | `pointer_draw` | `false` | `NXRT_PLAY_POINTER_DRAW` | `src/gfx/play/play.cpp` | Test aid: draws an arrow at the menu pointer into the game's own frame, so a game screenshot shows where the pointer is (the OS cursor is not part of the frame). | | `play` | `selftest` | empty | `NXRT_PLAY_SELFTEST` | `src/gfx/play/play_selftest.h` | Window self-test script for the oracles (steps are listed in that header). | | `play` | `late_sample` | `true` | `NXRT_PLAY_LATE_SAMPLE` | `src/gfx/play/play.cpp` | Pump the window's events again right before the first `ProcessInput` of a frame takes the mouse counts, so the aim includes what the mouse did since the frame boundary. | +| `split` | `window` | `0` | `NXRT_SPLIT_WINDOW` | `src/gfx/play/play_split.cpp` | Split screen (`include/nxrt/split.h`): the game runs twice on one PC and each process is a window in its half of the screen; the two meet through Link Play on 127.0.0.1. `1`: this process is the first window (the first half), `2`: the second, `0`: no split screen. The launcher's **Split screen** sets it for the two processes it starts, in their environment only. The window has no frame, fills its half of the work area of the `[display] monitor` display (else the primary one) and is put back when anything moves, resizes or maximises it; `[display] window_mode`, the window size and Alt+Enter do nothing. Where the window system places windows itself (a Wayland session without XWayland) the window is left where it is and a warning says so; X11 is asked for first on Linux. The second window cannot take the keyboard focus until it is in its half, so starting it leaves the keyboard with the first; after that a click gives a window the keyboard and mouse. `[audio] mute_unfocused` does not apply. | +| `split` | `layout` | `stacked` | `NXRT_SPLIT_LAYOUT` | `src/gfx/play/play_split.cpp` | `stacked`: top and bottom halves, each as wide as the screen (window 1 on top). `side`: left and right halves (window 1 on the left). | +| `split` | `pad` | the window's number | `NXRT_SPLIT_PAD` | `src/gfx/play/play_split.cpp` | The one controller this window plays, by its place in the order the controllers were connected (`1` = the first); every other controller does nothing in this window, its quit and overlay combinations included. `0`: none, the window is played with the keyboard and mouse only. | +| `split` | `mute` | `false` | `NXRT_SPLIT_MUTE` | `src/gfx/play/play_split.cpp` | This window plays no sound (two copies of the same music). | +| `split` | `first_account` | empty | `NXRT_SPLIT_FIRST_ACCOUNT` | `src/gfx/play/play_split.cpp`, `games/pkp/core/pkp_save_uuid.cpp` | Window 2 only: the folder name of the first player's account save (`/account/`, 32 hex digits; both windows share the save folder). Pokopia: a save in window 2 that has the same player UUID as that save (a copy of it, made for a second player without a save) gets a UUID of its own before the game reads it, as `uuid_repair` does, because the host refuses a visitor with its own UUID. | | `prompts` | `style` | `auto` | none (controls.ini only) | `src/gfx/play/play_config.cpp` (read from `controls.ini`) | Button icons the game's prompts show. `auto` (the default) shows keyboard and mouse icons until a controller is used, then that controller's icons, and goes back to the keyboard when a key or mouse button is pressed. The other values are `switch` (the game's own icons), `xbox`, `playstation`, `steam` (Steam Controller), `steamdeck` (Steam Deck), `switch1` (Nintendo Switch: Kenney's art, not the game's own), `switch2` (Nintendo Switch 2), `wiiu` (Wii U), `steamframe` (Steam Frame), `index` (Valve Index: A, B, the triggers and the trackpad; the left stick stands for the d-pad), `touch` (touch-screen gestures) and `keyboard` (keyboard and mouse). `auto` picks `steamdeck` for a Steam pad on a handheld and `steam` elsewhere. Also accepts `ps`, `ps4`, `ps5`, `dualsense`, `steamcontroller`, `deck`, `steam_deck`, `nintendo_switch`, `ns1`, `ns2`, `switch_2`, `nintendo_switch_2`, `wii_u`, `steam_frame`, `frame`, `valve_index`, `touchscreen`, `kbm`, `mouse` and `keyboard_mouse`. Stored in `controls.ini` under `[prompts]`, not in `nxrt.ini`. Set it in the launcher (Controls tab) or on the F1 page (Controller tab, Button prompts); both show a preview of the chosen style's icon for each Switch button (the launcher with the factory mapping, F1 with the current one). Changes apply on the next frame, with no restart. Keyboard icons show the keys the action is bound to: a rebound jump key shows the new key, and a key with no icon of its own gets a plain key icon. Every controller set follows `[padmap]` (a button the controller has no icon for keeps the game's own) and are read from the icon pack `assets/prompts/prompt_icons.pak` next to pkp.exe (shipped in the release zip; see `prompts dir`). | | `fps` | `show` | `0` | none (controls.ini only) | `src/gfx/play/play.cpp`, `src/gfx/overlay.cpp` | Frame rate counter in a corner of the game window. Off by default. While it is off, the overlay does one atomic read per frame and nothing else. The hotkey (`key`), the Display tab of the F1 page and the launcher's Extras tab can turn it on or off, and the choice is saved. | | `fps` | `key` | `F2` | none (controls.ini only) | `src/gfx/play/play.cpp` | Keyboard key that shows and hides the counter. The game never receives it, so do not bind the same key to an action. Any SDL scancode name. | diff --git a/runtime/include/nxrt/play.h b/runtime/include/nxrt/play.h index e5eaaa5d..9297cf8a 100644 --- a/runtime/include/nxrt/play.h +++ b/runtime/include/nxrt/play.h @@ -37,6 +37,10 @@ struct DisplayConfig { int fps_cap = 60; // 0 = unlimited bool keep_aspect = true; gfx::PresentMode present_mode = gfx::PresentMode::Immediate; // what the vsync setting asks for (the renderer falls back to what the surface supports) + // Split screen (nxrt/split.h): play mode puts the window in its half itself (platform::InitOptions::place_windows), and the second + // window appears without taking the keyboard focus from the first (platform::WindowDesc::focusable). + bool places_window = false; + bool takes_focus = true; }; DisplayConfig display(); FrameLimiter* limiter(); // owned by play mode; pass to nvn::BackendDesc::limiter diff --git a/runtime/include/nxrt/split.h b/runtime/include/nxrt/split.h new file mode 100644 index 00000000..e2e85b34 --- /dev/null +++ b/runtime/include/nxrt/split.h @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// Split screen: the game runs twice on one PC, each process a window in its half of the screen, and the two meet through the game's own +// multiplayer on 127.0.0.1. Whoever starts the pair (the launcher) tells each process which window it is; play mode then keeps the +// window in its half and gives it one controller (src/gfx/play/play_split.cpp), and the game layer can ask here which player it runs. +// After pokopia-native's split screen (MIT, windows/docs/split-screen.md): the same design, on this runtime's own window and input code. +// +// Configuration ([split], environment NXRT_SPLIT_, read once; docs/CONFIG.md): +// window = 0 1: the first window (the first half, it hosts), 2: the second (it visits); 0: no split screen +// layout = stacked stacked: top and bottom halves, each as wide as the screen; side: left and right halves +// pad = the controller this window plays, by its place in the order the controllers were connected (1 = the first); +// 0: none (keyboard and mouse only) +// mute = false this window plays no sound +// first_account = window 2: the folder name of the first player's account save (/account/, 32 hex digits), for a +// game layer whose save must differ from it. A name and not a path: both windows share the save folder, and an +// environment variable does not carry every path on Windows +#pragma once +#include + +namespace nxrt::split { + +int window(); // 0: no split screen, else which window this process is (1 or 2) +std::string first_account(); // empty when the starter named none (or what it named is not 32 hex digits) + +} // namespace nxrt::split diff --git a/runtime/src/gfx/play/play_events.cpp b/runtime/src/gfx/play/play_events.cpp index bdd507d9..7133aad7 100644 --- a/runtime/src/gfx/play/play_events.cpp +++ b/runtime/src/gfx/play/play_events.cpp @@ -101,7 +101,7 @@ void handle_event(const input::Event& e, uint64_t now) { break; case EventType::KeyDown: if ((e.u.key.scancode == SDL_SCANCODE_RETURN || e.u.key.scancode == SDL_SCANCODE_KP_ENTER) && (e.mods & SDL_KMOD_ALT)) { - if (!(e.flags & input::kFlagRepeat)) toggle_fullscreen(); + if (!(e.flags & input::kFlagRepeat)) toggle_fullscreen(); // (nothing in split screen: the window keeps its half) return; } if (!(e.flags & input::kFlagRepeat)) mm::pointer().on_other_input(); @@ -157,7 +157,7 @@ void handle_event(const input::Event& e, uint64_t now) { } break; case EventType::WindowFocusLost: - audio::set_muted(st.window && st.settings.audio.mute_unfocused); + apply_window_mute(); st.engine->release_all(now); key_state::clear(); st.mouse1 = false; @@ -165,7 +165,7 @@ void handle_event(const input::Event& e, uint64_t now) { mm::pointer().on_focus_lost(); break; case EventType::WindowFocusGained: - audio::set_muted(false); + apply_window_mute(); st.limiter.reset_schedule(); break; case EventType::WindowRestored: @@ -187,12 +187,13 @@ void handle_event(const input::Event& e, uint64_t now) { // Shortest gap between two rumble writes to the pads (30 per second). constexpr uint64_t kRumbleMinGapNs = 1000000000ull / 30; -// Reads every open pad, merges them (buttons OR, the stick with the larger deflection wins) and publishes the result to the source. +// Reads every pad this window plays (own_pads: all the open ones, or in split screen its one), merges them (buttons OR, the stick with the +// larger deflection wins) and publishes the result to the source. void poll_pads(uint64_t now) { G& st = g(); PadFrame pf; input::GamepadInfo infos[8]; - const size_t n = input::gamepad_list(infos, 8); + const size_t n = own_pads(infos, 8); bool have_six = false; uint16_t lo = 0, hi = 0; { diff --git a/runtime/src/gfx/play/play_frame.cpp b/runtime/src/gfx/play/play_frame.cpp index e396a3e6..8cf80a24 100644 --- a/runtime/src/gfx/play/play_frame.cpp +++ b/runtime/src/gfx/play/play_frame.cpp @@ -21,9 +21,11 @@ void busy_pump() { // Master volume (live). The mute while the window has no focus is set every frame (update_hook) and on focus changes. void apply_audio(const AudioSettings& a) { audio::set_master_volume(static_cast(a.volume)); } -void apply_unfocused_mute() { +// In split screen one of the two windows never has the focus, so [audio] mute_unfocused does not apply there: a window is silent when +// its starter said so ([split] mute). +void apply_window_mute() { G& st = g(); - audio::set_muted(st.window && st.settings.audio.mute_unfocused && !platform::focused()); + audio::set_muted(split_active() ? split_muted() : st.window && st.settings.audio.mute_unfocused && !platform::focused()); } // ---- hooks ---------------------------------------------------------------------------------------------------------------------------- @@ -83,7 +85,10 @@ int update_hook(::Ctx*, uint64_t, void*) { st.thread_mismatch.store(true); NXLOG_W(kTag, "the frame-boundary hook runs on another thread than the one that started play mode: SDL events are not pumped"); } - if (st.window && on_pump_thread) platform::pump_events(); + if (st.window && on_pump_thread) { + platform::pump_events(); + split_keep(now); + } // settings queued by the page { @@ -106,7 +111,8 @@ int update_hook(::Ctx*, uint64_t, void*) { apply_fps_counter(s.fps); st.want_present.store(static_cast(present_mode_for(s.display))); apply_audio(s.audio); - if (st.window && s.display.monitor != old_monitor && s.display.monitor > 0) { + // split screen: the window stays in its half (split_keep follows another monitor), whatever mode and size the settings name + if (st.window && !split_active() && s.display.monitor != old_monitor && s.display.monitor > 0) { if (platform::move_to_display(s.display.monitor)) st.limiter.reset_schedule(); apply_frame_cap(s); // another display can mean another refresh rate } @@ -115,7 +121,7 @@ int update_hook(::Ctx*, uint64_t, void*) { apply_frame_cap(s); // another window mode can mean another refresh rate (vsync cap) } // The windowed size is live while the window is windowed; in fullscreen it is the size the window goes back to (the next start). - if (st.window && (s.display.width != old_w || s.display.height != old_h) && platform::fullscreen_mode() == platform::FullscreenMode::Windowed) + if (st.window && !split_active() && (s.display.width != old_w || s.display.height != old_h) && platform::fullscreen_mode() == platform::FullscreenMode::Windowed) platform::set_window_size(s.display.width, s.display.height); std::string err; if (!save_settings(st.path, s, &err)) NXLOG_W(kTag, "cannot save %s: %s", st.path.c_str(), err.c_str()); @@ -123,7 +129,7 @@ int update_hook(::Ctx*, uint64_t, void*) { } } - apply_unfocused_mute(); + apply_window_mute(); // events input::Event buf[128]; @@ -182,7 +188,7 @@ int update_hook(::Ctx*, uint64_t, void*) { pin.last = st.last_dev; pin.last_pad_kind = st.last_pad_kind; input::GamepadInfo pads[1]; - pin.connected_pad_kind = input::gamepad_list(pads, 1) > 0 ? static_cast(pads[0].kind) : -1; + pin.connected_pad_kind = own_pads(pads, 1) > 0 ? static_cast(pads[0].kind) : -1; prompts_update(st.settings, pin); } diff --git a/runtime/src/gfx/play/play_hosts.cpp b/runtime/src/gfx/play/play_hosts.cpp index 51541554..963ed822 100644 --- a/runtime/src/gfx/play/play_hosts.cpp +++ b/runtime/src/gfx/play/play_hosts.cpp @@ -94,9 +94,9 @@ class Host : public UiHost { s.prompt_now = prompts_effective_name(); if (st.pi_calls.load() == 0) s.aim = "not in game"; s.mouse_captured = st.window && platform::relative_mouse(); - input::GamepadInfo infos[4]; - s.pads = static_cast(input::gamepad_count()); - if (input::gamepad_list(infos, 4) > 0) { + input::GamepadInfo infos[8]; + s.pads = static_cast(own_pads(infos, 8)); // the ones this window plays, as poll_pads reads them (split screen: its one) + if (s.pads > 0) { s.pad_name = infos[0].name; s.pad_gyro = infos[0].gyro; s.pad_rumble = infos[0].rumble; diff --git a/runtime/src/gfx/play/play_split.cpp b/runtime/src/gfx/play/play_split.cpp new file mode 100644 index 00000000..e1439e6e --- /dev/null +++ b/runtime/src/gfx/play/play_split.cpp @@ -0,0 +1,149 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// Play mode: split screen (nxrt/split.h). This process is one of two windows: it sits in its half of the display's work area without a +// frame and is put back when anything moves it, it plays one controller (by its place in connection order) and it can be silent. The +// keyboard and mouse belong to the window with the focus, as always; the second window is made unable to take the focus until it is in +// its half, so starting it does not take the keyboard from the first. +#include "nxrt/split.h" + +#include "play_state.h" + +namespace nxrt::split { +namespace { + +struct Cfg { + int window = 0; + bool side = false; + int pad = 0; + bool mute = false; + std::string first_account; +}; + +const Cfg& cfg() { + static const Cfg c = [] { + Cfg r; + const int64_t w = config_get_int("split", "window", 0); + if (w != 1 && w != 2) { + if (w != 0) NXLOG_W("play", "[split] window = %lld is not 0, 1 or 2: no split screen", static_cast(w)); + return r; + } + r.window = static_cast(w); + const std::string layout = config_get_str("split", "layout", "stacked"); + r.side = layout == "side"; + if (!r.side && layout != "stacked") NXLOG_W("play", "[split] layout = %s is not stacked or side: stacked", layout.c_str()); + r.pad = static_cast(std::clamp(config_get_int("split", "pad", r.window), 0, 8)); + r.mute = config_get_bool("split", "mute", false); + const std::string first = config_get_str("split", "first_account", ""); + const bool hex = first.size() == 32 && std::all_of(first.begin(), first.end(), [](unsigned char ch) { return std::isxdigit(ch) != 0; }); + if (hex) r.first_account = first; + else if (!first.empty()) NXLOG_W("play", "[split] first_account is not 32 hex digits: ignored"); + return r; + }(); + return c; +} + +} // namespace + +int window() { return cfg().window; } +std::string first_account() { return cfg().first_account; } + +} // namespace nxrt::split + +namespace nxrt::play { +using namespace detail; +namespace detail { +namespace { + +// What split_keep compares the window with. Main thread only. +struct Held { + bool placed = false; // the window system took our position: the window is kept there + platform::Rect want; // its half, as last computed + platform::Rect got; // where the window system put it then (it may round a size or keep a margin: that is not fought) + uint64_t next_check_ns = 0; +}; +Held& held() { + static Held h; + return h; +} + +// The work area the pair shares: the display of [display] monitor, else the primary one. +bool work_area(platform::Rect* out) { + const int monitor = g().settings.display.monitor; + return (monitor > 0 && platform::display_work_area(monitor, out)) || platform::display_work_area(0, out); +} + +bool place() { + Held& h = held(); + platform::Rect area; + if (!work_area(&area)) return false; + h.want = split_half(area, split::window(), split::cfg().side); + if (!platform::place_window(h.want)) return false; + if (!platform::window_rect(&h.got)) h.got = h.want; + g().limiter.reset_schedule(); + return true; +} + +} // namespace + +platform::Rect split_half(const platform::Rect& area, int window, bool side) { + platform::Rect r = area; + if (side) { + const int first = area.w / 2; + r.w = window == 2 ? area.w - first : first; + if (window == 2) r.x += first; + } else { + const int first = area.h / 2; + r.h = window == 2 ? area.h - first : first; + if (window == 2) r.y += first; + } + return r; +} + +bool split_active() { return split::window() != 0; } + +bool split_muted() { return split::cfg().mute; } + +size_t own_pads(input::GamepadInfo* out, size_t max) { + if (!split_active()) return input::gamepad_list(out, max); + const int place = split::cfg().pad; + input::GamepadInfo all[8]; + const size_t n = input::gamepad_list(all, 8); + if (place <= 0 || static_cast(place) > n || !out || max == 0) return 0; + out[0] = all[place - 1]; + return 1; +} + +void split_start() { + G& st = g(); + const split::Cfg& c = split::cfg(); + Held& h = held(); + h.placed = st.window && place(); + if (st.window && !h.placed) + NXLOG_W(kTag, "split screen: window %d could not be put in its half (the window system places windows itself): move it there by hand", c.window); + if (h.placed && h.got != h.want) + NXLOG_W(kTag, "split screen: the window system put window %d at %d,%d %dx%d, not at its half %d,%d %dx%d: it is left there", c.window, h.got.x, + h.got.y, h.got.w, h.got.h, h.want.x, h.want.y, h.want.w, h.want.h); + // the window was made unable to take the focus (the game's start-up names that in its WindowDesc); from here a click gives it the keyboard + if (st.window) platform::set_window_focusable(true); + NXLOG_I(kTag, "split screen: window %d, %s, %s, sound %s, %s %d,%d %dx%d", c.window, c.side ? "side by side" : "stacked", + c.pad ? ("controller " + std::to_string(c.pad)).c_str() : "no controller (keyboard and mouse)", c.mute ? "off" : "on", + h.placed ? "at" : "not placed, wanted", h.placed ? h.got.x : h.want.x, h.placed ? h.got.y : h.want.y, + h.placed ? h.got.w : h.want.w, h.placed ? h.got.h : h.want.h); +} + +void split_keep(uint64_t now) { + Held& h = held(); + if (!h.placed || now < h.next_check_ns) return; + h.next_check_ns = now + 250 * kMs; + if (platform::minimized()) return; // the player's own doing; it is put back when it is restored somewhere else + platform::Rect cur, area; + if (!platform::window_rect(&cur)) return; + const bool moved = cur != h.got || platform::fullscreen_mode() != platform::FullscreenMode::Windowed; + // the half itself changes with the work area (a taskbar that moved, another resolution) and with [display] monitor + const bool other_half = work_area(&area) && split_half(area, split::window(), split::cfg().side) != h.want; + if (!moved && !other_half) return; + NXLOG_D(kTag, "split screen: the window is at %d,%d %dx%d, not in its half: putting it back", cur.x, cur.y, cur.w, cur.h); + if (!place()) h.placed = false; // refused now: not asked again four times a second +} + +} // namespace detail +} // namespace nxrt::play diff --git a/runtime/src/gfx/play/play_startup.cpp b/runtime/src/gfx/play/play_startup.cpp index 1d583121..c4fd28d7 100644 --- a/runtime/src/gfx/play/play_startup.cpp +++ b/runtime/src/gfx/play/play_startup.cpp @@ -3,6 +3,7 @@ #include "play_state.h" #include "nxrt/key_state.h" #include "nxrt/screenshot.h" +#include "nxrt/split.h" #include "nxrt/text.h" #include "nxrt/vi_sinks.h" @@ -132,6 +133,8 @@ DisplayConfig display() { d.fps_cap = st.settings.display.fps_cap; d.keep_aspect = st.settings.display.keep_aspect; d.present_mode = present_mode_for(st.settings.display); + d.places_window = split_active(); + d.takes_focus = split::window() != 2; return d; } @@ -240,8 +243,12 @@ bool start(const StartOptions& opt) { // game waits for it (keyboard_service; also headless with swkbd_prompt = force, which has an overlay and no window) if (st.window || st.overlay) svc_set_busy_hook(GetCurrentThreadId(), &busy_pump); kernel::set_blocked_hook(GetCurrentThreadId(), &keyboard_service); - if (st.window && st.settings.display.monitor > 0) platform::move_to_display(st.settings.display.monitor); - if (st.window && st.settings.display.window_mode != "windowed") set_window_mode(st.settings.display.window_mode); + if (split_active()) { + split_start(); // the window's half of the screen, in place of the settings' monitor and window mode + } else { + if (st.window && st.settings.display.monitor > 0) platform::move_to_display(st.settings.display.monitor); + if (st.window && st.settings.display.window_mode != "windowed") set_window_mode(st.settings.display.window_mode); + } const GamePlay* gp = game_play(); { // display options: the internal resolution comes from the window as it is now (after the window mode change above) diff --git a/runtime/src/gfx/play/play_state.h b/runtime/src/gfx/play/play_state.h index 468edfb6..b654a294 100644 --- a/runtime/src/gfx/play/play_state.h +++ b/runtime/src/gfx/play/play_state.h @@ -167,6 +167,15 @@ void set_window_mode(const std::string& mode); void toggle_fullscreen(); void apply_fps_counter(const FpsSettings& f); +// play_split.cpp: split screen (nxrt/split.h) +bool split_active(); +bool split_muted(); // this window plays no sound +platform::Rect split_half(const platform::Rect& area, int window, bool side); // pure: window 1's or 2's half of a work area +// The controllers this window plays, in the order they were connected: every one, or in split screen the one in its place (or none). +size_t own_pads(input::GamepadInfo* out, size_t max); +void split_start(); // at start, in place of the display settings' monitor and window mode: the window goes to its half +void split_keep(uint64_t now); // the frame boundary: puts the window back when something moved it + // play_events.cpp void vib_sink(uint32_t slot, int hand, const hid::VibrationValue& v, void*); void handle_event(const input::Event& e, uint64_t now); @@ -176,6 +185,7 @@ void poll_pads(uint64_t now); // play_frame.cpp extern std::atomic g_last_pump_ms; void busy_pump(); +void apply_window_mute(); // the sound is off: [audio] mute_unfocused without the focus, or a silent split screen window void keyboard_service(); void pre_frame(void*); int update_hook(::Ctx*, uint64_t, void*); diff --git a/runtime/src/gfx/play/play_window.cpp b/runtime/src/gfx/play/play_window.cpp index 9d28b2a3..d00db939 100644 --- a/runtime/src/gfx/play/play_window.cpp +++ b/runtime/src/gfx/play/play_window.cpp @@ -17,7 +17,7 @@ const char* window_mode_name(platform::FullscreenMode m) { void set_window_mode(const std::string& mode) { G& st = g(); - if (!st.window) return; + if (!st.window || split_active()) return; // a split screen window is in its half, without a mode of its own const platform::FullscreenMode want = mode == "borderless" ? platform::FullscreenMode::Borderless : mode == "exclusive" ? platform::FullscreenMode::Exclusive : platform::FullscreenMode::Windowed; @@ -36,7 +36,7 @@ void set_window_mode(const std::string& mode) { void toggle_fullscreen() { G& st = g(); - if (!st.window) return; + if (!st.window || split_active()) return; std::string target; if (platform::fullscreen_mode() == platform::FullscreenMode::Windowed) target = st.settings.display.window_mode == "exclusive" ? "exclusive" : "borderless"; From 9632422ef535ae0ebe6d040f6c9b843d7f3ec99f Mon Sep 17 00:00:00 2001 From: Piktrip <119789656+Piktrip@users.noreply.github.com> Date: Sun, 15 Nov 2026 11:58:34 +0100 Subject: [PATCH 03/13] Game layer: a player UUID of its own for split screen's second player The second player's save can be a copy of the first player's, and the host refuses a visitor with its own player UUID (error 9005), as it did with the UUID older builds shared. In split screen's second window a save whose UUID equals the one of the first player's save ([split] first_account) gets a new one in the same places, before the game reads it. The UUID is read from its plain copy in SYDAT and only taken when the bytes there are a version 4 UUID. The rewrite the repair already did is now swap_uuid, with the UUID to replace as a parameter; the repair of the shared UUID uses it unchanged. Co-Authored-By: Claude --- runtime/games/pkp/core/pkp_save_uuid.cpp | 115 +++++++++++++++++------ runtime/games/pkp/core/pkp_save_uuid.h | 9 +- 2 files changed, 92 insertions(+), 32 deletions(-) diff --git a/runtime/games/pkp/core/pkp_save_uuid.cpp b/runtime/games/pkp/core/pkp_save_uuid.cpp index 74f3b58c..bc543048 100644 --- a/runtime/games/pkp/core/pkp_save_uuid.cpp +++ b/runtime/games/pkp/core/pkp_save_uuid.cpp @@ -1,5 +1,5 @@ // SPDX-License-Identifier: GPL-3.0-or-later -// Pokémon Pokopia: repair of the shared player UUID (pkp_save_uuid.h). CMNDAT layout from berichan/PokoHex (GPL-3.0, SaveFile.cs): +// Pokémon Pokopia: a save's player UUID made its own (pkp_save_uuid.h). CMNDAT layout from berichan/PokoHex (GPL-3.0, SaveFile.cs): // magic 0x31227687, end of the compressed data at +0x10, zlib stream from 0x130. The rewrite is the one work/tools/pkp_uuid.py made // (checked in game: a save so changed joins a host made from the same original save). #include "core/pkp_save_uuid.h" @@ -21,6 +21,7 @@ #include "miniz.h" #include "nxrt/log.h" #include "nxrt/entropy.h" +#include "nxrt/split.h" namespace nxrt::games::pkp { namespace { @@ -33,6 +34,7 @@ constexpr uint8_t kShared[16] = {0xb9, 0xae, 0x85, 0xed, 0x20, 0xe7, 0x4f, 0x6b, constexpr uint32_t kCmnMagic = 0x31227687; constexpr size_t kCmnHeader = 0x130; constexpr size_t kCmnEndAt = 0x10; +constexpr size_t kSysUuidAt = 0x61; // S00/SYDAT.BIN: the player UUID's plain copy (2.0.1 saves; read_uuid checks what it finds there) using Bytes = std::vector; @@ -82,13 +84,14 @@ uint32_t rd32(const Bytes& b, size_t at) { return v; } -// A file with the UUID replaced: *count places, *out the new contents. False when it cannot be read or is not the expected layout. -bool rewrite(const stdfs::path& p, bool cmndat, const uint8_t* uuid, size_t* count, Bytes* out, std::string* why) { +// A file with the UUID `from` replaced by `uuid`: *count places, *out the new contents. False when it cannot be read or is not the +// expected layout. +bool rewrite(const stdfs::path& p, bool cmndat, const uint8_t* from, const uint8_t* uuid, size_t* count, Bytes* out, std::string* why) { Bytes file; if (!read_all(p, &file)) { *why = "cannot be read"; return false; } if (!cmndat) { *out = file; - *count = replace_all(*out, kShared, uuid); + *count = replace_all(*out, from, uuid); return true; } if (file.size() < kCmnHeader || rd32(file, 0) != kCmnMagic) { *why = "not a Pokopia common save"; return false; } @@ -99,7 +102,7 @@ bool rewrite(const stdfs::path& p, bool cmndat, const uint8_t* uuid, size_t* cou if (!raw_p) { *why = "does not decompress"; return false; } Bytes raw(static_cast(raw_p), static_cast(raw_p) + raw_n); mz_free(raw_p); - *count = replace_all(raw, kShared, uuid); + *count = replace_all(raw, from, uuid); if (*count == 0) { *out = file; return true; } size_t z_n = 0; const int flags = static_cast(tdefl_create_comp_flags_from_zip_params(9, 15, MZ_DEFAULT_STRATEGY)); // zlib header, level 9 @@ -130,14 +133,24 @@ std::string uuid_str(const uint8_t* u) { return s; } -void repair() { +// What swap_uuid did: the new UUID, how many places held the old one (G00, B00, S00) and where the copy of the save is. +struct Swap { + uint8_t to[16] = {}; + size_t total = 0, counts[3] = {}; + stdfs::path backup; +}; + +// Gives the account save a new random player UUID in every place that holds `from`: the owner stamps in CMNDAT (G00 and B00) and the +// plain copy in SYDAT. A copy of the whole account folder is kept first. False when nothing was written: no save, a pending commit or a +// failure (logged, the save is as it was). True with total 0: the save does not hold `from`. +bool swap_uuid(const uint8_t* from, Swap* r) { const stdfs::path root = save_files::account_dir(); std::error_code ec; - if (!stdfs::is_directory(root, ec)) return; // no save yet: a new game gets a random UUID now + if (!stdfs::is_directory(root, ec)) return false; // no save yet: a new game gets a random UUID now if (save_files::commit_pending()) { NXLOG_W(kTag, "player UUID: not checked, the save has an interrupted commit (%s.commit) the game finishes first; checked again next start", u8(root).c_str()); - return; + return false; } struct Part { const char* rel; @@ -147,35 +160,31 @@ void repair() { }; Part parts[] = {{"G00/CMNDAT.BIN", true}, {"B00/CMNDAT.BIN", true}, {"S00/SYDAT.BIN", false}}; - uint8_t uuid[16]; do { - entropy::fill(uuid, sizeof uuid); - uuid[6] = static_cast((uuid[6] & 0x0F) | 0x40); // version 4 - uuid[8] = static_cast((uuid[8] & 0x3F) | 0x80); // RFC 4122 variant - } while (std::memcmp(uuid, kShared, 16) == 0); + entropy::fill(r->to, sizeof r->to); + r->to[6] = static_cast((r->to[6] & 0x0F) | 0x40); // version 4 + r->to[8] = static_cast((r->to[8] & 0x3F) | 0x80); // RFC 4122 variant + } while (std::memcmp(r->to, kShared, 16) == 0 || std::memcmp(r->to, from, 16) == 0); - size_t total = 0; - for (Part& pt : parts) { + for (size_t i = 0; i < 3; ++i) { + Part& pt = parts[i]; const stdfs::path p = root / stdfs::path(pt.rel); if (!stdfs::is_regular_file(p, ec)) continue; std::string why; - if (!rewrite(p, pt.cmndat, uuid, &pt.count, &pt.data, &why)) { + if (!rewrite(p, pt.cmndat, from, r->to, &pt.count, &pt.data, &why)) { NXLOG_W(kTag, "player UUID: %s %s; the save is left as it is", u8(p).c_str(), why.c_str()); - return; + return false; } - total += pt.count; - } - if (total == 0) { - NXLOG_I(kTag, "player UUID: this save has its own (not the shared one), nothing to repair"); - return; + r->counts[i] = pt.count; + r->total += pt.count; } + if (r->total == 0) return true; // a copy of the whole account folder first - stdfs::path backup; std::string error; - if (!save_files::copy_account("uuid-backup", 0, &backup, &error)) { - NXLOG_E(kTag, "player UUID: the backup to %s failed (%s); the save is left as it is", u8(backup).c_str(), error.c_str()); - return; + if (!save_files::copy_account("uuid-backup", 0, &r->backup, &error)) { + NXLOG_E(kTag, "player UUID: the backup to %s failed (%s); the save is left as it is", u8(r->backup).c_str(), error.c_str()); + return false; } for (const Part& pt : parts) { @@ -187,15 +196,58 @@ void repair() { for (const Part& q : parts) { if (q.count == 0) continue; std::error_code e2; - stdfs::copy_file(backup / stdfs::path(q.rel), root / stdfs::path(q.rel), stdfs::copy_options::overwrite_existing, e2); + stdfs::copy_file(r->backup / stdfs::path(q.rel), root / stdfs::path(q.rel), stdfs::copy_options::overwrite_existing, e2); } NXLOG_E(kTag, "player UUID: writing %s failed (Win32 error %lu); the save was put back from %s", u8(p).c_str(), - static_cast(err), u8(backup).c_str()); + static_cast(err), u8(r->backup).c_str()); + return false; + } + return true; +} + +void repair() { + Swap r; + if (!swap_uuid(kShared, &r)) return; + if (r.total == 0) { + NXLOG_I(kTag, "player UUID: this save has its own (not the shared one), nothing to repair"); return; } NXLOG_W(kTag, "player UUID: this save had %s, the UUID every save made with older builds shares (Link Play refused visits with error " "9005); now %s (%zu places: G00 %zu, B00 %zu, S00 %zu). Backup: %s", - uuid_str(kShared).c_str(), uuid_str(uuid).c_str(), total, parts[0].count, parts[1].count, parts[2].count, u8(backup).c_str()); + uuid_str(kShared).c_str(), uuid_str(r.to).c_str(), r.total, r.counts[0], r.counts[1], r.counts[2], u8(r.backup).c_str()); +} + +// The player UUID of the account save in `root`, from its plain copy in SYDAT. False without that file or when the bytes there are not +// a version 4 UUID (nn::util::GenerateUuid makes one): then nothing is known and nothing is changed. +bool read_uuid(const stdfs::path& root, uint8_t out[16]) { + Bytes sy; + if (!read_all(root / "S00" / "SYDAT.BIN", &sy) || sy.size() < kSysUuidAt + 16) return false; + const uint8_t* u = sy.data() + kSysUuidAt; + if ((u[6] & 0xF0) != 0x40 || (u[8] & 0xC0) != 0x80) return false; + std::memcpy(out, u, 16); + return true; +} + +// Split screen's second window: its save may be a copy of the first player's (the launcher makes one for a second player who has no +// save), and the first window's game refuses a visitor with its own UUID. So a save here with the first save's UUID gets a new one. +void second_player() { + const std::string first = split::first_account(); + if (split::window() != 2 || first.empty()) return; + uint8_t mine[16], theirs[16]; + if (!read_uuid(save_files::account_dir(), mine)) { + NXLOG_I(kTag, "split screen: the second player has no save with a player UUID yet (a new game makes one)"); + return; + } + if (!read_uuid(save_files::save_dir() / "account" / first, theirs) || std::memcmp(mine, theirs, 16) != 0) { + NXLOG_I(kTag, "split screen: the second player's save has a player UUID of its own (%s)", uuid_str(mine).c_str()); + return; + } + Swap r; + if (!swap_uuid(mine, &r)) return; + if (r.total == 0) return; + NXLOG_I(kTag, "split screen: the second player's save was a copy of the first player's (player UUID %s); now %s (%zu places: G00 %zu, " + "B00 %zu, S00 %zu). Backup: %s", + uuid_str(mine).c_str(), uuid_str(r.to).c_str(), r.total, r.counts[0], r.counts[1], r.counts[2], u8(r.backup).c_str()); } } // namespace @@ -211,7 +263,10 @@ void save_uuid_repair() { } namespace { -void install(const FeatureInstall&) { save_uuid_repair(); } +void install(const FeatureInstall&) { + save_uuid_repair(); + second_player(); +} } // namespace const Feature kSaveUuidFeature = {.name = "save_uuid", .install = &install}; diff --git a/runtime/games/pkp/core/pkp_save_uuid.h b/runtime/games/pkp/core/pkp_save_uuid.h index 0b291913..2f65bd47 100644 --- a/runtime/games/pkp/core/pkp_save_uuid.h +++ b/runtime/games/pkp/core/pkp_save_uuid.h @@ -1,11 +1,15 @@ // SPDX-License-Identifier: GPL-3.0-or-later -// Pokémon Pokopia: repair of the shared player UUID (pkp_save_uuid.cpp, [pkp] uuid_repair). +// Pokémon Pokopia: a save's player UUID made its own (pkp_save_uuid.cpp): the repair of the shared one ([pkp] uuid_repair), and split +// screen's second player. // Every save is given a player UUID at new game (main 0x5aef60, nn::util::GenerateUuid at 0x5af08c), and Link Play's host refuses a // visitor with its own UUID (0x5463c0, error 9005). Until GetInfo RandomEntropy came from the OS (src/kernel/svc_info.cpp) it was one // fixed value, so every save made with this runtime got the same UUID, b9ae85ed-20e7-4f6b-89a1-9f30fcf9f0f9, and no two players could // visit each other. At start, before the game reads its save, a save with that UUID gets a fresh random one in every place it is stored: // the owner stamps in CMNDAT (G00 and its backup B00; zlib from 0x130, end offset at +0x10) and the plain copy in S00/SYDAT. STGDAT has // none. A copy of the account folder is kept first, in /uuid-backup/