fivem
fivem copied to clipboard
[RedM] Cannot override base-game railway data
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 byTRAINTRACK_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 bydata_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:
-
Patch
CTrainConfigFileMounter
to clear the array of loaded track objects if it is not empty. This would enabledata_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. -
Add a manifest statement to override
traintracks.xml
. A new resource manifest statement, such asreplace_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 aresource:/
path to the loading function instead of the defaultcommon:/
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
- The Railway Editor has a wiki page at https://github.com/Sage-of-Mirrors/NaviGator/wiki/Railway-Editor.
- You can see a train running on custom tracks in the Great Plains here: https://www.youtube.com/watch?v=gDPD-eh5Gew and in Mexico here: https://youtu.be/7PhDqPqoeZM. Both of these were made with NaviGator and assets pulled from Nexus.
I have started an implementation of my second idea (fxmanifest
statement for replacing traintracks.xml
) here: https://github.com/Sage-of-Mirrors/fivem/commit/af7c525778fbb7b23833828b97615c56e3a91c29. I just need to get a pattern for the function call in CTrainConfigFileMounter
that loads the XML file.