Skip to content

Commit

Permalink
chore(deps): bump libraries/hl2sdk-cs2 from f7ed6a0 to 36dd2db (r…
Browse files Browse the repository at this point in the history
…oflmuffin#452)

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: roflmuffin <[email protected]>
  • Loading branch information
dependabot[bot] and roflmuffin authored May 10, 2024
1 parent aec696a commit 02d5191
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 145 deletions.
65 changes: 32 additions & 33 deletions src/core/managers/chat_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,19 @@
*/

#include "core/managers/chat_manager.h"
#include "core/managers/con_command_manager.h"
#include "scripting/callback_manager.h"
#include "characterset.h"

#include <funchook.h>
#include <igameevents.h>
#include <baseentity.h>
#include <public/eiface.h>
#include "core/memory.h"
#include "core/log.h"

#include "characterset.h"
#include "core/coreconfig.h"
#include "core/gameconfig.h"

#include <funchook.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 {

Expand All @@ -39,10 +37,10 @@ ChatManager::~ChatManager() {}

void ChatManager::OnAllInitialized()
{
m_pHostSay = reinterpret_cast<HostSay>(
modules::server->FindSignature(globals::gameConfig->GetSignature("Host_Say")));
m_pHostSay = reinterpret_cast<HostSay>(modules::server->FindSignature(globals::gameConfig->GetSignature("Host_Say")));

if (m_pHostSay == nullptr) {
if (m_pHostSay == nullptr)
{
CSSHARP_CORE_ERROR("Failed to find signature for \'Host_Say\'");
return;
}
Expand All @@ -54,12 +52,13 @@ void ChatManager::OnAllInitialized()

void ChatManager::OnShutdown() {}

void DetourHostSay(CBaseEntity* pController, CCommand& args, bool teamonly, int unk1,
const char* unk2)
void DetourHostSay(CEntityInstance* pController, CCommand& args, bool teamonly, int unk1, const char* unk2)
{
if (pController) {
if (pController)
{
auto pEvent = globals::gameEventManager->CreateEvent("player_chat", true);
if (pEvent) {
if (pEvent)
{
pEvent->SetBool("teamonly", teamonly);
pEvent->SetInt("userid", pController->GetEntityIndex().Get() - 1);
pEvent->SetString("text", args[1]);
Expand All @@ -72,25 +71,26 @@ void DetourHostSay(CBaseEntity* pController, CCommand& args, bool teamonly, int
bool bSilent = globals::coreConfig->IsSilentChatTrigger(args[1], prefix);
bool bCommand = globals::coreConfig->IsPublicChatTrigger(args[1], prefix) || bSilent;

if (!bSilent) {
if (!bSilent)
{
m_pHostSay(pController, args, teamonly, unk1, unk2);
}

if (bCommand)
{
char *pszMessage = (char *)(args.ArgS() + prefix.length() + 1);
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;
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) {
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());
}
Expand All @@ -99,30 +99,29 @@ void DetourHostSay(CBaseEntity* pController, CCommand& args, bool teamonly, int
}
}

bool ChatManager::OnSayCommandPre(CBaseEntity* pController, CCommand& command) { return false; }
bool ChatManager::OnSayCommandPre(CEntityInstance* pController, CCommand& command) { return false; }

void ChatManager::OnSayCommandPost(CBaseEntity* pController, CCommand& command)
void ChatManager::OnSayCommandPost(CEntityInstance* pController, CCommand& command)
{
auto commandStr = command.Arg(0);

return InternalDispatch(pController, commandStr, command);
}

void ChatManager::InternalDispatch(CBaseEntity* pPlayerController, const char* szTriggerPhase,
CCommand& fullCommand)
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);
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);
globals::conCommandManager.ExecuteCommandCallbacks(fullCommand.Arg(0), CCommandContext(CommandTarget_t::CT_NO_TARGET, slot),
fullCommand, HookMode::Pre, CommandCallingContext::Chat);
}
} // namespace counterstrikesharp
} // namespace counterstrikesharp
17 changes: 8 additions & 9 deletions src/core/managers/chat_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
#include <map>
#include <vector>

#include "core/globals.h"
#include "core/global_listener.h"
#include "core/globals.h"
#include "scripting/script_engine.h"

namespace counterstrikesharp {
class ScriptCallback;

typedef void (*HostSay)(CBaseEntity*, CCommand&, bool, int, const char*);
typedef void (*HostSay)(CEntityInstance*, CCommand&, bool, int, const char*);

class ChatCommandInfo
{
Expand All @@ -52,18 +52,17 @@ class ChatManager : public GlobalClass
void OnAllInitialized() override;
void OnShutdown() override;

bool OnSayCommandPre(CBaseEntity* pController, CCommand& args);
void OnSayCommandPost(CBaseEntity* pController, CCommand& args);
bool OnSayCommandPre(CEntityInstance* pController, CCommand& args);
void OnSayCommandPost(CEntityInstance* pController, CCommand& args);

private:
void InternalDispatch(CBaseEntity* pPlayerController, const char* szTriggerPhrase,
CCommand& pFullCommand);
void InternalDispatch(CEntityInstance* pPlayerController, const char* szTriggerPhrase, CCommand& pFullCommand);

std::vector<ChatCommandInfo*> m_cmd_list;
std::map<std::string, ChatCommandInfo*> m_cmd_lookup;
};

static void DetourHostSay(CBaseEntity* pController, CCommand& args, bool teamonly, int unk1,
const char* unk2);
static void DetourHostSay(CEntityInstance* pController, CCommand& args, bool teamonly, int unk1, const char* unk2);
static HostSay m_pHostSay = nullptr;

} // namespace counterstrikesharp
} // namespace counterstrikesharp
68 changes: 30 additions & 38 deletions src/core/managers/voice_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
*/

#include "core/managers/voice_manager.h"
#include "core/managers/player_manager.h"

#include <entity2/entitysystem.h>
#include <public/eiface.h>
#include "scripting/callback_manager.h"
#include <schema.h>
#include <entity2/entitysystem.h>

SH_DECL_HOOK3(IVEngineServer2, SetClientListening, SH_NOATTRIB, 0, bool, CPlayerSlot, CPlayerSlot,
bool);
#include "core/managers/player_manager.h"
#include "scripting/callback_manager.h"

SH_DECL_HOOK3(IVEngineServer2, SetClientListening, SH_NOATTRIB, 0, bool, CPlayerSlot, CPlayerSlot, bool);

namespace counterstrikesharp {

Expand All @@ -33,14 +33,12 @@ VoiceManager::~VoiceManager() {}

void VoiceManager::OnAllInitialized()
{
SH_ADD_HOOK(IVEngineServer2, SetClientListening, globals::engine,
SH_MEMBER(this, &VoiceManager::SetClientListening), false);
SH_ADD_HOOK(IVEngineServer2, SetClientListening, globals::engine, SH_MEMBER(this, &VoiceManager::SetClientListening), false);
}

void VoiceManager::OnShutdown()
{
SH_REMOVE_HOOK(IVEngineServer2, SetClientListening, globals::engine,
SH_MEMBER(this, &VoiceManager::SetClientListening), false);
SH_REMOVE_HOOK(IVEngineServer2, SetClientListening, globals::engine, SH_MEMBER(this, &VoiceManager::SetClientListening), false);
}

bool VoiceManager::SetClientListening(CPlayerSlot iReceiver, CPlayerSlot iSender, bool bListen)
Expand All @@ -56,49 +54,44 @@ bool VoiceManager::SetClientListening(CPlayerSlot iReceiver, CPlayerSlot iSender

if (pReceiver->m_selfMutes->Get(iSender.Get()))
{
RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, bListen, &IVEngineServer2::SetClientListening,
(iReceiver, iSender, false));
RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, bListen, &IVEngineServer2::SetClientListening, (iReceiver, iSender, false));
}

if (senderFlags & Speak_Muted)
{
RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, bListen, &IVEngineServer2::SetClientListening,
(iReceiver, iSender, false));
RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, bListen, &IVEngineServer2::SetClientListening, (iReceiver, iSender, false));
}

