Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web/Desktop: Allow specifying the player version #8961

Merged
merged 3 commits into from
Jan 10, 2023
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
16 changes: 13 additions & 3 deletions core/src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1917,6 +1917,7 @@ pub struct PlayerBuilder {
warn_on_unsupported_content: bool,
load_behavior: LoadBehavior,
spoofed_url: Option<String>,
player_version: Option<u8>,
}

impl PlayerBuilder {
Expand Down Expand Up @@ -1952,6 +1953,7 @@ impl PlayerBuilder {
warn_on_unsupported_content: true,
load_behavior: LoadBehavior::Streaming,
spoofed_url: None,
player_version: None,
}
}

Expand Down Expand Up @@ -2071,6 +2073,12 @@ impl PlayerBuilder {
self
}

// Configures the target player version.
pub fn with_player_version(mut self, version: Option<u8>) -> Self {
self.player_version = version;
self
}

/// Builds the player, wiring up the backends and configuring the specified settings.
pub fn build(self) -> Arc<Mutex<Player>> {
use crate::backend::*;
Expand Down Expand Up @@ -2101,8 +2109,10 @@ impl PlayerBuilder {
.video
.unwrap_or_else(|| Box::new(null::NullVideoBackend::new()));

let player_version = self.player_version.unwrap_or(NEWEST_PLAYER_VERSION);

// Instantiate the player.
let fake_movie = Arc::new(SwfMovie::empty(NEWEST_PLAYER_VERSION));
let fake_movie = Arc::new(SwfMovie::empty(player_version));
let frame_rate = 12.0;
let player = Arc::new_cyclic(|self_ref| {
Mutex::new(Player {
Expand Down Expand Up @@ -2141,7 +2151,7 @@ impl PlayerBuilder {
system: SystemProperties::default(),
transform_stack: TransformStack::new(),
instance_counter: 0,
player_version: NEWEST_PLAYER_VERSION,
player_version,
is_playing: self.autoplay,
needs_render: true,
warn_on_unsupported_content: self.warn_on_unsupported_content,
Expand All @@ -2159,7 +2169,7 @@ impl PlayerBuilder {
GcRootData {
audio_manager: AudioManager::new(),
action_queue: ActionQueue::new(),
avm1: Avm1::new(gc_context, NEWEST_PLAYER_VERSION),
avm1: Avm1::new(gc_context, player_version),
avm2: Avm2::new(gc_context),
current_context_menu: None,
drag_object: None,
Expand Down
7 changes: 6 additions & 1 deletion desktop/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ struct Opt {
/// Spoofs the root SWF URL provided to ActionScript.
#[clap(long, value_parser)]
spoof_url: Option<Url>,

/// The version of the player to emulate
#[clap(long, short)]
player_version: Option<u8>,
}

#[cfg(feature = "render_trace")]
Expand Down Expand Up @@ -281,7 +285,8 @@ impl App {
.with_warn_on_unsupported_content(!opt.dont_warn_on_unsupported_content)
.with_fullscreen(opt.fullscreen)
.with_load_behavior(opt.load_behavior)
.with_spoofed_url(opt.spoof_url.clone().map(|url| url.to_string()));
.with_spoofed_url(opt.spoof_url.clone().map(|url| url.to_string()))
.with_player_version(opt.player_version);

let player = builder.build();

Expand Down
1 change: 1 addition & 0 deletions web/packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ export const DEFAULT_CONFIG: Required<Config> = {
wmode: WindowMode.Opaque,
publicPath: null,
polyfills: true,
playerVerion: null,
};
10 changes: 10 additions & 0 deletions web/packages/core/src/load-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,16 @@ export interface BaseLoadOptions {
* @default WindowMode.Window
*/
wmode?: WindowMode;

/**
* The emulated version of the player
*
* This controls the version that is reported to the movie
* null means latest version
*
* @default null
*/
playerVerion?: number | null;
}

/**
Expand Down
4 changes: 4 additions & 0 deletions web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ struct Config {

#[serde(rename = "maxExecutionDuration")]
max_execution_duration: Duration,

#[serde(rename = "playerVersion")]
plaver_version: Option<u8>,
}

/// Metadata about the playing SWF file to be passed back to JavaScript.
Expand Down Expand Up @@ -518,6 +521,7 @@ impl Ruffle {
.with_letterbox(config.letterbox)
.with_max_execution_duration(config.max_execution_duration)
.with_warn_on_unsupported_content(config.warn_on_unsupported_content)
.with_player_version(config.plaver_version)
.build();

let mut callstack = None;
Expand Down