mirror of
https://github.com/rehlds/metamod-r.git
synced 2025-01-13 15:18:19 +03:00
Refactoring
This commit is contained in:
parent
855e14b95e
commit
333918455c
@ -137,7 +137,8 @@
|
|||||||
<OmitFramePointers>true</OmitFramePointers>
|
<OmitFramePointers>true</OmitFramePointers>
|
||||||
<BufferSecurityCheck>false</BufferSecurityCheck>
|
<BufferSecurityCheck>false</BufferSecurityCheck>
|
||||||
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
|
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
|
||||||
<SDLCheck>false</SDLCheck>
|
<SDLCheck>
|
||||||
|
</SDLCheck>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<OutputFile>.\release/metamod.dll</OutputFile>
|
<OutputFile>.\release/metamod.dll</OutputFile>
|
||||||
@ -246,7 +247,6 @@
|
|||||||
<ClInclude Include="..\src\sdk_util.h" />
|
<ClInclude Include="..\src\sdk_util.h" />
|
||||||
<ClInclude Include="..\src\studioapi.h" />
|
<ClInclude Include="..\src\studioapi.h" />
|
||||||
<ClInclude Include="..\src\support_meta.h" />
|
<ClInclude Include="..\src\support_meta.h" />
|
||||||
<ClInclude Include="..\src\types_meta.h" />
|
|
||||||
<ClInclude Include="..\src\utils.h" />
|
<ClInclude Include="..\src\utils.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -172,9 +172,6 @@
|
|||||||
<ClInclude Include="..\src\support_meta.h">
|
<ClInclude Include="..\src\support_meta.h">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\src\types_meta.h">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\src\utils.h">
|
<ClInclude Include="..\src\utils.h">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
#define ENGAPI_ENTRY(name, loglevel) API_ENTRY(enginefuncs_t, name, loglevel)
|
#define ENGAPI_ENTRY(name, loglevel) API_ENTRY(enginefuncs_t, name, loglevel)
|
||||||
|
|
||||||
// trace flag, loglevel, name
|
// trace flag, loglevel, name
|
||||||
dllapi_info_t dllapi_info = {
|
dllapi_info_t g_dllapi_info = {
|
||||||
DLLAPI_ENTRY(GameInit, 1), // pfnGameInit
|
DLLAPI_ENTRY(GameInit, 1), // pfnGameInit
|
||||||
DLLAPI_ENTRY(Spawn, 2), // pfnSpawn
|
DLLAPI_ENTRY(Spawn, 2), // pfnSpawn
|
||||||
DLLAPI_ENTRY(Think, 2), // pfnThink
|
DLLAPI_ENTRY(Think, 2), // pfnThink
|
||||||
@ -61,7 +61,7 @@ dllapi_info_t dllapi_info = {
|
|||||||
{ 0, "", 0 },
|
{ 0, "", 0 },
|
||||||
};
|
};
|
||||||
|
|
||||||
newapi_info_t newapi_info = {
|
newapi_info_t g_newapi_info = {
|
||||||
NEWAPI_ENTRY(OnFreeEntPrivateData, 3), // pfnOnFreeEntPrivateData
|
NEWAPI_ENTRY(OnFreeEntPrivateData, 3), // pfnOnFreeEntPrivateData
|
||||||
NEWAPI_ENTRY(GameShutdown, 3), // pfnGameShutdown
|
NEWAPI_ENTRY(GameShutdown, 3), // pfnGameShutdown
|
||||||
NEWAPI_ENTRY(ShouldCollide, 3), // pfnShouldCollide
|
NEWAPI_ENTRY(ShouldCollide, 3), // pfnShouldCollide
|
||||||
@ -71,7 +71,7 @@ newapi_info_t newapi_info = {
|
|||||||
{ 0, "", 0 },
|
{ 0, "", 0 },
|
||||||
};
|
};
|
||||||
|
|
||||||
engine_info_t engine_info = {
|
engine_info_t g_engineapi_info = {
|
||||||
ENGAPI_ENTRY(PrecacheModel, 2), // pfnPrecacheModel
|
ENGAPI_ENTRY(PrecacheModel, 2), // pfnPrecacheModel
|
||||||
ENGAPI_ENTRY(PrecacheSound, 2), // pfnPrecacheSound
|
ENGAPI_ENTRY(PrecacheSound, 2), // pfnPrecacheSound
|
||||||
ENGAPI_ENTRY(SetModel, 2), // pfnSetModel
|
ENGAPI_ENTRY(SetModel, 2), // pfnSetModel
|
||||||
|
@ -253,6 +253,6 @@ struct engine_info_t
|
|||||||
api_info_t END;
|
api_info_t END;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern dllapi_info_t dllapi_info;
|
extern dllapi_info_t g_dllapi_info;
|
||||||
extern newapi_info_t newapi_info;
|
extern newapi_info_t g_newapi_info;
|
||||||
extern engine_info_t engine_info;
|
extern engine_info_t g_engineapi_info;
|
||||||
|
@ -35,8 +35,8 @@ metacmd_t g_meta_cmds[] =
|
|||||||
// Register commands and cvars.
|
// Register commands and cvars.
|
||||||
void meta_register_cmdcvar()
|
void meta_register_cmdcvar()
|
||||||
{
|
{
|
||||||
CVAR_REGISTER(&meta_debug);
|
CVAR_REGISTER(&g_meta_debug);
|
||||||
CVAR_REGISTER(&meta_version);
|
CVAR_REGISTER(&g_meta_version);
|
||||||
REG_SVR_COMMAND("meta", server_meta);
|
REG_SVR_COMMAND("meta", server_meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,11 +183,11 @@ void cmd_meta_game()
|
|||||||
}
|
}
|
||||||
|
|
||||||
META_CONS("GameDLL info:");
|
META_CONS("GameDLL info:");
|
||||||
META_CONS(" name: %s", GameDLL.name);
|
META_CONS(" name: %s", g_GameDLL.name);
|
||||||
META_CONS(" desc: %s", GameDLL.desc);
|
META_CONS(" desc: %s", g_GameDLL.desc);
|
||||||
META_CONS(" gamedir: %s", GameDLL.gamedir);
|
META_CONS(" gamedir: %s", g_GameDLL.gamedir);
|
||||||
META_CONS(" dll file: %s", GameDLL.file);
|
META_CONS(" dll file: %s", g_GameDLL.file);
|
||||||
META_CONS("dll pathname: %s", GameDLL.pathname);
|
META_CONS("dll pathname: %s", g_GameDLL.pathname);
|
||||||
g_regMsgs->show();
|
g_regMsgs->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -267,18 +267,6 @@ void cmd_meta_config()
|
|||||||
g_config->show();
|
g_config->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
// gamedir/filename
|
|
||||||
// gamedir/dlls/filename
|
|
||||||
//
|
|
||||||
// dir/mm_file
|
|
||||||
// dir/file
|
|
||||||
//
|
|
||||||
// path
|
|
||||||
// path_mm
|
|
||||||
// path_MM
|
|
||||||
// path.so, path.dll
|
|
||||||
// path_i386.so, path_i486.so, etc
|
|
||||||
|
|
||||||
// "meta load" console command.
|
// "meta load" console command.
|
||||||
void cmd_meta_load()
|
void cmd_meta_load()
|
||||||
{
|
{
|
||||||
@ -292,12 +280,11 @@ void cmd_meta_load()
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
META_CONS(" name.dll");
|
META_CONS(" name.dll");
|
||||||
META_CONS(" name_mm.dll");
|
META_CONS(" name_mm.dll");
|
||||||
META_CONS(" mm_name.dll");
|
|
||||||
#else
|
#else
|
||||||
META_CONS(" name.so");
|
META_CONS(" name.so");
|
||||||
META_CONS(" name_mm.so");
|
META_CONS(" name_mm.so");
|
||||||
META_CONS(" name_MM.so");
|
META_CONS(" name_mm_i386.so");
|
||||||
META_CONS(" mm_name.so");
|
META_CONS(" ...etc");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
META_CONS(" in a number of directories, including:");
|
META_CONS(" in a number of directories, including:");
|
||||||
@ -339,8 +326,6 @@ void cmd_doplug(PLUG_CMD pcmd)
|
|||||||
|
|
||||||
if (*arg && !*endptr)
|
if (*arg && !*endptr)
|
||||||
findp = g_plugins->find(pindex);
|
findp = g_plugins->find(pindex);
|
||||||
|
|
||||||
// else try to match some string (prefix)
|
|
||||||
else
|
else
|
||||||
findp = g_plugins->find_match(arg, unique);
|
findp = g_plugins->find_match(arg, unique);
|
||||||
|
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "types_meta.h"
|
|
||||||
|
|
||||||
// Flags to use for meta_cmd_doplug(), to operate on existing plugins; note
|
// Flags to use for meta_cmd_doplug(), to operate on existing plugins; note
|
||||||
// "load" operates on a non-existing plugin thus isn't included here.
|
// "load" operates on a non-existing plugin thus isn't included here.
|
||||||
enum PLUG_CMD
|
enum PLUG_CMD
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include "precompiled.h"
|
#include "precompiled.h"
|
||||||
|
|
||||||
MConfig::MConfig() : debuglevel(0), plugins_file(nullptr), exec_cfg(nullptr), list(nullptr), filename(nullptr)
|
MConfig::MConfig() : m_debuglevel(0), m_plugins_file(nullptr), m_exec_cfg(nullptr), m_list(nullptr), m_filename(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -8,14 +8,14 @@ MConfig::MConfig() : debuglevel(0), plugins_file(nullptr), exec_cfg(nullptr), li
|
|||||||
// _after_ constructor, so that all the fields are allocated (d'oh).
|
// _after_ constructor, so that all the fields are allocated (d'oh).
|
||||||
void MConfig::init(option_t* global_options)
|
void MConfig::init(option_t* global_options)
|
||||||
{
|
{
|
||||||
list = global_options;
|
m_list = global_options;
|
||||||
for (auto optp = list; optp->name; optp++)
|
for (auto optp = m_list; optp->name; optp++)
|
||||||
set(optp, optp->init);
|
set(optp, optp->init);
|
||||||
}
|
}
|
||||||
|
|
||||||
option_t *MConfig::find(const char* lookup) const
|
option_t *MConfig::find(const char* lookup) const
|
||||||
{
|
{
|
||||||
for (auto optp = list; optp->name; optp++)
|
for (auto optp = m_list; optp->name; optp++)
|
||||||
{
|
{
|
||||||
if (!strcmp(optp->name, lookup)) {
|
if (!strcmp(optp->name, lookup)) {
|
||||||
return optp;
|
return optp;
|
||||||
@ -145,16 +145,16 @@ bool MConfig::load(const char* fn)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
filename = Q_strdup(loadfile);
|
m_filename = Q_strdup(loadfile);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MConfig::show() const
|
void MConfig::show() const
|
||||||
{
|
{
|
||||||
META_CONS("Config options from localinfo and %s:", filename);
|
META_CONS("Config options from localinfo and %s:", m_filename);
|
||||||
|
|
||||||
for (auto optp = list; optp->name; optp++)
|
for (auto optp = m_list; optp->name; optp++)
|
||||||
{
|
{
|
||||||
int *optval = (int *)optp->dest;
|
int *optval = (int *)optp->dest;
|
||||||
char **optstr = (char **)optp->dest;
|
char **optstr = (char **)optp->dest;
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "types_meta.h"
|
|
||||||
|
|
||||||
// Max length of line in config file.
|
// Max length of line in config file.
|
||||||
#define MAX_CONF_LEN 1024
|
#define MAX_CONF_LEN 1024
|
||||||
|
|
||||||
@ -23,22 +21,23 @@ struct option_t
|
|||||||
char *init; // initial value, as a string, just as config file would
|
char *init; // initial value, as a string, just as config file would
|
||||||
};
|
};
|
||||||
|
|
||||||
class MConfig {
|
class MConfig
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
MConfig();
|
MConfig();
|
||||||
|
|
||||||
int debuglevel; // to use for meta_debug
|
|
||||||
char *plugins_file; // ie metamod.ini, plugins.ini
|
|
||||||
char *exec_cfg; // ie metaexec.cfg, exec.cfg
|
|
||||||
|
|
||||||
void init(option_t *global_options);
|
void init(option_t *global_options);
|
||||||
bool load(const char *filename);
|
bool load(const char *filename);
|
||||||
bool set(const char *key, const char *value) const;
|
bool set(const char *key, const char *value) const;
|
||||||
void show() const;
|
void show() const;
|
||||||
|
|
||||||
|
int m_debuglevel; // to use for meta_debug
|
||||||
|
char *m_plugins_file; // ie metamod.ini, plugins.ini
|
||||||
|
char *m_exec_cfg; // ie metaexec.cfg, exec.cfg
|
||||||
|
|
||||||
private:
|
private:
|
||||||
option_t *list;
|
option_t *m_list;
|
||||||
char *filename;
|
char *m_filename;
|
||||||
|
|
||||||
option_t *find(const char *lookup) const;
|
option_t *find(const char *lookup) const;
|
||||||
static bool set(option_t *setp, const char *value);
|
static bool set(option_t *setp, const char *value);
|
||||||
|
@ -50,7 +50,7 @@ void EXT_FUNC mm_ServerDeactivate(void)
|
|||||||
g_plugins->unpause_all();
|
g_plugins->unpause_all();
|
||||||
// g_plugins->retry_all(PT_CHANGELEVEL);
|
// g_plugins->retry_all(PT_CHANGELEVEL);
|
||||||
g_players.clear_all_cvar_queries();
|
g_players.clear_all_cvar_queries();
|
||||||
requestid_counter = 0;
|
g_requestid_counter = 0;
|
||||||
|
|
||||||
/* RETURN TO ENGINE */
|
/* RETURN TO ENGINE */
|
||||||
}
|
}
|
||||||
@ -221,7 +221,7 @@ void compile_dllfunc_callbacks()
|
|||||||
jitdata.post_table_offset = offsetof(MPlugin, m_dllapi_post_table);
|
jitdata.post_table_offset = offsetof(MPlugin, m_dllapi_post_table);
|
||||||
|
|
||||||
for (auto& cd : g_dllfunc_cdata) {
|
for (auto& cd : g_dllfunc_cdata) {
|
||||||
jitdata.pfn_original = *(size_t *)(size_t(GameDLL.funcs.dllapi_table) + cd.offset);
|
jitdata.pfn_original = *(size_t *)(size_t(g_GameDLL.funcs.dllapi_table) + cd.offset);
|
||||||
jitdata.args_count = cd.args_count;
|
jitdata.args_count = cd.args_count;
|
||||||
jitdata.has_ret = cd.has_ret;
|
jitdata.has_ret = cd.has_ret;
|
||||||
jitdata.has_varargs = cd.has_varargs;
|
jitdata.has_varargs = cd.has_varargs;
|
||||||
@ -242,7 +242,7 @@ void compile_newdllfunc_callbacks()
|
|||||||
jitdata.post_table_offset = offsetof(MPlugin, m_newapi_post_table);
|
jitdata.post_table_offset = offsetof(MPlugin, m_newapi_post_table);
|
||||||
|
|
||||||
for (auto& cd : g_newdllfunc_cdata) {
|
for (auto& cd : g_newdllfunc_cdata) {
|
||||||
jitdata.pfn_original = *(size_t *)(size_t(GameDLL.funcs.newapi_table) + cd.offset);
|
jitdata.pfn_original = *(size_t *)(size_t(g_GameDLL.funcs.newapi_table) + cd.offset);
|
||||||
jitdata.args_count = cd.args_count;
|
jitdata.args_count = cd.args_count;
|
||||||
jitdata.has_ret = cd.has_ret;
|
jitdata.has_ret = cd.has_ret;
|
||||||
jitdata.has_varargs = cd.has_varargs;
|
jitdata.has_varargs = cd.has_varargs;
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
#define CDATA_ENG_H(x, p, h) CDATA_ENTRY(enginefuncs_t, x, p, size_t(h))
|
#define CDATA_ENG_H(x, p, h) CDATA_ENTRY(enginefuncs_t, x, p, size_t(h))
|
||||||
#define CDATA_ENG(x) CDATA_ENTRY(enginefuncs_t, x, P_PRE, 0u)
|
#define CDATA_ENG(x) CDATA_ENTRY(enginefuncs_t, x, P_PRE, 0u)
|
||||||
|
|
||||||
meta_enginefuncs_t meta_engfuncs; // static trampolines to dynamic callbacks (for gamedll)
|
meta_enginefuncs_t g_meta_engfuncs; // static trampolines to dynamic callbacks (for gamedll)
|
||||||
meta_enginefuncs_t meta_engfuncs_jit; // dynamic jit callbacks
|
meta_enginefuncs_t g_meta_engfuncs_jit; // dynamic jit callbacks
|
||||||
|
|
||||||
void MM_PRE_HOOK mm_QueryClientCvarValue(const edict_t* pEdict, const char* cvarName)
|
void MM_PRE_HOOK mm_QueryClientCvarValue(const edict_t* pEdict, const char* cvarName)
|
||||||
{
|
{
|
||||||
@ -253,7 +253,7 @@ void compile_engfuncs_callbacks()
|
|||||||
jitdata.mm_hook_time = cd.mm_hook_time;
|
jitdata.mm_hook_time = cd.mm_hook_time;
|
||||||
jitdata.mm_hook = cd.mm_hook;
|
jitdata.mm_hook = cd.mm_hook;
|
||||||
|
|
||||||
*(size_t *)(size_t(&meta_engfuncs_jit) + cd.offset) = g_jit.compile_callback(&jitdata);
|
*(size_t *)(size_t(&g_meta_engfuncs_jit) + cd.offset) = g_jit.compile_callback(&jitdata);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,7 +261,7 @@ void compile_engine_tramps()
|
|||||||
{
|
{
|
||||||
// we compile simple static functions that will call dynamic callbacks
|
// we compile simple static functions that will call dynamic callbacks
|
||||||
for (auto& cd : g_engfuncs_cdata) {
|
for (auto& cd : g_engfuncs_cdata) {
|
||||||
*(size_t *)(size_t(&meta_engfuncs) + cd.offset) = g_jit.compile_tramp(size_t(&meta_engfuncs_jit) + cd.offset/*, cd.mm_hook, cd.mm_hook_time*/);
|
*(size_t *)(size_t(&g_meta_engfuncs) + cd.offset) = g_jit.compile_tramp(size_t(&g_meta_engfuncs_jit) + cd.offset/*, cd.mm_hook, cd.mm_hook_time*/);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <archtypes.h>
|
struct enginefuncs_s;
|
||||||
|
|
||||||
// Plugin's GetEngineFunctions, called by metamod.
|
// Plugin's GetEngineFunctions, called by metamod.
|
||||||
typedef int (*GET_ENGINE_FUNCTIONS_FN)(enginefuncs_t *pengfuncsFromEngine, int *interfaceVersion);
|
typedef int (*GET_ENGINE_FUNCTIONS_FN)(enginefuncs_s *pengfuncsFromEngine, int *interfaceVersion);
|
||||||
|
|
||||||
// According to SDK engine/eiface.h:
|
// According to SDK engine/eiface.h:
|
||||||
// ONLY ADD NEW FUNCTIONS TO THE END OF THIS STRUCT. INTERFACE VERSION IS FROZEN AT 138
|
// ONLY ADD NEW FUNCTIONS TO THE END OF THIS STRUCT. INTERFACE VERSION IS FROZEN AT 138
|
||||||
@ -13,7 +13,7 @@ typedef int (*GET_ENGINE_FUNCTIONS_FN)(enginefuncs_t *pengfuncsFromEngine, int *
|
|||||||
// normal enginefuncs_t type for their meta_engfuncs.
|
// normal enginefuncs_t type for their meta_engfuncs.
|
||||||
#ifdef METAMOD_CORE
|
#ifdef METAMOD_CORE
|
||||||
#include "meta_eiface.h" // meta_enginefuncs_t
|
#include "meta_eiface.h" // meta_enginefuncs_t
|
||||||
extern meta_enginefuncs_t meta_engfuncs;
|
extern meta_enginefuncs_t g_meta_engfuncs;
|
||||||
#else
|
#else
|
||||||
extern enginefuncs_t meta_engfuncs;
|
extern enginefuncs_t meta_engfuncs;
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "eiface.h" // engfuncs_t, globalvars_t
|
|
||||||
|
|
||||||
// Our structure for storing engine references.
|
// Our structure for storing engine references.
|
||||||
struct engine_t
|
struct engine_t
|
||||||
{
|
{
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
//! this structure contains a list of supported mods and their dlls names
|
//! this structure contains a list of supported mods and their dlls names
|
||||||
//! To add support for another mod add an entry here, and add all the
|
//! To add support for another mod add an entry here, and add all the
|
||||||
//! exported entities to link_func.cpp
|
//! exported entities to link_func.cpp
|
||||||
const game_modinfo_t known_games[] = {
|
const game_modinfo_t g_known_games[] = {
|
||||||
// name/gamedir linux_so win_dll desc
|
// name/gamedir linux_so win_dll desc
|
||||||
//
|
//
|
||||||
// Previously enumerated in this sourcefile, the list is now kept in a
|
// Previously enumerated in this sourcefile, the list is now kept in a
|
||||||
@ -20,7 +20,7 @@ const game_modinfo_t known_games[] = {
|
|||||||
// Find a modinfo corresponding to the given game name.
|
// Find a modinfo corresponding to the given game name.
|
||||||
inline const game_modinfo_t *lookup_game(const char *name)
|
inline const game_modinfo_t *lookup_game(const char *name)
|
||||||
{
|
{
|
||||||
for (auto& known : known_games)
|
for (auto& known : g_known_games)
|
||||||
{
|
{
|
||||||
if (known.name && !Q_stricmp(known.name, name))
|
if (known.name && !Q_stricmp(known.name, name))
|
||||||
return &known;
|
return &known;
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "types_meta.h"
|
|
||||||
#include "metamod.h"
|
#include "metamod.h"
|
||||||
|
|
||||||
// Information we have about each game/mod DLL.
|
// Information we have about each game/mod DLL.
|
||||||
|
@ -14,12 +14,12 @@ void NOINLINE do_link_ent(ENTITY_FN *pfnEntity, int *missing, const char *entStr
|
|||||||
if (!*pfnEntity)
|
if (!*pfnEntity)
|
||||||
{
|
{
|
||||||
META_DEBUG(9, "Looking up game entity '%s'", entStr);
|
META_DEBUG(9, "Looking up game entity '%s'", entStr);
|
||||||
*pfnEntity = (ENTITY_FN)GameDLL.sys_module.getsym(entStr);
|
*pfnEntity = (ENTITY_FN)g_GameDLL.sys_module.getsym(entStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!*pfnEntity)
|
if (!*pfnEntity)
|
||||||
{
|
{
|
||||||
META_ERROR("Couldn't find game entity '%s' in game DLL '%s': %s", entStr, GameDLL.name, CSysModule::getloaderror());
|
META_ERROR("Couldn't find game entity '%s' in game DLL '%s': %s", entStr, g_GameDLL.name, CSysModule::getloaderror());
|
||||||
*missing = 1;
|
*missing = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include "precompiled.h"
|
#include "precompiled.h"
|
||||||
|
|
||||||
cvar_t meta_debug = { "meta_debug", "0", FCVAR_EXTDLL , 0, nullptr };
|
cvar_t g_meta_debug = { "meta_debug", "0", FCVAR_EXTDLL , 0, nullptr };
|
||||||
|
|
||||||
enum MLOG_SERVICE
|
enum MLOG_SERVICE
|
||||||
{
|
{
|
||||||
@ -108,8 +108,8 @@ struct BufferedMessage
|
|||||||
BufferedMessage *next;
|
BufferedMessage *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
static BufferedMessage *messageQueueStart = nullptr;
|
static BufferedMessage *g_messageQueueStart = nullptr;
|
||||||
static BufferedMessage *messageQueueEnd = nullptr;
|
static BufferedMessage *g_messageQueueEnd = nullptr;
|
||||||
|
|
||||||
void buffered_ALERT(MLOG_SERVICE service, ALERT_TYPE atype, const char *prefix, const char *fmt, va_list ap)
|
void buffered_ALERT(MLOG_SERVICE service, ALERT_TYPE atype, const char *prefix, const char *fmt, va_list ap)
|
||||||
{
|
{
|
||||||
@ -136,14 +136,14 @@ void buffered_ALERT(MLOG_SERVICE service, ALERT_TYPE atype, const char *prefix,
|
|||||||
Q_vsnprintf(msg->buf, sizeof buf, fmt, ap);
|
Q_vsnprintf(msg->buf, sizeof buf, fmt, ap);
|
||||||
msg->next = nullptr;
|
msg->next = nullptr;
|
||||||
|
|
||||||
if (!messageQueueEnd)
|
if (!g_messageQueueEnd)
|
||||||
{
|
{
|
||||||
messageQueueStart = messageQueueEnd = msg;
|
g_messageQueueStart = g_messageQueueEnd = msg;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
messageQueueEnd->next = msg;
|
g_messageQueueEnd->next = msg;
|
||||||
messageQueueEnd = msg;
|
g_messageQueueEnd = msg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,7 +153,7 @@ void buffered_ALERT(MLOG_SERVICE service, ALERT_TYPE atype, const char *prefix,
|
|||||||
// jumptable is set. Don't call it if it isn't set.
|
// jumptable is set. Don't call it if it isn't set.
|
||||||
void flush_ALERT_buffer(void)
|
void flush_ALERT_buffer(void)
|
||||||
{
|
{
|
||||||
BufferedMessage *msg = messageQueueStart;
|
BufferedMessage *msg = g_messageQueueStart;
|
||||||
int dev = (int)CVAR_GET_FLOAT("developer");
|
int dev = (int)CVAR_GET_FLOAT("developer");
|
||||||
|
|
||||||
while (msg)
|
while (msg)
|
||||||
@ -166,10 +166,10 @@ void flush_ALERT_buffer(void)
|
|||||||
ALERT(msg->atype, "b>%s %s\n", msg->prefix, msg->buf);
|
ALERT(msg->atype, "b>%s %s\n", msg->prefix, msg->buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
messageQueueStart = messageQueueStart->next;
|
g_messageQueueStart = g_messageQueueStart->next;
|
||||||
delete msg;
|
delete msg;
|
||||||
msg = messageQueueStart;
|
msg = g_messageQueueStart;
|
||||||
}
|
}
|
||||||
|
|
||||||
messageQueueStart = messageQueueEnd = nullptr;
|
g_messageQueueStart = g_messageQueueEnd = nullptr;
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,17 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "enginecallbacks.h" // ALERT, etc
|
|
||||||
|
|
||||||
// max buffer size for printed messages
|
// max buffer size for printed messages
|
||||||
#define MAX_LOGMSG_LEN 1024
|
#define MAX_LOGMSG_LEN 1024
|
||||||
|
|
||||||
// max buffer size for client messages
|
// max buffer size for client messages
|
||||||
#define MAX_CLIENTMSG_LEN 128
|
#define MAX_CLIENTMSG_LEN 128
|
||||||
|
|
||||||
extern cvar_t meta_debug;
|
extern cvar_t g_meta_debug;
|
||||||
|
|
||||||
template<typename ...t_args>
|
template<typename ...t_args>
|
||||||
void META_DEBUG(int level, const char* fmt, t_args... args)
|
void META_DEBUG(int level, const char* fmt, t_args... args)
|
||||||
{
|
{
|
||||||
if (unlikely(meta_debug.value >= level))
|
if (unlikely(g_meta_debug.value >= level))
|
||||||
META_DEBUG_(level, fmt, args...);
|
META_DEBUG_(level, fmt, args...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,26 +5,11 @@ void meta_new_dll_functions_t::set_from(NEW_DLL_FUNCTIONS* _pFuncs)
|
|||||||
Q_memcpy(this, _pFuncs, sizeof(NEW_DLL_FUNCTIONS));
|
Q_memcpy(this, _pFuncs, sizeof(NEW_DLL_FUNCTIONS));
|
||||||
}
|
}
|
||||||
|
|
||||||
void meta_new_dll_functions_t::copy_to(NEW_DLL_FUNCTIONS *_pFuncs) const
|
|
||||||
{
|
|
||||||
#if 0
|
|
||||||
// TODO: Implement regamedll check
|
|
||||||
// exit
|
|
||||||
|
|
||||||
#endif
|
|
||||||
Q_memcpy(_pFuncs, this, sizeof(NEW_DLL_FUNCTIONS));
|
|
||||||
}
|
|
||||||
|
|
||||||
void meta_enginefuncs_t::set_from(enginefuncs_t* _pFuncs)
|
void meta_enginefuncs_t::set_from(enginefuncs_t* _pFuncs)
|
||||||
{
|
{
|
||||||
Q_memcpy(this, _pFuncs, sizeof(enginefuncs_t));
|
Q_memcpy(this, _pFuncs, sizeof(enginefuncs_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
void meta_enginefuncs_t::copy_to(enginefuncs_t* _pFuncs) const
|
|
||||||
{
|
|
||||||
Q_memcpy(_pFuncs, this, sizeof(enginefuncs_t));
|
|
||||||
}
|
|
||||||
|
|
||||||
void HL_enginefuncs_t::initialise_interface(enginefuncs_t* _pFuncs)
|
void HL_enginefuncs_t::initialise_interface(enginefuncs_t* _pFuncs)
|
||||||
{
|
{
|
||||||
set_from(_pFuncs);
|
set_from(_pFuncs);
|
||||||
|
@ -12,9 +12,6 @@ struct meta_new_dll_functions_t: public NEW_DLL_FUNCTIONS
|
|||||||
{
|
{
|
||||||
// Fill this object with pointers copied from a NEW_DLL_FUNCTIONS struct.
|
// Fill this object with pointers copied from a NEW_DLL_FUNCTIONS struct.
|
||||||
void set_from(NEW_DLL_FUNCTIONS* pFuncs);
|
void set_from(NEW_DLL_FUNCTIONS* pFuncs);
|
||||||
|
|
||||||
// Copy the pointers from this object to a NEW_DLL_FUNCTIONS struct.
|
|
||||||
void copy_to(NEW_DLL_FUNCTIONS* pFuncs) const;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// meta_enginefuncs_t
|
// meta_enginefuncs_t
|
||||||
@ -22,9 +19,6 @@ struct meta_enginefuncs_t : public enginefuncs_t
|
|||||||
{
|
{
|
||||||
// Fill this object with pointers copied from an enginefuncs_t struct.
|
// Fill this object with pointers copied from an enginefuncs_t struct.
|
||||||
void set_from(enginefuncs_t* pFuncs);
|
void set_from(enginefuncs_t* pFuncs);
|
||||||
|
|
||||||
// Copy the pointers from this object to an enginefuncs_t struct.
|
|
||||||
void copy_to(enginefuncs_t* pFuncs) const;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// This is a specialisation of the meta_enginefuncs_t struct which is only
|
// This is a specialisation of the meta_enginefuncs_t struct which is only
|
||||||
@ -48,9 +42,4 @@ private:
|
|||||||
{
|
{
|
||||||
meta_enginefuncs_t::set_from(pFuncs);
|
meta_enginefuncs_t::set_from(pFuncs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void copy_to(enginefuncs_t* pFuncs)
|
|
||||||
{
|
|
||||||
meta_enginefuncs_t::copy_to(pFuncs);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
#include "precompiled.h"
|
#include "precompiled.h"
|
||||||
|
|
||||||
cvar_t meta_version = { "metamod_version", APP_VERSION_STRD, FCVAR_SERVER, 0, nullptr };
|
cvar_t g_meta_version = { "metamod_version", APP_VERSION_STRD, FCVAR_SERVER, 0, nullptr };
|
||||||
|
|
||||||
MConfig static_config;
|
MConfig g_static_config;
|
||||||
MConfig *g_config = &static_config;
|
MConfig *g_config = &g_static_config;
|
||||||
option_t global_options[] =
|
option_t g_global_options[] =
|
||||||
{
|
{
|
||||||
{ "debuglevel", CF_INT, &g_config->debuglevel, "0" },
|
{ "debuglevel", CF_INT, &g_config->m_debuglevel, "0" },
|
||||||
{ "plugins_file", CF_PATH, &g_config->plugins_file, PLUGINS_INI },
|
{ "plugins_file", CF_PATH, &g_config->m_plugins_file, PLUGINS_INI },
|
||||||
{ "exec_cfg", CF_STR, &g_config->exec_cfg, EXEC_CFG },
|
{ "exec_cfg", CF_STR, &g_config->m_exec_cfg, EXEC_CFG },
|
||||||
|
|
||||||
// list terminator
|
// list terminator
|
||||||
{ NULL, CF_NONE, NULL, NULL }
|
{ NULL, CF_NONE, NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
gamedll_t GameDLL;
|
gamedll_t g_GameDLL;
|
||||||
|
|
||||||
meta_globals_t g_metaGlobals;
|
meta_globals_t g_metaGlobals;
|
||||||
|
|
||||||
@ -27,9 +27,9 @@ MRegMsgList *g_regMsgs;
|
|||||||
|
|
||||||
MPlayerList g_players;
|
MPlayerList g_players;
|
||||||
|
|
||||||
unsigned int CALL_API_count = 0;
|
unsigned int g_CALL_API_count = 0;
|
||||||
|
|
||||||
int requestid_counter = 0;
|
int g_requestid_counter = 0;
|
||||||
|
|
||||||
// Very first metamod function that's run.
|
// Very first metamod function that's run.
|
||||||
// Do startup operations...
|
// Do startup operations...
|
||||||
@ -65,11 +65,11 @@ void metamod_startup()
|
|||||||
|
|
||||||
// Set a slight debug level for developer mode, if debug level not
|
// Set a slight debug level for developer mode, if debug level not
|
||||||
// already set.
|
// already set.
|
||||||
if ((int) CVAR_GET_FLOAT("developer") != 0 && meta_debug.value == 0)
|
if ((int) CVAR_GET_FLOAT("developer") != 0 && g_meta_debug.value == 0)
|
||||||
CVAR_SET_FLOAT("meta_debug", 3.0);
|
CVAR_SET_FLOAT("meta_debug", 3.0);
|
||||||
|
|
||||||
// Init default values
|
// Init default values
|
||||||
g_config->init(global_options);
|
g_config->init(g_global_options);
|
||||||
|
|
||||||
// Find config file
|
// Find config file
|
||||||
cfile = CONFIG_INI;
|
cfile = CONFIG_INI;
|
||||||
@ -111,8 +111,8 @@ void metamod_startup()
|
|||||||
|
|
||||||
// Check for an initial debug level, since cfg files don't get exec'd
|
// Check for an initial debug level, since cfg files don't get exec'd
|
||||||
// until later.
|
// until later.
|
||||||
if (g_config->debuglevel != 0)
|
if (g_config->m_debuglevel != 0)
|
||||||
CVAR_SET_FLOAT("meta_debug", g_config->debuglevel);
|
CVAR_SET_FLOAT("meta_debug", g_config->m_debuglevel);
|
||||||
|
|
||||||
// Prepare for registered commands from plugins.
|
// Prepare for registered commands from plugins.
|
||||||
g_regCmds = new MRegCmdList();
|
g_regCmds = new MRegCmdList();
|
||||||
@ -162,10 +162,10 @@ void metamod_startup()
|
|||||||
|
|
||||||
if (!valid_gamedir_file(PLUGINS_INI) && valid_gamedir_file(OLD_PLUGINS_INI))
|
if (!valid_gamedir_file(PLUGINS_INI) && valid_gamedir_file(OLD_PLUGINS_INI))
|
||||||
mmfile = OLD_PLUGINS_INI;
|
mmfile = OLD_PLUGINS_INI;
|
||||||
if (valid_gamedir_file(g_config->plugins_file))
|
if (valid_gamedir_file(g_config->m_plugins_file))
|
||||||
mmfile = g_config->plugins_file;
|
mmfile = g_config->m_plugins_file;
|
||||||
else
|
else
|
||||||
META_ERROR("g_plugins file is empty/missing: %s; falling back to %s", g_config->plugins_file, mmfile);
|
META_ERROR("g_plugins file is empty/missing: %s; falling back to %s", g_config->m_plugins_file, mmfile);
|
||||||
|
|
||||||
g_plugins = new MPluginList(mmfile);
|
g_plugins = new MPluginList(mmfile);
|
||||||
|
|
||||||
@ -189,8 +189,8 @@ void metamod_startup()
|
|||||||
// Only attempt load if the file appears to exist and be non-empty, to
|
// Only attempt load if the file appears to exist and be non-empty, to
|
||||||
// avoid confusing users with "couldn't exec exec.cfg" console
|
// avoid confusing users with "couldn't exec exec.cfg" console
|
||||||
// messages.
|
// messages.
|
||||||
if (valid_gamedir_file(g_config->exec_cfg))
|
if (valid_gamedir_file(g_config->m_exec_cfg))
|
||||||
mmfile = g_config->exec_cfg;
|
mmfile = g_config->m_exec_cfg;
|
||||||
|
|
||||||
else if (valid_gamedir_file(OLD_EXEC_CFG))
|
else if (valid_gamedir_file(OLD_EXEC_CFG))
|
||||||
mmfile = OLD_EXEC_CFG;
|
mmfile = OLD_EXEC_CFG;
|
||||||
@ -219,7 +219,7 @@ bool meta_init_gamedll(void)
|
|||||||
char gamedir[PATH_MAX];
|
char gamedir[PATH_MAX];
|
||||||
char *cp;
|
char *cp;
|
||||||
|
|
||||||
Q_memset(&GameDLL, 0, sizeof(GameDLL));
|
Q_memset(&g_GameDLL, 0, sizeof(g_GameDLL));
|
||||||
|
|
||||||
GET_GAME_DIR(gamedir);
|
GET_GAME_DIR(gamedir);
|
||||||
normalize_pathname(gamedir);
|
normalize_pathname(gamedir);
|
||||||
@ -239,13 +239,13 @@ bool meta_init_gamedll(void)
|
|||||||
// Old style; GET_GAME_DIR returned full pathname. Copy this into
|
// Old style; GET_GAME_DIR returned full pathname. Copy this into
|
||||||
// our gamedir, and truncate to get the game name.
|
// our gamedir, and truncate to get the game name.
|
||||||
// (note check for both linux and win32 full pathname.)
|
// (note check for both linux and win32 full pathname.)
|
||||||
Q_strncpy(GameDLL.gamedir, gamedir, sizeof GameDLL.gamedir - 1);
|
Q_strncpy(g_GameDLL.gamedir, gamedir, sizeof g_GameDLL.gamedir - 1);
|
||||||
GameDLL.gamedir[sizeof GameDLL.gamedir - 1] = '\0';
|
g_GameDLL.gamedir[sizeof g_GameDLL.gamedir - 1] = '\0';
|
||||||
|
|
||||||
cp = Q_strrchr(gamedir, '/') + 1;
|
cp = Q_strrchr(gamedir, '/') + 1;
|
||||||
|
|
||||||
Q_strncpy(GameDLL.name, cp, sizeof GameDLL.name - 1);
|
Q_strncpy(g_GameDLL.name, cp, sizeof g_GameDLL.name - 1);
|
||||||
GameDLL.name[sizeof GameDLL.name - 1] = '\0';
|
g_GameDLL.name[sizeof g_GameDLL.name - 1] = '\0';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -258,12 +258,12 @@ bool meta_init_gamedll(void)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_snprintf(GameDLL.gamedir, sizeof GameDLL.gamedir, "%s/%s", buf, gamedir);
|
Q_snprintf(g_GameDLL.gamedir, sizeof g_GameDLL.gamedir, "%s/%s", buf, gamedir);
|
||||||
Q_strncpy(GameDLL.name, gamedir, sizeof GameDLL.name - 1);
|
Q_strncpy(g_GameDLL.name, gamedir, sizeof g_GameDLL.name - 1);
|
||||||
GameDLL.name[sizeof(GameDLL.name) - 1] = '\0';
|
g_GameDLL.name[sizeof(g_GameDLL.name) - 1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
META_DEBUG(3, "Game: %s", GameDLL.name);
|
META_DEBUG(3, "Game: %s", g_GameDLL.name);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,7 +272,7 @@ bool get_function_table(const char* ifname, int ifvers_mm, table_t*& table, size
|
|||||||
{
|
{
|
||||||
typedef int(*getfunc_t)(table_t *pFunctionTable, ifvers_t interfaceVersion);
|
typedef int(*getfunc_t)(table_t *pFunctionTable, ifvers_t interfaceVersion);
|
||||||
|
|
||||||
auto pfnGetFuncs = (getfunc_t)GameDLL.sys_module.getsym(ifname);
|
auto pfnGetFuncs = (getfunc_t)g_GameDLL.sys_module.getsym(ifname);
|
||||||
|
|
||||||
if (pfnGetFuncs) {
|
if (pfnGetFuncs) {
|
||||||
table = (table_t *)Q_calloc(1, table_size);
|
table = (table_t *)Q_calloc(1, table_size);
|
||||||
@ -280,11 +280,11 @@ bool get_function_table(const char* ifname, int ifvers_mm, table_t*& table, size
|
|||||||
int ifvers_gamedll = ifvers_mm;
|
int ifvers_gamedll = ifvers_mm;
|
||||||
|
|
||||||
if (pfnGetFuncs(table, ifvers_gamedll)) {
|
if (pfnGetFuncs(table, ifvers_gamedll)) {
|
||||||
META_DEBUG(3, "dll: Game '%s': Found %s", GameDLL.name, ifname);
|
META_DEBUG(3, "dll: Game '%s': Found %s", g_GameDLL.name, ifname);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
META_ERROR("dll: Failure calling %s in game '%s'", ifname, GameDLL.name);
|
META_ERROR("dll: Failure calling %s in game '%s'", ifname, g_GameDLL.name);
|
||||||
Q_free(table);
|
Q_free(table);
|
||||||
table = nullptr;
|
table = nullptr;
|
||||||
|
|
||||||
@ -296,13 +296,13 @@ bool get_function_table(const char* ifname, int ifvers_mm, table_t*& table, size
|
|||||||
if (ifvers_gamedll > ifvers_mm)
|
if (ifvers_gamedll > ifvers_mm)
|
||||||
META_CONS("g_engine appears to be outdated, check for updates");
|
META_CONS("g_engine appears to be outdated, check for updates");
|
||||||
else
|
else
|
||||||
META_CONS("The game DLL for %s appears to be outdated, check for updates", GameDLL.name);
|
META_CONS("The game DLL for %s appears to be outdated, check for updates", g_GameDLL.name);
|
||||||
META_CONS("==================");
|
META_CONS("==================");
|
||||||
ALERT(at_error, "Exiting...\n");
|
ALERT(at_error, "Exiting...\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
META_DEBUG(5, "dll: Game '%s': No %s", GameDLL.name, ifname);
|
META_DEBUG(5, "dll: Game '%s': No %s", g_GameDLL.name, ifname);
|
||||||
table = nullptr;
|
table = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -314,22 +314,22 @@ bool get_function_table_old(const char* ifname, int ifvers_mm, table_t*& table,
|
|||||||
{
|
{
|
||||||
typedef int (*getfunc_t)(table_t *pFunctionTable, int interfaceVersion);
|
typedef int (*getfunc_t)(table_t *pFunctionTable, int interfaceVersion);
|
||||||
|
|
||||||
auto pfnGetFuncs = (getfunc_t)GameDLL.sys_module.getsym(ifname);
|
auto pfnGetFuncs = (getfunc_t)g_GameDLL.sys_module.getsym(ifname);
|
||||||
|
|
||||||
if (pfnGetFuncs) {
|
if (pfnGetFuncs) {
|
||||||
table = (table_t *)Q_calloc(1, table_size);
|
table = (table_t *)Q_calloc(1, table_size);
|
||||||
|
|
||||||
if (pfnGetFuncs(table, ifvers_mm)) {
|
if (pfnGetFuncs(table, ifvers_mm)) {
|
||||||
META_DEBUG(3, "dll: Game '%s': Found %s", GameDLL.name, ifname);
|
META_DEBUG(3, "dll: Game '%s': Found %s", g_GameDLL.name, ifname);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
META_ERROR("dll: Failure calling %s in game '%s'", ifname, GameDLL.name);
|
META_ERROR("dll: Failure calling %s in game '%s'", ifname, g_GameDLL.name);
|
||||||
Q_free(table);
|
Q_free(table);
|
||||||
table = nullptr;
|
table = nullptr;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
META_DEBUG(5, "dll: Game '%s': No %s", GameDLL.name, ifname);
|
META_DEBUG(5, "dll: Game '%s': No %s", g_GameDLL.name, ifname);
|
||||||
table = nullptr;
|
table = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -343,17 +343,17 @@ bool get_function_table_old(const char* ifname, int ifvers_mm, table_t*& table,
|
|||||||
// (GiveFnptrsToDll, GetEntityAPI, GetEntityAPI2)
|
// (GiveFnptrsToDll, GetEntityAPI, GetEntityAPI2)
|
||||||
bool meta_load_gamedll(void)
|
bool meta_load_gamedll(void)
|
||||||
{
|
{
|
||||||
if (!setup_gamedll(&GameDLL))
|
if (!setup_gamedll(&g_GameDLL))
|
||||||
{
|
{
|
||||||
META_ERROR("dll: Unrecognized game: %s", GameDLL.name);
|
META_ERROR("dll: Unrecognized game: %s", g_GameDLL.name);
|
||||||
// meta_errno should be already set in lookup_game()
|
// meta_errno should be already set in lookup_game()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// open the game DLL
|
// open the game DLL
|
||||||
if (!GameDLL.sys_module.load(GameDLL.pathname))
|
if (!g_GameDLL.sys_module.load(g_GameDLL.pathname))
|
||||||
{
|
{
|
||||||
META_ERROR("dll: Couldn't load game DLL %s: %s", GameDLL.pathname, CSysModule::getloaderror());
|
META_ERROR("dll: Couldn't load game DLL %s: %s", g_GameDLL.pathname, CSysModule::getloaderror());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -364,41 +364,41 @@ bool meta_load_gamedll(void)
|
|||||||
// wanted to catch one of the functions, but now that plugins are
|
// wanted to catch one of the functions, but now that plugins are
|
||||||
// dynamically loadable at any time, we have to always pass our table,
|
// dynamically loadable at any time, we have to always pass our table,
|
||||||
// so that any plugin loaded later can catch what they need to.
|
// so that any plugin loaded later can catch what they need to.
|
||||||
auto pfn_give_engfuncs = (GIVE_ENGINE_FUNCTIONS_FN)GameDLL.sys_module.getsym("GiveFnptrsToDll");
|
auto pfn_give_engfuncs = (GIVE_ENGINE_FUNCTIONS_FN)g_GameDLL.sys_module.getsym("GiveFnptrsToDll");
|
||||||
|
|
||||||
if (pfn_give_engfuncs)
|
if (pfn_give_engfuncs)
|
||||||
{
|
{
|
||||||
pfn_give_engfuncs(&meta_engfuncs, gpGlobals);
|
pfn_give_engfuncs(&g_meta_engfuncs, gpGlobals);
|
||||||
META_DEBUG(3, "dll: Game '%s': Called GiveFnptrsToDll", GameDLL.name);
|
META_DEBUG(3, "dll: Game '%s': Called GiveFnptrsToDll", g_GameDLL.name);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
META_ERROR("dll: Couldn't find GiveFnptrsToDll() in game DLL '%s'", GameDLL.name);
|
META_ERROR("dll: Couldn't find GiveFnptrsToDll() in game DLL '%s'", g_GameDLL.name);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Look for API-NEW interface in Game dll. We do this before API2/API, because
|
// Look for API-NEW interface in Game dll. We do this before API2/API, because
|
||||||
// that's what the engine appears to do..
|
// that's what the engine appears to do..
|
||||||
get_function_table<int&>("GetNewDLLFunctions", NEW_DLL_FUNCTIONS_VERSION, GameDLL.funcs.newapi_table);
|
get_function_table<int&>("GetNewDLLFunctions", NEW_DLL_FUNCTIONS_VERSION, g_GameDLL.funcs.newapi_table);
|
||||||
|
|
||||||
// Look for API2 interface in plugin; preferred over API-1.
|
// Look for API2 interface in plugin; preferred over API-1.
|
||||||
bool found = get_function_table<int&>("GetEntityAPI2", INTERFACE_VERSION, GameDLL.funcs.dllapi_table);
|
bool found = get_function_table<int&>("GetEntityAPI2", INTERFACE_VERSION, g_GameDLL.funcs.dllapi_table);
|
||||||
|
|
||||||
// Look for API-1 in plugin, if API2 interface wasn't found.
|
// Look for API-1 in plugin, if API2 interface wasn't found.
|
||||||
if (!found) {
|
if (!found) {
|
||||||
found = get_function_table_old("GetEntityAPI", INTERFACE_VERSION, GameDLL.funcs.dllapi_table);
|
found = get_function_table_old("GetEntityAPI", INTERFACE_VERSION, g_GameDLL.funcs.dllapi_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If didn't find either, return failure.
|
// If didn't find either, return failure.
|
||||||
if (!found) {
|
if (!found) {
|
||||||
META_ERROR("dll: Couldn't find either GetEntityAPI nor GetEntityAPI2 in game DLL '%s'", GameDLL.name);
|
META_ERROR("dll: Couldn't find either GetEntityAPI nor GetEntityAPI2 in game DLL '%s'", g_GameDLL.name);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// prepare gamedll callbacks
|
// prepare gamedll callbacks
|
||||||
compile_gamedll_callbacks();
|
compile_gamedll_callbacks();
|
||||||
|
|
||||||
META_LOG("Game DLL for '%s' loaded successfully", GameDLL.desc);
|
META_LOG("Game DLL for '%s' loaded successfully", g_GameDLL.desc);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
#include "mreg.h" // MRegCmdList, etc
|
#include "mreg.h" // MRegCmdList, etc
|
||||||
#include "conf_meta.h" // MConfig
|
#include "conf_meta.h" // MConfig
|
||||||
#include "osdep.h" // NAME_MAX, etc
|
#include "osdep.h" // NAME_MAX, etc
|
||||||
#include "types_meta.h" // bool
|
|
||||||
#include "mplayer.h" // MPlayerList
|
#include "mplayer.h" // MPlayerList
|
||||||
#include "meta_eiface.h" // HL_enginefuncs_t, meta_enginefuncs_t
|
#include "meta_eiface.h" // HL_enginefuncs_t, meta_enginefuncs_t
|
||||||
#include "engine_t.h" // engine_t, Engine
|
#include "engine_t.h" // engine_t, Engine
|
||||||
@ -25,7 +24,7 @@
|
|||||||
#define CONFIG_INI "addons/metamod/config.ini"
|
#define CONFIG_INI "addons/metamod/config.ini"
|
||||||
|
|
||||||
// cvar to contain version
|
// cvar to contain version
|
||||||
extern cvar_t meta_version;
|
extern cvar_t g_meta_version;
|
||||||
|
|
||||||
// Info about the game dll/mod.
|
// Info about the game dll/mod.
|
||||||
struct gamedll_t
|
struct gamedll_t
|
||||||
@ -40,7 +39,7 @@ struct gamedll_t
|
|||||||
gamedll_funcs_t funcs; // dllapi_table, newapi_table
|
gamedll_funcs_t funcs; // dllapi_table, newapi_table
|
||||||
};
|
};
|
||||||
|
|
||||||
extern gamedll_t GameDLL;
|
extern gamedll_t g_GameDLL;
|
||||||
|
|
||||||
// SDK variables for storing engine funcs and globals.
|
// SDK variables for storing engine funcs and globals.
|
||||||
extern HL_enginefuncs_t g_engfuncs;
|
extern HL_enginefuncs_t g_engfuncs;
|
||||||
@ -85,10 +84,10 @@ extern NEW_DLL_FUNCTIONS *pHookedNewDllFunctions;
|
|||||||
// metamod assumed that g_metaGlobals is free to be used.
|
// metamod assumed that g_metaGlobals is free to be used.
|
||||||
// With call_count we can fix this by backuping up g_metaGlobals if
|
// With call_count we can fix this by backuping up g_metaGlobals if
|
||||||
// it's already being used.
|
// it's already being used.
|
||||||
extern unsigned int CALL_API_count;
|
extern unsigned int g_CALL_API_count;
|
||||||
|
|
||||||
// stores previous requestid counter
|
// stores previous requestid counter
|
||||||
extern int requestid_counter;
|
extern int g_requestid_counter;
|
||||||
|
|
||||||
// (patch by BAILOPAN)
|
// (patch by BAILOPAN)
|
||||||
// Holds cached player info, right now only things for querying cvars
|
// Holds cached player info, right now only things for querying cvars
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "types_meta.h" // bool
|
|
||||||
#include "mplugin.h" // class MPlugin
|
#include "mplugin.h" // class MPlugin
|
||||||
#include "plinfo.h" // plid_t, etc
|
#include "plinfo.h" // plid_t, etc
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include "precompiled.h"
|
#include "precompiled.h"
|
||||||
|
|
||||||
MPlayer::MPlayer() : isQueried(false)
|
MPlayer::MPlayer() : m_isQueried(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -17,16 +17,16 @@ void MPlayer::set_cvar_query(const char *cvar)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
isQueried = true;
|
m_isQueried = true;
|
||||||
Q_strncpy(cvarName, cvar, sizeof cvarName - 1);
|
Q_strncpy(g_cvarName, cvar, sizeof g_cvarName - 1);
|
||||||
cvarName[sizeof cvarName - 1] = '\0';
|
g_cvarName[sizeof g_cvarName - 1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unmark player as querying a client cvar
|
// Unmark player as querying a client cvar
|
||||||
void MPlayer::clear_cvar_query(const char *cvar)
|
void MPlayer::clear_cvar_query(const char *cvar)
|
||||||
{
|
{
|
||||||
isQueried = false;
|
m_isQueried = false;
|
||||||
cvarName[0] = '\0';
|
g_cvarName[0] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if a client cvar is queried for this player
|
// Check if a client cvar is queried for this player
|
||||||
@ -34,9 +34,9 @@ void MPlayer::clear_cvar_query(const char *cvar)
|
|||||||
// or the name of the cvar.
|
// or the name of the cvar.
|
||||||
const char *MPlayer::is_querying_cvar(void) const
|
const char *MPlayer::is_querying_cvar(void) const
|
||||||
{
|
{
|
||||||
if (isQueried)
|
if (m_isQueried)
|
||||||
{
|
{
|
||||||
return cvarName;
|
return g_cvarName;
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -49,7 +49,7 @@ void MPlayerList::set_player_cvar_query(const edict_t *pEntity, const char *cvar
|
|||||||
{
|
{
|
||||||
int indx = ENTINDEX(pEntity);
|
int indx = ENTINDEX(pEntity);
|
||||||
if (indx >= 1 && indx <= gpGlobals->maxClients)
|
if (indx >= 1 && indx <= gpGlobals->maxClients)
|
||||||
players[indx].set_cvar_query(cvar);
|
m_players[indx].set_cvar_query(cvar);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unmark player as querying a client cvar
|
// Unmark player as querying a client cvar
|
||||||
@ -57,14 +57,14 @@ void MPlayerList::clear_player_cvar_query(const edict_t *pEntity, const char *cv
|
|||||||
{
|
{
|
||||||
int indx = ENTINDEX(pEntity);
|
int indx = ENTINDEX(pEntity);
|
||||||
if (indx >= 1 && indx <= gpGlobals->maxClients)
|
if (indx >= 1 && indx <= gpGlobals->maxClients)
|
||||||
players[indx].clear_cvar_query(cvar);
|
m_players[indx].clear_cvar_query(cvar);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPlayerList::clear_all_cvar_queries(void)
|
void MPlayerList::clear_all_cvar_queries(void)
|
||||||
{
|
{
|
||||||
for (int indx = 1; indx <= gpGlobals->maxClients; indx++)
|
for (int indx = 1; indx <= gpGlobals->maxClients; indx++)
|
||||||
{
|
{
|
||||||
players[indx].clear_cvar_query();
|
m_players[indx].clear_cvar_query();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ const char *MPlayerList::is_querying_cvar(const edict_t *pEntity) const
|
|||||||
{
|
{
|
||||||
int indx = ENTINDEX(pEntity);
|
int indx = ENTINDEX(pEntity);
|
||||||
if (indx >= 1 && indx <= gpGlobals->maxClients)
|
if (indx >= 1 && indx <= gpGlobals->maxClients)
|
||||||
return players[indx].is_querying_cvar();
|
return m_players[indx].is_querying_cvar();
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "types_meta.h"
|
|
||||||
|
|
||||||
// Info on an individual player
|
// Info on an individual player
|
||||||
class MPlayer
|
class MPlayer
|
||||||
{
|
{
|
||||||
@ -13,8 +11,8 @@ public:
|
|||||||
const char *is_querying_cvar() const; // check if a player is querying a cvar. returns
|
const char *is_querying_cvar() const; // check if a player is querying a cvar. returns
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool isQueried; // is this player currently queried for a cvar value
|
bool m_isQueried; // is this player currently queried for a cvar value
|
||||||
char cvarName[64]; // name of the cvar if getting queried
|
char g_cvarName[64]; // name of the cvar if getting queried
|
||||||
};
|
};
|
||||||
|
|
||||||
// A list of players. The number of max players is fixed and small enough
|
// A list of players. The number of max players is fixed and small enough
|
||||||
@ -28,6 +26,6 @@ public:
|
|||||||
const char *is_querying_cvar(const edict_t *pEntity) const;
|
const char *is_querying_cvar(const edict_t *pEntity) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int maxplayers = 32;
|
int m_maxplayers = 32;
|
||||||
MPlayer players[MAX_CLIENTS + 1]; // array of players
|
MPlayer m_players[MAX_CLIENTS + 1]; // array of players
|
||||||
};
|
};
|
||||||
|
@ -281,9 +281,9 @@ bool MPlugin::resolve(void)
|
|||||||
m_file = m_pathname;
|
m_file = m_pathname;
|
||||||
|
|
||||||
// store pathname: the gamedir relative path, or an absolute path
|
// store pathname: the gamedir relative path, or an absolute path
|
||||||
size_t len = Q_strlen(GameDLL.gamedir);
|
size_t len = Q_strlen(g_GameDLL.gamedir);
|
||||||
|
|
||||||
if (!Q_strnicmp(m_pathname, GameDLL.gamedir, len))
|
if (!Q_strnicmp(m_pathname, g_GameDLL.gamedir, len))
|
||||||
{
|
{
|
||||||
Q_strncpy(m_filename, m_pathname + len + 1, sizeof m_filename - 1);
|
Q_strncpy(m_filename, m_pathname + len + 1, sizeof m_filename - 1);
|
||||||
m_filename[sizeof m_filename - 1] = '\0';
|
m_filename[sizeof m_filename - 1] = '\0';
|
||||||
@ -306,7 +306,7 @@ char *MPlugin::resolve_dirs(char *path) const
|
|||||||
{
|
{
|
||||||
static char buf[PATH_MAX ];
|
static char buf[PATH_MAX ];
|
||||||
|
|
||||||
Q_snprintf(buf, sizeof buf, "%s/%s", GameDLL.gamedir, path);
|
Q_snprintf(buf, sizeof buf, "%s/%s", g_GameDLL.gamedir, path);
|
||||||
|
|
||||||
// try this path
|
// try this path
|
||||||
struct stat st;
|
struct stat st;
|
||||||
@ -318,7 +318,7 @@ char *MPlugin::resolve_dirs(char *path) const
|
|||||||
if (found)
|
if (found)
|
||||||
return found;
|
return found;
|
||||||
|
|
||||||
Q_snprintf(buf, sizeof buf, "%s/dlls/%s", GameDLL.gamedir, path);
|
Q_snprintf(buf, sizeof buf, "%s/dlls/%s", g_GameDLL.gamedir, path);
|
||||||
|
|
||||||
// try this path
|
// try this path
|
||||||
if (!stat(buf, &st) && S_ISREG(st.st_mode))
|
if (!stat(buf, &st) && S_ISREG(st.st_mode))
|
||||||
@ -663,7 +663,7 @@ bool MPlugin::query(void)
|
|||||||
|
|
||||||
// Make a copy of the meta_util function table for each plugin, for the
|
// Make a copy of the meta_util function table for each plugin, for the
|
||||||
// same reason.
|
// same reason.
|
||||||
Q_memcpy(&m_mutil_funcs, &MetaUtilFunctions, sizeof m_mutil_funcs);
|
Q_memcpy(&m_mutil_funcs, &g_MetaUtilFunctions, sizeof m_mutil_funcs);
|
||||||
|
|
||||||
if (pfn_query(META_INTERFACE_VERSION, &m_info, &m_mutil_funcs) != TRUE)
|
if (pfn_query(META_INTERFACE_VERSION, &m_info, &m_mutil_funcs) != TRUE)
|
||||||
{
|
{
|
||||||
@ -801,7 +801,7 @@ bool MPlugin::attach(PLUG_LOADTIME now)
|
|||||||
{
|
{
|
||||||
// Make copy of gameDLL's function tables for each plugin, so we don't
|
// Make copy of gameDLL's function tables for each plugin, so we don't
|
||||||
// risk the plugins screwing with the tables everyone uses.
|
// risk the plugins screwing with the tables everyone uses.
|
||||||
if (GameDLL.funcs.dllapi_table && !m_gamedll_funcs.dllapi_table) // TODO: check it
|
if (g_GameDLL.funcs.dllapi_table && !m_gamedll_funcs.dllapi_table) // TODO: check it
|
||||||
{
|
{
|
||||||
m_gamedll_funcs.dllapi_table = (DLL_FUNCTIONS *)Q_malloc(sizeof(DLL_FUNCTIONS));
|
m_gamedll_funcs.dllapi_table = (DLL_FUNCTIONS *)Q_malloc(sizeof(DLL_FUNCTIONS));
|
||||||
if (!m_gamedll_funcs.dllapi_table)
|
if (!m_gamedll_funcs.dllapi_table)
|
||||||
@ -809,9 +809,9 @@ bool MPlugin::attach(PLUG_LOADTIME now)
|
|||||||
META_ERROR("dll: Failed attach plugin '%s': Failed malloc() for dllapi_table");
|
META_ERROR("dll: Failed attach plugin '%s': Failed malloc() for dllapi_table");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Q_memcpy(m_gamedll_funcs.dllapi_table, GameDLL.funcs.dllapi_table, sizeof(DLL_FUNCTIONS));
|
Q_memcpy(m_gamedll_funcs.dllapi_table, g_GameDLL.funcs.dllapi_table, sizeof(DLL_FUNCTIONS));
|
||||||
}
|
}
|
||||||
if (GameDLL.funcs.newapi_table && !m_gamedll_funcs.newapi_table)
|
if (g_GameDLL.funcs.newapi_table && !m_gamedll_funcs.newapi_table)
|
||||||
{
|
{
|
||||||
m_gamedll_funcs.newapi_table = (NEW_DLL_FUNCTIONS *)Q_calloc(1, sizeof(meta_new_dll_functions_t));
|
m_gamedll_funcs.newapi_table = (NEW_DLL_FUNCTIONS *)Q_calloc(1, sizeof(meta_new_dll_functions_t));
|
||||||
if (!m_gamedll_funcs.newapi_table)
|
if (!m_gamedll_funcs.newapi_table)
|
||||||
@ -819,7 +819,7 @@ bool MPlugin::attach(PLUG_LOADTIME now)
|
|||||||
META_ERROR("dll: Failed attach plugin '%s': Failed malloc() for newapi_table");
|
META_ERROR("dll: Failed attach plugin '%s': Failed malloc() for newapi_table");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
static_cast<meta_new_dll_functions_t *>(m_gamedll_funcs.newapi_table)->set_from(GameDLL.funcs.newapi_table);
|
static_cast<meta_new_dll_functions_t *>(m_gamedll_funcs.newapi_table)->set_from(g_GameDLL.funcs.newapi_table);
|
||||||
}
|
}
|
||||||
auto pfn_attach = (META_ATTACH_FN)m_sys_module.getsym("Meta_Attach");
|
auto pfn_attach = (META_ATTACH_FN)m_sys_module.getsym("Meta_Attach");
|
||||||
if (!pfn_attach)
|
if (!pfn_attach)
|
||||||
@ -1210,14 +1210,14 @@ void MPlugin::show()
|
|||||||
META_CONS("%*s: %s", width, "last loaded", tstr);
|
META_CONS("%*s: %s", width, "last loaded", tstr);
|
||||||
// XXX show file time ?
|
// XXX show file time ?
|
||||||
|
|
||||||
show_table("DLLAPI", m_dllapi_table, &dllapi_info.pfnGameInit, false);
|
show_table("DLLAPI", m_dllapi_table, &g_dllapi_info.pfnGameInit, false);
|
||||||
show_table("DLLAPI Post", m_dllapi_post_table, &dllapi_info.pfnGameInit, true);
|
show_table("DLLAPI Post", m_dllapi_post_table, &g_dllapi_info.pfnGameInit, true);
|
||||||
|
|
||||||
show_table("NEWAPI", m_newapi_table, &newapi_info.pfnOnFreeEntPrivateData, false);
|
show_table("NEWAPI", m_newapi_table, &g_newapi_info.pfnOnFreeEntPrivateData, false);
|
||||||
show_table("NEWAPI Post", m_newapi_post_table, &newapi_info.pfnOnFreeEntPrivateData, true);
|
show_table("NEWAPI Post", m_newapi_post_table, &g_newapi_info.pfnOnFreeEntPrivateData, true);
|
||||||
|
|
||||||
show_table("Engine", m_engine_table, &engine_info.pfnPrecacheModel, false);
|
show_table("Engine", m_engine_table, &g_engineapi_info.pfnPrecacheModel, false);
|
||||||
show_table("Engine Post", m_engine_post_table, &engine_info.pfnPrecacheModel, true);
|
show_table("Engine Post", m_engine_post_table, &g_engineapi_info.pfnPrecacheModel, true);
|
||||||
|
|
||||||
g_regCmds->show(m_index);
|
g_regCmds->show(m_index);
|
||||||
g_regCvars->show(m_index);
|
g_regCvars->show(m_index);
|
||||||
|
@ -2,7 +2,12 @@
|
|||||||
|
|
||||||
MRegCmd::MRegCmd(char* cmd_name, REG_CMD_FN cmd_handler, MPlugin* cmd_plugin) : m_pfunction(cmd_handler), m_plugid(cmd_plugin->m_index), m_status(RG_VALID)
|
MRegCmd::MRegCmd(char* cmd_name, REG_CMD_FN cmd_handler, MPlugin* cmd_plugin) : m_pfunction(cmd_handler), m_plugid(cmd_plugin->m_index), m_status(RG_VALID)
|
||||||
{
|
{
|
||||||
m_name = _strdup(cmd_name);
|
m_name = Q_strdup(cmd_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
MRegCmd::~MRegCmd()
|
||||||
|
{
|
||||||
|
Q_free(m_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MRegCmd::call() const
|
bool MRegCmd::call() const
|
||||||
@ -32,6 +37,13 @@ MRegCmdList::MRegCmdList() : m_list()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MRegCmdList::~MRegCmdList()
|
||||||
|
{
|
||||||
|
for (auto reg : m_list) {
|
||||||
|
delete reg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
MRegCmd *MRegCmdList::find(const char *name) const
|
MRegCmd *MRegCmdList::find(const char *name) const
|
||||||
{
|
{
|
||||||
for (auto reg : m_list)
|
for (auto reg : m_list)
|
||||||
@ -139,14 +151,21 @@ void MRegCmdList::show(int plugin_id) const
|
|||||||
|
|
||||||
MRegCvar::MRegCvar(cvar_t* cv_ptr, MPlugin* cv_plugin) : m_cvar(cv_ptr), m_plugid(cv_plugin->m_index), m_status(RG_VALID)
|
MRegCvar::MRegCvar(cvar_t* cv_ptr, MPlugin* cv_plugin) : m_cvar(cv_ptr), m_plugid(cv_plugin->m_index), m_status(RG_VALID)
|
||||||
{
|
{
|
||||||
m_cvar = g_static_allocator.allocate<cvar_t>();
|
m_cvar = new cvar_t;
|
||||||
m_cvar->name = _strdup(cv_ptr->name);
|
m_cvar->name = Q_strdup(cv_ptr->name);
|
||||||
m_cvar->string = _strdup(cv_ptr->string);
|
m_cvar->string = Q_strdup(cv_ptr->string);
|
||||||
m_cvar->flags = cv_ptr->flags;
|
m_cvar->flags = cv_ptr->flags;
|
||||||
m_cvar->value = cv_ptr->value;
|
m_cvar->value = cv_ptr->value;
|
||||||
m_cvar->next = cv_ptr->next;
|
m_cvar->next = cv_ptr->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MRegCvar::~MRegCvar()
|
||||||
|
{
|
||||||
|
Q_free((void *)m_cvar->name);
|
||||||
|
Q_free(m_cvar->string);
|
||||||
|
delete m_cvar;
|
||||||
|
}
|
||||||
|
|
||||||
cvar_t* MRegCvar::getcvar() const
|
cvar_t* MRegCvar::getcvar() const
|
||||||
{
|
{
|
||||||
return m_cvar;
|
return m_cvar;
|
||||||
@ -157,9 +176,16 @@ MRegCvarList::MRegCvarList() : m_list()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MRegCvarList::~MRegCvarList()
|
||||||
|
{
|
||||||
|
for (auto reg : m_list) {
|
||||||
|
delete reg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
MRegCvar *MRegCvarList::add(cvar_t* src, MPlugin* plugin)
|
MRegCvar *MRegCvarList::add(cvar_t* src, MPlugin* plugin)
|
||||||
{
|
{
|
||||||
MRegCvar *reg_cvar = new(g_static_allocator.allocate<MRegCvar>()) MRegCvar(src, plugin);
|
MRegCvar *reg_cvar = new MRegCvar(src, plugin);
|
||||||
m_list.push_back(reg_cvar);
|
m_list.push_back(reg_cvar);
|
||||||
return reg_cvar;
|
return reg_cvar;
|
||||||
}
|
}
|
||||||
@ -270,12 +296,19 @@ MRegMsgList::MRegMsgList() : m_list()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MRegMsgList::~MRegMsgList()
|
||||||
|
{
|
||||||
|
for (auto reg : m_list) {
|
||||||
|
delete reg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
MRegMsg *MRegMsgList::add(const char *addname, int addmsgid, int addsize)
|
MRegMsg *MRegMsgList::add(const char *addname, int addmsgid, int addsize)
|
||||||
{
|
{
|
||||||
// Copy msg data into empty slot.
|
// Copy msg data into empty slot.
|
||||||
// Note: 'addname' assumed to be a constant string allocated in the
|
// Note: 'addname' assumed to be a constant string allocated in the
|
||||||
// gamedll.
|
// gamedll.
|
||||||
auto msg = new(g_static_allocator.allocate<MRegMsg>()) MRegMsg(addname, addmsgid, addsize);
|
auto msg = new MRegMsg(addname, addmsgid, addsize);
|
||||||
m_list.push_back(msg);
|
m_list.push_back(msg);
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ class MRegCmd
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MRegCmd(char* cmd_name, REG_CMD_FN cmd_handler, MPlugin* cmd_plugin);
|
MRegCmd(char* cmd_name, REG_CMD_FN cmd_handler, MPlugin* cmd_plugin);
|
||||||
|
~MRegCmd();
|
||||||
bool call() const; // try to call the function
|
bool call() const; // try to call the function
|
||||||
void disable();
|
void disable();
|
||||||
char* getname() const;
|
char* getname() const;
|
||||||
@ -44,6 +45,7 @@ class MRegCmdList
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MRegCmdList();
|
MRegCmdList();
|
||||||
|
~MRegCmdList();
|
||||||
MRegCmd *find(const char *name) const;
|
MRegCmd *find(const char *name) const;
|
||||||
MRegCmd *add(char *name, REG_CMD_FN cmd_handler, MPlugin* cmd_plugin);
|
MRegCmd *add(char *name, REG_CMD_FN cmd_handler, MPlugin* cmd_plugin);
|
||||||
void remove(char* cmd_name);
|
void remove(char* cmd_name);
|
||||||
@ -60,6 +62,7 @@ class MRegCvar
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MRegCvar(cvar_t* cv_ptr, MPlugin* cv_plugin);
|
MRegCvar(cvar_t* cv_ptr, MPlugin* cv_plugin);
|
||||||
|
~MRegCvar();
|
||||||
cvar_t* getcvar() const;
|
cvar_t* getcvar() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -75,6 +78,7 @@ class MRegCvarList
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MRegCvarList();
|
MRegCvarList();
|
||||||
|
~MRegCvarList();
|
||||||
MRegCvar *add(cvar_t* src, MPlugin* plugin);
|
MRegCvar *add(cvar_t* src, MPlugin* plugin);
|
||||||
MRegCvar *find(const char *findname); // find by MRegCvar->data.name
|
MRegCvar *find(const char *findname); // find by MRegCvar->data.name
|
||||||
void disable(int plugin_id) const; // change status to Invalid
|
void disable(int plugin_id) const; // change status to Invalid
|
||||||
@ -107,6 +111,7 @@ class MRegMsgList
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MRegMsgList();
|
MRegMsgList();
|
||||||
|
~MRegMsgList();
|
||||||
MRegMsg *add(const char *addname, int addmsgid, int addsize);
|
MRegMsg *add(const char *addname, int addmsgid, int addsize);
|
||||||
MRegMsg *find(const char *findname);
|
MRegMsg *find(const char *findname);
|
||||||
MRegMsg *find(int findmsgid);
|
MRegMsg *find(int findmsgid);
|
||||||
|
@ -175,11 +175,11 @@ void EXT_FUNC mutil_CenterSayVarargs(plid_t plid, hudtextparms_t tparms, const c
|
|||||||
qboolean EXT_FUNC 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)
|
||||||
{
|
{
|
||||||
META_DEBUG(8, "Looking up game entity '%s' for plugin '%s'", entStr, plid->name);
|
META_DEBUG(8, "Looking up game entity '%s' for plugin '%s'", entStr, plid->name);
|
||||||
ENTITY_FN pfnEntity = (ENTITY_FN)GameDLL.sys_module.getsym(entStr);
|
ENTITY_FN pfnEntity = (ENTITY_FN)g_GameDLL.sys_module.getsym(entStr);
|
||||||
|
|
||||||
if (!pfnEntity)
|
if (!pfnEntity)
|
||||||
{
|
{
|
||||||
META_ERROR("Couldn't find game entity '%s' in game DLL '%s' for plugin '%s'", entStr, GameDLL.name, plid->name);
|
META_ERROR("Couldn't find game entity '%s' in game DLL '%s' for plugin '%s'", entStr, g_GameDLL.name, plid->name);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,22 +266,22 @@ const char* EXT_FUNC mutil_GetGameInfo(plid_t plid, ginfo_t type)
|
|||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case GINFO_NAME:
|
case GINFO_NAME:
|
||||||
cp = GameDLL.name;
|
cp = g_GameDLL.name;
|
||||||
break;
|
break;
|
||||||
case GINFO_DESC:
|
case GINFO_DESC:
|
||||||
cp = GameDLL.desc;
|
cp = g_GameDLL.desc;
|
||||||
break;
|
break;
|
||||||
case GINFO_GAMEDIR:
|
case GINFO_GAMEDIR:
|
||||||
cp = GameDLL.gamedir;
|
cp = g_GameDLL.gamedir;
|
||||||
break;
|
break;
|
||||||
case GINFO_DLL_FULLPATH:
|
case GINFO_DLL_FULLPATH:
|
||||||
cp = GameDLL.pathname;
|
cp = g_GameDLL.pathname;
|
||||||
break;
|
break;
|
||||||
case GINFO_DLL_FILENAME:
|
case GINFO_DLL_FILENAME:
|
||||||
cp = GameDLL.file;
|
cp = g_GameDLL.file;
|
||||||
break;
|
break;
|
||||||
case GINFO_REALDLL_FULLPATH:
|
case GINFO_REALDLL_FULLPATH:
|
||||||
cp = GameDLL.real_pathname;
|
cp = g_GameDLL.real_pathname;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
META_ERROR("GetGameInfo: invalid request '%d' from plugin '%s'", type, plid->name);
|
META_ERROR("GetGameInfo: invalid request '%d' from plugin '%s'", type, plid->name);
|
||||||
@ -371,13 +371,13 @@ const char* EXT_FUNC mutil_IsQueryingClientCvar(plid_t plid, const edict_t* pEdi
|
|||||||
int EXT_FUNC mutil_MakeRequestId(plid_t plid)
|
int EXT_FUNC mutil_MakeRequestId(plid_t plid)
|
||||||
{
|
{
|
||||||
//the offset is to distinguish from gamedll requests, if any
|
//the offset is to distinguish from gamedll requests, if any
|
||||||
return abs(0xbeef << 16) + (++requestid_counter);
|
return abs(0xbeef << 16) + (++g_requestid_counter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EXT_FUNC 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)
|
if (peng)
|
||||||
*peng = &meta_engfuncs;
|
*peng = &g_meta_engfuncs;
|
||||||
|
|
||||||
if (pdll)
|
if (pdll)
|
||||||
*pdll = pHookedDllFunctions;
|
*pdll = pHookedDllFunctions;
|
||||||
@ -387,7 +387,7 @@ void EXT_FUNC mutil_GetHookTables(plid_t plid, enginefuncs_t** peng, DLL_FUNCTIO
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Meta Utility Function table.
|
// Meta Utility Function table.
|
||||||
mutil_funcs_t MetaUtilFunctions = {
|
mutil_funcs_t g_MetaUtilFunctions = {
|
||||||
mutil_LogConsole, // pfnLogConsole
|
mutil_LogConsole, // pfnLogConsole
|
||||||
mutil_LogMessage, // pfnLogMessage
|
mutil_LogMessage, // pfnLogMessage
|
||||||
mutil_LogError, // pfnLogError
|
mutil_LogError, // pfnLogError
|
||||||
|
@ -48,7 +48,7 @@ struct mutil_funcs_t
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
extern mutil_funcs_t MetaUtilFunctions;
|
extern mutil_funcs_t g_MetaUtilFunctions;
|
||||||
|
|
||||||
// Meta Utility Functions
|
// Meta Utility Functions
|
||||||
void mutil_LogConsole(plid_t plid, const char *fmt, ...);
|
void mutil_LogConsole(plid_t plid, const char *fmt, ...);
|
||||||
@ -70,16 +70,6 @@ const char *mutil_IsQueryingClientCvar(plid_t plid, const edict_t *pEdict);
|
|||||||
int mutil_MakeRequestId(plid_t plid);
|
int mutil_MakeRequestId(plid_t plid);
|
||||||
void mutil_GetHookTables(plid_t plid, enginefuncs_t **peng, DLL_FUNCTIONS **pdll, NEW_DLL_FUNCTIONS **pnewdll);
|
void mutil_GetHookTables(plid_t plid, enginefuncs_t **peng, DLL_FUNCTIONS **pdll, NEW_DLL_FUNCTIONS **pnewdll);
|
||||||
|
|
||||||
#ifdef UNFINISHED
|
|
||||||
int mutil_HookGameEvent(plid_t plid, game_event_t event, event_func_t pfnHandle);
|
|
||||||
int mutil_HookLogTrigger(plid_t plid, const char *trigger, logmatch_func_t pfnHandle);
|
|
||||||
int mutil_HookLogString(plid_t plid, const char *string, logmatch_func_t pfnHandle);
|
|
||||||
int mutil_HookLogRegex(plid_t plid, const char *pattern, logmatch_func_t pfnHandle);
|
|
||||||
|
|
||||||
qboolean mutil_RemoveHookID(plid_t plid, int hookid);
|
|
||||||
int mutil_RemoveHookAll(plid_t plid);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Convenience macros for MetaUtil functions
|
// Convenience macros for MetaUtil functions
|
||||||
#define LOG_CONSOLE (*gpMetaUtilFuncs->pfnLogConsole)
|
#define LOG_CONSOLE (*gpMetaUtilFuncs->pfnLogConsole)
|
||||||
#define LOG_MESSAGE (*gpMetaUtilFuncs->pfnLogMessage)
|
#define LOG_MESSAGE (*gpMetaUtilFuncs->pfnLogMessage)
|
||||||
@ -99,12 +89,3 @@ int mutil_RemoveHookAll(plid_t plid);
|
|||||||
#define IS_QUERYING_CLIENT_CVAR (*gpMetaUtilFuncs->pfnIsQueryingClientCvar)
|
#define IS_QUERYING_CLIENT_CVAR (*gpMetaUtilFuncs->pfnIsQueryingClientCvar)
|
||||||
#define MAKE_REQUESTID (*gpMetaUtilFuncs->pfnMakeRequestId)
|
#define MAKE_REQUESTID (*gpMetaUtilFuncs->pfnMakeRequestId)
|
||||||
#define GET_HOOK_TABLES (*gpMetaUtilFuncs->pfnGetHookTables)
|
#define GET_HOOK_TABLES (*gpMetaUtilFuncs->pfnGetHookTables)
|
||||||
|
|
||||||
#ifdef UNFINISHED
|
|
||||||
#define HOOK_GAME_EVENT (*gpMetaUtilFuncs->pfnHookGameEvent)
|
|
||||||
#define HOOK_LOG_TRIGGER (*gpMetaUtilFuncs->pfnHookLogTrigger)
|
|
||||||
#define HOOK_LOG_STRING (*gpMetaUtilFuncs->pfnHookLogString)
|
|
||||||
#define HOOK_LOG_REGEX (*gpMetaUtilFuncs->pfnHookLogRegex)
|
|
||||||
#define REMOVE_HOOK_ID (*gpMetaUtilFuncs->pfnRemoveHookID)
|
|
||||||
#define REMOVE_HOOK_ALL (*gpMetaUtilFuncs->pfnRemoveHookAll)
|
|
||||||
#endif
|
|
||||||
|
@ -40,7 +40,6 @@
|
|||||||
#include "meta_api.h"
|
#include "meta_api.h"
|
||||||
#include "mutil.h"
|
#include "mutil.h"
|
||||||
#include "reg_support.h"
|
#include "reg_support.h"
|
||||||
#include "types_meta.h"
|
|
||||||
#include "mlist.h"
|
#include "mlist.h"
|
||||||
#include "mplugin.h"
|
#include "mplugin.h"
|
||||||
#include "plinfo.h"
|
#include "plinfo.h"
|
||||||
|
@ -44,11 +44,11 @@ C_DLLEXPORT int Server_GetBlendingInterface(int version,
|
|||||||
if (!getblend)
|
if (!getblend)
|
||||||
{
|
{
|
||||||
META_DEBUG(6, "Looking up Server_GetBlendingInterface");
|
META_DEBUG(6, "Looking up Server_GetBlendingInterface");
|
||||||
getblend = (GETBLENDAPI_FN)GameDLL.sys_module.getsym("Server_GetBlendingInterface");
|
getblend = (GETBLENDAPI_FN)g_GameDLL.sys_module.getsym("Server_GetBlendingInterface");
|
||||||
}
|
}
|
||||||
if (!getblend)
|
if (!getblend)
|
||||||
{
|
{
|
||||||
META_DEBUG(6, "Couldn't find Server_GetBlendingInterface in game DLL '%s': %s", GameDLL.name, "function not found");
|
META_DEBUG(6, "Couldn't find Server_GetBlendingInterface in game DLL '%s': %s", g_GameDLL.name, "function not found");
|
||||||
missing = 1;
|
missing = 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,8 @@
|
|||||||
|
|
||||||
void __declspec(noreturn) do_exit(int exitval)
|
void __declspec(noreturn) do_exit(int exitval)
|
||||||
{
|
{
|
||||||
//TerminateProcess(GetCurrentProcess(), 1);
|
//Allahu Akbar!!
|
||||||
*((int *)NULL) = 0;
|
*((int *)nullptr) = 0;
|
||||||
while (true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks for a non-empty file, relative to the gamedir if necessary.
|
// Checks for a non-empty file, relative to the gamedir if necessary.
|
||||||
@ -31,7 +30,7 @@ int valid_gamedir_file(const char* path)
|
|||||||
buf[sizeof buf - 1] = '\0';
|
buf[sizeof buf - 1] = '\0';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
snprintf(buf, sizeof buf, "%s/%s", GameDLL.gamedir, path);
|
snprintf(buf, sizeof buf, "%s/%s", g_GameDLL.gamedir, path);
|
||||||
|
|
||||||
int ret = stat(buf, &st);
|
int ret = stat(buf, &st);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
@ -76,7 +75,7 @@ char* full_gamedir_path(const char* path, char* fullpath)
|
|||||||
Q_strncpy(buf, path, sizeof buf - 1);
|
Q_strncpy(buf, path, sizeof buf - 1);
|
||||||
buf[sizeof buf - 1] = '\0';
|
buf[sizeof buf - 1] = '\0';
|
||||||
}
|
}
|
||||||
else snprintf(buf, sizeof buf, "%s/%s", GameDLL.gamedir, path);
|
else snprintf(buf, sizeof buf, "%s/%s", g_GameDLL.gamedir, path);
|
||||||
|
|
||||||
// Remove relative path components, if possible.
|
// Remove relative path components, if possible.
|
||||||
if (!realpath(buf, fullpath))
|
if (!realpath(buf, fullpath))
|
||||||
|
@ -1 +0,0 @@
|
|||||||
#pragma once
|
|
@ -1,7 +1,5 @@
|
|||||||
#include "precompiled.h"
|
#include "precompiled.h"
|
||||||
|
|
||||||
static_allocator g_static_allocator(static_allocator::mp_readwrite);
|
|
||||||
|
|
||||||
bool is_yes(const char* str)
|
bool is_yes(const char* str)
|
||||||
{
|
{
|
||||||
return !Q_strcmp(str, "true") || !Q_strcmp(str, "yes") || !Q_strcmp(str, "1");
|
return !Q_strcmp(str, "true") || !Q_strcmp(str, "yes") || !Q_strcmp(str, "1");
|
||||||
|
@ -43,8 +43,6 @@ private:
|
|||||||
memory_protection m_protection;
|
memory_protection m_protection;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern static_allocator g_static_allocator;
|
|
||||||
|
|
||||||
bool is_yes(const char* str);
|
bool is_yes(const char* str);
|
||||||
bool is_no(const char* str);
|
bool is_no(const char* str);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user