Skip to content

Commit

Permalink
Merge branch 'main' of github.com:roflmuffin/CounterStrikeSharp into …
Browse files Browse the repository at this point in the history
…main
  • Loading branch information
roflmuffin committed Oct 22, 2023
2 parents d661283 + 4aaadfd commit 2c9da17
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
15 changes: 14 additions & 1 deletion managed/CounterStrikeSharp.API/Core/Model/CCSPlayerController.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using CounterStrikeSharp.API.Modules.Memory;
using CounterStrikeSharp.API.Modules.Utils;

namespace CounterStrikeSharp.API.Core;

public partial class CCSPlayerController
Expand All @@ -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);
}
}
16 changes: 16 additions & 0 deletions managed/CounterStrikeSharp.API/Modules/Memory/VirtualFunctions.cs
Original file line number Diff line number Diff line change
@@ -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<IntPtr, HudDestination, string, IntPtr, IntPtr, IntPtr, IntPtr> ClientPrint =
VirtualFunction.CreateVoid<IntPtr, HudDestination, string, IntPtr, IntPtr, IntPtr, IntPtr>(
GameData.GetSignature("ClientPrint"));

public static Action<HudDestination, string, IntPtr, IntPtr, IntPtr, IntPtr> ClientPrintAll =
VirtualFunction.CreateVoid<HudDestination, string, IntPtr, IntPtr, IntPtr, IntPtr>(
GameData.GetSignature("UTIL_ClientPrintAll"));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace CounterStrikeSharp.API.Modules.Utils;

public enum HudDestination
{
Notify = 1,
Console = 2,
Chat = 3,
Center = 4,
}
7 changes: 7 additions & 0 deletions managed/CounterStrikeSharp.API/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 2c9da17

Please sign in to comment.