mirror of
https://github.com/roflmuffin/CounterStrikeSharp.git
synced 2025-12-06 16:06:37 -08:00
Compare commits
10 Commits
v1.0.296
...
build-numb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e99d27ca30 | ||
|
|
44d3c51bc7 | ||
|
|
f72e6d5daf | ||
|
|
c8bccb07e0 | ||
|
|
2c0640700a | ||
|
|
0f71e1aebe | ||
|
|
ac38ec249b | ||
|
|
cff24f4321 | ||
|
|
f05cc5e043 | ||
|
|
bd1105d752 |
Submodule libraries/Protobufs updated: b46090af9c...157162d97b
Submodule libraries/hl2sdk-cs2 updated: a658a0f7ef...a26ca82e87
@@ -206,6 +206,18 @@ namespace CounterStrikeSharp.API.Core
|
||||
}
|
||||
}
|
||||
|
||||
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<T>(IntPtr hook, int datatype){
|
||||
lock (ScriptContext.GlobalScriptContext.Lock) {
|
||||
ScriptContext.GlobalScriptContext.Reset();
|
||||
|
||||
@@ -347,4 +347,9 @@ public partial class CCSPlayerController
|
||||
{
|
||||
base.Teleport(position, angles, velocity);
|
||||
}
|
||||
|
||||
public void ReplicateConVar(string conVar, string value)
|
||||
{
|
||||
NativeAPI.ReplicateConvar(Slot, conVar, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public partial class NetworkedVector<T> : NativeObject, IReadOnlyCollection<T>
|
||||
}
|
||||
|
||||
public unsafe uint Size => Unsafe.Read<uint>((void*)Handle);
|
||||
|
||||
|
||||
public unsafe int Count => NativeAPI.GetNetworkVectorSize(Handle);
|
||||
|
||||
public T this[int index]
|
||||
@@ -28,7 +28,7 @@ public partial class NetworkedVector<T> : NativeObject, IReadOnlyCollection<T>
|
||||
{
|
||||
throw new NotSupportedException("Networked vectors currently only support CHandle<T>");
|
||||
}
|
||||
|
||||
|
||||
return (T)Activator.CreateInstance(typeof(T), NativeAPI.GetNetworkVectorElementAt(Handle, index));
|
||||
}
|
||||
}
|
||||
@@ -50,4 +50,4 @@ public partial class NetworkedVector<T> : NativeObject, IReadOnlyCollection<T>
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public class Target
|
||||
private static bool ConstTargetType(string target, out TargetType targetType)
|
||||
{
|
||||
targetType = TargetType.Invalid;
|
||||
if (!target.StartsWith("@"))
|
||||
if (!target.StartsWith('@'))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -50,13 +50,13 @@ public class Target
|
||||
{
|
||||
targetType = TargetType.Invalid;
|
||||
slug = null!;
|
||||
if (!target.StartsWith("#"))
|
||||
if (!target.StartsWith('#'))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
slug = target.TrimStart('#');
|
||||
if (slug.StartsWith("STEAM")) targetType = TargetType.IdSteamEscaped;
|
||||
if (slug.StartsWith("STEAM") && slug.Contains(':')) targetType = TargetType.IdSteamEscaped;
|
||||
else if (!ulong.TryParse(slug, out _)) targetType = TargetType.ExplicitName;
|
||||
else if (slug.Length == 17) targetType = TargetType.IdSteam64;
|
||||
else targetType = TargetType.IdUserid;
|
||||
@@ -101,10 +101,9 @@ public class Target
|
||||
TargetType.GroupNotMe => player.SteamID != caller?.SteamID,
|
||||
TargetType.PlayerMe => player.SteamID == caller?.SteamID,
|
||||
TargetType.IdUserid => player.UserId.ToString() == Slug,
|
||||
TargetType.IdSteamEscaped => ((SteamID)player.SteamID).SteamId2 == Slug,
|
||||
TargetType.IdSteam64 => ((SteamID)player.SteamID).SteamId64.ToString() == Slug,
|
||||
TargetType.ExplicitName => player.PlayerName.Contains(Slug, StringComparison.OrdinalIgnoreCase),
|
||||
TargetType.ImplicitName => player.PlayerName.Contains(Slug, StringComparison.OrdinalIgnoreCase),
|
||||
TargetType.IdSteamEscaped when player.SteamID != 0 => (SteamID)player.SteamID == (SteamID)Slug,
|
||||
TargetType.IdSteam64 => player.SteamID.ToString() == Slug,
|
||||
TargetType.ExplicitName or TargetType.ImplicitName => player.PlayerName.Contains(Slug, StringComparison.OrdinalIgnoreCase),
|
||||
_ => false
|
||||
};
|
||||
}
|
||||
|
||||
@@ -72,6 +72,16 @@ public class FakeConVar<T> where T : IComparable<T>
|
||||
|
||||
try
|
||||
{
|
||||
var argString = args.ArgString;
|
||||
|
||||
if (typeof(T) == typeof(string))
|
||||
{
|
||||
if (argString.Length >= 2 && argString.StartsWith('"') && argString.EndsWith('"'))
|
||||
{
|
||||
argString = argString.Substring(1, argString.Length - 2);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(dotnet8): Replace with IParsable<T>
|
||||
bool success = true;
|
||||
T parsedValue = default(T);
|
||||
@@ -80,11 +90,11 @@ public class FakeConVar<T> where T : IComparable<T>
|
||||
{
|
||||
try
|
||||
{
|
||||
parsedValue = (T)converter.ConvertFromString(args.ArgString);
|
||||
parsedValue = (T)converter.ConvertFromString(argString);
|
||||
}
|
||||
catch
|
||||
{
|
||||
success = typeof(T) == typeof(bool) && TryConvertCustomBoolean(args.ArgString, out parsedValue);
|
||||
success = typeof(T) == typeof(bool) && TryConvertCustomBoolean(argString, out parsedValue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,4 +147,4 @@ public class FakeConVar<T> where T : IComparable<T>
|
||||
_value = value;
|
||||
ValueChanged?.Invoke(this, _value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,8 @@ public static class PluginConfigExtensions
|
||||
{
|
||||
private static readonly JsonSerializerOptions _jsonSerializerOptions = new()
|
||||
{
|
||||
WriteIndented = true
|
||||
WriteIndented = true,
|
||||
ReadCommentHandling = JsonCommentHandling.Skip
|
||||
};
|
||||
|
||||
public static JsonSerializerOptions JsonSerializerOptions => _jsonSerializerOptions;
|
||||
@@ -62,7 +63,7 @@ public static class PluginConfigExtensions
|
||||
|
||||
var configContent = File.ReadAllText(configPath);
|
||||
|
||||
var newConfig = JsonSerializer.Deserialize<T>(configContent)
|
||||
var newConfig = JsonSerializer.Deserialize<T>(configContent, JsonSerializerOptions)
|
||||
?? throw new JsonException($"Deserialization failed for configuration file '{configPath}'.");
|
||||
|
||||
foreach (var property in typeof(T).GetProperties(BindingFlags.Instance | BindingFlags.Public))
|
||||
|
||||
@@ -29,13 +29,13 @@ public class CenterHtmlMenu : BaseMenu
|
||||
public string NextPageColor { get; set; } = "yellow";
|
||||
public string CloseColor { get; set; } = "red";
|
||||
|
||||
public CenterHtmlMenu(string title, BasePlugin plugin) : base(ModifyTitle(title))
|
||||
public CenterHtmlMenu(string title, BasePlugin plugin) : base(title)
|
||||
{
|
||||
_plugin = plugin;
|
||||
}
|
||||
|
||||
|
||||
[Obsolete("Use the constructor that takes a BasePlugin")]
|
||||
public CenterHtmlMenu(string title) : base(ModifyTitle(title))
|
||||
public CenterHtmlMenu(string title) : base(title)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -45,40 +45,18 @@ public class CenterHtmlMenu : BaseMenu
|
||||
{
|
||||
throw new InvalidOperationException("This method is unsupported with the CenterHtmlMenu constructor used." +
|
||||
"Please provide a BasePlugin in the constructor.");
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
MenuManager.OpenCenterHtmlMenu(_plugin, player, this);
|
||||
}
|
||||
|
||||
public override ChatMenuOption AddMenuOption(string display, Action<CCSPlayerController, ChatMenuOption> onSelect,
|
||||
bool disabled = false)
|
||||
{
|
||||
var option = new ChatMenuOption(ModifyOptionDisplay(display), disabled, onSelect);
|
||||
var option = new ChatMenuOption(display, disabled, onSelect);
|
||||
MenuOptions.Add(option);
|
||||
return option;
|
||||
}
|
||||
|
||||
private static string ModifyTitle(string title)
|
||||
{
|
||||
if (title.Length > 32)
|
||||
{
|
||||
Application.Instance.Logger.LogWarning("Title should not be longer than 32 characters for a CenterHtmlMenu");
|
||||
return title[..32];
|
||||
}
|
||||
|
||||
return title;
|
||||
}
|
||||
|
||||
private static string ModifyOptionDisplay(string display)
|
||||
{
|
||||
if (display.Length > 26)
|
||||
{
|
||||
Application.Instance.Logger.LogWarning("Display should not be longer than 26 characters for a CenterHtmlMenu item");
|
||||
return display[..26];
|
||||
}
|
||||
|
||||
return display;
|
||||
}
|
||||
}
|
||||
|
||||
public class CenterHtmlMenuInstance : BaseMenuInstance
|
||||
|
||||
@@ -15,13 +15,17 @@
|
||||
*/
|
||||
|
||||
#include <eiface.h>
|
||||
#include <networksystem/inetworkmessages.h>
|
||||
|
||||
#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 <networkbasetypes.pb.h>
|
||||
|
||||
namespace counterstrikesharp {
|
||||
|
||||
@@ -191,6 +195,25 @@ void SetConVarStringValue(ScriptContext& script_context)
|
||||
pCvar->values = reinterpret_cast<CVValue_t**>((char*)value);
|
||||
}
|
||||
|
||||
void ReplicateConVar(ScriptContext& script_context)
|
||||
{
|
||||
auto slot = script_context.GetArgument<int>(0);
|
||||
auto name = script_context.GetArgument<const char*>(1);
|
||||
auto value = script_context.GetArgument<const char*>(2);
|
||||
|
||||
INetworkMessageInternal* pNetMsg = globals::networkMessages->FindNetworkMessagePartial("SetConVar");
|
||||
auto msg = pNetMsg->AllocateMessage()->ToPB<CNETMsg_SetConVar>();
|
||||
|
||||
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
|
||||
|
||||
@@ -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
|
||||
SET_FAKE_CLIENT_CONVAR_VALUE: clientIndex:int,convarName:string,convarValue:string -> void
|
||||
REPLICATE_CONVAR: clientSlot:int,convarName:string,convarValue:string -> void
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
#include <ios>
|
||||
#include <sstream>
|
||||
|
||||
#include "scripting/autonative.h"
|
||||
#include "core/function.h"
|
||||
#include "scripting/script_engine.h"
|
||||
#include "core/memory.h"
|
||||
#include "core/log.h"
|
||||
#include "core/memory.h"
|
||||
#include "scripting/autonative.h"
|
||||
#include "scripting/script_engine.h"
|
||||
|
||||
namespace counterstrikesharp {
|
||||
std::vector<ValveFunction*> m_managed_ptrs;
|
||||
@@ -44,21 +44,22 @@ ValveFunction* CreateVirtualFunctionBySignature(ScriptContext& script_context)
|
||||
|
||||
auto* function_addr = FindSignature(binary_name, signature_hex_string);
|
||||
|
||||
if (function_addr == nullptr) {
|
||||
if (function_addr == nullptr)
|
||||
{
|
||||
script_context.ThrowNativeError("Could not find signature %s", signature_hex_string);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto args = std::vector<DataType_t>();
|
||||
for (int i = 0; i < num_arguments; i++) {
|
||||
for (int i = 0; i < num_arguments; i++)
|
||||
{
|
||||
args.push_back(script_context.GetArgument<DataType_t>(5 + i));
|
||||
}
|
||||
|
||||
auto function = new ValveFunction(function_addr, CONV_CDECL, args, return_type);
|
||||
function->SetSignature(signature_hex_string);
|
||||
|
||||
CSSHARP_CORE_TRACE("Created virtual function, pointer found at {}, signature {}", function_addr,
|
||||
signature_hex_string);
|
||||
CSSHARP_CORE_TRACE("Created virtual function, pointer found at {}, signature {}", function_addr, signature_hex_string);
|
||||
|
||||
m_managed_ptrs.push_back(function);
|
||||
return function;
|
||||
@@ -72,7 +73,8 @@ ValveFunction* CreateVirtualFunction(ScriptContext& script_context)
|
||||
auto return_type = script_context.GetArgument<DataType_t>(3);
|
||||
|
||||
void** vtable = *(void***)ptr;
|
||||
if (!vtable) {
|
||||
if (!vtable)
|
||||
{
|
||||
script_context.ThrowNativeError("Failed to get the virtual function table.");
|
||||
return nullptr;
|
||||
}
|
||||
@@ -80,7 +82,8 @@ ValveFunction* CreateVirtualFunction(ScriptContext& script_context)
|
||||
auto function_addr = (void*)vtable[vtable_offset];
|
||||
|
||||
auto args = std::vector<DataType_t>();
|
||||
for (int i = 0; i < num_arguments; i++) {
|
||||
for (int i = 0; i < num_arguments; i++)
|
||||
{
|
||||
args.push_back(script_context.GetArgument<DataType_t>(4 + i));
|
||||
}
|
||||
|
||||
@@ -97,7 +100,8 @@ void HookFunction(ScriptContext& script_context)
|
||||
auto callback = script_context.GetArgument<CallbackT>(1);
|
||||
auto post = script_context.GetArgument<bool>(2);
|
||||
|
||||
if (!function) {
|
||||
if (!function)
|
||||
{
|
||||
script_context.ThrowNativeError("Invalid function pointer");
|
||||
return;
|
||||
}
|
||||
@@ -111,7 +115,8 @@ void UnhookFunction(ScriptContext& script_context)
|
||||
auto callback = script_context.GetArgument<CallbackT>(1);
|
||||
auto post = script_context.GetArgument<bool>(2);
|
||||
|
||||
if (!function) {
|
||||
if (!function)
|
||||
{
|
||||
script_context.ThrowNativeError("Invalid function pointer");
|
||||
return;
|
||||
}
|
||||
@@ -123,7 +128,8 @@ void ExecuteVirtualFunction(ScriptContext& script_context)
|
||||
{
|
||||
auto function = script_context.GetArgument<ValveFunction*>(0);
|
||||
|
||||
if (!function) {
|
||||
if (!function)
|
||||
{
|
||||
script_context.ThrowNativeError("Invalid function pointer");
|
||||
return;
|
||||
}
|
||||
@@ -155,8 +161,7 @@ void RemoveAllNetworkVectorElements(ScriptContext& script_context)
|
||||
|
||||
REGISTER_NATIVES(memory, {
|
||||
ScriptEngine::RegisterNativeHandler("CREATE_VIRTUAL_FUNCTION", CreateVirtualFunction);
|
||||
ScriptEngine::RegisterNativeHandler("CREATE_VIRTUAL_FUNCTION_BY_SIGNATURE",
|
||||
CreateVirtualFunctionBySignature);
|
||||
ScriptEngine::RegisterNativeHandler("CREATE_VIRTUAL_FUNCTION_BY_SIGNATURE", CreateVirtualFunctionBySignature);
|
||||
ScriptEngine::RegisterNativeHandler("EXECUTE_VIRTUAL_FUNCTION", ExecuteVirtualFunction);
|
||||
ScriptEngine::RegisterNativeHandler("HOOK_FUNCTION", HookFunction);
|
||||
ScriptEngine::RegisterNativeHandler("UNHOOK_FUNCTION", UnhookFunction);
|
||||
|
||||
Reference in New Issue
Block a user