diff --git a/Artemis/Artemis/App.config b/Artemis/Artemis/App.config index d50a7a65e..5422855a9 100644 --- a/Artemis/Artemis/App.config +++ b/Artemis/Artemis/App.config @@ -4,6 +4,7 @@ +
+ + + C:\Program Files (x86)\Steam\steamapps\common\Counter-Strike Global Offensive + + #FFFF2900 diff --git a/Artemis/Artemis/Artemis.csproj b/Artemis/Artemis/Artemis.csproj index c1317196e..3857362fe 100644 --- a/Artemis/Artemis/Artemis.csproj +++ b/Artemis/Artemis/Artemis.csproj @@ -192,6 +192,11 @@ True AudioVisualization.settings + + True + True + CounterStrike.settings + True True @@ -217,7 +222,6 @@ - @@ -291,6 +295,10 @@ + + SettingsSingleFileGenerator + CounterStrike.Designer.cs + SettingsSingleFileGenerator VolumeDisplay.Designer.cs diff --git a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeModel.cs b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeModel.cs index f57179fea..9ec2c8178 100644 --- a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeModel.cs +++ b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeModel.cs @@ -5,9 +5,9 @@ using System.Drawing.Drawing2D; using System.Linq; using Artemis.Models; using Artemis.Utilities.GameSense; -using Artemis.Utilities.GameSense.JsonModels; using Artemis.Utilities.Keyboard; using Newtonsoft.Json; +using Newtonsoft.Json.Linq; namespace Artemis.Modules.Games.CounterStrike { @@ -23,13 +23,17 @@ namespace Artemis.Modules.Games.CounterStrike ProcessName = "csgo"; Scale = 4; - AmmoRect = new KeyboardRectangle(Scale, 0, 0, 84, 24, new List {Color.Blue, Color.Red}, + AmmoRect = new KeyboardRectangle(Scale, 0, 0, 16*Scale, 1*Scale, new List {Color.Blue, Color.Red}, + LinearGradientMode.Horizontal); + TeamRect = new KeyboardRectangle(Scale, 0, 1*Scale, 21*Scale, 8*Scale, new List {Color.CornflowerBlue}, LinearGradientMode.Horizontal); } + public KeyboardRectangle TeamRect { get; set; } + public int Scale { get; set; } - public CounterStrikeJson CsJson { get; set; } + public JObject CsJson { get; set; } public KeyboardRectangle AmmoRect { get; set; } public override void Dispose() @@ -44,19 +48,46 @@ namespace Artemis.Modules.Games.CounterStrike public override void Update() { - if (CsJson?.player.weapons == null) + if (CsJson == null) return; - var activeWeapon = CsJson.player.weapons.FirstOrDefault(w => w.Value.state.Equals("active")); + UpdateAmmo(); + UpdateTeam(); + } + + private void UpdateTeam() + { + var currentTeam = CsJson["player"]["team"]; + if (currentTeam == null) + return; + + TeamRect.Colors = currentTeam.Value() == "T" + ? new List {Color.FromArgb(255, 255, 129, 0)} + : new List {Color.FromArgb(255, 112, 209, 255)}; + } + + private void UpdateAmmo() + { + var activeWeapon = + CsJson["player"]["weapons"].Children() + .Select(c => c.First) + .FirstOrDefault(w => w["state"]?.Value() == "active"); // Update the ammo display - var ammoPercentage = 0; - if (activeWeapon.Value?.ammo_clip_max > 0) - ammoPercentage = - (int) ((Math.Ceiling(100.00/activeWeapon.Value.ammo_clip_max))*activeWeapon.Value.ammo_clip); + if (activeWeapon?["ammo_clip_max"] == null || activeWeapon["ammo_clip"] == null) + return; - AmmoRect.Height = ammoPercentage; - if (ammoPercentage < 30) + var maxAmmo = activeWeapon["ammo_clip_max"].Value(); + var ammo = activeWeapon["ammo_clip"].Value(); + + if (maxAmmo < 0) + return; + + var ammoPercentage = (int) Math.Ceiling(100.00/maxAmmo)*ammo; + AmmoRect.Width = ((int) Math.Floor((16/100.00)*ammoPercentage))*Scale; + + // Low ammo indicator + if (ammoPercentage < 37) AmmoRect.StartBlink(1000); else AmmoRect.StopBlink(); @@ -64,12 +95,13 @@ namespace Artemis.Modules.Games.CounterStrike public override Bitmap GenerateBitmap() { - var bitmap = new Bitmap(21, 6); + var bitmap = new Bitmap(21*Scale, 6*Scale); using (var g = Graphics.FromImage(bitmap)) { g.Clear(Color.Transparent); AmmoRect.Draw(g); + TeamRect.Draw(g); } return bitmap; } @@ -83,7 +115,7 @@ namespace Artemis.Modules.Games.CounterStrike return; // Parse the JSON - CsJson = JsonConvert.DeserializeObject(jsonString); + CsJson = JsonConvert.DeserializeObject(jsonString); } } } \ No newline at end of file diff --git a/Artemis/Artemis/Settings/CounterStrike.Designer.cs b/Artemis/Artemis/Settings/CounterStrike.Designer.cs new file mode 100644 index 000000000..02a6786cb --- /dev/null +++ b/Artemis/Artemis/Settings/CounterStrike.Designer.cs @@ -0,0 +1,38 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Artemis.Settings { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] + internal sealed partial class CounterStrike : global::System.Configuration.ApplicationSettingsBase { + + private static CounterStrike defaultInstance = ((CounterStrike)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new CounterStrike()))); + + public static CounterStrike Default { + get { + return defaultInstance; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("C:\\Program Files (x86)\\Steam\\steamapps\\common\\Counter-Strike Global Offensive")] + public string GameDirectory { + get { + return ((string)(this["GameDirectory"])); + } + set { + this["GameDirectory"] = value; + } + } + } +} diff --git a/Artemis/Artemis/Settings/CounterStrike.settings b/Artemis/Artemis/Settings/CounterStrike.settings new file mode 100644 index 000000000..01f5dc62a --- /dev/null +++ b/Artemis/Artemis/Settings/CounterStrike.settings @@ -0,0 +1,9 @@ + + + + + + C:\Program Files (x86)\Steam\steamapps\common\Counter-Strike Global Offensive + + + \ No newline at end of file diff --git a/Artemis/Artemis/Utilities/GameSense/JsonModels/CounterStrikeJson.cs b/Artemis/Artemis/Utilities/GameSense/JsonModels/CounterStrikeJson.cs deleted file mode 100644 index 4de0b5522..000000000 --- a/Artemis/Artemis/Utilities/GameSense/JsonModels/CounterStrikeJson.cs +++ /dev/null @@ -1,96 +0,0 @@ -using System.Collections.Generic; - -namespace Artemis.Utilities.GameSense.JsonModels -{ - public class CounterStrikeJson - { - public Provider provider { get; set; } - public Map map { get; set; } - public Round round { get; set; } - public Player player { get; set; } - public Auth auth { get; set; } - } - - public class Provider - { - public string name { get; set; } - public int appid { get; set; } - public int version { get; set; } - public string steamid { get; set; } - public int timestamp { get; set; } - } - - public class Map - { - public string name { get; set; } - public string phase { get; set; } - public int round { get; set; } - public Team_Ct team_ct { get; set; } - public Team_T team_t { get; set; } - } - - public class Team_Ct - { - public int score { get; set; } - } - - public class Team_T - { - public int score { get; set; } - } - - public class Round - { - public string phase { get; set; } - } - - public class Player - { - public string steamid { get; set; } - public string name { get; set; } - public string team { get; set; } - public string activity { get; set; } - public State state { get; set; } - public Dictionary weapons { get; set; } - public Match_Stats match_stats { get; set; } - } - - public class State - { - public int health { get; set; } - public int armor { get; set; } - public bool helmet { get; set; } - public int flashed { get; set; } - public int smoked { get; set; } - public int burning { get; set; } - public int money { get; set; } - public int round_kills { get; set; } - public int round_killhs { get; set; } - } - - public class Match_Stats - { - public int kills { get; set; } - public int assists { get; set; } - public int deaths { get; set; } - public int mvps { get; set; } - public int score { get; set; } - } - - public class Weapon - { - public string name { get; set; } - public string paintkit { get; set; } - public string type { get; set; } - public string state { get; set; } - public int ammo_clip { get; set; } - public int ammo_clip_max { get; set; } - public int ammo_reserve { get; set; } - } - - public class Auth - { - public string key1 { get; set; } - public string key2 { get; set; } - } -} \ No newline at end of file