Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: client message. #695

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,21 @@ set(SOURCE_FILES
src/core/managers/server_manager.h
src/scripting/natives/natives_server.cpp
src/scripting/natives/natives_usermessages.cpp
src/scripting/natives/natives_clientmessages.cpp
libraries/nlohmann/json.hpp
src/core/managers/voice_manager.cpp
src/core/managers/voice_manager.h
src/core/managers/usermessage_manager.cpp
src/core/managers/usermessage_manager.h
src/core/managers/clientmessage_manager.cpp
src/core/managers/clientmessage_manager.h
src/scripting/natives/natives_dynamichooks.cpp
src/core/game_system.h
src/core/game_system.cpp
src/core/UserMessage.h
src/core/UserMessage.cpp
src/core/ClientMessage.h
src/core/ClientMessage.cpp
src/core/recipientfilters.h
)

Expand Down
6 changes: 6 additions & 0 deletions configs/addons/counterstrikesharp/gamedata/gamedata.json
Original file line number Diff line number Diff line change
Expand Up @@ -265,5 +265,11 @@
"windows": 584,
"linux": 584
}
},
"CServerSideClient": {
"offsets": {
"windows": 8,
"linux": -64
}
jaredliu2018 marked this conversation as resolved.
Show resolved Hide resolved
}
}
5 changes: 5 additions & 0 deletions docfx/examples/WithClientMessages.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[!INCLUDE [WithClientMessages](../../examples/WithClientMessages/README.md)]

<a href="https://github.com/roflmuffin/CounterStrikeSharp/tree/main/examples/WithClientMessages" class="btn btn-secondary">View project on Github <i class="bi bi-github"></i></a>

[!code-csharp[](../../examples/WithClientMessages/WithClientMessagesPlugin.cs)]
2 changes: 2 additions & 0 deletions docfx/examples/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ items:
href: WithTranslations.md
- name: User Messages
href: WithUserMessages.md
- name: Client Messages
href: WithClientMessages.md
- name: Voice Overrides
href: WithVoiceOverrides.md
- name: Warcraft Plugin
Expand Down
2 changes: 2 additions & 0 deletions examples/WithClientMessages/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# With Client Messages
This is example shows how you can hook, interrupt and send Client Messages.
12 changes: 12 additions & 0 deletions examples/WithClientMessages/WithClientMessages.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<CopyLocalLockFileAssemblies>false</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\managed\CounterStrikeSharp.API\CounterStrikeSharp.API.csproj" />
</ItemGroup>
</Project>
40 changes: 40 additions & 0 deletions examples/WithClientMessages/WithClientMessagesPlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes;
using CounterStrikeSharp.API.Modules.ClientMessages;
using Microsoft.Extensions.Logging;
using Serilog.Core;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
namespace WithClientMessages;

[MinimumApiVersion(80)]
public class WithClientMessagesPlugin : BasePlugin
{
public override string ModuleName => "Example: With Client Messages";
public override string ModuleVersion => "1.0.0";
public override string ModuleAuthor => "CounterStrikeSharp & Contributors";
public override string ModuleDescription => "A simple plugin that hooks and sends Client Messages";

public override void Load(bool hotReload)
{
// Hooks can be added using the client message ID. In this case it's the ID for `CClientMsg_CustomGameEvent`.
HookClientMessage(280, cm =>
{
string event_name = cm.ReadString("event_name");
byte[] data = cm.ReadBytes("data");

// send back
var message = ClientMessage.FromPartialName("CClientMsg_CustomGameEvent");
message.SetString("event_name", event_name);
message.SetBytes("data", data);

var player = Utilities.GetPlayerFromSlot(cm.Sender)!;

message.Send(player);

return HookResult.Continue;
}, HookMode.Pre);
}
}
Loading