Compare commits
11 Commits
905a278bb1
...
3dabf95bb0
Author | SHA1 | Date | |
---|---|---|---|
3dabf95bb0 | |||
24821b84e9 | |||
18543a14e5 | |||
48097a6319 | |||
bf2acf6835 | |||
f3fd128173 | |||
f3dabc0e3f | |||
fb23f94e4e | |||
e5ba8b1871 | |||
5e4d9599ba | |||
bc25d7d384 |
6
OpenCS2hock.sln.DotSettings
Normal file
6
OpenCS2hock.sln.DotSettings
Normal file
@ -0,0 +1,6 @@
|
||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=CS/@EntryIndexedValue">CS</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=GSI/@EntryIndexedValue">GSI</s:String>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=appmanifest/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=libraryfolders/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=steamapps/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
3
OpenCS2hock.sln.DotSettings.user
Normal file
3
OpenCS2hock.sln.DotSettings.user
Normal file
@ -0,0 +1,3 @@
|
||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=OpenCS2hock_002FResources/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/ResxEditorPersonal/Initialized/@EntryValue">True</s:Boolean></wpf:ResourceDictionary>
|
50
OpenCS2hock/GSIServer.cs
Normal file
50
OpenCS2hock/GSIServer.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenCS2hock;
|
||||
|
||||
public class GSIServer
|
||||
{
|
||||
private HttpListener HttpListener { get; init; }
|
||||
public delegate void OnMessageEventHandler(string content);
|
||||
public event OnMessageEventHandler? OnMessage;
|
||||
|
||||
private bool _keepRunning = true;
|
||||
public bool IsRunning { get; private set; }
|
||||
|
||||
public GSIServer(int port)
|
||||
{
|
||||
HttpListener = new HttpListener();
|
||||
HttpListener.Prefixes.Add($"http://127.0.0.1:{port}/");
|
||||
HttpListener.Start();
|
||||
|
||||
Thread connectionListener = new (HandleConnection);
|
||||
connectionListener.Start();
|
||||
}
|
||||
|
||||
private async void HandleConnection()
|
||||
{
|
||||
while (_keepRunning)
|
||||
{
|
||||
HttpListenerContext context = await HttpListener.GetContextAsync();
|
||||
HttpListenerRequest request = context.Request;
|
||||
|
||||
Console.WriteLine($"[{request.HttpMethod}] {request.Url} - {request.UserAgent}");
|
||||
|
||||
HttpResponseMessage responseMessage = new HttpResponseMessage(HttpStatusCode.Accepted);
|
||||
context.Response.OutputStream.Write(Encoding.UTF8.GetBytes(responseMessage.ToString()));
|
||||
|
||||
StreamReader reader = new StreamReader(request.InputStream, request.ContentEncoding);
|
||||
string content = await reader.ReadToEndAsync();
|
||||
Console.WriteLine(content);
|
||||
OnMessage?.Invoke(content);
|
||||
}
|
||||
HttpListener.Close();
|
||||
IsRunning = false;
|
||||
}
|
||||
|
||||
internal void Dispose()
|
||||
{
|
||||
_keepRunning = false;
|
||||
}
|
||||
}
|
39
OpenCS2hock/Installer.cs
Normal file
39
OpenCS2hock/Installer.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace OpenCS2hock;
|
||||
|
||||
public static class Installer
|
||||
{
|
||||
public static void InstallGsi()
|
||||
{
|
||||
string installLocation = Path.Combine(GetInstallDirectory(), "game\\csgo\\cfg\\gamestate_integration_opencs2hock.cfg");
|
||||
File.WriteAllText(installLocation, Resources.GSI_CFG_Content);
|
||||
}
|
||||
|
||||
public static string GetInstallDirectory(int appId = 730)
|
||||
{
|
||||
string steamInstallation =
|
||||
#pragma warning disable CA1416 //Registry only available on Windows
|
||||
(string)(Registry.GetValue(@"HKEY_CURRENT_USER\SOFTWARE\Valve\Steam", "SteamPath", null) ??
|
||||
#pragma warning restore CA1416
|
||||
throw new DirectoryNotFoundException("No Steam Installation found."));
|
||||
string libraryFolderFilepath = Path.Combine(steamInstallation, "steamapps\\libraryfolders.vdf");
|
||||
string? libraryPath = null;
|
||||
string? appManifestFolderPath = null;
|
||||
foreach (string line in File.ReadAllLines(libraryFolderFilepath))
|
||||
if (line.Contains("path"))
|
||||
libraryPath = line.Split("\"").Last(split => split.Length > 0);
|
||||
else if (line.Contains($"\"{appId}\""))
|
||||
appManifestFolderPath = Path.Combine(libraryPath!, $"steamapps\\appmanifest_{appId}.acf");
|
||||
|
||||
string installationPath = "";
|
||||
if (appManifestFolderPath is null)
|
||||
throw new DirectoryNotFoundException($"No {appId} Installation found.");
|
||||
foreach(string line in File.ReadAllLines(appManifestFolderPath))
|
||||
if (line.Contains("installdir"))
|
||||
installationPath = Path.Combine(libraryPath!, "steamapps\\common", line.Split("\"").Last(split => split.Length > 0));
|
||||
|
||||
return installationPath;
|
||||
}
|
||||
|
||||
}
|
28
OpenCS2hock/OpenCS2hock.cs
Normal file
28
OpenCS2hock/OpenCS2hock.cs
Normal file
@ -0,0 +1,28 @@
|
||||
namespace OpenCS2hock;
|
||||
|
||||
public class OpenCS2hock
|
||||
{
|
||||
private GSIServer GSIServer { get; init; }
|
||||
private List<Shocker> _shockers = new();
|
||||
|
||||
public OpenCS2hock()
|
||||
{
|
||||
Installer.InstallGsi();
|
||||
this.GSIServer = new GSIServer(3000);
|
||||
this.GSIServer.OnMessage += OnGSIMessage;
|
||||
|
||||
Thread runningThread = new(() =>
|
||||
{
|
||||
while (GSIServer.IsRunning)
|
||||
Thread.Sleep(10);
|
||||
});
|
||||
runningThread.Start();
|
||||
}
|
||||
|
||||
private void OnGSIMessage(string content)
|
||||
{
|
||||
string fileName = Path.Combine(Environment.CurrentDirectory, $"{DateTime.Now.ToLongTimeString().Replace(':','.')}.json");
|
||||
File.WriteAllText(fileName, content);
|
||||
Console.WriteLine(fileName);
|
||||
}
|
||||
}
|
@ -8,4 +8,19 @@
|
||||
<RootNamespace>OpenCS2Hock</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Update="Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -4,6 +4,6 @@ public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
|
||||
new OpenCS2hock();
|
||||
}
|
||||
}
|
88
OpenCS2hock/Resources.Designer.cs
generated
Normal file
88
OpenCS2hock/Resources.Designer.cs
generated
Normal file
@ -0,0 +1,88 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace OpenCS2hock {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||
/// </summary>
|
||||
// This class was auto-generated by the StronglyTypedResourceBuilder
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cached ResourceManager instance used by this class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("OpenCS2Hock.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the current thread's CurrentUICulture property for all
|
||||
/// resource lookups using this strongly typed resource class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to "OpenCS2hock"
|
||||
///{
|
||||
///"uri" "http://127.0.0.1:3000"
|
||||
///"timeout" "5.0"
|
||||
///"buffer" "0.1"
|
||||
///"throttle" "0.5"
|
||||
///"heartbeat" "60.0"
|
||||
///"output"
|
||||
/// {
|
||||
/// "precision_time" "3"
|
||||
/// "precision_position" "1"
|
||||
/// "precision_vector" "3"
|
||||
/// }
|
||||
///"data"
|
||||
/// {
|
||||
/// "provider" "1" // general info about client being listened to: game name, appid, client steamid, etc.
|
||||
/// "map" "1" // map, gamemode, and current match phase ('warmup', 'intermission', 'gameover', 'live') and current score
|
||||
/// [rest of string was truncated]";.
|
||||
/// </summary>
|
||||
internal static string GSI_CFG_Content {
|
||||
get {
|
||||
return ResourceManager.GetString("GSI_CFG_Content", resourceCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
24
OpenCS2hock/Resources.resx
Normal file
24
OpenCS2hock/Resources.resx
Normal file
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>1.3</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="GSI_CFG_Content" type="System.Resources.ResXFileRef">
|
||||
<value>gamestate_integration_opencs2hock.cfg;System.String, mscorlib, Version=4.0.0.0, Culture=neutral</value>
|
||||
</data>
|
||||
</root>
|
14
OpenCS2hock/Shocker.cs
Normal file
14
OpenCS2hock/Shocker.cs
Normal file
@ -0,0 +1,14 @@
|
||||
namespace OpenCS2hock;
|
||||
|
||||
public abstract class Shocker
|
||||
{
|
||||
public string ApiKey, Endpoint;
|
||||
public enum ControlAction { Beep, Vibrate, Shock }
|
||||
public abstract void Control(ControlAction action, byte intensity, short duration);
|
||||
|
||||
public Shocker(string endpoint, string apiKey)
|
||||
{
|
||||
this.Endpoint = endpoint;
|
||||
this.ApiKey = apiKey;
|
||||
}
|
||||
}
|
23
OpenCS2hock/gamestate_integration_opencs2hock.cfg
Normal file
23
OpenCS2hock/gamestate_integration_opencs2hock.cfg
Normal file
@ -0,0 +1,23 @@
|
||||
"OpenCS2hock"
|
||||
{
|
||||
"uri" "http://127.0.0.1:3000"
|
||||
"timeout" "5.0"
|
||||
"buffer" "0.1"
|
||||
"throttle" "0.5"
|
||||
"heartbeat" "60.0"
|
||||
"output"
|
||||
{
|
||||
"precision_time" "3"
|
||||
"precision_position" "1"
|
||||
"precision_vector" "3"
|
||||
}
|
||||
"data"
|
||||
{
|
||||
"provider" "1" // general info about client being listened to: game name, appid, client steamid, etc.
|
||||
"map" "1" // map, gamemode, and current match phase ('warmup', 'intermission', 'gameover', 'live') and current score
|
||||
"round" "1" // round phase ('freezetime', 'over', 'live'), bomb state ('planted', 'exploded', 'defused'), and round winner (if any)
|
||||
"player_id" "1" // player name, clan tag, observer slot (ie key to press to observe this player) and team
|
||||
"player_state" "1" // player state for this current round such as health, armor, kills this round, etc.
|
||||
"player_match_stats" "1" // player stats this match such as kill, assists, score, deaths and MVPs
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user