1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00
This commit is contained in:
SpoinkyNL 2016-03-09 19:19:12 +01:00
commit a31a33a6c9
20 changed files with 1021 additions and 395 deletions

View File

@ -3,6 +3,7 @@
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="Artemis.Modules.Games.Dota2.Dota2" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Modules.Overlays.VolumeDisplay.VolumeDisplay" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Modules.Games.RocketLeague.RocketLeague" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Settings.Offsets" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
@ -22,6 +23,20 @@
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<userSettings>
<Artemis.Modules.Games.Dota2.Dota2>
<setting name="Enabled" serializeAs="String">
<value>True</value>
</setting>
<setting name="GameDirectory" serializeAs="String">
<value />
</setting>
<setting name="CanCastAbility" serializeAs="String">
<value>True</value>
</setting>
<setting name="ShowHealth" serializeAs="String">
<value>True</value>
</setting>
</Artemis.Modules.Games.Dota2.Dota2>
<Artemis.Modules.Overlays.VolumeDisplay.VolumeDisplay>
<setting name="Enabled" serializeAs="String">
<value>True</value>

View File

@ -1,25 +1,25 @@
<Application x:Class="Artemis.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
<Application x:Class="Artemis.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:artemis="clr-namespace:Artemis"
DispatcherUnhandledException="Application_DispatcherUnhandledException"
ShutdownMode="OnExplicitShutdown">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary>
<artemis:ArtemisBootstrapper x:Key="ArtemisBootstrapper" />
</ResourceDictionary>
<!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
<!-- Accent and AppTheme setting -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Teal.xaml" />
<ResourceDictionary
Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
<ResourceDictionary Source="/Resources/Icons.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
xmlns:artemis="clr-namespace:Artemis"
DispatcherUnhandledException="Application_DispatcherUnhandledException"
ShutdownMode="OnExplicitShutdown">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary>
<artemis:ArtemisBootstrapper x:Key="ArtemisBootstrapper" />
</ResourceDictionary>
<!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
<!-- Accent and AppTheme setting -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Teal.xaml" />
<ResourceDictionary
Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
<ResourceDictionary Source="/Resources/Icons.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>

View File

@ -293,6 +293,14 @@
</Compile>
<Compile Include="Modules\Games\CounterStrike\CounterStrikeModel.cs" />
<Compile Include="Modules\Games\CounterStrike\CounterStrikeSettings.cs" />
<Compile Include="Modules\Games\Dota2\Dota2.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<DependentUpon>Dota2.settings</DependentUpon>
</Compile>
<Compile Include="Modules\Games\Dota2\Dota2DataModel.cs" />
<Compile Include="Modules\Games\Dota2\Dota2Model.cs" />
<Compile Include="Modules\Games\Dota2\Dota2Settings.cs" />
<Compile Include="Modules\Games\RocketLeague\RocketLeague.Designer.cs">
<DependentUpon>RocketLeague.settings</DependentUpon>
<AutoGen>True</AutoGen>
@ -430,6 +438,7 @@
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<None Include="Modules\Effects\AudioVisualizer\AudioVisualization.settings">
<Generator>SettingsSingleFileGenerator</Generator>
@ -443,6 +452,10 @@
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>CounterStrike.Designer.cs</LastGenOutput>
</None>
<None Include="Modules\Games\Dota2\Dota2.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Dota2.Designer.cs</LastGenOutput>
</None>
<None Include="Modules\Games\RocketLeague\RocketLeague.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>RocketLeague.Designer.cs</LastGenOutput>
@ -465,6 +478,7 @@
</Content>
<Resource Include="Resources\logo.ico" />
<Resource Include="Resources\logo-disabled.ico" />
<Resource Include="Resources\Dota2\dotaGamestateConfiguration.txt" />
<None Include="Resources\LogitechLED.dll" />
<Content Include="Resources\Witcher3\playerWitcher.txt" />
<Content Include="Resources\Witcher3\artemis.txt" />
@ -559,7 +573,7 @@
<Content Include="LogitechLedEnginesWrapper.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Resources\CounterStrike\gamestateConfiguration.txt" />
<Content Include="Resources\CounterStrike\csgoGamestateConfiguration.txt" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.5.2">

