Skip to content
Open
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
17 changes: 4 additions & 13 deletions core/src/avm2/globals/flash/system/capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,12 @@ pub fn get_version<'gc>(
_this: Value<'gc>,
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> {
let os = match activation.avm2().player_runtime {
PlayerRuntime::FlashPlayer => "WIN",
PlayerRuntime::AIR => {
if cfg!(windows) {
"WIN"
} else if cfg!(target_vendor = "apple") {
"MAC"
} else {
"LNX"
}
}
};
Ok(AvmString::new_utf8(
activation.gc(),
format!("{os} {},0,0,0", activation.avm2().player_version),
activation
.context
.system
.get_version_string(activation.context.player_version),
)
.into())
}
Expand Down
15 changes: 14 additions & 1 deletion core/src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2560,6 +2560,7 @@
avm2_optimizer_enabled: bool,
#[cfg(feature = "default_font")]
default_font: bool,
custom_version_string: Option<String>,
}

impl PlayerBuilder {
Expand Down Expand Up @@ -2616,6 +2617,7 @@
avm2_optimizer_enabled: true,
#[cfg(feature = "default_font")]
default_font: true,
custom_version_string: None,
}
}

Expand Down Expand Up @@ -2843,6 +2845,13 @@
self
}

/// Override the version string reported by `Capabilities.version`/`$version`, to this custom one.
/// SWFs normally expect a string in the format of "1,2,3,4", and by default Ruffle reports `(player_version),0,0,0` (e.g. `32,0,0,0`)
pub fn with_custom_version_string(mut self, value: Option<String>) -> Self {
self.custom_version_string = value;
self
}

Check warning on line 2853 in core/src/player.rs

View workflow job for this annotation

GitHub Actions / Coverage Report

Coverage

Uncovered lines (2850–2853)

fn create_gc_root<'gc>(
gc_context: &'gc Mutation<'gc>,
player_version: u8,
Expand Down Expand Up @@ -2979,7 +2988,11 @@
// TODO: AVM1 and AVM2 use separate RNGs (though algorithm is same), so this is technically incorrect.
// See: https://github.com/ruffle-rs/ruffle/issues/20244
rng: AvmRng::default(),
system: SystemProperties::new(language),
system: SystemProperties::new(
self.player_runtime,
language,
self.custom_version_string,
),
page_url: self.page_url.clone(),
transform_stack: TransformStack::new(),
instance_counter: 0,
Expand Down
45 changes: 37 additions & 8 deletions core/src/system_properties.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::context::UpdateContext;
use crate::PlayerRuntime;
use bitflags::bitflags;
use core::fmt;
use fluent_templates::{langid, LanguageIdentifier};
Expand Down Expand Up @@ -266,10 +267,29 @@
pub cpu_architecture: CpuArchitecture,
/// The highest supported h264 decoder level
pub idc_level: String,
/// A custom version string to report, instead of player version
pub custom_version_string: Option<String>,
}

