diff --git a/managed/CounterStrikeSharp.API/Core/Model/CCSPlayerController.cs b/managed/CounterStrikeSharp.API/Core/Model/CCSPlayerController.cs index 45acb44e6..2e1757f8d 100644 --- a/managed/CounterStrikeSharp.API/Core/Model/CCSPlayerController.cs +++ b/managed/CounterStrikeSharp.API/Core/Model/CCSPlayerController.cs @@ -1,3 +1,6 @@ +using CounterStrikeSharp.API.Modules.Memory; +using CounterStrikeSharp.API.Modules.Utils; + namespace CounterStrikeSharp.API.Core; public partial class CCSPlayerController @@ -10,9 +13,19 @@ public int? UserId return NativeAPI.GetUseridFromIndex((int)this.EntityIndex.Value.Value); } } - + public void PrintToConsole(string message) { NativeAPI.PrintToConsole((int)EntityIndex.Value.Value, message); } + + public void PrintToChat(string message) + { + VirtualFunctions.ClientPrint(this.Handle, HudDestination.Chat, message, 0, 0, 0, 0); + } + + public void PrintToCenter(string message) + { + VirtualFunctions.ClientPrint(this.Handle, HudDestination.Center, message, 0, 0, 0, 0); + } } \ No newline at end of file diff --git a/managed/CounterStrikeSharp.API/Modules/Memory/VirtualFunctions.cs b/managed/CounterStrikeSharp.API/Modules/Memory/VirtualFunctions.cs new file mode 100644 index 000000000..7922cb395 --- /dev/null +++ b/managed/CounterStrikeSharp.API/Modules/Memory/VirtualFunctions.cs @@ -0,0 +1,16 @@ +using System; +using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Modules.Utils; + +namespace CounterStrikeSharp.API.Modules.Memory; + +public static class VirtualFunctions +{ + public static Action ClientPrint = + VirtualFunction.CreateVoid( + GameData.GetSignature("ClientPrint")); + + public static Action ClientPrintAll = + VirtualFunction.CreateVoid( + GameData.GetSignature("UTIL_ClientPrintAll")); +} \ No newline at end of file diff --git a/managed/CounterStrikeSharp.API/Modules/Utils/HudDestination.cs b/managed/CounterStrikeSharp.API/Modules/Utils/HudDestination.cs new file mode 100644 index 000000000..dd2236f7f --- /dev/null +++ b/managed/CounterStrikeSharp.API/Modules/Utils/HudDestination.cs @@ -0,0 +1,9 @@ +namespace CounterStrikeSharp.API.Modules.Utils; + +public enum HudDestination +{ + Notify = 1, + Console = 2, + Chat = 3, + Center = 4, +} \ No newline at end of file diff --git a/managed/CounterStrikeSharp.API/Server.cs b/managed/CounterStrikeSharp.API/Server.cs index d601fab51..b2f1bef5a 100644 --- a/managed/CounterStrikeSharp.API/Server.cs +++ b/managed/CounterStrikeSharp.API/Server.cs @@ -20,6 +20,8 @@ using System.Linq; using System.Runtime.InteropServices; using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Modules.Memory; +using CounterStrikeSharp.API.Modules.Utils; namespace CounterStrikeSharp.API { @@ -50,6 +52,11 @@ public static void NextFrame(Action task) NativeAPI.QueueTaskForNextFrame(ptr); } + public static void PrintToChatAll(string message) + { + VirtualFunctions.ClientPrintAll(HudDestination.Chat, message, 0, 0, 0, 0); + } + public static string GameDirectory => NativeAPI.GetGameDirectory(); public static bool IsMapValid(string mapName) => NativeAPI.IsMapValid(mapName);