diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 3b3df7c..491cad3 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -5,11 +5,11 @@ using System.Runtime.InteropServices; // Les informations générales relatives à un assembly dépendent de // l'ensemble d'attributs suivant. Changez les valeurs de ces attributs pour modifier les informations // associées à un assembly. -[assembly: AssemblyTitle("rFactor 2 Message Center")] -[assembly: AssemblyDescription("Read Access to the rFactor 2 Message Center")] +[assembly: AssemblyTitle("rFactor 2 MiscData")] +[assembly: AssemblyDescription("Read Access to miscellaneous rFactor 2 Data")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Kilian Kurt Hofmann")] -[assembly: AssemblyProduct("rFactor 2 Message Center")] +[assembly: AssemblyProduct("rFactor 2 MiscData")] [assembly: AssemblyCopyright("Copyright © 2022")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs index cf40a56..41a9067 100644 --- a/Properties/Resources.Designer.cs +++ b/Properties/Resources.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace rFactor2MessageCenter.Properties { +namespace rFactor2MiscData.Properties { using System; @@ -39,7 +39,7 @@ namespace rFactor2MessageCenter.Properties { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("rFactor2MessageCenter.Properties.Resources", typeof(Resources).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("rFactor2MiscData.Properties.Resources", typeof(Resources).Assembly); resourceMan = temp; } return resourceMan; diff --git a/rFactor 2 Message Center.csproj b/rFactor 2 Misc Data.csproj similarity index 96% rename from rFactor 2 Message Center.csproj rename to rFactor 2 Misc Data.csproj index b4d196b..3051123 100644 --- a/rFactor 2 Message Center.csproj +++ b/rFactor 2 Misc Data.csproj @@ -7,8 +7,8 @@ {833040C9-FE5E-4CCF-B21D-71979E049B6B} Library Properties - rFactor2MessageCenter - rFactor2 Message Center + rFactor2MiscData + rFactor2 Misc Data v4.8 512 @@ -78,7 +78,7 @@ - + True diff --git a/rFactor 2 Message Center.sln b/rFactor 2 MiscData.sln similarity index 91% rename from rFactor 2 Message Center.sln rename to rFactor 2 MiscData.sln index 21c8352..09140cc 100644 --- a/rFactor 2 Message Center.sln +++ b/rFactor 2 MiscData.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.4.33103.184 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "rFactor 2 Message Center", "rFactor 2 Message Center.csproj", "{833040C9-FE5E-4CCF-B21D-71979E049B6B}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "rFactor 2 Misc Data", "rFactor 2 Misc Data.csproj", "{833040C9-FE5E-4CCF-B21D-71979E049B6B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/rFactor2MessageCenter.cs b/rFactor2MessageCenter.cs deleted file mode 100644 index 04548a2..0000000 --- a/rFactor2MessageCenter.cs +++ /dev/null @@ -1,73 +0,0 @@ -using GameReaderCommon; -using RfactorReader.RF2; -using SimHub.Plugins; - -namespace rFactor2MessageCenter -{ - [PluginDescription("Read Access to the rFactor 2 Message Center")] - [PluginAuthor("Kilian Kurt Hofmann")] - [PluginName("rFactor 2 Message Center")] - public class rFactor2MessageCenter : IPlugin, IDataPlugin - { - private const string LAST_MESSAGE = "LastMessage"; - - /// - /// Instance of the current plugin manager - /// - public PluginManager PluginManager { get; set; } - - /// - /// Gets a short plugin title to show in left menu. Return null if you want to use the title as defined in PluginName attribute. - /// - public string LeftMenuTitle => null; - - /// - /// Called one time per game data update, contains all normalized game data, - /// raw data are intentionnally "hidden" under a generic object type (A plugin SHOULD NOT USE IT) - /// - /// This method is on the critical path, it must execute as fast as possible and avoid throwing any error - /// - /// - /// - /// Current game data, including current and previous data frame. - public void DataUpdate(PluginManager pluginManager, ref GameData data) - { - // Define the value of our property (declared in init) - if (data.GameRunning && data is GameData _data) - { - StatusData newData = _data.GameNewData; - string message = System.Text.Encoding.Default.GetString(newData.Raw.extended.mLastHistoryMessage); - int index = message.IndexOf('\0'); - if( index >= 0) - { - message = message.Remove(index); - } - pluginManager.SetPropertyValue(LAST_MESSAGE, GetType(), message); - } - } - - /// - /// Called at plugin manager stop, close/dispose anything needed here ! - /// Plugins are rebuilt at game change - /// - /// - public void End(PluginManager pluginManager) - { - SimHub.Logging.Current.Info("Stopping plugin"); - - pluginManager.ClearProperties(GetType()); - } - - /// - /// Called once after plugins startup - /// Plugins are rebuilt at game change - /// - /// - public void Init(PluginManager pluginManager) - { - SimHub.Logging.Current.Info("Starting plugin"); - - pluginManager.AddProperty(LAST_MESSAGE, GetType(), "No Data", "Last Message Center Entry"); - } - } -} \ No newline at end of file diff --git a/rFactor2MiscData.cs b/rFactor2MiscData.cs new file mode 100644 index 0000000..a7bbf48 --- /dev/null +++ b/rFactor2MiscData.cs @@ -0,0 +1,114 @@ +using CrewChiefV4.rFactor2_V2.rFactor2Data; +using GameReaderCommon; +using RfactorReader.RF2; +using SimHub.Plugins; +using System; + +namespace rFactor2MiscData +{ + [PluginDescription("Read Access to miscellaneous rFactor 2 Data")] + [PluginAuthor("Kilian Kurt Hofmann")] + [PluginName("rFactor 2 Misc Data")] + public class rFactor2MiscData : IPlugin, IDataPlugin + { + private const string LAST_MESSAGE = "rF2MiscData.LastMessage"; + private const string VEHICLE_BASE = "rF2MiscData.Position"; + private const string VEHICLE_FUEL = ".Fuel"; + private const string VEHICLE_THROTTLE= ".Throttle"; + private const string VEHICLE_BRAKE = ".Brake"; + private const string VEHICLE_PLACE = ".Place"; + private const string VEHICLE_DRIVERNAME = ".DriverName"; + + /// + /// Instance of the current plugin manager + /// + public PluginManager PluginManager { get; set; } + + /// + /// Gets a short plugin title to show in left menu. Return null if you want to use the title as defined in PluginName attribute. + /// + public string LeftMenuTitle => null; + + /// + /// Called one time per game data update, contains all normalized game data, + /// raw data are intentionnally "hidden" under a generic object type (A plugin SHOULD NOT USE IT) + /// + /// This method is on the critical path, it must execute as fast as possible and avoid throwing any error + /// + /// + /// + /// Current game data, including current and previous data frame. + public void DataUpdate(PluginManager pluginManager, ref GameData data) + { + // Define the value of our property (declared in init) + if (data.GameRunning && data is GameData _data) + { + WrapV2 newData = _data.GameNewData.Raw; + + // Last Message + string message = System.Text.Encoding.Default.GetString(newData.extended.mLastHistoryMessage); + int index = message.IndexOf('\0'); + if( index >= 0) + { + message = message.Remove(index); + } + pluginManager.SetPropertyValue(LAST_MESSAGE, GetType(), message); + + int maxVehicles = Math.Min(newData.Scoring.mVehicles.Length, newData.telemetry.mVehicles.Length); + for(int i = 0; i < maxVehicles; i++) + { + rF2VehicleTelemetry telemetry = newData.telemetry.mVehicles[i]; + rF2VehicleScoring scoring = newData.Scoring.mVehicles[i]; + // Vehicle Fuel + pluginManager.SetPropertyValue($"{VEHICLE_BASE}{scoring.mPlace:000}{VEHICLE_FUEL}", GetType(), telemetry.mFuel); + // Vehicle Throttle + pluginManager.SetPropertyValue($"{VEHICLE_BASE}{scoring.mPlace:000}{VEHICLE_THROTTLE}", GetType(), telemetry.mFilteredThrottle); + // Vehicle Brake + pluginManager.SetPropertyValue($"{VEHICLE_BASE}{scoring.mPlace:000}{VEHICLE_BRAKE}", GetType(), telemetry.mFilteredBrake); + // Vehicle Position + pluginManager.SetPropertyValue($"{VEHICLE_BASE}{scoring.mPlace:000}{VEHICLE_PLACE}", GetType(), scoring.mPlace); + // Vehicle Driver Name + string driverName = System.Text.Encoding.Default.GetString(scoring.mDriverName); + index = message.IndexOf('\0'); + if (index >= 0) + { + message = message.Remove(index); + } + pluginManager.SetPropertyValue($"{VEHICLE_BASE}{scoring.mPlace:000}{VEHICLE_DRIVERNAME}", GetType(), driverName); + } + } + } + + /// + /// Called at plugin manager stop, close/dispose anything needed here ! + /// Plugins are rebuilt at game change + /// + /// + public void End(PluginManager pluginManager) + { + SimHub.Logging.Current.Info("Stopping plugin"); + + pluginManager.ClearProperties(GetType()); + } + + /// + /// Called once after plugins startup + /// Plugins are rebuilt at game change + /// + /// + public void Init(PluginManager pluginManager) + { + SimHub.Logging.Current.Info("Starting plugin"); + + pluginManager.AddProperty(LAST_MESSAGE, GetType(), "No Data", "Last Message Center Entry"); + for (int i = 1; i <= 104; i++) + { + pluginManager.AddProperty($"{VEHICLE_BASE}{i:000}{VEHICLE_FUEL}", GetType(), "No Data", $"Vehicle at position {i}: Fuel"); + pluginManager.AddProperty($"{VEHICLE_BASE}{i:000}{VEHICLE_THROTTLE}", GetType(), "No Data", $"Vehicle at position {i}: Throttle"); + pluginManager.AddProperty($"{VEHICLE_BASE}{i:000}{VEHICLE_BRAKE}", GetType(), "No Data", $"Vehicle at position {i}: Brake"); + pluginManager.AddProperty($"{VEHICLE_BASE}{i:000}{VEHICLE_PLACE}", GetType(), "No Data", $"Vehicle at position {i}: Place"); + pluginManager.AddProperty($"{VEHICLE_BASE}{i:000}{VEHICLE_DRIVERNAME}", GetType(), "No Data", $"Vehicle at position {i}: Driver Name"); + } + } + } +} \ No newline at end of file