Move RootConsoleMenu::ConsolePrint into the logic bridge.

This commit is contained in:
David Anderson 2015-08-28 12:00:29 -04:00
parent 2c886943a0
commit 23d55dd9d5
4 changed files with 31 additions and 15 deletions

View File

@ -67,23 +67,10 @@ void RootConsoleMenu::OnSourceModShutdown()
void RootConsoleMenu::ConsolePrint(const char *fmt, ...)
{
char buffer[512];
va_list ap;
va_start(ap, fmt);
size_t len = vsnprintf(buffer, sizeof(buffer), fmt, ap);
UTIL_ConsolePrintVa(fmt, ap);
va_end(ap);
if (len >= sizeof(buffer) - 1)
{
buffer[510] = '\n';
buffer[511] = '\0';
} else {
buffer[len++] = '\n';
buffer[len] = '\0';
}
META_CONPRINT(buffer);
}
bool RootConsoleMenu::AddRootConsoleCommand(const char *cmd, const char *text, IRootConsoleCommand *pHandler)

View File

@ -52,7 +52,7 @@ using namespace SourceHook;
* Add 1 to the RHS of this expression to bump the intercom file
* This is to prevent mismatching core/logic binaries
*/
#define SM_LOGIC_MAGIC (0x0F47C0DE - 36)
#define SM_LOGIC_MAGIC (0x0F47C0DE - 37)
#if defined SM_LOGIC
class IVEngineServer
@ -318,6 +318,7 @@ struct sm_core_t
bool (*DescribePlayer)(int index, const char **namep, const char **authp, int *useridp);
int (*MaxClients)();
int (*GetGlobalTarget)();
void (*ConsolePrintVa)(const char *fmt, va_list ap);
const char *gamesuffix;
/* Data */
ServerGlobals *serverGlobals;

View File

@ -544,6 +544,30 @@ static int get_global_target()
return g_SourceMod.GetGlobalTarget();
}
void UTIL_ConsolePrintVa(const char *fmt, va_list ap)
{
char buffer[512];
size_t len = ke::SafeVsprintf(buffer, sizeof(buffer), fmt, ap);
if (len >= sizeof(buffer) - 1)
{
buffer[510] = '\n';
buffer[511] = '\0';
} else {
buffer[len++] = '\n';
buffer[len] = '\0';
}
META_CONPRINT(buffer);
}
void UTIL_ConsolePrint(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
UTIL_ConsolePrintVa(fmt, ap);
va_end(ap);
}
#if defined METAMOD_PLAPI_VERSION
#if SOURCE_ENGINE == SE_LEFT4DEAD
#define GAMEFIX "2.l4d"
@ -636,6 +660,7 @@ static sm_core_t core_bridge =
describe_player,
get_max_clients,
get_global_target,
UTIL_ConsolePrintVa,
GAMEFIX,
&serverGlobals,
};

View File

@ -151,6 +151,9 @@ private:
CVector<GAME_FRAME_HOOK> m_frame_hooks;
};
void UTIL_ConsolePrintVa(const char *fmt, va_list ap);
void UTIL_ConsolePrint(const char *fmt, ...);
extern bool g_Loaded;
extern bool sm_show_debug_spew;
extern SourceModBase g_SourceMod;