Skip to content

Commit e0a4425

Browse files
committed
v1.0.7-SpamFix
1 parent 4c40adf commit e0a4425

File tree

2 files changed

+61
-28
lines changed

2 files changed

+61
-28
lines changed

Plugin/FortniteEmotesNDances.cs

+44-13
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using CounterStrikeSharp.API.Modules.Timers;
1515
using Microsoft.Extensions.Logging;
1616
using FortniteEmotes.API;
17+
using CounterStrikeSharp.API.Modules.UserMessages;
1718

1819
namespace FortniteEmotes;
1920

@@ -23,7 +24,7 @@ public partial class Plugin : BasePlugin, IPluginConfig<PluginConfig>
2324
public override string ModuleName => "Fortnite Emotes & Dances";
2425
public override string ModuleDescription => "CS2 Port of Fortnite Emotes & Dances";
2526
public override string ModuleAuthor => "Cruze";
26-
public override string ModuleVersion => "1.0.7-MeshgroupFix";
27+
public override string ModuleVersion => "1.0.7-MeshgroupFix + SpamFix";
2728

2829
public required PluginConfig Config { get; set; } = new();
2930

@@ -401,8 +402,9 @@ public override void Load(bool hotReload)
401402
RegisterListener<Listeners.OnTick>(OnTick);
402403
RegisterListener<Listeners.OnServerPrecacheResources>(OnServerPrecacheResources);
403404

404-
AddCommandListener("say", OnSay, HookMode.Pre);
405-
AddCommandListener("say_team", OnSay, HookMode.Pre);
405+
// AddCommandListener("say", OnSay, HookMode.Pre);
406+
// AddCommandListener("say_team", OnSay, HookMode.Pre);
407+
HookUserMessage(118, OnMessage, HookMode.Pre);
406408
VirtualFunctions.CBaseEntity_TakeDamageOldFunc.Hook(OnTakeDamage, HookMode.Pre);
407409

408410
Menu_OnLoad();
@@ -433,8 +435,10 @@ public override void Unload(bool hotReload)
433435
RemoveListener<Listeners.OnTick>(OnTick);
434436
RemoveListener<Listeners.OnServerPrecacheResources>(OnServerPrecacheResources);
435437

436-
RemoveCommandListener("say", OnSay, HookMode.Pre);
437-
RemoveCommandListener("say_team", OnSay, HookMode.Pre);
438+
// RemoveCommandListener("say", OnSay, HookMode.Pre);
439+
// RemoveCommandListener("say_team", OnSay, HookMode.Pre);
440+
441+
UnhookUserMessage(118, OnMessage, HookMode.Pre);
438442
VirtualFunctions.CBaseEntity_TakeDamageOldFunc.Unhook(OnTakeDamage, HookMode.Pre);
439443
}
440444

@@ -453,7 +457,7 @@ private HookResult OnTakeDamage(DynamicHook h)
453457
var pawn = victim.As<CCSPlayerPawn>();
454458

455459
if (pawn == null || !pawn.IsValid) return HookResult.Continue;
456-
460+
457461
if (pawn.OriginalController.Value is not { } victimController) return HookResult.Continue;
458462

459463
if (victimController.IsBot || victimController.IsHLTV) return HookResult.Continue;
@@ -470,16 +474,44 @@ private HookResult OnTakeDamage(DynamicHook h)
470474
return HookResult.Continue;
471475
}
472476

