Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 13 additions & 4 deletions include/runtime/display_size.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define MOCKTAIL_RUNTIME_DISPLAY_SIZE_H_

#include <cstdint>
#include <cstdlib>
#include <limits>

namespace mocktail {
Expand Down Expand Up @@ -60,11 +61,19 @@ inline DisplaySize ParseDisplaySize(const char* value) {
static_cast<std::int32_t>(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<std::int32_t>(static_cast<std::int64_t>(pixels) * 254 /
1600);
960);
}

inline DisplaySize HostDisplayMillimeters() {
const DisplaySize pixels =
ParseDisplaySize(std::getenv(kDisplaySizeEnvironment));
return {PixelsToMillimetersAtDesktopDpi(pixels.width),
PixelsToMillimetersAtDesktopDpi(pixels.height)};
}

} // namespace runtime
Expand Down
15 changes: 12 additions & 3 deletions include/runtime/roblox_game_session_native_adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
}
};

Expand Down
8 changes: 4 additions & 4 deletions src/legacy/legacy_runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/roblox_experience_composition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2008,9 +2008,9 @@ Status RobloxExperienceComposition::BuildLaunchObjects(
? surface.dpi_scale
: surface_config_.dpi_scale) &&
SetField<jint>(env, params_local, params_class, "viewportWidthMm", "I",
surface_config_.viewport_width_mm) &&
surface_config_.ViewportMillimeters().width) &&
SetField<jint>(env, params_local, params_class, "viewportHeightMm", "I",
surface_config_.viewport_height_mm) &&
surface_config_.ViewportMillimeters().height) &&
SetField<jboolean>(
env, params_local, params_class, "isTouchDevice", "Z",
surface_config_.is_touch_device ? JNI_TRUE : JNI_FALSE) &&
Expand Down
5 changes: 3 additions & 2 deletions src/runtime/roblox_game_session_native_adapter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand All @@ -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
Expand Down
11 changes: 6 additions & 5 deletions tests/display_size_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions tests/roblox_game_session_native_adapter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down