diff --git a/managed/CounterStrikeSharp.API/Core/API.cs b/managed/CounterStrikeSharp.API/Core/API.cs index 12fe56a27..94c794624 100644 --- a/managed/CounterStrikeSharp.API/Core/API.cs +++ b/managed/CounterStrikeSharp.API/Core/API.cs @@ -206,6 +206,18 @@ public static void SetFakeClientConvarValue(int clientindex, string convarname, } } + public static void ReplicateConvar(int clientslot, string convarname, string convarvalue){ + lock (ScriptContext.GlobalScriptContext.Lock) { + ScriptContext.GlobalScriptContext.Reset(); + ScriptContext.GlobalScriptContext.Push(clientslot); + ScriptContext.GlobalScriptContext.Push(convarname); + ScriptContext.GlobalScriptContext.Push(convarvalue); + ScriptContext.GlobalScriptContext.SetIdentifier(0xC8728BEC); + ScriptContext.GlobalScriptContext.Invoke(); + ScriptContext.GlobalScriptContext.CheckErrors(); + } + } + public static T DynamicHookGetReturn(IntPtr hook, int datatype){ lock (ScriptContext.GlobalScriptContext.Lock) { ScriptContext.GlobalScriptContext.Reset(); diff --git a/managed/CounterStrikeSharp.API/Core/Model/CCSPlayerController.cs b/managed/CounterStrikeSharp.API/Core/Model/CCSPlayerController.cs index 989c5bb44..d79747856 100644 --- a/managed/CounterStrikeSharp.API/Core/Model/CCSPlayerController.cs +++ b/managed/CounterStrikeSharp.API/Core/Model/CCSPlayerController.cs @@ -347,4 +347,9 @@ public VoiceFlags VoiceFlags { base.Teleport(position, angles, velocity); } + + public void ReplicateConVar(string conVar, string value) + { + NativeAPI.ReplicateConvar(Slot, conVar, value); + } } diff --git a/src/scripting/natives/natives_commands.cpp b/src/scripting/natives/natives_commands.cpp index 141b3e23a..f1e8b4a13 100644 --- a/src/scripting/natives/natives_commands.cpp +++ b/src/scripting/natives/natives_commands.cpp @@ -15,13 +15,17 @@ */ #include +#include #include "scripting/autonative.h" #include "scripting/callback_manager.h" #include "core/managers/con_command_manager.h" #include "core/managers/player_manager.h" +#include "core/recipientfilters.h" +#include "igameeventsystem.h" #include "scripting/script_engine.h" #include "core/log.h" +#include namespace counterstrikesharp { @@ -191,6 +195,25 @@ void SetConVarStringValue(ScriptContext& script_context) pCvar->values = reinterpret_cast((char*)value); } +void ReplicateConVar(ScriptContext& script_context) +{ + auto slot = script_context.GetArgument(0); + auto name = script_context.GetArgument(1); + auto value = script_context.GetArgument(2); + + INetworkMessageInternal* pNetMsg = globals::networkMessages->FindNetworkMessagePartial("SetConVar"); + auto msg = pNetMsg->AllocateMessage()->ToPB(); + + CMsg_CVars_CVar* cvarMsg = msg->mutable_convars()->add_cvars(); + cvarMsg->set_name(name); + cvarMsg->set_value(value); + + CSingleRecipientFilter filter(slot); + globals::gameEventSystem->PostEventAbstract(-1, false, &filter, pNetMsg, msg, 0); + + delete msg; +} + REGISTER_NATIVES(commands, { ScriptEngine::RegisterNativeHandler("ADD_COMMAND", AddCommand); ScriptEngine::RegisterNativeHandler("REMOVE_COMMAND", RemoveCommand); @@ -211,5 +234,6 @@ REGISTER_NATIVES(commands, { IssueClientCommandFromServer); ScriptEngine::RegisterNativeHandler("GET_CLIENT_CONVAR_VALUE", GetClientConVarValue); ScriptEngine::RegisterNativeHandler("SET_FAKE_CLIENT_CONVAR_VALUE", SetFakeClientConVarValue); + ScriptEngine::RegisterNativeHandler("REPLICATE_CONVAR", ReplicateConVar); }) } // namespace counterstrikesharp diff --git a/src/scripting/natives/natives_commands.yaml b/src/scripting/natives/natives_commands.yaml index 3504386ae..b59871a32 100644 --- a/src/scripting/natives/natives_commands.yaml +++ b/src/scripting/natives/natives_commands.yaml @@ -12,4 +12,5 @@ ISSUE_CLIENT_COMMAND_FROM_SERVER: slot:int,command:string -> void FIND_CONVAR: name:string -> pointer SET_CONVAR_STRING_VALUE: convar:pointer,value:string -> void GET_CLIENT_CONVAR_VALUE: clientIndex:int,convarName:string -> string -SET_FAKE_CLIENT_CONVAR_VALUE: clientIndex:int,convarName:string,convarValue:string -> void \ No newline at end of file +SET_FAKE_CLIENT_CONVAR_VALUE: clientIndex:int,convarName:string,convarValue:string -> void +REPLICATE_CONVAR: clientSlot:int,convarName:string,convarValue:string -> void