477+
public HookResult OnMessage(UserMessage um)
478+
{
479+
if (Utilities.GetPlayerFromIndex(um.ReadInt("entityindex")) is not CCSPlayerController player || player.IsBot)
480+
{
481+
return HookResult.Continue;
482+
}
483+
484+
if(!Config.ChatTriggersEnabled || player == null)
485+
return HookResult.Continue;
486+
487+
string message = um.ReadString("param2");
488+
489+
if(string.IsNullOrEmpty(message) || message.StartsWith("!") || message.StartsWith("/") || message.StartsWith("."))
490+
return HookResult.Continue;
491+
492+
return OnPlayerSay(player, message);
493+
}
494+
495+
/*
496+
Not using this since RemoveCommandListener("say") doesn't actually remove listener and was causing issue when hot-reloading plugin
497+
*/
473498
public HookResult OnSay(CCSPlayerController? player, CommandInfo command)
474499
{
475500
if(!Config.ChatTriggersEnabled || player == null)
476501
return HookResult.Continue;
477-
502+
478503
string message = command.GetArg(1);
479504

480505
if(string.IsNullOrEmpty(message) || message.StartsWith("!") || message.StartsWith("/") || message.StartsWith("."))
481506
return HookResult.Continue;
482507

508+
OnPlayerSay(player, message);
509+
510+
return HookResult.Continue;
511+
}
512+
513+
private HookResult OnPlayerSay(CCSPlayerController player, string message)
514+
{
483515
foreach(var trigger in g_ChatTriggers)
484516
{
485517
if(trigger.Value.Any(message.Equals))
@@ -492,7 +524,7 @@ public HookResult OnSay(CCSPlayerController? player, CommandInfo command)
492524
hasPerm = true;
493525
break;
494526
}
495-
527+
496528
if(permission[0] == '@' && AdminManager.PlayerHasPermissions(player, permission))
497529
{
498530
hasPerm = true;
@@ -509,7 +541,7 @@ public HookResult OnSay(CCSPlayerController? player, CommandInfo command)
509541
player.PrintToChat($" {Localizer["emote.prefix"]} {Localizer["emote.no-access"]}");
510542
return HookResult.Stop;
511543
}
512-
544+
513545
hasPerm = false;
514546
foreach(var permission in trigger.Key.Permission)
515547
{
@@ -518,7 +550,7 @@ public HookResult OnSay(CCSPlayerController? player, CommandInfo command)
518550
hasPerm = true;
519551
break;
520552
}
521-
553+
522554
if(permission[0] == '@' && AdminManager.PlayerHasPermissions(player, permission))
523555
{
524556
hasPerm = true;
@@ -536,7 +568,7 @@ public HookResult OnSay(CCSPlayerController? player, CommandInfo command)
536568
player.PrintToChat($" {Localizer["emote.prefix"]} {Localizer["emote.no-access"]}");
537569
return HookResult.Stop;
538570
}
539-
571+
540572
string error = "";
541573
if(!PlayEmote(player, trigger.Key, ref error))
542574
{
@@ -546,14 +578,13 @@ public HookResult OnSay(CCSPlayerController? player, CommandInfo command)
546578
return HookResult.Stop;
547579
}
548580
}
549-
550581
return HookResult.Continue;
551582
}
552583

