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

feat(extra-natives/rdr3): Add extra natives for train tracks #2548

Closed
wants to merge 8 commits into from
Closed

feat(extra-natives/rdr3): Add extra natives for train tracks #2548

wants to merge 8 commits into from

Conversation

Sage-of-Mirrors
Copy link
Contributor

Goal of this PR

This PR provides three new natives for RedM for working with train tracks:

  • GET_TRACK_COUNT: Returns the number of tracks that are currently loaded in the world.
  • GET_TRACK_FROM_INDEX: Returns the name hash of the track at the given index, or 0 if that index is invalid.
  • LOAD_TRACKS_FROM_FILE: Disposes of the currently-loaded tracks and loads new ones from a given traintracks.xml file. This allows for fully customized rail networks.

How is this PR achieving the goal

The extra natives can be find in extra-natives-rdr3/src/TrackNatives.cpp.

GET_TRACK_COUNT and GET_TRACK_FROM_INDEX are just directly accessing the track data.

LOAD_TRACKS_FROM_FILE is based on FiveM's LOAD_WATER_FROM_PATH.

While this approach appears to work without issue, I am not sure how vehicle replication works. If a connecting client doesn't run a resource containing a LOAD_TRACKS_FROM_FILE call before the server tells it to spawn a replicated train object, the client will crash. I ran a few tests on my local machine with multiple clients, and I did not get any crashes upon logging onto a local server. However, I currently cannot rule out the possibility that a higher ping or larger set of resources to load may delay the execution of a script long enough to cause a crash. More thorough testing may be required unless someone with more intimate knowledge of CFX's vehicle replication system can confirm that this will never be an issue.

This PR applies to the following area(s)

RedM, Natives

Successfully tested on

Game builds: 1491.50

Platforms: Windows

Checklist

  • Code compiles and has been tested successfully.
  • Code explains itself well and/or is documented.
  • My commit message explains what the changes do and what they are for.
  • No extra compilation warnings are added by these changes.

Fixes issues

Fixes #2424

@github-actions github-actions bot added the RedM Issues/PRs related to RedM label May 15, 2024
@Sage-of-Mirrors
Copy link
Contributor Author

This resource can be used to test the three extra natives: tracktest.zip.

@github-actions github-actions bot added the triage Needs a preliminary assessment to determine the urgency and required action label May 15, 2024
@Sage-of-Mirrors
Copy link
Contributor Author

At the request of @Disquse, I did some testing to determine if a bad actor could exploit LOAD_TRACKS_FROM_FILE to intentionally cause clients to crash. Unfortunately, I found that this is possible. If a client spawns a train on tracks that they have locally, but other clients do not have, those clients without the tracks will crash.

What can I do to prevent this? There's a patch for train config crashes, should I develop a similar patch for trains? Ensuring that the track index CREATE_MISSION_TRAIN gets is valid?

@Sage-of-Mirrors
Copy link
Contributor Author

Sage-of-Mirrors commented Jun 1, 2024

EDIT: Previous comment was inaccurate - the crash in question is still unresolved.

@github-actions github-actions bot added invalid Requires changes before it's considered valid and can be (re)triaged and removed triage Needs a preliminary assessment to determine the urgency and required action labels Jun 1, 2024
@Sage-of-Mirrors
Copy link
Contributor Author

Closing this MR because I'm bad at git. Will open a new, clean one in a moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid Requires changes before it's considered valid and can be (re)triaged RedM Issues/PRs related to RedM
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RedM] Cannot override base-game railway data
1 participant