Skip to content

Commit

Permalink
avm2: Deserialize AMF dictionary (#15169)
Browse files Browse the repository at this point in the history
  • Loading branch information
wsxarcher authored Feb 8, 2024
1 parent 71f828a commit 50a8815
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
32 changes: 30 additions & 2 deletions core/src/avm2/amf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,36 @@ pub fn deserialize_value<'gc>(
);
VectorObject::from_vector(storage, activation)?.into()
}
AmfValue::Dictionary(..) | AmfValue::Custom(..) | AmfValue::Reference(_) => {
tracing::error!("Deserialization not yet implemented: {:?}", val);
AmfValue::Dictionary(values, has_weak_keys) => {
let obj = activation
.avm2()
.classes()
.dictionary
.construct(activation, &[(*has_weak_keys).into()])?;
let dict_obj = obj.as_dictionary_object().unwrap();

for (key, value) in values {
let key = deserialize_value(activation, key)?;
let value = deserialize_value(activation, value)?;

if let Value::Object(key) = key {
dict_obj.set_property_by_object(key, value, activation.context.gc_context);
} else {
let key_string = key.coerce_to_string(activation)?;
dict_obj.set_public_property(key_string, value, activation)?;
}
}
dict_obj.into()
}
AmfValue::Custom(..) => {
tracing::error!("Deserialization not yet implemented for Custom: {:?}", val);
Value::Undefined
}
AmfValue::Reference(_) => {
tracing::error!(
"Deserialization not yet implemented for Reference: {:?}",
val
);
Value::Undefined
}
AmfValue::AMF3(val) => deserialize_value(activation, val)?,
Expand Down
3 changes: 3 additions & 0 deletions core/src/avm2/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ pub struct SystemClasses<'gc> {
pub sampledataevent: ClassObject<'gc>,
pub avm1movie: ClassObject<'gc>,
pub focusevent: ClassObject<'gc>,
pub dictionary: ClassObject<'gc>,
}

impl<'gc> SystemClasses<'gc> {
Expand Down Expand Up @@ -306,6 +307,7 @@ impl<'gc> SystemClasses<'gc> {
sampledataevent: object,
avm1movie: object,
focusevent: object,
dictionary: object,
}
}
}
Expand Down Expand Up @@ -816,6 +818,7 @@ fn load_playerglobal<'gc>(
("flash.net", "FileReference", filereference),
("flash.net", "FileFilter", filefilter),
("flash.utils", "ByteArray", bytearray),
("flash.utils", "Dictionary", dictionary),
("flash.system", "ApplicationDomain", application_domain),
("flash.text", "Font", font),
("flash.text", "StaticText", statictext),
Expand Down

0 comments on commit 50a8815

Please sign in to comment.