diff --git a/Artemis/Artemis/App.config b/Artemis/Artemis/App.config index eb58324d3..0de9f6336 100644 --- a/Artemis/Artemis/App.config +++ b/Artemis/Artemis/App.config @@ -3,6 +3,7 @@ +
@@ -22,6 +23,14 @@ + + + True + + + + + True diff --git a/Artemis/Artemis/Artemis.csproj b/Artemis/Artemis/Artemis.csproj index 16aba318b..0f459c912 100644 --- a/Artemis/Artemis/Artemis.csproj +++ b/Artemis/Artemis/Artemis.csproj @@ -292,6 +292,13 @@ + + True + True + Dota2.settings + + + RocketLeague.settings True @@ -441,6 +448,10 @@ SettingsSingleFileGenerator CounterStrike.Designer.cs + + SettingsSingleFileGenerator + Dota2.Designer.cs + SettingsSingleFileGenerator RocketLeague.Designer.cs diff --git a/Artemis/Artemis/Modules/Effects/AmbientLightning/AmbientLightningEffectModel.cs b/Artemis/Artemis/Modules/Effects/AmbientLightning/AmbientLightningEffectModel.cs index 3fc79e42a..8f97f156c 100644 --- a/Artemis/Artemis/Modules/Effects/AmbientLightning/AmbientLightningEffectModel.cs +++ b/Artemis/Artemis/Modules/Effects/AmbientLightning/AmbientLightningEffectModel.cs @@ -1,139 +1,139 @@ -using System.Collections.Generic; -using System.Drawing; -using System.Drawing.Drawing2D; -using System.IO; -using System.Linq; -using System.Windows.Forms; -using Artemis.Managers; -using Artemis.Models; -using Artemis.Utilities; -using Artemis.Utilities.Keyboard; -using Kaliko.ImageLibrary; -using Kaliko.ImageLibrary.Filters; - -namespace Artemis.Modules.Effects.AmbientLightning -{ - internal class AmbientLightningEffectModel : EffectModel - { - private KeyboardRectangle _botRect; - private List _colors; - private List _rectangles; - private ScreenCapture _screenCapturer; - private KeyboardRectangle _topRect; - - public AmbientLightningEffectModel(MainManager mainManager, AmbientLightningEffectSettings settings) - : base(mainManager) - { - Name = "Ambient Lightning"; - Settings = settings; - Scale = 4; - Initialized = false; - } - - public int Scale { get; set; } - - public AmbientLightningEffectSettings Settings { get; set; } - - public KeyboardRectangle KeyboardRectangle { get; set; } - - public override void Dispose() - { - Initialized = false; - - _screenCapturer.Dispose(); - _screenCapturer = null; - } - - public override void Enable() - { - Initialized = false; - - _colors = new List(); - _screenCapturer = new ScreenCapture(); - _topRect = new KeyboardRectangle(MainManager.KeyboardManager.ActiveKeyboard, 0, 0, new List(), - LinearGradientMode.Horizontal) {Height = MainManager.KeyboardManager.ActiveKeyboard.Height*Scale/2}; - _botRect = new KeyboardRectangle(MainManager.KeyboardManager.ActiveKeyboard, 0, 0, new List(), - LinearGradientMode.Horizontal); - - Initialized = true; - } - - public override void Update() - { - var capture = _screenCapturer.Capture(); - if (capture == null) - return; - - _rectangles = new List(); - // Analise the result - // Chop the screen into 2 rows and 3 columns - var resolution = Screen.PrimaryScreen.Bounds; - var blockWidth = resolution.Width/3; - var blockHeight = resolution.Height/2; - var colorIndex = 0; - for (var row = 0; row < 2; row++) - { - for (var column = 0; column < 3; column++) - { - var blockBase = new Point(blockWidth*column, blockHeight*row); - var samples = new List(); - // For each block, take samples - for (var blockRow = 0; blockRow < 6; blockRow++) - { - for (var blockColumn = 0; blockColumn < 6; blockColumn++) - { - var x = blockWidth/6*blockColumn + blockWidth/6/4 + blockBase.X; - var y = blockHeight/6*blockRow + blockHeight/6/4 + blockBase.Y; - samples.Add(_screenCapturer.GetColor(capture, new Point(x, y))); - } - } - - // Take the average of the samples - var averageR = samples.Sum(s => s.R)/samples.Count; - var averageG = samples.Sum(s => s.G)/samples.Count; - var averageB = samples.Sum(s => s.B)/samples.Count; - - if (_colors.Count <= colorIndex) - _colors.Add(Color.FromArgb(255, averageR, averageG, averageB)); - else - _colors[colorIndex] = Color.FromArgb(255, (averageR + _colors[colorIndex].R * 5) / 6, (averageG + _colors[colorIndex].G * 5) / 6, (averageB + _colors[colorIndex].B * 5) / 6); - colorIndex++; - } - } - - // Put the resulting colors in 6 rectangles, their size differs per keyboard - var rectWidth = MainManager.KeyboardManager.ActiveKeyboard.Width/3*Scale; - var rectHeight = MainManager.KeyboardManager.ActiveKeyboard.Height/2*Scale; - for (var row = 0; row < 2; row++) - { - for (var column = 0; column < 3; column++) - { - var rectBase = new Point(rectWidth * column, rectHeight * row); - _rectangles.Add(new Rectangle(rectBase.X, rectBase.Y, rectWidth, rectHeight)); - } - } - } - - public override Bitmap GenerateBitmap() - { - var bitmap = MainManager.KeyboardManager.ActiveKeyboard.KeyboardBitmap(Scale); - using (var g = Graphics.FromImage(bitmap)) - { - var i = 0; - foreach (var rectangle in _rectangles) - { - g.FillRectangle(new SolidBrush(_colors[i]), rectangle); - i++; - } - } - - var test = new KalikoImage(bitmap); - test.ApplyFilter(new GaussianBlurFilter(8f)); +using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Drawing2D; +using System.IO; +using System.Linq; +using System.Windows.Forms; +using Artemis.Managers; +using Artemis.Models; +using Artemis.Utilities; +using Artemis.Utilities.Keyboard; +using Kaliko.ImageLibrary; +using Kaliko.ImageLibrary.Filters; + +namespace Artemis.Modules.Effects.AmbientLightning +{ + internal class AmbientLightningEffectModel : EffectModel + { + private KeyboardRectangle _botRect; + private List _colors; + private List _rectangles; + private ScreenCapture _screenCapturer; + private KeyboardRectangle _topRect; + + public AmbientLightningEffectModel(MainManager mainManager, AmbientLightningEffectSettings settings) + : base(mainManager) + { + Name = "Ambient Lightning"; + Settings = settings; + Scale = 4; + Initialized = false; + } + + public int Scale { get; set; } + + public AmbientLightningEffectSettings Settings { get; set; } + + public KeyboardRectangle KeyboardRectangle { get; set; } + + public override void Dispose() + { + Initialized = false; + + _screenCapturer.Dispose(); + _screenCapturer = null; + } + + public override void Enable() + { + Initialized = false; + + _colors = new List(); + _screenCapturer = new ScreenCapture(); + _topRect = new KeyboardRectangle(MainManager.KeyboardManager.ActiveKeyboard, 0, 0, new List(), + LinearGradientMode.Horizontal) {Height = MainManager.KeyboardManager.ActiveKeyboard.Height*Scale/2}; + _botRect = new KeyboardRectangle(MainManager.KeyboardManager.ActiveKeyboard, 0, 0, new List(), + LinearGradientMode.Horizontal); + + Initialized = true; + } + + public override void Update() + { + var capture = _screenCapturer.Capture(); + if (capture == null) + return; + + _rectangles = new List(); + // Analise the result + // Chop the screen into 2 rows and 3 columns + var resolution = Screen.PrimaryScreen.Bounds; + var blockWidth = resolution.Width/3; + var blockHeight = resolution.Height/2; + var colorIndex = 0; + for (var row = 0; row < 2; row++) + { + for (var column = 0; column < 3; column++) + { + var blockBase = new Point(blockWidth*column, blockHeight*row); + var samples = new List(); + // For each block, take samples + for (var blockRow = 0; blockRow < 6; blockRow++) + { + for (var blockColumn = 0; blockColumn < 6; blockColumn++) + { + var x = blockWidth/6*blockColumn + blockWidth/6/4 + blockBase.X; + var y = blockHeight/6*blockRow + blockHeight/6/4 + blockBase.Y; + samples.Add(_screenCapturer.GetColor(capture, new Point(x, y))); + } + } + + // Take the average of the samples + var averageR = samples.Sum(s => s.R)/samples.Count; + var averageG = samples.Sum(s => s.G)/samples.Count; + var averageB = samples.Sum(s => s.B)/samples.Count; + + if (_colors.Count <= colorIndex) + _colors.Add(Color.FromArgb(255, averageR, averageG, averageB)); + else + _colors[colorIndex] = Color.FromArgb(255, (averageR + _colors[colorIndex].R * 5) / 6, (averageG + _colors[colorIndex].G * 5) / 6, (averageB + _colors[colorIndex].B * 5) / 6); + colorIndex++; + } + } + + // Put the resulting colors in 6 rectangles, their size differs per keyboard + var rectWidth = MainManager.KeyboardManager.ActiveKeyboard.Width/3*Scale; + var rectHeight = MainManager.KeyboardManager.ActiveKeyboard.Height/2*Scale; + for (var row = 0; row < 2; row++) + { + for (var column = 0; column < 3; column++) + { + var rectBase = new Point(rectWidth * column, rectHeight * row); + _rectangles.Add(new Rectangle(rectBase.X, rectBase.Y, rectWidth, rectHeight)); + } + } + } + + public override Bitmap GenerateBitmap() + { + var bitmap = MainManager.KeyboardManager.ActiveKeyboard.KeyboardBitmap(Scale); + using (var g = Graphics.FromImage(bitmap)) + { + var i = 0; + foreach (var rectangle in _rectangles) + { + g.FillRectangle(new SolidBrush(_colors[i]), rectangle); + i++; + } + } + + var test = new KalikoImage(bitmap); + test.ApplyFilter(new GaussianBlurFilter(8f)); var ms = new MemoryStream(); test.SaveBmp(ms); - ms.Position = 0; - return new Bitmap(ms); - - } - } + ms.Position = 0; + return new Bitmap(ms); + + } + } } \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Games/Dota2/Dota2.Designer.cs b/Artemis/Artemis/Modules/Games/Dota2/Dota2.Designer.cs new file mode 100644 index 000000000..6f9530bef --- /dev/null +++ b/Artemis/Artemis/Modules/Games/Dota2/Dota2.Designer.cs @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// 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.Modules.Games.Dota2 { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] + internal sealed partial class Dota2 : global::System.Configuration.ApplicationSettingsBase { + + private static Dota2 defaultInstance = ((Dota2)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Dota2()))); + + public static Dota2 Default { + get { + return defaultInstance; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool Enabled { + get { + return ((bool)(this["Enabled"])); + } + set { + this["Enabled"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string GameDirectory { + get { + return ((string)(this["GameDirectory"])); + } + set { + this["GameDirectory"] = value; + } + } + } +} diff --git a/Artemis/Artemis/Modules/Games/Dota2/Dota2.settings b/Artemis/Artemis/Modules/Games/Dota2/Dota2.settings new file mode 100644 index 000000000..a9a33f1de --- /dev/null +++ b/Artemis/Artemis/Modules/Games/Dota2/Dota2.settings @@ -0,0 +1,12 @@ + + + + + + True + + + + + + \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Games/Dota2/Dota2Model.cs b/Artemis/Artemis/Modules/Games/Dota2/Dota2Model.cs new file mode 100644 index 000000000..a5fbff92b --- /dev/null +++ b/Artemis/Artemis/Modules/Games/Dota2/Dota2Model.cs @@ -0,0 +1,78 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Artemis.Managers; +using Artemis.Models; +using Artemis.Utilities.GameState; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; + +namespace Artemis.Modules.Games.Dota2 +{ + class Dota2Model : GameModel + { + public Dota2Model(MainManager mainManager, Dota2Settings settings) : base(mainManager) + { + Settings = settings; + Name = "Dota2"; + ProcessName = "dota2"; + Enabled = Settings.Enabled; + Initialized = false; + Scale = 4; + } + + #region Variables + + public Dota2Settings Settings { get; set; } + public JObject D2Json { get; set; } + public int Scale { get; set; } + #endregion + + + public override void Dispose() + { + Initialized = false; + MainManager.GameStateWebServer.GameDataReceived -= HandleGameData; + } + + public override void Enable() + { + Initialized = false; + + MainManager.GameStateWebServer.GameDataReceived += HandleGameData; + Initialized = true; + } + + public override void Update() + { + throw new NotImplementedException(); + } + + public override Bitmap GenerateBitmap() + { + var bitmap = MainManager.KeyboardManager.ActiveKeyboard.KeyboardBitmap(Scale); + + using (var g = Graphics.FromImage(bitmap)) + { + g.Clear(Color.Transparent); + } + return bitmap; + } + + + public void HandleGameData(object sender, GameDataReceivedEventArgs e) + { + var jsonString = e.Json.ToString(); + + // Ensure it's CS:GO JSON + if (!jsonString.Contains("Dota 2")) + return; + + // Parse the JSON + D2Json = JsonConvert.DeserializeObject(jsonString); + } + } +} diff --git a/Artemis/Artemis/Modules/Games/Dota2/Dota2Settings.cs b/Artemis/Artemis/Modules/Games/Dota2/Dota2Settings.cs new file mode 100644 index 000000000..6ee180183 --- /dev/null +++ b/Artemis/Artemis/Modules/Games/Dota2/Dota2Settings.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Artemis.Models; + +namespace Artemis.Modules.Games.Dota2 +{ + class Dota2Settings : GameSettings + { + + public Dota2Settings() + { + Load(); + } + + + #region Variables + public string GameDirectory { get; set; } + #endregion + + + public override void Load() + { + Enabled = Dota2.Default.Enabled; + GameDirectory = Dota2.Default.GameDirectory; + } + + public override void Save() + { + Dota2.Default.Enabled = Enabled; + Dota2.Default.GameDirectory = GameDirectory; + } + + public override void ToDefault() + { + Enabled = false; + GameDirectory = string.Empty; + } + } +} diff --git a/Artemis/Artemis/Modules/Games/Dota2/Dota2View.xaml b/Artemis/Artemis/Modules/Games/Dota2/Dota2View.xaml index deffd25e7..903ad837d 100644 --- a/Artemis/Artemis/Modules/Games/Dota2/Dota2View.xaml +++ b/Artemis/Artemis/Modules/Games/Dota2/Dota2View.xaml @@ -2,12 +2,58 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:cal="http://www.caliburnproject.org" mc:Ignorable="d" - d:DesignHeight="300" d:DesignWidth="300"> + d:DesignHeight="424" d:DesignWidth="635"> - - + + + + + + + + + + + + + + + + + + + + + + + + +