From 200fe16e1cc6eef86ba40d3ccf27b08161ac3baf Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sat, 17 Nov 2007 05:41:47 +0000 Subject: [PATCH] fix for amb1156 - CS:S Tools overrides the PrintHintText native with its own version. this is a fail-safe for CS:S being loaded, as we can have better control from an extension. --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401698 --- extensions/cstrike/extension.cpp | 6 ++++ extensions/cstrike/extension.h | 2 ++ extensions/cstrike/natives.cpp | 45 +++++++++++++++++++++++++++ extensions/cstrike/sdk/smsdk_config.h | 1 + extensions/cstrike/sdk/smsdk_ext.cpp | 6 ++++ extensions/cstrike/sdk/smsdk_ext.h | 6 ++++ 6 files changed, 66 insertions(+) diff --git a/extensions/cstrike/extension.cpp b/extensions/cstrike/extension.cpp index 182ae75e..d0b8daa4 100644 --- a/extensions/cstrike/extension.cpp +++ b/extensions/cstrike/extension.cpp @@ -45,6 +45,7 @@ IBinTools *g_pBinTools = NULL; IGameConfig *g_pGameConf = NULL; IGameEventManager2 *gameevents = NULL; bool hooked_everything = false; +int g_msgHintText = -1; SMEXT_LINK(&g_CStrike); @@ -67,6 +68,11 @@ bool CStrike::SDK_OnLoad(char *error, size_t maxlength, bool late) sharesys->AddNatives(myself, g_CSNatives); sharesys->RegisterLibrary(myself, "cstrike"); + if ((g_msgHintText = usermsgs->GetMessageIndex("HintText")) != -1) + { + sharesys->OverrideNatives(myself, g_CS_PrintHintText); + } + return true; } diff --git a/extensions/cstrike/extension.h b/extensions/cstrike/extension.h index 916bb2d2..acf301f3 100644 --- a/extensions/cstrike/extension.h +++ b/extensions/cstrike/extension.h @@ -122,5 +122,7 @@ public: /* Interfaces from SourceMod */ extern IBinTools *g_pBinTools; extern IGameConfig *g_pGameConf; +extern int g_msgHintText; +extern sp_nativeinfo_t g_CS_PrintHintText[]; #endif // _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_ diff --git a/extensions/cstrike/natives.cpp b/extensions/cstrike/natives.cpp index e5f085c4..ce711e68 100644 --- a/extensions/cstrike/natives.cpp +++ b/extensions/cstrike/natives.cpp @@ -69,6 +69,45 @@ inline CBaseEntity *GetCBaseEntity(int num, bool isplayer) return pUnk->GetBaseEntity(); } +static cell_t CS_PrintHintText(IPluginContext *pContext, const cell_t *params) +{ + int client = params[1]; + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(params[1]); + + if (!pPlayer) + { + return pContext->ThrowNativeError("Client index %d is invalid", client); + } + + if (!pPlayer->IsInGame()) + { + return pContext->ThrowNativeError("Client %d is not in game", client); + } + + g_pSM->SetGlobalTarget(client); + + char buffer[192]; + g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, 2); + + /* Check for an error before printing to the client */ + if (pContext->GetContext()->n_err != SP_ERROR_NONE) + { + return 0; + } + + bf_write *pBitBuf = usermsgs->StartMessage(g_msgHintText, ¶ms[1], 1, USERMSG_RELIABLE); + if (pBitBuf == NULL) + { + return pContext->ThrowNativeError("Could not send a usermessage"); + } + pBitBuf->WriteByte(1); + pBitBuf->WriteString(buffer); + usermsgs->EndMessage(); + + return 1; +} + + static cell_t CS_RespawnPlayer(IPluginContext *pContext, const cell_t *params) { static ICallWrapper *pWrapper = NULL; @@ -124,3 +163,9 @@ sp_nativeinfo_t g_CSNatives[] = {"CS_SwitchTeam", CS_SwitchTeam}, {NULL, NULL} }; + +sp_nativeinfo_t g_CS_PrintHintText[] = +{ + {"PrintHintText", CS_PrintHintText}, + {NULL, NULL}, +}; diff --git a/extensions/cstrike/sdk/smsdk_config.h b/extensions/cstrike/sdk/smsdk_config.h index fc402227..a070e6b3 100644 --- a/extensions/cstrike/sdk/smsdk_config.h +++ b/extensions/cstrike/sdk/smsdk_config.h @@ -71,5 +71,6 @@ #define SMEXT_ENABLE_TIMERSYS //#define SMEXT_ENABLE_THREADER //#define SMEXT_ENABLE_LIBSYS +#define SMEXT_ENABLE_USERMSGS #endif // _INCLUDE_SOURCEMOD_EXTENSION_CONFIG_H_ diff --git a/extensions/cstrike/sdk/smsdk_ext.cpp b/extensions/cstrike/sdk/smsdk_ext.cpp index 60480b22..f5e6f3fc 100644 --- a/extensions/cstrike/sdk/smsdk_ext.cpp +++ b/extensions/cstrike/sdk/smsdk_ext.cpp @@ -79,6 +79,9 @@ IThreader *threader = NULL; #if defined SMEXT_ENABLE_LIBSYS ILibrarySys *libsys = NULL; #endif +#if defined SMEXT_ENABLE_USERMSGS +IUserMessages *usermsgs = NULL; +#endif /** Exports the main interface */ PLATFORM_EXTERN_C IExtensionInterface *GetSMExtAPI() @@ -149,6 +152,9 @@ bool SDKExtension::OnExtensionLoad(IExtension *me, IShareSys *sys, char *error, #if defined SMEXT_ENABLE_LIBSYS SM_GET_IFACE(LIBRARYSYS, libsys); #endif +#if defined SMEXT_ENABLE_USERMSGS + SM_GET_IFACE(USERMSGS, usermsgs); +#endif if (SDK_OnLoad(error, maxlength, late)) { diff --git a/extensions/cstrike/sdk/smsdk_ext.h b/extensions/cstrike/sdk/smsdk_ext.h index 905e13a6..c137616b 100644 --- a/extensions/cstrike/sdk/smsdk_ext.h +++ b/extensions/cstrike/sdk/smsdk_ext.h @@ -73,6 +73,9 @@ #if defined SMEXT_ENABLE_LIBSYS #include #endif +#if defined SMEXT_ENABLE_USERMSGS +#include +#endif #if defined SMEXT_CONF_METAMOD #include @@ -260,6 +263,9 @@ extern IThreader *threader; #if defined SMEXT_ENABLE_LIBSYS extern ILibrarySys *libsys; #endif +#if defined SMEXT_ENABLE_USERMSGS +extern IUserMessages *usermsgs; +#endif #if defined SMEXT_CONF_METAMOD PLUGIN_GLOBALVARS();