From 23710bdf7aea5891f9c29ed762b3ed9f85a13a15 Mon Sep 17 00:00:00 2001 From: Logan Saso Date: Tue, 8 Mar 2016 19:25:47 -0800 Subject: [PATCH 1/4] Removed useless code --- Artemis/Artemis/App.xaml | 46 +++++++++---------- .../Razer/Utilities/RazerUtilities.cs | 35 +------------- Artemis/Artemis/Utilities/ImageUtilities.cs | 38 --------------- 3 files changed, 25 insertions(+), 94 deletions(-) diff --git a/Artemis/Artemis/App.xaml b/Artemis/Artemis/App.xaml index 110eccc23..bae7d6958 100644 --- a/Artemis/Artemis/App.xaml +++ b/Artemis/Artemis/App.xaml @@ -1,25 +1,25 @@ - - - - - - - - - - - - - - - - - - + xmlns:artemis="clr-namespace:Artemis" + DispatcherUnhandledException="Application_DispatcherUnhandledException" + ShutdownMode="OnExplicitShutdown"> + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Artemis/Artemis/KeyboardProviders/Razer/Utilities/RazerUtilities.cs b/Artemis/Artemis/KeyboardProviders/Razer/Utilities/RazerUtilities.cs index cc33c32d5..07c7a17d7 100644 --- a/Artemis/Artemis/KeyboardProviders/Razer/Utilities/RazerUtilities.cs +++ b/Artemis/Artemis/KeyboardProviders/Razer/Utilities/RazerUtilities.cs @@ -1,6 +1,7 @@ using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; +using Artemis.Utilities; using Corale.Colore.Razer.Keyboard.Effects; namespace Artemis.KeyboardProviders.Razer.Utilities @@ -11,7 +12,7 @@ namespace Artemis.KeyboardProviders.Razer.Utilities { var keyboardGrid = Custom.Create(); if (b.Width > width || b.Height > height) - b = ResizeImage(b, width, height); + b = ImageUtilities.ResizeImage(b, width, height); for (var y = 0; y < b.Height; y++) for (var x = 0; x < b.Width; x++) @@ -19,37 +20,5 @@ namespace Artemis.KeyboardProviders.Razer.Utilities return keyboardGrid; } - - /// - /// Resize the image to the specified width and height. - /// - /// The image to resize. - /// The width to resize to. - /// The height to resize to. - /// The resized image. - public static Bitmap ResizeImage(Image image, int width, int height) - { - var destRect = new Rectangle(0, 0, width, height); - var destImage = new Bitmap(width, height); - - destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution); - - using (var graphics = Graphics.FromImage(destImage)) - { - graphics.CompositingMode = CompositingMode.SourceCopy; - graphics.CompositingQuality = CompositingQuality.HighQuality; - graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; - graphics.SmoothingMode = SmoothingMode.HighQuality; - graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; - - using (var wrapMode = new ImageAttributes()) - { - wrapMode.SetWrapMode(WrapMode.TileFlipXY); - graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode); - } - } - - return destImage; - } } } \ No newline at end of file diff --git a/Artemis/Artemis/Utilities/ImageUtilities.cs b/Artemis/Artemis/Utilities/ImageUtilities.cs index 51a0490e4..64537a075 100644 --- a/Artemis/Artemis/Utilities/ImageUtilities.cs +++ b/Artemis/Artemis/Utilities/ImageUtilities.cs @@ -78,44 +78,6 @@ namespace Artemis.Utilities return result; } - /// - /// Saves an image as a jpeg image, with the given quality - /// - /// Path to which the image would be saved. - /// - /// An integer from 0 to 100, with 100 being the - /// highest quality - /// - /// - /// An invalid value was entered for image quality. - /// - public static void SaveJpeg(string path, Image image, int quality) - { - //ensure the quality is within the correct range - if ((quality < 0) || (quality > 100)) - { - //create the error message - var error = - string.Format( - "Jpeg image quality must be between 0 and 100, with 100 being the highest quality. A value of {0} was specified.", - quality); - //throw a helpful exception - throw new ArgumentOutOfRangeException(error); - } - - //create an encoder parameter for the image quality - var qualityParam = new EncoderParameter(Encoder.Quality, quality); - //get the jpeg codec - var jpegCodec = GetEncoderInfo("image/jpeg"); - - //create a collection of all parameters that we will pass to the encoder - var encoderParams = new EncoderParameters(1); - //set the quality parameter for the codec - encoderParams.Param[0] = qualityParam; - //save the image using the codec and the parameters - image.Save(path, jpegCodec, encoderParams); - } - /// /// Returns the image codec with the given mime type /// From 1db97b73cb81422cc3a868a11460a36d59fed17f Mon Sep 17 00:00:00 2001 From: Logan Saso Date: Tue, 8 Mar 2016 20:41:15 -0800 Subject: [PATCH 2/4] Began Dota2 Support --- Artemis/Artemis/App.config | 9 + Artemis/Artemis/Artemis.csproj | 11 + .../AmbientLightningEffectModel.cs | 272 +++++++++--------- .../Modules/Games/Dota2/Dota2.Designer.cs | 50 ++++ .../Modules/Games/Dota2/Dota2.settings | 12 + .../Artemis/Modules/Games/Dota2/Dota2Model.cs | 78 +++++ .../Modules/Games/Dota2/Dota2Settings.cs | 42 +++ .../Modules/Games/Dota2/Dota2View.xaml | 54 +++- .../Modules/Games/Dota2/Dota2ViewModel.cs | 51 +++- .../Utilities/GameState/GameStateWebServer.cs | 210 +++++++------- Artemis/Artemis/ViewModels/GamesViewModel.cs | 4 +- 11 files changed, 543 insertions(+), 250 deletions(-) create mode 100644 Artemis/Artemis/Modules/Games/Dota2/Dota2.Designer.cs create mode 100644 Artemis/Artemis/Modules/Games/Dota2/Dota2.settings create mode 100644 Artemis/Artemis/Modules/Games/Dota2/Dota2Model.cs create mode 100644 Artemis/Artemis/Modules/Games/Dota2/Dota2Settings.cs 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"> - - + + + + + + + + + + + + + + + + + + + + + + + + +