Commit Graph

3706 Commits

Author SHA1 Message Date
Mike Welsh c618a12d14 core: Remove _ pattern in `avm1::Activation::do_action`
The match is exhaustive, so replace `_` with `Action::Unknown`.
2022-01-17 21:35:57 -08:00
Mike Welsh 2b2346b65e swf: Add `avm1::Action::End`
Returning an `Action::End` instead of `None` when reading the end
of an action.
2022-01-17 21:35:57 -08:00
Mike Welsh 9141451ca1 swf: Use structs for avm1 `Action` variants
Use a struct for all variants of `avm1::Action`.
This makes the style more consistent instead of using a mix of
struct and tuple variants, and allows the data to be easily passed
around.
2022-01-17 21:35:57 -08:00
Adrian Wielgosik 5358940774 avm2: Support basic string.replace
Supports:
- string.replace(string, string)
- string.replace(regex, simple_string)

Does not support:
- string.replace(regex, string_with_replacement_codes)
- string.replace(any, function)
2022-01-17 20:10:20 -08:00
relrelb 3b25a3b901 avm1: Correct `MovieClipLoader.getProgress`
Handle strings, numbers and DisplayObject targets.
Return compressed length rather than uncompressed length.
2022-01-15 13:08:01 -08:00
relrelb eb23f19fad avm1: Correct `MovieClipLoader.unloadClip`
Handle strings, numbers and DisplayObject targets.
2022-01-15 13:08:01 -08:00
relrelb 0da8e504ab avm1: Correct `MovieClipLoader.loadClip`
Handle strings, numbers and DisplayObject targets (not just MovieClips).
To support non-MovieClip targets, turn `clip.as_movie_clip().unwrap()`
to `if let Some(mc) = clip.as_movie_clip()` in `Loader`.
2022-01-15 13:08:01 -08:00
relrelb e9607cfcbb chore: Appease clippy 2022-01-15 11:16:24 -08:00
relrelb 25722e7abe avm1: Fix `onLoadInit` event order
`onLoadInit` is queued after all `DoAction`s of the loaded clips.
That is, if clip1, clip2, clip3 are loaded in the same frame
(in this order), then actions will be executed as follows:

* `DoAction` of clip3
* `DoAction` of clip2
* `DoAction` of clip1
* `onLoadInit` of clip3
* `onLoadInit` of clip2
* `onLoadInit` of clip1

Previously, those were incorrectly executed as follows:

