Skip to content

Conversation

@zjk261
Copy link
Contributor

@zjk261 zjk261 commented Oct 16, 2025

I didn't really understand how rng function is called inside avmplus, but this does fix RandomnessTest.swf from #20244, with some multiply opcodes replaced with multiply_i
RandomnessTest.zip

@zjk261 zjk261 marked this pull request as draft October 16, 2025 05:25
@zjk261 zjk261 marked this pull request as ready for review October 16, 2025 07:24
@danielhjacobs danielhjacobs added waiting-on-review Waiting on review from a Ruffle team member A-core Area: Core player, where no other category fits T-fix Type: Bug fix (in something that's supposed to work already) labels Oct 16, 2025
@kjarosh kjarosh added the squash-on-merge Marks a PR to be squashed before merging. label Oct 16, 2025
@torokati44
Copy link
Member

with some multiply opcodes replaced with multiply_i

Could you please elaborate on that?

I feel like #21907 could be related...

@zjk261
Copy link
Contributor Author

zjk261 commented Oct 17, 2025

#20244 (comment)
the original swf still does not produce 2137 with this
so I replaced some multiply opcode with multiply_i with ffdec according to this comment
I know very little about this, sorry

@Randomno
Copy link

Randomno commented Oct 17, 2025

The test requires integer multiplication, and Flash's AVM2 optimizer does this integer multiplication even with the regular multiply opcode, while Ruffle doesn't.

https://docs.google.com/presentation/d/1nUp89sZnQAtvsXFkzxyKdsdzYWsZ2OzV2BhlzTeJVsc/edit?slide=id.g2f09243411c_0_10#slide=id.g2f09243411c_0_10

@torokati44
Copy link
Member

Also, I think the small_rng feature of rand can be dropped now. Unfortunately, not the entire crate, as flash.crypto.generateRandomBytes uses os_rng and std.

Copy link
Collaborator

@Lord-McSweeney Lord-McSweeney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add the SWF in the issue as a test?

@Lord-McSweeney Lord-McSweeney added waiting-on-author Waiting on the PR author to make the requested changes and removed waiting-on-review Waiting on review from a Ruffle team member labels Oct 17, 2025
@zjk261
Copy link
Contributor Author

zjk261 commented Oct 18, 2025

@Randomno can I use modified SWF file as test?

@Randomno
Copy link

Koong (the author of it) says yes

@zjk261 zjk261 force-pushed the avmrng branch 3 times, most recently from 4cb20bf to a14655d Compare October 20, 2025 01:49
@zjk261 zjk261 requested a review from Lord-McSweeney October 21, 2025 02:09
@zjk261 zjk261 force-pushed the avmrng branch 2 times, most recently from c9d1786 to d1f1c98 Compare October 21, 2025 04:58
@@ -0,0 +1,3 @@
743483584
5402
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these results consistent for you in Flash Player? For me, the first two numbers outputted are random with each run.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not consistent

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case can you modify the SWF to only output the last number? For this test I think we'd want the output to be reproducible in Flash Player.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this? Removed most of the extra stuff, just traces true if the two numbers match.

However, it sometimes fails in Flash (as did the original version of the test). I think there's either an error in the algorithm, or Flash is executing stuff weirdly. Maybe should test with a pause between each step.

I tend to get 80% success rate in Flash Player 32.

test.zip

Copy link

@koonggames koonggames Oct 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed the consistency issue, it sometimes did not work because a double was not converted to a uint and when the polynomial used in the rng got too large values didn't match up.

rngtestruffle.zip

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm yeah, in 1000 attempts I got 7 failures. Target, probe, doublecheck:

7043, 1970344600, 266490418
653, 310941477, 1794949550
6349, 753898449, 1488657303
8564, 749768811, 1196820749
2950, 240060092, 1191158361
1542, 1440380734, 774071793
7838, 1007439541, 429495897

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe triplecheck is needed?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell the reversing itself is flawless now, when it breaks it seems to be during the rng calling part. No clue why, I can look into it tomorrow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main.zip
I think this should always work? I tested 1000 times and did not fail

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Lord-McSweeney I think it should be consistent now?

@Lord-McSweeney Lord-McSweeney removed the waiting-on-author Waiting on the PR author to make the requested changes label Oct 26, 2025
@Dinnerbone
Copy link
Contributor

Thanks everyone for the work that went into this!

@Dinnerbone Dinnerbone enabled auto-merge (squash) November 3, 2025 18:57
@Dinnerbone Dinnerbone merged commit d5a7e30 into ruffle-rs:master Nov 3, 2025
26 checks passed
@Randomno
Copy link

Randomno commented Nov 3, 2025

@zjk261 Thank you for implementing this

@zjk261 zjk261 deleted the avmrng branch November 6, 2025 13:08
Hancock33 added a commit to Hancock33/batocera.piboy that referenced this pull request Nov 9, 2025
-----------------------------------------------------------------------------------
ares.mk 35671b2f8dee508e01155f14b38a370528b281da # Version: Commits on Nov 04, 2025
-----------------------------------------------------------------------------------
ld: Fix some media info registers. Fixes JB Harold side changing.,

----------------------------------------------------------------------------------
clk.mk 0332bb4f12f707a19e06d00774257dc2d4970d48 # Version: Commits on Nov 04, 2025
----------------------------------------------------------------------------------
Merge pull request #1624 from TomHarte/ArchimedesVideoTiming

Pull clock divider inside the loop.,

------------------------------------------------------------------------------------------
duckstation.mk a5e20511d969d4499591088f7d86eefac8d0dbd7 # Version: Commits on Nov 04, 2025
------------------------------------------------------------------------------------------
Update the Simplified-Chinese Translation. (#3606),

-----------------------------------------------------------------------------------
eden.mk 4bf2e0a7aa1c466ab98e6dfc9972c039345cc927 # Version: Commits on Nov 04, 2025
-----------------------------------------------------------------------------------
[dynarmic] Add a formatter for `Dynarmic::IR::Opcode` (#2948)

-------------------------------------------------------------------------------------
hatari.mk 4df48fe4ceae69a21930a815e525941eb06f9a1c # Version: Commits on Nov 03, 2025
-------------------------------------------------------------------------------------
Fix str.c assert,

-----------------------------------------------------------------------------------
play.mk 77c62d3a942e219bc9d072b4800fa0881208ce2a # Version: Commits on Nov 03, 2025
-----------------------------------------------------------------------------------
Fix some issues with recoil server not shutting down properly.,

-------------------------------------------------------------------------------------
ppsspp.mk 607451fe6a5322b030757cf54e855c9470af96b0 # Version: Commits on Nov 04, 2025
-------------------------------------------------------------------------------------
Merge pull request #20961 from hrydgard/misc-code-cleanup

Misc code cleanup,

--------------------------------------------------------------------------------------
shadps4.mk 683e5f3b0462f91cc7a80c6f688d5b83e51f32be # Version: Commits on Nov 04, 2025
--------------------------------------------------------------------------------------
Core: Simulate write-only file access with read-write access (#3360)

* Swap write access mode for read write

Opening with access mode w will erase the opened file. We do not want this.

* Create mode

Opening with write access was previously the only way to create a file through open, so add a separate FileAccessMode that uses the write access mode to create files.

* Update file_system.cpp

Remove a hack added to posix_rename to bypass the file clearing behaviors of FileAccessMode::Write

* Check access mode in read functions

Write-only files cause the EBADF return on the various read functions. Now that we're opening files differently, properly handling this is necessary.

* Separate appends into proper modes

Fixes a potential regression from one of my prior PRs, and ensures the Write | Append flag combo also behaves properly in read-related functions.

* Move IsWriteOnly check after device/socket reads

file->f is only valid for files, so checking this before checking for sockets/devices will cause access violations.

* Fix issues

Now that Write is identical to ReadWrite, internal uses of Write need to be swapped to my new Create mode

* Fix remaining uses of FileAccessMode write to create files

Missed these before.

* Fix rebase

* Add stubbed get_authinfo (#3722)

* mostly stubbed get_authinfo

* Return value observed on console if get_authinfo was called for the current thread, esrch otherwise

---------

Co-authored-by: kalaposfos13 <[email protected]>

Co-authored-by: georgemoralis <[email protected]>,

-------------------------------------------------
vice.mk r45815 # Version: Commits on Nov 03, 2025
-------------------------------------------------
fix warning

git-svn-id: https://svn.code.sf.net/p/vice-emu/code/trunk@45815 379a1393-f5fb-40a0-bcee-ef074d9b53f7,

-------------------------------------------------------------------------------------------
xenia-native.mk efa0a8bb395a16d2457b8d07d8d50951ad12a873 # Version: Commits on Oct 31, 2025
-------------------------------------------------------------------------------------------
[XBDM] Added sketchy implementation of DmPMCGetCounterName and DmPMCInstallAndStart,

-----------------------------------------------------------------------------------
ymir.mk 472f287ea239e6572871538a6664c9feba02b499 # Version: Commits on Nov 03, 2025
-----------------------------------------------------------------------------------
chore: Add categories to some CHANGELOG entries,

-------------------------------------------------------------------------------------
ikemen.mk be61dcdca44a43af41d32f92e390cec0a298b5be # Version: Commits on Nov 04, 2025
-------------------------------------------------------------------------------------
Merge pull request #2861 from rakieldev/newstuff

refactor: migrate AIR indices to int32,

---------------------------------------------------------------
ruffle.mk nightly-2025-11-04 # Version: Commits on Nov 04, 2025
---------------------------------------------------------------
## What's Changed

* tests: Deduplicate tests with multiple FP versions by @moulins in ruffle-rs/ruffle#22121

* avm1: Implement Sound.id3 by @kjarosh in ruffle-rs/ruffle#22122

* avm1: Clean up use of BitmapData in BitmapData functions by @Dinnerbone in ruffle-rs/ruffle#22120

* core: Use same RNG algorithm as avmplus by @zjk261 in ruffle-rs/ruffle#21938

* build(deps): bump the cargo-minor group with 2 updates by @dependabot[bot] in ruffle-rs/ruffle#22135

## New Contributors

* @zjk261 made their first contribution in ruffle-rs/ruffle#21938

**Full Changelog**: ruffle-rs/ruffle@nightly-2025-11-03...nightly-2025-11-04,

--------------------------------------------------------------------------------------
scummvm.mk c08ea1e6536c25353f6e7dda717cc174f116b4c7 # Version: Commits on Nov 04, 2025
--------------------------------------------------------------------------------------
I18N: Update translation (Italian)

Currently translated at 100.0% (3056 of 3056 strings),

---------------------------------------------------------------------------------------
thextech.mk fdff234f27d4a3d558f156db3bd7f66761e305c9 # Version: Commits on Nov 04, 2025
---------------------------------------------------------------------------------------
Update changelog.txt,

------------------------------------------------------------------------------------
box64.mk e6843dcb9ff8b3f889e4e60f495408d14ba48ae3 # Version: Commits on Nov 04, 2025
------------------------------------------------------------------------------------
[CMAKE] Fix typo (#3122),

-----------------------------------------------------------------------------------------
catacombgl.mk 1979244f3668630c25e3d5501d038cf9b4c89b85 # Version: Commits on Nov 03, 2025
-----------------------------------------------------------------------------------------
Set direction for actors loaded from DOS saved game,

----------------------------------------------------------------------------------------
openmohaa.mk f2c31e956e6045a566625bf804eb0ab539ca0f8d # Version: Commits on Nov 03, 2025
----------------------------------------------------------------------------------------
fix(common): provide the delta time when executing console commands on dedicated servers

This fixes an issue in which the `wait` command would prevent further commands from being executed afterward.,

----------------------------------------------------------------------------------
stk.mk ceecb88822ed41f65242212de35cc7f3ff2088c7 # Version: Commits on Nov 04, 2025
----------------------------------------------------------------------------------
Prefill textbox for options and grand prix renaming (#5557),

-------------------------------------------------------
syncthing.mk v2.0.11 # Version: Commits on Nov 04, 2025
-------------------------------------------------------
## Major changes in 2.0

- Database backend switched from LevelDB to SQLite. There is a migration on

  first launch which can be lengthy for larger setups. The new database is

  easier to understand and maintain and, hopefully, less buggy.

- The logging format has changed to use structured log entries (a message

  plus several key-value pairs). Additionally, we can now control the log

  level per package, and a new log level WARNING has been inserted between

  INFO and ERROR (which was previously known as WARNING...). The INFO level

  has become more verbose, indicating the sync actions taken by Syncthing. A

  new command line flag `--log-level` sets the default log level for all

  packages, and the `STTRACE` environment variable and GUI has been updated

  to set log levels per package. The `--verbose` and `--logflags` command

  line options have been removed and will be ignored if given.

- Deleted items are no longer kept forever in the database, instead they are

  forgotten after fifteen months. If your use case require deletes to take

  effect after more than a fifteen month delay, set the

  `--db-delete-retention-interval` command line option or corresponding

  environment variable to zero, or a longer time interval of your choosing.

- Modernised command line options parsing. Old single-dash long options are

  no longer supported, e.g. `-home` must be given as `--home`. Some options

  have been renamed, others have become subcommands. All serve options are

  now also accepted as environment variables. See  `syncthing --help` and

  `syncthing serve --help` for details.

- Rolling hash detection of shifted data is no longer supported as this

  effectively never helped. Instead, scanning and syncing is faster and more

  efficient without it.

- A \default folder\ is no longer created on first startup.

- Multiple connections are now used by default between v2 devices. The new

  default value is to use three connections: one for index metadata and two

  for data exchange.

- The following platforms unfortunately no longer get prebuilt binaries for

  download at syncthing.net and on GitHub, due to complexities related to

  cross compilation with SQLite:

  - dragonfly/amd64

  - solaris/amd64

  - linux/ppc64

  - netbsd/*

  - openbsd/386 and openbsd/arm

  - windows/arm

- The handling of conflict resolution involving deleted files has changed. A

  delete can now be the winning outcome of conflict resolution, resulting in

  the deleted file being moved to a conflict copy.

This release is also available as:

* APT repository: https://apt.syncthing.net/

* Docker image: `docker.io/syncthing/syncthing:2.0.11` or `ghcr.io/syncthing/syncthing:2.0.11`

  (`{docker,ghcr}.io/syncthing/syncthing:2` to follow just the major version)

## What's Changed

### Fixes

* fix(policy): only allow approvals by non-author contributors by @marbens-arch in syncthing/syncthing#10419

* fix(fs): store `getExpireAdd` mutex in `caseCache` (fixes #9836) by @marbens-arch in syncthing/syncthing#10430

* fix(fs): apply case option to fakefs in casefs tests by @marbens-arch in syncthing/syncthing#10439

* fix(fs): only apply case option to fakefs in stress test by @marbens-arch in syncthing/syncthing#10440

### Other

* docs(docker): make host network mode the default by @bt90 in syncthing/syncthing#10416

* chore(upnp): remove incorrect embedding of nat.Service (fixes #10426) by @imsodin in syncthing/syncthing#10428

* chore: minor lint fixes by @calmh in syncthing/syncthing#10436

* chore(gui): add Azerbaijani (az) and Kurdish (ckb) l10n templates. by @acolomb in syncthing/syncthing#10442

**Full Changelog**: syncthing/syncthing@v2.0.10...v2.0.11,

-----------------------------------------------------------------------------------------
winetricks.mk 533f41704766765cfb3706fb2aa197acbb05df32 # Version: Commits on Nov 04, 2025
-----------------------------------------------------------------------------------------
ev3: remove broken verb,

----------------------------------------------------------------------------------------------------
sdl2-gamecontrollerdb.mk 958e252520ece96cd1b03d5ff0d835db2f048991 # Version: Commits on Nov 04, 2025
----------------------------------------------------------------------------------------------------
Upstream, sort,

----------------------------------------------------------------------------------------
retroarch.mk 081ced99408f18b1311eab48defb8d6efa5c0425 # Version: Commits on Nov 04, 2025
----------------------------------------------------------------------------------------
Use hotkeys from core port 0 (#18353),

----------------------------------------------------------------------------------------
doomretro.mk 29aeae614094bfe8ddc9e3e2fe07b9c4b5db96ac # Version: Commits on Nov 04, 2025
----------------------------------------------------------------------------------------
Update releasenotes.md,

-------------------------------------------------------------------------------------
gzdoom.mk 5e9e2302f4c8193d227a5c5ddffc8ab8be4bb05d # Version: Commits on Nov 04, 2025
-------------------------------------------------------------------------------------
reverted the tooltip feature.

In its current state it is not usable and causes errors and since it is bound to see no more updates it is better removed entirely.,

----------------------------------------------------------------------------------
trx.mk 78f44fe41288ba8fe8f1f5e61eb25b554cc7a2bf # Version: Commits on Nov 04, 2025
----------------------------------------------------------------------------------
tools/output-package-name: require arguments,

---------------------------------------------------------------------------------------------------
libretro-dosbox-pure.mk e8cb6683e8539757644d84278cf4deb2b0d0debc # Version: Commits on Nov 04, 2025
---------------------------------------------------------------------------------------------------
Fix shut down menu item on standalone version with \Advanced > Start Menu\ set to the default,

------------------------------------------------------------------------------------------------------
libretro-doublecherrygb.mk 9bcde59b7a45171262f5589b3b303cecff79f4cd # Version: Commits on Nov 04, 2025
------------------------------------------------------------------------------------------------------
🚨fixed compiler warnings,

--------------------------------------------------------------------------------------------------
libretro-gearcoleco.mk e2f85230c1b2d75697f7f5d49fe477f217a48952 # Version: Commits on Nov 03, 2025
--------------------------------------------------------------------------------------------------
Add VGM recorder,

-------------------------------------------------------------------------------------------------
libretro-geargrafx.mk 89737b0eff46bcc56c2a7a486a1e833743cfe0f0 # Version: Commits on Nov 03, 2025
-------------------------------------------------------------------------------------------------
Minor typo,

--------------------------------------------------------------------------------------------------
libretro-gearsystem.mk 572693112ca3a59525f4161bc0b25e7f632319ca # Version: Commits on Nov 03, 2025
--------------------------------------------------------------------------------------------------
Add VGM recorder. Fix #121,

----------------------------------------------------------------------------------------------
libretro-ppsspp.mk 607451fe6a5322b030757cf54e855c9470af96b0 # Version: Commits on Nov 04, 2025
----------------------------------------------------------------------------------------------
Merge pull request #20961 from hrydgard/misc-code-cleanup

Misc code cleanup,

-----------------------------------------------------------------------------------------------
libretro-scummvm.mk c08ea1e6536c25353f6e7dda717cc174f116b4c7 # Version: Commits on Nov 04, 2025
-----------------------------------------------------------------------------------------------
I18N: Update translation (Italian)

Currently translated at 100.0% (3056 of 3056 strings),

---------------------------------------------------------------------------------------------
libretro-vba-m.mk d24fd6d47d8cdd3c3337dc0476e5b7eea5d4fe97 # Version: Commits on Nov 04, 2025
---------------------------------------------------------------------------------------------
translations: transifex pull

Signed-off-by: Rafael Kitover <[email protected]>,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-core Area: Core player, where no other category fits squash-on-merge Marks a PR to be squashed before merging. T-fix Type: Bug fix (in something that's supposed to work already)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants