Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions regamedll/dlls/API/CAPI_Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ GAMEHOOK_REGISTRY(CBasePlayer_RemoveAllItems);
GAMEHOOK_REGISTRY(CBasePlayer_UpdateStatusBar);
GAMEHOOK_REGISTRY(CBasePlayer_TakeDamageImpulse);

GAMEHOOK_REGISTRY(SendSayMessage);

int CReGameApi::GetMajorVersion() {
return REGAMEDLL_API_VERSION_MAJOR;
}
Expand Down
9 changes: 9 additions & 0 deletions regamedll/dlls/API/CAPI_Impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,10 @@ typedef IHookChainRegistryClassImpl<void, CBasePlayer> CReGameHookRegistry_CBase
typedef IHookChainClassImpl<void, CBasePlayer, CBasePlayer *, float, float> CReGameHook_CBasePlayer_TakeDamageImpulse;
typedef IHookChainRegistryClassImpl<void, CBasePlayer, CBasePlayer *, float, float> CReGameHookRegistry_CBasePlayer_TakeDamageImpulse;

// SendSayMessage hook
typedef IHookChainImpl<void, CBasePlayer *, const char *, BOOL, const char*, const char*, const char*, bool, const char*, bool> CReGameHook_SendSayMessage;
typedef IHookChainRegistryImpl<void, CBasePlayer *, const char *, BOOL, const char*, const char*, const char*, bool, const char*, bool> CReGameHookRegistry_SendSayMessage;

class CReGameHookchains: public IReGameHookchains {
public:
// CBasePlayer virtual
Expand Down Expand Up @@ -921,6 +925,8 @@ class CReGameHookchains: public IReGameHookchains {
CReGameHookRegistry_CBasePlayer_UpdateStatusBar m_CBasePlayer_UpdateStatusBar;
CReGameHookRegistry_CBasePlayer_TakeDamageImpulse m_CBasePlayer_TakeDamageImpulse;

CReGameHookRegistry_SendSayMessage m_SendSayMessage;

public:
virtual IReGameHookRegistry_CBasePlayer_Spawn *CBasePlayer_Spawn();
virtual IReGameHookRegistry_CBasePlayer_Precache *CBasePlayer_Precache();
Expand Down Expand Up @@ -1080,8 +1086,11 @@ class CReGameHookchains: public IReGameHookchains {
virtual IReGameHookRegistry_CBasePlayer_PlayerDeathThink *CBasePlayer_PlayerDeathThink();
virtual IReGameHookRegistry_CBasePlayer_Observer_Think *CBasePlayer_Observer_Think();
virtual IReGameHookRegistry_CBasePlayer_RemoveAllItems *CBasePlayer_RemoveAllItems();

virtual IReGameHookRegistry_CBasePlayer_UpdateStatusBar *CBasePlayer_UpdateStatusBar();
virtual IReGameHookRegistry_CBasePlayer_TakeDamageImpulse *CBasePlayer_TakeDamageImpulse();

virtual IReGameHookRegistry_SendSayMessage *SendSayMessage();
};

extern CReGameHookchains g_ReGameHookchains;
Expand Down
79 changes: 60 additions & 19 deletions regamedll/dlls/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -751,9 +751,7 @@ void EXT_FUNC ClientPutInServer(edict_t *pEntity)

void Host_Say(edict_t *pEntity, BOOL teamonly)
{
int j;
char *p;
char text[128];
char szTemp[256];
const char *cpSay = "say";
const char *cpSayTeam = "say_team";
Expand Down Expand Up @@ -946,19 +944,6 @@ void Host_Say(edict_t *pEntity, BOOL teamonly)
}
}

text[0] = '\0';

// -3 for /n and null terminator
j = sizeof(text) - 3 - Q_strlen(text) - Q_strlen(pszFormat);

if (placeName)
{
j -= Q_strlen(placeName) + 1;
}

if ((signed int)Q_strlen(p) > j)
p[j] = 0;

for (char *pAmpersand = p; pAmpersand && *pAmpersand != '\0'; pAmpersand++)
{
if (pAmpersand[0] == '%')
Expand All @@ -970,7 +955,54 @@ void Host_Say(edict_t *pEntity, BOOL teamonly)
}
}