View File

@ -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;
}
/// <summary>
/// Resize the image to the specified width and height.
/// </summary>
/// <param name="image">The image to resize.</param>
/// <param name="width">The width to resize to.</param>
/// <param name="height">The height to resize to.</param>
/// <returns>The resized image.</returns>
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;
}
}
}

View File

@ -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<Color> _colors;
private List<Rectangle> _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<Color>();
_screenCapturer = new ScreenCapture();
_topRect = new KeyboardRectangle(MainManager.KeyboardManager.ActiveKeyboard, 0, 0, new List<Color>(),
LinearGradientMode.Horizontal) {Height = MainManager.KeyboardManager.ActiveKeyboard.Height*Scale/2};
_botRect = new KeyboardRectangle(MainManager.KeyboardManager.ActiveKeyboard, 0, 0, new List<Color>(),
LinearGradientMode.Horizontal);
Initialized = true;
}
public override void Update()
{
var capture = _screenCapturer.Capture();
if (capture == null)
return;
_rectangles = new List<Rectangle>();
// 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<Color>();
// 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<Color> _colors;
private List<Rectangle> _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<Color>();
_screenCapturer = new ScreenCapture();
_topRect = new KeyboardRectangle(MainManager.KeyboardManager.ActiveKeyboard, 0, 0, new List<Color>(),
LinearGradientMode.Horizontal) {Height = MainManager.KeyboardManager.ActiveKeyboard.Height*Scale/2};
_botRect = new KeyboardRectangle(MainManager.KeyboardManager.ActiveKeyboard, 0, 0, new List<Color>(),
LinearGradientMode.Horizontal);
Initialized = true;
}
public override void Update()
{
var capture = _screenCapturer.Capture();
if (capture == null)
return;
_rectangles = new List<Rectangle>();
// 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<Color>();
// 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);
}
}
}

View File

@ -44,7 +44,7 @@ namespace Artemis.Modules.Games.CounterStrike
return;
if (Directory.Exists(((CounterStrikeSettings) GameSettings).GameDirectory + "/csgo/cfg"))
{
var cfgFile = Resources.gamestateConfiguration.Replace("{{port}}",
var cfgFile = Resources.csgoGamestateConfiguration.Replace("{{port}}",
MainManager.GameStateWebServer.Port.ToString());
File.WriteAllText(
((CounterStrikeSettings) GameSettings).GameDirectory + "/csgo/cfg/gamestate_integration_artemis.cfg",

View File

@ -0,0 +1,74 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 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.
// </auto-generated>
//------------------------------------------------------------------------------
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;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("True")]
public bool CanCastAbility {
get {
return ((bool)(this["CanCastAbility"]));
}
set {
this["CanCastAbility"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("True")]
public bool ShowHealth {
get {
return ((bool)(this["ShowHealth"]));
}
set {
this["ShowHealth"] = value;
}
}
}
}

View File

@ -0,0 +1,18 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="Artemis.Modules.Games.Dota2" GeneratedClassName="Dota2">
<Profiles />
<Settings>
<Setting Name="Enabled" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="GameDirectory" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="CanCastAbility" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="ShowHealth" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
</Settings>
</SettingsFile>

View File

@ -0,0 +1,227 @@
namespace Artemis.Modules.Games.Dota2
{
class Dota2DataModel
{
public class Rootobject
{
public Provider provider { get; set; }
public Map map { get; set; }
public Player player { get; set; }
public Hero hero { get; set; }
public Abilities abilities { get; set; }
public Items items { get; set; }
public Previously previously { get; set; }
}
public class Provider
{
public string name { get; set; }
public int appid { get; set; }
public int version { get; set; }
public int timestamp { get; set; }
}
public class Map
{
public string name { get; set; }
public long matchid { get; set; }
public int game_time { get; set; }
public int clock_time { get; set; }
public bool daytime { get; set; }
public bool nightstalker_night { get; set; }
public string game_state { get; set; }
public string win_team { get; set; }
public string customgamename { get; set; }
public int ward_purchase_cooldown { get; set; }
}
public class Player
{
public string steamid { get; set; }
public string name { get; set; }
public string activity { get; set; }
public int kills { get; set; }
public int deaths { get; set; }
public int assists { get; set; }
public int last_hits { get; set; }
public int denies { get; set; }
public int kill_streak { get; set; }
public string team_name { get; set; }
public int gold { get; set; }
public int gold_reliable { get; set; }
public int gold_unreliable { get; set; }
public int gpm { get; set; }
public int xpm { get; set; }
}
public class Hero
{
public int id { get; set; }
public string name { get; set; }
public int level { get; set; }
public bool alive { get; set; }
public int respawn_seconds { get; set; }
public int buyback_cost { get; set; }
public int buyback_cooldown { get; set; }
public int health { get; set; }
public int max_health { get; set; }
public int health_percent { get; set; }
public int mana { get; set; }
public int max_mana { get; set; }
public int mana_percent { get; set; }
public bool silenced { get; set; }
public bool stunned { get; set; }
public bool disarmed { get; set; }
public bool magicimmune { get; set; }
public bool hexed { get; set; }
public bool muted { get; set; }
public bool _break { get; set; }
public bool has_debuff { get; set; }
}
public class Abilities
{
public Ability0 ability0 { get; set; }
public Ability1 ability1 { get; set; }
public Ability2 ability2 { get; set; }
public Ability3 ability3 { get; set; }
public Attributes attributes { get; set; }
}
public class Ability0
{
public string name { get; set; }
public int level { get; set; }
public bool can_cast { get; set; }
public bool passive { get; set; }
public bool ability_active { get; set; }
public int cooldown { get; set; }
public bool ultimate { get; set; }
}
public class Ability1
{
public string name { get; set; }
public int level { get; set; }
public bool can_cast { get; set; }
public bool passive { get; set; }
public bool ability_active { get; set; }
public int cooldown { get; set; }
public bool ultimate { get; set; }
}
public class Ability2
{
public string name { get; set; }
public int level { get; set; }
public bool can_cast { get; set; }
public bool passive { get; set; }
public bool ability_active { get; set; }
public int cooldown { get; set; }
public bool ultimate { get; set; }
}
public class Ability3
{
public string name { get; set; }
public int level { get; set; }
public bool can_cast { get; set; }
public bool passive { get; set; }
public bool ability_active { get; set; }
public int cooldown { get; set; }
public bool ultimate { get; set; }
}
public class Attributes
{
public int level { get; set; }
}
public class Items
{
public Slot0 slot0 { get; set; }
public Slot1 slot1 { get; set; }
public Slot2 slot2 { get; set; }
public Slot3 slot3 { get; set; }
public Slot4 slot4 { get; set; }
public Slot5 slot5 { get; set; }
public Stash0 stash0 { get; set; }
public Stash1 stash1 { get; set; }
public Stash2 stash2 { get; set; }
public Stash3 stash3 { get; set; }
public Stash4 stash4 { get; set; }
public Stash5 stash5 { get; set; }
}
public class Slot0
{
public string name { get; set; }
}
public class Slot1
{
public string name { get; set; }
}
public class Slot2
{
public string name { get; set; }
}
public class Slot3
{
public string name { get; set; }
}
public class Slot4
{
public string name { get; set; }
}
public class Slot5
{
public string name { get; set; }
}
public class Stash0
{
public string name { get; set; }
}
public class Stash1
{
public string name { get; set; }
}
public class Stash2
{
public string name { get; set; }
}
public class Stash3
{
public string name { get; set; }
}
public class Stash4
{
public string name { get; set; }
}
public class Stash5
{
public string name { get; set; }
}
public class Previously
{
public Player1 player { get; set; }
}
public class Player1
{
public int gold { get; set; }
public int gold_unreliable { get; set; }
}
}
}

View File

@ -0,0 +1,118 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Artemis.KeyboardProviders;
using Artemis.Managers;
using Artemis.Models;
using Artemis.Utilities.GameState;
using Artemis.Utilities.Keyboard;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Artemis.Modules.Games.Dota2;
namespace Artemis.Modules.Games.Dota2
{
class Dota2Model : GameModel
{
private KeyboardRegion _topRow;
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 Dota2DataModel.Rootobject D2Json { get; set; }
public int Scale { get; set; }
public KeyboardRectangle HealthRect { get; set; }
#endregion
public override void Dispose()
{
Initialized = false;
MainManager.GameStateWebServer.GameDataReceived -= HandleGameData;
}
public override void Enable()
{
Initialized = false;
_topRow = MainManager.KeyboardManager.ActiveKeyboard.KeyboardRegions.First(r => r.RegionName == "TopRow");
HealthRect = new KeyboardRectangle(MainManager.KeyboardManager.ActiveKeyboard, 0, _topRow.TopLeft.X,
new List<Color>(),
LinearGradientMode.Horizontal)
{ Height = Scale, ContainedBrush = false };
MainManager.GameStateWebServer.GameDataReceived += HandleGameData;
Initialized = true;
}
public override void Update()
{
if (D2Json == null)
return;
if (Settings.CanCastAbility)
UpdateAbilities();
if (Settings.ShowHealth)
UpdateHealth();
}
private void UpdateHealth()
{
var health = D2Json.hero.health_percent;
if(health > 66)
HealthRect.Colors = new List<Color> { Color.Lime };
else if (health > 33)
HealthRect.Colors = new List<Color> {Color.Yellow};
else
HealthRect.Colors = new List<Color> {Color.Red};
}
private void UpdateAbilities()
{
Console.WriteLine();
//Update keys according to the abilities they take.
}
public override Bitmap GenerateBitmap()
{
var bitmap = MainManager.KeyboardManager.ActiveKeyboard.KeyboardBitmap(Scale);
using (var g = Graphics.FromImage(bitmap))
{
g.Clear(Color.Transparent);
HealthRect.Draw(g);
}
return bitmap;
}
public void HandleGameData(object sender, GameDataReceivedEventArgs e)
{
var jsonString = e.Json.ToString();
// Ensure it's Dota 2 JSON
if (!jsonString.Contains("Dota 2"))
return;
// Parse the JSON
D2Json = JsonConvert.DeserializeObject<Dota2DataModel.Rootobject>(jsonString);
}
}
}

View File

@ -0,0 +1,52 @@
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; }
public bool CanCastAbility { get; set; }
public bool ShowHealth { get; set; }
#endregion
public override void Load()
{
ShowHealth = Dota2.Default.ShowHealth;
CanCastAbility = Dota2.Default.CanCastAbility;
Enabled = Dota2.Default.Enabled;
GameDirectory = Dota2.Default.GameDirectory;
}
public override void Save()
{
Dota2.Default.ShowHealth = ShowHealth;
Dota2.Default.CanCastAbility = CanCastAbility;
Dota2.Default.Enabled = Enabled;
Dota2.Default.GameDirectory = GameDirectory;
Dota2.Default.Save();
}
public override void ToDefault()
{
ShowHealth = true;
CanCastAbility = true;
Enabled = false;
GameDirectory = string.Empty;
}
}
}

View File

@ -1,13 +1,88 @@
<UserControl x:Class="Artemis.Modules.Games.Dota2.Dota2View"
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"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
<Grid>
<TextBlock Text="Dota 2 support is still to be done." />
</Grid>
</ScrollViewer>
<UserControl x:Class="Artemis.Modules.Games.Dota2.Dota2View"
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:cal="http://www.caliburnproject.org"
xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
mc:Ignorable="d"
d:DesignHeight="424" d:DesignWidth="635">
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
<Grid Margin="15, 5, 15, 5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="80" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Margin="0,0,1,0">
<Label FontSize="20" HorizontalAlignment="Left">
<Label.Content>
<AccessText TextWrapping="Wrap"
Text="Shows various information Dota 2." />
</Label.Content>
</Label>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<Label Content="Enable effect" Margin="0 3 0 0" HorizontalAlignment="Right" />
<ToggleButton x:Name="EffectEnabled" Margin="0 3 0 0" Width="25" Height="25"
IsChecked="{Binding Path=GameSettings.Enabled, Mode=TwoWay}"
Style="{DynamicResource MetroCircleToggleButtonStyle}"
cal:Message.Attach="[Event Click] = [Action ToggleEffect]" />
</StackPanel>
</StackPanel>
<StackPanel Grid.Row="1"
Grid.Column="0"
Grid.ColumnSpan="2" Margin="0,0,1,0">
<Label FontSize="16" Content="Dota 2 Directory" FontFamily="Segoe UI Semibold" Foreground="#535353"
Width="130" HorizontalAlignment="Left" />
<Grid>
<TextBox x:Name="GameDirectory" Height="23" TextWrapping="Wrap" Margin="5,0,30,0"
Text="{Binding Path=GameSettings.GameDirectory, Mode=TwoWay}"
cal:Message.Attach="[Event LostFocus] = [Action PlaceConfigFile]" />
<Button x:Name="BrowseDirectory" Content="..." RenderTransformOrigin="-0.039,-0.944"
HorizontalAlignment="Right" Width="25"
Style="{DynamicResource SquareButtonStyle}" Height="25" />
</Grid>
</StackPanel>
<!-- Abilities Display -->
<TextBlock Grid.Row="2" Grid.Column="0" HorizontalAlignment="Left" Width="168" VerticalAlignment="Center"
Height="16" Margin="0,10,0,9">
Show abilities that can be cast.
</TextBlock>
<controls:ToggleSwitch IsChecked="{Binding Path=GameSettings.CanCastAbility, Mode=TwoWay}"
Grid.Row="2" Grid.Column="1" HorizontalAlignment="Right" OnLabel="Yes" OffLabel="No"
Margin="0,0,-5,0" Width="114" />
<!-- Health Display -->
<TextBlock Grid.Row="3" Grid.Column="0" HorizontalAlignment="Left" Width="168" VerticalAlignment="Center"
Height="16" Margin="0,10,0,9">
Show health on F-Keys.
</TextBlock>
<controls:ToggleSwitch IsChecked="{Binding Path=GameSettings.ShowHealth, Mode=TwoWay}"
Grid.Row="3" Grid.Column="1" HorizontalAlignment="Right" OnLabel="Yes" OffLabel="No"
Margin="0,0,-5,0" Width="114" />
<StackPanel Grid.Column="0" Grid.Row="9" Orientation="Horizontal" VerticalAlignment="Bottom">
<Button x:Name="ResetSettings" Content="Reset effect" VerticalAlignment="Top" Width="100"
Style="{DynamicResource SquareButtonStyle}" />
<Button x:Name="SaveSettings" Content="Save changes" VerticalAlignment="Top" Width="100"
Margin="10,0,0,0"
Style="{DynamicResource SquareButtonStyle}" />
</StackPanel>
</Grid>
</ScrollViewer>
</UserControl>

View File

@ -1,16 +1,73 @@
using Artemis.Managers;
using Artemis.ViewModels.Abstract;
namespace Artemis.Modules.Games.Dota2
{
public class Dota2ViewModel : GameViewModel
{
public Dota2ViewModel(MainManager mainManager)
{
MainManager = mainManager;
}
public static string Name => "Dota 2 (NYI)";
public string Content => "Dota 2 Content";
}
using System;
using System.IO;
using System.Windows.Forms;
using Artemis.Managers;
using Artemis.Properties;
using Artemis.ViewModels.Abstract;
namespace Artemis.Modules.Games.Dota2
{
public class Dota2ViewModel : GameViewModel
{
public Dota2ViewModel(MainManager mainManager)
{
MainManager = mainManager;
GameSettings = new Dota2Settings();
GameModel = new Dota2Model(mainManager, (Dota2Settings) GameSettings);
MainManager.EffectManager.EffectModels.Add(GameModel);
PlaceConfigFile();
}
public static string Name => "Dota 2";
public string Content => "Dota 2 Content";
public void BrowseDirectory()
{
var dialog = new FolderBrowserDialog { SelectedPath = ((Dota2Settings)GameSettings).GameDirectory };
var result = dialog.ShowDialog();
if (result != DialogResult.OK)
return;
((Dota2Settings)GameSettings).GameDirectory = dialog.SelectedPath;
NotifyOfPropertyChange(() => GameSettings);
GameSettings.Save();
PlaceConfigFile();
}
public void PlaceConfigFile()
{
if (((Dota2Settings)GameSettings).GameDirectory == string.Empty)
return;
if (Directory.Exists(((Dota2Settings)GameSettings).GameDirectory + "/game/dota/cfg"))
{
var cfgFile = Resources.dotaGamestateConfiguration.Replace("{{port}}",
MainManager.GameStateWebServer.Port.ToString());
try
{
File.WriteAllText(
((Dota2Settings)GameSettings).GameDirectory + "/game/dota/cfg/gamestate_integration/gamestate_integration_artemis.cfg",
cfgFile);
}
catch (DirectoryNotFoundException)
{
Directory.CreateDirectory(((Dota2Settings) GameSettings).GameDirectory + "/game/dota/cfg/gamestate_integration/");
File.WriteAllText(
((Dota2Settings)GameSettings).GameDirectory + "/game/dota/cfg/gamestate_integration/gamestate_integration_artemis.cfg",
cfgFile);
}
return;
}
MainManager.DialogService.ShowErrorMessageBox("Please select a valid Dota 2 directory\n\n" +
@"By default Dota 2 is in \SteamApps\common\Dota2");
((Dota2Settings)GameSettings).GameDirectory = string.Empty;
NotifyOfPropertyChange(() => GameSettings);
GameSettings.Save();
}
}
}

View File

@ -61,14 +61,14 @@ namespace Artemis.Properties {
}
/// <summary>
/// Looks up a localized string similar to &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-16&quot;?&gt;
///&lt;!-- Used by Artemis to get the active Sign --&gt;
///&lt;UserConfig&gt;
/// &lt;Group id=&quot;Artemis&quot; displayName=&quot;Artemis&quot;&gt;
/// &lt;VisibleVars&gt;
/// &lt;Var id=&quot;ActiveSign&quot; displayName=&quot;ActiveSign&quot; displayType=&quot;SLIDER:0:1:1000000&quot;/&gt;
/// &lt;/VisibleVars&gt;
/// &lt;/Group&gt;
/// Looks up a localized string similar to &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-16&quot;?&gt;
///&lt;!-- Used by Artemis to get the active Sign --&gt;
///&lt;UserConfig&gt;
/// &lt;Group id=&quot;Artemis&quot; displayName=&quot;Artemis&quot;&gt;
/// &lt;VisibleVars&gt;
/// &lt;Var id=&quot;ActiveSign&quot; displayName=&quot;ActiveSign&quot; displayType=&quot;SLIDER:0:1:1000000&quot;/&gt;
/// &lt;/VisibleVars&gt;
/// &lt;/Group&gt;
///&lt;/UserConfig&gt;.
/// </summary>
internal static string artemisXml {
@ -88,28 +88,53 @@ namespace Artemis.Properties {
}
/// <summary>
/// Looks up a localized string similar to &quot;Artemis&quot;
///{
/// &quot;uri&quot; &quot;http://localhost:{{port}}/csgo_game_event&quot;
/// &quot;timeout&quot; &quot;5.0&quot;
/// &quot;buffer&quot; &quot;0.1&quot;
/// &quot;throttle&quot; &quot;0.1&quot;
/// &quot;heartbeat&quot; &quot;30.0&quot;
/// &quot;data&quot;
/// {
/// &quot;provider&quot; &quot;1&quot;
/// &quot;map&quot; &quot;1&quot;
/// &quot;round&quot; &quot;1&quot;
/// &quot;player_id&quot; &quot;1&quot;
/// &quot;player_state&quot; &quot;1&quot;
/// &quot;player_weapons&quot; &quot;1&quot;
/// &quot;player_match_stats&quot; &quot;1&quot;
/// }
/// Looks up a localized string similar to &quot;Artemis&quot;
///{
/// &quot;uri&quot; &quot;http://localhost:{{port}}/csgo_game_event&quot;
/// &quot;timeout&quot; &quot;5.0&quot;
/// &quot;buffer&quot; &quot;0.1&quot;
/// &quot;throttle&quot; &quot;0.1&quot;
/// &quot;heartbeat&quot; &quot;30.0&quot;
/// &quot;data&quot;
/// {
/// &quot;provider&quot; &quot;1&quot;
/// &quot;map&quot; &quot;1&quot;
/// &quot;round&quot; &quot;1&quot;
/// &quot;player_id&quot; &quot;1&quot;
/// &quot;player_state&quot; &quot;1&quot;
/// &quot;player_weapons&quot; &quot;1&quot;
/// &quot;player_match_stats&quot; &quot;1&quot;
/// }
///}.
/// </summary>
internal static string gamestateConfiguration {
internal static string csgoGamestateConfiguration {
get {
return ResourceManager.GetString("gamestateConfiguration", resourceCulture);
return ResourceManager.GetString("csgoGamestateConfiguration", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to &quot;Artemis&quot;
///{
/// &quot;uri&quot; &quot;http://localhost:4000/&quot;
/// &quot;timeout&quot; &quot;5.0&quot;
/// &quot;buffer&quot; &quot;0.1&quot;
/// &quot;throttle&quot; &quot;0.1&quot;
/// &quot;heartbeat&quot; &quot;30.0&quot;
/// &quot;data&quot;
/// {
/// &quot;provider&quot; &quot;1&quot;
/// &quot;map&quot; &quot;1&quot;
/// &quot;player&quot; &quot;1&quot;
/// &quot;hero&quot; &quot;1&quot;
/// &quot;abilities&quot; &quot;1&quot;
/// &quot;items&quot; &quot;1&quot;
/// }
///}.
/// </summary>
internal static string dotaGamestateConfiguration {
get {
return ResourceManager.GetString("dotaGamestateConfiguration", resourceCulture);
}
}

View File

@ -124,8 +124,11 @@
<data name="bow" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\bow.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="gamestateConfiguration" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\resources\counterstrike\gamestateconfiguration.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
<data name="csgoGamestateConfiguration" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\resources\counterstrike\csgoGamestateconfiguration.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data>
<data name="dotaGamestateConfiguration" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\resources\dota2\dotaGamestateconfiguration.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data>
<data name="LogitechLED" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\LogitechLED.dll;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>

View File

@ -0,0 +1,17 @@
"Artemis"
{
"uri" "http://localhost:{{port}}/"
"timeout" "5.0"
"buffer" "0.1"
"throttle" "0.1"
"heartbeat" "30.0"
"data"
{
"provider" "1"
"map" "1"
"player" "1"
"hero" "1"
"abilities" "1"
"items" "1"
}
}

View File

@ -1,110 +1,110 @@
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using Artemis.Settings;
using Newtonsoft.Json;
namespace Artemis.Utilities.GameState
{
public class GameStateWebServer
{
public delegate void GameDataReceivedEventHandler(
object sender, GameDataReceivedEventArgs gameDataReceivedEventArgs);
private readonly HttpListener _listener = new HttpListener();
public GameStateWebServer()
{
Start();
}
public int Port { get; private set; }
public bool Running { get; private set; }
public event GameDataReceivedEventHandler GameDataReceived;
public void Start()
{
if (Running)
return;
try
{
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using Artemis.Settings;
using Newtonsoft.Json;
namespace Artemis.Utilities.GameState
{
public class GameStateWebServer
{
public delegate void GameDataReceivedEventHandler(
object sender, GameDataReceivedEventArgs gameDataReceivedEventArgs);
private readonly HttpListener _listener = new HttpListener();
public GameStateWebServer()
{
Start();
}
public int Port { get; private set; }
public bool Running { get; private set; }
public event GameDataReceivedEventHandler GameDataReceived;
public void Start()
{
if (Running)
return;
try
{
_listener.Prefixes.Clear();
Port = General.Default.GamestatePort;
_listener.Prefixes.Add($"http://localhost:{Port}/");
_listener.Start();
}
catch (Exception)
{
MessageBox.Show("Couldn't start the webserver. CS:GO effect won't work :c \n\nTry changing the port in Settings and restart Artemis.");
}
ThreadPool.QueueUserWorkItem(o =>
{
try
{
while (_listener.IsListening)
{
ThreadPool.QueueUserWorkItem(c =>
{
var ctx = c as HttpListenerContext;
if (ctx == null)
return;
try
{
var rstr = HandleRequest(ctx.Request);
var buf = Encoding.UTF8.GetBytes(rstr);
ctx.Response.ContentLength64 = buf.Length;
ctx.Response.OutputStream.Write(buf, 0, buf.Length);
}
catch
{
// ignored
}
finally
{
// always close the stream
ctx.Response.OutputStream.Close();
}
}, _listener.GetContext());
}
}
catch
{
// ignored
}
});
Running = true;
}
public void Stop()
{
_listener.Stop();
}
private string HandleRequest(HttpListenerRequest request)
{
object json;
using (var reader = new StreamReader(request.InputStream, request.ContentEncoding))
{
var result = reader.ReadToEnd();
json = JsonConvert.DeserializeObject<object>(result);
}
if (json != null)
OnGameDataReceived(new GameDataReceivedEventArgs(json));
return JsonConvert.SerializeObject(json);
}
protected virtual void OnGameDataReceived(GameDataReceivedEventArgs e)
{
GameDataReceived?.Invoke(this, e);
}
}
_listener.Start();
}
catch (Exception)
{
MessageBox.Show("Couldn't start the webserver. CS:GO/Dota2 effects won't work :c \n\nTry changing the port in Settings and restart Artemis.");
}
ThreadPool.QueueUserWorkItem(o =>
{
try
{
while (_listener.IsListening)
{
ThreadPool.QueueUserWorkItem(c =>
{
var ctx = c as HttpListenerContext;
if (ctx == null)
return;
try
{
var rstr = HandleRequest(ctx.Request);
var buf = Encoding.UTF8.GetBytes(rstr);
ctx.Response.ContentLength64 = buf.Length;
ctx.Response.OutputStream.Write(buf, 0, buf.Length);
}
catch
{
// ignored
}
finally
{
// always close the stream
ctx.Response.OutputStream.Close();
}
}, _listener.GetContext());
}
}
catch
{
// ignored
}
});
Running = true;
}
public void Stop()
{
_listener.Stop();
}
private string HandleRequest(HttpListenerRequest request)
{
object json;
using (var reader = new StreamReader(request.InputStream, request.ContentEncoding))
{
var result = reader.ReadToEnd();
json = JsonConvert.DeserializeObject<object>(result);
}
if (json != null)
OnGameDataReceived(new GameDataReceivedEventArgs(json));
return JsonConvert.SerializeObject(json);
}
protected virtual void OnGameDataReceived(GameDataReceivedEventArgs e)
{
GameDataReceived?.Invoke(this, e);
}
}
}

View File

@ -78,44 +78,6 @@ namespace Artemis.Utilities
return result;
}
/// <summary>
/// Saves an image as a jpeg image, with the given quality
/// </summary>
/// <param name="path">Path to which the image would be saved.</param>
/// <param name="quality">
/// An integer from 0 to 100, with 100 being the
/// highest quality
/// </param>
/// <exception cref="ArgumentOutOfRangeException">
/// An invalid value was entered for image quality.
/// </exception>
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);
}
/// <summary>
/// Returns the image codec with the given mime type
/// </summary>

View File

@ -18,7 +18,7 @@ namespace Artemis.ViewModels
{
_rocketLeagueVm = new RocketLeagueViewModel(mainManager) {DisplayName = "Rocket League"};
_counterStrikeVm = new CounterStrikeViewModel(mainManager) {DisplayName = "CS:GO"};
//_dota2Vm = new Dota2ViewModel(MainManager) {DisplayName = "Dota 2 (NYI)"};
_dota2Vm = new Dota2ViewModel(mainManager) {DisplayName = "Dota 2"};
_witcher3Vm = new Witcher3ViewModel(mainManager) {DisplayName = "The Witcher 3"};
}
@ -28,7 +28,7 @@ namespace Artemis.ViewModels
ActivateItem(_rocketLeagueVm);
ActivateItem(_counterStrikeVm);
//ActivateItem(_dota2Vm);
ActivateItem(_dota2Vm);
ActivateItem(_witcher3Vm);
}
}