Compare commits
39 Commits
b5b65dbe45
...
master
Author | SHA1 | Date | |
---|---|---|---|
4ca3a8b464 | |||
11c8a4f38f | |||
a11f50b6d8 | |||
8371f119d5 | |||
386c211de5 | |||
eda66a2334 | |||
04be9d6fab | |||
f18e6744f4 | |||
fba5d42db3 | |||
ea6099a7d2 | |||
316cc815b5 | |||
996255b490 | |||
d72ae0fd5d | |||
6ce91bbae7 | |||
81fbc36b77 | |||
b17b2a8067 | |||
1d6699ed8a | |||
23f9581383 | |||
6a200dbb64 | |||
bbfa9989ec | |||
b45a68bf1c | |||
bf1db814a6 | |||
f4a28f6951 | |||
42f44c3eb8 | |||
278f94b6aa | |||
69dfc4fc46 | |||
bd36a2c39e | |||
3462c06fac | |||
d8cb872a02 | |||
592fee31ca | |||
b4e9e595a7 | |||
6a19f91219 | |||
19c2a7515f | |||
1c161cde55 | |||
bc711d65e6 | |||
65b9b195ca | |||
b084b0e13f | |||
4b66a7147a | |||
1d5df8a095 |
3
CS2GSI.sln.DotSettings
Normal file
3
CS2GSI.sln.DotSettings
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:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=CS/@EntryIndexedValue">CS</s:String>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=steamid/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
4
CS2GSI.sln.DotSettings.user
Normal file
4
CS2GSI.sln.DotSettings.user
Normal file
@ -0,0 +1,4 @@
|
||||
<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/=CS2GSI_002FResources/@EntryIndexedValue">True</s:Boolean>
|
||||
|
||||
<s:Boolean x:Key="/Default/ResxEditorPersonal/Initialized/@EntryValue">True</s:Boolean></wpf:ResourceDictionary>
|
32
CS2GSI/CS2Event.cs
Normal file
32
CS2GSI/CS2Event.cs
Normal file
@ -0,0 +1,32 @@
|
||||
namespace CS2GSI;
|
||||
|
||||
public enum CS2Event : byte {
|
||||
OnKill = 0,
|
||||
OnHeadshot = 1,
|
||||
OnDeath = 2,
|
||||
OnFlashed = 3,
|
||||
OnBurning = 4,
|
||||
OnSmoked = 5,
|
||||
OnRoundStart = 6,
|
||||
OnRoundOver = 7,
|
||||
OnRoundWin = 8,
|
||||
OnRoundLoss = 9,
|
||||
OnDamageTaken = 10,
|
||||
OnMatchStart = 11,
|
||||
OnMatchOver = 12,
|
||||
OnMoneyChange = 13,
|
||||
OnHealthChange = 14,
|
||||
OnArmorChange = 15,
|
||||
OnHelmetChange = 16,
|
||||
OnEquipmentValueChange = 17,
|
||||
OnTeamChange = 18,
|
||||
OnPlayerChange = 19,
|
||||
OnHalfTime = 20,
|
||||
OnFreezeTime = 21,
|
||||
OnBombPlanted = 22,
|
||||
OnBombDefused = 23,
|
||||
OnBombExploded = 24,
|
||||
AnyEvent = 25,
|
||||
AnyMessage = 26,
|
||||
OnActivityChange = 27
|
||||
}
|
@ -2,5 +2,22 @@
|
||||
|
||||
public class CS2EventArgs : EventArgs
|
||||
{
|
||||
|
||||
private readonly object? _value;
|
||||
public readonly bool HasValue;
|
||||
|
||||
public CS2EventArgs(object? value = null)
|
||||
{
|
||||
this._value = value;
|
||||
this.HasValue = value is not null;
|
||||
}
|
||||
|
||||
public T? ValueAsOrDefault<T>()
|
||||
{
|
||||
return _value is T val ? val : default;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return _value?.ToString() ?? "NoArgs";
|
||||
}
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
using CS2GSI.GameState;
|
||||
using CS2Event = CS2GSI.CS2GSI.CS2Event;
|
||||
|
||||
namespace CS2GSI;
|
||||
|
||||
@ -12,10 +11,15 @@ internal static class CS2EventGenerator
|
||||
events.AddRange(GenerateMapEvents(previousPlayerState, newGameState, lastGameState));
|
||||
|
||||
if(lastGameState.Player?.SteamId != newGameState.Player?.SteamId)
|
||||
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnPlayerChange, new CS2EventArgs()));
|
||||
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnPlayerChange, new CS2EventArgs(newGameState.Player?.SteamId)));
|
||||
|
||||
if(events.Count > 0)
|
||||
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.AnyEvent, new CS2EventArgs()));
|
||||
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.AnyEvent, new CS2EventArgs(events.Count)));
|
||||
|
||||
if (lastGameState.Player?.Activity != newGameState.Player?.Activity)
|
||||
events.Add(new(CS2Event.OnActivityChange, new CS2EventArgs(newGameState.Player?.Activity)));
|
||||
|
||||
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.AnyMessage, new CS2EventArgs()));
|
||||
return events;
|
||||
}
|
||||
|
||||
@ -30,9 +34,18 @@ internal static class CS2EventGenerator
|
||||
|
||||
if(newGameState.Round?.Phase == Round.RoundPhase.Over && lastGameState.Round?.Phase == Round.RoundPhase.Live)
|
||||
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnRoundOver, new CS2EventArgs()));
|
||||
|
||||
if (newGameState.Map?.Round is not null && newGameState.Map?.Round != previousPlayerState.Map?.Round)
|
||||
{
|
||||
if(newGameState.Round?.WinnerTeam is not null && newGameState.Round?.WinnerTeam == previousPlayerState.Player?.Team)
|
||||
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnRoundWin, new CS2EventArgs()));
|
||||
|
||||
if(newGameState.Round?.WinnerTeam is not null && newGameState.Round?.WinnerTeam != previousPlayerState.Player?.Team)
|
||||
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnRoundLoss, new CS2EventArgs()));
|
||||
}
|
||||
}
|
||||
|
||||
if(newGameState.Map?.Phase == Map.MapPhase.Live && lastGameState.Map?.Phase != Map.MapPhase.Live)
|
||||
if(newGameState.Map?.Phase == Map.MapPhase.Live && lastGameState.Map?.Phase == Map.MapPhase.Warmup)
|
||||
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnMatchStart, new CS2EventArgs()));
|
||||
|
||||
if(newGameState.Map?.Phase == Map.MapPhase.GameOver && lastGameState.Map?.Phase != Map.MapPhase.GameOver)
|
||||
@ -63,13 +76,13 @@ internal static class CS2EventGenerator
|
||||
return events;
|
||||
|
||||
if(newGameState.Player?.MatchStats?.Kills > previousPlayerState.Player?.MatchStats?.Kills && newGameState.Player is { MatchStats: not null})
|
||||
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnKill, new CS2EventArgs()));
|
||||
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnKill, new CS2EventArgs(newGameState.Player?.MatchStats?.Kills)));
|
||||
|
||||
if(newGameState.Player?.State?.RoundHs > previousPlayerState.Player?.State?.RoundHs && newGameState.Player is { State: not null})
|
||||
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnHeadshot, new CS2EventArgs()));
|
||||
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnHeadshot, new CS2EventArgs(newGameState.Player?.State?.RoundHs)));
|
||||
|
||||
if(newGameState.Player?.MatchStats?.Deaths > previousPlayerState.Player?.MatchStats?.Deaths && newGameState.Player is { MatchStats: not null})
|
||||
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnDeath, new CS2EventArgs()));
|
||||
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnDeath, new CS2EventArgs(newGameState.Player?.MatchStats?.Deaths)));
|
||||
|
||||
if(newGameState.Player?.State?.Flashed > 0 && newGameState.Player is { State: not null})
|
||||
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnFlashed, new CS2EventArgs()));
|
||||
@ -81,25 +94,25 @@ internal static class CS2EventGenerator
|
||||
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnSmoked, new CS2EventArgs()));
|
||||
|
||||
if(newGameState.Player?.State?.Health < previousPlayerState.Player?.State?.Health && newGameState.Player is { State: not null})
|
||||
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnDamageTaken, new CS2EventArgs()));
|
||||
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnDamageTaken, new CS2EventArgs(previousPlayerState.Player?.State?.Health - newGameState.Player?.State?.Health)));
|
||||
|
||||
if(newGameState.Player?.State?.Health != previousPlayerState.Player?.State?.Health && newGameState.Player is { State: not null})
|
||||
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnHealthChange, new CS2EventArgs()));
|
||||
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnHealthChange, new CS2EventArgs(newGameState.Player?.State?.Health - previousPlayerState.Player?.State?.Health)));
|
||||
|
||||
if(newGameState.Player?.State?.Money != previousPlayerState.Player?.State?.Money && newGameState.Player is { State: not null})
|
||||
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnMoneyChange, new CS2EventArgs()));
|
||||
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnMoneyChange, new CS2EventArgs(newGameState.Player?.State?.Money - previousPlayerState.Player?.State?.Money)));
|
||||
|
||||
if(newGameState.Player?.State?.Armor != previousPlayerState.Player?.State?.Armor && newGameState.Player is { State: not null})
|
||||
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnArmorChange, new CS2EventArgs()));
|
||||
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnArmorChange, new CS2EventArgs(newGameState.Player?.State?.Armor - previousPlayerState.Player?.State?.Armor)));
|
||||
|
||||
if(newGameState.Player?.State?.Helmet != previousPlayerState.Player?.State?.Helmet && newGameState.Player is { State: not null})
|
||||
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnHelmetChange, new CS2EventArgs()));
|
||||
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnHelmetChange, new CS2EventArgs(newGameState.Player?.State?.Helmet)));
|
||||
|
||||
if(newGameState.Player?.State?.EquipmentValue != previousPlayerState.Player?.State?.EquipmentValue && newGameState.Player is { State: not null})
|
||||
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnEquipmentValueChange, new CS2EventArgs()));
|
||||
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnEquipmentValueChange, new CS2EventArgs(newGameState.Player?.State?.EquipmentValue - previousPlayerState.Player?.State?.EquipmentValue)));
|
||||
|
||||
if(newGameState.Player?.Team != previousPlayerState.Player?.Team && newGameState.Player is not null)
|
||||
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnTeamChange, new CS2EventArgs()));
|
||||
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnTeamChange, new CS2EventArgs(newGameState.Player?.Team)));
|
||||
|
||||
|
||||
return events;
|
||||
|
212
CS2GSI/CS2GSI.cs
212
CS2GSI/CS2GSI.cs
@ -1,53 +1,80 @@
|
||||
using CS2GSI.GameState;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace CS2GSI;
|
||||
|
||||
public class CS2GSI
|
||||
{
|
||||
private GSIServer _gsiServer;
|
||||
private List<CS2GameState> _allGameStates = new();
|
||||
private readonly GSIServer _gsiServer = null!;
|
||||
private readonly List<CS2GameState> _allGameStates = new();
|
||||
private CS2GameState? _lastLocalGameState = null;
|
||||
private ILogger? logger;
|
||||
private readonly ILogger? _logger;
|
||||
public bool IsRunning => this._gsiServer.IsRunning;
|
||||
public CS2GameState? CurrentGameState => _lastLocalGameState;
|
||||
|
||||
private const string DebugDirectory = "Debug";
|
||||
public static string StatesDirectory => Path.Join(DebugDirectory, "States");
|
||||
public static string MessagesDirectory => Path.Join(DebugDirectory, "Messages");
|
||||
public static string EventsDirectory => Path.Join(DebugDirectory, "Messages");
|
||||
public static bool DebugEnabled = false;
|
||||
|
||||
public CS2GSI(ILogger? logger = null)
|
||||
public CS2GSI(ILogger? logger = null, bool debugEnabled = false)
|
||||
{
|
||||
this.logger = logger;
|
||||
this.logger?.Log(LogLevel.Information, "Installing GSI-Configfile...");
|
||||
this._logger = logger;
|
||||
this._logger?.Log(LogLevel.Information, Resources.Installing_GSI_File);
|
||||
try
|
||||
{
|
||||
GsiConfigInstaller.InstallGsi();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.logger?.Log(LogLevel.Error, e.StackTrace);
|
||||
this.logger?.Log(LogLevel.Critical, "Could not install GSI-Configfile. Exiting.");
|
||||
this._logger?.Log(LogLevel.Error, e.StackTrace);
|
||||
this._logger?.Log(LogLevel.Critical, Resources.Installing_GSI_File_Failed);
|
||||
return;
|
||||
}
|
||||
this._gsiServer = new GSIServer(3000, logger);
|
||||
|
||||
DebugEnabled = debugEnabled;
|
||||
this._gsiServer = GSIServer.Create(3000, logger);
|
||||
this._gsiServer.OnMessage += GsiServerOnOnMessage;
|
||||
|
||||
while(this._gsiServer.IsRunning)
|
||||
Thread.Sleep(10);
|
||||
}
|
||||
|
||||
private void GsiServerOnOnMessage(string messageJson)
|
||||
{
|
||||
JObject jsonObject = JObject.Parse(messageJson);
|
||||
CS2GameState newState = CS2GameState.ParseFromJObject(jsonObject);
|
||||
this.logger?.Log(LogLevel.Debug, $"Received State:\n{newState.ToString()}");
|
||||
this._lastLocalGameState = newState.UpdateGameStateForLocal(_lastLocalGameState);
|
||||
this.logger?.Log(LogLevel.Debug, $"Updated Local State:\n{_lastLocalGameState.ToString()}");
|
||||
this._logger?.Log(LogLevel.Debug, $"{Resources.Received_State}:\n{newState.ToString()}");
|
||||
|
||||
if (_lastLocalGameState is not null)
|
||||
double time = DateTime.UtcNow.Subtract(
|
||||
new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)
|
||||
).TotalMilliseconds;
|
||||
string timeString = $"{time:N0}.json";
|
||||
|
||||
if (DebugEnabled)
|
||||
{
|
||||
List<ValueTuple<CS2Event, CS2EventArgs>> generatedEvents = CS2EventGenerator.GenerateEvents(_lastLocalGameState.Value, newState, _allGameStates.Last());
|
||||
this.logger?.Log(LogLevel.Information, $"Generated {generatedEvents.Count} events.");
|
||||
if(generatedEvents.Count > 0)
|
||||
this.logger?.Log(LogLevel.Debug, $"Events:\n\t{string.Join("\n\t", generatedEvents)}");
|
||||
Directory.CreateDirectory(StatesDirectory);
|
||||
Directory.CreateDirectory(MessagesDirectory);
|
||||
File.WriteAllText(Path.Join(StatesDirectory, timeString),
|
||||
JsonConvert.SerializeObject(newState, Formatting.Indented, new Newtonsoft.Json.Converters.StringEnumConverter()));
|
||||
File.WriteAllText(Path.Join(MessagesDirectory, timeString), messageJson);
|
||||
}
|
||||
|
||||
if (_lastLocalGameState is not null && _allGameStates.Count > 0)
|
||||
{
|
||||
List<ValueTuple<CS2Event, CS2EventArgs>> generatedEvents = CS2EventGenerator.GenerateEvents(_lastLocalGameState, newState, _allGameStates.Last());
|
||||
this._logger?.Log(LogLevel.Information, $"Generated {generatedEvents.Count} event{(generatedEvents.Count > 1 ? 's' : null)}:\n- {string.Join("\n- ", generatedEvents)}");
|
||||
if (DebugEnabled)
|
||||
{
|
||||
Directory.CreateDirectory(EventsDirectory);
|
||||
File.WriteAllText(Path.Join(StatesDirectory, EventsDirectory),
|
||||
JsonConvert.SerializeObject(generatedEvents, Formatting.Indented, new Newtonsoft.Json.Converters.StringEnumConverter()));
|
||||
}
|
||||
|
||||
InvokeEvents(generatedEvents);
|
||||
}
|
||||
this._lastLocalGameState = newState.UpdateGameStateForLocal(_lastLocalGameState);
|
||||
this._logger?.Log(LogLevel.Debug, $"\n{Resources.Updated_Local_State}:\n{_lastLocalGameState}");
|
||||
_allGameStates.Add(newState);
|
||||
}
|
||||
|
||||
@ -60,111 +87,43 @@ public class CS2GSI
|
||||
|
||||
private void InvokeEvent(ValueTuple<CS2Event, CS2EventArgs> cs2Event)
|
||||
{
|
||||
switch (cs2Event.Item1)
|
||||
{
|
||||
case CS2Event.OnKill:
|
||||
OnKill?.Invoke(cs2Event.Item2);
|
||||
break;
|
||||
case CS2Event.OnHeadshot:
|
||||
OnHeadshot?.Invoke(cs2Event.Item2);
|
||||
break;
|
||||
case CS2Event.OnDeath:
|
||||
OnDeath?.Invoke(cs2Event.Item2);
|
||||
break;
|
||||
case CS2Event.OnFlashed:
|
||||
OnFlashed?.Invoke(cs2Event.Item2);
|
||||
break;
|
||||
case CS2Event.OnBurning:
|
||||
OnBurning?.Invoke(cs2Event.Item2);
|
||||
break;
|
||||
case CS2Event.OnSmoked:
|
||||
OnSmoked?.Invoke(cs2Event.Item2);
|
||||
break;
|
||||
case CS2Event.OnRoundStart:
|
||||
OnRoundStart?.Invoke(cs2Event.Item2);
|
||||
break;
|
||||
case CS2Event.OnRoundOver:
|
||||
OnRoundOver?.Invoke(cs2Event.Item2);
|
||||
break;
|
||||
case CS2Event.OnDamageTaken:
|
||||
OnDamageTaken?.Invoke(cs2Event.Item2);
|
||||
break;
|
||||
case CS2Event.OnMatchStart:
|
||||
OnMatchStart?.Invoke(cs2Event.Item2);
|
||||
break;
|
||||
case CS2Event.OnMatchOver:
|
||||
OnMatchOver?.Invoke(cs2Event.Item2);
|
||||
break;
|
||||
case CS2Event.OnMoneyChange:
|
||||
OnMoneyChange?.Invoke(cs2Event.Item2);
|
||||
break;
|
||||
case CS2Event.OnHealthChange:
|
||||
OnHealthChange?.Invoke(cs2Event.Item2);
|
||||
break;
|
||||
case CS2Event.OnArmorChange:
|
||||
OnArmorChange?.Invoke(cs2Event.Item2);
|
||||
break;
|
||||
case CS2Event.OnHelmetChange:
|
||||
OnHelmetChange?.Invoke(cs2Event.Item2);
|
||||
break;
|
||||
case CS2Event.OnEquipmentValueChange:
|
||||
OnEquipmentValueChange?.Invoke(cs2Event.Item2);
|
||||
break;
|
||||
case CS2Event.OnTeamChange:
|
||||
OnTeamChange?.Invoke(cs2Event.Item2);
|
||||
break;
|
||||
case CS2Event.OnPlayerChange:
|
||||
OnPlayerChange?.Invoke(cs2Event.Item2);
|
||||
break;
|
||||
case CS2Event.OnFreezeTime:
|
||||
OnFreezeTime?.Invoke(cs2Event.Item2);
|
||||
break;
|
||||
case CS2Event.OnHalfTime:
|
||||
OnHalfTime?.Invoke(cs2Event.Item2);
|
||||
break;
|
||||
case CS2Event.OnBombDefused:
|
||||
OnBombDefused?.Invoke(cs2Event.Item2);
|
||||
break;
|
||||
case CS2Event.OnBombExploded:
|
||||
OnBombExploded?.Invoke(cs2Event.Item2);
|
||||
break;
|
||||
case CS2Event.OnBombPlanted:
|
||||
OnBombPlanted?.Invoke(cs2Event.Item2);
|
||||
break;
|
||||
case CS2Event.AnyEvent:
|
||||
AnyEvent?.Invoke(cs2Event.Item2);
|
||||
break;
|
||||
default:
|
||||
this.logger?.Log(LogLevel.Error, $"Unknown Event {cs2Event}");
|
||||
return;
|
||||
}
|
||||
GetEventHandlerForEvent(cs2Event.Item1)?.Invoke(cs2Event.Item2);
|
||||
}
|
||||
|
||||
internal enum CS2Event {
|
||||
OnKill,
|
||||
OnHeadshot,
|
||||
OnDeath,
|
||||
OnFlashed,
|
||||
OnBurning,
|
||||
OnSmoked,
|
||||
OnRoundStart,
|
||||
OnRoundOver,
|
||||
OnDamageTaken,
|
||||
OnMatchStart,
|
||||
OnMatchOver,
|
||||
OnMoneyChange,
|
||||
OnHealthChange,
|
||||
OnArmorChange,
|
||||
OnHelmetChange,
|
||||
OnEquipmentValueChange,
|
||||
OnTeamChange,
|
||||
OnPlayerChange,
|
||||
OnHalfTime,
|
||||
OnFreezeTime,
|
||||
OnBombPlanted,
|
||||
OnBombDefused,
|
||||
OnBombExploded,
|
||||
AnyEvent
|
||||
private CS2EventHandler? GetEventHandlerForEvent(CS2Event cs2Event)
|
||||
{
|
||||
return cs2Event switch
|
||||
{
|
||||
CS2Event.OnKill => this.OnKill,
|
||||
CS2Event.OnHeadshot => this.OnHeadshot,
|
||||
CS2Event.OnDeath => this.OnDeath,
|
||||
CS2Event.OnFlashed => this.OnFlashed,
|
||||
CS2Event.OnBurning => this.OnBurning,
|
||||
CS2Event.OnSmoked => this.OnSmoked,
|
||||
CS2Event.OnRoundStart => this.OnRoundStart,
|
||||
CS2Event.OnRoundOver => this.OnRoundOver,
|
||||
CS2Event.OnRoundWin => this.OnRoundWin,
|
||||
CS2Event.OnRoundLoss => this.OnRoundLoss,
|
||||
CS2Event.OnDamageTaken => this.OnDamageTaken,
|
||||
CS2Event.OnMatchStart => this.OnMatchStart,
|
||||
CS2Event.OnMatchOver => this.OnMatchOver,
|
||||
CS2Event.OnMoneyChange => this.OnMoneyChange,
|
||||
CS2Event.OnHealthChange => this.OnHealthChange,
|
||||
CS2Event.OnArmorChange => this.OnArmorChange,
|
||||
CS2Event.OnHelmetChange => this.OnHelmetChange,
|
||||
CS2Event.OnEquipmentValueChange => this.OnEquipmentValueChange,
|
||||
CS2Event.OnTeamChange => this.OnTeamChange,
|
||||
CS2Event.OnPlayerChange => this.OnPlayerChange,
|
||||
CS2Event.OnHalfTime => this.OnHalfTime,
|
||||
CS2Event.OnFreezeTime => this.OnFreezeTime,
|
||||
CS2Event.OnBombPlanted => this.OnBombPlanted,
|
||||
CS2Event.OnBombDefused => this.OnBombDefused,
|
||||
CS2Event.OnBombExploded => this.OnBombExploded,
|
||||
CS2Event.AnyEvent => this.OnAnyEvent,
|
||||
CS2Event.AnyMessage => this.OnAnyMessage,
|
||||
CS2Event.OnActivityChange => this.OnActivityChange,
|
||||
_ => throw new ArgumentException(Resources.Unknown_Event, nameof(cs2Event))
|
||||
};
|
||||
}
|
||||
|
||||
public delegate void CS2EventHandler(CS2EventArgs eventArgs);
|
||||
@ -177,6 +136,8 @@ public class CS2GSI
|
||||
OnSmoked,
|
||||
OnRoundStart,
|
||||
OnRoundOver,
|
||||
OnRoundWin,
|
||||
OnRoundLoss,
|
||||
OnDamageTaken,
|
||||
OnMatchStart,
|
||||
OnMatchOver,
|
||||
@ -192,6 +153,7 @@ public class CS2GSI
|
||||
OnBombPlanted,
|
||||
OnBombDefused,
|
||||
OnBombExploded,
|
||||
AnyEvent;
|
||||
|
||||
OnAnyEvent,
|
||||
OnAnyMessage,
|
||||
OnActivityChange;
|
||||
}
|
@ -1,9 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version>1.1.0</Version>
|
||||
<Title>CS2GSI</Title>
|
||||
<Authors>Glax</Authors>
|
||||
<RepositoryUrl>https://github.com/C9Glax/CS2GSI</RepositoryUrl>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<PackageProjectUrl>https://github.com/C9Glax/CS2GSI</PackageProjectUrl>
|
||||
<PackageLicenseUrl></PackageLicenseUrl>
|
||||
<TargetFrameworks>net8.0;net9.0;net7.0</TargetFrameworks>
|
||||
<LangVersion>latestmajor</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@ -25,5 +33,21 @@
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\LICENSE" Pack="true" PackagePath=""/>
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\README.md" Pack="true" PackagePath="\"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
2
CS2GSI/CS2GSI.csproj.DotSettings.user
Normal file
2
CS2GSI/CS2GSI.csproj.DotSettings.user
Normal file
@ -0,0 +1,2 @@
|
||||
<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/CodeEditing/Localization/MoveToResource/LastResourceFile/@EntryValue">F2272524-6CDD-4ACD-8CFF-64B9AF98D54A/f:Resources.resx</s:String></wpf:ResourceDictionary>
|
@ -42,8 +42,8 @@ internal static class GsiConfigInstaller
|
||||
path = "~/.local/share/Steam/steamapps/libraryfolders.vdf";
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
path = "~/Library/Application Support/Steam/steamapps/libraryfolders.vdf";
|
||||
else throw new Exception("Could not get Installation FolderPath");
|
||||
return path ?? throw new FileNotFoundException("No libraryfolders.vdf found");
|
||||
else throw new Exception(Resources.No_Installation_Folderpath);
|
||||
return path ?? throw new FileNotFoundException(Resources.No_Libraryfolders_vdf);
|
||||
}
|
||||
|
||||
[SupportedOSPlatform("windows")]
|
||||
@ -51,7 +51,7 @@ internal static class GsiConfigInstaller
|
||||
{
|
||||
string steamInstallation =
|
||||
(string)(Registry.GetValue(@"HKEY_CURRENT_USER\SOFTWARE\Valve\Steam", "SteamPath", null) ??
|
||||
throw new DirectoryNotFoundException("No Steam Installation found."));
|
||||
throw new DirectoryNotFoundException(Resources.No_Steam));
|
||||
return Path.Combine(steamInstallation, "steamapps\\libraryfolders.vdf");
|
||||
}
|
||||
}
|
@ -8,31 +8,41 @@ namespace CS2GSI;
|
||||
|
||||
internal class GSIServer
|
||||
{
|
||||
public static GSIServer? Instance { get; private set; }
|
||||
private HttpListener HttpListener { get; init; }
|
||||
internal delegate void OnMessageEventHandler(string content);
|
||||
internal event OnMessageEventHandler? OnMessage;
|
||||
private bool _keepRunning = true;
|
||||
internal bool IsRunning { get; private set; }
|
||||
private ILogger? logger;
|
||||
|
||||
internal delegate void OnMessageEventHandler(string content);
|
||||
internal event OnMessageEventHandler? OnMessage;
|
||||
|
||||
internal GSIServer(int port, ILogger? logger = null)
|
||||
public static GSIServer Create(int port, ILogger? logger = null)
|
||||
{
|
||||
Instance = new GSIServer(port, logger);
|
||||
return Instance;
|
||||
}
|
||||
|
||||
private GSIServer(){}
|
||||
|
||||
private GSIServer(int port, ILogger? logger = null)
|
||||
{
|
||||
this.logger = logger;
|
||||
string prefix = $"http://127.0.0.1:{port}/";
|
||||
HttpListener = new HttpListener();
|
||||
HttpListener.Prefixes.Add(prefix);
|
||||
HttpListener.Start();
|
||||
this.HttpListener = new HttpListener();
|
||||
this.HttpListener.Prefixes.Add(prefix);
|
||||
this.HttpListener.Start();
|
||||
this.logger?.Log(LogLevel.Information, $"Listening on {prefix}");
|
||||
|
||||
Thread connectionListener = new (HandleConnection);
|
||||
connectionListener.Start();
|
||||
|
||||
IsRunning = true;
|
||||
this.IsRunning = true;
|
||||
}
|
||||
|
||||
private async void HandleConnection()
|
||||
{
|
||||
while (_keepRunning)
|
||||
while (this._keepRunning)
|
||||
{
|
||||
HttpListenerContext context = await HttpListener.GetContextAsync();
|
||||
HttpListenerRequest request = context.Request;
|
||||
@ -44,18 +54,18 @@ internal class GSIServer
|
||||
|
||||
StreamReader reader = new (request.InputStream, request.ContentEncoding);
|
||||
string content = await reader.ReadToEndAsync();
|
||||
this.logger?.Log(LogLevel.Debug, $"Message Content:\n{content}");
|
||||
OnMessage?.Invoke(content);
|
||||
this.logger?.Log(LogLevel.Debug, content);
|
||||
}
|
||||
HttpListener.Close();
|
||||
IsRunning = false;
|
||||
this.HttpListener.Close();
|
||||
this.IsRunning = false;
|
||||
this.logger?.Log(LogLevel.Information, "Stopped GSIServer.");
|
||||
}
|
||||
|
||||
internal void Dispose()
|
||||
{
|
||||
this.logger?.Log(LogLevel.Information, "Stopping GSIServer.");
|
||||
_keepRunning = false;
|
||||
this._keepRunning = false;
|
||||
}
|
||||
|
||||
}
|
@ -2,9 +2,9 @@
|
||||
|
||||
namespace CS2GSI.GameState;
|
||||
|
||||
public struct CS2GameState
|
||||
public record CS2GameState : GameState
|
||||
{
|
||||
public string ProviderSteamId;
|
||||
public string ProviderSteamId = null!;
|
||||
public int Timestamp;
|
||||
public Map? Map;
|
||||
public Player? Player;
|
||||
@ -12,11 +12,7 @@ public struct CS2GameState
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{GetType()}\n" +
|
||||
$"\tTime: {Timestamp}\tSteamId: {ProviderSteamId}\n" +
|
||||
$"\t{Map}\n" +
|
||||
$"\t{Round}\n" +
|
||||
$"\t{Player}\n";
|
||||
return base.ToString();
|
||||
}
|
||||
|
||||
internal static CS2GameState ParseFromJObject(JObject jsonObject)
|
||||
@ -25,9 +21,9 @@ public struct CS2GameState
|
||||
{
|
||||
ProviderSteamId = jsonObject.SelectToken("provider.steamid")!.Value<string>()!,
|
||||
Timestamp = jsonObject.SelectToken("provider.timestamp")!.Value<int>(),
|
||||
Map = GameState.Map.ParseFromJObject(jsonObject),
|
||||
Player = GameState.Player.ParseFromJObject(jsonObject),
|
||||
Round = GameState.Round.ParseFromJObject(jsonObject)
|
||||
Map = Map.ParseFromJObject(jsonObject),
|
||||
Player = Player.ParseFromJObject(jsonObject),
|
||||
Round = Round.ParseFromJObject(jsonObject)
|
||||
};
|
||||
}
|
||||
|
||||
@ -36,7 +32,7 @@ public struct CS2GameState
|
||||
if (previousLocalState is null)
|
||||
return this.Player?.SteamId == ProviderSteamId ? this : null;
|
||||
if (this.Player?.SteamId != ProviderSteamId)
|
||||
return this.WithPlayer(previousLocalState.Value.Player);
|
||||
return this.WithPlayer(previousLocalState.Player);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
21
CS2GSI/GameState/GameState.cs
Normal file
21
CS2GSI/GameState/GameState.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System.Reflection;
|
||||
|
||||
namespace CS2GSI.GameState;
|
||||
|
||||
public abstract record GameState
|
||||
{
|
||||
public override string ToString()
|
||||
{
|
||||
string ret = "";
|
||||
foreach (FieldInfo field in GetType().GetFields())
|
||||
{
|
||||
string filler = GetType().GetFields().Last() != field ? "\u251c\u2500" : "\u2514\u2500";
|
||||
string filler2 = GetType().GetFields().Last() != field ? "\u2502" : " ";
|
||||
if (field.FieldType.BaseType == typeof(GameState))
|
||||
ret += $"\b{filler}\u2510 {field.Name}\n{field.GetValue(this)?.ToString()?.Replace("\b", $"\b{filler2} ")}";
|
||||
else
|
||||
ret += $"\b{filler} {field.Name}{new string('.', field.Name.Length > 25 ? 0 : 25-field.Name.Length)}{field.GetValue(this)}\n";
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
@ -2,18 +2,14 @@
|
||||
|
||||
namespace CS2GSI.GameState;
|
||||
|
||||
public struct GameStateTeam
|
||||
public record GameStateTeam : GameState
|
||||
{
|
||||
public CS2Team Team;
|
||||
public int Score, ConsecutiveRoundLosses, TimeoutsRemaining, MatchesWonThisSeries;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{GetType()}\n" +
|
||||
$"\tScore: {Score}\n" +
|
||||
$"\tConsecutiveRoundLosses: {ConsecutiveRoundLosses}\n" +
|
||||
$"\tTimeoutsRemaining: {TimeoutsRemaining}\n" +
|
||||
$"\tMatchesWonThisSeries: {MatchesWonThisSeries}\n";
|
||||
return base.ToString();
|
||||
}
|
||||
|
||||
internal static GameStateTeam ParseFromJObject(JObject jsonObject, CS2Team team)
|
||||
|
@ -2,20 +2,16 @@
|
||||
|
||||
namespace CS2GSI.GameState;
|
||||
|
||||
public struct Map
|
||||
public record Map : GameState
|
||||
{
|
||||
public string Mode, Name;
|
||||
public string Mode = null!, MapName = null!;
|
||||
public MapPhase Phase;
|
||||
public int Round, NumMatchesToWinSeries;
|
||||
public GameStateTeam GameStateTeamCT, GameStateTeamT;
|
||||
public GameStateTeam GameStateTeamCT = null!, GameStateTeamT = null!;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{GetType()}\n" +
|
||||
$"\t{Mode} {Name} {Round} Matches to Win Series: {NumMatchesToWinSeries}\n" +
|
||||
$"\t{Phase}\n" +
|
||||
$"\t{GameStateTeamCT}\n" +
|
||||
$"\t{GameStateTeamT}\n";
|
||||
return base.ToString();
|
||||
}
|
||||
|
||||
internal static Map? ParseFromJObject(JObject jsonObject)
|
||||
@ -24,7 +20,7 @@ public struct Map
|
||||
? new Map()
|
||||
{
|
||||
Mode = jsonObject.SelectToken("map.mode")!.Value<string>()!,
|
||||
Name = jsonObject.SelectToken("map.name")!.Value<string>()!,
|
||||
MapName = jsonObject.SelectToken("map.name")!.Value<string>()!,
|
||||
Phase = MapPhaseFromString(jsonObject.SelectToken("map.phase")!.Value<string>()!),
|
||||
Round = jsonObject.SelectToken("map.round")!.Value<int>(),
|
||||
NumMatchesToWinSeries = jsonObject.SelectToken("map.num_matches_to_win_series")!.Value<int>(),
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
namespace CS2GSI.GameState;
|
||||
|
||||
public struct Player
|
||||
public record Player : GameState
|
||||
{
|
||||
public string SteamId, Name;
|
||||
public string SteamId = null!, Name = null!;
|
||||
public PlayerActivity Activity;
|
||||
public CS2Team? Team;
|
||||
public int? ObserverSlot;
|
||||
@ -13,34 +13,31 @@ public struct Player
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{GetType()}\n" +
|
||||
$"\t{Name} {SteamId} {Activity} {Team}\n" +
|
||||
$"\t{State}\n" +
|
||||
$"\t{MatchStats}\n";
|
||||
return base.ToString();
|
||||
}
|
||||
|
||||
internal static Player? ParseFromJObject(JObject jsonObject)
|
||||
{
|
||||
return new Player()
|
||||
return jsonObject.SelectToken("player") is not null ? new Player()
|
||||
{
|
||||
SteamId = jsonObject.SelectToken("player.steamid")!.Value<string>()!,
|
||||
Name = jsonObject.SelectToken("player.name")!.Value<string>()!,
|
||||
Team = CS2TeamFromString(jsonObject.SelectToken("player.team")!.Value<string>()!),
|
||||
Team = CS2TeamFromString(jsonObject.SelectToken("player.team")?.Value<string>()),
|
||||
Activity = PlayerActivityFromString(jsonObject.SelectToken("player.activity")!.Value<string>()!),
|
||||
State = PlayerState.ParseFromJObject(jsonObject),
|
||||
MatchStats = PlayerMatchStats.ParseFromJObject(jsonObject)
|
||||
};
|
||||
} : null;
|
||||
}
|
||||
|
||||
public enum PlayerActivity {Playing, Menu, TextInput}
|
||||
|
||||
private static CS2Team CS2TeamFromString(string str)
|
||||
private static CS2Team? CS2TeamFromString(string? str)
|
||||
{
|
||||
return str.ToLower() switch
|
||||
return str?.ToLower() switch
|
||||
{
|
||||
"t" => CS2Team.T,
|
||||
"ct" => CS2Team.CT,
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -2,27 +2,24 @@
|
||||
|
||||
namespace CS2GSI.GameState;
|
||||
|
||||
public struct PlayerMatchStats
|
||||
public record PlayerMatchStats : GameState
|
||||
{
|
||||
public int Kills, Assists, Deaths, MVPs, Score;
|
||||
|
||||
internal static PlayerMatchStats ParseFromJObject(JObject jsonObject)
|
||||
{
|
||||
return new PlayerMatchStats()
|
||||
{
|
||||
Kills = jsonObject.SelectToken($"player.match_stats.kills")!.Value<int>(),
|
||||
Assists = jsonObject.SelectToken($"player.match_stats.assists")!.Value<int>(),
|
||||
Deaths = jsonObject.SelectToken($"player.match_stats.deaths")!.Value<int>(),
|
||||
MVPs = jsonObject.SelectToken($"player.match_stats.mvps")!.Value<int>(),
|
||||
Score = jsonObject.SelectToken($"player.match_stats.score")!.Value<int>(),
|
||||
};
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{GetType()}\n" +
|
||||
$"\tKAD: {Kills} {Assists} {Deaths}\n" +
|
||||
$"\tMVPs: {MVPs}\n" +
|
||||
$"\tScore: {Score}\n";
|
||||
return base.ToString();
|
||||
}
|
||||
|
||||
internal static PlayerMatchStats? ParseFromJObject(JObject jsonObject)
|
||||
{
|
||||
return jsonObject.SelectToken("player.match_stats") is not null ? new PlayerMatchStats()
|
||||
{
|
||||
Kills = jsonObject.SelectToken("player.match_stats.kills")!.Value<int>(),
|
||||
Assists = jsonObject.SelectToken("player.match_stats.assists")!.Value<int>(),
|
||||
Deaths = jsonObject.SelectToken("player.match_stats.deaths")!.Value<int>(),
|
||||
MVPs = jsonObject.SelectToken("player.match_stats.mvps")!.Value<int>(),
|
||||
Score = jsonObject.SelectToken("player.match_stats.score")!.Value<int>(),
|
||||
} : null;
|
||||
}
|
||||
}
|
@ -2,39 +2,30 @@
|
||||
|
||||
namespace CS2GSI.GameState;
|
||||
|
||||
public struct PlayerState
|
||||
public record PlayerState : GameState
|
||||
{
|
||||
public int Health, Armor, Flashed, Smoked, Burning, Money, RoundKills, RoundHs, EquipmentValue;
|
||||
public bool Helmet;
|
||||
|
||||
internal static PlayerState ParseFromJObject(JObject jsonObject)
|
||||
{
|
||||
return new PlayerState()
|
||||
{
|
||||
Health = jsonObject.SelectToken($"player.state.health")!.Value<int>(),
|
||||
Armor = jsonObject.SelectToken($"player.state.armor")!.Value<int>(),
|
||||
Helmet = jsonObject.SelectToken($"player.state.helmet")!.Value<bool>(),
|
||||
Flashed = jsonObject.SelectToken($"player.state.flashed")!.Value<int>(),
|
||||
Smoked = jsonObject.SelectToken($"player.state.smoked")!.Value<int>(),
|
||||
Burning = jsonObject.SelectToken($"player.state.burning")!.Value<int>(),
|
||||
Money = jsonObject.SelectToken($"player.state.money")!.Value<int>(),
|
||||
RoundKills = jsonObject.SelectToken($"player.state.round_kills")!.Value<int>(),
|
||||
RoundHs = jsonObject.SelectToken($"player.state.round_killhs")!.Value<int>(),
|
||||
EquipmentValue = jsonObject.SelectToken($"player.state.equip_value")!.Value<int>(),
|
||||
};
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{GetType()}\n" +
|
||||
$"\tHealth: {Health}\n" +
|
||||
$"\tArmor: {Armor}\n" +
|
||||
$"\tFlashed: {Flashed}\n" +
|
||||
$"\tSmoked: {Smoked}\n" +
|
||||
$"\tBurning: {Burning}\n" +
|
||||
$"\tMoney: {Money}\n" +
|
||||
$"\tRoundKills: {RoundKills}\n" +
|
||||
$"\tRoundHs: {RoundHs}\n" +
|
||||
$"\tEquipmentValue: {EquipmentValue}\n";
|
||||
return base.ToString();
|
||||
}
|
||||
|
||||
internal static PlayerState? ParseFromJObject(JObject jsonObject)
|
||||
{
|
||||
return jsonObject.SelectToken("player.state") is not null ? new PlayerState()
|
||||
{
|
||||
Health = jsonObject.SelectToken("player.state.health")!.Value<int>(),
|
||||
Armor = jsonObject.SelectToken("player.state.armor")!.Value<int>(),
|
||||
Helmet = jsonObject.SelectToken("player.state.helmet")!.Value<bool>(),
|
||||
Flashed = jsonObject.SelectToken("player.state.flashed")!.Value<int>(),
|
||||
Smoked = jsonObject.SelectToken("player.state.smoked")!.Value<int>(),
|
||||
Burning = jsonObject.SelectToken("player.state.burning")!.Value<int>(),
|
||||
Money = jsonObject.SelectToken("player.state.money")!.Value<int>(),
|
||||
RoundKills = jsonObject.SelectToken("player.state.round_kills")!.Value<int>(),
|
||||
RoundHs = jsonObject.SelectToken("player.state.round_killhs")!.Value<int>(),
|
||||
EquipmentValue = jsonObject.SelectToken("player.state.equip_value")!.Value<int>(),
|
||||
} : null;
|
||||
}
|
||||
}
|
@ -2,32 +2,32 @@
|
||||
|
||||
namespace CS2GSI.GameState;
|
||||
|
||||
public struct Round
|
||||
public record Round : GameState
|
||||
{
|
||||
public RoundPhase Phase;
|
||||
public BombStatus Bomb;
|
||||
public CS2Team WinnerTeam;
|
||||
public BombStatus? Bomb;
|
||||
public CS2Team? WinnerTeam;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{GetType()}\n" +
|
||||
$"\t{Phase} {WinnerTeam} {Bomb}\n";
|
||||
return base.ToString();
|
||||
}
|
||||
|
||||
internal static Round? ParseFromJObject(JObject jsonObject)
|
||||
{
|
||||
return new Round()
|
||||
return jsonObject.SelectToken("round") is not null ? new Round()
|
||||
{
|
||||
Phase = RoundPhaseFromString(jsonObject.SelectToken("round.phase")!.Value<string>()!),
|
||||
WinnerTeam = CS2TeamFromString(jsonObject.SelectToken("round.win_team")!.Value<string>()!),
|
||||
Bomb = BombStatusFromString(jsonObject.SelectToken("round.bomb")!.Value<string>()!)
|
||||
};
|
||||
WinnerTeam = CS2TeamFromString(jsonObject.SelectToken("round.win_team")?.Value<string>()),
|
||||
Bomb = BombStatusFromString(jsonObject.SelectToken("round.bomb")?.Value<string>())
|
||||
} : null;
|
||||
}
|
||||
|
||||
public enum RoundPhase
|
||||
{
|
||||
Over, Freezetime, Live
|
||||
}
|
||||
|
||||
private static RoundPhase RoundPhaseFromString(string str)
|
||||
{
|
||||
return str switch
|
||||
@ -44,24 +44,24 @@ public struct Round
|
||||
Planted, Exploded, Defused
|
||||
}
|
||||
|
||||
private static BombStatus BombStatusFromString(string str)
|
||||
private static BombStatus? BombStatusFromString(string? str)
|
||||
{
|
||||
return str switch
|
||||
{
|
||||
"planted" => BombStatus.Planted,
|
||||
"exploded" => BombStatus.Exploded,
|
||||
"defused" => BombStatus.Defused,
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
|
||||
private static CS2Team CS2TeamFromString(string str)
|
||||
private static CS2Team? CS2TeamFromString(string? str)
|
||||
{
|
||||
return str.ToLower() switch
|
||||
return str?.ToLower() switch
|
||||
{
|
||||
"t" => CS2Team.T,
|
||||
"ct" => CS2Team.CT,
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
}
|
72
CS2GSI/Resources.Designer.cs
generated
72
CS2GSI/Resources.Designer.cs
generated
@ -89,5 +89,77 @@ namespace CS2GSI {
|
||||
return ResourceManager.GetString("GSI_CFG_Content", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Installing GSI-Configfile....
|
||||
/// </summary>
|
||||
internal static string Installing_GSI_File {
|
||||
get {
|
||||
return ResourceManager.GetString("Installing_GSI_File", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Could not install GSI-Configfile. Exiting..
|
||||
/// </summary>
|
||||
internal static string Installing_GSI_File_Failed {
|
||||
get {
|
||||
return ResourceManager.GetString("Installing_GSI_File_Failed", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Could not get Steam-Installation FolderPath.
|
||||
/// </summary>
|
||||
internal static string No_Installation_Folderpath {
|
||||
get {
|
||||
return ResourceManager.GetString("No_Installation_Folderpath", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to No libraryfolders.vdf found.
|
||||
/// </summary>
|
||||
internal static string No_Libraryfolders_vdf {
|
||||
get {
|
||||
return ResourceManager.GetString("No_Libraryfolders_vdf", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to No Steam Installation found..
|
||||
/// </summary>
|
||||
internal static string No_Steam {
|
||||
get {
|
||||
return ResourceManager.GetString("No_Steam", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Received State.
|
||||
/// </summary>
|
||||
internal static string Received_State {
|
||||
get {
|
||||
return ResourceManager.GetString("Received_State", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Unknown Event.
|
||||
/// </summary>
|
||||
internal static string Unknown_Event {
|
||||
get {
|
||||
return ResourceManager.GetString("Unknown_Event", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Updated Local State.
|
||||
/// </summary>
|
||||
internal static string Updated_Local_State {
|
||||
get {
|
||||
return ResourceManager.GetString("Updated_Local_State", resourceCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
38
CS2GSI/Resources.de.resx
Normal file
38
CS2GSI/Resources.de.resx
Normal file
@ -0,0 +1,38 @@
|
||||
<root>
|
||||
<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="Installing_GSI_File" xml:space="preserve">
|
||||
<value>Installiere GSI-Konfigurationsdatei...</value>
|
||||
</data>
|
||||
<data name="Installing_GSI_File_Failed" xml:space="preserve">
|
||||
<value>GSI-Konfigurationsdatei nicht installiert.</value>
|
||||
</data>
|
||||
<data name="No_Installation_Folderpath" xml:space="preserve">
|
||||
<value>Steam-Installationspfad konnte nicht gefunden werden.</value>
|
||||
</data>
|
||||
<data name="No_Libraryfolders_vdf" xml:space="preserve">
|
||||
<value>libraryfolders.vdf nicht gefunden</value>
|
||||
</data>
|
||||
<data name="No_Steam" xml:space="preserve">
|
||||
<value>Keine Steam Installation gefunden.</value>
|
||||
</data>
|
||||
<data name="Received_State" xml:space="preserve">
|
||||
<value>Erhaltener Zustand</value>
|
||||
</data>
|
||||
<data name="Unknown_Event" xml:space="preserve">
|
||||
<value>Unbekanntes Ereignis</value>
|
||||
</data>
|
||||
<data name="Updated_Local_State" xml:space="preserve">
|
||||
<value>Erneuerter Lokaler Zustand</value>
|
||||
</data>
|
||||
</root>
|
@ -21,4 +21,29 @@
|
||||
<data name="GSI_CFG_Content" type="System.Resources.ResXFileRef">
|
||||
<value>gamestate_integration_cs2gsi.cfg;System.String, mscorlib, Version=4.0.0.0, Culture=neutral</value>
|
||||
</data>
|
||||
<data name="Unknown_Event" xml:space="preserve">
|
||||
<value>Unknown Event</value>
|
||||
<comment>Event is not defined</comment>
|
||||
</data>
|
||||
<data name="Installing_GSI_File" xml:space="preserve">
|
||||
<value>Installing GSI-Configfile...</value>
|
||||
</data>
|
||||
<data name="Installing_GSI_File_Failed" xml:space="preserve">
|
||||
<value>Could not install GSI-Configfile. Exiting.</value>
|
||||
</data>
|
||||
<data name="Received_State" xml:space="preserve">
|
||||
<value>Received State</value>
|
||||
</data>
|
||||
<data name="Updated_Local_State" xml:space="preserve">
|
||||
<value>Updated Local State</value>
|
||||
</data>
|
||||
<data name="No_Installation_Folderpath" xml:space="preserve">
|
||||
<value>Could not get Steam-Installation FolderPath</value>
|
||||
</data>
|
||||
<data name="No_Libraryfolders_vdf" xml:space="preserve">
|
||||
<value>No libraryfolders.vdf found</value>
|
||||
</data>
|
||||
<data name="No_Steam" xml:space="preserve">
|
||||
<value>No Steam Installation found.</value>
|
||||
</data>
|
||||
</root>
|
53
README.md
53
README.md
@ -1,2 +1,55 @@
|
||||
# CS2GSI
|
||||
[](/LICENSE)
|
||||
[](https://www.nuget.org/packages/CS2GSI/)
|
||||
[](https://github.com/C9Glax/CS2GSI)
|
||||
[](https://github.com/C9Glax/CS2GSI/releases/latest)
|
||||
|
||||
## .net7.0, .net8.0, .net9.0
|
||||
|
||||
|
||||
## Example Usage
|
||||
```csharp
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
CS2GSI.CS2GSI gsi = new ();
|
||||
gsi.AnyMessage += eventArgs => Console.WriteLine("Message");
|
||||
gsi.OnKill += eventArgs => Console.WriteLine($"Kill number {eventArgs.ValueAsOrDefault<int>()}");
|
||||
while(gsi.IsRunning)
|
||||
Thread.Sleep(10);
|
||||
}
|
||||
```
|
||||
|
||||
### Events
|
||||
|
||||
All Events with IDs here: https://github.com/C9Glax/CS2GSI/blob/master/CS2GSI/CS2Event.cs
|
||||
|
||||
`EventName` (_ParameterType_) Description
|
||||
|
||||
* `OnKill` (_int_) Number of Kills in Match
|
||||
* `OnHeadshot` (_int_) Number of Headshots in Round
|
||||
* `OnDeath` (_int_) Number of Deaths in Match
|
||||
* `OnFlashed`
|
||||
* `OnBurning`
|
||||
* `OnSmoked`
|
||||
* `OnRoundStart`
|
||||
* `OnRoundOver`
|
||||
* `OnRoundWin`
|
||||
* `OnRoundLoss`
|
||||
* `OnDamageTaken` (_int_) Amount of Damage Taken
|
||||
* `OnMatchStart`
|
||||
* `OnMatchOver`
|
||||
* `OnMoneyChange` (_int_) Delta in Money
|
||||
* `OnHealthChange` (_int_) Delta in Health
|
||||
* `OnArmorChange` (_int_) Delta in Armor
|
||||
* `OnHelmetChange` (_bool_) Helmet on/off
|
||||
* `OnEquipmentValueChange` (_int_) Delta in Equipmentvalue
|
||||
* `OnTeamChange`
|
||||
* `OnPlayerChange` (_string_) SteamId64
|
||||
* `OnHalfTime`
|
||||
* `OnFreezeTime`
|
||||
* `OnBombPlanted`
|
||||
* `OnBombDefused`
|
||||
* `OnBombExploded`
|
||||
* `AnyEvent`
|
||||
* `AnyMessage`
|
||||
* `OnActivityChange` (_string_) Activity
|
@ -1,11 +1,14 @@
|
||||
// See https://aka.ms/new-console-template for more information
|
||||
|
||||
using CS2GSI.TestApp;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
public class TestApp
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
new CS2GSI.CS2GSI(new Logger());
|
||||
CS2GSI.CS2GSI gsi = new (new Logger(LogLevel.Debug));
|
||||
while(gsi.IsRunning)
|
||||
Thread.Sleep(10);
|
||||
}
|
||||
}
|
@ -2,9 +2,10 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<TargetFrameworks>net7.0;net8.0;net9.0</TargetFrameworks>
|
||||
<LangVersion>latestmajor</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
Reference in New Issue
Block a user