Skip to content

Commit 53cbd91

Browse files
Fixed deaths with no killer being skipped + Fixed deaths by bomb explosion being missed (they don't trigger the player_death event) + Fixed unknown 'weapons' such as trigger_hurt showing Pistol as their Class
1 parent db647fd commit 53cbd91

File tree

4 files changed

+56
-10
lines changed

4 files changed

+56
-10
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<Company>Source Engine Discord</Company>
1616
<Copyright>© 2014 EHVAG, 2020 Source Engine Discord and contributors</Copyright>
1717
<Product>SourceEngine.Demo</Product>
18-
<Version>2.0.8</Version>
18+
<Version>2.0.9</Version>
1919
</PropertyGroup>
2020

2121
<PropertyGroup Label="Package Metadata">

src/SourceEngine.Demo.Parser/DP/Handler/GameEventHandler.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,13 @@ public static void Apply(GameEvent rawEvent, DemoParser parser, bool parseChicke
273273
kill.TeamKill = false;
274274
kill.Suicide = false;
275275

276-
if (kill.Victim != null && kill.Killer != null)
276+
if (kill.Victim != null)
277277
{
278-
if (kill.Victim.SteamID != 0 && kill.Victim.SteamID == kill.Killer.SteamID)
278+
if (kill.Victim.SteamID != 0 && kill.Victim.SteamID == kill.Killer?.SteamID)
279279
{
280280
kill.Suicide = true;
281281
}
282-
else if (kill.Victim.Team == kill.Killer.Team)
282+
else if (kill.Killer != null && kill.Victim.Team == kill.Killer.Team)
283283
{
284284
kill.TeamKill = true;
285285
}
@@ -334,11 +334,20 @@ public static void Apply(GameEvent rawEvent, DemoParser parser, bool parseChicke
334334

335335
hurt.Weapon = new Equipment ((string)data ["weapon"], "");
336336

337-
if (hurt.Attacker != null && hurt.Weapon.Class != EquipmentClass.Grenade && hurt.Attacker.Weapons.Any ()) {
337+
if (hurt.Attacker != null && hurt.Weapon.Class != EquipmentClass.Grenade && hurt.Attacker.Weapons.Any ()) {
338338
hurt.Weapon = hurt.Attacker.ActiveWeapon;
339-
}
339+
}
340+
341+
hurt.TimeInRound = parser.CurrentTime - timestampFreezetimeEnded;
342+
343+
hurt.PossiblyKilledByBombExplosion = (hurt.Health == 0 &&
344+
string.IsNullOrWhiteSpace(hurt.Weapon.OriginalString) &&
345+
hurt.Weapon.Weapon == EquipmentElement.Unknown &&
346+
hurt.Weapon.Class == EquipmentClass.Unknown)
347+
? true
348+
: false;
340349

341-
parser.RaisePlayerHurt (hurt);
350+
parser.RaisePlayerHurt(hurt);
342351
break;
343352

344353
#region Nades

src/SourceEngine.Demo.Parser/Events.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,11 @@ public class HostagePickedUpEventArgs : EventArgs
282282

283283
public class PlayerHurtEventArgs : EventArgs
284284
{
285+
/// <summary>
286+
/// The time in the round the event has occurred
287+
/// </summary>
288+
public double TimeInRound { get; set; }
289+
285290
/// <summary>
286291
/// The hurt player
287292
/// </summary>
@@ -335,6 +340,12 @@ public class PlayerHurtEventArgs : EventArgs
335340
/// </summary>
336341
/// <value>The hitgroup.</value>
337342
public Hitgroup Hitgroup { get; set; }
343+
344+
/// <summary>
345+
/// Shows if it is possible that the player was killed by a bomb explosion (player_death is not triggered when it is due to the bomb (unsure if this is always or just sometimes)).
346+
/// </summary>
347+
/// <value>The hitgroup.</value>
348+
public bool PossiblyKilledByBombExplosion { get; set; }
338349
}
339350

340351
public class BlindEventArgs : EventArgs
@@ -723,7 +734,7 @@ public static EquipmentElement MapEquipment(string OriginalString)
723734

724735
public enum EquipmentElement
725736
{
726-
Unknown = 0,
737+
Unknown = -100,
727738

728739
//Pistols
729740
P2000 = 1,

src/SourceEngine.Demo.Stats/DemoProcessor.cs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,32 @@ public static MatchData FromDemoFile(string file, bool parseChickens, bool parse
587587
md.addEvent(typeof(PlayerKilledEventArgs), e);
588588
};
589589

590+
dp.PlayerHurt += (object sender, PlayerHurtEventArgs e) => { // only interested in player_hurt events when it is possible that a player_death event is not triggered due to death by bomb explosion
591+
if (e.PossiblyKilledByBombExplosion)
592+
{
593+
var round = GetCurrentRoundNum(md);
594+
595+
var playerKilledEventArgs = new PlayerKilledEventArgs()
596+
{
597+
Round = round,
598+
TimeInRound = e.TimeInRound,
599+
Killer = e.Attacker,
600+
KillerBotTakeover = false, // ?
601+
Victim = e.Player,
602+
VictimBotTakeover = false, // ?
603+
Assister = null,
604+
AssisterBotTakeover = false, // ?
605+
Suicide = false,
606+
TeamKill = false,
607+
PenetratedObjects = 0,
608+
Headshot = false,
609+
AssistedFlash = false,
610+
};
611+
612+
md.addEvent(typeof(PlayerKilledEventArgs), playerKilledEventArgs);
613+
}
614+
};
615+
590616
dp.RoundMVP += (object sender, RoundMVPEventArgs e) => {
591617
md.addEvent(typeof(RoundMVPEventArgs), e);
592618
};
@@ -1791,7 +1817,7 @@ public List<playerPositionsStats> GetPlayerPositionsStats(ProcessedData processe
17911817
foreach (var playerPositionsInstance in steamIdsGroup)
17921818
{
17931819
// skip players who have died this round
1794-
if (!processedData.PlayerKilledEventsValues.Any(x => x.Round == playerPositionsStat.Round && x.Victim.SteamID == playerPositionsInstance.SteamID && x.TimeInRound <= playerPositionByTimeInRound.TimeInRound ))
1820+
if (!processedData.PlayerKilledEventsValues.Any(x => x.Round == playerPositionsStat.Round && (x.Victim?.SteamID != 0 && x.Victim.SteamID == playerPositionsInstance.SteamID) && x.TimeInRound <= playerPositionByTimeInRound.TimeInRound ))
17951821
{
17961822
playerPositionByTimeInRound.PlayerPositionBySteamID.Add(new PlayerPositionBySteamID()
17971823
{
@@ -1953,7 +1979,7 @@ public static bool CheckIfPlayerAliveAtThisPointInRound(MatchData md, Player pla
19531979

19541980
var kills = md.events.Where(k => k.Key.Name.ToString() == "PlayerKilledEventArgs").Select(v => (PlayerKilledEventArgs)v.Value.ElementAt(0));
19551981

1956-
return !kills.Any(x => x.Round == round && x.Victim.SteamID == player.SteamID);
1982+
return !kills.Any(x => x.Round == round && (x.Victim?.SteamID != 0 && x.Victim.SteamID == player?.SteamID));
19571983
}
19581984

19591985
public int CheckForUpdatedUserId(int userId)

0 commit comments

Comments
 (0)