From 3873c685180d0ecbb0a06ff24ac6f8b823ecd598 Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Sat, 27 Aug 2016 13:00:57 +0200 Subject: [PATCH] 1.3.1.0 Added K65 LUX RGB support Added K65 RGB RAPIDFIRE support Replaced ETS2 telemetry reader with a better one Fixed ETS2 plugin placement Cleaned up plugin-placing code on several modules --- Artemis/Artemis/Artemis.csproj | 11 +- .../Corsair/CorsairKeyboards.cs | 2 + .../Data/Ets2TelemetryData.cs | 367 +++++++++ .../Data/Ets2TelemetryDataReader.cs | 44 + .../Data/IEts2TelemetryData.cs | 763 ++++++++++++++++++ .../Data/Reader/Ets2TelemetryStructure.cs | 214 +++++ .../Data/Reader/SharedProcessMemory.cs | 84 ++ .../EurotruckSimulator2DataModel.cs | 16 +- .../EurotruckSimulator2Model.cs | 34 +- .../EurotruckSimulator2View.xaml | 35 +- .../EurotruckSimulator2View.xaml.cs | 6 + .../EurotruckSimulator2ViewModel.cs | 66 +- .../Resources/Win32/ets2-telemetry-server.dll | Bin 0 -> 79872 bytes .../Resources/Win64/ets2-telemetry-server.dll | Bin 0 -> 93696 bytes .../UnrealTournamentViewModel.cs | 6 +- .../Games/Witcher3/Witcher3ViewModel.cs | 6 +- Artemis/Artemis/Properties/AssemblyInfo.cs | 4 +- .../Artemis/Properties/Resources.Designer.cs | 20 + Artemis/Artemis/Properties/Resources.resx | 6 + Artemis/Artemis/Utilities/GeneralHelpers.cs | 2 +- Artemis/Artemis/Utilities/Updater.cs | 4 +- Artemis/Artemis/Views/WelcomeView.xaml.cs | 3 +- 22 files changed, 1609 insertions(+), 84 deletions(-) create mode 100644 Artemis/Artemis/Modules/Games/EurotruckSimulator2/Data/Ets2TelemetryData.cs create mode 100644 Artemis/Artemis/Modules/Games/EurotruckSimulator2/Data/Ets2TelemetryDataReader.cs create mode 100644 Artemis/Artemis/Modules/Games/EurotruckSimulator2/Data/IEts2TelemetryData.cs create mode 100644 Artemis/Artemis/Modules/Games/EurotruckSimulator2/Data/Reader/Ets2TelemetryStructure.cs create mode 100644 Artemis/Artemis/Modules/Games/EurotruckSimulator2/Data/Reader/SharedProcessMemory.cs create mode 100644 Artemis/Artemis/Modules/Games/EurotruckSimulator2/Resources/Win32/ets2-telemetry-server.dll create mode 100644 Artemis/Artemis/Modules/Games/EurotruckSimulator2/Resources/Win64/ets2-telemetry-server.dll diff --git a/Artemis/Artemis/Artemis.csproj b/Artemis/Artemis/Artemis.csproj index 428dacda1..09fb424d3 100644 --- a/Artemis/Artemis/Artemis.csproj +++ b/Artemis/Artemis/Artemis.csproj @@ -171,10 +171,6 @@ ..\packages\DynamicExpresso.Core.1.3.1.0\lib\net40\DynamicExpresso.Core.dll True - - False - lib\Ets2SdkClient.dll - ..\packages\gong-wpf-dragdrop.0.1.4.3\lib\net40\GongSolutions.Wpf.DragDrop.dll True @@ -370,6 +366,11 @@ + + + + + @@ -838,6 +839,8 @@ PreserveNewest + + diff --git a/Artemis/Artemis/DeviceProviders/Corsair/CorsairKeyboards.cs b/Artemis/Artemis/DeviceProviders/Corsair/CorsairKeyboards.cs index a77d286b7..49997f09b 100644 --- a/Artemis/Artemis/DeviceProviders/Corsair/CorsairKeyboards.cs +++ b/Artemis/Artemis/DeviceProviders/Corsair/CorsairKeyboards.cs @@ -65,6 +65,8 @@ namespace Artemis.DeviceProviders.Corsair break; case "K65 RGB": case "CGK65 RGB": + case "K65 LUX RGB": + case "K65 RGB RAPIDFIRE": Height = 7; Width = 18; Slug = "corsair-k65-rgb"; diff --git a/Artemis/Artemis/Modules/Games/EurotruckSimulator2/Data/Ets2TelemetryData.cs b/Artemis/Artemis/Modules/Games/EurotruckSimulator2/Data/Ets2TelemetryData.cs new file mode 100644 index 000000000..a98f267cd --- /dev/null +++ b/Artemis/Artemis/Modules/Games/EurotruckSimulator2/Data/Ets2TelemetryData.cs @@ -0,0 +1,367 @@ +using System; +using System.Text; +using Artemis.Modules.Games.EurotruckSimulator2.Data.Reader; + +namespace Artemis.Modules.Games.EurotruckSimulator2.Data +{ + internal class Ets2TelemetryData : IEts2TelemetryData + { + private Box _rawData; + + public IEts2Game Game => new Ets2Game(_rawData); + public IEts2Truck Truck => new Ets2Truck(_rawData); + public IEts2Trailer Trailer => new Ets2Trailer(_rawData); + public IEts2Job Job => new Ets2Job(_rawData); + public IEts2Navigation Navigation => new Ets2Navigation(_rawData); + + public void Update(Ets2TelemetryStructure rawData) + { + _rawData = new Box(rawData); + } + + internal static DateTime SecondsToDate(int seconds) + { + if (seconds < 0) seconds = 0; + return new DateTime((long) seconds*10000000, DateTimeKind.Utc); + } + + internal static DateTime MinutesToDate(int minutes) + { + return SecondsToDate(minutes*60); + } + + internal static string BytesToString(byte[] bytes) + { + if (bytes == null) + return string.Empty; + return Encoding.UTF8.GetString(bytes, 0, Array.FindIndex(bytes, b => b == 0)); + } + } + + internal class Ets2Game : IEts2Game + { + private readonly Box _rawData; + + public Ets2Game(Box rawData) + { + _rawData = rawData; + } + + public bool Paused => _rawData.Struct.paused != 0; + public DateTime Time => Ets2TelemetryData.MinutesToDate(_rawData.Struct.timeAbsolute); + public float TimeScale => _rawData.Struct.localScale; + public DateTime NextRestStopTime => Ets2TelemetryData.MinutesToDate(_rawData.Struct.nextRestStop); + public string Version => $"{_rawData.Struct.ets2_version_major}.{_rawData.Struct.ets2_version_minor}"; + public string TelemetryPluginVersion => _rawData.Struct.ets2_telemetry_plugin_revision.ToString(); + } + + internal class Ets2Vector : IEts2Vector + { + public Ets2Vector(float x, float y, float z) + { + X = x; + Y = y; + Z = z; + } + + public float X { get; } + public float Y { get; } + public float Z { get; } + } + + internal class Ets2Placement : IEts2Placement + { + public Ets2Placement(float x, float y, float z, + float heading, float pitch, float roll) + { + X = x; + Y = y; + Z = z; + Heading = heading; + Pitch = pitch; + Roll = roll; + } + + public float X { get; } + public float Y { get; } + public float Z { get; } + public float Heading { get; } + public float Pitch { get; } + public float Roll { get; } + } + + internal class Ets2Truck : IEts2Truck + { + private readonly Box _rawData; + + public Ets2Truck(Box rawData) + { + _rawData = rawData; + } + + public string Id => Ets2TelemetryData.BytesToString(_rawData.Struct.truckMakeId); + public string Make => Ets2TelemetryData.BytesToString(_rawData.Struct.truckMake); + public string Model => Ets2TelemetryData.BytesToString(_rawData.Struct.truckModel); + + /// + /// Truck speed in km/h. + /// + public float Speed => _rawData.Struct.speed*3.6f; + + /// + /// Cruise control speed in km/h. + /// + public float CruiseControlSpeed => _rawData.Struct.cruiseControlSpeed*3.6f; + + public bool CruiseControlOn => _rawData.Struct.cruiseControl != 0; + public float Odometer => _rawData.Struct.truckOdometer; + public int Gear => _rawData.Struct.gear; + public int DisplayedGear => _rawData.Struct.displayedGear; + public int ForwardGears => _rawData.Struct.gearsForward; + public int ReverseGears => _rawData.Struct.gearsReverse; + public string ShifterType => Ets2TelemetryData.BytesToString(_rawData.Struct.shifterType); + public float EngineRpm => _rawData.Struct.engineRpm; + public float EngineRpmMax => _rawData.Struct.engineRpmMax; + public float Fuel => _rawData.Struct.fuel; + public float FuelCapacity => _rawData.Struct.fuelCapacity; + public float FuelAverageConsumption => _rawData.Struct.fuelAvgConsumption; + public float FuelWarningFactor => _rawData.Struct.fuelWarningFactor; + public bool FuelWarningOn => _rawData.Struct.fuelWarning != 0; + public float WearEngine => _rawData.Struct.wearEngine; + public float WearTransmission => _rawData.Struct.wearTransmission; + public float WearCabin => _rawData.Struct.wearCabin; + public float WearChassis => _rawData.Struct.wearChassis; + public float WearWheels => _rawData.Struct.wearWheels; + public float UserSteer => _rawData.Struct.userSteer; + public float UserThrottle => _rawData.Struct.userThrottle; + public float UserBrake => _rawData.Struct.userBrake; + public float UserClutch => _rawData.Struct.userClutch; + public float GameSteer => _rawData.Struct.gameSteer; + public float GameThrottle => _rawData.Struct.gameThrottle; + public float GameBrake => _rawData.Struct.gameBrake; + public float GameClutch => _rawData.Struct.gameClutch; + public int ShifterSlot => _rawData.Struct.shifterSlot; + + //public int ShifterToggle + //{ + // get { return _rawData.Struct.shifterToggle; } + //} + + public bool EngineOn => _rawData.Struct.engineEnabled != 0; + public bool ElectricOn => _rawData.Struct.electricEnabled != 0; + public bool WipersOn => _rawData.Struct.wipers != 0; + public int RetarderBrake => _rawData.Struct.retarderBrake; + public int RetarderStepCount => (int) _rawData.Struct.retarderStepCount; + public bool ParkBrakeOn => _rawData.Struct.parkBrake != 0; + public bool MotorBrakeOn => _rawData.Struct.motorBrake != 0; + public float BrakeTemperature => _rawData.Struct.brakeTemperature; + public float Adblue => _rawData.Struct.adblue; + public float AdblueCapacity => _rawData.Struct.adblueCapacity; + public float AdblueAverageConsumption => _rawData.Struct.adblueConsumption; + public bool AdblueWarningOn => _rawData.Struct.adblueWarning != 0; + public float AirPressure => _rawData.Struct.airPressure; + public bool AirPressureWarningOn => _rawData.Struct.airPressureWarning != 0; + public float AirPressureWarningValue => _rawData.Struct.airPressureWarningValue; + public bool AirPressureEmergencyOn => _rawData.Struct.airPressureEmergency != 0; + public float AirPressureEmergencyValue => _rawData.Struct.airPressureEmergencyValue; + public float OilTemperature => _rawData.Struct.oilTemperature; + public float OilPressure => _rawData.Struct.oilPressure; + public bool OilPressureWarningOn => _rawData.Struct.oilPressureWarning != 0; + public float OilPressureWarningValue => _rawData.Struct.oilPressureWarningValue; + public float WaterTemperature => _rawData.Struct.waterTemperature; + public bool WaterTemperatureWarningOn => _rawData.Struct.waterTemperatureWarning != 0; + public float WaterTemperatureWarningValue => _rawData.Struct.waterTemperatureWarningValue; + public float BatteryVoltage => _rawData.Struct.batteryVoltage; + public bool BatteryVoltageWarningOn => _rawData.Struct.batteryVoltageWarning != 0; + public float BatteryVoltageWarningValue => _rawData.Struct.batteryVoltageWarningValue; + public float LightsDashboardValue => _rawData.Struct.lightsDashboard; + public bool LightsDashboardOn => _rawData.Struct.lightsDashboard > 0; + public bool BlinkerLeftActive => _rawData.Struct.blinkerLeftActive != 0; + public bool BlinkerRightActive => _rawData.Struct.blinkerRightActive != 0; + public bool BlinkerLeftOn => _rawData.Struct.blinkerLeftOn != 0; + public bool BlinkerRightOn => _rawData.Struct.blinkerRightOn != 0; + public bool LightsParkingOn => _rawData.Struct.lightsParking != 0; + public bool LightsBeamLowOn => _rawData.Struct.lightsBeamLow != 0; + public bool LightsBeamHighOn => _rawData.Struct.lightsBeamHigh != 0; + public bool LightsAuxFrontOn => _rawData.Struct.lightsAuxFront != 0; + public bool LightsAuxRoofOn => _rawData.Struct.lightsAuxRoof != 0; + public bool LightsBeaconOn => _rawData.Struct.lightsBeacon != 0; + public bool LightsBrakeOn => _rawData.Struct.lightsBrake != 0; + public bool LightsReverseOn => _rawData.Struct.lightsReverse != 0; + + public IEts2Placement Placement => new Ets2Placement( + _rawData.Struct.coordinateX, + _rawData.Struct.coordinateY, + _rawData.Struct.coordinateZ, + _rawData.Struct.rotationX, + _rawData.Struct.rotationY, + _rawData.Struct.rotationZ); + + public IEts2Vector Acceleration => new Ets2Vector( + _rawData.Struct.accelerationX, + _rawData.Struct.accelerationY, + _rawData.Struct.accelerationZ); + + public IEts2Vector Head => new Ets2Vector( + _rawData.Struct.headPositionX, + _rawData.Struct.headPositionY, + _rawData.Struct.headPositionZ); + + public IEts2Vector Cabin => new Ets2Vector( + _rawData.Struct.cabinPositionX, + _rawData.Struct.cabinPositionY, + _rawData.Struct.cabinPositionZ); + + public IEts2Vector Hook => new Ets2Vector( + _rawData.Struct.hookPositionX, + _rawData.Struct.hookPositionY, + _rawData.Struct.hookPositionZ); + + /* + public IEts2GearSlot[] GearSlots + { + get + { + var array = new IEts2GearSlot[_rawData.Struct.selectorCount]; + for (int i = 0; i < array.Length; i++) + array[i] = new Ets2GearSlot(_rawData, i); + return array; + } + } + + public IEts2Wheel[] Wheels + { + get + { + var array = new IEts2Wheel[_rawData.Struct.wheelCount]; + for (int i = 0; i < array.Length; i++) + array[i] = new Ets2Wheel(_rawData, i); + return array; + } + } + */ + } + + internal class Ets2Trailer : IEts2Trailer + { + private readonly Box _rawData; + + public Ets2Trailer(Box rawData) + { + _rawData = rawData; + } + + public bool Attached => _rawData.Struct.trailer_attached != 0; + public string Id => Ets2TelemetryData.BytesToString(_rawData.Struct.trailerId); + public string Name => Ets2TelemetryData.BytesToString(_rawData.Struct.trailerName); + + /// + /// Trailer mass in kilograms. + /// + public float Mass => _rawData.Struct.trailerMass; + + public float Wear => _rawData.Struct.wearTrailer; + + public IEts2Placement Placement => new Ets2Placement( + _rawData.Struct.trailerCoordinateX, + _rawData.Struct.trailerCoordinateY, + _rawData.Struct.trailerCoordinateZ, + _rawData.Struct.trailerRotationX, + _rawData.Struct.trailerRotationY, + _rawData.Struct.trailerRotationZ); + } + + internal class Ets2Navigation : IEts2Navigation + { + private readonly Box _rawData; + + public Ets2Navigation(Box rawData) + { + _rawData = rawData; + } + + public DateTime EstimatedTime => Ets2TelemetryData.SecondsToDate((int) _rawData.Struct.navigationTime); + public int EstimatedDistance => (int) _rawData.Struct.navigationDistance; + + public int SpeedLimit + => + _rawData.Struct.navigationSpeedLimit > 0 ? (int) Math.Round(_rawData.Struct.navigationSpeedLimit*3.6f) : 0; + } + + internal class Ets2Job : IEts2Job + { + private readonly Box _rawData; + + public Ets2Job(Box rawData) + { + _rawData = rawData; + } + + public int Income => _rawData.Struct.jobIncome; + public DateTime DeadlineTime => Ets2TelemetryData.MinutesToDate(_rawData.Struct.jobDeadline); + + public DateTime RemainingTime + { + get + { + if (_rawData.Struct.jobDeadline > 0) + return Ets2TelemetryData.MinutesToDate(_rawData.Struct.jobDeadline - _rawData.Struct.timeAbsolute); + return Ets2TelemetryData.MinutesToDate(0); + } + } + + public string SourceCity => Ets2TelemetryData.BytesToString(_rawData.Struct.jobCitySource); + public string SourceCompany => Ets2TelemetryData.BytesToString(_rawData.Struct.jobCompanySource); + public string DestinationCity => Ets2TelemetryData.BytesToString(_rawData.Struct.jobCityDestination); + public string DestinationCompany => Ets2TelemetryData.BytesToString(_rawData.Struct.jobCompanyDestination); + } + + /* + class Ets2Wheel : IEts2Wheel + { + public Ets2Wheel(Box rawData, int wheelIndex) + { + Simulated = rawData.Struct.wheelSimulated[wheelIndex] != 0; + Steerable = rawData.Struct.wheelSteerable[wheelIndex] != 0; + Radius = rawData.Struct.wheelRadius[wheelIndex]; + Position = new Ets2Vector( + rawData.Struct.wheelPositionX[wheelIndex], + rawData.Struct.wheelPositionY[wheelIndex], + rawData.Struct.wheelPositionZ[wheelIndex]); + Powered = rawData.Struct.wheelPowered[wheelIndex] != 0; + Liftable = rawData.Struct.wheelLiftable[wheelIndex] != 0; + } + + public bool Simulated { get; private set; } + public bool Steerable { get; private set; } + public bool Powered { get; private set; } + public bool Liftable { get; private set; } + public float Radius { get; private set; } + public IEts2Vector Position { get; private set; } + } + + class Ets2GearSlot : IEts2GearSlot + { + public Ets2GearSlot(Box rawData, int slotIndex) + { + Gear = rawData.Struct.slotGear[slotIndex]; + HandlePosition = (int)rawData.Struct.slotHandlePosition[slotIndex]; + SlotSelectors = (int)rawData.Struct.slotSelectors[slotIndex]; + } + + public int Gear { get; private set; } + public int HandlePosition { get; private set; } + public int SlotSelectors { get; private set; } + } + */ + + internal class Box where T : struct + { + public Box(T @struct) + { + Struct = @struct; + } + + public T Struct { get; set; } + } +} \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Games/EurotruckSimulator2/Data/Ets2TelemetryDataReader.cs b/Artemis/Artemis/Modules/Games/EurotruckSimulator2/Data/Ets2TelemetryDataReader.cs new file mode 100644 index 000000000..5b9172318 --- /dev/null +++ b/Artemis/Artemis/Modules/Games/EurotruckSimulator2/Data/Ets2TelemetryDataReader.cs @@ -0,0 +1,44 @@ +using System; +using Artemis.Modules.Games.EurotruckSimulator2.Data.Reader; + +namespace Artemis.Modules.Games.EurotruckSimulator2.Data +{ + public class Ets2TelemetryDataReader : IDisposable + { + /// + /// ETS2 telemetry plugin maps the data to this mapped file name. + /// + private const string Ets2TelemetryMappedFileName = "Local\\Ets2TelemetryServer"; + + // ReSharper disable once InconsistentNaming + private static readonly Lazy instance = new Lazy( + () => new Ets2TelemetryDataReader()); + + private readonly Ets2TelemetryData _data = new Ets2TelemetryData(); + + private readonly object _lock = new object(); + + private readonly SharedProcessMemory _sharedMemory = + new SharedProcessMemory(Ets2TelemetryMappedFileName); + + public static Ets2TelemetryDataReader Instance => instance.Value; + + public bool IsConnected => _sharedMemory.IsConnected; + + public void Dispose() + { + _sharedMemory?.Dispose(); + } + + public IEts2TelemetryData Read() + { + lock (_lock) + { + _sharedMemory.Data = default(Ets2TelemetryStructure); + _sharedMemory.Read(); + _data.Update(_sharedMemory.Data); + return _data; + } + } + } +} \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Games/EurotruckSimulator2/Data/IEts2TelemetryData.cs b/Artemis/Artemis/Modules/Games/EurotruckSimulator2/Data/IEts2TelemetryData.cs new file mode 100644 index 000000000..a64d40b7e --- /dev/null +++ b/Artemis/Artemis/Modules/Games/EurotruckSimulator2/Data/IEts2TelemetryData.cs @@ -0,0 +1,763 @@ +using System; + +namespace Artemis.Modules.Games.EurotruckSimulator2.Data +{ + public interface IEts2TelemetryData + { + /// + /// Game information. + /// + IEts2Game Game { get; } + + /// + /// Truck information. + /// + IEts2Truck Truck { get; } + + /// + /// Trailer information. + /// + IEts2Trailer Trailer { get; } + + /// + /// Job information. + /// + IEts2Job Job { get; } + + /// + /// Navigation information. + /// + IEts2Navigation Navigation { get; } + } + + public interface IEts2Game + { + /// + /// Current game time. + /// Serializes to ISO 8601 string in JSON. + /// Example: "0001-01-05T05:11:00Z" + /// + DateTime Time { get; } + + /// + /// True if game is currently paused, false otherwise. + /// + bool Paused { get; } + + /// + /// Current version of the telemetry plugin DLL file. + /// Example: "4" + /// + string TelemetryPluginVersion { get; } + + /// + /// Current version of the game. + /// Example: "1.10" + /// + string Version { get; } + + /// + /// When the fatigue simulation is disabled, the behavior of this channel + /// is implementation dependent. The game might provide the value which would + /// apply if it was enabled or provide no value at all. + /// Example: "0001-01-01T10:52:00Z" + /// + DateTime NextRestStopTime { get; } + + /// + /// Scale applied to distance and time to compensate + /// for the scale of the map (e.g. 1s of real time corresponds + /// to local_scale seconds of simulated game time). + /// Example: 3 + /// + float TimeScale { get; } + } + + public interface IEts2Vector + { + float X { get; } + float Y { get; } + float Z { get; } + } + + public interface IEts2Placement + { + /// + /// X coordinate of the placement. + /// Example: 13723.7881 + /// + float X { get; } + + /// + /// Y coordinate of the placement. + /// Example: 65.22377 + /// + float Y { get; } + + /// + /// Z coordinate of the placement. + /// Example: 13738.8018 + /// + float Z { get; } + + /// + /// The angle is measured counterclockwise in horizontal plane when looking + /// from top where 0 corresponds to forward (north), 0.25 to left (west), + /// 0.5 to backward (south) and 0.75 to right (east). + /// Stored in unit range where (0,1) corresponds to (0,360). + /// Example: 0.13688866 + /// + float Heading { get; } + + /// + /// The pitch angle is zero when in horizontal direction, + /// with positive values pointing up (0.25 directly to zenith), + /// and negative values pointing down (-0.25 directly to nadir). + /// Stored in unit range where (-0.25,0.25) corresponds to (-90,90). + /// Example: 0.00005 + /// + float Pitch { get; } + + /// + /// The angle is measured in counterclockwise when looking in direction of the roll axis. + /// Stored in unit range where (-0.5,0.5) corresponds to (-180,180). + /// Example: -0.00009 + /// + float Roll { get; } + } + + public interface IEts2Truck + { + /// + /// Current truck speed in km/h. + /// Example: 50.411231 + /// + float Speed { get; } + + /// + /// Represents vehicle space linear acceleration of + /// the truck measured in meters per second^2. + /// Example: { "x": 0.046569, "y": -0.00116, "z": -1.03676 } + /// + IEts2Vector Acceleration { get; } + + /// + /// Current truck placement in the game world. + /// + IEts2Placement Placement { get; } + + /// + /// The value of the odometer in km. + /// Example: 105809.25 + /// + float Odometer { get; } + + /// + /// Speed selected for the cruise control in km/h. + /// Example: 75 + /// + float CruiseControlSpeed { get; } + + /// + /// Brand Id of the current truck. + /// Example: "man". + /// + string Id { get; } + + /// + /// Localized brand name of the current truck for display purposes. + /// Example: "MAN". + /// + string Make { get; } + + /// + /// Localized model name of the current truck. + /// Example: "TGX". + /// + string Model { get; } + + /// + /// Gear that is currently selected in the engine. + /// Positive values reflect forward gears, negative - reverse. + /// Example: 9 + /// + int Gear { get; } + + /// + /// Gear that is currently displayed on the main dashboard. + /// Positive values reflect forward gears, negative - reverse. + /// Example: 4 + /// + int DisplayedGear { get; } + + /// + /// Number of forward gears on undamaged truck. + /// Example: 12 + /// + int ForwardGears { get; } + + /// + /// Number of reverse gears on undamaged truck. + /// Example: 2 + /// + int ReverseGears { get; } + + /// + /// Current RPM value of the truck's engine (rotates per minute). + /// Example: 1372.3175 + /// + float EngineRpm { get; } + + /// + /// Maximal RPM value of the truck's engine. + /// Example: 2500 + /// + float EngineRpmMax { get; } + + /// + /// Current amount of fuel in liters. + /// Example: 696.7544 + /// + float Fuel { get; } + + /// + /// Fuel tank capacity in litres. + /// Example: 700 + /// + float FuelCapacity { get; } + + /// + /// Average consumption of the fuel in liters/km. + /// Example: 0.4923077 + /// + float FuelAverageConsumption { get; } + + /// + /// Steering received from input (-1;1). + /// Note that it is interpreted counterclockwise. + /// If the user presses the steer right button on digital input + /// (e.g. keyboard) this value goes immediatelly to -1.0 + /// Example: -1.0 + /// + float UserSteer { get; } + + /// + /// Throttle received from input (-1;1). + /// If the user presses the forward button on digital input + /// (e.g. keyboard) this value goes immediatelly to 1.0 + /// Example: 0 + /// + float UserThrottle { get; } + + /// + /// Brake received from input (-1;1) + /// If the user presses the brake button on digital input + /// (e.g. keyboard) this value goes immediatelly to 1.0 + /// Example: 0 + /// + float UserBrake { get; } + + /// + /// Clutch received from input (-1;1) + /// If the user presses the clutch button on digital input + /// (e.g. keyboard) this value goes immediatelly to 1.0 + /// Example: 0 + /// + float UserClutch { get; } + + /// + /// Steering as used by the simulation (-1;1) + /// Note that it is interpreted counterclockwise. + /// Accounts for interpolation speeds and simulated + /// counterfoces for digital inputs. + /// Example: -0.423521 + /// + float GameSteer { get; } + + /// + /// Throttle pedal input as used by the simulation (0;1) + /// Accounts for the press attack curve for digital inputs + /// or cruise-control input. + /// Example: 0.17161 + /// + float GameThrottle { get; } + + /// + /// Brake pedal input as used by the simulation (0;1) + /// Accounts for the press attack curve for digital inputs. + /// Does not contain retarder, parking or motor brake. + /// Example: 0 + /// + float GameBrake { get; } + + /// + /// Clutch pedal input as used by the simulation (0;1) + /// Accounts for the automatic shifting or interpolation of + /// player input. + /// Example: 0 + /// + float GameClutch { get; } + + /// + /// Current level of the retarder brake. + /// Ranges from 0 to RetarderStepCount. + /// Example: 0 + /// + int RetarderBrake { get; } + + /// + /// Number of steps in the retarder. + /// Set to zero if retarder is not mounted to the truck. + /// Example: 3 + /// + int RetarderStepCount { get; } + + /// + /// Gearbox slot the h-shifter handle is currently in. + /// 0 means that no slot is selected. + /// Example: 0 + /// + int ShifterSlot { get; } + + /// + /// TODO: need to fix. + /// + /// + /// Pressure in the brake air tank in psi. + /// Example: 133.043961 + /// + float AirPressure { get; } + + /// + /// Temperature of the brakes in degrees celsius. + /// Example: 15.9377184 + /// + float BrakeTemperature { get; } + + /// + /// Amount of AdBlue in liters. + /// Example: 0 + /// + float Adblue { get; } + + /// + /// Average consumption of the adblue in liters/km. + /// Example: 0 + /// + float AdblueAverageConsumption { get; } + + /// + /// Pressure of the oil in psi. + /// Example: 36.4550362 + /// + float OilPressure { get; } + + /// + /// Temperature of the oil in degrees celsius. + /// Example: 16.2580566 + /// + float OilTemperature { get; } + + /// + /// Temperature of the water in degrees celsius. + /// Example: 16.1623955 + /// + float WaterTemperature { get; } + + /// + /// Voltage of the battery in volts. + /// Example: 23.4985161 + /// + float BatteryVoltage { get; } + + /// + /// AdBlue tank capacity in litres. + /// Example: 0 + /// + float AdblueCapacity { get; } + + /// + /// Current level of truck's engine wear/damage between 0 (min) and 1 (max). + /// Example: 0.00675457 + /// + float WearEngine { get; } + + /// + /// Current level of truck's transmission wear/damage between 0 (min) and 1 (max). + /// + float WearTransmission { get; } + + /// + /// Current level of truck's cabin wear/damage between 0 (min) and 1 (max). + /// + float WearCabin { get; } + + /// + /// Current level of truck's chassis wear/damage between 0 (min) and 1 (max). + /// + float WearChassis { get; } + + /// + /// Current level of truck's wheel wear/damage between 0 (min) and 1 (max). + /// + float WearWheels { get; } + + /// + /// Default position of the head in the cabin space. + /// Example: { "x": -0.795116067, "y": 1.43522251, "z": -0.08483863 } + /// + IEts2Vector Head { get; } + + /// + /// Position of the cabin in the vehicle space. + /// This is position of the joint around which the cabin rotates. + /// This attribute might be not present if the vehicle does not have a separate cabin. + /// Example: { "x": 0, "y": 1.36506855, "z": -1.70362806 } + /// + IEts2Vector Cabin { get; } + + /// + /// Position of the trailer connection hook in vehicle space. + /// Example: { "x": 0, "y": 0.939669, "z": -6.17736959 } + /// + IEts2Vector Hook { get; } + + /// + /// All available selectors (e.g. range/splitter toggles). TODO: need to fix. + /// + /// + /// Type of the shifter. + /// One of the following values: "arcade", "automatic", "manual", "hshifter". + /// + string ShifterType { get; } + + /// + /// Indicates whether cruise control is turned on or off. + /// + bool CruiseControlOn { get; } + + /// + /// Indicates whether wipers are currently turned on or off. + /// + bool WipersOn { get; } + + /// + /// Is the parking brake enabled or not. + /// + bool ParkBrakeOn { get; } + + /// + /// Is the motor brake enabled or not. + /// + bool MotorBrakeOn { get; } + + /// + /// Is the engine enabled or not. + /// + bool EngineOn { get; } + + /// + /// Is the electric enabled or not. + /// + bool ElectricOn { get; } + + /// + /// Is left blinker currently emits light or not. + /// + bool BlinkerLeftActive { get; } + + /// + /// Is right blinker currently emits light or not. + /// + bool BlinkerRightActive { get; } + + /// + /// Is left blinker currently turned on or off. + /// + bool BlinkerLeftOn { get; } + + /// + /// Is right blinker currently turned on or off. + /// + bool BlinkerRightOn { get; } + + /// + /// Are the parking lights enabled or not. + /// + bool LightsParkingOn { get; } + + /// + /// Are the low beam lights enabled or not. + /// + bool LightsBeamLowOn { get; } + + /// + /// Are the high beam lights enabled or not. + /// + bool LightsBeamHighOn { get; } + + /// + /// Are the auxiliary front lights active or not. + /// + bool LightsAuxFrontOn { get; } + + /// + /// Are the auxiliary roof lights active or not. + /// + bool LightsAuxRoofOn { get; } + + /// + /// Are the beacon lights enabled or not. + /// + bool LightsBeaconOn { get; } + + /// + /// Is the brake light active or not. + /// + bool LightsBrakeOn { get; } + + /// + /// Is the reverse light active or not. + /// + bool LightsReverseOn { get; } + + /// + /// Is the battery voltage/not charging warning active or not. + /// + bool BatteryVoltageWarningOn { get; } + + /// + /// Is the air pressure warning active or not. + /// + bool AirPressureWarningOn { get; } + + /// + /// Are the emergency brakes active as result of low air pressure or not. + /// + bool AirPressureEmergencyOn { get; } + + /// + /// Is the low adblue warning active or not. + /// + bool AdblueWarningOn { get; } + + /// + /// Is the oil pressure warning active or not. + /// + bool OilPressureWarningOn { get; } + + /// + /// Is the water temperature warning active or not. + /// + bool WaterTemperatureWarningOn { get; } + + /// + /// Intensity of the dashboard backlight between 0 (off) and 1 (max). + /// + float LightsDashboardValue { get; } + + /// + /// Is the dashboard backlight currently turned on or off. + /// + bool LightsDashboardOn { get; } + + /// + /// Is the low fuel warning active or not. + /// + bool FuelWarningOn { get; } + + /// + /// Fraction of the fuel capacity bellow which is activated the fuel warning. + /// Example: 0.15 + /// + float FuelWarningFactor { get; } + + /// + /// Pressure of the air in the tank bellow which the warning activates. + /// Example: 65 + /// + float AirPressureWarningValue { get; } + + /// + /// Pressure of the air in the tank bellow which the emergency brakes activate. + /// Example: 30 + /// + float AirPressureEmergencyValue { get; } + + /// + /// Pressure of the oil bellow which the warning activates. + /// Example: 10 + /// + float OilPressureWarningValue { get; } + + /// + /// Temperature of the water above which the warning activates. + /// Example: 105 + /// + float WaterTemperatureWarningValue { get; } + + /// + /// Voltage of the battery bellow which the warning activates. + /// Example: 22 + /// + float BatteryVoltageWarningValue { get; } + } + + public interface IEts2Navigation + { + /// + /// Relative estimated time of arrival. + /// Example: "0001-01-01T02:05:00Z" + /// + DateTime EstimatedTime { get; } + + /// + /// Estimated distance to the destination in meters. + /// Example: 1224 + /// + int EstimatedDistance { get; } + + /// + /// Current value of the "Route Advisor speed limit" in km/h. + /// Example: 50 + /// + int SpeedLimit { get; } + } + + public interface IEts2Job + { + /// + /// Reward in internal game-specific currency. + /// Example: 2316 + /// + int Income { get; } + + /// + /// Absolute in-game time of end of job delivery window. + /// Delivering the job after this time will cause it be late. + /// Example: "0001-01-09T03:34:00Z" + /// + DateTime DeadlineTime { get; } + + /// + /// Relative remaining in-game time left before deadline. + /// Example: "0001-01-01T07:06:00Z" + /// + DateTime RemainingTime { get; } + + /// + /// Localized name of the source city for display purposes. + /// Example: "Linz" + /// + string SourceCity { get; } + + /// + /// Localized name of the destination city for display purposes. + /// Example: "Salzburg" + /// + string DestinationCity { get; } + + /// + /// Localized name of the source company for display purposes. + /// Example: "DHL" + /// + string SourceCompany { get; } + + /// + /// Localized name of the destination company for display purposes. + /// Example: "JCB" + /// + string DestinationCompany { get; } + } + + public interface IEts2Trailer + { + /// + /// Id of the cargo for internal use by code. + /// Example: "derrick" + /// + string Id { get; } + + /// + /// Localized name of the current trailer for display purposes. + /// Example: "Derrick" + /// + string Name { get; } + + /// + /// Is the trailer attached to the truck or not. + /// + bool Attached { get; } + + /// + /// Mass of the cargo in kilograms. + /// Example: 22000 + /// + float Mass { get; } + + /// + /// Current trailer placement in the game world. + /// + IEts2Placement Placement { get; } + + /// + /// Current level of trailer wear/damage between 0 (min) and 1 (max). + /// Example: 0.0314717 + /// + float Wear { get; } + } + + /* + public interface IEts2Wheel + { + /// + /// Is the wheel physically simulated or not. + /// + bool Simulated { get; } + /// + /// Is the wheel steerable or not. + /// + bool Steerable { get; } + /// + /// Radius of the wheel. + /// Example: 0.5120504 + /// + float Radius { get; } + /// + /// Position of respective wheels in the vehicle space. + /// Example: { "x": -0.9, "y": 0.506898463, "z": 6.25029 } + /// + IEts2Vector Position { get; } + /// + /// Is the wheel powered or not. + /// + bool Powered { get; } + /// + /// Is the wheel liftable or not. + /// + bool Liftable { get; } + } + + public interface IEts2GearSlot + { + /// + /// Gear selected when requirements for this h-shifter slot are meet. + /// Example: 0 + /// + int Gear { get; } + /// + /// Position of h-shifter handle. + /// Zero corresponds to neutral position. + /// Mapping to physical position of the handle depends on input setup. + /// Example: 0 + /// + int HandlePosition { get; } + /// + /// Bitmask of required on/off state of selectors. + /// Only first N number of bits are relevant (where N is the number of IEts2GearSlot objects). + /// Example: 0 + /// + int SlotSelectors { get; } + } + */ +} \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Games/EurotruckSimulator2/Data/Reader/Ets2TelemetryStructure.cs b/Artemis/Artemis/Modules/Games/EurotruckSimulator2/Data/Reader/Ets2TelemetryStructure.cs new file mode 100644 index 000000000..89f1edaff --- /dev/null +++ b/Artemis/Artemis/Modules/Games/EurotruckSimulator2/Data/Reader/Ets2TelemetryStructure.cs @@ -0,0 +1,214 @@ +using System.Runtime.InteropServices; + +namespace Artemis.Modules.Games.EurotruckSimulator2.Data.Reader +{ + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] + internal struct Ets2TelemetryStructure + { + private const int GeneralStringSize = 64; + + public uint time; + public uint paused; + + public uint ets2_telemetry_plugin_revision; + public uint ets2_version_major; + public uint ets2_version_minor; + + // ***** REVISION 1 ****** // + + private readonly byte padding1; + public byte trailer_attached; + public byte padding2; + public byte padding3; + + public float speed; + public float accelerationX; + public float accelerationY; + public float accelerationZ; + + public float coordinateX; + public float coordinateY; + public float coordinateZ; + + public float rotationX; + public float rotationY; + public float rotationZ; + + public int gear; + public int gearsForward; + public int gearRanges; + public int gearRangeActive; + + public float engineRpm; + public float engineRpmMax; + + public float fuel; + public float fuelCapacity; + public float fuelRate; + public float fuelAvgConsumption; + + public float userSteer; + public float userThrottle; + public float userBrake; + public float userClutch; + + public float gameSteer; + public float gameThrottle; + public float gameBrake; + public float gameClutch; + + public float truckWeight; + public float trailerWeight; + + public int modelOffset; + public int modelLength; + + public int trailerOffset; + public int trailerLength; + + public int timeAbsolute; + public int gearsReverse; + + public float trailerMass; + + [MarshalAs(UnmanagedType.ByValArray, SizeConst = GeneralStringSize)] public byte[] trailerId; + + [MarshalAs(UnmanagedType.ByValArray, SizeConst = GeneralStringSize)] public byte[] trailerName; + + public int jobIncome; + public int jobDeadline; + + [MarshalAs(UnmanagedType.ByValArray, SizeConst = GeneralStringSize)] public byte[] jobCitySource; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = GeneralStringSize)] public byte[] jobCityDestination; + + [MarshalAs(UnmanagedType.ByValArray, SizeConst = GeneralStringSize)] public byte[] jobCompanySource; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = GeneralStringSize)] public byte[] jobCompanyDestination; + + // ***** REVISION 3 ****** // + + public int retarderBrake; + public int shifterSlot; + public int shifterToggle; + public int padding4; + + public byte cruiseControl; + public byte wipers; + + public byte parkBrake; + public byte motorBrake; + + public byte electricEnabled; + public byte engineEnabled; + + public byte blinkerLeftActive; + public byte blinkerRightActive; + public byte blinkerLeftOn; + public byte blinkerRightOn; + + public byte lightsParking; + public byte lightsBeamLow; + public byte lightsBeamHigh; + public uint lightsAuxFront; + public uint lightsAuxRoof; + public byte lightsBeacon; + public byte lightsBrake; + public byte lightsReverse; + + public byte batteryVoltageWarning; + public byte airPressureWarning; + public byte airPressureEmergency; + public byte adblueWarning; + public byte oilPressureWarning; + public byte waterTemperatureWarning; + + public float airPressure; + public float brakeTemperature; + public int fuelWarning; + public float adblue; + public float adblueConsumption; + public float oilPressure; + public float oilTemperature; + public float waterTemperature; + public float batteryVoltage; + public float lightsDashboard; + public float wearEngine; + public float wearTransmission; + public float wearCabin; + public float wearChassis; + public float wearWheels; + public float wearTrailer; + public float truckOdometer; + public float cruiseControlSpeed; + + [MarshalAs(UnmanagedType.ByValArray, SizeConst = GeneralStringSize)] public byte[] truckMake; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = GeneralStringSize)] public byte[] truckMakeId; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = GeneralStringSize)] public byte[] truckModel; + + // ***** REVISION 4 ****** // + + public float fuelWarningFactor; + public float adblueCapacity; + public float airPressureWarningValue; + public float airPressureEmergencyValue; + public float oilPressureWarningValue; + public float waterTemperatureWarningValue; + public float batteryVoltageWarningValue; + + public uint retarderStepCount; + + public float cabinPositionX; + public float cabinPositionY; + public float cabinPositionZ; + public float headPositionX; + public float headPositionY; + public float headPositionZ; + public float hookPositionX; + public float hookPositionY; + public float hookPositionZ; + + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public byte[] shifterType; + + public float localScale; + public int nextRestStop; + public float trailerCoordinateX; + public float trailerCoordinateY; + public float trailerCoordinateZ; + public float trailerRotationX; + public float trailerRotationY; + public float trailerRotationZ; + + public int displayedGear; + public float navigationDistance; + public float navigationTime; + public float navigationSpeedLimit; + + /* + const int MaxSlotCount = 32; // TODO: need to fix. + const int MaxWheelCount = 20; + public uint wheelCount; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = MaxWheelCount)] + public float[] wheelPositionX; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = MaxWheelCount)] + public float[] wheelPositionY; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = MaxWheelCount)] + public float[] wheelPositionZ; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = MaxWheelCount)] + public byte[] wheelSteerable; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = MaxWheelCount)] + public byte[] wheelSimulated; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = MaxWheelCount)] + public float[] wheelRadius; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = MaxWheelCount)] + public byte[] wheelPowered; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = MaxWheelCount)] + public byte[] wheelLiftable; + public uint selectorCount; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = MaxSlotCount)] + public int[] slotGear; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = MaxSlotCount)] + public uint[] slotHandlePosition; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = MaxSlotCount)] + public uint[] slotSelectors; + */ + } +} \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Games/EurotruckSimulator2/Data/Reader/SharedProcessMemory.cs b/Artemis/Artemis/Modules/Games/EurotruckSimulator2/Data/Reader/SharedProcessMemory.cs new file mode 100644 index 000000000..6de2569a4 --- /dev/null +++ b/Artemis/Artemis/Modules/Games/EurotruckSimulator2/Data/Reader/SharedProcessMemory.cs @@ -0,0 +1,84 @@ +using System; +using System.IO.MemoryMappedFiles; +using System.Runtime.InteropServices; + +namespace Artemis.Modules.Games.EurotruckSimulator2.Data.Reader +{ + internal class SharedProcessMemory : IDisposable + { + private readonly string _mapName; + private MemoryMappedViewAccessor _memoryMappedAccessor; + + private MemoryMappedFile _memoryMappedFile; + + public SharedProcessMemory(string mapName) + { + _mapName = mapName; + Data = default(T); + } + + public T Data { get; set; } + + public bool IsConnected + { + get + { + InitializeViewAccessor(); + return _memoryMappedAccessor != null; + } + } + + public void Dispose() + { + if (_memoryMappedAccessor != null) + { + _memoryMappedAccessor.Dispose(); + _memoryMappedFile.Dispose(); + } + } + + private void InitializeViewAccessor() + { + if (_memoryMappedAccessor == null) + try + { + _memoryMappedFile = MemoryMappedFile.OpenExisting(_mapName, MemoryMappedFileRights.ReadWrite); + _memoryMappedAccessor = _memoryMappedFile.CreateViewAccessor(0, Marshal.SizeOf(typeof(T)), + MemoryMappedFileAccess.Read); + } + // ReSharper disable once EmptyGeneralCatchClause + catch + { + } + } + + public void Read() + { + InitializeViewAccessor(); + + if (_memoryMappedAccessor == null) + return; + + var rawData = new byte[Marshal.SizeOf(typeof(T))]; + + _memoryMappedAccessor.ReadArray(0, rawData, 0, rawData.Length); + + T createdObject; + + var reservedMemPtr = IntPtr.Zero; + try + { + reservedMemPtr = Marshal.AllocHGlobal(rawData.Length); + Marshal.Copy(rawData, 0, reservedMemPtr, rawData.Length); + createdObject = (T) Marshal.PtrToStructure(reservedMemPtr, typeof(T)); + } + finally + { + if (reservedMemPtr != IntPtr.Zero) + Marshal.FreeHGlobal(reservedMemPtr); + } + + Data = createdObject; + } + } +} \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Games/EurotruckSimulator2/EurotruckSimulator2DataModel.cs b/Artemis/Artemis/Modules/Games/EurotruckSimulator2/EurotruckSimulator2DataModel.cs index 600556dc6..44493b246 100644 --- a/Artemis/Artemis/Modules/Games/EurotruckSimulator2/EurotruckSimulator2DataModel.cs +++ b/Artemis/Artemis/Modules/Games/EurotruckSimulator2/EurotruckSimulator2DataModel.cs @@ -1,18 +1,14 @@ using Artemis.Models.Interfaces; -using Ets2SdkClient; +using Artemis.Modules.Games.EurotruckSimulator2.Data; namespace Artemis.Modules.Games.EurotruckSimulator2 { public class EurotruckSimulator2DataModel : IDataModel { - public Ets2Telemetry._Axilliary Axilliary { get; set; } - public Ets2Telemetry._Controls Controls { get; set; } - public Ets2Telemetry._Damage Damage { get; set; } - public Ets2Telemetry._Drivetrain Drivetrain { get; set; } - public Ets2Telemetry._Job Job { get; set; } - public Ets2Telemetry._Lights Lights { get; set; } - public string Manufacturer { get; set; } - public string ManufacturerId { get; set; } - public Ets2Telemetry._Physics Physics { get; set; } + public IEts2Game Game { get; set; } + public IEts2Job Job { get; set; } + public IEts2Navigation Navigation { get; set; } + public IEts2Trailer Trailer { get; set; } + public IEts2Truck Truck { get; set; } } } \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Games/EurotruckSimulator2/EurotruckSimulator2Model.cs b/Artemis/Artemis/Modules/Games/EurotruckSimulator2/EurotruckSimulator2Model.cs index e784be51d..9bbe52d92 100644 --- a/Artemis/Artemis/Modules/Games/EurotruckSimulator2/EurotruckSimulator2Model.cs +++ b/Artemis/Artemis/Modules/Games/EurotruckSimulator2/EurotruckSimulator2Model.cs @@ -2,8 +2,8 @@ using Artemis.DAL; using Artemis.Managers; using Artemis.Models; +using Artemis.Modules.Games.EurotruckSimulator2.Data; using Artemis.Profiles.Layers.Models; -using Ets2SdkClient; using Ninject.Extensions.Logging; namespace Artemis.Modules.Games.EurotruckSimulator2 @@ -24,42 +24,26 @@ namespace Artemis.Modules.Games.EurotruckSimulator2 public ILogger Logger { get; set; } public int Scale { get; set; } - public Ets2SdkTelemetry Telemetry { get; set; } - public override void Dispose() { Initialized = false; - - Telemetry.Data -= TelemetryOnData; - Telemetry = null; } public override void Enable() { - Telemetry = new Ets2SdkTelemetry(); - Telemetry.Data += TelemetryOnData; - if (Telemetry.Error != null) - MainManager.Logger.Error(Telemetry.Error, "Exception in the Eurotruck SDK"); - Initialized = true; } - private void TelemetryOnData(Ets2Telemetry data, bool newTimestamp) - { - ((EurotruckSimulator2DataModel) DataModel).Axilliary = data.Axilliary; - ((EurotruckSimulator2DataModel) DataModel).Controls = data.Controls; - ((EurotruckSimulator2DataModel) DataModel).Damage = data.Damage; - ((EurotruckSimulator2DataModel) DataModel).Drivetrain = data.Drivetrain; - ((EurotruckSimulator2DataModel) DataModel).Job = data.Job; - ((EurotruckSimulator2DataModel) DataModel).Lights = data.Lights; - ((EurotruckSimulator2DataModel) DataModel).Manufacturer = data.Manufacturer; - ((EurotruckSimulator2DataModel) DataModel).ManufacturerId = data.ManufacturerId; - ((EurotruckSimulator2DataModel) DataModel).Physics = data.Physics; - } - public override void Update() { - // Updating is handled in the TelemetryOnData event + var dataModel = (EurotruckSimulator2DataModel) DataModel; + var telemetryData = Ets2TelemetryDataReader.Instance.Read(); + + dataModel.Game = telemetryData.Game; + dataModel.Job = telemetryData.Job; + dataModel.Navigation = telemetryData.Navigation; + dataModel.Trailer = telemetryData.Trailer; + dataModel.Truck = telemetryData.Truck; } public override List GetRenderLayers(bool keyboardOnly) diff --git a/Artemis/Artemis/Modules/Games/EurotruckSimulator2/EurotruckSimulator2View.xaml b/Artemis/Artemis/Modules/Games/EurotruckSimulator2/EurotruckSimulator2View.xaml index 56582d491..9edffb950 100644 --- a/Artemis/Artemis/Modules/Games/EurotruckSimulator2/EurotruckSimulator2View.xaml +++ b/Artemis/Artemis/Modules/Games/EurotruckSimulator2/EurotruckSimulator2View.xaml @@ -5,7 +5,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:cal="http://www.caliburnproject.org" mc:Ignorable="d" - d:DesignHeight="476.986" d:DesignWidth="538.772"> + d:DesignHeight="559.725" d:DesignWidth="882.696"> @@ -20,31 +20,50 @@ - -