From ee274e0ee1faded7faf5d64b126346b115b15bc9 Mon Sep 17 00:00:00 2001 From: Kalle Date: Sun, 29 Dec 2024 16:22:36 +0100 Subject: [PATCH] fix: do not unregister hooks to avoid sudden server crashes --- src/RollTheDice+DiceBigTaserBattery.cs | 1 - src/RollTheDice+DiceFastBombAction.cs | 6 ++---- src/RollTheDice+DiceIncreaseSpeed.cs | 5 ----- src/RollTheDice+DicePlayerAsChicken.cs | 1 - src/RollTheDice+DicePlayerDisguiseAsPlant.cs | 1 - src/RollTheDice+DicePlayerRespawn.cs | 6 ++---- src/RollTheDice+DicePlayerVampire.cs | 2 +- 7 files changed, 5 insertions(+), 17 deletions(-) diff --git a/src/RollTheDice+DiceBigTaserBattery.cs b/src/RollTheDice+DiceBigTaserBattery.cs index f6b2a06..02cb201 100644 --- a/src/RollTheDice+DiceBigTaserBattery.cs +++ b/src/RollTheDice+DiceBigTaserBattery.cs @@ -27,7 +27,6 @@ private void DiceBigTaserBatteryLoad() private void DiceBigTaserBatteryUnload() { - DeregisterEventHandler(EventDiceBigTaserBatteryOnWeaponFire); DiceBigTaserBatteryReset(); } diff --git a/src/RollTheDice+DiceFastBombAction.cs b/src/RollTheDice+DiceFastBombAction.cs index 1f6ec93..959ed23 100644 --- a/src/RollTheDice+DiceFastBombAction.cs +++ b/src/RollTheDice+DiceFastBombAction.cs @@ -49,8 +49,6 @@ private void DiceFastBombActionLoad() private void DiceFastBombActionUnload() { - DeregisterEventHandler(DiceFastBombActionEventBeginDefuse); - DeregisterEventHandler(DiceFastBombActionEventBeginPlant); DiceFastBombActionReset(); } @@ -64,9 +62,9 @@ private HookResult DiceFastBombActionEventBeginDefuse(EventBombBegindefuse @even { var player = @event.Userid; if (player == null) return HookResult.Continue; + if (!_playersCanInstantDefuse.Contains(player)) return HookResult.Continue; var playerPawn = player.PlayerPawn.Value; if (playerPawn == null) return HookResult.Continue; - if (!_playersCanInstantDefuse.Contains(player)) return HookResult.Continue; var c4 = Utilities.FindAllEntitiesByDesignerName("planted_c4").First(); Server.NextFrame(() => { @@ -80,9 +78,9 @@ private HookResult DiceFastBombActionEventBeginPlant(EventBombBeginplant @event, { var player = @event.Userid; if (player == null) return HookResult.Continue; + if (!_playersCanInstantPlant.Contains(player)) return HookResult.Continue; var playerPawn = player.PlayerPawn.Value; if (playerPawn == null) return HookResult.Continue; - if (!_playersCanInstantPlant.Contains(player)) return HookResult.Continue; var weaponService = playerPawn.WeaponServices?.ActiveWeapon; if (weaponService == null) return HookResult.Continue; var activeWeapon = weaponService.Value; diff --git a/src/RollTheDice+DiceIncreaseSpeed.cs b/src/RollTheDice+DiceIncreaseSpeed.cs index e3503ac..c79d94f 100644 --- a/src/RollTheDice+DiceIncreaseSpeed.cs +++ b/src/RollTheDice+DiceIncreaseSpeed.cs @@ -32,7 +32,6 @@ private void DiceIncreaseSpeedLoad() private void DiceIncreaseSpeedUnload() { - DeregisterEventHandler(EventDiceIncreaseSpeedOnPlayerHurt); DiceIncreaseSpeedReset(); } @@ -56,13 +55,9 @@ private void DiceIncreaseSpeedReset() private HookResult EventDiceIncreaseSpeedOnPlayerHurt(EventPlayerHurt @event, GameEventInfo info) { var victim = @event.Userid; - // ignore if victim is null if (victim == null) return HookResult.Continue; - // ignore if player is not in the list if (!_playersWithIncreasedSpeed.Contains(victim)) return HookResult.Continue; - // check if player is valid if (victim == null || victim.PlayerPawn == null || !victim.PlayerPawn.IsValid || victim.PlayerPawn.Value == null || victim.LifeState != (byte)LifeState_t.LIFE_ALIVE) return HookResult.Continue; - // get player pawn var playerPawn = victim.PlayerPawn.Value!; AddTimer(0f, () => { diff --git a/src/RollTheDice+DicePlayerAsChicken.cs b/src/RollTheDice+DicePlayerAsChicken.cs index 168d408..edff6bf 100644 --- a/src/RollTheDice+DicePlayerAsChicken.cs +++ b/src/RollTheDice+DicePlayerAsChicken.cs @@ -50,7 +50,6 @@ private void DicePlayerAsChickenUnload() private void DicePlayerAsChickenReset() { // remove listeners - DeregisterEventHandler(EventDicePlayerAsChickenOnPlayerDeath); RemoveListener(EventDicePlayerAsChickenOnTick); RemoveListener(EventDicePlayerAsChickenCheckTransmit); // iterate through all players diff --git a/src/RollTheDice+DicePlayerDisguiseAsPlant.cs b/src/RollTheDice+DicePlayerDisguiseAsPlant.cs index 83ca472..2aca2aa 100644 --- a/src/RollTheDice+DicePlayerDisguiseAsPlant.cs +++ b/src/RollTheDice+DicePlayerDisguiseAsPlant.cs @@ -56,7 +56,6 @@ private void DicePlayerDisguiseAsPlantLoad() private void DicePlayerDisguiseAsPlantUnload() { - DeregisterEventHandler(EventDicePlayerDisguiseAsPlantOnPlayerDeath); DicePlayerDisguiseAsPlantReset(); } diff --git a/src/RollTheDice+DicePlayerRespawn.cs b/src/RollTheDice+DicePlayerRespawn.cs index d9bcd01..7c47133 100644 --- a/src/RollTheDice+DicePlayerRespawn.cs +++ b/src/RollTheDice+DicePlayerRespawn.cs @@ -30,8 +30,6 @@ private void DicePlayerRespawnLoad() private void DicePlayerRespawnUnload() { - DeregisterEventHandler(EventDicePlayerRespawnOnPlayerDeath); - DeregisterEventHandler(EventDicePlayerRespawnOnPlayerTeam); DicePlayerRespawnReset(); } @@ -90,15 +88,15 @@ private void EventDicePlayerRespawnOnTick() private HookResult EventDicePlayerRespawnOnPlayerDeath(EventPlayerDeath @event, GameEventInfo info) { var player = @event.Userid; - var attacker = @event.Attacker; if (player == null) return HookResult.Continue; + if (!_playersWithRespawnAbility.ContainsKey(player)) return HookResult.Continue; var playerPawn = player.PlayerPawn.Value; if (playerPawn == null) return HookResult.Continue; var weaponService = playerPawn.WeaponServices; if (weaponService == null) return HookResult.Continue; - if (!_playersWithRespawnAbility.ContainsKey(player)) return HookResult.Continue; // give weapons from attacker because player is dead and has no weapons in weaponsService (they are removed) var tmpWeaponList = new List(); + var attacker = @event.Attacker; if (attacker != null && attacker.PlayerPawn != null && attacker.PlayerPawn.Value != null diff --git a/src/RollTheDice+DicePlayerVampire.cs b/src/RollTheDice+DicePlayerVampire.cs index 967b8a8..c73157a 100644 --- a/src/RollTheDice+DicePlayerVampire.cs +++ b/src/RollTheDice+DicePlayerVampire.cs @@ -25,7 +25,7 @@ private void DicePlayerVampireLoad() private void DicePlayerVampireUnload() { - DeregisterEventHandler(EventDicePlayerVampireOnPlayerHurt); + DicePlayerVampireReset(); } private void DicePlayerVampireReset()