Q_strlcat(text, p);
SendSayMessage(pPlayer, pcmd, teamonly, p, pszFormat, pszConsoleFormat, bSenderDead, placeName, consoleUsesPlaceName);
}

LINK_HOOK_VOID_CHAIN(SendSayMessage, (CBasePlayer *pPlayer, const char *pszCmd, BOOL teamonly, const char *pszText, const char *pszFormat, const char *pszConsoleFormat, bool bSenderDead, const char *placeName, bool consoleUsesPlaceName), pPlayer, pszCmd, teamonly, pszText, pszFormat, pszConsoleFormat, bSenderDead, placeName, consoleUsesPlaceName)

void EXT_FUNC __API_HOOK(SendSayMessage)(CBasePlayer *pPlayer, const char *pszCmd, BOOL teamonly, const char *pszText, const char *pszFormat, const char *pszConsoleFormat, bool bSenderDead, const char *placeName, bool consoleUsesPlaceName)
{
char msg[256]; // local mutable copy of pszText
char text[128];
int j;

msg[0] = '\0';
text[0] = '\0';

// safety
if (!pszText)
pszText = "";
if (!pszFormat)
pszFormat = "";

Q_strlcpy(msg, pszText);

// -3 for /n and null terminator
j = sizeof(text) - 3 - Q_strlen(pszFormat);

if (placeName)
j -= Q_strlen(placeName) + 1;

// huge pszFormat/placeName len
if (j < 0)
j = 0;

size_t len = Q_strlen(msg);
if ((signed int)len > j)
{
msg[j] = '\0';
len = j;
}

// removing newline if exists (UTIL_LogPrintf fix)
// (may come from a modder mistake)
if (len > 0 && msg[len - 1] == '\n')
{
msg[len - 1] = '\0';
len--;
}

Q_strlcat(text, msg);
Q_strlcat(text, "\n");

// loop through all players
Expand All @@ -979,6 +1011,8 @@ void Host_Say(edict_t *pEntity, BOOL teamonly)
// so check it, or it will infinite loop

CBasePlayer *pReceiver = nullptr;
edict_t *pEntity = ENT(pPlayer->pev);

while ((pReceiver = UTIL_FindEntityByClassname(pReceiver, "player")))
{
if (FNullEnt(pReceiver->edict()))
Expand Down Expand Up @@ -1066,10 +1100,13 @@ void Host_Say(edict_t *pEntity, BOOL teamonly)
// echo to server console
if (pszConsoleFormat)
{
char fmt[128];
Q_strlcpy(fmt, pszConsoleFormat);

if (placeName && consoleUsesPlaceName)
SERVER_PRINT(UTIL_VarArgs(pszConsoleFormat, STRING(pPlayer->pev->netname), placeName, text));
SERVER_PRINT(UTIL_VarArgs(fmt, STRING(pPlayer->pev->netname), placeName, text));
else
SERVER_PRINT(UTIL_VarArgs(pszConsoleFormat, STRING(pPlayer->pev->netname), text));
SERVER_PRINT(UTIL_VarArgs(fmt, STRING(pPlayer->pev->netname), text));
}
else
{
Expand All @@ -1079,13 +1116,17 @@ void Host_Say(edict_t *pEntity, BOOL teamonly)

if (logmessages.value)
{
#ifdef REGAMEDLL_ADD
const char *temp = pszCmd; // allow custom say command
#else
const char *temp = teamonly ? "say_team" : "say";
#endif
const char *deadText = (pPlayer->m_iTeam != SPECTATOR && bSenderDead) ? " (dead)" : "";

char *szTeam = GetTeam(pPlayer->m_iTeam);

UTIL_LogPrintf("\"%s<%i><%s><%s>\" %s \"%s\"%s\n", STRING(pPlayer->pev->netname), GETPLAYERUSERID(pPlayer->edict()), GETPLAYERAUTHID(pPlayer->edict()),
szTeam, temp, p, deadText);
szTeam, temp, msg, deadText);
}
}

Expand Down
2 changes: 2 additions & 0 deletions regamedll/dlls/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ extern unsigned short m_usResetDecals;
extern unsigned short g_iShadowSprite;

#ifdef REGAMEDLL_API
void SendSayMessage_OrigFunc(CBasePlayer *pPlayer, const char *pszCmd, BOOL teamonly, const char *pszText, const char *pszFormat, const char *pszConsoleFormat, bool bSenderDead, const char *placeName, bool consoleUsesPlaceName);
void HandleMenu_ChooseAppearance_OrigFunc(CBasePlayer *pPlayer, int slot);
BOOL HandleMenu_ChooseTeam_OrigFunc(CBasePlayer *pPlayer, int slot);
bool BuyGunAmmo_OrigFunc(CBasePlayer *pPlayer, CBasePlayerItem *weapon, bool bBlinkMoney);
Expand Down Expand Up @@ -136,6 +137,7 @@ void ProcessKickVote(CBasePlayer *pVotingPlayer, CBasePlayer *pKickPlayer);
void CheckStartMoney();
void ClientPutInServer(edict_t *pEntity);
void Host_Say(edict_t *pEntity, BOOL teamonly);
void SendSayMessage(CBasePlayer *pPlayer, const char *pszCmd, BOOL teamonly, const char *pszText, const char *pszFormat, const char *pszConsoleFormat, bool bSenderDead, const char *placeName, bool consoleUsesPlaceName);
void DropSecondary(CBasePlayer *pPlayer);
void DropPrimary(CBasePlayer *pPlayer);
bool CanBuyThis(CBasePlayer *pPlayer, int iWeapon);
Expand Down
7 changes: 7 additions & 0 deletions regamedll/public/regamedll/regamedll_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,10 @@ typedef IHookChainRegistryClass<void, class CBasePlayer> IReGameHookRegistry_CBa
typedef IHookChainClass<void, class CBasePlayer, class CBasePlayer *, float, float> IReGameHook_CBasePlayer_TakeDamageImpulse;
typedef IHookChainRegistryClass<void, class CBasePlayer, class CBasePlayer *, float, float> IReGameHookRegistry_CBasePlayer_TakeDamageImpulse;

// SendSayMessage hook
typedef IHookChain<void, CBasePlayer *, const char *, BOOL, const char*, const char*, const char*, bool, const char*, bool> IReGameHook_SendSayMessage;
typedef IHookChainRegistry<void, CBasePlayer *, const char *, BOOL, const char*, const char*, const char*, bool, const char*, bool> IReGameHookRegistry_SendSayMessage;

class IReGameHookchains {
public:
virtual ~IReGameHookchains() {}
Expand Down Expand Up @@ -798,8 +802,11 @@ class IReGameHookchains {
virtual IReGameHookRegistry_CBasePlayer_PlayerDeathThink *CBasePlayer_PlayerDeathThink() = 0;
virtual IReGameHookRegistry_CBasePlayer_Observer_Think *CBasePlayer_Observer_Think() = 0;
virtual IReGameHookRegistry_CBasePlayer_RemoveAllItems *CBasePlayer_RemoveAllItems() = 0;

virtual IReGameHookRegistry_CBasePlayer_UpdateStatusBar *CBasePlayer_UpdateStatusBar() = 0;
virtual IReGameHookRegistry_CBasePlayer_TakeDamageImpulse *CBasePlayer_TakeDamageImpulse() = 0;

virtual IReGameHookRegistry_SendSayMessage *SendSayMessage() = 0;
};

struct ReGameFuncs_t {
Expand Down