core: Allow NetStream script data to call any functions

This commit is contained in:
Lord-McSweeney 2023-07-19 00:26:06 -07:00 committed by kmeisthax
parent dd0d4f7eea
commit 7c33932f53
1 changed files with 30 additions and 54 deletions

View File

@ -24,7 +24,6 @@ use gc_arena::{Collect, GcCell, MutationContext};
use ruffle_render::bitmap::BitmapInfo; use ruffle_render::bitmap::BitmapInfo;
use ruffle_video::frame::EncodedFrame; use ruffle_video::frame::EncodedFrame;
use ruffle_video::VideoStreamHandle; use ruffle_video::VideoStreamHandle;
use ruffle_wstr::WStr;
use std::cmp::max; use std::cmp::max;
use std::io::Seek; use std::io::Seek;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
@ -713,66 +712,43 @@ impl<'gc> NetStream<'gc> {
) -> Result<(), Avm2Error<'gc>> { ) -> Result<(), Avm2Error<'gc>> {
match avm_object { match avm_object {
Some(AvmObject::Avm1(object)) => { Some(AvmObject::Avm1(object)) => {
match variable_name { let avm_string_name = AvmString::new_utf8_bytes(context.gc_context, variable_name);
b"onCuePoint" | b"onMetaData" => {
let avm_string_name =
AvmString::new_utf8_bytes(context.gc_context, variable_name);
let root = context.stage.root_clip().expect("root"); let root = context.stage.root_clip().expect("root");
let mut activation = Avm1Activation::from_nothing( let mut activation = Avm1Activation::from_nothing(
context.reborrow(), context.reborrow(),
Avm1ActivationIdentifier::root(format!("[FLV {}]", avm_string_name)), Avm1ActivationIdentifier::root(format!("[FLV {}]", avm_string_name)),
root, root,
); );
let avm1_object_value = variable_data.to_avm1_value(&mut activation); let avm1_object_value = variable_data.to_avm1_value(&mut activation);
if let Err(e) = object.call_method( if let Err(e) = object.call_method(
avm_string_name, avm_string_name,
&[avm1_object_value], &[avm1_object_value],
&mut activation, &mut activation,
Avm1ExecutionReason::Special, Avm1ExecutionReason::Special,
) { ) {
tracing::error!( tracing::error!(
"Got error when dispatching AVM1 onCuePoint event from NetStream: {}", "Got error when dispatching AVM1 {} script data handler from NetStream: {}",
e avm_string_name,
); e,
} );
} }
b"onXMPData" => {
tracing::warn!("Stub: FLV stream data onXMPData for AVM1");
}
_ => {
tracing::warn!(
"Stub: FLV stream data {} for AVM1",
WStr::from_units(variable_name)
);
}
};
} }
Some(AvmObject::Avm2(_object)) => { Some(AvmObject::Avm2(_object)) => {
match variable_name { let mut activation = Avm2Activation::from_nothing(context.reborrow());
b"onCuePoint" | b"onMetaData" => { let client_object = self
let mut activation = Avm2Activation::from_nothing(context.reborrow()); .client()
let client_object = self.client().expect( .expect("Client should be initialized if script data is being accessed");
"Client should be initialized if script data is being accessed",
);
let data_object = variable_data.to_avm2_value(&mut activation); let data_object = variable_data.to_avm2_value(&mut activation);
client_object.call_public_property( client_object.call_public_property(
AvmString::new_utf8_bytes(activation.context.gc_context, variable_name), AvmString::new_utf8_bytes(activation.context.gc_context, variable_name),
&[data_object], &[data_object],
&mut activation, &mut activation,
)?; )?;
}
_ => {
tracing::warn!(
"Stub: FLV stream data {} for AVM2",
WStr::from_units(variable_name)
);
}
};
} }
None => {} None => {}
}; };