Hey, looking at the SM structure I can't see info about what car and track is used. Is this information available somehow? If not as a text, then maybe as a code to a lookup table? Thanks.
Hi Tom, In SM we get Track and Car Ids. Sector 3 provides a JSON object with all the data and one has to look it up. I have uploaded an example of how these can be used in this thread. Hope you find it helpful. https://forum.sector3studios.com/index.php?threads/shared-memory-api.1525/page-11#post-37629 Note: I have changed the JSON object to be more friendly but you might want to use Sector 3 original JSON file
Stefan, thanks for the reply, the code is a big help. By the quick look at your code, am I right the JSON object is generated on the disk, not in the memory?
That's correct. It's a JSON file supplied and maintained by Sector 3. https://github.com/sector3studios/r3e-spectator-overlay/blob/master/r3e-data.json You can always put this in a database if you wish but that needs some work and it also gets updated by them with new cars/tracks. What I actually do for my apps, I load the file from the disk and then keep it in memory for speed Cheers Stefan
Ahh, thanks for explanation. I originally thought the file is generated for each session and populated with some static info about it. But it is indeed a lookup table for IDs provided by SM. Makes sense.
Hi Robert, Is it possible to add some information about the session type? We want to know whether it is a Leaderboard run, a offline practice session or a mp race. And if it is a mp session the name of the ds is also very interesting for us. Regards, Gil
Hi Stefan, Thanks for sharing your code R3ESharedMemoryApiExample. I have translated it to VB Net and it seems to work except for the DriverData. I am getting an error when I run the code. Type must be a struct containing no references The error comes from these lines Contains name and vehicle info for all drivers in place order MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst:=128) Public AllDriversData() AsDriverData Do you know how I can correct this? When I run your code remaining time and track name are correct, but the driver name shows some ÿ and place shows 4957 in practice mode and 4960 in race mode. Thank you in advance Henrik
Hi Henrik I do not know VB (last I touched it was VB6 in 2000!) but make sure that the DriverData object is as array as shown below // Contains name and vehicle info for all drivers in place order [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 128)] public DriverData[] AllDriversData; As for the driver name, I did not encode it but you need to encode it, something like this in C# System.Text.Encoding.UTF8.GetString(driver.DriverInfo.Name).Replace("/0", "") Regards Stefan
Hi Stefan, Thank you for your answer. I got it now. Must have made a mistake somewhere. I will try to encode the driver name with the code you supplied. Can you show how to get the name of the car please? Regards, Henrik
Hi Henrik, In my example, in class R3ESharedMemoryApiExample.Tools.RaceroomData, you can add methods similar to these: public Car GetCarData(int Id) { var defaultCar = new Car() { Name = string.Empty }; if (Id <= 0) return defaultCar; var carData = _gameData.Cars.Where(c => c.Id == Id).FirstOrDefault(); return _gameData != null ? carData ?? defaultCar : defaultCar; } public Class GetCarClass(int Id) { var defaultClass = new Class() { Name = string.Empty }; if (Id <= 0) return defaultClass; var classData = _gameData.Classes.Where(c => c.Id == Id).FirstOrDefault(); return _gameData != null ? classData ?? defaultClass : defaultClass; } public Manufacturer GetCarManufacturer(int Id) { var defaultCarManufacturer = new Manufacturer() { Name = string.Empty }; if (Id <= 0) return defaultCarManufacturer; var carData =_gameData.Manufacturers.Where(c => c.Id == Id).FirstOrDefault(); return _gameData != null ? carData ?? defaultCarManufacturer : defaultCarManufacturer; } public Track GetTrackData(int Id) { var defaultTrack = new Track() { Name = string.Empty, Layouts = new Layout[] { } }; if (Id <= 0) return defaultTrack; var trackData = _gameData.Tracks.Where(t => t.Id == Id).FirstOrDefault(); return _gameData != null ? trackData ?? defaultTrack : defaultTrack; } public Team GeTeamData(int Id) { var defaultTeam = new Team() { Name = string.Empty }; if (Id <= 0) return defaultTeam; var teamData = _gameData.Teams.Where(t => t.Id == Id).FirstOrDefault(); return _gameData != null ? teamData ?? defaultTeam : defaultTeam; } Code is just for illustration so just make you checks for a null returned object. Then you can call them: //get driver by slotId or my driver name if you wish var driver = data.AllDriversData.Where(d => d.DriverInfo.SlotId == slotId).FirstOrDefault(); var driverInfo = driver.DriverInfo; var driverName = System.Text.Encoding.UTF8.GetString(driverInfo.Name).TrimEnd('\0'); var vehicleName = raceroomData.GeTeamData(driverInfo.TeamId).Name; var vehicleClass = raceroomData.GetCarClass(driverInfo.ClassId).Name; var vehicleManufacture = raceroomData.GetCarManufacturer(driverInfo.ManufacturerId).Name;
Hi Stefan, Thank you very much. I can’t wait to try it out. As far as I have understood from your posts the JSON file is maintained by Sector 3. The update from December 2015 looks different than the one in your example. Do you have an easy way to change the JSON object to meet the syntax of your friendly version or do you do it manually? /Henrik
Hi Henrik, My solution is using a converted version of Sector3 JSON file which is quite a bad idea as I need to update it manually whenever they change it. I suggest to try to use their version or maybe they have some API, not sure, need to investigate. Cheers Stefan
helo guys I need a help, I see em C++ have information TRACK_INFO, have track_id, layout e etc... But I don't find this properties in C#, I tried not git hub More not found, I inserted the properiedade in C # more returning this value 0 if they can update the C # file with these informations would be very grateful. and I wonder if there is how to return the server name of the pilot is racing ...
Hi Stefan, Thank you for your answer. You are right about converting the JSON object. It must be done automatically or another solution must be found since the JSON file is too big to just do it manually. I have never touched the JSON subject before and don’t know anything about the Newtonsoft. Since it can’t be read correctly is that because of the structure? If you find a better way to read the JSON file would you let me know please? Thank you again, Henrik
Phyllip - crew chief v4 uses c# and is open source on github. You're welcome to borrow bits of the code if you want. Server name isn't available, would be nice to have tho
Thanks for help!! its Works! but I need a litle help again, I need return car information of current driver but return result = 0 I use this in R3E public struct DriverInfo { [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] public Byte[] Name; public Int32 CarNumber; public Int32 ClassId; public Int32 ModelId; public Int32 TeamId; public Int32 LiveryId; public Int32 ManufacturerId; public Int32 SlotId; public Int32 ClassPerformanceIndex; }
Sir, so I got curious and checked your code. Are you creating the car data classes manually yourself? I could not find any references to S3 json data file or any data related to it...