impl SystemProperties {
pub fn new(language: LanguageIdentifier) -> Self {
pub fn new(
player_runtime: PlayerRuntime,
language: LanguageIdentifier,
custom_version_string: Option<String>,
) -> Self {
let (manufacturer, os) = match player_runtime {
PlayerRuntime::FlashPlayer => (Manufacturer::Windows, OperatingSystem::WindowsUnknown),
PlayerRuntime::AIR => {
if cfg!(windows) {
(Manufacturer::Windows, OperatingSystem::WindowsUnknown)

Check warning on line 284 in core/src/system_properties.rs

View workflow job for this annotation

GitHub Actions / Coverage Report

Coverage

Uncovered line (284)
} else if cfg!(target_vendor = "apple") {
(Manufacturer::Macintosh, OperatingSystem::MacOs)

Check warning on line 286 in core/src/system_properties.rs

View workflow job for this annotation

GitHub Actions / Coverage Report

Coverage

Uncovered line (286)
} else {
(Manufacturer::Linux, OperatingSystem::Linux)
}
}
};

SystemProperties {
//TODO: default to true on fp>=7, false <= 6
exact_settings: true,
Expand All @@ -284,19 +304,28 @@
pixel_aspect_ratio: 1_f32,
// source: https://tracker.adobe.com/#/view/FP-3949775
dpi: 72_f32,
manufacturer: Manufacturer::Linux,
os: OperatingSystem::Linux,
manufacturer,
os,
cpu_architecture: CpuArchitecture::X86,
idc_level: "5.1".into(),
custom_version_string,
}
}

pub fn get_version_string(&self, player_version: u8) -> String {
format!(
"{} {},0,0,0",
self.manufacturer.get_platform_name(),
player_version
)
if let Some(custom_version_string) = &self.custom_version_string {
format!(
"{} {}",
self.manufacturer.get_platform_name(),

Check warning on line 319 in core/src/system_properties.rs

View workflow job for this annotation

GitHub Actions / Coverage Report

Coverage

Uncovered lines (317–319)
custom_version_string
)
} else {
format!(
"{} {},0,0,0",
self.manufacturer.get_platform_name(),
player_version
)
}
}

pub fn has_capability(&self, cap: SystemCapabilities) -> bool {
Expand Down
2 changes: 2 additions & 0 deletions desktop/assets/texts/en-US/settings.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ scale-mode-force-tooltip =

player-version = Player Version

custom-player-version-string = Custom Player Version

player-runtime = Player Runtime
player-runtime-flash = Flash Player
player-runtime-air = Adobe AIR
Expand Down
5 changes: 5 additions & 0 deletions desktop/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ pub struct Opt {
#[clap(long)]
pub player_version: Option<u8>,

/// Override the version string reported by `Capabilities.version`/`$version`, to this custom one.
/// SWFs normally expect a string in the format of "1,2,3,4", and by default Ruffle reports `(player_version),0,0,0` (e.g. `32,0,0,0`)
#[clap(long)]
pub custom_player_version: Option<String>,

/// The runtime to emulate (Flash Player or Adobe AIR)
#[clap(long)]
pub player_runtime: Option<PlayerRuntime>,
Expand Down
48 changes: 48 additions & 0 deletions desktop/src/gui/dialogs/open_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub struct OpenDialog {
load_behavior: OptionalField<EnumDropdownField<LoadBehavior>>,
letterbox: OptionalField<EnumDropdownField<Letterbox>>,
player_version: OptionalField<NumberField<u8>>,
custom_player_version_string: OptionalField<SingleLineTextField>,
player_runtime: OptionalField<EnumDropdownField<PlayerRuntime>>,
dummy_external_interface: OptionalField<BooleanDropdownField>,
upgrade_to_https: OptionalField<BooleanDropdownField>,
Expand Down Expand Up @@ -229,6 +230,10 @@ impl OpenDialog {
defaults.player.player_version,
NumberField::new(1..=NEWEST_PLAYER_VERSION, DEFAULT_PLAYER_VERSION),
);
let custom_player_version_string = OptionalField::new(
defaults.player.custom_player_version_string.clone(),
SingleLineTextField::new("32,0,0,0"),
);
let player_runtime = OptionalField::new(
defaults.player.player_runtime,
EnumDropdownField::new(
Expand Down Expand Up @@ -280,6 +285,7 @@ impl OpenDialog {
load_behavior,
letterbox,
player_version,
custom_player_version_string,
player_runtime,
dummy_external_interface,
upgrade_to_https,
Expand Down Expand Up @@ -499,6 +505,14 @@ impl OpenDialog {
.ui(ui, &mut self.options.player.player_version, locale);
ui.end_row();

ui.label(text(locale, "custom-player-version-string"));
self.custom_player_version_string.ui(
ui,
&mut self.options.player.custom_player_version_string,
locale,
);
ui.end_row();

ui.label(text(locale, "player-runtime"));
self.player_runtime
.ui(ui, &mut self.options.player.player_runtime, locale);
Expand Down Expand Up @@ -614,6 +628,40 @@ impl InnerField for UrlField {
}
}

struct SingleLineTextField {
hint: &'static str,
}

impl SingleLineTextField {
pub fn new(hint: &'static str) -> Self {
Self { hint }
}
}

impl InnerField for SingleLineTextField {
type Value = String;
type Result = String;

fn value_if_missing(&self) -> Self::Value {
String::new()
}

fn ui(&self, ui: &mut Ui, value: &mut Self::Value, error: bool, _locale: &LanguageIdentifier) {
TextEdit::singleline(value)
.hint_text(self.hint)
.text_color_opt(if error {
Some(ui.style().visuals.error_fg_color)
} else {
None
})
.ui(ui);
}

fn value_to_result(&self, value: &Self::Value) -> Result<Self::Result, ()> {
Ok(value.to_string())
}
}

struct CookieField {
hint: &'static str,
}
Expand Down
1 change: 1 addition & 0 deletions desktop/src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ impl From<&GlobalPreferences> for LaunchOptions {
referer: value.cli.referer.clone(),
cookie: value.cli.cookie.clone(),
player_version: value.cli.player_version,
custom_player_version_string: value.cli.custom_player_version.clone(),
player_runtime: value.cli.player_runtime,
frame_rate: value.cli.frame_rate,
dummy_external_interface: if value.cli.dummy_external_interface {
Expand Down
Loading
Loading