dariowouters / ts-map

ATS/ETS2 map renderer
MIT License
85 stars 28 forks source link

Reading navigation data (.navcache) #30

Closed cerus closed 2 years ago

cerus commented 2 years ago

Hey there! I'm currently working on a ETS map viewer and your ts-map project has been really helpful so far, thanks a lot for this.

I would like to add navigation / route generation to my map, but that's easier said than done. One way of doing this would be to export the roads and prefabs so that I can run some sort of algorithm to generate a route, but I have absolutely no idea how I should do that. Another way would be to work with the navigation cache of ETS2. Unfortunately the .navcache format is not documented anywhere.

I've tried to reverse engineer the format myself, but I'm already stuck. I've only been able to decipher the first part of what I assume to be the header (4 bytes magic value (NAVC) followed by 4 bytes version (0x01)).

It seems like you have a bit more experience with reverse engineering file formats than I do judging by this repository. Would you be able to help with this? I understand if that's completely out of scope.

The navigation cache can be found in Documents\Euro Truck Simulator 2\cache\<profile id>.navcache. I can send you my own navcache if needed.

Thank you!

dariowouters commented 2 years ago

I took a quick look at the navcache files but couldn't really see anything familiar. It would probably require reverse engineering the game's exe to figure out how it creates those files.

But I don't think you really need that file, the nodes in the .base files contain a previous and next item UID, so you should be able to path through from point a to point b using those. As for prefabs with more than 2 nodes you might have to check the .ppd documentation for what values to use to get the path to an end node.

You could take a look at the code of either of these projects as they both have a navigation feature:

cerus commented 2 years ago

Thank you so much for pointing me in this direction! I was able to update edoaxyz's fork and get it running.

I'll close this issue for now. Again, thank you!

cerus commented 2 years ago

Update for anyone who might be stumbling on this in the future:

I've sent an email to SCS regarding the .navcache format and they said that the file is only used to cache company cargo and distance between companies, so that's not what I was looking for.

However they also told me that there's the cvar g_gps_debug_graph which can be enabled to print navigation data when the navigation graph is built.

Spoiler: Email
Hi Maximilian, the file you mentioned contains computed distances from companies which generate cargoes to companies which consume it which is probably not what you want. To get the data that game uses for its navigation set the g_gps_debug_graph cvar to 1 and the game will print the data used to build the graph into the game log with "[nav]" prefix (also don't forget to use -unlimitedlog startup parameter, so that game log won't be truncated and prepare for some huge log output). Best regards, 50keda
Spoiler: Log output snippet
00:00:37.138 : Route data generation started.
00:00:37.272 : [nav] mode 0 connection node 0x32F17060A1430000 at -35242.542969;50.292969;41868.785156 => node 0x33116DB407830000 at -35299.718750;46.718750;41947.554688 shared 0x32F170C407030001 flags 0 initial dist 97.512497
00:00:37.272 : [nav] heuristic driving time 82.343887 heuristic fastest time 74.109497
00:00:37.272 : [nav] result 686.199036 time_class 0000002a
00:00:37.272 : [nav] mode 0 connection node 0x32F17060A1430000 at -35242.542969;50.292969;41868.785156 => node 0x371989BC5C210000 at -35199.859375;53.964844;41788.414063 shared 0x371989BC06610001 flags 0 initial dist 91.140701
00:00:37.272 : [nav] heuristic driving time 76.963257 heuristic fastest time 69.266937
00:00:37.272 : [nav] result 641.360474 time_class 0000002a
00:00:37.272 : [nav] mode 0 uturn check node 0x32F17060A1430000 at -35242.542969;50.292969;41868.785156 => node 0x32F17060A1430000 at -35242.542969;50.292969;41868.785156 shared 0x0 flags 0
00:00:37.272 : [nav] uturn
00:00:37.272 : [nav] result 400000.000000 time_class 00000000
00:00:37.272 : [nav] mode 0 uturn check node 0x32F17060A1430000 at -35242.542969;50.292969;41868.785156 => node 0x32F17060A1430000 at -35242.542969;50.292969;41868.785156 shared 0x0 flags 0
00:00:37.272 : [nav] uturn
00:00:37.272 : [nav] result 400000.000000 time_class 00000000
00:00:37.272 : [nav] mode 0 connection node 0x32F170F033430000 at -35157.128906;55.835938;40943.937500 => node 0x331A7DF414030003 at -35161.281250;55.968750;40959.746094 shared 0x331A7DF47C830001 flags 0 initial dist 16.345373
00:00:37.272 : [nav] heuristic driving time 15.528105 heuristic fastest time 12.422484
00:00:37.272 : [nav] result 129.400879 time_class 000ff004
00:00:37.272 : [nav] mode 0 connection node 0x32F170F033430000 at -35157.128906;55.835938;40943.937500 => node 0x33458C2447030002 at -35158.089844;52.578125;40855.410156 shared 0x2C09FCB4A3460001 flags 0 initial dist 88.834396
00:00:37.272 : [nav] heuristic driving time 75.015709 heuristic fastest time 67.514137
00:00:37.272 : [nav] result 625.130981 time_class 00000004
  
dowmeister commented 2 years ago

Is nice they replied. out of curiosity, to which email you write to?

wonder how others g_*_debug exist :D

cerus commented 2 years ago

Is nice they replied. out of curiosity, to which email you write to?

I wrote to contribution@scssoft.com which is meant for modding wiki contribution requests and not for modding questions, but it was the only email address I could find :D

meatlayer commented 2 years ago

Thank you so much for pointing me in this direction! I was able to update edoaxyz's fork and get it running.

I'll close this issue for now. Again, thank you!

Do you plan to publish a your fork? It would be interesting to see a working version.

cerus commented 2 years ago

Thank you so much for pointing me in this direction! I was able to update edoaxyz's fork and get it running. I'll close this issue for now. Again, thank you!

Do you plan to publish a your fork? It would be interesting to see a working version.

It's very messy, but I can create a repository for it later today. :)

cerus commented 2 years ago

I've published the fork: https://github.com/Spedcord/ts-map

As I said it's very messy and not user friendly. It's also not perfect. Feel free to modify.

cc @meatlayer