* `DoAction` of clip3
* `onLoadInit` of clip3
* `DoAction` of clip2
* `onLoadInit` of clip2
* `DoAction` of clip1
* `onLoadInit` of clip1
2022-01-14 17:27:14 -08:00
TÖRÖK Attila 12f9bec194 chore: Bump h263-rs git reference
To make use of https://github.com/ruffle-rs/h263-rs/pull/17
2022-01-14 17:09:39 -08:00
Mike Welsh 232f1dd120 chore: Appease clippy 2022-01-10 23:37:11 -08:00
dependabot[bot] 8f53449762 build(deps): bump indexmap from 1.7.0 to 1.8.0
Bumps [indexmap](https://github.com/bluss/indexmap) from 1.7.0 to 1.8.0.
- [Release notes](https://github.com/bluss/indexmap/releases)
- [Changelog](https://github.com/bluss/indexmap/blob/master/RELEASES.rst)
- [Commits](https://github.com/bluss/indexmap/compare/1.7.0...1.8.0)

---
updated-dependencies:
- dependency-name: indexmap
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-01-10 22:08:19 -08:00
dependabot[bot] 491cc05a79 build(deps): bump syn from 1.0.84 to 1.0.85
Bumps [syn](https://github.com/dtolnay/syn) from 1.0.84 to 1.0.85.
- [Release notes](https://github.com/dtolnay/syn/releases)
- [Commits](https://github.com/dtolnay/syn/compare/1.0.84...1.0.85)

---
updated-dependencies:
- dependency-name: syn
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-01-10 22:07:29 -08:00
relrelb b39ab9034c core: Remove `Player::is_mouse_down`
Now that `InputManager` tracks the mouse button, it can be used
instead.
2022-01-10 01:18:49 -08:00
relrelb 573aa89c9a core: Handle mouse events in `InputManager::handle_event` 2022-01-10 01:18:49 -08:00
relrelb 82b4c6ef27 core: Support mouse buttons in `KeyCode`
Add `MouseLeft`, `MouseRight` and `MouseMiddle` to `KeyCode` for
AVM1's `Key.isDown()` function.
2022-01-10 01:18:49 -08:00
relrelb 6396c21bc0 core: Rename `PlayerEvent::MouseLeft` to `MouseLeave`
So it's not consfusing with `KeyCode::MouseLeft`.
2022-01-10 01:18:49 -08:00
relrelb c00532aed2 core: Cleanup mouse update logic
Move code that is exclusive to mouse events from
`Player::update_mouse_state` to `Player::handle_event`.
2022-01-10 01:18:49 -08:00
Adrian Wielgosik 86210363f0 avm2: Remove Object::derive() machinery for AS3 prototypes 2022-01-09 18:23:10 -08:00
relrelb b79144c122 avm1: Remove `TextFormatObject::set_text_format`
Use `text_format_mut` instead.
2022-01-10 00:26:33 +02:00
Mike Welsh 2653c5f5c3 audio: Handle gaps in MP3 SoundStreamBlock tags (fix #3817)
An MP3 "stream" sound can sometimes have frames without a
SoundStreamBlock tag, despite the SWF spec saying there should
at least be a tag with 0 samples on each frame. Ruffle would
stop the sound in this case, but the Flash Player may or may not
stop thje sound in the audio depending on the number of "empty"
frames. This could cause the audio to stutter as it continuously
stopped and restarted.

Handle this by keeping track of how many samples we've encountered
in MP3 blocks, and deducting the amount of samples consumed by each
timeline frame. Stop the sound if we run out of samples, as opposed
to when we hit a frame without a SoundStreamBlock.

Fixes #3817.
2022-01-07 13:23:53 -08:00
Mike Welsh b2f7c98f88 audio: Sync animation with embedded audio streams
This is a first pass at syncing animation and audio playback when
and embedded audio stream is playing.

Fixes #3020, #3663, #3958.
2022-01-07 13:23:53 -08:00
relrelb 8c736b9756 avm1: Fix `MovieClipLoader` event arguments
The first argument of all events is the target MovieClip. It was
incorrect.

Also, `onLoadComplete` accepts an additional `httpStatus` argument.
Stub it to 0.
2022-01-07 10:39:16 -08:00
relrelb e045a9502b core: Small cleanup in `Loader`
Remove unnecessary calls to `introduce_loader_handle`, which are
dominated by `add_loader` that already calls it. As a result, `add_loader`
remained the only function to call `introduce_loader_handle`, so inline
it there.
2022-01-07 10:39:16 -08:00
relrelb c05ff4cbc8 core: Unify `Loader::Xml` into `Loader::LoadVars`
Since they are identical (they both load the URL as a string, then
fire the `onHTTPStatus` and `onData` events). In fact, AVM1's
`XML.prototype.load` and `LoadVars.prototype.load` functions are
both defined as `ASnative(301, 0)`, so they invoke the same native
code under the hood.
2022-01-07 09:51:27 -08:00
dependabot[bot] a9e86a73cf build(deps): bump serde from 1.0.132 to 1.0.133
Bumps [serde](https://github.com/serde-rs/serde) from 1.0.132 to 1.0.133.
- [Release notes](https://github.com/serde-rs/serde/releases)
- [Commits](https://github.com/serde-rs/serde/compare/v1.0.132...v1.0.133)

---
updated-dependencies:
- dependency-name: serde
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-01-03 23:28:57 +02:00
dependabot[bot] 6533511994 build(deps): bump quote from 1.0.10 to 1.0.14
Bumps [quote](https://github.com/dtolnay/quote) from 1.0.10 to 1.0.14.
- [Release notes](https://github.com/dtolnay/quote/releases)
- [Commits](https://github.com/dtolnay/quote/compare/1.0.10...1.0.14)

---
updated-dependencies:
- dependency-name: quote
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-01-03 22:50:58 +02:00
Mike Welsh 34ed9cbbaa core: Fix incorrect closing of paths in drawing API (fix #5598)
The path starting position was not being set correctly after a
moveTo command, which could cause stray strokes to appear in the
drawing.

Fixes #5598, #5768, #5957.
2022-01-01 22:24:08 -08:00
relrelb 655adedc1c xml: Remove `XmlNode::is_as2_compatible`
Now all `XmlNodeData` types are AS2-compatible, so `is_as2_compatible`
always returns `true`.
2022-01-02 07:36:49 +02:00
relrelb 30cd2aa4f1 xml: Remove `XmlNodeData::DocType`
`XmlNode::is_as2_compatible` returns `false` for `XmlNodeData::DocType`
nodes, which means they are not included in string representations of
XML documents, and they cannot be traversed using the DOM methods.

So don't create those when parsing an XML from string, but still
store the `DOCTYPE` declaration string on the `XmlDocument`, which
is accissible through the `.docTypeDecl` property.
2022-01-02 07:36:49 +02:00
relrelb 827bb6e48e xml: Remove `XmlNodeData::Comment`
`XmlNode::is_as2_compatible` returns `false` for `XmlNodeData::Comment`
nodes, which means they are not included in string representations of
XML documents, and they cannot be traversed using the DOM methods.

So simply don't create those when parsing an XML from string.
2022-01-02 07:36:49 +02:00
relrelb e477fca9e4 xml: Use OR patterns
This results in a slightly shorter code, and avoids some duplication.
2021-12-31 19:00:12 +02:00
relrelb 8bd144ec88 xml: Make `XmlDocumentData::root` non-`Option`
Since `XmlNode::document` doesn't exist anymore, so as the circular-
reference between `XmlDocument` and `XmlNode`.
2021-12-31 19:00:12 +02:00
relrelb 3676db47a3 xml: Remove unused `XmlNode::document` 2021-12-31 19:00:12 +02:00
relrelb f7e80e3fb9 xml: Inline `XmlDocument::add_child_to_tree`
Include the XML root node itself as part of the stack, so appending
children to it is no longer considered a special case.
2021-12-31 09:35:09 +02:00
relrelb e1198bd30c xml: Inline `XmlDocument::process_event`
Now that `replace_with_str` is defined in `XmlDocument`, there is
no need anymore for a separate function that handles nodes which have
document-wide implications.
2021-12-31 09:35:09 +02:00
relrelb 7d148fb61d xml: Move `XmlNode::replace_with_str` to `XmlDocument`
It only makes sense to call this method on document roots.
2021-12-31 09:35:09 +02:00
Adrian Wielgosik fcab60de7e core: register non-ascii fonts lazily 2021-12-31 01:10:48 +01:00
relrelb 0bab5f6d91 avm1: Use `XmlObject`
Previously Ruffle's AVM1 runtime incorrectly permitted calling `XML`
functions on `XMLNode` objects. For example:

```as
var xml = new XML("<a><b></b></a>");
trace(XML.prototype.createElement.call(xml.firstChild, "aaa")); // traces "undefined" in Flash, but "<aaa />" in Ruffle before this commit.
```

Disallow this by using the newly-reintroduced `XmlObject` for `XML` objects
(rather than `XmlNodeObject` that represents also `XMLNode` object), and check
for it in all `XML` builtins.
2021-12-30 22:13:14 +02:00
relrelb b501b4697a avm1: Re-introduce `XmlObject`
The newly-reintroduced `XmlObject` will represent `XML` document objects.
Currently it's unused, but the following commit will make use of it.
2021-12-30 22:13:14 +02:00
TÖRÖK Attila 09ca48e389 chore: Bump h263-rs git reference 2021-12-30 16:22:27 +01:00
TÖRÖK Attila 6f68938591 video/vp6: Fix keyframe detection on Vp6WithAlpha videos 2021-12-29 11:28:05 +01:00
dependabot[bot] 56b340ebf5 build(deps): bump syn from 1.0.82 to 1.0.84
Bumps [syn](https://github.com/dtolnay/syn) from 1.0.82 to 1.0.84.
- [Release notes](https://github.com/dtolnay/syn/releases)
- [Commits](https://github.com/dtolnay/syn/compare/1.0.82...1.0.84)

---
updated-dependencies:
- dependency-name: syn
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-12-27 22:32:21 +02:00
relrelb e547fd710d xml: Remove `XmlName`
Instead use a much simpler approach using `XmlNode::local_name` and
`XmlNode::prefix`.
2021-12-27 20:53:34 +02:00
relrelb 6ca1ac05da avm1: Rename `XmlObject` to `XmlNodeObject`
The name `XmlObject` will be re-used in a future PR for `XML`
document objects.
2021-12-27 20:53:34 +02:00
Moulins 74ab24c0c3 core: fix wide string handling in html::text_format
Closes #5839
2021-12-21 22:19:13 +02:00
Adrian Wielgosik 4230d1f19f avm2: Add Mouse.hide(), Mouse.show() 2021-12-21 17:32:57 +01:00
dependabot[bot] fd816f3a0a build(deps): bump serde from 1.0.131 to 1.0.132
Bumps [serde](https://github.com/serde-rs/serde) from 1.0.131 to 1.0.132.
- [Release notes](https://github.com/serde-rs/serde/releases)
- [Commits](https://github.com/serde-rs/serde/compare/v1.0.131...v1.0.132)

---
updated-dependencies:
- dependency-name: serde
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-12-21 08:35:54 +02:00
relrelb b1151b2ab2 html: Rewrite `FormatSpans::to_html`
The new implementation doesn't use the `xml` crate, nor `quick-xml`,
but rather just iterates the `TextSpan`s and builds the formatted HTML
string.
2021-12-20 08:31:59 +02:00
relrelb 2ad5c644b0 avm1: Make `ArrayObject` proto non-`Option`
It was always passed as `Some`, so there's no reason for allowing
`None`.
2021-12-18 13:39:22 +02:00
relrelb 9d87a34f25 html: Ignore tag errors
Flash stops parsing the XML in such cases, but still returns the
partially-processed text.
2021-12-18 11:34:31 +02:00
relrelb c1404f6a3e html: Expand empty elements
`quick-xml` has a feature to split empty elements into an `Open` and
a `Close` event. Use it to avoid duplicated code.
2021-12-18 11:34:31 +02:00
relrelb 7e20543578 html: Don't check end names
Flash permits mismatched closing tags (e.g. `<mytag></different_tag>`),
so turn-off this check.
2021-12-18 11:34:31 +02:00
Adrian Wielgosik 5d81a0ce64 avm2: Remove .clone() calls now that Index is Copy 2021-12-17 21:09:40 -07:00
Adrian Wielgosik a8fb1c2b16 avm2: pass Multiname to resolve_type() by reference 2021-12-17 21:09:40 -07:00
Adrian Wielgosik 22a0711d85 avm2: Use TU's method cache for callstatic, newfunction opcodes 2021-12-17 21:09:40 -07:00
Adrian Wielgosik 4b23f4dfb7 avm2: Set correct value type in op_convert_u/i 2021-12-17 21:06:33 -07:00
TÖRÖK Attila 0a2767fcb4 video: Wire up DefineVideoStream smoothing flag to the renderer
With all the weird logic for when it actually takes effect
2021-12-17 21:03:57 -07:00
David Wendt 2aee3555ab chore: Fix all new clippy lints added in latest Rust nightly 2021-12-17 20:53:26 -07:00
relrelb 07c5330456 core: Introduce `InputManager`
`InputManager` encapsulates the common logic that previously the
`UiBackend`s used to implement.
2021-12-15 14:20:30 -08:00
Adrian Wielgosik 726ec47f19 avm2: Support inheritance of protected traits 2021-12-15 22:26:41 +01:00
Adrian Wielgosik 11534a4b34 avm2: Implement parseInt, parseFloat 2021-12-15 22:16:49 +01:00
Adrian Wielgosik 49feb23649 avm2: Move toplevel functions to separate file 2021-12-15 22:16:49 +01:00
TÖRÖK Attila 95665bdc47 video: Extract software decoders (or glue) into their own modules, add screenvideo feature 2021-12-14 19:41:17 -07:00
TÖRÖK Attila fdc448533d video: Add Flash Screen Video (V1 only) decoder
Thanks a lot for the code and the help, Kostya!
2021-12-14 19:41:17 -07:00
Toad06 db98f0b42f avm1: Use inner SWFs version number 2021-12-14 19:39:30 -07:00
dependabot[bot] c6dfcb4e37 build(deps): bump serde from 1.0.130 to 1.0.131
Bumps [serde](https://github.com/serde-rs/serde) from 1.0.130 to 1.0.131.
- [Release notes](https://github.com/serde-rs/serde/releases)
- [Commits](https://github.com/serde-rs/serde/compare/v1.0.130...v1.0.131)

---
updated-dependencies:
- dependency-name: serde
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-12-13 23:23:13 +02:00
dependabot[bot] b8ff8bb185 build(deps): bump jpeg-decoder from 0.2.0 to 0.2.1
Bumps [jpeg-decoder](https://github.com/image-rs/jpeg-decoder) from 0.2.0 to 0.2.1.
- [Release notes](https://github.com/image-rs/jpeg-decoder/releases)
- [Changelog](https://github.com/image-rs/jpeg-decoder/blob/master/CHANGELOG.md)
- [Commits](https://github.com/image-rs/jpeg-decoder/compare/v0.2.0...v0.2.1)

---
updated-dependencies:
- dependency-name: jpeg-decoder
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-12-13 23:23:01 +02:00
dependabot[bot] ef679d25c7 build(deps): bump encoding_rs from 0.8.29 to 0.8.30
Bumps [encoding_rs](https://github.com/hsivonen/encoding_rs) from 0.8.29 to 0.8.30.
- [Release notes](https://github.com/hsivonen/encoding_rs/releases)
- [Commits](https://github.com/hsivonen/encoding_rs/compare/v0.8.29...v0.8.30)

---
updated-dependencies:
- dependency-name: encoding_rs
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-12-13 23:22:28 +02:00
EmperorBale 30f2e0f8b1
avm2: Implement JSON (#5172)
* avm2: Implement JSON.parse

* avm2: Add AvmSerializer for serializing AVM values to JSON

* avm2: Add support for replacer objects

* avm2: use *const ObjectPtr for object stack

* avm2: Add support for space parameter is JSON.stringify

* avm2: Refactor AvmSerializer design

* avm2: Restrict spaces to a maximum of 10

* avm2: Refactor map_value

* tests: Add JSON.parse test

* chore: Appease clippy

* avm2: Check if value is undefined before inserting

* tests: Add test for JSON.stringify

* tests: Improve JSON.stringify test

* chore: Replace map_or with explicit match statements

* chore: Use QName::dynamic_name

* avm2: Use Object<'gc> instead of ObjectPtr

* chore: Use explicit match in deserialize_value

* Rebase fixes

Co-authored-by: Adrian Wielgosik <adrian.wielgosik@gmail.com>
2021-12-13 18:32:04 +01:00
Adrian Wielgosik ad1442dbaa avm2: Add a basic ContextMenu stub 2021-12-13 18:31:03 +01:00
Adrian Wielgosik 1f5979f168 chore: clippy 2021-12-11 20:48:09 +01:00
Adrian Wielgosik 1311b0a3d0 avm2: refactor Domain::get_defining_script 2021-12-11 20:48:09 +01:00
Adrian Wielgosik 0fb075a309 chore: cargo fmt 2021-12-11 20:48:09 +01:00
Adrian Wielgosik 3d8f611651 avm2: Update comments. 2021-12-11 20:48:09 +01:00
Adrian Wielgosik b747541709 avm2: Panic upon encountering CallMethod opcode 2021-12-11 20:48:09 +01:00
Adrian Wielgosik 1d8c556944 avm2: Handle TODOs, throw errors where applicable 2021-12-11 20:48:09 +01:00
Adrian Wielgosik 24247dff0b avm2: install_const_late always appends slots 2021-12-11 20:48:09 +01:00
Adrian Wielgosik 4bd12ae4b3 avm2: Get prototypes from classes without get_property() 2021-12-11 20:48:09 +01:00
Adrian Wielgosik 49d16dea8b avm2: Rip out `receiver` from get/set/call_property 2021-12-11 20:48:09 +01:00
Adrian Wielgosik ee0798b258 avm2: Cleanup slots/global initialization some more 2021-12-11 20:48:09 +01:00
Adrian Wielgosik 21865edf9b avm2: Support const slots, fill some TODOs 2021-12-11 20:48:09 +01:00
Adrian Wielgosik b272d8722e avm2: Reword slot/disp_id assignment, remove Slot. 2021-12-11 20:48:09 +01:00
Adrian Wielgosik 4d8999c012 avm2: Make all prototypes ScriptObjects; also cleanup vector enumeration, Proxy 2021-12-11 20:48:09 +01:00
Adrian Wielgosik 3706db86d2 avm2: move properties from instances to vtable 2021-12-11 20:48:09 +01:00
relrelb d3fe4ea59a avm1: Split `XML` and `XMLNode` definitions
This reduces the file size of the previous `xml.rs` file, and makes
the code a bit more organized.
2021-12-11 20:28:37 +02:00
Adrian Wielgosik 6594d4159d avm2: Use Vec instead of HashMap for loaded constants 2021-12-11 10:03:29 +01:00
relrelb ca3b215561 chore: Appease clippy 2021-12-10 21:06:38 +02:00
relrelb 7966d850dd core: Normalize `\r` to `\n` in `avm_trace`
Fixes #3120.
2021-12-10 19:54:35 +02:00
relrelb eacf34d80a avm1: Remove `Function.prototype.toString`
`Function.prototype` doesn't have its own `toString` method, but
rather inherts it from `Object.prototype`. So remove `Function.prototype.toString`
and move its logic to `Object.prototype.toString`.
2021-12-10 11:36:39 +02:00
relrelb ce2eff8b25 render: Stub L16 JPEG pixel format
16-bit luminance (grayscale) images are very rare, so it's hard to
tell what the expected behavior should be.
2021-12-10 00:28:45 +02:00
dependabot[bot] 8007f21ffe build(deps): bump jpeg-decoder from 0.1.22 to 0.2.0
Bumps [jpeg-decoder](https://github.com/image-rs/jpeg-decoder) from 0.1.22 to 0.2.0.
- [Release notes](https://github.com/image-rs/jpeg-decoder/releases)
- [Changelog](https://github.com/image-rs/jpeg-decoder/blob/master/CHANGELOG.md)
- [Commits](https://github.com/image-rs/jpeg-decoder/compare/v0.1.22...v0.2.0)

---
updated-dependencies:
- dependency-name: jpeg-decoder
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-12-10 00:28:45 +02:00
Adrian Wielgosik d28dd3bd05 avm1: Fix up attributes of some builtins' protos 2021-12-10 00:28:21 +02:00
EmperorBale 0a25ebbc32 chore: Remove more explicit clones 2021-12-08 22:14:45 +01:00
EmperorBale d6b7d0c915 chore: Fix formatting 2021-12-08 22:14:45 +01:00
EmperorBale a192fbb113 chore: Remove explicit clones in avm2 2021-12-08 22:14:45 +01:00
EmperorBale 847a4fb61a chore: Remove explicit clones in value 2021-12-08 22:14:45 +01:00
EmperorBale 1709ea94e7 chore: Remove explicit clones in object 2021-12-08 22:14:45 +01:00
EmperorBale 8ea41bc151 chore: Remove explicit clones in slot 2021-12-08 22:14:45 +01:00
EmperorBale 15378bcfde chore: Remove explicit clones from vector 2021-12-08 22:14:45 +01:00