Xbox Cloud Gaming app for PS5 Homebrew
C
feat(webui): add streaming lock overlay and virtual touch gamepad for P1/P2, fix age rating bug, and document 8BitDo USB study
Rafael Abud Ferreira62525639289b
diff --git a/ROADMAP.md b/ROADMAP.mdindex f6886ed..43be4d7 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -243,14 +243,43 @@ is rolled back at the next start), then the app restarts itself| Priority | Item | Why | Size || :---: | --- | --- | --- || **1** | **Hardware video decoding (PS5 & other platforms)** | Integrate `libSceVideodec2` (sysmodule 207) into the active streaming pipeline (`StreamPlayer`) on PS5 to free an entire Zen 2 CPU core, reduce jitter/thermals, and map NV12 to Vulkan textures; enable VA-API / NVDEC via FFmpeg hwaccel on desktop/Steam Deck | medium–large |-| **2** | **Expanded WebUI settings (Settings & in-stream Game Menu)** | Expand local HTTP server (port 8080): full general settings (bitrate slider, 120 Hz, dead zones, light bar, trigger vibration, queue alert) plus real-time in-stream `StreamMenu` control (CAS sharpness, FSR 1/Anime4K upscalers, deband, pad speaker volume, smart trigger profiles, live session telemetry FPS/RTT/loss) | medium |+| **2** | **Expanded WebUI features & in-stream Game Menu** | Expand local HTTP server (port 8080): **Streaming Lock** (transparent backdrop-filter blur overlay and HTTP 409 rejection blocking search and filters while playing), **Virtual Touch Gamepad** on mobile browsers (full Xbox buttons, D-pad, dual virtual analog sticks, triggers/bumpers, View/Menu/Nexus, P1 main & P2 local co-op hot-join), full general settings (bitrate slider, 120 Hz, dead zones, light bar, trigger vibration, queue alert), real-time in-stream `StreamMenu` control (CAS sharpness, FSR 1/Anime4K upscalers, deband, pad speaker volume, smart trigger profiles), and live session telemetry (FPS/RTT/loss) | medium || **3** | **Mouse navigation in desktop UI** | On desktop/Steam Deck menus, mouse hover updates focus, left click triggers cards/buttons/tabs/options, mouse wheel scrolls shelves and the 550+ title vertical grid; strictly desktop-only (`XCLOUD_DESKTOP_APP`), inactive on PS5 | small–medium || **4a** | **Native Windows build (planned)** | Cross-compiled with `llvm-mingw` (or native MSVC/CMake), SDL3/Vulkan backend, XInput & DualSense controller integration, portable standalone `.zip` distribution | medium || **4b** | **Native Android build (planned)** | Android NDK (C++20) + Java/Kotlin wrapper, hardware video decoding via `AMediaCodec`, customizable on-screen touch overlay controls, and Bluetooth gamepad support | large || **5** | **Adaptive Voice Chat (DualSense mic & speaker with fallback)** | Optional voice routing: when using DualSense, route incoming voice chat to controller speaker while game audio stays on TV; transparent fallback for generic Xbox controllers, USB/P2 headsets or PC to use standard system mic and main audio mix without blocking | medium |+| **5b** | **8BitDo 2.4G & Third-Party Wireless Controller Support on PS5** | Direct `/dev/uhid*` or `libusb` driver bypass on jailbroken PS5 to support 8BitDo Ultimate 2.4G USB RF dongle (`0x2DC8:0x3106`) without requiring `libScePad` authentication; alternative paths via WebUI virtual gamepad and hardware converters | medium || **6** | Cloud playtime left (done in client; waiting for Microsoft) | From November 2026 cloud play is capped each month (Ultimate 15 h, Premium 10 h, Essential 5 h). Client support is ready (`AuthManager::fetchPlaytimeLimit`), waiting for Microsoft to enable quota | small–medium || **7** | Home-screen tile per game (later) | The PS5 Forwarder Format (ProsperoLight): generate standalone tiles on the PS5 home screen that directly launch a cloud game (deprioritized to end of roadmap) | small |+### Technical Feasibility Study: 8BitDo Ultimate 2.4G USB Dongle on PS5++**Context & Hardware Architecture**:+The 8BitDo Ultimate 2.4G wireless controller connects via its bundled 2.4 GHz USB RF adapter (`VID 0x2DC8`, `PID 0x3106`) or over Bluetooth. In standard operation, the 2.4G dongle acts as an X-Input or D-Input USB composite HID device.++**PlayStation 5 Subsystem & Security Analysis**:+1. **FreeBSD / Prospero Kernel Subsystem**:+ - The PS5 kernel (`sys/dev/usb`) detects and enumerates the 8BitDo 2.4G USB dongle as a generic USB device (`ugen` / `uhid`).+ - The kernel creates device nodes under `/dev/uhid*` and exposes raw USB transfer endpoints.+2. **Sony Userland (`libScePad`) Whitelist & Security Enforcement**:+ - Sony's userland input framework (`libScePad` and `libScePadCustom`) strictly limits pad handles to official Sony hardware: DualSense (`VID 0x054C`, `PID 0x0CE6`), DualSense Edge (`PID 0x0DF2`), and third-party controllers equipped with an authorized Sony cryptographic hardware coprocessor.+ - The console's security coprocessor performs periodic encrypted challenge-response authentication handshakes with the controller.+ - Unlicensed USB controllers and third-party 2.4G dongles fail this handshake or are ignored by `libScePad`, which returns invalid pad handles.+3. **Bluetooth Pairing Limitations**:+ - PS5 Bluetooth stack enforces Sony-specific EAP authentication handshakes and BD_ADDR filtering during device pairing.+ - Pairing generic Bluetooth gamepads or 8BitDo controllers in Bluetooth mode directly to the PS5 fails during discovery/handshake.++**Viable Implementation Paths**:+- **Path 1: WebUI Virtual Gamepad (Zero Extra Hardware, Zero Jailbreak Dependency) — *Implemented in v1.4.0***:+ - Users can pair the 8BitDo controller (via Bluetooth or USB OTG) to their smartphone, tablet, or laptop, open `http://<ps5-ip>:8080/`, and control the PS5 stream directly over Wi-Fi.+ - Supports Player 1 (main control) or Player 2 (seamless co-op hot-joining in active streams).+- **Path 2: Hardware Converter Adapters (Zero Code, 100% Native DualSense Emulation)**:+ - Hardware translation converters (such as Brook Wingman XE 2, Brook FGC, or Mayflash Magic-S Pro 2) handle the Sony hardware challenge-response authentication while interfacing with the 8BitDo 2.4G dongle.+ - The PS5 sees a fully authorized DualSense device with full input fidelity.+- **Path 3: Direct Userland USB HID Driver (`uhid` / `libusb`) on Jailbroken PS5 — *Planned (Priority 5b)***:+ - On jailbroken consoles (Prospero 3.xx–4.xx), homebrew userland can bypass `libScePad` entirely by opening `/dev/uhid*` directly or using `libusb`.+ - A lightweight driver module (`src/input/pad_usb.cpp`) will read raw HID reports from the 8BitDo dongle in D-Input mode (16-byte report: 2 analog sticks, 2 triggers, 14 digital buttons), map them into `input::ControllerState`, and merge them directly into `input::mergePads` alongside or in place of DualSense.+## Dropped (and why)- **Discord Rich Presence (desktop)**: dropped (Xbox Live / Game Pass ecosystem already provides native activity presence).diff --git a/src/app/app_core.cpp b/src/app/app_core.cppindex 9d759e6..528271e 100644--- a/src/app/app_core.cpp+++ b/src/app/app_core.cpp@@ -15,6 +15,7 @@#include "app/report.h"#include "app/settings.h"#include "app/shell.h"+#include "app/stream_player.h"#include "app/stream_screen.h"#include "app/web_server.h"#include "display/display.h"@@ -380,7 +381,12 @@ bool coreStartup() {outFilters.set("console", g_ui->filterSelectedPublic(ui::AppUi::Filter::Console));outFilters.set("mode", g_ui->filterSelectedPublic(ui::AppUi::Filter::Mode));outFilters.set("language", g_ui->filterSelectedPublic(ui::AppUi::Filter::Language));- }+ },+ /*isStreaming=*/[]() -> bool {+ return (g_ui && (g_ui->screen() == ui::Screen::Streaming || g_ui->screen() == ui::Screen::Launching)) ||+ (g_player && g_player->running());+ },+ /*injectGamepad=*/nullptr});startWebServer();g_ui->setWebUrl(webServerUrl());@@ -467,6 +473,11 @@ bool Core::frame() {input::setGyroActive(g_ui->screen() == ui::Screen::Streaming && !streamScreen->menuOpen());input::poll(pad);autoplayPad(pad);+ input::ControllerState vpad0;+ bool vconn0 = false;+ if (virtualGamepadState(0, vpad0, vconn0) && vconn0) {+ input::mergePads(pad, vpad0);+ }// USB keyboard: the app's screens (and its menu in a game) as with the// controller; in a game otherwise, its keys and the mouse go to the game.input::KbmInput kbm = input::kbmPoll();diff --git a/src/app/cli_main.cpp b/src/app/cli_main.cppindex 0a655a8..a4d252c 100644--- a/src/app/cli_main.cpp+++ b/src/app/cli_main.cpp@@ -375,7 +375,8 @@ int cmdUiPreview(auth::AuthManager& am, const std::string& dir) {if (xcloud::fetchProducts({id}, gssv.session().market.empty() ? "US" : gssv.session().market,ui::catalogLanguage(), full, e, true) &&full.count(id))- app.setDetailInfo(id, full[id].description, full[id].publisher, full[id].categories, full[id].heroUrl);+ app.setDetailInfo(id, full[id].description, full[id].publisher, full[id].categories, full[id].heroUrl,+ full[id].ratingAge, full[id].ratingSystem, full[id].ratingDescriptors);}save("details_buy", 2000);press([](ui::NavInput& n) { n.back = true; }, 1);diff --git a/src/app/price_loop.cpp b/src/app/price_loop.cppindex ef5618d..f2ddd80 100644--- a/src/app/price_loop.cpp+++ b/src/app/price_loop.cpp@@ -119,7 +119,8 @@ void priceLoop() {bool ok = xcloud::fetchProducts({id}, market, language, full, err, true) && full.count(id);if (ok) {const auto& p = full[id];- g_ui->setDetailInfo(id, p.description, p.publisher, p.categories, p.heroUrl);+ g_ui->setDetailInfo(id, p.description, p.publisher, p.categories, p.heroUrl,+ p.ratingAge, p.ratingSystem, p.ratingDescriptors);}XC_LOGI("details of %s: %s", id.c_str(), ok ? "ok" : err.empty() ? "not in the catalog" : err.c_str());}diff --git a/src/app/stream_screen.cpp b/src/app/stream_screen.cppindex 047fd15..c26d3b5 100644--- a/src/app/stream_screen.cpp+++ b/src/app/stream_screen.cpp@@ -7,6 +7,7 @@#include "app/autoplay.h"#include "app/shell.h"#include "app/stream_player.h"+#include "app/web_server.h"#include "display/display.h"#include "input/input_ext.h"#include "input/kbm.h"@@ -450,6 +451,17 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, bif (!pad.touching) swipe_.fired = false;else if (pad.btnTouchpad) swipe_.fired = true;}+ if (!menu_.isOpen()) {+ input::ControllerState vpad0;+ bool vconn0 = false;+ if (virtualGamepadState(0, vpad0, vconn0) && vconn0) {+ input::mergePads(sent, vpad0);+ if (vpad0.btnNexus) {+ sent.btnNexus = true;+ g_xboxButtonUntil = platform::nowMs() + 250;+ }+ }+ }if (platform::nowMs() < g_xboxButtonUntil) sent.btnNexus = true;g_player->sendInput(sent);// The keyboard as another player's controller (Settings): its own@@ -502,6 +514,16 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, bfor (int i = 1; i < input::kMaxPads; ++i) {input::ControllerState other;bool on = input::pollPad(i, other);+ input::ControllerState vpad;+ bool vconn = false;+ if (virtualGamepadState(i, vpad, vconn) && vconn) {+ if (on) {+ input::mergePads(other, vpad);+ } else {+ other = vpad;+ on = true;+ }+ }if (on) other = input::applyPadMap(other, padMap_); // the same map as player 1's (the keys keep theirs)if (on && i == kbSlot) input::mergePads(other, kbPad_); // the keyboard plays with this player's padif (on != padAttached_[i]) {@@ -510,6 +532,7 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, bstd::string who = std::to_string(i + 1);std::string name = input::padUserName(i);if (!name.empty()) who += " (" + name + ")";+ else if (vconn && !input::padConnected(i)) who += " (Web Gamepad)";// The PS5 user's name on the TV, not in the log.platform::notify(ui::trf(on ? ui::Str::PadConnected : ui::Str::PadDisconnected, who),std::string("controller ") + std::to_string(i + 1) +@@ -611,6 +634,7 @@ void StreamScreen::idle() {}if (wasStreaming_) {wasStreaming_ = false;+ for (bool& a : padAttached_) a = false;overlayPlayer_ = nullptr;std::lock_guard<std::mutex> lock(g_settingsMutex);input::setDeadzone(g_settings.deadzoneLeft / 100.0f, g_settings.deadzoneRight / 100.0f);diff --git a/src/app/web_server.cpp b/src/app/web_server.cppindex 23bcb8d..aaef957 100644--- a/src/app/web_server.cpp+++ b/src/app/web_server.cpp@@ -43,7 +43,7 @@ const char* kIndexHtml = R"html(<!DOCTYPE html>--danger: #d93838;}* { box-sizing: border-box; margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }-html, body { width: 100%; max-width: 100%; overflow-x: hidden; background: var(--bg); color: var(--text); padding-bottom: 40px; }+html, body { width: 100%; max-width: 100%; overflow-x: hidden; background: var(--bg); color: var(--text); padding-bottom: 40px; overscroll-behavior: none; }header { box-sizing: border-box; background: var(--surface); border-bottom: 1px solid var(--border); padding: 12px 14px; display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; max-width: 100%; overflow-x: hidden; }.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1 1 auto; }.logo-icon { flex-shrink: 0; width: 32px; height: 32px; border-radius: 50%; box-shadow: 0 0 10px rgba(16, 124, 65, 0.45); }@@ -102,6 +102,216 @@ select { background: var(--surface); color: #fff; border: 1px solid var(--borderpre { background: #07080b; border: 1px solid var(--border); border-radius: 10px; padding: 12px; font-family: monospace; font-size: 0.78rem; color: #c4ccdc; overflow-x: auto; max-height: 380px; white-space: pre-wrap; word-break: break-all; max-width: 100%; }.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #169c53; color: #fff; padding: 10px 20px; border-radius: 24px; font-size: 0.88rem; font-weight: 600; box-shadow: 0 4px 16px rgba(0,0,0,0.5); opacity: 0; pointer-events: none; transition: opacity 0.3s; z-index: 1000; max-width: 90%; text-align: center; }.toast.show { opacity: 1; }++/* Search overlay when streaming */+.search-disabled-overlay {+ position: absolute;+ top: 0; left: 0; right: 0; bottom: 0;+ background: rgba(11, 13, 19, 0.85);+ backdrop-filter: blur(8px);+ -webkit-backdrop-filter: blur(8px);+ display: none;+ flex-direction: column;+ align-items: center;+ justify-content: center;+ border-radius: 14px;+ z-index: 50;+ color: #fff;+ text-align: center;+ padding: 20px;+}+.search-disabled-overlay .msg {+ font-size: 0.95rem;+ font-weight: 700;+ letter-spacing: 0.6px;+ background: rgba(20, 23, 34, 0.95);+ border: 1px solid var(--border);+ padding: 12px 22px;+ border-radius: 20px;+ box-shadow: 0 4px 16px rgba(0,0,0,0.6);+ display: inline-flex;+ align-items: center;+ gap: 8px;+}++/* Virtual Gamepad */+.gamepad-container {+ user-select: none;+ -webkit-user-select: none;+ touch-action: none;+ width: 100%;+ max-width: 100%;+ display: flex;+ flex-direction: column;+ gap: 12px;+}+.player-select-row {+ display: flex;+ gap: 8px;+ width: 100%;+ margin-bottom: 6px;+}+.player-btn {+ flex: 1 1 0;+ padding: 10px 8px;+ border-radius: 10px;+ border: 1px solid var(--border);+ background: var(--surface-alt);+ color: var(--text-dim);+ font-size: clamp(0.78rem, 3.2vw, 0.88rem);+ font-weight: 700;+ cursor: pointer;+ text-align: center;+ transition: all 0.2s;+}+.player-btn.active {+ background: var(--primary);+ border-color: var(--primary);+ color: #fff;+ box-shadow: 0 2px 8px rgba(16, 124, 65, 0.4);+}+.pad-top-row {+ display: flex;+ justify-content: space-between;+ align-items: center;+ gap: 8px;+ width: 100%;+}+.pad-bumper-group {+ display: flex;+ flex-direction: column;+ gap: 6px;+}+.pad-btn {+ display: inline-flex;+ align-items: center;+ justify-content: center;+ background: var(--surface-alt);+ border: 1px solid var(--border);+ border-radius: 10px;+ color: #fff;+ font-weight: 700;+ cursor: pointer;+ touch-action: none;+ user-select: none;+ -webkit-user-select: none;+ transition: transform 0.08s, background 0.08s, border-color 0.08s;+ box-shadow: 0 2px 5px rgba(0,0,0,0.3);+}+.pad-btn:active, .pad-btn.pressed {+ transform: scale(0.92);+ background: var(--primary) !important;+ border-color: #4ade80 !important;+ box-shadow: 0 0 10px rgba(16, 124, 65, 0.6) !important;+}+.pad-btn-sm {+ width: 68px;+ height: 38px;+ font-size: 0.80rem;+}+.pad-center-group {+ display: flex;+ gap: 6px;+ align-items: center;+}+.pad-btn-center {+ padding: 8px 12px;+ font-size: 0.72rem;+ border-radius: 8px;+ background: #1e2433;+}+.pad-btn-nexus {+ width: 44px;+ height: 44px;+ border-radius: 50%;+ background: #107c41;+ border: 2px solid #fff;+ font-size: 0.80rem;+ font-weight: 900;+}+.pad-main-row {+ display: flex;+ justify-content: space-around;+ align-items: center;+ gap: 12px;+ margin-top: 8px;+ width: 100%;+}+.pad-side {+ flex: 1 1 0;+ display: flex;+ flex-direction: column;+ align-items: center;+ gap: 14px;+}+.dpad-cross {+ position: relative;+ width: 136px;+ height: 136px;+}+.dpad-btn {+ position: absolute;+ width: 44px;+ height: 44px;+ border-radius: 8px;+ font-size: 1.1rem;+}+.dpad-up { top: 0; left: 46px; }+.dpad-down { bottom: 0; left: 46px; }+.dpad-left { top: 46px; left: 0; }+.dpad-right { top: 46px; right: 0; }+.dpad-center {+ position: absolute;+ top: 46px; left: 46px;+ width: 44px; height: 44px;+ background: var(--surface);+}+.abxy-group {+ position: relative;+ width: 136px;+ height: 136px;+}+.abxy-btn {+ position: absolute;+ width: 44px;+ height: 44px;+ border-radius: 50%;+ font-size: 1.15rem;+ font-weight: 900;+ color: #fff;+}+.btn-y { top: 0; left: 46px; background: #c68900; border-color: #ffc400; }+.btn-a { bottom: 0; left: 46px; background: #0e6b37; border-color: #107c41; }+.btn-x { top: 46px; left: 0; background: #006eb8; border-color: #00a2ed; }+.btn-b { top: 46px; right: 0; background: #b80d1b; border-color: #e81123; }+.stick-zone {+ position: relative;+ width: 110px;+ height: 110px;+ border-radius: 50%;+ background: var(--surface-alt);+ border: 2px solid var(--border);+ touch-action: none;+ display: flex;+ align-items: center;+ justify-content: center;+}+.stick-head {+ width: 50px;+ height: 50px;+ border-radius: 50%;+ background: radial-gradient(circle at 35% 35%, #3a445e, #1c2130);+ border: 2px solid #58688a;+ box-shadow: 0 4px 8px rgba(0,0,0,0.5);+ pointer-events: none;+ transform: translate(0px, 0px);+ display: flex;+ align-items: center;+ justify-content: center;+ font-size: 0.70rem;+ font-weight: 800;+ color: var(--text-dim);+}</style></head><body>@@ -121,14 +331,18 @@ pre { background: #07080b; border: 1px solid var(--border); border-radius: 10px;<div class="nav-tabs"><div class="nav-tab active" id="navTab-search" onclick="switchTab('search')">🔍 Busca</div>- <div class="nav-tab" id="navTab-remap" onclick="switchTab('remap')">🎮 Controles</div>+ <div class="nav-tab" id="navTab-remap" onclick="switchTab('remap')">⚙️ Mapeamento</div>+ <div class="nav-tab" id="navTab-gamepad" onclick="switchTab('gamepad')">🎮 Controle</div><div class="nav-tab" id="navTab-logs" onclick="switchTab('logs')">📋 Logs</div></div><div class="content"><!-- TAB: SEARCH --><div id="tab-search" class="tab-pane">- <div class="card">+ <div class="card" id="searchCard" style="position: relative;">+ <div id="searchOverlay" class="search-disabled-overlay" style="display: none;">+ <div class="msg">🔒 Desativado enquanto jogando</div>+ </div><h2>🔍 Teclado Remoto para Busca</h2><p>Digite no celular para atualizar a pesquisa ativa na TV em tempo real sem precisar do controle.</p>@@ -274,6 +488,81 @@ pre { background: #07080b; border: 1px solid var(--border); border-radius: 10px;</div></div>+ <!-- TAB: GAMEPAD (CONTROLE VIRTUAL) -->+ <div id="tab-gamepad" class="tab-pane" style="display:none;">+ <div class="card">+ <h2>🎮 Controle Virtual (Smartphone)</h2>+ <p>Use o celular como controle tátil responsivo. Alterne entre Jogador 1 (principal) e Jogador 2 (co-op local)!</p>++ <div class="player-select-row">+ <button type="button" class="player-btn active" id="btnPlayer1" onclick="setVirtualPlayer(1)">+ 👤 Jogador 1 (Principal)+ </button>+ <button type="button" class="player-btn" id="btnPlayer2" onclick="setVirtualPlayer(2)">+ 👥 Jogador 2 (Co-op Local)+ </button>+ </div>++ <div class="gamepad-container" id="gamepadArea">+ <!-- Top row: Bumpers / Triggers / Center -->+ <div class="pad-top-row">+ <div class="pad-bumper-group">+ <button type="button" class="pad-btn pad-btn-sm" id="btn_lt" data-btn="triggerL2">LT</button>+ <button type="button" class="pad-btn pad-btn-sm" id="btn_lb" data-btn="btnL1">LB</button>+ <button type="button" class="pad-btn pad-btn-sm" id="btn_ls" data-btn="btnL3">LS (L3)</button>+ </div>+ <div class="pad-center-group">+ <button type="button" class="pad-btn pad-btn-center" id="btn_view" data-btn="btnView">VIEW</button>+ <button type="button" class="pad-btn pad-btn-nexus" id="btn_nexus" data-btn="btnNexus">X</button>+ <button type="button" class="pad-btn pad-btn-center" id="btn_menu" data-btn="btnMenu">MENU</button>+ </div>+ <div class="pad-bumper-group">+ <button type="button" class="pad-btn pad-btn-sm" id="btn_rt" data-btn="triggerR2">RT</button>+ <button type="button" class="pad-btn pad-btn-sm" id="btn_rb" data-btn="btnR1">RB</button>+ <button type="button" class="pad-btn pad-btn-sm" id="btn_rs" data-btn="btnR3">RS (R3)</button>+ </div>+ </div>++ <!-- Main row: Left (D-pad & Left Stick) and Right (ABXY & Right Stick) -->+ <div class="pad-main-row">+ <div class="pad-side">+ <!-- Left Stick -->+ <div class="stick-zone" id="leftStickZone">+ <div class="stick-head" id="leftStickHead">L3</div>+ </div>+ <!-- D-Pad -->+ <div class="dpad-cross">+ <button type="button" class="pad-btn dpad-btn dpad-up" data-btn="dpadUp">▲</button>+ <button type="button" class="pad-btn dpad-btn dpad-left" data-btn="dpadLeft">◀</button>+ <div class="dpad-center"></div>+ <button type="button" class="pad-btn dpad-btn dpad-right" data-btn="dpadRight">▶</button>+ <button type="button" class="pad-btn dpad-btn dpad-down" data-btn="dpadDown">▼</button>+ </div>+ </div>++ <div class="pad-side">+ <!-- ABXY Buttons -->+ <div class="abxy-group">+ <button type="button" class="pad-btn abxy-btn btn-y" data-btn="btnY">Y</button>+ <button type="button" class="pad-btn abxy-btn btn-x" data-btn="btnX">X</button>+ <button type="button" class="pad-btn abxy-btn btn-b" data-btn="btnB">B</button>+ <button type="button" class="pad-btn abxy-btn btn-a" data-btn="btnA">A</button>+ </div>+ <!-- Right Stick -->+ <div class="stick-zone" id="rightStickZone">+ <div class="stick-head" id="rightStickHead">R3</div>+ </div>+ </div>+ </div>+ </div>++ <div class="status-pill" style="margin-top: 14px;">+ <div class="status-dot"></div>+ <span id="gamepadStatus">Controle ativo para Jogador 1 (Principal)</span>+ </div>+ </div>+ </div>+<!-- TAB: LOGS --><div id="tab-logs" class="tab-pane" style="display:none;"><div class="card">@@ -368,6 +657,8 @@ function switchTab(name) {if (pane) pane.style.display = 'block';const tabBtn = document.getElementById('navTab-' + name);if (tabBtn) tabBtn.classList.add('active');+ if (name === 'search') pollStreamingState();+ if (name === 'gamepad') sendPadState();}function switchRemapSub(mode) {@@ -715,6 +1006,204 @@ fetch('/api/settings').then(r => r.json()).then(s => {renderPadMap();renderKeyMap();});++// --- Virtual Gamepad & Streaming Polling ---+let activePlayer = 1;+const padState = {+ btnA: false, btnB: false, btnX: false, btnY: false,+ dpadUp: false, dpadDown: false, dpadLeft: false, dpadRight: false,+ btnL1: false, btnR1: false, btnL3: false, btnR3: false,+ btnView: false, btnMenu: false, btnNexus: false,+ triggerL2: 0.0, triggerR2: 0.0,+ leftStickX: 0.0, leftStickY: 0.0,+ rightStickX: 0.0, rightStickY: 0.0+};+let padSendScheduled = false;++function setVirtualPlayer(p) {+ activePlayer = p;+ document.getElementById('btnPlayer1').classList.toggle('active', p === 1);+ document.getElementById('btnPlayer2').classList.toggle('active', p === 2);+ const statusEl = document.getElementById('gamepadStatus');+ if (statusEl) {+ statusEl.textContent = 'Controle ativo para Jogador ' + p + (p === 2 ? ' (Co-op Local)' : ' (Principal)');+ }+ sendPadState();+}++function sendPadState() {+ const payload = { player: activePlayer, ...padState };+ fetch('/api/gamepad', {+ method: 'POST',+ headers: { 'Content-Type': 'application/json' },+ body: JSON.stringify(payload)+ }).catch(() => {});+}++function schedulePadSend() {+ if (padSendScheduled) return;+ padSendScheduled = true;+ requestAnimationFrame(() => {+ padSendScheduled = false;+ sendPadState();+ });+}++function bindPadButtons() {+ document.querySelectorAll('[data-btn]').forEach(el => {+ const key = el.getAttribute('data-btn');+ const isTrigger = key === 'triggerL2' || key === 'triggerR2';++ const onDown = (e) => {+ e.preventDefault();+ if (isTrigger) padState[key] = 1.0;+ else padState[key] = true;+ el.classList.add('pressed');+ if (navigator.vibrate) {+ try { navigator.vibrate(14); } catch (_) {}+ }+ sendPadState();+ };++ const onUp = (e) => {+ e.preventDefault();+ if (isTrigger) padState[key] = 0.0;+ else padState[key] = false;+ el.classList.remove('pressed');+ sendPadState();+ };++ el.addEventListener('touchstart', onDown, { passive: false });+ el.addEventListener('touchend', onUp, { passive: false });+ el.addEventListener('touchcancel', onUp, { passive: false });+ el.addEventListener('mousedown', onDown);+ el.addEventListener('mouseup', onUp);+ el.addEventListener('mouseleave', onUp);+ });+}++function setupStick(zoneId, headId, stickKeyX, stickKeyY, l3r3Key) {+ const zone = document.getElementById(zoneId);+ const head = document.getElementById(headId);+ if (!zone || !head) return;++ let activeTouchId = null;+ const maxR = 34;++ let touchStartMs = 0;+ let startX = 0, startY = 0;++ function updateStick(clientX, clientY) {+ const rect = zone.getBoundingClientRect();+ const cx = rect.left + rect.width / 2;+ const cy = rect.top + rect.height / 2;+ let dx = clientX - cx;+ let dy = clientY - cy;+ const dist = Math.hypot(dx, dy);+ if (dist > maxR) {+ dx = (dx / dist) * maxR;+ dy = (dy / dist) * maxR;+ }+ head.style.transform = `translate(${dx}px, ${dy}px)`;+ padState[stickKeyX] = Math.round((dx / maxR) * 100) / 100;+ padState[stickKeyY] = Math.round((dy / maxR) * 100) / 100;+ schedulePadSend();+ }++ function resetStick() {+ head.style.transform = 'translate(0px, 0px)';+ padState[stickKeyX] = 0.0;+ padState[stickKeyY] = 0.0;+ activeTouchId = null;+ sendPadState();+ }++ zone.addEventListener('touchstart', (e) => {+ e.preventDefault();+ if (activeTouchId === null && e.changedTouches.length > 0) {+ activeTouchId = e.changedTouches[0].identifier;+ touchStartMs = Date.now();+ startX = e.changedTouches[0].clientX;+ startY = e.changedTouches[0].clientY;+ updateStick(e.changedTouches[0].clientX, e.changedTouches[0].clientY);+ }+ }, { passive: false });++ zone.addEventListener('touchmove', (e) => {+ e.preventDefault();+ for (let i = 0; i < e.changedTouches.length; i++) {+ if (e.changedTouches[i].identifier === activeTouchId) {+ updateStick(e.changedTouches[i].clientX, e.changedTouches[i].clientY);+ break;+ }+ }+ }, { passive: false });++ const onTouchEnd = (e) => {+ for (let i = 0; i < e.changedTouches.length; i++) {+ if (e.changedTouches[i].identifier === activeTouchId) {+ const duration = Date.now() - touchStartMs;+ const moveDist = Math.hypot(e.changedTouches[i].clientX - startX, e.changedTouches[i].clientY - startY);+ resetStick();+ if (duration < 300 && moveDist < 12) {+ padState[l3r3Key] = true;+ sendPadState();+ setTimeout(() => {+ padState[l3r3Key] = false;+ sendPadState();+ }, 150);+ }+ break;+ }+ }+ };+ zone.addEventListener('touchend', onTouchEnd, { passive: false });+ zone.addEventListener('touchcancel', onTouchEnd, { passive: false });++ // Mouse fallback+ let isMouseDown = false;+ zone.addEventListener('mousedown', (e) => {+ isMouseDown = true;+ updateStick(e.clientX, e.clientY);+ });+ window.addEventListener('mousemove', (e) => {+ if (isMouseDown) updateStick(e.clientX, e.clientY);+ });+ window.addEventListener('mouseup', () => {+ if (isMouseDown) {+ isMouseDown = false;+ resetStick();+ }+ });+}++bindPadButtons();+setupStick('leftStickZone', 'leftStickHead', 'leftStickX', 'leftStickY', 'btnL3');+setupStick('rightStickZone', 'rightStickHead', 'rightStickX', 'rightStickY', 'btnR3');++// Periodic streaming state poll and search overlay lock+let isCurrentlyStreaming = false;+function pollStreamingState() {+ fetch('/api/status').then(r => r.json()).then(data => {+ const streaming = !!data.streaming;+ if (streaming !== isCurrentlyStreaming) {+ isCurrentlyStreaming = streaming;+ const overlay = document.getElementById('searchOverlay');+ if (overlay) overlay.style.display = streaming ? 'flex' : 'none';+ if (searchInput) searchInput.disabled = streaming;+ }+ }).catch(() => {});+}+setInterval(pollStreamingState, 1500);+pollStreamingState();++// Gamepad keepalive while gamepad tab is open (300ms ensures held buttons never drop)+setInterval(() => {+ const gpPane = document.getElementById('tab-gamepad');+ if (gpPane && gpPane.style.display !== 'none') {+ sendPadState();+ }+}, 300);</script></body></html>)html";@@ -927,6 +1416,46 @@ void WebServer::handleClient(int clientFd) {}}+namespace {+struct VirtualGamepadSlot {+ input::ControllerState state{};+ uint64_t lastActiveMs = 0;+};+std::mutex s_vpadMutex;+VirtualGamepadSlot s_virtualPads[2];+} // namespace++bool virtualGamepadState(int playerIndex, input::ControllerState& outState, bool& isConnected) {+ if (playerIndex < 0 || playerIndex > 1) {+ isConnected = false;+ outState = {};+ return false;+ }+ std::lock_guard<std::mutex> lock(s_vpadMutex);+ uint64_t now = platform::nowMs();+ uint64_t diff = now > s_virtualPads[playerIndex].lastActiveMs ? now - s_virtualPads[playerIndex].lastActiveMs : 0;+ isConnected = (s_virtualPads[playerIndex].lastActiveMs > 0 && diff < 4000);+ if (diff < 2000) {+ outState = s_virtualPads[playerIndex].state;+ } else {+ outState = {};+ }+ return isConnected;+}++void setVirtualGamepad(int playerIndex, const input::ControllerState& state) {+ if (playerIndex < 0 || playerIndex > 1) return;+ std::lock_guard<std::mutex> lock(s_vpadMutex);+ s_virtualPads[playerIndex].state = state;+ s_virtualPads[playerIndex].lastActiveMs = platform::nowMs();+}++void resetVirtualGamepads() {+ std::lock_guard<std::mutex> lock(s_vpadMutex);+ s_virtualPads[0] = {};+ s_virtualPads[1] = {};+}+static WebServerHooks s_hooks;void setWebServerHooks(WebServerHooks hooks) {@@ -943,9 +1472,11 @@ WebServer::HttpResponse WebServer::handleRequest(const std::string& method, consif (path == "/" || path == "/index.html") {return {200, "text/html; charset=utf-8", "", kIndexHtml};}- if (path == "/api/settings" || path == "/api/status") {+ if (path == "/api/settings" || path == "/api/status" || path == "/api/state") {json::Value root = json::Value::object();root.set("ok", true);+ bool streaming = s_hooks.isStreaming ? s_hooks.isStreaming() : false;+ root.set("streaming", streaming);if (s_hooks.getSettings) {s_hooks.getSettings(root);} else {@@ -981,7 +1512,69 @@ WebServer::HttpResponse WebServer::handleRequest(const std::string& method, cons}if (method == "POST") {+ if (path == "/api/gamepad" || path == "/api/input") {+ auto j = json::parse(body);+ if (!j || !j->isObject()) {+ return {400, "application/json", "", "{\"ok\":false,\"error\":\"invalid json\"}"};+ }+ int slot = 0;+ if ((*j).has("playerIndex")) {+ slot = static_cast<int>((*j)["playerIndex"].asInt(0));+ } else if ((*j).has("player")) {+ int p = static_cast<int>((*j)["player"].asInt(1));+ slot = (p == 2) ? 1 : 0;+ }+ if (slot < 0) slot = 0;+ if (slot > 1) slot = 1;+ int player = slot + 1;++ input::ControllerState s{};+ if ((*j).has("btnA")) s.btnA = (*j)["btnA"].asBool(false);+ if ((*j).has("btnB")) s.btnB = (*j)["btnB"].asBool(false);+ if ((*j).has("btnX")) s.btnX = (*j)["btnX"].asBool(false);+ if ((*j).has("btnY")) s.btnY = (*j)["btnY"].asBool(false);++ if ((*j).has("dpadUp")) s.dpadUp = (*j)["dpadUp"].asBool(false);+ if ((*j).has("dpadDown")) s.dpadDown = (*j)["dpadDown"].asBool(false);+ if ((*j).has("dpadLeft")) s.dpadLeft = (*j)["dpadLeft"].asBool(false);+ if ((*j).has("dpadRight")) s.dpadRight = (*j)["dpadRight"].asBool(false);++ if ((*j).has("btnL1")) s.btnL1 = (*j)["btnL1"].asBool(false);+ if ((*j).has("btnR1")) s.btnR1 = (*j)["btnR1"].asBool(false);+ if ((*j).has("btnL3")) s.btnL3 = (*j)["btnL3"].asBool(false);+ if ((*j).has("btnR3")) s.btnR3 = (*j)["btnR3"].asBool(false);++ if ((*j).has("btnView")) s.btnTouchpad = (*j)["btnView"].asBool(false);+ if ((*j).has("btnMenu")) s.btnOptions = (*j)["btnMenu"].asBool(false);+ if ((*j).has("btnNexus")) s.btnNexus = (*j)["btnNexus"].asBool(false);++ if ((*j).has("triggerL2")) s.triggerL2 = static_cast<float>((*j)["triggerL2"].asNumber(0.0));+ if ((*j).has("triggerR2")) s.triggerR2 = static_cast<float>((*j)["triggerR2"].asNumber(0.0));++ if ((*j).has("leftStickX")) s.leftStickX = static_cast<float>((*j)["leftStickX"].asNumber(0.0));+ if ((*j).has("leftStickY")) s.leftStickY = static_cast<float>((*j)["leftStickY"].asNumber(0.0));+ if ((*j).has("rightStickX")) s.rightStickX = static_cast<float>((*j)["rightStickX"].asNumber(0.0));+ if ((*j).has("rightStickY")) s.rightStickY = static_cast<float>((*j)["rightStickY"].asNumber(0.0));++ setVirtualGamepad(slot, s);+ if (s_hooks.injectGamepad) {+ s_hooks.injectGamepad(slot, s);+ }++ json::Value res = json::Value::object();+ res.set("ok", true);+ res.set("player", player);+ return {200, "application/json", "", res.dump()};+ }if (path == "/api/search") {+ bool streaming = s_hooks.isStreaming ? s_hooks.isStreaming() : false;+ if (streaming) {+ json::Value res = json::Value::object();+ res.set("ok", false);+ res.set("error", "streaming_active");+ res.set("message", "Desativado enquanto jogando");+ return {409, "application/json", "", res.dump()};+ }auto j = json::parse(body);std::string q;std::string tab = "gamepass";diff --git a/src/app/web_server.h b/src/app/web_server.hindex 43a5803..39fd249 100644--- a/src/app/web_server.h+++ b/src/app/web_server.h@@ -4,6 +4,7 @@// live search typing, and log download via mobile browser / QR code.#pragma once+#include "input/controller.h"#include "platform/platform.h"#include "util/json.h"@@ -22,9 +23,19 @@ struct WebServerHooks {std::function<void(const std::string& query)> setSearchQuery;std::function<void(const std::string* query, const std::string* tab, const json::Value* filters)> setSearchParams;std::function<void(std::string& outQuery, std::string& outTab, json::Value& outFilters)> getSearchParams;+ std::function<bool()> isStreaming;+ std::function<void(int playerIndex, const input::ControllerState& state)> injectGamepad;};void setWebServerHooks(WebServerHooks hooks);+// Virtual gamepad input query:+// playerIndex: 0 = Player 1, 1 = Player 2+// outState: contains current active buttons/axes (resets to neutral after ~600ms of inactivity)+// isConnected: true if any report/keepalive received within ~3000ms+bool virtualGamepadState(int playerIndex, input::ControllerState& outState, bool& isConnected);+void setVirtualGamepad(int playerIndex, const input::ControllerState& state);+void resetVirtualGamepads();+class WebServer {public:WebServer();diff --git a/src/input/keyboard_nav.cpp b/src/input/keyboard_nav.cppindex 1f8a4ca..cb8fad0 100644--- a/src/input/keyboard_nav.cpp+++ b/src/input/keyboard_nav.cpp@@ -93,6 +93,7 @@ void mergePads(ControllerState& pad, const ControllerState& e) {pad.btnR3 |= e.btnR3;pad.btnOptions |= e.btnOptions;pad.btnTouchpad |= e.btnTouchpad;+ pad.btnNexus |= e.btnNexus;auto further = [](float& a, float b) {if (std::abs(b) > std::abs(a)) a = b;};diff --git a/src/ui/app_ui.cpp b/src/ui/app_ui.cppindex 26aa4ae..e44db92 100644--- a/src/ui/app_ui.cpp+++ b/src/ui/app_ui.cpp@@ -759,7 +759,8 @@ std::vector<std::string> AppUi::pricesWanted(size_t max, bool background) {std::string AppUi::detailWanted(uint64_t nowMs) {std::lock_guard<std::mutex> lock(mutex_);if (screen_ != Screen::Details || detail_.productId.empty()) return {};- if (!detail_.description.empty() && !detail_.heroUrl.empty()) return {};+ if (detailInfo_.find(detail_.productId) != detailInfo_.end()) return {};+ if (!detail_.description.empty() && !detail_.heroUrl.empty() && !detail_.ratingAge.empty()) return {};if (detail_.productId == detailAskedFor_ && nowMs - detailAskedAt_ < 5000) return {};detailAskedFor_ = detail_.productId;detailAskedAt_ = nowMs;@@ -820,14 +821,19 @@ std::string AppUi::tileName(const std::string& productId) const {}void AppUi::setDetailInfo(const std::string& productId, const std::string& description, const std::string& publisher,- const std::vector<std::string>& categories, const std::string& heroUrl) {+ const std::vector<std::string>& categories, const std::string& heroUrl,+ const std::string& ratingAge, const std::string& ratingSystem,+ const std::vector<std::string>& ratingDescriptors) {std::lock_guard<std::mutex> lock(mutex_);- detailInfo_[productId] = {description, publisher, heroUrl, categories};+ detailInfo_[productId] = {description, publisher, heroUrl, categories, ratingAge, ratingSystem, ratingDescriptors};if (detail_.productId != productId) return;if (!description.empty()) detail_.description = description;if (!publisher.empty()) detail_.publisher = publisher;if (!categories.empty()) detail_.categories = categories;if (!heroUrl.empty()) detail_.heroUrl = heroUrl;+ if (!ratingAge.empty()) detail_.ratingAge = ratingAge;+ if (!ratingSystem.empty()) detail_.ratingSystem = ratingSystem;+ if (!ratingDescriptors.empty()) detail_.ratingDescriptors = ratingDescriptors;dirty_ = true;}@@ -977,6 +983,9 @@ void AppUi::openDetails(const GameTile& tile) {if (detail_.heroUrl.empty()) detail_.heroUrl = info->second.heroUrl;if (detail_.publisher.empty()) detail_.publisher = info->second.publisher;if (detail_.categories.empty()) detail_.categories = info->second.categories;+ if (detail_.ratingAge.empty()) detail_.ratingAge = info->second.ratingAge;+ if (detail_.ratingSystem.empty()) detail_.ratingSystem = info->second.ratingSystem;+ if (detail_.ratingDescriptors.empty()) detail_.ratingDescriptors = info->second.ratingDescriptors;}detailButtonFocus_ = 0;screen_ = Screen::Details;@@ -986,15 +995,30 @@ void AppUi::openDetails(const GameTile& tile) {void AppUi::refreshDetail() {// Caller holds mutex_. Hero art and descriptions arrive after the page opened.if (screen_ != Screen::Details || detail_.productId.empty()) return;+ bool changed = false;auto take = [&](const GameTile& t) {- if (t.productId == detail_.productId && t.heroUrl.size() + t.description.size() >- detail_.heroUrl.size() + detail_.description.size())- detail_ = t;+ if (t.productId == detail_.productId) {+ if (t.heroUrl.size() + t.description.size() >+ detail_.heroUrl.size() + detail_.description.size()) {+ detail_.heroUrl = t.heroUrl;+ detail_.description = t.description;+ if (!t.publisher.empty()) detail_.publisher = t.publisher;+ if (!t.categories.empty()) detail_.categories = t.categories;+ changed = true;+ }+ if (detail_.ratingAge.empty() && !t.ratingAge.empty()) {+ detail_.ratingAge = t.ratingAge;+ detail_.ratingSystem = t.ratingSystem;+ detail_.ratingDescriptors = t.ratingDescriptors;+ changed = true;+ }+ }};for (const auto& row : rows_)for (const auto& t : row.tiles) take(t);for (const auto* list : {&owned_, &purchasable_, &gamePassPool_, &libraryPool_})for (const auto& t : *list) take(t);+ if (changed) dirty_ = true;}void AppUi::runSearch() {diff --git a/src/ui/app_ui.h b/src/ui/app_ui.hindex 79810b0..00aaa5b 100644--- a/src/ui/app_ui.h+++ b/src/ui/app_ui.h@@ -341,7 +341,9 @@ public:// Fills in the open page when it shows `productId`, and keeps the details// for the next time that game's page opens.void setDetailInfo(const std::string& productId, const std::string& description, const std::string& publisher,- const std::vector<std::string>& categories, const std::string& heroUrl);+ const std::vector<std::string>& categories, const std::string& heroUrl,+ const std::string& ratingAge = {}, const std::string& ratingSystem = {},+ const std::vector<std::string>& ratingDescriptors = {});// Opens a game's page (autoplay tests).void showDetails(const GameTile& tile);// The `index`-th game to buy, if loaded (autoplay tests).@@ -668,6 +670,8 @@ private:struct DetailInfo {std::string description, publisher, heroUrl;std::vector<std::string> categories;+ std::string ratingAge, ratingSystem;+ std::vector<std::string> ratingDescriptors;};std::map<std::string, DetailInfo> detailInfo_; // fetched on demand, by product idstd::string updateCurrent_, updateAvailable_, updateNotes_;diff --git a/src/xcloud/catalog.cpp b/src/xcloud/catalog.cppindex 9020847..55b528c 100644--- a/src/xcloud/catalog.cpp+++ b/src/xcloud/catalog.cpp@@ -197,6 +197,62 @@ void parseContentRatings(const json::Value& p, const std::string& market,outSystem.clear();outDescriptors.clear();+ struct Candidate {+ std::string system;+ std::string rawId;+ int age = -1;+ std::vector<std::string> descriptors;+ };+ std::vector<Candidate> candidates;++ // Microsoft Game Pass v3 catalog API returns singular "ContentRating" object in hydration+ const json::Value* singleRating = nullptr;+ if (p.has("ContentRating") && p["ContentRating"].isObject()) {+ singleRating = &p["ContentRating"];+ } else if (p.has("MarketProperties") && p["MarketProperties"].isArray() && p["MarketProperties"].size() > 0) {+ const auto& mp0 = p["MarketProperties"][0];+ if (mp0.has("ContentRating") && mp0["ContentRating"].isObject()) {+ singleRating = &mp0["ContentRating"];+ }+ } else if (p.has("LocalizedProperties") && p["LocalizedProperties"].isArray() && p["LocalizedProperties"].size() > 0) {+ const auto& lp0 = p["LocalizedProperties"][0];+ if (lp0.has("ContentRating") && lp0["ContentRating"].isObject()) {+ singleRating = &lp0["ContentRating"];+ }+ }++ if (singleRating) {+ Candidate c;+ c.system = (*singleRating)["RatingSystem"].str();+ if (c.system.empty()) c.system = (*singleRating)["ratingSystem"].str();+ if (c.system.empty()) c.system = (*singleRating)["RatingSystemId"].str();++ c.rawId = (*singleRating)["LongName"].str();+ if (c.rawId.empty()) c.rawId = (*singleRating)["RatingId"].str();+ if (c.rawId.empty()) c.rawId = (*singleRating)["ratingId"].str();+ if (c.rawId.empty()) c.rawId = (*singleRating)["Description"].str();++ if ((*singleRating).has("Age")) {+ c.age = static_cast<int>((*singleRating)["Age"].asInt(-1));+ }++ auto descVal = (*singleRating).has("LocalizedDescriptors") ? (*singleRating)["LocalizedDescriptors"]+ : (*singleRating).has("RatingDescriptors") ? (*singleRating)["RatingDescriptors"]+ : (*singleRating)["ratingDescriptors"];+ if (descVal.isArray()) {+ for (const auto& d : descVal.items()) {+ if (d.isString() && !d.str().empty()) c.descriptors.push_back(d.str());+ }+ }+ if ((*singleRating).has("LocalizedInteractiveElements") && (*singleRating)["LocalizedInteractiveElements"].isArray()) {+ for (const auto& d : (*singleRating)["LocalizedInteractiveElements"].items()) {+ if (d.isString() && !d.str().empty()) c.descriptors.push_back(d.str());+ }+ }+ if (!c.rawId.empty() || c.age >= 0) candidates.push_back(std::move(c));+ }++ // Also parse array format if present ("ContentRatings")const json::Value* ratingsArray = nullptr;if (p.has("ContentRatings") && p["ContentRatings"].isArray()) {ratingsArray = &p["ContentRatings"];@@ -212,44 +268,39 @@ void parseContentRatings(const json::Value& p, const std::string& market,}}- if (!ratingsArray || ratingsArray->items().empty()) return;-- struct Candidate {- std::string system;- std::string rawId;- std::vector<std::string> descriptors;- };- std::vector<Candidate> candidates;-- for (const auto& item : ratingsArray->items()) {- Candidate c;- c.system = item["RatingSystem"].str();- if (c.system.empty()) c.system = item["ratingSystem"].str();- if (c.system.empty()) c.system = item["RatingSystemId"].str();-- c.rawId = item["RatingId"].str();- if (c.rawId.empty()) c.rawId = item["ratingId"].str();- if (c.rawId.empty()) c.rawId = item["RatingName"].str();- if (c.rawId.empty()) c.rawId = item["ratingName"].str();-- auto descVal = item.has("RatingDescriptors") ? item["RatingDescriptors"] : item["ratingDescriptors"];- if (descVal.isArray()) {- for (const auto& d : descVal.items()) {- if (d.isString()) {- if (!d.str().empty()) c.descriptors.push_back(d.str());- } else if (d.isObject()) {- std::string s = d["Name"].str();- if (s.empty()) s = d["Descriptor"].str();- if (!s.empty()) c.descriptors.push_back(s);+ if (ratingsArray) {+ for (const auto& item : ratingsArray->items()) {+ Candidate c;+ c.system = item["RatingSystem"].str();+ if (c.system.empty()) c.system = item["ratingSystem"].str();+ if (c.system.empty()) c.system = item["RatingSystemId"].str();++ c.rawId = item["RatingId"].str();+ if (c.rawId.empty()) c.rawId = item["ratingId"].str();+ if (c.rawId.empty()) c.rawId = item["RatingName"].str();+ if (c.rawId.empty()) c.rawId = item["ratingName"].str();+ if (c.rawId.empty()) c.rawId = item["LongName"].str();+ if (item.has("Age")) c.age = static_cast<int>(item["Age"].asInt(-1));++ auto descVal = item.has("RatingDescriptors") ? item["RatingDescriptors"] : item["ratingDescriptors"];+ if (descVal.isArray()) {+ for (const auto& d : descVal.items()) {+ if (d.isString()) {+ if (!d.str().empty()) c.descriptors.push_back(d.str());+ } else if (d.isObject()) {+ std::string s = d["Name"].str();+ if (s.empty()) s = d["Descriptor"].str();+ if (!s.empty()) c.descriptors.push_back(s);+ }}+ } else if (descVal.isString() && !descVal.str().empty()) {+ c.descriptors.push_back(descVal.str());+ } else if (item.has("RatingDescriptor") && item["RatingDescriptor"].isString()) {+ c.descriptors.push_back(item["RatingDescriptor"].str());}- } else if (descVal.isString() && !descVal.str().empty()) {- c.descriptors.push_back(descVal.str());- } else if (item.has("RatingDescriptor") && item["RatingDescriptor"].isString()) {- c.descriptors.push_back(item["RatingDescriptor"].str());- }- if (!c.rawId.empty()) candidates.push_back(std::move(c));+ if (!c.rawId.empty() || c.age >= 0) candidates.push_back(std::move(c));+ }}if (candidates.empty()) return;@@ -298,34 +349,44 @@ void parseContentRatings(const json::Value& p, const std::string& market,std::string sysLower;for (char ch : selected->system) sysLower += static_cast<char>(std::tolower(static_cast<unsigned char>(ch)));+ int ageNum = selected->age;+ if (ageNum < 0) {+ try {+ ageNum = std::stoi(raw);+ } catch (...) {}+ }+if (sysLower.find("classind") != std::string::npos || sysLower.find("djctq") != std::string::npos) {outSystem = "ClassInd";- if (rawLower.find("livre") != std::string::npos || rawLower == "l" || rawLower == "0" || rawLower == "general") outAge = "Livre";- else if (rawLower.find("10") != std::string::npos || rawLower == "ten") outAge = "10+";- else if (rawLower.find("12") != std::string::npos || rawLower == "twelve") outAge = "12+";- else if (rawLower.find("14") != std::string::npos || rawLower == "fourteen") outAge = "14+";- else if (rawLower.find("16") != std::string::npos || rawLower == "sixteen") outAge = "16+";- else if (rawLower.find("18") != std::string::npos || rawLower == "eighteen") outAge = "18+";+ if (rawLower.find("livre") != std::string::npos || rawLower == "l" || rawLower == "0" || rawLower == "general" || ageNum == 0 || ageNum == 1) outAge = "Livre";+ else if (ageNum == 10 || rawLower.find("10") != std::string::npos || rawLower == "ten") outAge = "10+";+ else if (ageNum == 12 || rawLower.find("12") != std::string::npos || rawLower == "twelve") outAge = "12+";+ else if (ageNum == 14 || rawLower.find("14") != std::string::npos || rawLower == "fourteen") outAge = "14+";+ else if (ageNum == 16 || rawLower.find("16") != std::string::npos || rawLower == "sixteen") outAge = "16+";+ else if (ageNum >= 18 || rawLower.find("18") != std::string::npos || rawLower == "eighteen") outAge = "18+";+ else if (ageNum > 0) outAge = std::to_string(ageNum) + "+";else outAge = raw;} else if (sysLower.find("esrb") != std::string::npos) {outSystem = "ESRB";- if (rawLower.find("everyone 10") != std::string::npos || rawLower == "e10" || rawLower == "e10+" || rawLower == "everyone10plus") outAge = "E10+";- else if (rawLower.find("everyone") != std::string::npos || rawLower == "e") outAge = "E";- else if (rawLower.find("teen") != std::string::npos || rawLower == "t") outAge = "T";- else if (rawLower.find("mature") != std::string::npos || rawLower == "m" || rawLower == "mature 17+") outAge = "M";+ if (ageNum == 10 || rawLower.find("everyone 10") != std::string::npos || rawLower == "e10" || rawLower == "e10+" || rawLower == "everyone10plus") outAge = "E10+";+ else if (ageNum >= 17 || rawLower.find("mature") != std::string::npos || rawLower == "m" || rawLower == "mature 17+") outAge = "M";+ else if (ageNum == 13 || rawLower.find("teen") != std::string::npos || rawLower == "t") outAge = "T";+ else if ((ageNum > 0 && ageNum <= 6) || rawLower.find("everyone") != std::string::npos || rawLower == "e") outAge = "E";else if (rawLower.find("adult") != std::string::npos || rawLower == "ao") outAge = "AO";else if (rawLower.find("pending") != std::string::npos || rawLower == "rp") outAge = "RP";+ else if (ageNum > 0) outAge = std::to_string(ageNum) + "+";else outAge = raw;} else if (sysLower.find("pegi") != std::string::npos) {outSystem = "PEGI";- if (rawLower.find("3") != std::string::npos) outAge = "3+";- else if (rawLower.find("7") != std::string::npos) outAge = "7+";- else if (rawLower.find("12") != std::string::npos) outAge = "12+";- else if (rawLower.find("16") != std::string::npos) outAge = "16+";- else if (rawLower.find("18") != std::string::npos) outAge = "18+";+ if (ageNum == 3 || rawLower.find("3") != std::string::npos) outAge = "3+";+ else if (ageNum == 7 || rawLower.find("7") != std::string::npos) outAge = "7+";+ else if (ageNum == 12 || rawLower.find("12") != std::string::npos) outAge = "12+";+ else if (ageNum == 16 || rawLower.find("16") != std::string::npos) outAge = "16+";+ else if (ageNum >= 18 || rawLower.find("18") != std::string::npos) outAge = "18+";+ else if (ageNum > 0) outAge = std::to_string(ageNum) + "+";else outAge = raw;} else {- outAge = raw;+ outAge = raw.empty() && ageNum > 0 ? std::to_string(ageNum) + "+" : raw;}}diff --git a/tests/test_main.cpp b/tests/test_main.cppindex 93e8a83..2877d7b 100644--- a/tests/test_main.cpp+++ b/tests/test_main.cpp@@ -3239,6 +3239,61 @@ static void testBlock3Features() {xcloud::parseContentRatings(*jMature, "BR", ageFb, sysFb, descFb);CHECK(sysFb == "ESRB");CHECK(ageFb == "M");++ // Microsoft Game Pass v3 catalog API singular "ContentRating" object (RemoteHighSapphire0)+ auto jV3Br = json::parse(R"({+ "ContentRating": {+ "LongName": "16 anos",+ "Description": "Para maiores de 16 anos",+ "Age": 16,+ "RatingSystem": "DJCTQ",+ "LocalizedDescriptors": ["Violência"],+ "LocalizedInteractiveElements": ["Usuários Interagem", "Compras no Jogo"]+ }+ })");+ CHECK(jV3Br.has_value());+ std::string ageV3Br, sysV3Br;+ std::vector<std::string> descV3Br;+ xcloud::parseContentRatings(*jV3Br, "BR", ageV3Br, sysV3Br, descV3Br);+ CHECK(sysV3Br == "ClassInd");+ CHECK(ageV3Br == "16+");+ CHECK(descV3Br.size() == 3);+ CHECK(descV3Br[0] == "Violência");+ CHECK(descV3Br[1] == "Usuários Interagem");++ // V3 Livre+ auto jV3Livre = json::parse(R"({+ "ContentRating": {+ "LongName": "Livre",+ "Description": "Para todas as idades",+ "Age": 1,+ "RatingSystem": "DJCTQ",+ "LocalizedDescriptors": []+ }+ })");+ CHECK(jV3Livre.has_value());+ std::string ageLivre, sysLivre;+ std::vector<std::string> descLivre;+ xcloud::parseContentRatings(*jV3Livre, "BR", ageLivre, sysLivre, descLivre);+ CHECK(sysLivre == "ClassInd");+ CHECK(ageLivre == "Livre");++ // V3 ESRB+ auto jV3Esrb = json::parse(R"({+ "ContentRating": {+ "LongName": "TEEN",+ "Age": 13,+ "RatingSystem": "ESRB",+ "LocalizedDescriptors": ["Blood", "Mild Violence"]+ }+ })");+ CHECK(jV3Esrb.has_value());+ std::string ageV3Us, sysV3Us;+ std::vector<std::string> descV3Us;+ xcloud::parseContentRatings(*jV3Esrb, "US", ageV3Us, sysV3Us, descV3Us);+ CHECK(sysV3Us == "ESRB");+ CHECK(ageV3Us == "T");+ CHECK(descV3Us.size() == 2 && descV3Us[0] == "Blood");}// 2. Local Web Micro-Server@@ -3489,6 +3544,156 @@ static void testBlock3Features() {}}+void testWebStreamingAndGamepad() {+ xc::app::WebServer srv;+ bool streamingFlag = false;+ std::string currentQuery = "";+ std::string currentTab = "gamepass";+ json::Value currentFilters = json::Value::object();++ xc::app::WebServerHooks hooks;+ hooks.isStreaming = [&]() { return streamingFlag; };+ hooks.getSearchParams = [&](std::string& q, std::string& tab, json::Value& f) {+ q = currentQuery;+ tab = currentTab;+ f = currentFilters;+ };+ hooks.setSearchParams = [&](const std::string* q, const std::string* tab, const json::Value* f) {+ if (q) currentQuery = *q;+ if (tab) currentTab = *tab;+ if (f) currentFilters = *f;+ };+ xc::app::setWebServerHooks(hooks);++ // 1. GET /api/status when not streaming+ {+ auto res = srv.handleRequest("GET", "/api/status", "");+ CHECK(res.status == 200);+ auto j = json::parse(res.body);+ CHECK(j && j->isObject());+ CHECK((*j)["ok"].asBool(false) == true);+ CHECK((*j)["streaming"].asBool(true) == false);+ }++ // 2. POST /api/search when not streaming should succeed+ {+ auto res = srv.handleRequest("POST", "/api/search", "{\"query\":\"halo\",\"tab\":\"gamepass\"}");+ CHECK(res.status == 200);+ auto j = json::parse(res.body);+ CHECK(j && (*j)["ok"].asBool(false) == true);+ CHECK(currentQuery == "halo");+ }++ // 3. GET /api/status when streaming is active+ streamingFlag = true;+ {+ auto res = srv.handleRequest("GET", "/api/status", "");+ CHECK(res.status == 200);+ auto j = json::parse(res.body);+ CHECK(j && (*j)["streaming"].asBool(false) == true);+ }++ // 4. POST /api/search when streaming must be blocked with 409 Conflict+ {+ auto res = srv.handleRequest("POST", "/api/search", "{\"query\":\"gears\",\"tab\":\"gamepass\"}");+ CHECK(res.status == 409);+ auto j = json::parse(res.body);+ CHECK(j && (*j)["ok"].asBool(true) == false);+ CHECK((*j)["error"].asString() == "streaming_active");+ CHECK(currentQuery == "halo"); // Search state was preserved and not changed+ }++ // 5. Virtual gamepad: Player 1 (main controller)+ {+ xc::app::resetVirtualGamepads();+ input::ControllerState s0;+ bool conn0 = false;+ xc::app::virtualGamepadState(0, s0, conn0);+ CHECK(!conn0);++ auto res = srv.handleRequest("POST", "/api/gamepad",+ "{\"player\":1,\"btnA\":true,\"leftStickX\":0.75,\"leftStickY\":-0.5,\"btnNexus\":true}");+ CHECK(res.status == 200);+ bool ok = xc::app::virtualGamepadState(0, s0, conn0);+ CHECK(ok);+ CHECK(conn0);+ CHECK(s0.btnA == true);+ CHECK(s0.btnB == false);+ CHECK(s0.btnNexus == true);+ CHECK(std::abs(s0.leftStickX - 0.75f) < 0.01f);+ CHECK(std::abs(s0.leftStickY - (-0.5f)) < 0.01f);+ }++ // 6. Virtual gamepad: Player 2 (co-op controller)+ {+ input::ControllerState s1;+ bool conn1 = false;+ xc::app::virtualGamepadState(1, s1, conn1);+ CHECK(!conn1);++ auto res = srv.handleRequest("POST", "/api/gamepad",+ "{\"player\":2,\"btnB\":true,\"triggerR2\":0.9,\"btnView\":true,\"dpadUp\":true}");+ CHECK(res.status == 200);+ bool ok = xc::app::virtualGamepadState(1, s1, conn1);+ CHECK(ok);+ CHECK(conn1);+ CHECK(s1.btnB == true);+ CHECK(s1.btnA == false);+ CHECK(s1.btnTouchpad == true); // btnView maps to btnTouchpad+ CHECK(s1.dpadUp == true);+ CHECK(std::abs(s1.triggerR2 - 0.9f) < 0.01f);+ // Test L3 and R3 buttons on Virtual Gamepad+ input::ControllerState s0;+ bool conn0 = false;+ auto resL3R3 = srv.handleRequest("POST", "/api/gamepad",+ "{\"player\":1,\"btnL3\":true,\"btnR3\":true}");+ CHECK(resL3R3.status == 200);+ bool okL3R3 = xc::app::virtualGamepadState(0, s0, conn0);+ CHECK(okL3R3);+ CHECK(s0.btnL3 == true);+ CHECK(s0.btnR3 == true);+ }++ // 7. Reset virtual gamepads+ {+ xc::app::resetVirtualGamepads();+ input::ControllerState s0, s1;+ bool conn0 = false, conn1 = false;+ xc::app::virtualGamepadState(0, s0, conn0);+ xc::app::virtualGamepadState(1, s1, conn1);+ CHECK(!conn0);+ CHECK(!conn1);+ }++ // 8. Test AppUi::detailWanted prevents infinite re-fetching when detailInfo_ exists+ {+ ui::Fonts dummyFonts{};+ ui::ImageCache images([] {});+ ui::AppUi uiApp(dummyFonts, images);+ ui::GameTile tile;+ tile.productId = "PROD_UNRATED";+ tile.name = "Unrated Game";+ tile.description = "Short desc";+ tile.heroUrl = "http://example.com/hero.jpg";+ tile.ratingAge = ""; // Empty age rating++ uiApp.showDetails(tile);+ // First wanted call should ask for details+ std::string asked = uiApp.detailWanted(1000);+ CHECK(asked == "PROD_UNRATED");++ // Simulate priceLoop fetching details and storing in detailInfo_+ uiApp.setDetailInfo("PROD_UNRATED", "Longer desc", "Publisher X", {"Indie"}, "http://example.com/hero.jpg",+ "", "", {});++ // Subsequent detailWanted calls (even after 5000ms) must NOT ask again+ std::string askedAfter = uiApp.detailWanted(10000);+ CHECK(askedAfter.empty());+ }++ xc::app::setWebServerHooks({});+}+int main() {testBlock3Features();testWishlist();@@ -3556,6 +3761,7 @@ int main() {testBlock1Features();testVideoDecoder();testDrawNv12();+ testWebStreamingAndGamepad();if (g_failures) {std::fprintf(stderr, "%d failure(s)\n", g_failures);return 1;