553584
public void OnMapStart(string map)
554585
{
555586
g_PlayerSettings = new();
556-
587+
557588
g_GameRules = null;
558589

559590
AddTimer(1.0f, () =>

Plugin/Helpers.cs

+17-15
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class PlayerSettings
3232
public CDynamicProp? CameraProp { get; set; } = null;
3333
public CDynamicProp? AnimProp { get; set; } = null;
3434
public uint CameraPropIndex { get; set; } = 0;
35-
public int Cooldown { get; set; } = 0;
35+
public float Cooldown { get; set; } = 0;
3636
public CSSTimer? Timer { get; set; } = null;
3737
public CSSTimer? DefaultAnimTimer { get; set; } = null;
3838
public CSSTimer? SoundTimer { get; set; } = null;
@@ -98,7 +98,7 @@ public bool PlayEmote(CCSPlayerController target, Emote emote, ref string error,
9898
break;
9999
}
100100

101-
if(!target.IsValidPlayer() || !target.PlayerPawn.IsValidPawnAlive() || target.ControllingBot || target.AbsOrigin == null || target.PlayerPawn.Value!.CameraServices == null)
101+
if(!target.IsValidPlayer() || !target.PlayerPawn.IsValidPawnAlive() || target.ControllingBot || target.AbsOrigin == null || target.PlayerPawn.Value?.CameraServices == null)
102102
{
103103
error = $" {Localizer["emote.prefix"]} {Localizer[$"emote{(player == null ? "":".player")}.alivecheck"]}";
104104
return false;
@@ -119,7 +119,7 @@ public bool PlayEmote(CCSPlayerController target, Emote emote, ref string error,
119119

120120
if(g_PlayerSettings[steamID].Cooldown > time && player == null)
121121
{
122-
error = $" {Localizer["emote.prefix"]} {Localizer["emote.cooldowncheck", g_PlayerSettings[steamID].Cooldown - time]}";
122+
error = $" {Localizer["emote.prefix"]} {Localizer["emote.cooldowncheck", (int)g_PlayerSettings[steamID].Cooldown - time]}";
123123
return false;
124124
}
125125

@@ -250,10 +250,7 @@ public bool PlayEmote(CCSPlayerController target, Emote emote, ref string error,
250250
g_PlayerSettings[steamID].CameraProp = SetCam(target);
251251
g_PlayerSettings[steamID].CameraPropIndex = g_PlayerSettings[steamID].CameraProp?.Index ?? 0;
252252

253-
Server.RunOnTick(Server.TickCount + 4, () =>
254-
{
255-
g_PlayerSettings[steamID].IsDancing = true;
256-
});
253+
g_PlayerSettings[steamID].IsDancing = true;
257254

258255
if(player == null)
259256
{
@@ -276,12 +273,16 @@ public bool PlayEmote(CCSPlayerController target, Emote emote, ref string error,
276273
break;
277274
}
278275
}
279-
280-
g_PlayerSettings[steamID].Cooldown = time + (hasVIP ? Config.EmoteVIPCooldown : Config.EmoteCooldown);
276+
float cdTime = hasVIP ? Config.EmoteVIPCooldown : Config.EmoteCooldown;
277+
if(cdTime <= 0)
278+
{
279+
cdTime = 0.1f;
280+
}
281+
g_PlayerSettings[steamID].Cooldown = time + cdTime;
281282
}
282-
283+
283284
string emoteName = $"{Localizer[$"{emote.Name}"]}";
284-
285+
285286
target.PrintToChat($" {Localizer["emote.prefix"]} {Localizer["emote.playing", emoteName]}");
286287

287288
if(Config.SoundModuleEnabled)
@@ -300,7 +301,7 @@ public bool PlayEmote(CCSPlayerController target, Emote emote, ref string error,
300301
g_PlayerSettings[steamID].Reset();
301302
return;
302303
}
303-
304+
304305
DebugLogs("SoundPlayed: " + emote.Sound);
305306
EmitSound(target, emote.Sound, emote.SoundVolume);
306307
}, TimerFlags.REPEAT|TimerFlags.STOP_ON_MAPCHANGE);
@@ -815,7 +816,7 @@ private void RefreshPlayerGloves(CCSPlayerController player, bool update = false
815816
{
816817
if(!Config.EmoteGlovesFix)
817818
return;
818-
819+
819820
if(!player.IsValidPlayer() || !player.PlayerPawn.IsValidPawnAlive())
820821
return;
821822

@@ -824,9 +825,10 @@ private void RefreshPlayerGloves(CCSPlayerController player, bool update = false
824825
return;
825826

826827
var model = playerPawnValue.CBodyComponent?.SceneNode?.GetSkeletonInstance()?.ModelState.ModelName ?? string.Empty;
827-
ulong meshgroupmask = playerPawnValue.CBodyComponent?.SceneNode?.GetSkeletonInstance()?.ModelState.MeshGroupMask ?? 0;
828+
828829
if (!string.IsNullOrEmpty(model))
829830
{
831+
ulong meshgroupmask = playerPawnValue.CBodyComponent?.SceneNode?.GetSkeletonInstance()?.ModelState.MeshGroupMask ?? 0;
830832
playerPawnValue.SetModel("characters/models/tm_jumpsuit/tm_jumpsuit_varianta.vmdl");
831833
playerPawnValue.SetModel(model);
832834

@@ -843,7 +845,7 @@ private void RefreshPlayerGloves(CCSPlayerController player, bool update = false
843845
{
844846
if(playerPawnValue == null)
845847
return;
846-
848+
847849
SetBodygroup(playerPawnValue.Handle, "default_gloves", 1);
848850
});
849851
}

0 commit comments

Comments
 (0)