Skip to content

Commit

Permalink
fix: do not unregister hooks to avoid sudden server crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
derkalle4 committed Dec 29, 2024
1 parent 15d95d7 commit ee274e0
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 17 deletions.
1 change: 0 additions & 1 deletion src/RollTheDice+DiceBigTaserBattery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ private void DiceBigTaserBatteryLoad()

private void DiceBigTaserBatteryUnload()
{
DeregisterEventHandler<EventWeaponFire>(EventDiceBigTaserBatteryOnWeaponFire);
DiceBigTaserBatteryReset();
}

Expand Down
6 changes: 2 additions & 4 deletions src/RollTheDice+DiceFastBombAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ private void DiceFastBombActionLoad()

private void DiceFastBombActionUnload()
{
DeregisterEventHandler<EventBombBegindefuse>(DiceFastBombActionEventBeginDefuse);
DeregisterEventHandler<EventBombBeginplant>(DiceFastBombActionEventBeginPlant);
DiceFastBombActionReset();
}

Expand All @@ -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<CPlantedC4>("planted_c4").First();
Server.NextFrame(() =>
{
Expand All @@ -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;
Expand Down
5 changes: 0 additions & 5 deletions src/RollTheDice+DiceIncreaseSpeed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ private void DiceIncreaseSpeedLoad()

private void DiceIncreaseSpeedUnload()
{
DeregisterEventHandler<EventPlayerHurt>(EventDiceIncreaseSpeedOnPlayerHurt);
DiceIncreaseSpeedReset();
}

Expand All @@ -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, () =>
{
Expand Down
1 change: 0 additions & 1 deletion src/RollTheDice+DicePlayerAsChicken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ private void DicePlayerAsChickenUnload()
private void DicePlayerAsChickenReset()
{
// remove listeners
DeregisterEventHandler<EventPlayerDeath>(EventDicePlayerAsChickenOnPlayerDeath);
RemoveListener<Listeners.OnTick>(EventDicePlayerAsChickenOnTick);
RemoveListener<Listeners.CheckTransmit>(EventDicePlayerAsChickenCheckTransmit);
// iterate through all players
Expand Down
1 change: 0 additions & 1 deletion src/RollTheDice+DicePlayerDisguiseAsPlant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ private void DicePlayerDisguiseAsPlantLoad()

private void DicePlayerDisguiseAsPlantUnload()
{
DeregisterEventHandler<EventPlayerDeath>(EventDicePlayerDisguiseAsPlantOnPlayerDeath);
DicePlayerDisguiseAsPlantReset();
}

Expand Down
6 changes: 2 additions & 4 deletions src/RollTheDice+DicePlayerRespawn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ private void DicePlayerRespawnLoad()

private void DicePlayerRespawnUnload()
{
DeregisterEventHandler<EventPlayerDeath>(EventDicePlayerRespawnOnPlayerDeath);
DeregisterEventHandler<EventPlayerTeam>(EventDicePlayerRespawnOnPlayerTeam);
DicePlayerRespawnReset();
}

Expand Down Expand Up @@ -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<string>();
var attacker = @event.Attacker;
if (attacker != null
&& attacker.PlayerPawn != null
&& attacker.PlayerPawn.Value != null
Expand Down
2 changes: 1 addition & 1 deletion src/RollTheDice+DicePlayerVampire.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private void DicePlayerVampireLoad()

private void DicePlayerVampireUnload()
{
DeregisterEventHandler<EventPlayerHurt>(EventDicePlayerVampireOnPlayerHurt);
DicePlayerVampireReset();
}

private void DicePlayerVampireReset()
Expand Down

0 comments on commit ee274e0

Please sign in to comment.