From a10b31b118c95fbf97fcde7869982b81baec3fd0 Mon Sep 17 00:00:00 2001 From: Tom Schuster Date: Tue, 20 Aug 2024 14:19:47 +0200 Subject: [PATCH] avm2: For AIR report the correct OS in flash.system.Capabilities --- .../avm2/globals/flash/system/Capabilities.as | 13 +----- .../avm2/globals/flash/system/capabilities.rs | 40 +++++++++++++++++-- 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/core/src/avm2/globals/flash/system/Capabilities.as b/core/src/avm2/globals/flash/system/Capabilities.as index 5013652ce..96fe83290 100644 --- a/core/src/avm2/globals/flash/system/Capabilities.as +++ b/core/src/avm2/globals/flash/system/Capabilities.as @@ -1,23 +1,13 @@ package flash.system { import __ruffle__.stub_getter; public final class Capabilities { - public static function get os(): String { - stub_getter("flash.system.Capabilities", "os"); - return "Windows 8" - } - + public native static function get os(): String; public native static function get playerType(): String; - public native static function get version(): String; - public native static function get screenResolutionX():Number; - public native static function get screenResolutionY():Number; - public native static function get pixelAspectRatio():Number; - public native static function get screenDPI():Number; - public static function get manufacturer(): String { stub_getter("flash.system.Capabilities", "manufacturer"); return "Adobe Windows" @@ -29,6 +19,5 @@ package flash.system { public static function get isDebugger(): Boolean { return false } - } } diff --git a/core/src/avm2/globals/flash/system/capabilities.rs b/core/src/avm2/globals/flash/system/capabilities.rs index 555febfcd..4cd926b1e 100644 --- a/core/src/avm2/globals/flash/system/capabilities.rs +++ b/core/src/avm2/globals/flash/system/capabilities.rs @@ -3,16 +3,50 @@ use crate::avm2::{Activation, AvmString, Error, Object, Value}; use crate::player::PlayerRuntime; +/// Implements `flash.system.Capabilities.os` +pub fn get_os<'gc>( + activation: &mut Activation<'_, 'gc>, + _this: Object<'gc>, + _args: &[Value<'gc>], +) -> Result, Error<'gc>> { + let os = match activation.avm2().player_runtime { + // For most normal Flash Player usage, the OS should not matter, + // so let's pretend it's Windows for the broadest possible compatibility. + PlayerRuntime::FlashPlayer => "Windows 8", + PlayerRuntime::AIR => { + if cfg!(windows) { + "Windows 10" + } else if cfg!(target_os = "macos") { + "Mac OS 10.5.2" + } else { + "Linux 5.10.49" + } + } + }; + Ok(AvmString::new_utf8(activation.gc(), os).into()) +} + /// Implements `flash.system.Capabilities.version` pub fn get_version<'gc>( activation: &mut Activation<'_, 'gc>, _this: Object<'gc>, _args: &[Value<'gc>], ) -> Result, Error<'gc>> { - // TODO: Report the correct OS instead of always reporting Windows + let os = match activation.avm2().player_runtime { + PlayerRuntime::FlashPlayer => "WIN", + PlayerRuntime::AIR => { + if cfg!(windows) { + "WIN" + } else if cfg!(target_os = "macos") { + "MAC" + } else { + "LNX" + } + } + }; Ok(AvmString::new_utf8( - activation.context.gc_context, - format!("WIN {},0,0,0", activation.avm2().player_version), + activation.gc(), + format!("{os} {},0,0,0", activation.avm2().player_version), ) .into()) }