diff --git a/Artemis/Artemis/Artemis.csproj b/Artemis/Artemis/Artemis.csproj index 802b21a7b..22820281f 100644 --- a/Artemis/Artemis/Artemis.csproj +++ b/Artemis/Artemis/Artemis.csproj @@ -131,6 +131,10 @@ LocalIntranet + + False + lib\AssettoCorsaSharedMemory.dll + ..\packages\Betwixt.1.4.1\lib\net35\Betwixt.dll True @@ -371,6 +375,13 @@ + + + + + AssettoCorsaView.xaml + + @@ -784,7 +795,7 @@ - + PreserveNewest @@ -831,6 +842,10 @@ Designer MSBuild:Compile + + MSBuild:Compile + Designer + Designer MSBuild:Compile diff --git a/Artemis/Artemis/Modules/Games/AssettoCorsa/AssettoCorsaDataModel.cs b/Artemis/Artemis/Modules/Games/AssettoCorsa/AssettoCorsaDataModel.cs new file mode 100644 index 000000000..75c21b4cb --- /dev/null +++ b/Artemis/Artemis/Modules/Games/AssettoCorsa/AssettoCorsaDataModel.cs @@ -0,0 +1,164 @@ +using Artemis.Modules.Abstract; +using AssettoCorsaSharedMemory; +using MoonSharp.Interpreter; + +namespace Artemis.Modules.Games.AssettoCorsa +{ + [MoonSharpUserData] + public class AssettoCorsaDataModel : ModuleDataModel + { + public AssettoCorsaDataModel() + { + Physics = new Physics(); + Interface = new Graphics(); + StaticInfo = new StaticInfo(); + } + + public Physics Physics { get; set; } + public Graphics Interface { get; set; } + public StaticInfo StaticInfo { get; set; } + } + + [MoonSharpUserData] + public class Physics + { + public float Abs { get; set; } + public float Gas { get; set; } + public float Brake { get; set; } + public float Fuel { get; set; } + public int Gear { get; set; } + public int Rpms { get; set; } + public float SteerAngle { get; set; } + public float SpeedKmh { get; set; } + public float[] Velocity { get; set; } + public float[] AccG { get; set; } + public float[] WheelSlip { get; set; } + public float[] WheelLoad { get; set; } + public float[] WheelsPressure { get; set; } + public float[] WheelAngularSpeed { get; set; } + public float[] TyreWear { get; set; } + public float[] TyreDirtyLevel { get; set; } + public float[] TyreCoreTemperature { get; set; } + public float[] CamberRad { get; set; } + public float[] SuspensionTravel { get; set; } + public float Drs { get; set; } + public float TC { get; set; } + public float Heading { get; set; } + public float Pitch { get; set; } + public float Roll { get; set; } + public float CgHeight { get; set; } + public float[] CarDamage { get; set; } + public int NumberOfTyresOut { get; set; } + public int PitLimiterOn { get; set; } + public float KersCharge { get; set; } + public float KersInput { get; set; } + public int AutoShifterOn { get; set; } + public float[] RideHeight { get; set; } + public float TurboBoost { get; set; } + public float Ballast { get; set; } + public float AirDensity { get; set; } + public float AirTemp { get; set; } + public float RoadTemp { get; set; } + public float[] LocalAngularVelocity { get; set; } + public float FinalFF { get; set; } + public float PerformanceMeter { get; set; } + public int EngineBrake { get; set; } + public int ErsRecoveryLevel { get; set; } + public int ErsPowerLevel { get; set; } + public int ErsHeatCharging { get; set; } + public int ErsisCharging { get; set; } + public float KersCurrentKJ { get; set; } + public int DrsAvailable { get; set; } + public int DrsEnabled { get; set; } + public float[] BrakeTemp { get; set; } + public float Clutch { get; set; } + public float[] TyreTempI { get; set; } + public float[] TyreTempM { get; set; } + public float[] TyreTempO { get; set; } + public int IsAIControlled { get; set; } + public Coordinates[] TyreContactPoint { get; set; } + public Coordinates[] TyreContactNormal { get; set; } + public Coordinates[] TyreContactHeading { get; set; } + public float BrakeBias { get; set; } + } + + [MoonSharpUserData] + public class Graphics + { + public AC_STATUS Status { get; set; } + public AC_SESSION_TYPE Session { get; set; } + public string CurrentTime { get; set; } + public string LastTime { get; set; } + public string BestTime { get; set; } + public string Split { get; set; } + public int Position { get; set; } + public int iCurrentTime { get; set; } + public int iBestTime { get; set; } + public int iLastTime { get; set; } + public float SessionTimeLeft { get; set; } + public float DistanceTraveled { get; set; } + public int IsInPit { get; set; } + public int CurrentSectorIndex { get; set; } + public int LastSectorTime { get; set; } + public int NumberOfLaps { get; set; } + public string TyreCompound { get; set; } + public float ReplayTimeMultiplier { get; set; } + public float NormalizedCarPosition { get; set; } + } + + [MoonSharpUserData] + public class StaticInfo + { + public StaticInfo() + { + Session = new Session(); + Car = new Car(); + } + + public string SMVersion { get; set; } + public string ACVersion { get; set; } + public Session Session { get; set; } + public Car Car { get; set; } + } + + [MoonSharpUserData] + public class Session + { + public int NumberOfSessions { get; set; } + public int NumCars { get; set; } + public string Track { get; set; } + public string TrackConfiguration { get; set; } + public float TrackSPlineLength { get; set; } + public string PlayerName { get; set; } + public string PlayerSurname { get; set; } + public string PlayerNick { get; set; } + public int SectorCount { get; set; } + public int PenaltiesEnabled { get; set; } + } + + [MoonSharpUserData] + public class Car + { + public string CarModel { get; set; } + public float MaxTorque { get; set; } + public float MaxPower { get; set; } + public int MaxRpm { get; set; } + public float MaxFuel { get; set; } + public float[] SuspensionMaxTravel { get; set; } + public float[] TyreRadius { get; set; } + public float MaxTurboBoost { get; set; } + public float AidFuelRate { get; set; } + public float AidTireRate { get; set; } + public float AidMechanicalDamage { get; set; } + public int AidAllowTyreBlankets { get; set; } + public float AidStability { get; set; } + public int AidAutoClutch { get; set; } + public int AidAutoBlip { get; set; } + public int HasDRS { get; set; } + public int HasERS { get; set; } + public int HasKERS { get; set; } + public float KersMaxJoules { get; set; } + public int EngineBrakeSettingsCount { get; set; } + public int ErsPowerControllerCount { get; set; } + } +} \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Games/AssettoCorsa/AssettoCorsaModel.cs b/Artemis/Artemis/Modules/Games/AssettoCorsa/AssettoCorsaModel.cs new file mode 100644 index 000000000..f4a574fd6 --- /dev/null +++ b/Artemis/Artemis/Modules/Games/AssettoCorsa/AssettoCorsaModel.cs @@ -0,0 +1,173 @@ +using System; +using Artemis.DAL; +using Artemis.Managers; +using Artemis.Modules.Abstract; +using AssettoCorsaSharedMemory; + +namespace Artemis.Modules.Games.AssettoCorsa +{ + public class AssettoCorsaModel : ModuleModel + { + private AssettoCorsaSharedMemory.AssettoCorsa _ac; + + public AssettoCorsaModel(DeviceManager deviceManager, LuaManager luaManager) : base(deviceManager, luaManager) + { + Settings = SettingsProvider.Load(); + DataModel = new AssettoCorsaDataModel(); + ProcessNames.Add("AssettoCorsa"); + } + + public override string Name => "AssettoCorsa"; + public override bool IsOverlay => false; + public override bool IsBoundToProcess => true; + + public override void Enable() + { + _ac = new AssettoCorsaSharedMemory.AssettoCorsa {PhysicsInterval = 40}; + // The event handlers map their respecive enums to the datamodel, not pretty but fastest way possible + _ac.StaticInfoUpdated += AcOnStaticInfoUpdated; + _ac.GraphicsUpdated += AcOnGraphicsUpdated; + _ac.PhysicsUpdated += AcOnPhysicsUpdated; + _ac.Start(); + + base.Enable(); + } + + public override void Dispose() + { + base.Dispose(); + _ac.Stop(); + _ac = null; + } + + private void AcOnStaticInfoUpdated(object sender, StaticInfoEventArgs e) + { + var dataModel = (AssettoCorsaDataModel)DataModel; + dataModel.StaticInfo.SMVersion = e.StaticInfo.SMVersion; + dataModel.StaticInfo.ACVersion = e.StaticInfo.ACVersion; + dataModel.StaticInfo.Session.NumberOfSessions = e.StaticInfo.NumberOfSessions; + dataModel.StaticInfo.Session.NumCars = e.StaticInfo.NumCars; + dataModel.StaticInfo.Session.Track = e.StaticInfo.Track; + dataModel.StaticInfo.Session.TrackConfiguration = e.StaticInfo.TrackConfiguration; + dataModel.StaticInfo.Session.TrackSPlineLength = e.StaticInfo.TrackSPlineLength; + dataModel.StaticInfo.Session.PlayerName = e.StaticInfo.PlayerName; + dataModel.StaticInfo.Session.PlayerSurname = e.StaticInfo.PlayerSurname; + dataModel.StaticInfo.Session.PlayerNick = e.StaticInfo.PlayerNick; + dataModel.StaticInfo.Session.SectorCount = e.StaticInfo.SectorCount; + dataModel.StaticInfo.Session.PenaltiesEnabled = e.StaticInfo.PenaltiesEnabled; + dataModel.StaticInfo.Car.CarModel = e.StaticInfo.CarModel; + dataModel.StaticInfo.Car.MaxTorque = e.StaticInfo.MaxTorque; + dataModel.StaticInfo.Car.MaxPower = e.StaticInfo.MaxPower; + dataModel.StaticInfo.Car.MaxRpm = e.StaticInfo.MaxRpm; + dataModel.StaticInfo.Car.MaxFuel = e.StaticInfo.MaxFuel; + dataModel.StaticInfo.Car.SuspensionMaxTravel = e.StaticInfo.SuspensionMaxTravel; + dataModel.StaticInfo.Car.TyreRadius = e.StaticInfo.TyreRadius; + dataModel.StaticInfo.Car.MaxTurboBoost = e.StaticInfo.MaxTurboBoost; + dataModel.StaticInfo.Car.AidFuelRate = e.StaticInfo.AidFuelRate; + dataModel.StaticInfo.Car.AidTireRate = e.StaticInfo.AidTireRate; + dataModel.StaticInfo.Car.AidMechanicalDamage = e.StaticInfo.AidMechanicalDamage; + dataModel.StaticInfo.Car.AidAllowTyreBlankets = e.StaticInfo.AidAllowTyreBlankets; + dataModel.StaticInfo.Car.AidStability = e.StaticInfo.AidStability; + dataModel.StaticInfo.Car.AidAutoClutch = e.StaticInfo.AidAutoClutch; + dataModel.StaticInfo.Car.AidAutoBlip = e.StaticInfo.AidAutoBlip; + dataModel.StaticInfo.Car.HasDRS = e.StaticInfo.HasDRS; + dataModel.StaticInfo.Car.HasERS = e.StaticInfo.HasERS; + dataModel.StaticInfo.Car.HasKERS = e.StaticInfo.HasKERS; + dataModel.StaticInfo.Car.KersMaxJoules = e.StaticInfo.KersMaxJoules; + dataModel.StaticInfo.Car.EngineBrakeSettingsCount = e.StaticInfo.EngineBrakeSettingsCount; + dataModel.StaticInfo.Car.ErsPowerControllerCount = e.StaticInfo.ErsPowerControllerCount; + } + + private void AcOnGraphicsUpdated(object sender, GraphicsEventArgs e) + { + var dataModel = (AssettoCorsaDataModel)DataModel; + dataModel.Interface.Status = e.Graphics.Status; + dataModel.Interface.Session = e.Graphics.Session; + dataModel.Interface.CurrentTime = e.Graphics.CurrentTime; + dataModel.Interface.LastTime = e.Graphics.LastTime; + dataModel.Interface.BestTime = e.Graphics.BestTime; + dataModel.Interface.Split = e.Graphics.Split; + dataModel.Interface.Position = e.Graphics.Position; + dataModel.Interface.iCurrentTime = e.Graphics.iCurrentTime; + dataModel.Interface.iLastTime = e.Graphics.iLastTime; + dataModel.Interface.iBestTime = e.Graphics.iBestTime; + dataModel.Interface.SessionTimeLeft = e.Graphics.SessionTimeLeft; + dataModel.Interface.DistanceTraveled = e.Graphics.DistanceTraveled; + dataModel.Interface.IsInPit = e.Graphics.IsInPit; + dataModel.Interface.CurrentSectorIndex = e.Graphics.CurrentSectorIndex; + dataModel.Interface.LastSectorTime = e.Graphics.LastSectorTime; + dataModel.Interface.NumberOfLaps = e.Graphics.NumberOfLaps; + dataModel.Interface.TyreCompound = e.Graphics.TyreCompound; + dataModel.Interface.ReplayTimeMultiplier = e.Graphics.ReplayTimeMultiplier; + dataModel.Interface.NormalizedCarPosition = e.Graphics.NormalizedCarPosition; + } + + private void AcOnPhysicsUpdated(object sender, PhysicsEventArgs e) + { + var dataModel = (AssettoCorsaDataModel)DataModel; + dataModel.Physics.Abs = e.Physics.Abs; + dataModel.Physics.Gas = e.Physics.Gas; + dataModel.Physics.Brake = e.Physics.Brake; + dataModel.Physics.Fuel = e.Physics.Fuel; + dataModel.Physics.Gear = e.Physics.Gear; + dataModel.Physics.Rpms = e.Physics.Rpms; + dataModel.Physics.SteerAngle = e.Physics.SteerAngle; + dataModel.Physics.SpeedKmh = e.Physics.SpeedKmh; + dataModel.Physics.Velocity = e.Physics.Velocity; + dataModel.Physics.AccG = e.Physics.AccG; + dataModel.Physics.WheelSlip = e.Physics.WheelSlip; + dataModel.Physics.WheelLoad = e.Physics.WheelLoad; + dataModel.Physics.WheelsPressure = e.Physics.WheelsPressure; + dataModel.Physics.WheelAngularSpeed = e.Physics.WheelAngularSpeed; + dataModel.Physics.TyreWear = e.Physics.TyreWear; + dataModel.Physics.TyreDirtyLevel = e.Physics.TyreDirtyLevel; + dataModel.Physics.TyreCoreTemperature = e.Physics.TyreCoreTemperature; + dataModel.Physics.CamberRad = e.Physics.CamberRad; + dataModel.Physics.SuspensionTravel = e.Physics.SuspensionTravel; + dataModel.Physics.Drs = e.Physics.Drs; + dataModel.Physics.TC = e.Physics.TC; + dataModel.Physics.Heading = e.Physics.Heading; + dataModel.Physics.Pitch = e.Physics.Pitch; + dataModel.Physics.Roll = e.Physics.Roll; + dataModel.Physics.CgHeight = e.Physics.CgHeight; + dataModel.Physics.CarDamage = e.Physics.CarDamage; + dataModel.Physics.NumberOfTyresOut = e.Physics.NumberOfTyresOut; + dataModel.Physics.PitLimiterOn = e.Physics.PitLimiterOn; + dataModel.Physics.KersCharge = e.Physics.KersCharge; + dataModel.Physics.KersInput = e.Physics.KersInput; + dataModel.Physics.AutoShifterOn = e.Physics.AutoShifterOn; + dataModel.Physics.RideHeight = e.Physics.RideHeight; + dataModel.Physics.TurboBoost = e.Physics.TurboBoost; + dataModel.Physics.Ballast = e.Physics.Ballast; + dataModel.Physics.AirDensity = e.Physics.AirDensity; + dataModel.Physics.AirTemp = e.Physics.AirTemp; + dataModel.Physics.RoadTemp = e.Physics.RoadTemp; + dataModel.Physics.LocalAngularVelocity = e.Physics.LocalAngularVelocity; + dataModel.Physics.FinalFF = e.Physics.FinalFF; + dataModel.Physics.PerformanceMeter = e.Physics.PerformanceMeter; + dataModel.Physics.EngineBrake = e.Physics.EngineBrake; + dataModel.Physics.ErsRecoveryLevel = e.Physics.ErsRecoveryLevel; + dataModel.Physics.ErsPowerLevel = e.Physics.ErsPowerLevel; + dataModel.Physics.ErsHeatCharging = e.Physics.ErsHeatCharging; + dataModel.Physics.ErsisCharging = e.Physics.ErsisCharging; + dataModel.Physics.KersCurrentKJ = e.Physics.KersCurrentKJ; + dataModel.Physics.DrsAvailable = e.Physics.DrsAvailable; + dataModel.Physics.DrsEnabled = e.Physics.DrsEnabled; + dataModel.Physics.BrakeTemp = e.Physics.BrakeTemp; + dataModel.Physics.Clutch = e.Physics.Clutch; + dataModel.Physics.TyreTempI = e.Physics.TyreTempI; + dataModel.Physics.TyreTempM = e.Physics.TyreTempM; + dataModel.Physics.TyreTempO = e.Physics.TyreTempO; + dataModel.Physics.IsAIControlled = e.Physics.IsAIControlled; + dataModel.Physics.TyreContactPoint = e.Physics.TyreContactPoint; + dataModel.Physics.TyreContactNormal = e.Physics.TyreContactNormal; + dataModel.Physics.TyreContactHeading = e.Physics.TyreContactHeading; + dataModel.Physics.BrakeBias = e.Physics.BrakeBias; + } + + public override void Update() + { + // Updating is done by the events + } + } +} \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Games/AssettoCorsa/AssettoCorsaSettings.cs b/Artemis/Artemis/Modules/Games/AssettoCorsa/AssettoCorsaSettings.cs new file mode 100644 index 000000000..ecba09fc2 --- /dev/null +++ b/Artemis/Artemis/Modules/Games/AssettoCorsa/AssettoCorsaSettings.cs @@ -0,0 +1,8 @@ +using Artemis.Modules.Abstract; + +namespace Artemis.Modules.Games.AssettoCorsa +{ + public class AssettoCorsaSettings : ModuleSettings + { + } +} \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Games/AssettoCorsa/AssettoCorsaView.xaml b/Artemis/Artemis/Modules/Games/AssettoCorsa/AssettoCorsaView.xaml new file mode 100644 index 000000000..f531cbb36 --- /dev/null +++ b/Artemis/Artemis/Modules/Games/AssettoCorsa/AssettoCorsaView.xaml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + The Assetto Corsa module uses the + + Assetto Corsa Shared Memory Library + + project by mdjarv + + + + + + + + + + +