diff --git a/.clang-format b/.clang-format
index fce858d1..0828fb5c 100644
--- a/.clang-format
+++ b/.clang-format
@@ -38,7 +38,7 @@ BraceWrapping:
SplitEmptyNamespace: true
PointerAlignment: Left
-SortIncludes: CaseSensitive
+SortIncludes: Never
IncludeBlocks: Regroup
IncludeCategories:
# External headers in <> with extension or /
diff --git a/.devcontainer/linux/devcontainer.json b/.devcontainer/linux/devcontainer.json
index e0c201dd..aafc31ec 100644
--- a/.devcontainer/linux/devcontainer.json
+++ b/.devcontainer/linux/devcontainer.json
@@ -1,11 +1,18 @@
{
"name": "SteamRT Sniper SDK",
"image": "registry.gitlab.steamos.cloud/steamrt/sniper/sdk:latest",
- "customizations": {
+ "updateContentCommand": "git submodule update --init --recursive",
+ "customizations": {
"vscode": {
"extensions": [
- "ms-vscode.cpptools"
+ "ms-vscode.cpptools",
+ "ms-vscode.cpptools-extension-pack",
+ "GitHub.copilot",
+ "jeff-hykin.better-cpp-syntax"
]
}
+ },
+ "features": {
+ "ghcr.io/devcontainers/features/dotnet": "8.0"
}
}
\ No newline at end of file
diff --git a/.github/workflows/lint-code.yaml b/.github/workflows/lint-code.yaml
new file mode 100644
index 00000000..4e036e38
--- /dev/null
+++ b/.github/workflows/lint-code.yaml
@@ -0,0 +1,25 @@
+name: Code format checks
+
+on:
+ pull_request:
+ paths:
+ - '.github/workflows/**'
+ - 'src/**'
+ - '.clang-format'
+ push:
+ paths:
+ - '.github/workflows/**'
+ - 'src/**'
+ - '.clang-format'
+
+jobs:
+ lint:
+ name: Lint code with clang-format
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ - uses: jidicula/clang-format-action@4726374d1aa3c6aecf132e5197e498979588ebc8
+ with:
+ clang-format-version: '20'
+ check-path: 'src'
+ exclude-regex: '(sdk|\.proto)'
\ No newline at end of file
diff --git a/src/core/UserMessage.cpp b/src/core/UserMessage.cpp
index acda7080..0e87e201 100644
--- a/src/core/UserMessage.cpp
+++ b/src/core/UserMessage.cpp
@@ -1,41 +1,41 @@
-/*
- * This file is part of CounterStrikeSharp.
- * CounterStrikeSharp is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * CounterStrikeSharp is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with CounterStrikeSharp. If not, see . *
- */
-#include "UserMessage.h"
-
-#include "networksystem/inetworkserializer.h"
-
-using namespace google;
-
-namespace counterstrikesharp {
-int UserMessage::GetMessageID() { return msgSerializable->GetNetMessageInfo()->m_MessageId; }
-
-std::string UserMessage::GetMessageName() { return msgSerializable->GetUnscopedName(); }
-
-bool UserMessage::HasField(std::string fieldName)
-{
- const google::protobuf::Descriptor* descriptor = msg->GetDescriptor();
- const google::protobuf::FieldDescriptor* field = descriptor->FindFieldByName(fieldName);
-
- if (field == nullptr || (field->label() == google::protobuf::FieldDescriptor::LABEL_REPEATED))
- {
- return false;
- }
-
- return this->msg->GetReflection()->HasField(*this->msg, field);
-}
-
-const CNetMessagePB* UserMessage::GetProtobufMessage() { return msg; }
-} // namespace counterstrikesharp
+/*
+ * This file is part of CounterStrikeSharp.
+ * CounterStrikeSharp is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * CounterStrikeSharp is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with CounterStrikeSharp. If not, see . *
+ */
+#include "UserMessage.h"
+
+#include "networksystem/inetworkserializer.h"
+
+using namespace google;
+
+namespace counterstrikesharp {
+int UserMessage::GetMessageID() { return msgSerializable->GetNetMessageInfo()->m_MessageId; }
+
+std::string UserMessage::GetMessageName() { return msgSerializable->GetUnscopedName(); }
+
+bool UserMessage::HasField(std::string fieldName)
+{
+ const google::protobuf::Descriptor* descriptor = msg->GetDescriptor();
+ const google::protobuf::FieldDescriptor* field = descriptor->FindFieldByName(fieldName);
+
+ if (field == nullptr || (field->label() == google::protobuf::FieldDescriptor::LABEL_REPEATED))
+ {
+ return false;
+ }
+
+ return this->msg->GetReflection()->HasField(*this->msg, field);
+}
+
+const CNetMessagePB* UserMessage::GetProtobufMessage() { return msg; }
+} // namespace counterstrikesharp
diff --git a/src/core/cs2_sdk/interfaces/cgameresourceserviceserver.h b/src/core/cs2_sdk/interfaces/cgameresourceserviceserver.h
index a3955277..40bad521 100644
--- a/src/core/cs2_sdk/interfaces/cgameresourceserviceserver.h
+++ b/src/core/cs2_sdk/interfaces/cgameresourceserviceserver.h
@@ -28,8 +28,7 @@ class CGameResourceService
public:
CGameEntitySystem* GetGameEntitySystem()
{
- return *reinterpret_cast(
- (uintptr_t)(this) +
- counterstrikesharp::globals::gameConfig->GetOffset("GameEntitySystem"));
+ return *reinterpret_cast((uintptr_t)(this) +
+ counterstrikesharp::globals::gameConfig->GetOffset("GameEntitySystem"));
}
-};
\ No newline at end of file
+};
diff --git a/src/core/cs2_sdk/interfaces/cs2_interfaces.cpp b/src/core/cs2_sdk/interfaces/cs2_interfaces.cpp
index 861a45ee..e50730cf 100644
--- a/src/core/cs2_sdk/interfaces/cs2_interfaces.cpp
+++ b/src/core/cs2_sdk/interfaces/cs2_interfaces.cpp
@@ -26,11 +26,10 @@
#include "tier0/memdbgon.h"
namespace counterstrikesharp {
-void interfaces::Initialize() {
- pGameResourceServiceServer = (CGameResourceService*)modules::engine->FindInterface(
- GAMERESOURCESERVICESERVER_INTERFACE_VERSION);
+void interfaces::Initialize()
+{
+ pGameResourceServiceServer = (CGameResourceService*)modules::engine->FindInterface(GAMERESOURCESERVICESERVER_INTERFACE_VERSION);
g_pCVar = (ICvar*)modules::tier0->FindInterface(CVAR_INTERFACE_VERSION);
- g_pSource2GameEntities = (ISource2GameEntities*)modules::server->FindInterface(
- SOURCE2GAMEENTITIES_INTERFACE_VERSION);
+ g_pSource2GameEntities = (ISource2GameEntities*)modules::server->FindInterface(SOURCE2GAMEENTITIES_INTERFACE_VERSION);
}
-} // namespace counterstrikesharp
+} // namespace counterstrikesharp
diff --git a/src/core/cs2_sdk/interfaces/cs2_interfaces.h b/src/core/cs2_sdk/interfaces/cs2_interfaces.h
index 23356940..cad67211 100644
--- a/src/core/cs2_sdk/interfaces/cs2_interfaces.h
+++ b/src/core/cs2_sdk/interfaces/cs2_interfaces.h
@@ -25,6 +25,6 @@ namespace counterstrikesharp {
namespace interfaces {
void Initialize();
-inline CGameResourceService *pGameResourceServiceServer = nullptr;
-} // namespace interfaces
-} // namespace counterstrikesharp
\ No newline at end of file
+inline CGameResourceService* pGameResourceServiceServer = nullptr;
+} // namespace interfaces
+} // namespace counterstrikesharp
diff --git a/src/core/cs2_sdk/schema.cpp b/src/core/cs2_sdk/schema.cpp
index f88932b2..a2cea1a1 100644
--- a/src/core/cs2_sdk/schema.cpp
+++ b/src/core/cs2_sdk/schema.cpp
@@ -33,8 +33,10 @@
using SchemaKeyValueMap_t = CUtlMap;
using SchemaTableMap_t = CUtlMap;
-bool IsFieldNetworked(SchemaClassFieldData_t& field) {
- for (int i = 0; i < field.m_nStaticMetadataCount; i++) {
+bool IsFieldNetworked(SchemaClassFieldData_t& field)
+{
+ for (int i = 0; i < field.m_nStaticMetadataCount; i++)
+ {
static auto networkEnabled = hash_32_fnv1a_const("MNetworkEnable");
if (networkEnabled == hash_32_fnv1a_const(field.m_pStaticMetadata[i].m_pszName)) return true;
}
@@ -42,16 +44,16 @@ bool IsFieldNetworked(SchemaClassFieldData_t& field) {
return false;
}
-static bool InitSchemaFieldsForClass(SchemaTableMap_t* tableMap,
- const char* className,
- uint32_t classKey) {
+static bool InitSchemaFieldsForClass(SchemaTableMap_t* tableMap, const char* className, uint32_t classKey)
+{
CSchemaSystemTypeScope* pType = counterstrikesharp::globals::schemaSystem->FindTypeScopeForModule(MODULE_PREFIX "server" MODULE_EXT);
if (!pType) return false;
SchemaClassInfoData_t* pClassInfo = pType->FindDeclaredClass(className).Get();
- if (!pClassInfo) {
+ if (!pClassInfo)
+ {
SchemaKeyValueMap_t* map = new SchemaKeyValueMap_t(0, 0, DefLessFunc(uint32_t));
tableMap->Insert(classKey, map);
@@ -66,31 +68,34 @@ static bool InitSchemaFieldsForClass(SchemaTableMap_t* tableMap,
keyValueMap->EnsureCapacity(fieldsSize);
tableMap->Insert(classKey, keyValueMap);
- for (int i = 0; i < fieldsSize; ++i) {
+ for (int i = 0; i < fieldsSize; ++i)
+ {
SchemaClassFieldData_t& field = pFields[i];
- keyValueMap->Insert(hash_32_fnv1a_const(field.m_pszName),
- {field.m_nSingleInheritanceOffset, IsFieldNetworked(field)});
+ keyValueMap->Insert(hash_32_fnv1a_const(field.m_pszName), { field.m_nSingleInheritanceOffset, IsFieldNetworked(field) });
}
return true;
}
-int16_t schema::FindChainOffset(const char* className) {
- CSchemaSystemTypeScope* pType =
- counterstrikesharp::globals::schemaSystem->FindTypeScopeForModule(MODULE_PREFIX "server" MODULE_EXT);
+int16_t schema::FindChainOffset(const char* className)
+{
+ CSchemaSystemTypeScope* pType = counterstrikesharp::globals::schemaSystem->FindTypeScopeForModule(MODULE_PREFIX "server" MODULE_EXT);
if (!pType) return false;
auto* pClassInfo = pType->FindDeclaredClass(className).Get();
- do {
+ do
+ {
SchemaClassFieldData_t* pFields = pClassInfo->m_pFields;
short fieldsSize = pClassInfo->m_nFieldCount;
- for (int i = 0; i < fieldsSize; ++i) {
+ for (int i = 0; i < fieldsSize; ++i)
+ {
SchemaClassFieldData_t& field = pFields[i];
- if (V_strcmp(field.m_pszName, "__m_pChainEntity") == 0) {
+ if (V_strcmp(field.m_pszName, "__m_pChainEntity") == 0)
+ {
return field.m_nSingleInheritanceOffset;
}
}
@@ -99,29 +104,29 @@ int16_t schema::FindChainOffset(const char* className) {
return 0;
}
-SchemaKey schema::GetOffset(const char* className,
- uint32_t classKey,
- const char* memberName,
- uint32_t memberKey) {
+SchemaKey schema::GetOffset(const char* className, uint32_t classKey, const char* memberName, uint32_t memberKey)
+{
static SchemaTableMap_t schemaTableMap(0, 0, DefLessFunc(uint32_t));
int16_t tableMapIndex = schemaTableMap.Find(classKey);
- if (!schemaTableMap.IsValidIndex(tableMapIndex)) {
- if (InitSchemaFieldsForClass(&schemaTableMap, className, classKey))
- return GetOffset(className, classKey, memberName, memberKey);
+ if (!schemaTableMap.IsValidIndex(tableMapIndex))
+ {
+ if (InitSchemaFieldsForClass(&schemaTableMap, className, classKey)) return GetOffset(className, classKey, memberName, memberKey);
- return {0, 0};
+ return { 0, 0 };
}
SchemaKeyValueMap_t* tableMap = schemaTableMap[tableMapIndex];
int16_t memberIndex = tableMap->Find(memberKey);
- if (!tableMap->IsValidIndex(memberIndex)) {
- return {0, 0};
+ if (!tableMap->IsValidIndex(memberIndex))
+ {
+ return { 0, 0 };
}
return tableMap->Element(memberIndex);
}
-void SetStateChanged(Z_CBaseEntity* pEntity, int offset) {
+void SetStateChanged(Z_CBaseEntity* pEntity, int offset)
+{
// addresses::StateChanged(pEntity->m_NetworkTransmitComponent(), pEntity, offset, -1, -1);
auto vars = counterstrikesharp::globals::getGlobalVars();
diff --git a/src/core/cs2_sdk/schema.h b/src/core/cs2_sdk/schema.h
index 3a51654e..cbbf18ca 100644
--- a/src/core/cs2_sdk/schema.h
+++ b/src/core/cs2_sdk/schema.h
@@ -30,29 +30,28 @@
#undef schema
-struct SchemaKey {
+struct SchemaKey
+{
int32_t offset;
bool networked;
};
class Z_CBaseEntity;
-void SetStateChanged(Z_CBaseEntity *pEntity, int offset);
+void SetStateChanged(Z_CBaseEntity* pEntity, int offset);
inline uint32_t val_32_const = 0x811c9dc5;
inline uint32_t prime_32_const = 0x1000193;
inline uint64_t val_64_const = 0xcbf29ce484222325;
inline uint64_t prime_64_const = 0x100000001b3;
-inline uint32_t hash_32_fnv1a_const(const char *str, const uint32_t value = val_32_const) noexcept {
- return (str[0] == '\0')
- ? value
- : hash_32_fnv1a_const(&str[1], (value ^ uint32_t(str[0])) * prime_32_const);
+inline uint32_t hash_32_fnv1a_const(const char* str, const uint32_t value = val_32_const) noexcept
+{
+ return (str[0] == '\0') ? value : hash_32_fnv1a_const(&str[1], (value ^ uint32_t(str[0])) * prime_32_const);
}
-inline uint64_t hash_64_fnv1a_const(const char *str, const uint64_t value = val_64_const) noexcept {
- return (str[0] == '\0')
- ? value
- : hash_64_fnv1a_const(&str[1], (value ^ uint64_t(str[0])) * prime_64_const);
+inline uint64_t hash_64_fnv1a_const(const char* str, const uint64_t value = val_64_const) noexcept
+{
+ return (str[0] == '\0') ? value : hash_64_fnv1a_const(&str[1], (value ^ uint64_t(str[0])) * prime_64_const);
}
namespace schema {
@@ -95,6 +94,6 @@ static std::vector CS2BadList = {
"m_nMusicID",
};
-int16_t FindChainOffset(const char *className);
-SchemaKey GetOffset(const char *className, uint32_t classKey, const char *memberName, uint32_t memberKey);
-} // namespace schema
+int16_t FindChainOffset(const char* className);
+SchemaKey GetOffset(const char* className, uint32_t classKey, const char* memberName, uint32_t memberKey);
+} // namespace schema
diff --git a/src/core/function.cpp b/src/core/function.cpp
index 58c990f2..c61335de 100644
--- a/src/core/function.cpp
+++ b/src/core/function.cpp
@@ -52,30 +52,30 @@ std::map g_HookMap;
// ============================================================================
int GetDynCallConvention(Convention_t eConv)
{
- switch (eConv) {
- case CONV_CUSTOM:
- return -1;
- case CONV_CDECL:
- return DC_CALL_C_DEFAULT;
- case CONV_THISCALL:
+ switch (eConv)
+ {
+ case CONV_CUSTOM:
+ return -1;
+ case CONV_CDECL:
+ return DC_CALL_C_DEFAULT;
+ case CONV_THISCALL:
#ifdef _WIN32
- return DC_CALL_C_X86_WIN32_THIS_MS;
+ return DC_CALL_C_X86_WIN32_THIS_MS;
#else
- return DC_CALL_C_X86_WIN32_THIS_GNU;
+ return DC_CALL_C_X86_WIN32_THIS_GNU;
#endif
#ifdef _WIN32
- case CONV_STDCALL:
- return DC_CALL_C_X86_WIN32_STD;
- case CONV_FASTCALL:
- return DC_CALL_C_X86_WIN32_FAST_MS;
+ case CONV_STDCALL:
+ return DC_CALL_C_X86_WIN32_STD;
+ case CONV_FASTCALL:
+ return DC_CALL_C_X86_WIN32_FAST_MS;
#endif
}
return -1;
}
-ValveFunction::ValveFunction(void* ulAddr, Convention_t callingConvention,
- std::vector args, DataType_t returnType)
+ValveFunction::ValveFunction(void* ulAddr, Convention_t callingConvention, std::vector args, DataType_t returnType)
: m_ulAddr(ulAddr)
{
m_Args = args;
@@ -87,8 +87,7 @@ ValveFunction::ValveFunction(void* ulAddr, Convention_t callingConvention,
m_iCallingConvention = GetDynCallConvention(m_eCallingConvention);
}
-ValveFunction::ValveFunction(void* ulAddr, Convention_t callingConvention, DataType_t* args,
- int argCount, DataType_t returnType)
+ValveFunction::ValveFunction(void* ulAddr, Convention_t callingConvention, DataType_t* args, int argCount, DataType_t returnType)
: m_ulAddr(ulAddr)
{
@@ -101,13 +100,9 @@ ValveFunction::ValveFunction(void* ulAddr, Convention_t callingConvention, DataT
ValveFunction::~ValveFunction() {}
-bool ValveFunction::IsCallable()
-{
- return (m_eCallingConvention != CONV_CUSTOM) && (m_iCallingConvention != -1);
-}
+bool ValveFunction::IsCallable() { return (m_eCallingConvention != CONV_CUSTOM) && (m_iCallingConvention != -1); }
-template
-ReturnType CallHelper(Function func, DCCallVM* vm, void* addr)
+template ReturnType CallHelper(Function func, DCCallVM* vm, void* addr)
{
ReturnType result;
result = (ReturnType)func(vm, (void*)addr);
@@ -118,119 +113,120 @@ void CallHelperVoid(DCCallVM* vm, void* addr) { dcCallVoid(vm, (void*)addr); }
void ValveFunction::Call(ScriptContext& script_context, int offset)
{
- if (!IsCallable())
- return;
+ if (!IsCallable()) return;
dcReset(g_pCallVM);
dcMode(g_pCallVM, m_iCallingConvention);
- for (size_t i = 0; i < m_Args.size(); i++) {
+ for (size_t i = 0; i < m_Args.size(); i++)
+ {
int contextIndex = i + offset;
- switch (m_Args[i]) {
- case DATA_TYPE_BOOL:
- dcArgBool(g_pCallVM, script_context.GetArgument(contextIndex));
- break;
- case DATA_TYPE_CHAR:
- dcArgChar(g_pCallVM, script_context.GetArgument(contextIndex));
- break;
- case DATA_TYPE_UCHAR:
- dcArgChar(g_pCallVM, script_context.GetArgument(contextIndex));
- break;
- case DATA_TYPE_SHORT:
- dcArgShort(g_pCallVM, script_context.GetArgument(contextIndex));
- break;
- case DATA_TYPE_USHORT:
- dcArgShort(g_pCallVM, script_context.GetArgument(contextIndex));
- break;
- case DATA_TYPE_INT:
- dcArgInt(g_pCallVM, script_context.GetArgument(contextIndex));
- break;
- case DATA_TYPE_UINT:
- dcArgInt(g_pCallVM, script_context.GetArgument(contextIndex));
- break;
- case DATA_TYPE_LONG:
- dcArgLong(g_pCallVM, script_context.GetArgument(contextIndex));
- break;
- case DATA_TYPE_ULONG:
- dcArgLong(g_pCallVM, script_context.GetArgument(contextIndex));
- break;
- case DATA_TYPE_LONG_LONG:
- dcArgLongLong(g_pCallVM, script_context.GetArgument(contextIndex));
- break;
- case DATA_TYPE_ULONG_LONG:
- dcArgLongLong(g_pCallVM, script_context.GetArgument(contextIndex));
- break;
- case DATA_TYPE_FLOAT:
- dcArgFloat(g_pCallVM, script_context.GetArgument(contextIndex));
- break;
- case DATA_TYPE_DOUBLE:
- dcArgDouble(g_pCallVM, script_context.GetArgument(contextIndex));
- break;
- case DATA_TYPE_POINTER:
- dcArgPointer(g_pCallVM, script_context.GetArgument(contextIndex));
- break;
- case DATA_TYPE_STRING:
- dcArgPointer(g_pCallVM, (void*)script_context.GetArgument(contextIndex));
- break;
- default:
- assert(!"Unknown function parameter type!");
- break;
+ switch (m_Args[i])
+ {
+ case DATA_TYPE_BOOL:
+ dcArgBool(g_pCallVM, script_context.GetArgument(contextIndex));
+ break;
+ case DATA_TYPE_CHAR:
+ dcArgChar(g_pCallVM, script_context.GetArgument(contextIndex));
+ break;
+ case DATA_TYPE_UCHAR:
+ dcArgChar(g_pCallVM, script_context.GetArgument(contextIndex));
+ break;
+ case DATA_TYPE_SHORT:
+ dcArgShort(g_pCallVM, script_context.GetArgument(contextIndex));
+ break;
+ case DATA_TYPE_USHORT:
+ dcArgShort(g_pCallVM, script_context.GetArgument(contextIndex));
+ break;
+ case DATA_TYPE_INT:
+ dcArgInt(g_pCallVM, script_context.GetArgument(contextIndex));
+ break;
+ case DATA_TYPE_UINT:
+ dcArgInt(g_pCallVM, script_context.GetArgument(contextIndex));
+ break;
+ case DATA_TYPE_LONG:
+ dcArgLong(g_pCallVM, script_context.GetArgument(contextIndex));
+ break;
+ case DATA_TYPE_ULONG:
+ dcArgLong(g_pCallVM, script_context.GetArgument(contextIndex));
+ break;
+ case DATA_TYPE_LONG_LONG:
+ dcArgLongLong(g_pCallVM, script_context.GetArgument(contextIndex));
+ break;
+ case DATA_TYPE_ULONG_LONG:
+ dcArgLongLong(g_pCallVM, script_context.GetArgument(contextIndex));
+ break;
+ case DATA_TYPE_FLOAT:
+ dcArgFloat(g_pCallVM, script_context.GetArgument(contextIndex));
+ break;
+ case DATA_TYPE_DOUBLE:
+ dcArgDouble(g_pCallVM, script_context.GetArgument(contextIndex));
+ break;
+ case DATA_TYPE_POINTER:
+ dcArgPointer(g_pCallVM, script_context.GetArgument(contextIndex));
+ break;
+ case DATA_TYPE_STRING:
+ dcArgPointer(g_pCallVM, (void*)script_context.GetArgument(contextIndex));
+ break;
+ default:
+ assert(!"Unknown function parameter type!");
+ break;
}
}
- switch (m_eReturnType) {
- case DATA_TYPE_VOID:
- CallHelperVoid(g_pCallVM, m_ulAddr);
- break;
- case DATA_TYPE_BOOL:
- script_context.SetResult(CallHelper(dcCallBool, g_pCallVM, m_ulAddr));
- break;
- case DATA_TYPE_CHAR:
- script_context.SetResult(CallHelper(dcCallChar, g_pCallVM, m_ulAddr));
- break;
- case DATA_TYPE_UCHAR:
- script_context.SetResult(CallHelper(dcCallChar, g_pCallVM, m_ulAddr));
- break;
- case DATA_TYPE_SHORT:
- script_context.SetResult(CallHelper(dcCallShort, g_pCallVM, m_ulAddr));
- break;
- case DATA_TYPE_USHORT:
- script_context.SetResult(CallHelper(dcCallShort, g_pCallVM, m_ulAddr));
- break;
- case DATA_TYPE_INT:
- script_context.SetResult(CallHelper(dcCallInt, g_pCallVM, m_ulAddr));
- break;
- case DATA_TYPE_UINT:
- script_context.SetResult(CallHelper(dcCallInt, g_pCallVM, m_ulAddr));
- break;
- case DATA_TYPE_LONG:
- script_context.SetResult(CallHelper(dcCallLong, g_pCallVM, m_ulAddr));
- break;
- case DATA_TYPE_ULONG:
- script_context.SetResult(CallHelper(dcCallLong, g_pCallVM, m_ulAddr));
- break;
- case DATA_TYPE_LONG_LONG:
- script_context.SetResult(CallHelper(dcCallLongLong, g_pCallVM, m_ulAddr));
- break;
- case DATA_TYPE_ULONG_LONG:
- script_context.SetResult(
- CallHelper(dcCallLongLong, g_pCallVM, m_ulAddr));
- break;
- case DATA_TYPE_FLOAT:
- script_context.SetResult(CallHelper(dcCallFloat, g_pCallVM, m_ulAddr));
- break;
- case DATA_TYPE_DOUBLE:
- script_context.SetResult(CallHelper(dcCallDouble, g_pCallVM, m_ulAddr));
- break;
- case DATA_TYPE_POINTER:
- script_context.SetResult(CallHelper(dcCallPointer, g_pCallVM, m_ulAddr));
- break;
- case DATA_TYPE_STRING:
- script_context.SetResult(CallHelper(dcCallPointer, g_pCallVM, m_ulAddr));
- break;
- default:
- assert(!"Unknown function return type!");
- break;
+ switch (m_eReturnType)
+ {
+ case DATA_TYPE_VOID:
+ CallHelperVoid(g_pCallVM, m_ulAddr);
+ break;
+ case DATA_TYPE_BOOL:
+ script_context.SetResult(CallHelper(dcCallBool, g_pCallVM, m_ulAddr));
+ break;
+ case DATA_TYPE_CHAR:
+ script_context.SetResult(CallHelper(dcCallChar, g_pCallVM, m_ulAddr));
+ break;
+ case DATA_TYPE_UCHAR:
+ script_context.SetResult(CallHelper(dcCallChar, g_pCallVM, m_ulAddr));
+ break;
+ case DATA_TYPE_SHORT:
+ script_context.SetResult(CallHelper(dcCallShort, g_pCallVM, m_ulAddr));
+ break;
+ case DATA_TYPE_USHORT:
+ script_context.SetResult(CallHelper(dcCallShort, g_pCallVM, m_ulAddr));
+ break;
+ case DATA_TYPE_INT:
+ script_context.SetResult(CallHelper(dcCallInt, g_pCallVM, m_ulAddr));
+ break;
+ case DATA_TYPE_UINT:
+ script_context.SetResult(CallHelper(dcCallInt, g_pCallVM, m_ulAddr));
+ break;
+ case DATA_TYPE_LONG:
+ script_context.SetResult(CallHelper(dcCallLong, g_pCallVM, m_ulAddr));
+ break;
+ case DATA_TYPE_ULONG:
+ script_context.SetResult(CallHelper(dcCallLong, g_pCallVM, m_ulAddr));
+ break;
+ case DATA_TYPE_LONG_LONG:
+ script_context.SetResult(CallHelper(dcCallLongLong, g_pCallVM, m_ulAddr));
+ break;
+ case DATA_TYPE_ULONG_LONG:
+ script_context.SetResult(CallHelper(dcCallLongLong, g_pCallVM, m_ulAddr));
+ break;
+ case DATA_TYPE_FLOAT:
+ script_context.SetResult(CallHelper(dcCallFloat, g_pCallVM, m_ulAddr));
+ break;
+ case DATA_TYPE_DOUBLE:
+ script_context.SetResult(CallHelper(dcCallDouble, g_pCallVM, m_ulAddr));
+ break;
+ case DATA_TYPE_POINTER:
+ script_context.SetResult(CallHelper(dcCallPointer, g_pCallVM, m_ulAddr));
+ break;
+ case DATA_TYPE_STRING:
+ script_context.SetResult(CallHelper(dcCallPointer, g_pCallVM, m_ulAddr));
+ break;
+ default:
+ assert(!"Unknown function return type!");
+ break;
}
}
@@ -240,23 +236,24 @@ dyno::ReturnAction HookHandler(dyno::HookType hookType, dyno::Hook& hook)
auto callback = hookType == dyno::HookType::Pre ? vf->m_precallback : vf->m_postcallback;
- if (callback == nullptr) {
+ if (callback == nullptr)
+ {
return dyno::ReturnAction::Ignored;
}
callback->Reset();
callback->ScriptContext().Push(&hook);
- for (auto fnMethodToCall : callback->GetFunctions()) {
- if (!fnMethodToCall)
- continue;
+ for (auto fnMethodToCall : callback->GetFunctions())
+ {
+ if (!fnMethodToCall) continue;
fnMethodToCall(&callback->ScriptContextStruct());
auto result = callback->ScriptContext().GetResult();
- CSSHARP_CORE_TRACE("Received hook callback result of {}, hook mode {}", result,
- (int)hookType);
+ CSSHARP_CORE_TRACE("Received hook callback result of {}, hook mode {}", result, (int)hookType);
- if (result >= HookResult::Handled) {
+ if (result >= HookResult::Handled)
+ {
return dyno::ReturnAction::Supercede;
}
}
@@ -269,7 +266,8 @@ std::vector ConvertArgsToDynoHook(const std::vector converted;
converted.reserve(dataTypes.size());
- for (DataType_t dt : dataTypes) {
+ for (DataType_t dt : dataTypes)
+ {
converted.push_back(dyno::DataObject(static_cast(dt)));
}
@@ -290,19 +288,25 @@ void ValveFunction::AddHook(CallbackT callable, bool post)
hook->addCallback(dyno::HookType::Post, (dyno::HookHandler*)&HookHandler);
hook->addCallback(dyno::HookType::Pre, (dyno::HookHandler*)&HookHandler);
- if (post) {
- if (m_postcallback == nullptr) {
+ if (post)
+ {
+ if (m_postcallback == nullptr)
+ {
m_postcallback = globals::callbackManager.CreateCallback("");
}
m_postcallback->AddListener(callable);
- } else {
- if (m_precallback == nullptr) {
+ }
+ else
+ {
+ if (m_precallback == nullptr)
+ {
m_precallback = globals::callbackManager.CreateCallback("");
}
m_precallback->AddListener(callable);
}
}
-void ValveFunction::RemoveHook(CallbackT callable, bool post) {
+void ValveFunction::RemoveHook(CallbackT callable, bool post)
+{
dyno::HookManager& manager = dyno::HookManager::Get();
dyno::Hook* hook = manager.hook((void*)m_ulAddr, [this] {
#ifdef _WIN32
@@ -313,12 +317,17 @@ void ValveFunction::RemoveHook(CallbackT callable, bool post) {
});
g_HookMap[hook] = this;
- if (post) {
- if (m_postcallback != nullptr) {
+ if (post)
+ {
+ if (m_postcallback != nullptr)
+ {
m_postcallback->RemoveListener(callable);
}
- } else {
- if (m_precallback != nullptr) {
+ }
+ else
+ {
+ if (m_precallback != nullptr)
+ {
m_precallback->RemoveListener(callable);
}
}
diff --git a/src/core/function.h b/src/core/function.h
index 163fa671..f30cd9ee 100644
--- a/src/core/function.h
+++ b/src/core/function.h
@@ -40,7 +40,8 @@ class Hook;
namespace counterstrikesharp {
-enum DataType_t {
+enum DataType_t
+{
DATA_TYPE_VOID,
DATA_TYPE_BOOL,
DATA_TYPE_CHAR,
@@ -60,7 +61,8 @@ enum DataType_t {
DATA_TYPE_VARIANT
};
-enum Protection_t {
+enum Protection_t
+{
PROTECTION_NONE,
PROTECTION_READ,
PROTECTION_READ_WRITE,
@@ -69,19 +71,20 @@ enum Protection_t {
PROTECTION_EXECUTE_READ_WRITE
};
-enum Convention_t { CONV_CUSTOM, CONV_CDECL, CONV_THISCALL, CONV_STDCALL, CONV_FASTCALL };
+enum Convention_t
+{
+ CONV_CUSTOM,
+ CONV_CDECL,
+ CONV_THISCALL,
+ CONV_STDCALL,
+ CONV_FASTCALL
+};
-class ValveFunction {
-public:
- ValveFunction(void* ulAddr,
- Convention_t callingConvention,
- std::vector args,
- DataType_t returnType);
- ValveFunction(void* ulAddr,
- Convention_t callingConvention,
- DataType_t* args,
- int argCount,
- DataType_t returnType);
+class ValveFunction
+{
+ public:
+ ValveFunction(void* ulAddr, Convention_t callingConvention, std::vector args, DataType_t returnType);
+ ValveFunction(void* ulAddr, Convention_t callingConvention, DataType_t* args, int argCount, DataType_t returnType);
~ValveFunction();
@@ -110,4 +113,4 @@ public:
ScriptCallback* m_postcallback = nullptr;
};
-} // namespace counterstrikesharp
\ No newline at end of file
+} // namespace counterstrikesharp
diff --git a/src/core/game_system.cpp b/src/core/game_system.cpp
index adf2acc8..385d0dc4 100644
--- a/src/core/game_system.cpp
+++ b/src/core/game_system.cpp
@@ -36,7 +36,8 @@ bool InitGameSystems()
// bytes so we skip those
uint8* ptr = (uint8*)counterstrikesharp::globals::gameConfig->ResolveSignature("IGameSystem_InitAllSystems_pFirst") + 3;
- if (!ptr) {
+ if (!ptr)
+ {
CSSHARP_CORE_ERROR("Failed to InitGameSystems, see warnings above.");
return false;
}
@@ -63,4 +64,4 @@ GS_EVENT_MEMBER(CGameSystem, BuildGameSessionManifest)
CSSHARP_CORE_INFO("CGameSystem::BuildGameSessionManifest");
counterstrikesharp::globals::serverManager.OnPrecacheResources(pResourceManifest);
-}
\ No newline at end of file
+}
diff --git a/src/core/game_system.h b/src/core/game_system.h
index 16423bd7..30c9f115 100644
--- a/src/core/game_system.h
+++ b/src/core/game_system.h
@@ -37,11 +37,10 @@ class CGameSystem : public CBaseGameSystem
void SetGameSystemGlobalPtrs(void* pValue) override
{
- if (sm_Factory)
- sm_Factory->SetGlobalPtr(pValue);
+ if (sm_Factory) sm_Factory->SetGlobalPtr(pValue);
}
bool DoesGameSystemReallocate() override { return sm_Factory->ShouldAutoAdd(); }
static IGameSystemFactory* sm_Factory;
-};
\ No newline at end of file
+};
diff --git a/src/core/gameconfig.h b/src/core/gameconfig.h
index 196252b1..c1118b18 100644
--- a/src/core/gameconfig.h
+++ b/src/core/gameconfig.h
@@ -1,6 +1,5 @@
#pragma once
-
#include "core/globals.h"
#include "core/memory_module.h"
#include
diff --git a/src/core/global_listener.h b/src/core/global_listener.h
index 9b0c55ce..140ed5df 100644
--- a/src/core/global_listener.h
+++ b/src/core/global_listener.h
@@ -32,34 +32,37 @@
#pragma once
namespace counterstrikesharp {
-class GlobalClass {
-public:
+class GlobalClass
+{
+ public:
virtual ~GlobalClass() = default;
- GlobalClass() {
+ GlobalClass()
+ {
m_pGlobalClassNext = GlobalClass::head;
GlobalClass::head = this;
}
-public:
+ public:
virtual void OnStartup() {}
virtual void OnShutdown() {}
virtual void OnAllInitialized() {}
virtual void OnGameLoopInitialized() {}
virtual void OnAllInitialized_Post() {}
- virtual void OnLevelChange(const char *mapName) {}
+ virtual void OnLevelChange(const char* mapName) {}
virtual void OnLevelEnd() {}
-public:
- GlobalClass *m_pGlobalClassNext;
- static GlobalClass *head;
+ public:
+ GlobalClass* m_pGlobalClassNext;
+ static GlobalClass* head;
};
-} // namespace counterstrikesharp
+} // namespace counterstrikesharp
#define CALL_GLOBAL_LISTENER(func) \
- GlobalClass *pBase = GlobalClass::head; \
+ GlobalClass* pBase = GlobalClass::head; \
pBase = GlobalClass::head; \
- while (pBase) { \
+ while (pBase) \
+ { \
pBase->func; \
pBase = pBase->m_pGlobalClassNext; \
}
diff --git a/src/core/globals.cpp b/src/core/globals.cpp
index f3675962..dda8e483 100644
--- a/src/core/globals.cpp
+++ b/src/core/globals.cpp
@@ -1,4 +1,3 @@
-// clang-format off
#include "mm_plugin.h"
#include "core/globals.h"
#include "core/managers/player_manager.h"
@@ -28,7 +27,6 @@
#include
#include
-// clang-format on
namespace counterstrikesharp {
@@ -142,7 +140,8 @@ void DetourGameEventManagerInit(IGameEventManager2* pGameEventManager)
}
int source_hook_pluginid = 0;
-CGlobalVars* getGlobalVars() {
+CGlobalVars* getGlobalVars()
+{
INetworkGameServer* server = networkServerService->GetIGameServer();
if (!server) return nullptr;
return networkServerService->GetIGameServer()->GetGlobals();
diff --git a/src/core/log.cpp b/src/core/log.cpp
index aab61dbe..70db52d9 100644
--- a/src/core/log.cpp
+++ b/src/core/log.cpp
@@ -7,7 +7,8 @@
namespace counterstrikesharp {
std::shared_ptr Log::m_core_logger;
-void Log::Init() {
+void Log::Init()
+{
std::vector log_sinks;
auto color_sink = std::make_shared();
#if _WIN32
@@ -17,8 +18,7 @@ void Log::Init() {
#endif
log_sinks.emplace_back(color_sink);
- log_sinks.emplace_back(
- std::make_shared("counterstrikesharp.log", true));
+ log_sinks.emplace_back(std::make_shared("counterstrikesharp.log", true));
log_sinks[0]->set_pattern("%^[%T.%e] %n: %v%$");
log_sinks[1]->set_pattern("[%T.%e] [%l] %n: %v");
@@ -31,8 +31,9 @@ void Log::Init() {
spdlog::cfg::load_env_levels();
}
-void Log::Close() {
+void Log::Close()
+{
spdlog::drop("CSSharp");
m_core_logger = nullptr;
}
-} // namespace counterstrikesharp
+} // namespace counterstrikesharp
diff --git a/src/core/log.h b/src/core/log.h
index b1446557..21c762cb 100644
--- a/src/core/log.h
+++ b/src/core/log.h
@@ -6,21 +6,22 @@
#include
namespace counterstrikesharp {
-class Log {
-public:
+class Log
+{
+ public:
static void Init();
static void Close();
- static std::shared_ptr &GetCoreLogger() { return m_core_logger; }
+ static std::shared_ptr& GetCoreLogger() { return m_core_logger; }
-private:
+ private:
static std::shared_ptr m_core_logger;
};
-} // namespace counterstrikesharp
+} // namespace counterstrikesharp
-#define CSSHARP_CORE_TRACE(...) ::counterstrikesharp::Log::GetCoreLogger()->trace(__VA_ARGS__)
-#define CSSHARP_CORE_DEBUG(...) ::counterstrikesharp::Log::GetCoreLogger()->debug(__VA_ARGS__)
-#define CSSHARP_CORE_INFO(...) ::counterstrikesharp::Log::GetCoreLogger()->info(__VA_ARGS__)
-#define CSSHARP_CORE_WARN(...) ::counterstrikesharp::Log::GetCoreLogger()->warn(__VA_ARGS__)
-#define CSSHARP_CORE_ERROR(...) ::counterstrikesharp::Log::GetCoreLogger()->error(__VA_ARGS__)
+#define CSSHARP_CORE_TRACE(...) ::counterstrikesharp::Log::GetCoreLogger()->trace(__VA_ARGS__)
+#define CSSHARP_CORE_DEBUG(...) ::counterstrikesharp::Log::GetCoreLogger()->debug(__VA_ARGS__)
+#define CSSHARP_CORE_INFO(...) ::counterstrikesharp::Log::GetCoreLogger()->info(__VA_ARGS__)
+#define CSSHARP_CORE_WARN(...) ::counterstrikesharp::Log::GetCoreLogger()->warn(__VA_ARGS__)
+#define CSSHARP_CORE_ERROR(...) ::counterstrikesharp::Log::GetCoreLogger()->error(__VA_ARGS__)
#define CSSHARP_CORE_CRITICAL(...) ::counterstrikesharp::Log::GetCoreLogger()->critical(__VA_ARGS__)
diff --git a/src/core/managers/chat_manager.cpp b/src/core/managers/chat_manager.cpp
index 79b0adea..3c288e3b 100644
--- a/src/core/managers/chat_manager.cpp
+++ b/src/core/managers/chat_manager.cpp
@@ -1,127 +1,127 @@
-/*
- * This file is part of CounterStrikeSharp.
- * CounterStrikeSharp is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * CounterStrikeSharp is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with CounterStrikeSharp. If not, see . *
- */
-
-#include "core/managers/chat_manager.h"
-
-#include
-#include
-#include
-
-#include "characterset.h"
-#include "core/coreconfig.h"
-#include "core/gameconfig.h"
-#include "core/log.h"
-#include "core/managers/con_command_manager.h"
-#include "core/memory.h"
-#include "core/memory_module.h"
-#include "scripting/callback_manager.h"
-
-namespace counterstrikesharp {
-
-ChatManager::ChatManager() {}
-
-ChatManager::~ChatManager() {}
-
-void ChatManager::OnAllInitialized()
-{
- m_pHostSay = reinterpret_cast(modules::server->FindSignature(globals::gameConfig->GetSignature("Host_Say")));
-
- if (m_pHostSay == nullptr)
- {
- CSSHARP_CORE_ERROR("Failed to find signature for \'Host_Say\'");
- return;
- }
-
- auto m_hook = funchook_create();
- funchook_prepare(m_hook, (void**)&m_pHostSay, (void*)&DetourHostSay);
- funchook_install(m_hook, 0);
-}
-
-void ChatManager::OnShutdown() {}
-
-void DetourHostSay(CEntityInstance* pController, CCommand& args, bool teamonly, int unk1, const char* unk2)
-{
- if (pController)
- {
- auto pEvent = globals::gameEventManager->CreateEvent("player_chat", true);
- if (pEvent)
- {
- pEvent->SetBool("teamonly", teamonly);
- pEvent->SetInt("userid", pController->GetEntityIndex().Get() - 1);
- pEvent->SetString("text", args[1]);
-
- globals::gameEventManager->FireEvent(pEvent, true);
- }
- }
-
- std::string prefix;
- bool bSilent = globals::coreConfig->IsSilentChatTrigger(args[1], prefix);
- bool bCommand = globals::coreConfig->IsPublicChatTrigger(args[1], prefix) || bSilent;
-
- if (!bSilent)
- {
- m_pHostSay(pController, args, teamonly, unk1, unk2);
- }
-
- if (bCommand)
- {
- char* pszMessage = (char*)(args.ArgS() + prefix.length() + 1);
-
- // Trailing slashes are only removed if Host_Say has been called.
- if (bSilent) pszMessage[V_strlen(pszMessage) - 1] = 0;
-
- CCommand args;
- args.Tokenize(pszMessage);
-
- auto prefixedPhrase = std::string("css_") + args.Arg(0);
- auto bValidWithPrefix = globals::conCommandManager.IsValidValveCommand(prefixedPhrase.c_str());
-
- if (bValidWithPrefix)
- {
- // Re-tokenize with a `css_` prefix if we have found that its a valid command.
- args.Tokenize(("css_" + std::string(pszMessage)).c_str());
- }
-
- globals::chatManager.OnSayCommandPost(pController, args);
- }
-}
-
-bool ChatManager::OnSayCommandPre(CEntityInstance* pController, CCommand& command) { return false; }
-
-void ChatManager::OnSayCommandPost(CEntityInstance* pController, CCommand& command)
-{
- auto commandStr = command.Arg(0);
-
- return InternalDispatch(pController, commandStr, command);
-}
-
-void ChatManager::InternalDispatch(CEntityInstance* pPlayerController, const char* szTriggerPhase, CCommand& fullCommand)
-{
- if (pPlayerController == nullptr)
- {
- globals::conCommandManager.ExecuteCommandCallbacks(fullCommand.Arg(0),
- CCommandContext(CommandTarget_t::CT_NO_TARGET, CPlayerSlot(-1)), fullCommand,
- HookMode::Pre, CommandCallingContext::Chat);
- return;
- }
-
- auto index = pPlayerController->GetEntityIndex().Get();
- auto slot = CPlayerSlot(index - 1);
-
- globals::conCommandManager.ExecuteCommandCallbacks(fullCommand.Arg(0), CCommandContext(CommandTarget_t::CT_NO_TARGET, slot),
- fullCommand, HookMode::Pre, CommandCallingContext::Chat);
-}
-} // namespace counterstrikesharp
+/*
+ * This file is part of CounterStrikeSharp.
+ * CounterStrikeSharp is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * CounterStrikeSharp is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with CounterStrikeSharp. If not, see . *
+ */
+
+#include "core/managers/chat_manager.h"
+
+#include
+#include
+#include
+
+#include "characterset.h"
+#include "core/coreconfig.h"
+#include "core/gameconfig.h"
+#include "core/log.h"
+#include "core/managers/con_command_manager.h"
+#include "core/memory.h"
+#include "core/memory_module.h"
+#include "scripting/callback_manager.h"
+
+namespace counterstrikesharp {
+
+ChatManager::ChatManager() {}
+
+ChatManager::~ChatManager() {}
+
+void ChatManager::OnAllInitialized()
+{
+ m_pHostSay = reinterpret_cast(modules::server->FindSignature(globals::gameConfig->GetSignature("Host_Say")));
+
+ if (m_pHostSay == nullptr)
+ {
+ CSSHARP_CORE_ERROR("Failed to find signature for \'Host_Say\'");
+ return;
+ }
+
+ auto m_hook = funchook_create();
+ funchook_prepare(m_hook, (void**)&m_pHostSay, (void*)&DetourHostSay);
+ funchook_install(m_hook, 0);
+}
+
+void ChatManager::OnShutdown() {}
+
+void DetourHostSay(CEntityInstance* pController, CCommand& args, bool teamonly, int unk1, const char* unk2)
+{
+ if (pController)
+ {
+ auto pEvent = globals::gameEventManager->CreateEvent("player_chat", true);
+ if (pEvent)
+ {
+ pEvent->SetBool("teamonly", teamonly);
+ pEvent->SetInt("userid", pController->GetEntityIndex().Get() - 1);
+ pEvent->SetString("text", args[1]);
+
+ globals::gameEventManager->FireEvent(pEvent, true);
+ }
+ }
+
+ std::string prefix;
+ bool bSilent = globals::coreConfig->IsSilentChatTrigger(args[1], prefix);
+ bool bCommand = globals::coreConfig->IsPublicChatTrigger(args[1], prefix) || bSilent;
+
+ if (!bSilent)
+ {
+ m_pHostSay(pController, args, teamonly, unk1, unk2);
+ }
+
+ if (bCommand)
+ {
+ char* pszMessage = (char*)(args.ArgS() + prefix.length() + 1);
+
+ // Trailing slashes are only removed if Host_Say has been called.
+ if (bSilent) pszMessage[V_strlen(pszMessage) - 1] = 0;
+
+ CCommand args;
+ args.Tokenize(pszMessage);
+
+ auto prefixedPhrase = std::string("css_") + args.Arg(0);
+ auto bValidWithPrefix = globals::conCommandManager.IsValidValveCommand(prefixedPhrase.c_str());
+
+ if (bValidWithPrefix)
+ {
+ // Re-tokenize with a `css_` prefix if we have found that its a valid command.
+ args.Tokenize(("css_" + std::string(pszMessage)).c_str());
+ }
+
+ globals::chatManager.OnSayCommandPost(pController, args);
+ }
+}
+
+bool ChatManager::OnSayCommandPre(CEntityInstance* pController, CCommand& command) { return false; }
+
+void ChatManager::OnSayCommandPost(CEntityInstance* pController, CCommand& command)
+{
+ auto commandStr = command.Arg(0);
+
+ return InternalDispatch(pController, commandStr, command);
+}
+
+void ChatManager::InternalDispatch(CEntityInstance* pPlayerController, const char* szTriggerPhase, CCommand& fullCommand)
+{
+ if (pPlayerController == nullptr)
+ {
+ globals::conCommandManager.ExecuteCommandCallbacks(fullCommand.Arg(0),
+ CCommandContext(CommandTarget_t::CT_NO_TARGET, CPlayerSlot(-1)), fullCommand,
+ HookMode::Pre, CommandCallingContext::Chat);
+ return;
+ }
+
+ auto index = pPlayerController->GetEntityIndex().Get();
+ auto slot = CPlayerSlot(index - 1);
+
+ globals::conCommandManager.ExecuteCommandCallbacks(fullCommand.Arg(0), CCommandContext(CommandTarget_t::CT_NO_TARGET, slot),
+ fullCommand, HookMode::Pre, CommandCallingContext::Chat);
+}
+} // namespace counterstrikesharp
diff --git a/src/core/managers/chat_manager.h b/src/core/managers/chat_manager.h
index 12cb7970..d18ad3a9 100644
--- a/src/core/managers/chat_manager.h
+++ b/src/core/managers/chat_manager.h
@@ -1,68 +1,68 @@
-/*
- * This file is part of CounterStrikeSharp.
- * CounterStrikeSharp is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * CounterStrikeSharp is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with CounterStrikeSharp. If not, see . *
- */
-
-#pragma once
-
-#include