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"); } } }