Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Synchronization of RNG #1

Open
Sewer56 opened this issue May 23, 2020 · 1 comment
Open

Synchronization of RNG #1

Sewer56 opened this issue May 23, 2020 · 1 comment

Comments

@Sewer56
Copy link
Owner

Sewer56 commented May 23, 2020

In order to maintain consistency between players, the random number generator will require synchronizing.

Initial Synchronization

Initial synchronization should be performed by hooking the native srand function that has been inlined into the executable. It is available at 0x0059B7BD.

srand() is called on:

  • Race load start.
  • Race start (after intro cutscene).
  • Race restart.

Since srand is only called during initialization, the host should send out a seed to the players every time the function is called and wait for acknowledgements (effectively freeze the game). Players should wait for an acknowledgement from the host.

Constant Synchronization

While initial synchronization should maintain perfect synchronization in theory; in practice there are still edge cases such as a client disconnecting, grabbing an item box and reconnecting.

Other cases include RNG triggering events that may not be hooked by the user.
In order to enforce a consistent RNG for those edge cases, the client's seeds should simply force synchronize with the host in a non-blocking way.

During gameplay, after the host executes the rand function, the host should send a copy of the new seed using the reliable channel. Clients will apply this new seed asynchronously.

rand() is called on:

  • Periodically on a timer.
  • On item pickup.
  • On other similar conditions.

Address of rand: 0x0059B7CA

@Sewer56 Sewer56 changed the title Synchronization of RNG [WIP] Synchronization of RNG May 23, 2020
@Sewer56 Sewer56 changed the title [WIP] Synchronization of RNG Synchronization of RNG May 23, 2020
@Sewer56
Copy link
Owner Author

Sewer56 commented Feb 24, 2021

Implemented, however currently desyncs due to off-screen objects seeding RNG for one player but not the other.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant