1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-12 21:38:38 +00:00

Began Dota2 Support

This commit is contained in:
Logan Saso 2016-03-08 20:41:15 -08:00
parent 23710bdf7a
commit 1db97b73cb
11 changed files with 543 additions and 250 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,14 @@
<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>
</Artemis.Modules.Games.Dota2.Dota2>
<Artemis.Modules.Overlays.VolumeDisplay.VolumeDisplay>
<setting name="Enabled" serializeAs="String">
<value>True</value>

View File

@ -292,6 +292,13 @@
</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\Dota2Model.cs" />
<Compile Include="Modules\Games\Dota2\Dota2Settings.cs" />
<Compile Include="Modules\Games\RocketLeague\RocketLeague.Designer.cs">
<DependentUpon>RocketLeague.settings</DependentUpon>
<AutoGen>True</AutoGen>
@ -441,6 +448,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>

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

@ -0,0 +1,50 @@
//------------------------------------------------------------------------------
// <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;
}
}
}
}

View File

@ -0,0 +1,12 @@
<?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>
</Settings>
</SettingsFile>

View File

@ -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<JObject>(jsonString);
}
}
}

View File

@ -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;
}
}
}

View File

@ -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">
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
<Grid>
<TextBlock Text="Dota 2 support is still to be done." />
<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>
</Grid>
</ScrollViewer>
</UserControl>

View File

@ -1,4 +1,7 @@
using Artemis.Managers;
using System.IO;
using System.Windows.Forms;
using Artemis.Managers;
using Artemis.Properties;
using Artemis.ViewModels.Abstract;
namespace Artemis.Modules.Games.Dota2
@ -8,9 +11,51 @@ namespace Artemis.Modules.Games.Dota2
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 (NYI)";
public string Content => "Dota 2 Content";
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 + "/dota2/cfg"))
{
var cfgFile = Resources.gamestateConfiguration.Replace("{{port}}",
MainManager.GameStateWebServer.Port.ToString());
File.WriteAllText(
((Dota2Settings)GameSettings).GameDirectory + "/dota2/cfg/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

@ -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

@ -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);
}
}