diff --git a/metamod/src/commands_meta.cpp b/metamod/src/commands_meta.cpp index 3712b16..91c599b 100644 --- a/metamod/src/commands_meta.cpp +++ b/metamod/src/commands_meta.cpp @@ -41,7 +41,7 @@ void meta_register_cmdcvar() } // Parse "meta" console command. -void server_meta() +void EXT_FUNC server_meta() { const char *cmd = CMD_ARGV(1); @@ -59,7 +59,7 @@ void server_meta() } // Parse "meta" client command. -void client_meta(edict_t* pEntity) +void EXT_FUNC client_meta(edict_t* pEntity) { const char *cmd = CMD_ARGV(1); META_LOG("ClientCommand 'meta %s' from player '%s'", CMD_ARGS(), STRING(pEntity->v.netname)); diff --git a/metamod/src/dllapi.cpp b/metamod/src/dllapi.cpp index f850a78..24574b0 100644 --- a/metamod/src/dllapi.cpp +++ b/metamod/src/dllapi.cpp @@ -29,7 +29,7 @@ void mm_ClientCommand(edict_t *pEntity) } } -void mm_ServerDeactivate(void) +void EXT_FUNC mm_ServerDeactivate(void) { sFunctionTable_jit.pfnServerDeactivate(); @@ -46,11 +46,13 @@ void mm_ServerDeactivate(void) // from the previous map. It's also called right before shutdown, // which means whenever hlds quits, it'll reload the plugins just // before it exits, which is rather silly, but oh well. - g_plugins->refresh(PT_CHANGELEVEL); + g_plugins->refresh(PT_CHANGELEVEL); // <- callbacks rebuilded (!) g_plugins->unpause_all(); // g_plugins->retry_all(PT_CHANGELEVEL); g_players.clear_all_cvar_queries(); requestid_counter = 0; + + /* RETURN TO ENGINE */ } compile_data_t g_dllfunc_cdata[] = @@ -259,7 +261,7 @@ void compile_gamedll_tramps() *(size_t *)(size_t(&sFunctionTable) + cd.offset) = g_jit.compile_tramp(size_t(&sFunctionTable_jit) + cd.offset); } - // use direct hook + // use direct hook to prevent crash after callbacks rebuilding sFunctionTable.pfnServerDeactivate = mm_ServerDeactivate; for (auto& cd : g_newdllfunc_cdata) { diff --git a/metamod/src/jitasm.h b/metamod/src/jitasm.h index f74840d..a78f427 100644 --- a/metamod/src/jitasm.h +++ b/metamod/src/jitasm.h @@ -8887,7 +8887,8 @@ struct function_cdecl::ResultPtr result_ptr; operator FuncPtr() { return (FuncPtr)GetCode(); } void InternalMain() {static_cast(this)->naked_main();} - void naked_main() { + + virtual void naked_main() { using namespace detail::calling_convention_cdecl; Prolog(); detail::ResultDest result_dst(*this, ResultInfo()); diff --git a/metamod/src/metamod.cpp b/metamod/src/metamod.cpp index fe43521..42469ca 100644 --- a/metamod/src/metamod.cpp +++ b/metamod/src/metamod.cpp @@ -31,10 +31,6 @@ unsigned int CALL_API_count = 0; int requestid_counter = 0; -#ifdef UNFINISHED -MHookList *Hooks; -#endif // UNFINISHED - // Very first metamod function that's run. // Do startup operations... void metamod_startup() diff --git a/metamod/src/mutil.cpp b/metamod/src/mutil.cpp index 266b0f2..6b80875 100644 --- a/metamod/src/mutil.cpp +++ b/metamod/src/mutil.cpp @@ -10,7 +10,7 @@ hudtextparms_t default_csay_tparms = { }; // Log to console; newline added. -void mutil_LogConsole(plid_t plid, const char *fmt, ...) +void EXT_FUNC mutil_LogConsole(plid_t plid, const char *fmt, ...) { va_list ap; char buf[MAX_LOGMSG_LEN]; @@ -31,7 +31,7 @@ void mutil_LogConsole(plid_t plid, const char *fmt, ...) } // Log regular message to logs; newline added. -void mutil_LogMessage(plid_t plid, const char *fmt, ...) +void EXT_FUNC mutil_LogMessage(plid_t plid, const char *fmt, ...) { va_list ap; char buf[MAX_LOGMSG_LEN]; @@ -44,7 +44,7 @@ void mutil_LogMessage(plid_t plid, const char *fmt, ...) } // Log an error message to logs; newline added. -void mutil_LogError(plid_t plid, const char *fmt, ...) +void EXT_FUNC mutil_LogError(plid_t plid, const char *fmt, ...) { va_list ap; char buf[MAX_LOGMSG_LEN]; @@ -57,7 +57,7 @@ void mutil_LogError(plid_t plid, const char *fmt, ...) } // Log a message only if cvar "developer" set; newline added. -void mutil_LogDeveloper(plid_t plid, const char* fmt, ...) +void EXT_FUNC mutil_LogDeveloper(plid_t plid, const char* fmt, ...) { va_list ap; char buf[MAX_LOGMSG_LEN]; @@ -75,7 +75,7 @@ void mutil_LogDeveloper(plid_t plid, const char* fmt, ...) // Print message on center of all player's screens. Uses default text // parameters (color green, 10 second fade-in). -void mutil_CenterSay(plid_t plid, const char* fmt, ...) +void EXT_FUNC mutil_CenterSay(plid_t plid, const char* fmt, ...) { va_list ap; va_start(ap, fmt); @@ -84,7 +84,7 @@ void mutil_CenterSay(plid_t plid, const char* fmt, ...) } // Print a center-message, with given text parameters. -void mutil_CenterSayParms(plid_t plid, hudtextparms_t tparms, const char* fmt, ...) +void EXT_FUNC mutil_CenterSayParms(plid_t plid, hudtextparms_t tparms, const char* fmt, ...) { va_list ap; va_start(ap, fmt); @@ -94,7 +94,7 @@ void mutil_CenterSayParms(plid_t plid, hudtextparms_t tparms, const char* fmt, . // Print a center-message, with text parameters and varargs. Provides // functionality to the above center_say interfaces. -void mutil_CenterSayVarargs(plid_t plid, hudtextparms_t tparms, const char* fmt, va_list ap) +void EXT_FUNC mutil_CenterSayVarargs(plid_t plid, hudtextparms_t tparms, const char* fmt, va_list ap) { char buf[MAX_LOGMSG_LEN]; int n; @@ -115,7 +115,7 @@ void mutil_CenterSayVarargs(plid_t plid, hudtextparms_t tparms, const char* fmt, // Allow plugins to call the entity functions in the GameDLL. In // particular, calling "player()" as needed by most Bots. Suggested by // Jussi Kivilinna. -qboolean mutil_CallGameEntity(plid_t plid, const char *entStr, entvars_t *pev) +qboolean EXT_FUNC mutil_CallGameEntity(plid_t plid, const char *entStr, entvars_t *pev) { plugin_info_t *plinfo = (plugin_info_t *)plid; META_DEBUG(8, ("Looking up game entity '%s' for plugin '%s'", entStr, plinfo->name)); @@ -133,7 +133,7 @@ qboolean mutil_CallGameEntity(plid_t plid, const char *entStr, entvars_t *pev) // Find a usermsg, registered by the gamedll, with the corresponding // msgname, and return remaining info about it (msgid, size). -int mutil_GetUserMsgID(plid_t plid, const char* msgname, int* size) +int EXT_FUNC mutil_GetUserMsgID(plid_t plid, const char* msgname, int* size) { plugin_info_t *plinfo = (plugin_info_t *)plid; META_DEBUG(8, ("Looking up usermsg name '%s' for plugin '%s'", msgname, plinfo->name)); @@ -151,7 +151,7 @@ int mutil_GetUserMsgID(plid_t plid, const char* msgname, int* size) // Find a usermsg, registered by the gamedll, with the corresponding // msgid, and return remaining info about it (msgname, size). -const char* mutil_GetUserMsgName(plid_t plid, int msgid, int *size) +const char* EXT_FUNC mutil_GetUserMsgName(plid_t plid, int msgid, int *size) { plugin_info_t *plinfo = (plugin_info_t *)plid; META_DEBUG(8, ("Looking up usermsg id '%d' for plugin '%s'", msgid, plinfo->name)); @@ -197,7 +197,7 @@ const char* mutil_GetUserMsgName(plid_t plid, int msgid, int *size) } // Return the full path of the plugin's loaded dll/so file. -const char* mutil_GetPluginPath(plid_t plid) +const char* EXT_FUNC mutil_GetPluginPath(plid_t plid) { static char buf[PATH_MAX ]; MPlugin *plug; @@ -215,7 +215,7 @@ const char* mutil_GetPluginPath(plid_t plid) } // Return various string-based info about the game/MOD/gamedll. -const char* mutil_GetGameInfo(plid_t plid, ginfo_t type) +const char* EXT_FUNC mutil_GetGameInfo(plid_t plid, ginfo_t type) { static char buf[MAX_STRBUF_LEN]; const char *cp; @@ -249,7 +249,7 @@ const char* mutil_GetGameInfo(plid_t plid, ginfo_t type) return buf; } -int mutil_LoadMetaPlugin(plid_t plid, const char* fname, PLUG_LOADTIME now, void **plugin_handle) +int EXT_FUNC mutil_LoadMetaPlugin(plid_t plid, const char* fname, PLUG_LOADTIME now, void **plugin_handle) { MPlugin *pl_loaded; if (!fname) @@ -273,7 +273,7 @@ int mutil_LoadMetaPlugin(plid_t plid, const char* fname, PLUG_LOADTIME now, void } } -int mutil_UnloadMetaPlugin(plid_t plid, const char *fname, PLUG_LOADTIME now, PL_UNLOAD_REASON reason) +int EXT_FUNC mutil_UnloadMetaPlugin(plid_t plid, const char *fname, PLUG_LOADTIME now, PL_UNLOAD_REASON reason) { MPlugin *findp = nullptr; int pindex; @@ -301,7 +301,7 @@ int mutil_UnloadMetaPlugin(plid_t plid, const char *fname, PLUG_LOADTIME now, PL return meta_errno; } -int mutil_UnloadMetaPluginByHandle(plid_t plid, void *plugin_handle, PLUG_LOADTIME now, PL_UNLOAD_REASON reason) +int EXT_FUNC mutil_UnloadMetaPluginByHandle(plid_t plid, void *plugin_handle, PLUG_LOADTIME now, PL_UNLOAD_REASON reason) { MPlugin *findp; @@ -321,18 +321,18 @@ int mutil_UnloadMetaPluginByHandle(plid_t plid, void *plugin_handle, PLUG_LOADTI return meta_errno; } -const char* mutil_IsQueryingClientCvar(plid_t plid, const edict_t* pEdict) +const char* EXT_FUNC mutil_IsQueryingClientCvar(plid_t plid, const edict_t* pEdict) { return g_players.is_querying_cvar(pEdict); } -int mutil_MakeRequestId(plid_t plid) +int EXT_FUNC mutil_MakeRequestId(plid_t plid) { //the offset is to distinguish from gamedll requests, if any return abs(0xbeef << 16) + (++requestid_counter); } -void mutil_GetHookTables(plid_t plid, enginefuncs_t** peng, DLL_FUNCTIONS** pdll, NEW_DLL_FUNCTIONS** pnewdll) +void EXT_FUNC mutil_GetHookTables(plid_t plid, enginefuncs_t** peng, DLL_FUNCTIONS** pdll, NEW_DLL_FUNCTIONS** pnewdll) { if (peng) *peng = &meta_engfuncs; @@ -344,43 +344,6 @@ void mutil_GetHookTables(plid_t plid, enginefuncs_t** peng, DLL_FUNCTIONS** pdll *pnewdll = pHookedNewDllFunctions; } -#ifdef UNFINISHED - -int mutil_HookGameEvent(plid_t plid, game_event_t event, event_func_t pfnHandle) -{ - return Hooks->add(plid, event, pfnHandle); -} - -int mutil_HookLogTrigger(plid_t plid, const char *trigger, logmatch_func_t pfnHandle) -{ - return Hooks->add(plid, H_TRIGGER, trigger, pfnHandle); -} - -int mutil_HookLogString(plid_t plid, const char *string, logmatch_func_t pfnHandle) -{ - return Hooks->add(plid, H_STRING, string, pfnHandle); -} - -int mutil_HookLogRegex(plid_t plid, const char *pattern, logmatch_func_t pfnHandle) -{ - return Hooks->add(plid, H_STRING, pattern, pfnHandle); -} - -qboolean mutil_RemoveHookID(plid_t plid, int hookid) -{ - if (Hooks->remove(plid, hookid)) - return true; - - return false; -} - -int mutil_RemoveHookAll(plid_t plid) -{ - return Hooks->remove_all(plid); -} - -#endif // UNFINISHED - // Meta Utility Function table. mutil_funcs_t MetaUtilFunctions = { mutil_LogConsole, // pfnLogConsole @@ -401,12 +364,4 @@ mutil_funcs_t MetaUtilFunctions = { mutil_IsQueryingClientCvar, // pfnIsQueryingClientCvar mutil_MakeRequestId, // pfnMakeRequestId mutil_GetHookTables, // pfnGetHookTables -#ifdef UNFINISHED - mutil_HookGameEvent, // pfnGameEvent - mutil_HookLogTrigger, // pfnLogTrigger - mutil_HookLogString, // pfnLogString - mutil_HookLogRegex, // pfnLogRegex - mutil_RemoveHookID, // pfnRemoveHookID - mutil_RemoveHookAll, // pfnRemoveHookAll -#endif // UNFINISHED }; diff --git a/metamod/src/reg_support.cpp b/metamod/src/reg_support.cpp index 5b5d62a..e4e301e 100644 --- a/metamod/src/reg_support.cpp +++ b/metamod/src/reg_support.cpp @@ -45,7 +45,7 @@ // Generic command handler, passed to the engine for any AddServerCommand // calls made by the plugin. It finds the appropriate plugin function // pointer to call based on CMD_ARGV(0). -void meta_command_handler() +void EXT_FUNC meta_command_handler() { META_DEBUG(5, ("called: meta_command_handler; arg0=%s args='%s'", CMD_ARGV(0), CMD_ARGS())); const char *cmd = CMD_ARGV(0); @@ -78,7 +78,7 @@ void meta_command_handler() // The string handed to the engine is just a Q_strdup() of the plugin's // string. The function pointer handed to the engine is actually a pointer // to a generic command-handler function (see above). -void meta_AddServerCommand(char *cmd_name, void (*function)()) +void EXT_FUNC meta_AddServerCommand(char *cmd_name, void (*function)()) { MPlugin *iplug = NULL; MRegCmd *icmd = NULL; @@ -132,7 +132,7 @@ void meta_AddServerCommand(char *cmd_name, void (*function)()) // values via the engine functions, this will work fine. If the plugin // code tries to _directly_ read/set the fields of its own cvar structures, // it will fail to work properly. -void meta_CVarRegister(cvar_t *pCvar) +void EXT_FUNC meta_CVarRegister(cvar_t *pCvar) { MPlugin *iplug = nullptr; MRegCvar *icvar = nullptr; @@ -192,15 +192,15 @@ void meta_CVarRegister(cvar_t *pCvar) // commands and cvars). This merely provides differently located storage // for the string. -int meta_RegUserMsg(const char *pszName, int iSize) +int EXT_FUNC meta_RegUserMsg(const char *pszName, int iSize) { char *cp = Q_strdup(pszName); return REG_USER_MSG(cp, iSize); } // Intercept and record queries -void meta_QueryClientCvarValue(const edict_t *player, const char *cvarName) +void EXT_FUNC meta_QueryClientCvarValue(const edict_t *player, const char *cvarName) { g_players.set_player_cvar_query(player, cvarName); - (*g_engfuncs.pfnQueryClientCvarValue)(player, cvarName); + g_engfuncs.pfnQueryClientCvarValue(player, cvarName); } diff --git a/metamod/src/sdk_util.cpp b/metamod/src/sdk_util.cpp index 88865fd..349247d 100644 --- a/metamod/src/sdk_util.cpp +++ b/metamod/src/sdk_util.cpp @@ -17,7 +17,7 @@ char *UTIL_VarArgs(char *format, ...) void UTIL_LogPrintf(char *fmt, ...) { va_list argptr; - static char string[1024]; + char string[1024]; va_start(argptr, fmt); Q_vsnprintf(string, sizeof(string), fmt, argptr);