diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f448a83..e5fa8193 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ Release notes on GitHub are taken from the matching section here. - Blocking and unblocking players works when Nightcap has no saved `RBXEventTrackerV2` cookie. Roblox refused those requests with "BrowserTrackerID is missing or invalid"; Nightcap now sends its browser tracker. +- Games that size their UI by screen size, such as Racket Rivals, no longer show a tiny phone layout. Nightcap + reported a 9-inch screen; it now reports the monitor's size at 96 dpi. - On FreeBSD, Roblox downloads no longer fail with "error adding trust anchors" in a Fedora userspace. - On FreeBSD, sound plays through `/dev/dsp` without an `asound.conf`, once `alsa-plugins-oss` is installed in the Linux userspace. An existing `~/.asoundrc` or `/etc/asound.conf` is still used. diff --git a/include/runtime/display_size.h b/include/runtime/display_size.h index 613e8708..ffae9c75 100644 --- a/include/runtime/display_size.h +++ b/include/runtime/display_size.h @@ -2,6 +2,7 @@ #define MOCKTAIL_RUNTIME_DISPLAY_SIZE_H_ #include +#include #include namespace mocktail { @@ -60,11 +61,19 @@ inline DisplaySize ParseDisplaySize(const char* value) { static_cast(parts[1])}; } -// Physical length of a pixel span at the guest's fixed 160 dpi, rounded down -// to whole millimetres. -inline std::int32_t PixelsToMillimetersAt160Dpi(std::int32_t pixels) { +// Physical length of a pixel span at a desktop monitor's 96 dpi, rounded down +// to whole millimetres. Games size their UI from this, so it must read as a +// desktop screen, not a phone. +inline std::int32_t PixelsToMillimetersAtDesktopDpi(std::int32_t pixels) { return static_cast(static_cast(pixels) * 254 / - 1600); + 960); +} + +inline DisplaySize HostDisplayMillimeters() { + const DisplaySize pixels = + ParseDisplaySize(std::getenv(kDisplaySizeEnvironment)); + return {PixelsToMillimetersAtDesktopDpi(pixels.width), + PixelsToMillimetersAtDesktopDpi(pixels.height)}; } } // namespace runtime diff --git a/include/runtime/roblox_game_session_native_adapter.h b/include/runtime/roblox_game_session_native_adapter.h index 763d56de..bb621efc 100644 --- a/include/runtime/roblox_game_session_native_adapter.h +++ b/include/runtime/roblox_game_session_native_adapter.h @@ -12,6 +12,7 @@ #include "mocktail/status.h" #include "runtime/game_session_coordinator.h" #include "runtime/roblox_app_lifecycle.h" +#include "runtime/display_size.h" #include "runtime/roblox_capability_resolver.h" namespace mocktail { @@ -108,15 +109,23 @@ struct RobloxGameSessionJniObjects { struct RobloxGameSurfaceJniConfig { std::string asset_folder_path = "rbx_bin/assets"; float dpi_scale = 1.0f; - int32_t viewport_width_mm = 203; - int32_t viewport_height_mm = 114; + // 0 means the host display's size at desktop dpi. + int32_t viewport_width_mm = 0; + int32_t viewport_height_mm = 0; bool is_touch_device = false; bool is_mouse_device = true; bool is_keyboard_device = true; bool complete() const { return !asset_folder_path.empty() && dpi_scale > 0.0f && - viewport_width_mm > 0 && viewport_height_mm > 0; + viewport_width_mm >= 0 && viewport_height_mm >= 0; + } + + DisplaySize ViewportMillimeters() const { + if (viewport_width_mm > 0 && viewport_height_mm > 0) { + return {viewport_width_mm, viewport_height_mm}; + } + return HostDisplayMillimeters(); } }; diff --git a/src/legacy/legacy_runtime.cc b/src/legacy/legacy_runtime.cc index 210496cf..9f909c46 100644 --- a/src/legacy/legacy_runtime.cc +++ b/src/legacy/legacy_runtime.cc @@ -2870,11 +2870,11 @@ jobject BuildPlatformParams(JNIEnv* env, jobject surface, bool is_headless) { SetIntField(env, params, "screenHeight", platform_display.height); SetIntField(env, params, "densityDpi", 160); SetIntField(env, params, "viewportWidthMm", - mocktail::runtime::PixelsToMillimetersAt160Dpi( - platform_window.width)); + mocktail::runtime::PixelsToMillimetersAtDesktopDpi( + platform_display.width)); SetIntField(env, params, "viewportHeightMm", - mocktail::runtime::PixelsToMillimetersAt160Dpi( - platform_window.height)); + mocktail::runtime::PixelsToMillimetersAtDesktopDpi( + platform_display.height)); const mocktail::window::WindowViewportSnapshot viewport = mocktail::window::GetWindowViewportSnapshot(); SetFloatField(env, params, "dpiScale", viewport.dpi_scale); diff --git a/src/runtime/roblox_experience_composition.cc b/src/runtime/roblox_experience_composition.cc index 8d880f88..d44eacaf 100644 --- a/src/runtime/roblox_experience_composition.cc +++ b/src/runtime/roblox_experience_composition.cc @@ -2008,9 +2008,9 @@ Status RobloxExperienceComposition::BuildLaunchObjects( ? surface.dpi_scale : surface_config_.dpi_scale) && SetField(env, params_local, params_class, "viewportWidthMm", "I", - surface_config_.viewport_width_mm) && + surface_config_.ViewportMillimeters().width) && SetField(env, params_local, params_class, "viewportHeightMm", "I", - surface_config_.viewport_height_mm) && + surface_config_.ViewportMillimeters().height) && SetField( env, params_local, params_class, "isTouchDevice", "Z", surface_config_.is_touch_device ? JNI_TRUE : JNI_FALSE) && diff --git a/src/runtime/roblox_game_session_native_adapter.cc b/src/runtime/roblox_game_session_native_adapter.cc index a659f1da..5e367c84 100644 --- a/src/runtime/roblox_game_session_native_adapter.cc +++ b/src/runtime/roblox_game_session_native_adapter.cc @@ -714,6 +714,7 @@ Status RobloxGameSessionNativeAdapter::CreatePlatformParamsLocked( env->GetFieldID(params_class, "assetFolderPath", "Ljava/lang/String;"); jstring asset_path = env->NewStringUTF(surface_config_.asset_folder_path.c_str()); + const DisplaySize viewport_mm = surface_config_.ViewportMillimeters(); const bool populated = dpi_scale != nullptr && asset_folder != nullptr && asset_path != nullptr && @@ -723,8 +724,8 @@ Status RobloxGameSessionNativeAdapter::CreatePlatformParamsLocked( surface_config_.is_mouse_device ? JNI_TRUE : JNI_FALSE) && set_boolean("isKeyboardDevice", surface_config_.is_keyboard_device ? JNI_TRUE : JNI_FALSE) && - set_int("viewportWidthMm", surface_config_.viewport_width_mm) && - set_int("viewportHeightMm", surface_config_.viewport_height_mm); + set_int("viewportWidthMm", viewport_mm.width) && + set_int("viewportHeightMm", viewport_mm.height); if (populated) { env->SetFloatField(object, dpi_scale, surface.dpi_scale > 0.0f ? surface.dpi_scale diff --git a/tests/display_size_test.cc b/tests/display_size_test.cc index fc829948..3abe6e73 100644 --- a/tests/display_size_test.cc +++ b/tests/display_size_test.cc @@ -32,11 +32,12 @@ TEST(DisplaySizeTest, FallsBackWhenAValueDoesNotFitAJavaInt) { ExpectSize(ParseDisplaySize("99999999999999999999x1440"), 1920, 1080); } -TEST(DisplaySizeTest, ConvertsPixelsToMillimetersAt160Dpi) { - EXPECT_EQ(PixelsToMillimetersAt160Dpi(1280), 203); - EXPECT_EQ(PixelsToMillimetersAt160Dpi(720), 114); - EXPECT_EQ(PixelsToMillimetersAt160Dpi(3440), 546); - EXPECT_EQ(PixelsToMillimetersAt160Dpi(0), 0); +TEST(DisplaySizeTest, ConvertsPixelsToMillimetersAtDesktopDpi) { + EXPECT_EQ(PixelsToMillimetersAtDesktopDpi(1920), 508); + EXPECT_EQ(PixelsToMillimetersAtDesktopDpi(1080), 285); + EXPECT_EQ(PixelsToMillimetersAtDesktopDpi(3440), 910); + EXPECT_EQ(PixelsToMillimetersAtDesktopDpi(1366), 361); + EXPECT_EQ(PixelsToMillimetersAtDesktopDpi(0), 0); } } // namespace diff --git a/tests/roblox_game_session_native_adapter_test.cc b/tests/roblox_game_session_native_adapter_test.cc index 1208a53f..95429a6c 100644 --- a/tests/roblox_game_session_native_adapter_test.cc +++ b/tests/roblox_game_session_native_adapter_test.cc @@ -461,6 +461,33 @@ TEST_F(RobloxGameSessionNativeAdapterTest, EXPECT_EQ(runtime.Snapshot().active_surface_height, 1080U); } +TEST_F(RobloxGameSessionNativeAdapterTest, + PlatformParamsReportTheHostDisplayAsADesktopScreen) { + ASSERT_EQ(setenv("MOCKTAIL_DISPLAY_SIZE_INTERNAL", "3440x1440", 1), 0); + RobloxGameSessionRuntime runtime(Environment(), Symbols(), + RobloxGameSurfaceJniConfig{}); + ASSERT_TRUE(runtime + .InitializeAndStart(Binding(), AuthenticatedPrincipal(), + NetworkRequest(), Surface()) + .ok()); + const GameSessionUpdateResult update = + runtime.SurfaceChanged(Surface(33, 0x44, 1920, 1080)); + unsetenv("MOCKTAIL_DISPLAY_SIZE_INTERNAL"); + + ASSERT_TRUE(update.ok()) << update.cause.message(); + ASSERT_EQ(probe_.update_platform_params.size(), 1U); + JNIEnv* env = vm_->GetJNIEnv(); + jobject params = probe_.update_platform_params[0]; + jclass params_class = env->GetObjectClass(params); + EXPECT_EQ(env->GetIntField( + params, env->GetFieldID(params_class, "viewportWidthMm", "I")), + 910); + EXPECT_EQ(env->GetIntField(params, + env->GetFieldID(params_class, "viewportHeightMm", + "I")), + 381); +} + TEST_F(RobloxGameSessionNativeAdapterTest, SurfaceDpiScaleOverridesStartupFallbackDuringRebind) { RobloxGameSurfaceJniConfig surface_config;