14
14
using CounterStrikeSharp . API . Modules . Timers ;
15
15
using Microsoft . Extensions . Logging ;
16
16
using FortniteEmotes . API ;
17
+ using CounterStrikeSharp . API . Modules . UserMessages ;
17
18
18
19
namespace FortniteEmotes ;
19
20
@@ -23,7 +24,7 @@ public partial class Plugin : BasePlugin, IPluginConfig<PluginConfig>
23
24
public override string ModuleName => "Fortnite Emotes & Dances" ;
24
25
public override string ModuleDescription => "CS2 Port of Fortnite Emotes & Dances" ;
25
26
public override string ModuleAuthor => "Cruze" ;
26
- public override string ModuleVersion => "1.0.7-MeshgroupFix" ;
27
+ public override string ModuleVersion => "1.0.7-MeshgroupFix + SpamFix " ;
27
28
28
29
public required PluginConfig Config { get ; set ; } = new ( ) ;
29
30
@@ -401,8 +402,9 @@ public override void Load(bool hotReload)
401
402
RegisterListener < Listeners . OnTick > ( OnTick ) ;
402
403
RegisterListener < Listeners . OnServerPrecacheResources > ( OnServerPrecacheResources ) ;
403
404
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 ) ;
406
408
VirtualFunctions . CBaseEntity_TakeDamageOldFunc . Hook ( OnTakeDamage , HookMode . Pre ) ;
407
409
408
410
Menu_OnLoad ( ) ;
@@ -433,8 +435,10 @@ public override void Unload(bool hotReload)
433
435
RemoveListener < Listeners . OnTick > ( OnTick ) ;
434
436
RemoveListener < Listeners . OnServerPrecacheResources > ( OnServerPrecacheResources ) ;
435
437
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 ) ;
438
442
VirtualFunctions . CBaseEntity_TakeDamageOldFunc . Unhook ( OnTakeDamage , HookMode . Pre ) ;
439
443
}
440
444
@@ -453,7 +457,7 @@ private HookResult OnTakeDamage(DynamicHook h)
453
457
var pawn = victim . As < CCSPlayerPawn > ( ) ;
454
458
455
459
if ( pawn == null || ! pawn . IsValid ) return HookResult . Continue ;
456
-
460
+
457
461
if ( pawn . OriginalController . Value is not { } victimController ) return HookResult . Continue ;
458
462
459
463
if ( victimController . IsBot || victimController . IsHLTV ) return HookResult . Continue ;
@@ -470,16 +474,44 @@ private HookResult OnTakeDamage(DynamicHook h)
470
474
return HookResult . Continue ;
471
475
}
472
476
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
+ */
473
498
public HookResult OnSay ( CCSPlayerController ? player , CommandInfo command )
474
499
{
475
500
if ( ! Config . ChatTriggersEnabled || player == null )
476
501
return HookResult . Continue ;
477
-
502
+
478
503
string message = command . GetArg ( 1 ) ;
479
504
480
505
if ( string . IsNullOrEmpty ( message ) || message . StartsWith ( "!" ) || message . StartsWith ( "/" ) || message . StartsWith ( "." ) )
481
506
return HookResult . Continue ;
482
507
508
+ OnPlayerSay ( player , message ) ;
509
+
510
+ return HookResult . Continue ;
511
+ }
512
+
513
+ private HookResult OnPlayerSay ( CCSPlayerController player , string message )
514
+ {
483
515
foreach ( var trigger in g_ChatTriggers )
484
516
{
485
517
if ( trigger . Value . Any ( message . Equals ) )
@@ -492,7 +524,7 @@ public HookResult OnSay(CCSPlayerController? player, CommandInfo command)
492
524
hasPerm = true ;
493
525
break ;
494
526
}
495
-
527
+
496
528
if ( permission [ 0 ] == '@' && AdminManager . PlayerHasPermissions ( player , permission ) )
497
529
{
498
530
hasPerm = true ;
@@ -509,7 +541,7 @@ public HookResult OnSay(CCSPlayerController? player, CommandInfo command)
509
541
player . PrintToChat ( $ " { Localizer [ "emote.prefix" ] } { Localizer [ "emote.no-access" ] } ") ;
510
542
return HookResult . Stop ;
511
543
}
512
-
544
+
513
545
hasPerm = false ;
514
546
foreach ( var permission in trigger . Key . Permission )
515
547
{
@@ -518,7 +550,7 @@ public HookResult OnSay(CCSPlayerController? player, CommandInfo command)
518
550
hasPerm = true ;
519
551
break ;
520
552
}
521
-
553
+
522
554
if ( permission [ 0 ] == '@' && AdminManager . PlayerHasPermissions ( player , permission ) )
523
555
{
524
556
hasPerm = true ;
@@ -536,7 +568,7 @@ public HookResult OnSay(CCSPlayerController? player, CommandInfo command)
536
568
player . PrintToChat ( $ " { Localizer [ "emote.prefix" ] } { Localizer [ "emote.no-access" ] } ") ;
537
569
return HookResult . Stop ;
538
570
}
539
-
571
+
540
572
string error = "" ;
541
573
if ( ! PlayEmote ( player , trigger . Key , ref error ) )
542
574
{
@@ -546,14 +578,13 @@ public HookResult OnSay(CCSPlayerController? player, CommandInfo command)
546
578
return HookResult . Stop ;
547
579
}
548
580
}
549
-
550
581
return HookResult . Continue ;
551
582
}
552
583
553
584
public void OnMapStart ( string map )
554
585
{
555
586
g_PlayerSettings = new ( ) ;
556
-
587
+
557
588
g_GameRules = null ;
558
589
559
590
AddTimer ( 1.0f , ( ) =>
0 commit comments