if (listenOverride == Listen_Mute)
{
RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, bListen, &IVEngineServer2::SetClientListening,
(iReceiver, iSender, false));
} else if (listenOverride == Listen_Hear) {
RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, bListen, &IVEngineServer2::SetClientListening,
(iReceiver, iSender, true));
RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, bListen, &IVEngineServer2::SetClientListening, (iReceiver, iSender, false));
}
else if (listenOverride == Listen_Hear)
{
RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, bListen, &IVEngineServer2::SetClientListening, (iReceiver, iSender, true));
}

if ((senderFlags & Speak_All) || (receiverFlags & Speak_ListenAll)) {
RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, bListen, &IVEngineServer2::SetClientListening,
(iReceiver, iSender, true));
if ((senderFlags & Speak_All) || (receiverFlags & Speak_ListenAll))
{
RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, bListen, &IVEngineServer2::SetClientListening, (iReceiver, iSender, true));
}

if ((senderFlags & Speak_Team) || (receiverFlags & Speak_ListenTeam))
{
static auto classKey = hash_32_fnv1a_const("CBaseEntity");
static auto memberKey = hash_32_fnv1a_const("m_iTeamNum");
const static auto m_key = schema::GetOffset("CBaseEntity", classKey, "m_iTeamNum", memberKey);

auto receiverController = globals::entitySystem->GetBaseEntity(CEntityIndex(iReceiver.Get() + 1));
auto senderController = globals::entitySystem->GetBaseEntity(CEntityIndex(iSender.Get() + 1));
auto receiverController = globals::entitySystem->GetEntityInstance(CEntityIndex(iReceiver.Get() + 1));
auto senderController = globals::entitySystem->GetEntityInstance(CEntityIndex(iSender.Get() + 1));

if (receiverController && senderController)
{
auto receiverTeam = *reinterpret_cast<std::add_pointer_t<unsigned int>>(
(uintptr_t)(receiverController) + m_key.offset);
auto receiverTeam = *reinterpret_cast<std::add_pointer_t<unsigned int>>((uintptr_t)(receiverController) + m_key.offset);

auto senderTeam = *reinterpret_cast<std::add_pointer_t<unsigned int>>(
(uintptr_t)(senderController) + m_key.offset);
auto senderTeam = *reinterpret_cast<std::add_pointer_t<unsigned int>>((uintptr_t)(senderController) + m_key.offset);

RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, bListen,
&IVEngineServer2::SetClientListening,
RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, bListen, &IVEngineServer2::SetClientListening,
(iReceiver, iSender, receiverTeam == senderTeam));
}
}
Expand All @@ -111,19 +104,18 @@ void VoiceManager::OnClientCommand(CPlayerSlot slot, const CCommand& args)
{
auto pPlayer = globals::playerManager.GetPlayerBySlot(slot.Get());

if (!pPlayer)
return;
if (!pPlayer) return;

if (args.ArgC() > 1 && stricmp(args.Arg(0), "vban") == 0)
{
// clients just refuse to send vban for indexes over 32 and all 4 fields are just the same number, so we only get the first one
//for (int i = 1; (i < args.ArgC()) && (i < 3); i++) {
unsigned int mask = 0;
sscanf(args.Arg(1), "%x", &mask);
// for (int i = 1; (i < args.ArgC()) && (i < 3); i++) {
unsigned int mask = 0;
sscanf(args.Arg(1), "%x", &mask);

pPlayer->m_selfMutes->SetDWord(0, mask);
pPlayer->m_selfMutes->SetDWord(0, mask);
//}
}
}

} // namespace counterstrikesharp
} // namespace counterstrikesharp
Loading

0 comments on commit 02d5191

Please sign in to comment.