Start a new bridge mechanism for global callbacks.

This commit is contained in:
David Anderson 2015-08-29 22:10:59 -04:00
parent 38e1c2f1f3
commit 401aa038f8
3 changed files with 23 additions and 8 deletions

View File

@ -47,7 +47,7 @@ SH_DECL_HOOK1_void(IVEngineServer, LogPrint, SH_NOATTRIB, false, const char *);
static void HookLogPrint(const char *message) static void HookLogPrint(const char *message)
{ {
g_in_game_log_hook = true; g_in_game_log_hook = true;
bool stopped = logicore.OnLogPrint(message); bool stopped = logicore.callbacks->OnLogPrint(message);
g_in_game_log_hook = false; g_in_game_log_hook = false;
if (stopped) if (stopped)

View File

@ -92,9 +92,6 @@ static IGameConfig *GetCoreGameConfig()
return g_pGameConf; return g_pGameConf;
} }
// Defined in smn_filesystem.cpp.
extern bool OnLogPrint(const char *msg);
static void GenerateError(IPluginContext *ctx, cell_t idx, int err, const char *msg, ...) static void GenerateError(IPluginContext *ctx, cell_t idx, int err, const char *msg, ...)
{ {
va_list ap; va_list ap;
@ -128,6 +125,17 @@ static void OnRootCommand(const ICommandArgs *args)
g_RootMenu.GotRootCmd(args); g_RootMenu.GotRootCmd(args);
} }
// Defined in smn_filesystem.cpp.
extern bool OnLogPrint(const char *msg);
class ProviderCallbackListener : public IProviderCallbacks
{
public:
bool OnLogPrint(const char *msg) override {
return ::OnLogPrint(msg);
}
} sProviderCallbackListener;
static sm_logic_t logic = static sm_logic_t logic =
{ {
NULL, NULL,
@ -141,7 +149,6 @@ static sm_logic_t logic =
UTIL_ReplaceEx, UTIL_ReplaceEx,
UTIL_DecodeHexString, UTIL_DecodeHexString,
GetCoreGameConfig, GetCoreGameConfig,
OnLogPrint,
&g_DbgReporter, &g_DbgReporter,
GenerateError, GenerateError,
AddNatives, AddNatives,
@ -158,6 +165,7 @@ static sm_logic_t logic =
NULL, NULL,
&g_Logger, &g_Logger,
&g_RootMenu, &g_RootMenu,
&sProviderCallbackListener,
-1.0f -1.0f
}; };

View File

@ -52,7 +52,7 @@ using namespace SourceHook;
* Add 1 to the RHS of this expression to bump the intercom file * Add 1 to the RHS of this expression to bump the intercom file
* This is to prevent mismatching core/logic binaries * This is to prevent mismatching core/logic binaries
*/ */
#define SM_LOGIC_MAGIC (0x0F47C0DE - 46) #define SM_LOGIC_MAGIC (0x0F47C0DE - 47)
#if defined SM_LOGIC #if defined SM_LOGIC
# define IVEngineClass IVEngineServer # define IVEngineClass IVEngineServer
@ -331,6 +331,13 @@ public:
int (*GetGlobalTarget)(); int (*GetGlobalTarget)();
}; };
class IProviderCallbacks
{
public:
// Called when a log message is printed. Return true to supercede.
virtual bool OnLogPrint(const char *msg) = 0;
};
struct sm_logic_t struct sm_logic_t
{ {
SMGlobalClass *head; SMGlobalClass *head;
@ -344,7 +351,6 @@ struct sm_logic_t
char *(*ReplaceEx)(char *, size_t, const char *, size_t, const char *, size_t, bool); char *(*ReplaceEx)(char *, size_t, const char *, size_t, const char *, size_t, bool);
size_t (*DecodeHexString)(unsigned char *, size_t, const char *); size_t (*DecodeHexString)(unsigned char *, size_t, const char *);
IGameConfig * (*GetCoreGameConfig)(); IGameConfig * (*GetCoreGameConfig)();
bool (*OnLogPrint)(const char *msg); // true to supersede
IDebugListener *debugger; IDebugListener *debugger;
void (*GenerateError)(IPluginContext *, cell_t, int, const char *, ...); void (*GenerateError)(IPluginContext *, cell_t, int, const char *, ...);
void (*AddNatives)(sp_nativeinfo_t *natives); void (*AddNatives)(sp_nativeinfo_t *natives);
@ -361,6 +367,7 @@ struct sm_logic_t
IdentityToken_t *core_ident; IdentityToken_t *core_ident;
ILogger *logger; ILogger *logger;
IRootConsole *rootmenu; IRootConsole *rootmenu;
IProviderCallbacks *callbacks;
float sentinel; float sentinel;
}; };