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

[RedM] Cannot override base-game railway data #2424

Open
Sage-of-Mirrors opened this issue Mar 14, 2024 · 1 comment · May be fixed by #2575
Open

[RedM] Cannot override base-game railway data #2424

Sage-of-Mirrors opened this issue Mar 14, 2024 · 1 comment · May be fixed by #2575
Labels
bug RedM Issues/PRs related to RedM ScRT: Lua Issues/PRs related to the Lua scripting runtime triage Needs a preliminary assessment to determine the urgency and required action

Comments

@Sage-of-Mirrors
Copy link

What happened?

I have written a tool called NaviGator (https://github.com/Sage-of-Mirrors/NaviGator) which allows the user to edit Red Dead Redemption 2's railway data. The modified data is easily incorporated into the game's Offline version, as Lenny's Mod Loader (LML) provides mods with the ability to both stream new assets, and directly replace existing base-game assets. The latter is critical, as railways must reference each other in order for a train to move between them at a junction.

However, RedM does not currently offer a way to replace the necessary data. There are two main components to the railways:

  • Several *.dat files, which contain the information about the nodes making up the railway, and
  • traintracks.xml, which defines the track objects themselves, referencing the *.dat files by filepath.

I have investigated the following possible solutions, but none have provided a satisfactory result:

  • Creating a resource with data_file TRAINTRACK_FILE. The mounter invoked by TRAINTRACK_FILE, CTrainConfigFileMounter, does not clear the array of track objects before loading the new ones specified by the user in the resource; therefore, any tracks loaded by data_file TRAINTRACK_FILE are loaded in addition to the base-game's, rather than instead of them.
  • Creating a resource with REPLACE_LEVEL_META. traintracks.xml is referenced by the level meta via filepath, and changing that filepath to refer to a custom XML file in a resource would allow the user to directly control what tracks are loaded. However, RedM does not currently support replacing the level meta, and a solution for it appears to require solutions to other problems that are not currently clear.
  • Creating junctions with only one track referencing another. "Asymmetrical" junctions, where one track references another but not vice versa, are not supported by the game engine. The train cannot switch tracks and the game appears to become unstable.

Despite all of these dead ends, I am stubborn, and I have come up with two final ideas:

  1. Patch CTrainConfigFileMounter to clear the array of loaded track objects if it is not empty. This would enable data_file TRAINTRACK_FILE to replace all of the tracks initially loaded by the level. I have already determined the locations in memory where the loaded track objects are stored, along with a variable containing how many are currently loaded.
  2. Add a manifest statement to override traintracks.xml. A new resource manifest statement, such as replace_traintracks_file <path/to/file>, could trigger earlier in the loading process than my first solution and swap out the default XML file for one specified by the user. This would hypothetically be simpler, as the patch would just need to be able to optionally pass a resource:/ path to the loading function instead of the default common:/ path.

If either of these solutions sound like an acceptable addition to RedM, I am prepared to do the research and development to make that PR myself. All I ask for is guidance on the best practices related to patching the game.

Thank you for your time.

Expected result

Base-game railway data is overridden with data from a resource.

Reproduction steps

None.

Importancy

Slight inconvenience

Area(s)

RedM, Natives, ScRT: Lua

Specific version(s)

RedM 7619

Additional information

@Sage-of-Mirrors Sage-of-Mirrors added bug triage Needs a preliminary assessment to determine the urgency and required action labels Mar 14, 2024
@github-actions github-actions bot added RedM Issues/PRs related to RedM ScRT: Lua Issues/PRs related to the Lua scripting runtime labels Mar 14, 2024
@Sage-of-Mirrors
Copy link
Author

I have started an implementation of my second idea (fxmanifest statement for replacing traintracks.xml) here: Sage-of-Mirrors@af7c525. I just need to get a pattern for the function call in CTrainConfigFileMounter that loads the XML file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug RedM Issues/PRs related to RedM ScRT: Lua Issues/PRs related to the Lua scripting runtime triage Needs a preliminary assessment to determine the urgency and required action
Projects
None yet
1 participant