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

avm2: Work on flash.system.Capabilities #10945

Merged
merged 1 commit into from
May 19, 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
6 changes: 5 additions & 1 deletion core/src/avm2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ const BROADCAST_WHITELIST: [&str; 4] = ["enterFrame", "exitFrame", "frameConstru
#[derive(Collect)]
#[collect(no_drop)]
pub struct Avm2<'gc> {
/// The Flash Player version we're emulating.
player_version: u8,

/// Values currently present on the operand stack.
stack: Vec<Value<'gc>>,

Expand Down Expand Up @@ -142,10 +145,11 @@ pub struct Avm2<'gc> {

impl<'gc> Avm2<'gc> {
/// Construct a new AVM interpreter.
pub fn new(context: &mut GcContext<'_, 'gc>) -> Self {
pub fn new(context: &mut GcContext<'_, 'gc>, player_version: u8) -> Self {
let globals = Domain::global_domain(context.gc_context);

Self {
player_version,
stack: Vec::new(),
scope_stack: Vec::new(),
call_stack: GcCell::allocate(context.gc_context, CallStack::new()),
Expand Down
1 change: 1 addition & 0 deletions core/src/avm2/globals/flash/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
#![allow(clippy::module_inception)]

pub mod application_domain;
pub mod capabilities;
pub mod security;
pub mod system;
15 changes: 9 additions & 6 deletions core/src/avm2/globals/flash/system/Capabilities.as
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
package flash.system {
import __ruffle__.stub_getter;
public final class Capabilities {
public static function get os(): String {
stub_getter("flash.system.Capabilities", "os");
return "Linux 5.10.49"
}
public static function get playerType(): String {
return "StandAlone"
}
public static function get version(): String {
return "LNX 32,0,0,465"
}

public native static function get playerType(): String;

public native static function get version(): String;

public static function get manufacturer(): String {
stub_getter("flash.system.Capabilities", "manufacturer");
return "Adobe Linux"
}
public static function get language(): String {
stub_getter("flash.system.Capabilities", "language");
return "en"
}
public static function get isDebugger(): Boolean {
Expand Down
33 changes: 33 additions & 0 deletions core/src/avm2/globals/flash/system/capabilities.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//! `flash.display.Capabilities` native methods

use crate::avm2::{Activation, AvmString, Error, Object, Value};

/// Implements `flash.system.Capabilities.version`
pub fn get_version<'gc>(
activation: &mut Activation<'_, 'gc>,
_this: Option<Object<'gc>>,
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> {
// TODO: Report the correct OS instead of always reporting Linux
Lord-McSweeney marked this conversation as resolved.
Show resolved Hide resolved
Ok(AvmString::new_utf8(
activation.context.gc_context,
format!("LNX {},0,0,0", activation.avm2().player_version),
)
.into())
}

/// Implements `flash.system.Capabilities.playerType`
pub fn get_player_type<'gc>(
activation: &mut Activation<'_, 'gc>,
_this: Option<Object<'gc>>,
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> {
// TODO: When should "External" be returned?
let player_type = if cfg!(target_family = "wasm") {
"PlugIn"
} else {
"StandAlone"
};
Lord-McSweeney marked this conversation as resolved.
Show resolved Hide resolved

Ok(AvmString::new_utf8(activation.context.gc_context, player_type).into())
}
2 changes: 1 addition & 1 deletion core/src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2217,7 +2217,7 @@ impl PlayerBuilder {
audio_manager: AudioManager::new(),
action_queue: ActionQueue::new(),
avm1: Avm1::new(&mut init, player_version),
avm2: Avm2::new(&mut init),
avm2: Avm2::new(&mut init, player_version),
interner,
current_context_menu: None,
drag_object: None,
Expand Down