Commit Graph

3668 Commits

Author SHA1 Message Date
David Wendt 016cd6ccc0 avm2: Make event construction take an `EventData` parameter.
This also necessitated the introduction of a `FullScreenEvent` data type.
2022-01-22 19:58:32 -08:00
David Wendt 43161976c7 avm2: Add a new field to store mouse event data on dispatched events. 2022-01-22 19:58:32 -08:00
relrelb 164e1a38c0 core: Remove unnecessary parameter from `post_instantiation`
`display_object` was always equivalent to `self`, there's no need to
pass both.
2022-01-22 11:37:33 -08:00
Mike Welsh e11e1e870f avm1: Improve Object comparisons in SWFv5
SWFv5 always calls `Object.valueOf` at least once and sometimes
twice in the Equals2 op, even when comparing two Objects.

For example, `Object(1) == Object(1)` is true in SWFv5 but false
in SWFv6.
2022-01-21 16:40:19 -08:00
Mike Welsh bf599d9107 avm1: Clean up Value::abstract_eq
Consolidate several cases and fix some issues:
 * Object-to-primitive comparison always goes through `valueOf`.
 * `Object(undefined) == undefined` is true; this will coerce
   to a bare object with no `valueOf`, resulting in
   `undefined==undefined`.
 * `{valueOf:function() { return NaN; }} == NaN` is true.
2022-01-21 16:40:19 -08:00
Mike Welsh 4d8db1e64d avm1: Fix function closures inside `with`
When creating a scope for a closure, any `with` scopes were being
filtered out, but this was incorrect; `with` scopes are still on
the scope chain when the function is called.
2022-01-19 20:29:26 -08:00
relrelb 1de284dc5b html: Fix handling of end tag mismatch
Flash ignores mismatched end tags (i.e. end tags with a missing/different
corresponding start tag). `quick-xml` checks end tag mismatches by
default, but it cannot recover after encountering one.

Commit 7e20543578 already disabled
`quick-xml`'s check, but that caused mismatched `Event::End` to be
handled, which may empty `format_stack` and later panic on
`format_stack.last().unwrap()`.

Thus, check for mismatched end tags ourselves, in a similar manner
of `quick-xml`, but in a recoverable way.
2022-01-18 13:50:26 -08:00
David Wendt 57acf47a10 avm2: Allow access to stage properties without a valid root movie clip. 2022-01-18 11:06:23 -08:00
David Wendt df25d1ca8b avm2: Children of the root inherit their parent's `loaderInfo` 2022-01-18 11:06:23 -08:00
David Wendt f041cced72 avm2: The stage's loader info object allows access to `url`, `bytes`, and `parameters`. 2022-01-18 11:06:23 -08:00
Mike Welsh b181debff6 swf: Use bitflags for `avm1::GetUrl2` 2022-01-17 21:35:57 -08:00
Mike Welsh 4c3e14eae5 core: Clean up `DefineFunction` action
* Have `DefineFunction` and `DefineFunction2` go through the same
   code path by implementing `From<DefineFunction>` for
   `DefineFunction2`.
 * Change `register` to a `Option<NonZeroU8>` for size optimization.
 * Add `function::Param` to store param info instead of a tuple.
2022-01-17 21:35:57 -08:00
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