From 1c161cde5567afa7fa3e69e11df2696d7214c71d Mon Sep 17 00:00:00 2001 From: glax Date: Mon, 15 Jan 2024 23:52:30 +0100 Subject: [PATCH] Add EventArgs --- CS2GSI/CS2EventArgs.cs | 17 ++++++++++++++++- CS2GSI/CS2EventGenerator.cs | 24 ++++++++++++------------ TestApp/Program.cs | 3 ++- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/CS2GSI/CS2EventArgs.cs b/CS2GSI/CS2EventArgs.cs index 0fc497d..8404300 100644 --- a/CS2GSI/CS2EventArgs.cs +++ b/CS2GSI/CS2EventArgs.cs @@ -2,5 +2,20 @@ public class CS2EventArgs : EventArgs { - + public object? Value; + + public CS2EventArgs(object? value = null) + { + this.Value = value; + } + + public T? ValueAsOrDefault() + { + return Value is T val ? val : default; + } + + public override string ToString() + { + return Value?.ToString() ?? "NoArgs"; + } } \ No newline at end of file diff --git a/CS2GSI/CS2EventGenerator.cs b/CS2GSI/CS2EventGenerator.cs index a4a9198..3a4f6d8 100644 --- a/CS2GSI/CS2EventGenerator.cs +++ b/CS2GSI/CS2EventGenerator.cs @@ -12,10 +12,10 @@ internal static class CS2EventGenerator events.AddRange(GenerateMapEvents(previousPlayerState, newGameState, lastGameState)); if(lastGameState.Player?.SteamId != newGameState.Player?.SteamId) - events.Add(new ValueTuple(CS2Event.OnPlayerChange, new CS2EventArgs())); + events.Add(new ValueTuple(CS2Event.OnPlayerChange, new CS2EventArgs(newGameState.Player?.SteamId))); if(events.Count > 0) - events.Add(new ValueTuple(CS2Event.AnyEvent, new CS2EventArgs())); + events.Add(new ValueTuple(CS2Event.AnyEvent, new CS2EventArgs(events.Count))); events.Add(new ValueTuple(CS2Event.AnyMessage, new CS2EventArgs())); return events; @@ -65,13 +65,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.OnKill, new CS2EventArgs())); + events.Add(new ValueTuple(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.OnHeadshot, new CS2EventArgs())); + events.Add(new ValueTuple(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.OnDeath, new CS2EventArgs())); + events.Add(new ValueTuple(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.OnFlashed, new CS2EventArgs())); @@ -83,25 +83,25 @@ internal static class CS2EventGenerator events.Add(new ValueTuple(CS2Event.OnSmoked, new CS2EventArgs())); if(newGameState.Player?.State?.Health < previousPlayerState.Player?.State?.Health && newGameState.Player is { State: not null}) - events.Add(new ValueTuple(CS2Event.OnDamageTaken, new CS2EventArgs())); + events.Add(new ValueTuple(CS2Event.OnDamageTaken, new CS2EventArgs(newGameState.Player?.State?.Health))); if(newGameState.Player?.State?.Health != previousPlayerState.Player?.State?.Health && newGameState.Player is { State: not null}) - events.Add(new ValueTuple(CS2Event.OnHealthChange, new CS2EventArgs())); + events.Add(new ValueTuple(CS2Event.OnHealthChange, new CS2EventArgs(newGameState.Player?.State?.Health))); if(newGameState.Player?.State?.Money != previousPlayerState.Player?.State?.Money && newGameState.Player is { State: not null}) - events.Add(new ValueTuple(CS2Event.OnMoneyChange, new CS2EventArgs())); + events.Add(new ValueTuple(CS2Event.OnMoneyChange, new CS2EventArgs(newGameState.Player?.State?.Money))); if(newGameState.Player?.State?.Armor != previousPlayerState.Player?.State?.Armor && newGameState.Player is { State: not null}) - events.Add(new ValueTuple(CS2Event.OnArmorChange, new CS2EventArgs())); + events.Add(new ValueTuple(CS2Event.OnArmorChange, new CS2EventArgs(newGameState.Player?.State?.Armor))); if(newGameState.Player?.State?.Helmet != previousPlayerState.Player?.State?.Helmet && newGameState.Player is { State: not null}) - events.Add(new ValueTuple(CS2Event.OnHelmetChange, new CS2EventArgs())); + events.Add(new ValueTuple(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.OnEquipmentValueChange, new CS2EventArgs())); + events.Add(new ValueTuple(CS2Event.OnEquipmentValueChange, new CS2EventArgs(newGameState.Player?.State?.EquipmentValue))); if(newGameState.Player?.Team != previousPlayerState.Player?.Team && newGameState.Player is not null) - events.Add(new ValueTuple(CS2Event.OnTeamChange, new CS2EventArgs())); + events.Add(new ValueTuple(CS2Event.OnTeamChange, new CS2EventArgs(newGameState.Player?.Team))); return events; diff --git a/TestApp/Program.cs b/TestApp/Program.cs index ae6f76c..e7cb533 100644 --- a/TestApp/Program.cs +++ b/TestApp/Program.cs @@ -1,11 +1,12 @@ // 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()); + new CS2GSI.CS2GSI(new Logger(LogLevel.Information)); } } \ No newline at end of file