2
0
mirror of https://github.com/rehlds/metamod-r.git synced 2025-07-04 08:19:38 +03:00

Standardize code style

This commit is contained in:
asmodai 2017-05-09 19:31:09 +03:00
parent f7c115e736
commit 06d78fe775
44 changed files with 842 additions and 1076 deletions

View File

@ -6,7 +6,8 @@
#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 g_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
@ -71,7 +72,8 @@ newapi_info_t g_newapi_info = {
{ 0, "", 0 }, { 0, "", 0 },
}; };
engine_info_t g_engineapi_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
@ -108,16 +110,16 @@ engine_info_t g_engineapi_info = {
ENGAPI_ENTRY(TraceMonsterHull, 2), // pfnTraceMonsterHull ENGAPI_ENTRY(TraceMonsterHull, 2), // pfnTraceMonsterHull
ENGAPI_ENTRY(TraceHull, 2), // pfnTraceHull ENGAPI_ENTRY(TraceHull, 2), // pfnTraceHull
ENGAPI_ENTRY(TraceModel, 2), // pfnTraceModel ENGAPI_ENTRY(TraceModel, 2), // pfnTraceModel
ENGAPI_ENTRY(TraceTexture, 2), // pfnTraceTexture // CS: when moving ENGAPI_ENTRY(TraceTexture, 2), // pfnTraceTexture
ENGAPI_ENTRY(TraceSphere, 2), // pfnTraceSphere ENGAPI_ENTRY(TraceSphere, 2), // pfnTraceSphere
ENGAPI_ENTRY(GetAimVector, 2), // pfnGetAimVector ENGAPI_ENTRY(GetAimVector, 2), // pfnGetAimVector
ENGAPI_ENTRY(ServerCommand, 3), // pfnServerCommand ENGAPI_ENTRY(ServerCommand, 3), // pfnServerCommand
ENGAPI_ENTRY(ServerExecute, 3), // pfnServerExecute ENGAPI_ENTRY(ServerExecute, 3), // pfnServerExecute
ENGAPI_ENTRY(ClientCommand, 3), // pfnClientCommand // d'oh, ClientCommand in dllapi too ENGAPI_ENTRY(ClientCommand, 3), // pfnClientCommand
ENGAPI_ENTRY(ParticleEffect, 4), // pfnParticleEffect ENGAPI_ENTRY(ParticleEffect, 4), // pfnParticleEffect
ENGAPI_ENTRY(LightStyle, 2), // pfnLightStyle ENGAPI_ENTRY(LightStyle, 2), // pfnLightStyle
ENGAPI_ENTRY(DecalIndex, 2), // pfnDecalIndex ENGAPI_ENTRY(DecalIndex, 2), // pfnDecalIndex
ENGAPI_ENTRY(PointContents, 2), // pfnPointContents // CS: when moving ENGAPI_ENTRY(PointContents, 2), // pfnPointContents
ENGAPI_ENTRY(MessageBegin, 3), // pfnMessageBegin ENGAPI_ENTRY(MessageBegin, 3), // pfnMessageBegin
ENGAPI_ENTRY(MessageEnd, 3), // pfnMessageEnd ENGAPI_ENTRY(MessageEnd, 3), // pfnMessageEnd
ENGAPI_ENTRY(WriteByte, 3), // pfnWriteByte ENGAPI_ENTRY(WriteByte, 3), // pfnWriteByte
@ -163,7 +165,7 @@ engine_info_t g_engineapi_info = {
ENGAPI_ENTRY(CRC32_ProcessByte, 4), // pfnCRC32_ProcessByte ENGAPI_ENTRY(CRC32_ProcessByte, 4), // pfnCRC32_ProcessByte
ENGAPI_ENTRY(CRC32_Final, 4), // pfnCRC32_Final ENGAPI_ENTRY(CRC32_Final, 4), // pfnCRC32_Final
ENGAPI_ENTRY(RandomLong, 3), // pfnRandomLong ENGAPI_ENTRY(RandomLong, 3), // pfnRandomLong
ENGAPI_ENTRY(RandomFloat, 3), // pfnRandomFloat // CS: when firing ENGAPI_ENTRY(RandomFloat, 3), // pfnRandomFloat
ENGAPI_ENTRY(SetView, 2), // pfnSetView ENGAPI_ENTRY(SetView, 2), // pfnSetView
ENGAPI_ENTRY(Time, 2), // pfnTime ENGAPI_ENTRY(Time, 2), // pfnTime
ENGAPI_ENTRY(CrosshairAngle, 2), // pfnCrosshairAngle ENGAPI_ENTRY(CrosshairAngle, 2), // pfnCrosshairAngle
@ -208,7 +210,7 @@ engine_info_t g_engineapi_info = {
ENGAPI_ENTRY(DeltaSetFieldByIndex, 3), // pfnDeltaSetFieldByIndex ENGAPI_ENTRY(DeltaSetFieldByIndex, 3), // pfnDeltaSetFieldByIndex
ENGAPI_ENTRY(DeltaUnsetFieldByIndex, 3), // pfnDeltaUnsetFieldByIndex ENGAPI_ENTRY(DeltaUnsetFieldByIndex, 3), // pfnDeltaUnsetFieldByIndex
ENGAPI_ENTRY(SetGroupMask, 2), // pfnSetGroupMask ENGAPI_ENTRY(SetGroupMask, 2), // pfnSetGroupMask
ENGAPI_ENTRY(CreateInstancedBaseline, 3), // pfnCreateInstancedBaseline // d'oh, CreateInstancedBaseline in dllapi too ENGAPI_ENTRY(CreateInstancedBaseline, 3), // pfnCreateInstancedBaseline
ENGAPI_ENTRY(Cvar_DirectSet, 2), // pfnCvar_DirectSet ENGAPI_ENTRY(Cvar_DirectSet, 2), // pfnCvar_DirectSet
ENGAPI_ENTRY(ForceUnmodified, 2), // pfnForceUnmodified ENGAPI_ENTRY(ForceUnmodified, 2), // pfnForceUnmodified
ENGAPI_ENTRY(GetPlayerStats, 2), // pfnGetPlayerStats ENGAPI_ENTRY(GetPlayerStats, 2), // pfnGetPlayerStats

View File

@ -2,23 +2,17 @@
CJit g_jit; CJit g_jit;
class CUniqueLabel class CUniqueLabel : public std::string
{ {
public: public:
CUniqueLabel(const char* name) : m_name(name) CUniqueLabel(const char* name) : std::string(std::string(name) + std::to_string(m_unique_index++))
{ {
m_name += std::to_string(m_unique_index++);
}
operator std::string&()
{
return m_name;
} }
private: private:
std::string m_name;
static size_t m_unique_index; static size_t m_unique_index;
}; };
size_t CUniqueLabel::m_unique_index; size_t CUniqueLabel::m_unique_index;
class CForwardCallbackJIT : public jitasm::function<int, CForwardCallbackJIT, int> class CForwardCallbackJIT : public jitasm::function<int, CForwardCallbackJIT, int>
@ -26,7 +20,7 @@ class CForwardCallbackJIT : public jitasm::function<int, CForwardCallbackJIT, in
public: public:
CForwardCallbackJIT(jitdata_t* jitdata); CForwardCallbackJIT(jitdata_t* jitdata);
void naked_main(); void naked_main();
void call_func(jitasm::Frontend::Reg32 addr); void call_func(Reg32 addr);
private: private:
jitdata_t* m_jitdata; jitdata_t* m_jitdata;
@ -280,10 +274,10 @@ void CForwardCallbackJIT::naked_main()
ret(); ret();
} }
void CForwardCallbackJIT::call_func(jitasm::Frontend::Reg32 addr) void CForwardCallbackJIT::call_func(Reg32 addr)
{ {
const size_t fixed_args_count = m_jitdata->args_count - (m_jitdata->has_varargs ? 1u /* excluding format string */ : 0u); const size_t fixed_args_count = m_jitdata->args_count - (m_jitdata->has_varargs ? 1u /* excluding format string */ : 0u);
const size_t strbuf_offset = m_jitdata->has_ret ? sizeof(int) * 2 /* orig + over */ : 0; const size_t strbuf_offset = m_jitdata->has_ret ? sizeof(int) * 2u /* orig + over */ : 0u;
// push formatted buf instead of format string // push formatted buf instead of format string
if (m_jitdata->has_varargs) { if (m_jitdata->has_varargs) {

View File

@ -89,7 +89,6 @@ public:
private: private:
static bool is_hook_needed(jitdata_t* jitdata); static bool is_hook_needed(jitdata_t* jitdata);
private:
static_allocator m_callback_allocator; static_allocator m_callback_allocator;
static_allocator m_tramp_allocator; static_allocator m_tramp_allocator;
}; };

View File

@ -45,10 +45,8 @@ void EXT_FUNC server_meta()
{ {
const char *cmd = CMD_ARGV(1); const char *cmd = CMD_ARGV(1);
for (auto& meta_cmd : g_meta_cmds) for (auto& meta_cmd : g_meta_cmds) {
{ if (!Q_strcmp(cmd, meta_cmd.name)) {
if (!Q_strcmp(cmd, meta_cmd.name))
{
meta_cmd.handler(); meta_cmd.handler();
return; return;
} }
@ -67,14 +65,11 @@ void EXT_FUNC client_meta(edict_t* pEntity)
// arguments: none // arguments: none
if (!Q_strcmp(cmd, "version")) if (!Q_strcmp(cmd, "version"))
client_meta_version(pEntity); client_meta_version(pEntity);
else if (!Q_strcmp(cmd, "list")) else if (!Q_strcmp(cmd, "list"))
client_meta_pluginlist(pEntity); client_meta_pluginlist(pEntity);
else else {
{
META_CLIENT(pEntity, "Unrecognized meta command: %s", cmd); META_CLIENT(pEntity, "Unrecognized meta command: %s", cmd);
client_meta_usage(pEntity); client_meta_usage(pEntity);
return;
} }
} }
@ -114,8 +109,7 @@ void client_meta_usage(edict_t *pEntity)
// "meta version" console command. // "meta version" console command.
void cmd_meta_version() void cmd_meta_version()
{ {
if (CMD_ARGC() != 2) if (CMD_ARGC() != 2) {
{
META_CONS("usage: meta version"); META_CONS("usage: meta version");
return; return;
} }
@ -128,8 +122,7 @@ void cmd_meta_version()
// "meta version" client command. // "meta version" client command.
void client_meta_version(edict_t *pEntity) void client_meta_version(edict_t *pEntity)
{ {
if (CMD_ARGC() != 2) if (CMD_ARGC() != 2) {
{
META_CLIENT(pEntity, "usage: meta version"); META_CLIENT(pEntity, "usage: meta version");
return; return;
} }
@ -176,8 +169,7 @@ void cmd_meta_gpl()
// "meta game" console command. // "meta game" console command.
void cmd_meta_game() void cmd_meta_game()
{ {
if (CMD_ARGC() != 2) if (CMD_ARGC() != 2) {
{
META_CONS("usage: meta game"); META_CONS("usage: meta game");
return; return;
} }
@ -194,15 +186,13 @@ void cmd_meta_game()
// "meta refresh" console command. // "meta refresh" console command.
void cmd_meta_refresh() void cmd_meta_refresh()
{ {
if (CMD_ARGC() != 2) if (CMD_ARGC() != 2) {
{
META_CONS("usage: meta refresh"); META_CONS("usage: meta refresh");
return; return;
} }
META_LOG("Refreshing the plugins on demand..."); META_LOG("Refreshing the plugins on demand...");
if (g_plugins->refresh(PT_ANYTIME) != true) if (!g_plugins->refresh(PT_ANYTIME)) {
{
META_LOG("Refresh failed."); META_LOG("Refresh failed.");
} }
} }
@ -210,20 +200,18 @@ void cmd_meta_refresh()
// "meta list" console command. // "meta list" console command.
void cmd_meta_pluginlist() void cmd_meta_pluginlist()
{ {
if (CMD_ARGC() != 2) if (CMD_ARGC() != 2) {
{
META_CONS("usage: meta list"); META_CONS("usage: meta list");
return; return;
} }
g_plugins->show(0); g_plugins->show();
} }
// "meta list" client command. // "meta list" client command.
void client_meta_pluginlist(edict_t* pEntity) void client_meta_pluginlist(edict_t* pEntity)
{ {
if (CMD_ARGC() != 2) if (CMD_ARGC() != 2) {
{
META_CLIENT(pEntity, "usage: meta list"); META_CLIENT(pEntity, "usage: meta list");
return; return;
} }
@ -234,8 +222,7 @@ void client_meta_pluginlist(edict_t* pEntity)
// "meta cmds" console command. // "meta cmds" console command.
void cmd_meta_cmdlist() void cmd_meta_cmdlist()
{ {
if (CMD_ARGC() != 2) if (CMD_ARGC() != 2) {
{
META_CONS("usage: meta cmds"); META_CONS("usage: meta cmds");
return; return;
} }
@ -246,8 +233,7 @@ void cmd_meta_cmdlist()
// "meta cvars" console command. // "meta cvars" console command.
void cmd_meta_cvarlist() void cmd_meta_cvarlist()
{ {
if (CMD_ARGC() != 2) if (CMD_ARGC() != 2) {
{
META_CONS("usage: meta cvars"); META_CONS("usage: meta cvars");
return; return;
} }
@ -258,8 +244,7 @@ void cmd_meta_cvarlist()
// "meta config" console command. // "meta config" console command.
void cmd_meta_config() void cmd_meta_config()
{ {
if (CMD_ARGC() != 2) if (CMD_ARGC() != 2) {
{
META_CONS("usage: meta cvars"); META_CONS("usage: meta cvars");
return; return;
} }
@ -271,8 +256,7 @@ void cmd_meta_config()
void cmd_meta_load() void cmd_meta_load()
{ {
int argc = CMD_ARGC(); int argc = CMD_ARGC();
if (argc < 3) if (argc < 3) {
{
META_CONS("usage: meta load <name> [<description>]"); META_CONS("usage: meta load <name> [<description>]");
META_CONS(" where <name> is an identifier used to locate the plugin file."); META_CONS(" where <name> is an identifier used to locate the plugin file.");
META_CONS(" The system will look for a number of files based on this name, including:"); META_CONS(" The system will look for a number of files based on this name, including:");
@ -305,8 +289,7 @@ void cmd_doplug(PLUG_CMD pcmd)
int argc = CMD_ARGC(); int argc = CMD_ARGC();
const char *cmd = CMD_ARGV(1); const char *cmd = CMD_ARGV(1);
if (argc < 3) if (argc < 3) {
{
META_CONS("usage: meta %s <plugin> [<plugin> ...]", cmd); META_CONS("usage: meta %s <plugin> [<plugin> ...]", cmd);
META_CONS(" where <plugin> can be either the plugin index #"); META_CONS(" where <plugin> can be either the plugin index #");
META_CONS(" or a non-ambiguous prefix string matching name, desc, file, or logtag"); META_CONS(" or a non-ambiguous prefix string matching name, desc, file, or logtag");
@ -314,8 +297,7 @@ void cmd_doplug(PLUG_CMD pcmd)
} }
// i = 2 to skip first arg, as that's the "cmd" // i = 2 to skip first arg, as that's the "cmd"
for (int i = 2; i < argc; i++) for (int i = 2; i < argc; i++) {
{
const char *arg = CMD_ARGV(i); const char *arg = CMD_ARGV(i);
MPlugin *findp; MPlugin *findp;
char *endptr; char *endptr;
@ -333,27 +315,22 @@ void cmd_doplug(PLUG_CMD pcmd)
// - specified plugin was found in the list of current plugins // - specified plugin was found in the list of current plugins
// - plugin successfully loaded and began running // - plugin successfully loaded and began running
// Otherwise, print error and exit. // Otherwise, print error and exit.
if (pcmd == PC_REQUIRE) if (pcmd == PC_REQUIRE) {
{ if (findp && findp->status() >= PL_RUNNING && unique) {
if (findp && findp->status() >= PL_RUNNING && unique)
{
META_DEBUG(3, "Required plugin '%s' found loaded and running.", arg); META_DEBUG(3, "Required plugin '%s' found loaded and running.", arg);
return; return;
} }
// Output to both places, because we don't want the admin // Output to both places, because we don't want the admin
// to miss this.. // to miss this..
if (findp && !unique) if (findp && !unique) {
{
META_ERROR("Unique match for required plugin '%s' was not found! Exiting.", arg); META_ERROR("Unique match for required plugin '%s' was not found! Exiting.", arg);
META_CONS("\nERROR: Unique match for required plugin '%s' was not found! Exiting.\n", arg); META_CONS("\nERROR: Unique match for required plugin '%s' was not found! Exiting.\n", arg);
} }
else if (!findp) else if (!findp) {
{
META_ERROR("Required plugin '%s' was not found! Exiting.", arg); META_ERROR("Required plugin '%s' was not found! Exiting.", arg);
META_CONS("\nERROR: Required plugin '%s' was not found! Exiting.\n", arg); META_CONS("\nERROR: Required plugin '%s' was not found! Exiting.\n", arg);
} }
else else {
{
META_ERROR("Required plugin '%s' did not load successfully! (status=%s) Exiting.", arg, findp->str_status(ST_SIMPLE)); META_ERROR("Required plugin '%s' did not load successfully! (status=%s) Exiting.", arg, findp->str_status(ST_SIMPLE));
META_CONS("\nERROR: Required plugin '%s' did not load successfully! (status=%s) Exiting.\n", arg, findp->str_status(ST_SIMPLE)); META_CONS("\nERROR: Required plugin '%s' did not load successfully! (status=%s) Exiting.\n", arg, findp->str_status(ST_SIMPLE));
} }
@ -371,8 +348,7 @@ void cmd_doplug(PLUG_CMD pcmd)
return; return;
} }
switch (pcmd) switch (pcmd) {
{
case PC_PAUSE: case PC_PAUSE:
if (findp->pause()) if (findp->pause())
META_CONS("Paused plugin '%s'", findp->description()); META_CONS("Paused plugin '%s'", findp->description());
@ -388,8 +364,7 @@ void cmd_doplug(PLUG_CMD pcmd)
case PC_UNLOAD: case PC_UNLOAD:
{ {
findp->set_action(PA_UNLOAD); findp->set_action(PA_UNLOAD);
if (findp->unload(PT_ANYTIME, PNL_COMMAND)) if (findp->unload(PT_ANYTIME, PNL_COMMAND)) {
{
META_CONS("Unloaded plugin '%s'", findp->description()); META_CONS("Unloaded plugin '%s'", findp->description());
g_plugins->show(); g_plugins->show();
} }
@ -402,8 +377,7 @@ void cmd_doplug(PLUG_CMD pcmd)
case PC_FORCE_UNLOAD: case PC_FORCE_UNLOAD:
{ {
findp->set_action(PA_UNLOAD); findp->set_action(PA_UNLOAD);
if (findp->unload(PT_ANYTIME, PNL_CMD_FORCED)) if (findp->unload(PT_ANYTIME, PNL_CMD_FORCED)) {
{
META_CONS("Forced unload plugin '%s'", findp->description()); META_CONS("Forced unload plugin '%s'", findp->description());
g_plugins->show(); g_plugins->show();
} }
@ -431,8 +405,7 @@ void cmd_doplug(PLUG_CMD pcmd)
META_CONS("Retry failed for plugin '%s'", findp->description()); META_CONS("Retry failed for plugin '%s'", findp->description());
break; break;
case PC_CLEAR: case PC_CLEAR:
if (!findp->clear()) if (!findp->clear()) {
{
META_CONS("Clear failed for plugin '%s'", findp->description()); META_CONS("Clear failed for plugin '%s'", findp->description());
return; return;
} }

View File

@ -4,7 +4,7 @@
// "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
{ {
PC_NULL = 0, PC_NULL,
PC_PAUSE, // pause the plugin PC_PAUSE, // pause the plugin
PC_UNPAUSE, // unpause the plugin PC_UNPAUSE, // unpause the plugin
PC_UNLOAD, // unload the plugin PC_UNLOAD, // unload the plugin

View File

@ -16,8 +16,7 @@ void MConfig::init(option_t* global_options)
option_t* MConfig::find(const char* lookup) const option_t* MConfig::find(const char* lookup) const
{ {
for (auto optp = m_list; optp->name; optp++) for (auto optp = m_list; optp->name; optp++) {
{
if (!Q_strcmp(optp->name, lookup)) { if (!Q_strcmp(optp->name, lookup)) {
return optp; return optp;
} }
@ -46,11 +45,9 @@ bool MConfig::set(option_t* setp, const char* setstr)
if (!setstr) if (!setstr)
return true; return true;
switch (setp->type) switch (setp->type) {
{
case CF_INT: case CF_INT:
if (!isdigit(setstr[0])) if (!isdigit(setstr[0])) {
{
META_ERROR("option '%s' invalid format '%s'", setp->name, setstr); META_ERROR("option '%s' invalid format '%s'", setp->name, setstr);
return false; return false;
} }
@ -58,16 +55,13 @@ bool MConfig::set(option_t* setp, const char* setstr)
META_DEBUG(3, "set config int: %s = %d", setp->name, *optval); META_DEBUG(3, "set config int: %s = %d", setp->name, *optval);
break; break;
case CF_BOOL: case CF_BOOL:
if (is_yes(setstr)) if (is_yes(setstr)) {
{
*optval = TRUE; *optval = TRUE;
} }
else if (is_no(setstr)) else if (is_no(setstr)) {
{
*optval = FALSE; *optval = FALSE;
} }
else else {
{
META_ERROR("option '%s' invalid format '%s'", setp->name, META_ERROR("option '%s' invalid format '%s'", setp->name,
setstr); setstr);
return false; return false;
@ -99,48 +93,42 @@ bool MConfig::load(const char* fn)
{ {
char loadfile[PATH_MAX]; char loadfile[PATH_MAX];
char line[MAX_CONF_LEN]; char line[MAX_CONF_LEN];
char *optname, *optval;
option_t* optp;
// Make full pathname (from gamedir if relative, collapse "..", // Make full pathname (from gamedir if relative, collapse "..",
// backslashes, etc). // backslashes, etc).
full_gamedir_path(fn, loadfile); full_gamedir_path(fn, loadfile);
FILE* fp = fopen(loadfile, "r"); FILE* fp = fopen(loadfile, "r");
if (!fp) if (!fp) {
{
META_ERROR("unable to open config file '%s': %s", loadfile, strerror(errno)); META_ERROR("unable to open config file '%s': %s", loadfile, strerror(errno));
return false; return false;
} }
META_DEBUG(2, "Loading from config file: %s", loadfile); META_DEBUG(2, "Loading from config file: %s", loadfile);
for (int ln = 1; !feof(fp) && fgets(line, sizeof line, fp); ln++) for (int ln = 1; !feof(fp) && fgets(line, sizeof line, fp); ln++) {
{
if (line[0] == '#' || line[0] == ';' || !Q_strncmp(line, "//", 2)) if (line[0] == '#' || line[0] == ';' || !Q_strncmp(line, "//", 2))
continue; continue;
if (!(optname = strtok(line, " \t\r\n"))) char* optname = strtok(line, " \t\r\n");
{ if (!optname) {
META_ERROR("'%s' line %d: bad config format: missing option", loadfile, ln); META_ERROR("'%s' line %d: bad config format: missing option", loadfile, ln);
continue; continue;
} }
if (!(optval = strtok(nullptr, "\r\n"))) char *optval = strtok(nullptr, "\r\n");
{ if (!optval) {
META_ERROR("'%s' line %d: bad config format: missing value", loadfile, ln); META_ERROR("'%s' line %d: bad config format: missing value", loadfile, ln);
continue; continue;
} }
if (!(optp = find(optname))) auto optp = find(optname);
{ if (!optp) {
META_ERROR("'%s' line %d: unknown option name '%s'", loadfile, ln, optname); META_ERROR("'%s' line %d: unknown option name '%s'", loadfile, ln, optname);
continue; continue;
} }
if (!set(optp, optval)) if (!set(optp, optval)) {
{
META_ERROR("'%s' line %d: unable to set option '%s' value '%s'", loadfile, ln, optname, optval); META_ERROR("'%s' line %d: unable to set option '%s' value '%s'", loadfile, ln, optname, optval);
continue;
} }
} }
@ -153,15 +141,13 @@ void MConfig::show() const
{ {
META_CONS("Config options from localinfo and %s:", m_filename); META_CONS("Config options from localinfo and %s:", m_filename);
for (auto optp = m_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;
// cvar_t *optcvar = (cvar_t *) optp->dest; // cvar_t *optcvar = (cvar_t *) optp->dest;
// SETOPT_FN optcmd = (SETOPT_FN) optp->dest; // SETOPT_FN optcmd = (SETOPT_FN) optp->dest;
switch (optp->type) switch (optp->type) {
{
case CF_INT: case CF_INT:
printf(" %-20s\t%d\n", optp->name, *optval); printf(" %-20s\t%d\n", optp->name, *optval);
break; break;
@ -186,8 +172,7 @@ void MConfig::set_directory()
GetModuleFileName(hModule, m_directory, sizeof m_directory); GetModuleFileName(hModule, m_directory, sizeof m_directory);
#else #else
Dl_info addrInfo; Dl_info addrInfo;
if (dladdr((void *)GiveFnptrsToDll, &addrInfo)) if (dladdr((void *)GiveFnptrsToDll, &addrInfo)) {
{
Q_strncpy(m_directory, addrInfo.dli_fname, sizeof m_directory - 1); Q_strncpy(m_directory, addrInfo.dli_fname, sizeof m_directory - 1);
m_directory[sizeof m_directory - 1] = '\0'; m_directory[sizeof m_directory - 1] = '\0';
} }

View File

@ -12,7 +12,7 @@ NEW_DLL_FUNCTIONS sNewFunctionTable;
NEW_DLL_FUNCTIONS sNewFunctionTable_jit; NEW_DLL_FUNCTIONS sNewFunctionTable_jit;
NEW_DLL_FUNCTIONS *pHookedNewDllFunctions = &sNewFunctionTable; NEW_DLL_FUNCTIONS *pHookedNewDllFunctions = &sNewFunctionTable;
void MM_PRE_HOOK EXT_FUNC mm_ClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[128] ) void MM_PRE_HOOK EXT_FUNC mm_ClientConnect(edict_t *pEntity, const char *, const char *, char [128])
{ {
g_players.clear_player_cvar_query(pEntity); g_players.clear_player_cvar_query(pEntity);
} }
@ -149,13 +149,11 @@ compile_data_t g_newdllfunc_cdata[] =
C_DLLEXPORT int GetEntityAPI(DLL_FUNCTIONS *pFunctionTable, int interfaceVersion) C_DLLEXPORT int GetEntityAPI(DLL_FUNCTIONS *pFunctionTable, int interfaceVersion)
{ {
META_DEBUG(3, "called: GetEntityAPI; version=%d", interfaceVersion); META_DEBUG(3, "called: GetEntityAPI; version=%d", interfaceVersion);
if (!pFunctionTable) if (!pFunctionTable) {
{
META_ERROR("GetEntityAPI called with null pFunctionTable"); META_ERROR("GetEntityAPI called with null pFunctionTable");
return FALSE; return FALSE;
} }
if (interfaceVersion != INTERFACE_VERSION) if (interfaceVersion != INTERFACE_VERSION) {
{
META_ERROR("GetEntityAPI version mismatch; requested=%d ours=%d", interfaceVersion, INTERFACE_VERSION); META_ERROR("GetEntityAPI version mismatch; requested=%d ours=%d", interfaceVersion, INTERFACE_VERSION);
return FALSE; return FALSE;
} }
@ -168,13 +166,11 @@ C_DLLEXPORT int GetEntityAPI2(DLL_FUNCTIONS *pFunctionTable, int *interfaceVersi
{ {
META_DEBUG(3, "called: GetEntityAPI2; version=%d", *interfaceVersion); META_DEBUG(3, "called: GetEntityAPI2; version=%d", *interfaceVersion);
if (!pFunctionTable) if (!pFunctionTable) {
{
META_ERROR("GetEntityAPI2 called with null pFunctionTable"); META_ERROR("GetEntityAPI2 called with null pFunctionTable");
return FALSE; return FALSE;
} }
if (*interfaceVersion != INTERFACE_VERSION) if (*interfaceVersion != INTERFACE_VERSION) {
{
META_ERROR("GetEntityAPI2 version mismatch; requested=%d ours=%d", *interfaceVersion, INTERFACE_VERSION); META_ERROR("GetEntityAPI2 version mismatch; requested=%d ours=%d", *interfaceVersion, INTERFACE_VERSION);
//! Tell engine what version we had, so it can figure out who is out of date. //! Tell engine what version we had, so it can figure out who is out of date.
*interfaceVersion = INTERFACE_VERSION; *interfaceVersion = INTERFACE_VERSION;
@ -196,13 +192,11 @@ C_DLLEXPORT int GetNewDLLFunctions(NEW_DLL_FUNCTIONS *pNewFunctionTable, int *in
return FALSE; return FALSE;
#endif #endif
if (!pNewFunctionTable) if (!pNewFunctionTable) {
{
META_ERROR("GetNewDLLFunctions called with null pNewFunctionTable"); META_ERROR("GetNewDLLFunctions called with null pNewFunctionTable");
return FALSE; return FALSE;
} }
if (*interfaceVersion != NEW_DLL_FUNCTIONS_VERSION) if (*interfaceVersion != NEW_DLL_FUNCTIONS_VERSION) {
{
META_ERROR("GetNewDLLFunctions version mismatch; requested=%d ours=%d", *interfaceVersion, NEW_DLL_FUNCTIONS_VERSION); META_ERROR("GetNewDLLFunctions version mismatch; requested=%d ours=%d", *interfaceVersion, NEW_DLL_FUNCTIONS_VERSION);
//! Tell engine what version we had, so it can figure out who is out of date. //! Tell engine what version we had, so it can figure out who is out of date.
*interfaceVersion = NEW_DLL_FUNCTIONS_VERSION; *interfaceVersion = NEW_DLL_FUNCTIONS_VERSION;

View File

@ -3,7 +3,9 @@
// Our structure for storing engine references. // Our structure for storing engine references.
struct engine_t struct engine_t
{ {
engine_t() : funcs(nullptr), globals(nullptr), pl_funcs(nullptr) {} engine_t() : funcs(nullptr), globals(nullptr), pl_funcs(nullptr)
{
}
enginefuncs_t* funcs; // engine funcs enginefuncs_t* funcs; // engine funcs
globalvars_t* globals; // engine globals globalvars_t* globals; // engine globals

View File

@ -12,10 +12,6 @@
#include <enginecallback.h> // ALERT, etc #include <enginecallback.h> // ALERT, etc
#ifdef METAMOD_CORE
#undef enginefuncs_t
#endif
// Also, create some additional macros for engine callback functions, which // Also, create some additional macros for engine callback functions, which
// weren't in SDK dlls/enginecallbacks.h but probably should have been. // weren't in SDK dlls/enginecallbacks.h but probably should have been.
#define GET_INFOKEYBUFFER (*g_engfuncs.pfnGetInfoKeyBuffer) #define GET_INFOKEYBUFFER (*g_engfuncs.pfnGetInfoKeyBuffer)

View File

@ -18,10 +18,9 @@ const game_modinfo_t g_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) static const game_modinfo_t *lookup_game(const char *name)
{
for (auto& known : g_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;
} }
@ -33,35 +32,30 @@ inline const game_modinfo_t *lookup_game(const char *name)
// Installs gamedll from Steam cache // Installs gamedll from Steam cache
bool install_gamedll(char *from, const char *to) bool install_gamedll(char *from, const char *to)
{ {
int length_in;
int length_out;
if (!from) if (!from)
return false; return false;
if (!to) if (!to)
to = from; to = from;
int length_in;
byte *cachefile = LOAD_FILE_FOR_ME(from, &length_in); byte *cachefile = LOAD_FILE_FOR_ME(from, &length_in);
// If the file seems to exist in the cache. // If the file seems to exist in the cache.
if (cachefile) if (cachefile) {
{
int fd = open(to, O_WRONLY | O_CREAT | O_EXCL | O_BINARY, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); int fd = open(to, O_WRONLY | O_CREAT | O_EXCL | O_BINARY, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
if (fd < 0) if (fd < 0) {
{
META_DEBUG(3, "Installing gamedll from cache: Failed to create file %s: %s", to, strerror(errno)); META_DEBUG(3, "Installing gamedll from cache: Failed to create file %s: %s", to, strerror(errno));
FREE_FILE(cachefile); FREE_FILE(cachefile);
return false; return false;
} }
length_out = Q_write(fd, cachefile, length_in); int length_out = Q_write(fd, cachefile, length_in);
FREE_FILE(cachefile); FREE_FILE(cachefile);
close(fd); close(fd);
// Writing the file was not successfull // Writing the file was not successfull
if (length_out != length_in) if (length_out != length_in) {
{
META_DEBUG(3, "Installing gamedll from chache: Failed to write all %d bytes to file, only %d written: %s", length_in, length_out, strerror(errno)); META_DEBUG(3, "Installing gamedll from chache: Failed to write all %d bytes to file, only %d written: %s", length_in, length_out, strerror(errno));
// Let's not leave a mess but clean up nicely. // Let's not leave a mess but clean up nicely.
@ -73,8 +67,7 @@ bool install_gamedll(char *from, const char *to)
META_LOG("Installed gamedll %s from cache.", to); META_LOG("Installed gamedll %s from cache.", to);
} }
else else {
{
META_DEBUG(3, "Failed to install gamedll from cache: file %s not found in cache.", from); META_DEBUG(3, "Failed to install gamedll from cache: file %s not found in cache.", from);
return false; return false;
} }
@ -95,8 +88,7 @@ bool setup_gamedll(gamedll_t *gamedll)
const char *knownfn = nullptr; const char *knownfn = nullptr;
// First, look for a known game, based on gamedir. // First, look for a known game, based on gamedir.
if ((known = lookup_game(gamedll->name))) if ((known = lookup_game(gamedll->name))) {
{
#ifdef _WIN32 #ifdef _WIN32
knownfn = known->win_dll; knownfn = known->win_dll;
#else #else
@ -109,22 +101,19 @@ bool setup_gamedll(gamedll_t *gamedll)
return false; return false;
// Use override-dll if specified. // Use override-dll if specified.
if (g_config->m_gamedll) if (g_config->m_gamedll) {
{
Q_strncpy(gamedll->pathname, g_config->m_gamedll, sizeof gamedll->pathname - 1); Q_strncpy(gamedll->pathname, g_config->m_gamedll, sizeof gamedll->pathname - 1);
gamedll->pathname[sizeof gamedll->pathname - 1] = '\0'; gamedll->pathname[sizeof gamedll->pathname - 1] = '\0';
// If the path is relative, the gamedll file will be missing and // If the path is relative, the gamedll file will be missing and
// it might be found in the cache file. // it might be found in the cache file.
if (!is_abs_path(gamedll->pathname)) if (!is_abs_path(gamedll->pathname)) {
{
char szInstallPath[MAX_PATH]; char szInstallPath[MAX_PATH];
Q_snprintf(szInstallPath, sizeof(szInstallPath), "%s/%s", gamedll->gamedir, gamedll->pathname); Q_snprintf(szInstallPath, sizeof(szInstallPath), "%s/%s", gamedll->gamedir, gamedll->pathname);
// If we could successfully install the gamedll from the cache we // If we could successfully install the gamedll from the cache we
// rectify the pathname to be a full pathname. // rectify the pathname to be a full pathname.
if (install_gamedll(gamedll->pathname, szInstallPath)) if (install_gamedll(gamedll->pathname, szInstallPath)) {
{
Q_strncpy(gamedll->pathname, szInstallPath, sizeof(gamedll->pathname)); Q_strncpy(gamedll->pathname, szInstallPath, sizeof(gamedll->pathname));
} }
} }
@ -132,12 +121,10 @@ bool setup_gamedll(gamedll_t *gamedll)
override = true; override = true;
} }
// Else use Known-list dll. // Else use Known-list dll.
else if (known) else if (known) {
{
Q_snprintf(gamedll->pathname, sizeof(gamedll->pathname), "%s/dlls/%s", gamedll->gamedir, knownfn); Q_snprintf(gamedll->pathname, sizeof(gamedll->pathname), "%s/dlls/%s", gamedll->gamedir, knownfn);
} }
else else {
{
// Neither override nor known-list found a gamedll. // Neither override nor known-list found a gamedll.
return false; return false;
} }
@ -153,26 +140,22 @@ bool setup_gamedll(gamedll_t *gamedll)
// If found, store also the supposed "real" dll path based on the // If found, store also the supposed "real" dll path based on the
// gamedir, in case it differs from the "override" dll path. // gamedir, in case it differs from the "override" dll path.
if (known && override) if (known && override) {
{
Q_snprintf(gamedll->real_pathname, sizeof(gamedll->real_pathname), "%s/dlls/%s", gamedll->gamedir, knownfn); Q_snprintf(gamedll->real_pathname, sizeof(gamedll->real_pathname), "%s/dlls/%s", gamedll->gamedir, knownfn);
} }
else else {
{
Q_strncpy(gamedll->real_pathname, gamedll->pathname, sizeof gamedll->real_pathname - 1); Q_strncpy(gamedll->real_pathname, gamedll->pathname, sizeof gamedll->real_pathname - 1);
gamedll->real_pathname[sizeof gamedll->real_pathname - 1] = '\0'; gamedll->real_pathname[sizeof gamedll->real_pathname - 1] = '\0';
} }
if (override) if (override) {
{
// generate a desc // generate a desc
Q_snprintf(gamedll->desc, sizeof(gamedll->desc), "%s (override)", gamedll->file); Q_snprintf(gamedll->desc, sizeof(gamedll->desc), "%s (override)", gamedll->file);
// log result // log result
META_LOG("Overriding game '%s' with dllfile '%s'", gamedll->name, gamedll->file); META_LOG("Overriding game '%s' with dllfile '%s'", gamedll->name, gamedll->file);
} }
else if (known) else if (known) {
{
Q_strncpy(gamedll->desc, known->desc, sizeof gamedll->desc - 1); Q_strncpy(gamedll->desc, known->desc, sizeof gamedll->desc - 1);
gamedll->desc[sizeof gamedll->desc - 1] = '\0'; gamedll->desc[sizeof gamedll->desc - 1] = '\0';

View File

@ -1,38 +1,5 @@
#include "precompiled.h" #include "precompiled.h"
#ifdef _WIN32
//! Required DLL entry point
// The above SDK comment indicates this routine is required, but the MSDN
// documentation indicates it's actually optional. We keep it, though, for
// completeness.
BOOL WINAPI DllMain(HINSTANCE /* hinstDLL */, DWORD fdwReason, LPVOID /* lpvReserved */)
{
if (fdwReason == DLL_PROCESS_ATTACH)
{
/* nothing */
}
else if (fdwReason == DLL_PROCESS_DETACH)
{
/* nothing */
}
return TRUE;
}
#elif defined(linux) || defined(__APPLE__)
// Linux routines to correspond to ATTACH and DETACH cases above. These
// aren't required by linux, but are included here for completeness, and
// just in case we come across a need to do something at dll load or
// unload.
// NOTE: These aren't actually called. Needs investigation.
void _init()
{
// called before dlopen() returns
}
void _fini()
{
// called before dlclose() returns
}
#endif
//! Holds engine functionality callbacks //! Holds engine functionality callbacks
enginefuncs_t g_engfuncs; enginefuncs_t g_engfuncs;
globalvars_t* gpGlobals; globalvars_t* gpGlobals;

View File

@ -5,20 +5,17 @@
// Kivilinna <kijuhe00@students.oamk.fi>. // Kivilinna <kijuhe00@students.oamk.fi>.
void NOINLINE do_link_ent(ENTITY_FN* pfnEntity, int* missing, const char* entStr, entvars_t* pev) void NOINLINE do_link_ent(ENTITY_FN* pfnEntity, int* missing, const char* entStr, entvars_t* pev)
{ {
if (*missing) if (*missing) {
{
META_DEBUG(9, "Skipping entity '%s'; was previously found missing", entStr); META_DEBUG(9, "Skipping entity '%s'; was previously found missing", entStr);
return; return;
} }
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)g_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, g_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;

View File

@ -1,6 +1,13 @@
#include "precompiled.h" #include "precompiled.h"
cvar_t g_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
{ {
@ -30,8 +37,7 @@ void META_CONS(const char *fmt, ...)
void META_DEV(const char* fmt, ...) void META_DEV(const char* fmt, ...)
{ {
if (CVAR_GET_FLOAT && CVAR_GET_FLOAT("developer")) if (CVAR_GET_FLOAT && CVAR_GET_FLOAT("developer")) {
{
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
buffered_ALERT(mlsDEV, at_logged, "[META] dev:", fmt, ap); buffered_ALERT(mlsDEV, at_logged, "[META] dev:", fmt, ap);
@ -108,15 +114,14 @@ struct BufferedMessage
BufferedMessage* next; BufferedMessage* next;
}; };
static BufferedMessage *g_messageQueueStart = nullptr; static BufferedMessage* g_messageQueueStart;
static BufferedMessage *g_messageQueueEnd = nullptr; static BufferedMessage* g_messageQueueEnd;
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)
{ {
char buf[MAX_LOGMSG_LEN]; char buf[MAX_LOGMSG_LEN];
if (g_engfuncs.pfnAlertMessage) if (g_engfuncs.pfnAlertMessage) {
{
Q_vsnprintf(buf, sizeof buf, fmt, ap); Q_vsnprintf(buf, sizeof buf, fmt, ap);
ALERT(atype, "%s %s\n", prefix, buf); ALERT(atype, "%s %s\n", prefix, buf);
return; return;
@ -124,8 +129,7 @@ void buffered_ALERT(MLOG_SERVICE service, ALERT_TYPE atype, const char *prefix,
// g_engine AlertMessage function not available. Buffer message. // g_engine AlertMessage function not available. Buffer message.
BufferedMessage* msg = new BufferedMessage; BufferedMessage* msg = new BufferedMessage;
if (!msg) if (!msg) {
{
// though luck, gonna lose this message // though luck, gonna lose this message
return; return;
} }
@ -136,12 +140,10 @@ 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 (!g_messageQueueEnd) if (!g_messageQueueEnd) {
{
g_messageQueueStart = g_messageQueueEnd = msg; g_messageQueueStart = g_messageQueueEnd = msg;
} }
else else {
{
g_messageQueueEnd->next = msg; g_messageQueueEnd->next = msg;
g_messageQueueEnd = msg; g_messageQueueEnd = msg;
} }
@ -156,13 +158,10 @@ void flush_ALERT_buffer()
BufferedMessage* msg = g_messageQueueStart; BufferedMessage* msg = g_messageQueueStart;
int dev = (int)CVAR_GET_FLOAT("developer"); int dev = (int)CVAR_GET_FLOAT("developer");
while (msg) while (msg) {
{
if (msg->service == mlsDEV && dev == 0) { if (msg->service == mlsDEV && dev == 0) {
;
} }
else else {
{
ALERT(msg->atype, "b>%s %s\n", msg->prefix, msg->buf); ALERT(msg->atype, "b>%s %s\n", msg->prefix, msg->buf);
} }

View File

@ -1,10 +1,10 @@
#pragma once #pragma once
// max buffer size for printed messages enum
#define MAX_LOGMSG_LEN 1024 {
MAX_LOGMSG_LEN = 1024, // max buffer size for printed messages
// max buffer size for client messages MAX_CLIENTMSG_LEN = 128 // max buffer size for client messages
#define MAX_CLIENTMSG_LEN 128 };
extern cvar_t g_meta_debug; extern cvar_t g_meta_debug;

View File

@ -37,8 +37,6 @@ int g_requestid_counter = 0;
// Do startup operations... // Do startup operations...
void metamod_startup() void metamod_startup()
{ {
const char *cp;
char configFile[MAX_PATH]; char configFile[MAX_PATH];
char pluginFile[MAX_PATH]; char pluginFile[MAX_PATH];
char execFile[MAX_PATH]; char execFile[MAX_PATH];
@ -60,8 +58,7 @@ void metamod_startup()
// Get gamedir, very early on, because it seems we need it all over the // Get gamedir, very early on, because it seems we need it all over the
// place here at the start. // place here at the start.
if (!meta_init_gamedll()) if (!meta_init_gamedll()) {
{
META_ERROR("Failure to init game DLL; exiting..."); META_ERROR("Failure to init game DLL; exiting...");
do_exit(1); do_exit(1);
} }
@ -73,19 +70,18 @@ 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 && g_meta_debug.value == 0) if (CVAR_GET_FLOAT("developer") != 0.0 && g_meta_debug.value == 0.0)
CVAR_SET_FLOAT("meta_debug", 3.0); CVAR_SET_FLOAT("meta_debug", 3.0);
// Init default values // Init default values
g_config->init(g_global_options); g_config->init(g_global_options);
// Find config file // Find config file
if ((cp = LOCALINFO("mm_configfile")) && *cp != '\0') const char *cp = LOCALINFO("mm_configfile");
{ if (cp && *cp != '\0') {
META_LOG("Configfile specified via localinfo: %s", cp); META_LOG("Configfile specified via localinfo: %s", cp);
if (is_file_exists_in_gamedir(cp)) if (is_file_exists_in_gamedir(cp)) {
{
Q_strncpy(configFile, cp, sizeof configFile - 1); Q_strncpy(configFile, cp, sizeof configFile - 1);
configFile[sizeof configFile - 1] = '\0'; configFile[sizeof configFile - 1] = '\0';
} }
@ -93,8 +89,7 @@ void metamod_startup()
META_ERROR("Empty/missing config.ini file: %s; falling back to %s", cp, configFile); META_ERROR("Empty/missing config.ini file: %s; falling back to %s", cp, configFile);
} }
if (!is_file_exists_in_gamedir(configFile)) if (!is_file_exists_in_gamedir(configFile)) {
{
Q_strncpy(configFile, g_config->directory(), sizeof configFile - 1); Q_strncpy(configFile, g_config->directory(), sizeof configFile - 1);
configFile[sizeof configFile - 1] = '\0'; configFile[sizeof configFile - 1] = '\0';
@ -105,8 +100,7 @@ void metamod_startup()
} }
Q_strcat(configFile, "/" CONFIG_INI); Q_strcat(configFile, "/" CONFIG_INI);
if (!is_file_exists_in_gamedir(configFile)) if (!is_file_exists_in_gamedir(configFile)) {
{
META_DEBUG(2, "No config.ini file found: %s", CONFIG_INI); META_DEBUG(2, "No config.ini file found: %s", CONFIG_INI);
} }
} }
@ -116,39 +110,39 @@ void metamod_startup()
g_config->load(configFile); g_config->load(configFile);
// Now, override config options with localinfo commandline options. // Now, override config options with localinfo commandline options.
if ((cp = LOCALINFO("mm_debug")) && *cp != '\0') cp = LOCALINFO("mm_debug");
{ if (cp && *cp != '\0') {
META_LOG("Debuglevel specified via localinfo: %s", cp); META_LOG("Debuglevel specified via localinfo: %s", cp);
g_config->set("debuglevel", cp); g_config->set("debuglevel", cp);
} }
if ((cp = LOCALINFO("mm_gamedll")) && *cp != '\0') cp = LOCALINFO("mm_gamedll");
{ if (cp && *cp != '\0') {
META_LOG("Gamedll specified via localinfo: %s", cp); META_LOG("Gamedll specified via localinfo: %s", cp);
g_config->set("gamedll", cp); g_config->set("gamedll", cp);
} }
if ((cp = LOCALINFO("mm_pluginsfile")) && *cp != '\0') cp = LOCALINFO("mm_pluginsfile");
{ if (cp && *cp != '\0') {
META_LOG("Pluginsfile specified via localinfo: %s", cp); META_LOG("Pluginsfile specified via localinfo: %s", cp);
g_config->set("plugins_file", cp); g_config->set("plugins_file", cp);
} }
if ((cp = LOCALINFO("mm_execcfg")) && *cp != '\0') cp = LOCALINFO("mm_execcfg");
{ if (cp && *cp != '\0') {
META_LOG("Execcfg specified via localinfo: %s", cp); META_LOG("Execcfg specified via localinfo: %s", cp);
g_config->set("exec_cfg", cp); g_config->set("exec_cfg", cp);
} }
if ((cp = LOCALINFO("mm_clientmeta")) && *cp != '\0') cp = LOCALINFO("mm_clientmeta");
{ if (cp && *cp != '\0') {
META_LOG("Clientmeta specified via localinfo: %s", cp); META_LOG("Clientmeta specified via localinfo: %s", cp);
g_config->set("clientmeta", cp); g_config->set("clientmeta", cp);
} }
// 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->m_debuglevel != 0) if (g_config->m_debuglevel)
CVAR_SET_FLOAT("meta_debug", g_config->m_debuglevel); CVAR_SET_FLOAT("meta_debug", g_config->m_debuglevel);
if (!g_config->m_clientmeta) if (!g_config->m_clientmeta)
disable_clientcommand_fwd(); disable_clientcommand_fwd();
@ -197,8 +191,7 @@ void metamod_startup()
// In fact, we need gamedir even earlier, so moved up above. // In fact, we need gamedir even earlier, so moved up above.
// Load plugins file // Load plugins file
if (!is_file_exists_in_gamedir(pluginFile)) if (!is_file_exists_in_gamedir(pluginFile)) {
{
Q_strncpy(pluginFile, g_config->directory(), sizeof pluginFile - 1); Q_strncpy(pluginFile, g_config->directory(), sizeof pluginFile - 1);
pluginFile[sizeof pluginFile - 1] = '\0'; pluginFile[sizeof pluginFile - 1] = '\0';
@ -209,22 +202,19 @@ void metamod_startup()
} }
Q_strcat(pluginFile, "/" PLUGINS_INI); Q_strcat(pluginFile, "/" PLUGINS_INI);
if (!is_file_exists_in_gamedir(pluginFile)) if (!is_file_exists_in_gamedir(pluginFile)) {
{
META_DEBUG(2, "No plugins.ini file found: %s", PLUGINS_INI); META_DEBUG(2, "No plugins.ini file found: %s", PLUGINS_INI);
} }
} }
g_plugins = new MPluginList(pluginFile); g_plugins = new MPluginList(pluginFile);
if (!meta_load_gamedll()) if (!meta_load_gamedll()) {
{
META_ERROR("Failure to load game DLL; exiting..."); META_ERROR("Failure to load game DLL; exiting...");
do_exit(1); do_exit(1);
} }
if (!g_plugins->load()) if (!g_plugins->load()) {
{
META_ERROR("Failure to load plugins..."); META_ERROR("Failure to load plugins...");
// Exit on failure here? Dunno... // Exit on failure here? Dunno...
} }
@ -237,18 +227,15 @@ 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 (g_config->m_exec_cfg) if (g_config->m_exec_cfg) {
{
Q_strncpy(execFile, g_config->m_exec_cfg, sizeof execFile - 1); Q_strncpy(execFile, g_config->m_exec_cfg, sizeof execFile - 1);
execFile[sizeof execFile - 1] = '\0'; execFile[sizeof execFile - 1] = '\0';
} }
if (is_file_exists_in_gamedir(execFile)) if (is_file_exists_in_gamedir(execFile)) {
{
if (execFile[0] == '/') if (execFile[0] == '/')
META_ERROR("Cannot exec absolute pathnames: %s", execFile); META_ERROR("Cannot exec absolute pathnames: %s", execFile);
else else {
{
char cmd[NAME_MAX]; char cmd[NAME_MAX];
META_LOG("Exec'ing metamod exec.cfg: %s...", execFile); META_LOG("Exec'ing metamod exec.cfg: %s...", execFile);
Q_snprintf(cmd, sizeof cmd, "exec %s\n", execFile); Q_snprintf(cmd, sizeof cmd, "exec %s\n", execFile);
@ -262,11 +249,9 @@ void metamod_startup()
// - ME_NULLRESULT _getcwd failed // - ME_NULLRESULT _getcwd failed
bool meta_init_gamedll() bool meta_init_gamedll()
{ {
char gamedir[PATH_MAX];
char *cp;
Q_memset(&g_GameDLL, 0, sizeof g_GameDLL); Q_memset(&g_GameDLL, 0, sizeof g_GameDLL);
char gamedir[PATH_MAX];
GET_GAME_DIR(gamedir); GET_GAME_DIR(gamedir);
normalize_path(gamedir); normalize_path(gamedir);
@ -280,26 +265,23 @@ bool meta_init_gamedll()
// Note: the code has always assumed the server op wouldn't do: // Note: the code has always assumed the server op wouldn't do:
// hlds -game other/firearms // hlds -game other/firearms
// //
if (is_abs_path(gamedir)) if (is_abs_path(gamedir)) {
{
// 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(g_GameDLL.gamedir, gamedir, sizeof g_GameDLL.gamedir - 1); Q_strncpy(g_GameDLL.gamedir, gamedir, sizeof g_GameDLL.gamedir - 1);
g_GameDLL.gamedir[sizeof g_GameDLL.gamedir - 1] = '\0'; g_GameDLL.gamedir[sizeof g_GameDLL.gamedir - 1] = '\0';
cp = Q_strrchr(gamedir, '/') + 1; char* cp = Q_strrchr(gamedir, '/') + 1;
Q_strncpy(g_GameDLL.name, cp, sizeof g_GameDLL.name - 1); Q_strncpy(g_GameDLL.name, cp, sizeof g_GameDLL.name - 1);
g_GameDLL.name[sizeof g_GameDLL.name - 1] = '\0'; g_GameDLL.name[sizeof g_GameDLL.name - 1] = '\0';
} }
else else {
{
// New style; GET_GAME_DIR returned game name. Copy this into our // New style; GET_GAME_DIR returned game name. Copy this into our
// game name, and prepend the current working directory. // game name, and prepend the current working directory.
char buf[PATH_MAX]; char buf[PATH_MAX];
if (!_getcwd(buf, sizeof buf)) if (!_getcwd(buf, sizeof buf)) {
{
META_WARNING("dll: Couldn't get cwd; %s", strerror(errno)); META_WARNING("dll: Couldn't get cwd; %s", strerror(errno));
return false; return false;
} }
@ -389,16 +371,14 @@ bool get_function_table_old(const char* ifname, int ifvers_mm, table_t*& table,
// (GiveFnptrsToDll, GetEntityAPI, GetEntityAPI2) // (GiveFnptrsToDll, GetEntityAPI, GetEntityAPI2)
bool meta_load_gamedll() bool meta_load_gamedll()
{ {
if (!setup_gamedll(&g_GameDLL)) if (!setup_gamedll(&g_GameDLL)) {
{
META_ERROR("dll: Unrecognized game: %s", g_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 (!g_GameDLL.sys_module.load(g_GameDLL.pathname)) if (!g_GameDLL.sys_module.load(g_GameDLL.pathname)) {
{
META_ERROR("dll: Couldn't load game DLL %s: %s", g_GameDLL.pathname, CSysModule::getloaderror()); META_ERROR("dll: Couldn't load game DLL %s: %s", g_GameDLL.pathname, CSysModule::getloaderror());
return false; return false;
} }
@ -411,14 +391,11 @@ bool meta_load_gamedll()
// 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)g_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(&g_meta_engfuncs, gpGlobals); pfn_give_engfuncs(&g_meta_engfuncs, gpGlobals);
META_DEBUG(3, "dll: Game '%s': Called GiveFnptrsToDll", g_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'", g_GameDLL.name); META_ERROR("dll: Couldn't find GiveFnptrsToDll() in game DLL '%s'", g_GameDLL.name);
return false; return false;
} }

View File

@ -45,7 +45,8 @@ bool rehlds_api_try_init(CSysModule* engineModule, char* failureReason)
return true; return true;
} }
bool meta_init_rehlds_api() { bool meta_init_rehlds_api()
{
char failReason[2048]; char failReason[2048];
#ifdef WIN32 #ifdef WIN32

View File

@ -9,8 +9,7 @@ MPluginList::MPluginList(const char* ifile) : m_max_loaded_count(0)
// initialize array // initialize array
Q_memset(m_plist, 0, sizeof m_plist); Q_memset(m_plist, 0, sizeof m_plist);
for (int i = 0; i < MAX_PLUGINS; i++) for (int i = 0; i < MAX_PLUGINS; i++) {
{
new(m_plist + i) MPlugin(i + 1); // 1-based new(m_plist + i) MPlugin(i + 1); // 1-based
} }
@ -33,8 +32,7 @@ MPlugin *MPluginList::find(module_handle_t handle)
if (!handle) if (!handle)
return nullptr; return nullptr;
for (int i = 0; i < m_max_loaded_count; i++) for (int i = 0; i < m_max_loaded_count; i++) {
{
if (m_plist[i].m_status < PL_VALID) if (m_plist[i].m_status < PL_VALID)
continue; continue;
if (handle == m_plist[i].m_sys_module.gethandle()) if (handle == m_plist[i].m_sys_module.gethandle())
@ -63,8 +61,7 @@ MPlugin *MPluginList::find(plid_t id)
if (!id) if (!id)
return nullptr; return nullptr;
for (int i = 0; i < m_max_loaded_count; i++) for (int i = 0; i < m_max_loaded_count; i++) {
{
if (m_plist[i].m_status < PL_VALID) if (m_plist[i].m_status < PL_VALID)
continue; continue;
if (m_plist[i].m_info == id) if (m_plist[i].m_info == id)
@ -82,15 +79,13 @@ MPlugin *MPluginList::find(const char* findpath)
META_DEBUG(8, "Looking for loaded plugin with path: %s", findpath); META_DEBUG(8, "Looking for loaded plugin with path: %s", findpath);
for (int i = 0; i < m_max_loaded_count; i++) for (int i = 0; i < m_max_loaded_count; i++) {
{
META_DEBUG(9, "Looking at: plugin %s loadedpath: %s", m_plist[i].m_file, m_plist[i].m_pathname); META_DEBUG(9, "Looking at: plugin %s loadedpath: %s", m_plist[i].m_file, m_plist[i].m_pathname);
if (m_plist[i].m_status < PL_VALID) if (m_plist[i].m_status < PL_VALID)
continue; continue;
if (!Q_strcmp(m_plist[i].m_pathname, findpath)) if (!Q_strcmp(m_plist[i].m_pathname, findpath)) {
{
META_DEBUG(8, "Found loaded plugin %s", m_plist[i].m_file); META_DEBUG(8, "Found loaded plugin %s", m_plist[i].m_file);
return &m_plist[i]; return &m_plist[i];
} }
@ -124,8 +119,7 @@ MPlugin *MPluginList::find_match(const char *prefix, bool& unique)
MPlugin* pfound = nullptr; MPlugin* pfound = nullptr;
size_t len = Q_strlen(prefix); size_t len = Q_strlen(prefix);
for (int i = 0; i < m_max_loaded_count; i++) for (int i = 0; i < m_max_loaded_count; i++) {
{
auto plug = &m_plist[i]; auto plug = &m_plist[i];
if (plug->m_status < PL_VALID) if (plug->m_status < PL_VALID)
continue; continue;
@ -133,8 +127,7 @@ MPlugin *MPluginList::find_match(const char *prefix, bool& unique)
if (plug->info() && !Q_strnicmp(plug->info()->name, prefix, len) if (plug->info() && !Q_strnicmp(plug->info()->name, prefix, len)
|| !Q_strnicmp(plug->m_desc, prefix, len) || !Q_strnicmp(plug->m_desc, prefix, len)
|| !Q_strnicmp(plug->m_file, prefix, len) || !Q_strnicmp(plug->m_file, prefix, len)
|| plug->info() && !Q_strnicmp(plug->info()->logtag, prefix, len)) || plug->info() && !Q_strnicmp(plug->info()->logtag, prefix, len)) {
{
if (pfound) { if (pfound) {
unique = false; unique = false;
break; break;
@ -156,8 +149,7 @@ MPlugin *MPluginList::find_match(MPlugin* pmatch)
return nullptr; return nullptr;
} }
for (int i = 0; i < m_max_loaded_count; i++) for (int i = 0; i < m_max_loaded_count; i++) {
{
auto plug = &m_plist[i]; auto plug = &m_plist[i];
if (pmatch->platform_match(plug)) { if (pmatch->platform_match(plug)) {
@ -187,28 +179,23 @@ MPlugin* MPluginList::plugin_addload(plid_t plid, const char* fname, PLUG_LOADTI
} }
auto pl_found = find(pl_temp.m_pathname); auto pl_found = find(pl_temp.m_pathname);
if (pl_found) if (pl_found) {
{
META_DEBUG(1, "Plugin '%s' already in current list; file=%s desc='%s'", pl_temp.m_file, pl_found->m_file, pl_found->m_desc); META_DEBUG(1, "Plugin '%s' already in current list; file=%s desc='%s'", pl_temp.m_file, pl_found->m_file, pl_found->m_desc);
return pl_found; return pl_found;
} }
auto pl_added = add(&pl_temp); auto pl_added = add(&pl_temp);
if (!pl_added) if (!pl_added) {
{
META_DEBUG(1, "Couldn't add plugin '%s' to list; see log", pl_temp.m_desc); META_DEBUG(1, "Couldn't add plugin '%s' to list; see log", pl_temp.m_desc);
return nullptr; return nullptr;
} }
pl_added->m_action = PA_LOAD; pl_added->m_action = PA_LOAD;
if (!pl_added->load(now)) if (!pl_added->load(now)) {
{ if (pl_added->m_status == PL_OPENED) {
if (pl_added->m_status == PL_OPENED)
{
META_DEBUG(1, "Opened plugin '%s', but failed to attach; see log", pl_added->m_desc); META_DEBUG(1, "Opened plugin '%s', but failed to attach; see log", pl_added->m_desc);
} }
else else {
{
META_DEBUG(1, "Couldn't load plugin '%s'; see log", pl_added->m_desc); META_DEBUG(1, "Couldn't load plugin '%s'; see log", pl_added->m_desc);
} }
return nullptr; return nullptr;
@ -239,8 +226,7 @@ MPlugin* MPluginList::add(MPlugin* padd)
auto iplug = find_empty_slot(); auto iplug = find_empty_slot();
// couldn't find a slot to use // couldn't find a slot to use
if (!iplug) if (!iplug) {
{
META_ERROR("Couldn't add plugin '%s' to list; reached max plugins (%d)", padd->m_file, MAX_PLUGINS); META_ERROR("Couldn't add plugin '%s' to list; reached max plugins (%d)", padd->m_file, MAX_PLUGINS);
return nullptr; return nullptr;
} }
@ -276,23 +262,20 @@ bool MPluginList::ini_startup()
char line[MAX_STRBUF_LEN]; char line[MAX_STRBUF_LEN];
int n, ln; int n, ln;
if (!is_file_exists_in_gamedir(m_inifile)) if (!is_file_exists_in_gamedir(m_inifile)) {
{
META_ERROR("ini: Metamod plugins file empty or missing: %s", m_inifile); META_ERROR("ini: Metamod plugins file empty or missing: %s", m_inifile);
return false; return false;
} }
full_gamedir_path(m_inifile, m_inifile); full_gamedir_path(m_inifile, m_inifile);
FILE* fp = fopen(m_inifile, "r"); FILE* fp = fopen(m_inifile, "r");
if (!fp) if (!fp) {
{
META_ERROR("ini: Unable to open plugins file '%s': %s", m_inifile, strerror(errno)); META_ERROR("ini: Unable to open plugins file '%s': %s", m_inifile, strerror(errno));
return false; return false;
} }
META_LOG("ini: Begin reading plugins list: %s", m_inifile); META_LOG("ini: Begin reading plugins list: %s", m_inifile);
for (n = 0, ln = 1; !feof(fp) && fgets(line, sizeof line, fp) && n < MAX_PLUGINS; ln++) for (n = 0 , ln = 1; !feof(fp) && fgets(line, sizeof line, fp) && n < MAX_PLUGINS; ln++) {
{
// Remove line terminations. // Remove line terminations.
char* cp; char* cp;
if ((cp = Q_strrchr(line, '\r'))) if ((cp = Q_strrchr(line, '\r')))
@ -306,8 +289,7 @@ bool MPluginList::ini_startup()
continue; continue;
// Check for a duplicate - an existing entry with this pathname. // Check for a duplicate - an existing entry with this pathname.
if (find(m_plist[n].m_pathname)) if (find(m_plist[n].m_pathname)) {
{
// Should we check platform specific level here? // Should we check platform specific level here?
META_INFO("ini: Skipping duplicate plugin, line %d of %s: %s", ln, m_inifile, m_plist[n].m_pathname); META_INFO("ini: Skipping duplicate plugin, line %d of %s: %s", ln, m_inifile, m_plist[n].m_pathname);
continue; continue;
@ -316,8 +298,7 @@ bool MPluginList::ini_startup()
// Check for a matching platform with different platform specifics // Check for a matching platform with different platform specifics
// level. // level.
auto pmatch = find_match(&m_plist[n]); auto pmatch = find_match(&m_plist[n]);
if (pmatch) if (pmatch) {
{
META_DEBUG(1, "ini: Plugin in line %d overrides existing plugin", ln); META_DEBUG(1, "ini: Plugin in line %d overrides existing plugin", ln);
int index = pmatch->m_index; int index = pmatch->m_index;
Q_memset(pmatch, 0, sizeof(MPlugin)); Q_memset(pmatch, 0, sizeof(MPlugin));
@ -344,15 +325,13 @@ bool MPluginList::ini_refresh()
int n, ln; int n, ln;
FILE* fp = fopen(m_inifile, "r"); FILE* fp = fopen(m_inifile, "r");
if (!fp) if (!fp) {
{
META_ERROR("ini: Unable to open plugins file '%s': %s", m_inifile, strerror(errno)); META_ERROR("ini: Unable to open plugins file '%s': %s", m_inifile, strerror(errno));
return false; return false;
} }
META_LOG("ini: Begin re-reading plugins list: %s", m_inifile); META_LOG("ini: Begin re-reading plugins list: %s", m_inifile);
for (n = 0 , ln = 1; !feof(fp) && fgets(line, sizeof line, fp) && n < MAX_PLUGINS; ln++) for (n = 0 , ln = 1; !feof(fp) && fgets(line, sizeof line, fp) && n < MAX_PLUGINS; ln++) {
{
// Remove line terminations. // Remove line terminations.
char* cp; char* cp;
if ((cp = Q_strrchr(line, '\r'))) if ((cp = Q_strrchr(line, '\r')))
@ -363,38 +342,32 @@ bool MPluginList::ini_refresh()
// Parse into a temp plugin // Parse into a temp plugin
MPlugin pl_temp = {}; MPlugin pl_temp = {};
if (!pl_temp.ini_parseline(line)) if (!pl_temp.ini_parseline(line)) {
{
META_ERROR("ini: Skipping malformed line %d of %s", ln, m_inifile); META_ERROR("ini: Skipping malformed line %d of %s", ln, m_inifile);
continue; continue;
} }
// Try to find plugin with this pathname in the current list of // Try to find plugin with this pathname in the current list of
// plugins. // plugins.
auto pl_found = find(pl_temp.m_pathname); auto pl_found = find(pl_temp.m_pathname);
if (!pl_found) if (!pl_found) {
{
// Check for a matching platform with higher platform specifics // Check for a matching platform with higher platform specifics
// level. // level.
pl_found = find_match(&pl_temp); pl_found = find_match(&pl_temp);
if (pl_found) if (pl_found) {
{ if (pl_found->m_action == PA_LOAD) {
if (pl_found->m_action == PA_LOAD)
{
META_DEBUG(1, "ini: Plugin in line %d overrides loading of plugin", ln); META_DEBUG(1, "ini: Plugin in line %d overrides loading of plugin", ln);
int _index = pl_found->m_index; int _index = pl_found->m_index;
Q_memset(pl_found, 0, sizeof(MPlugin)); Q_memset(pl_found, 0, sizeof(MPlugin));
pl_found->m_index = _index; pl_found->m_index = _index;
} }
else else {
{
META_DEBUG(1, "ini: Plugin in line %d should override existing plugin. Unable to comply.", ln); META_DEBUG(1, "ini: Plugin in line %d should override existing plugin. Unable to comply.", ln);
continue; continue;
} }
} }
// new plugin; add to list // new plugin; add to list
auto pl_added = add(&pl_temp); auto pl_added = add(&pl_temp);
if (pl_added) if (pl_added) {
{
// try to load this plugin at the next opportunity // try to load this plugin at the next opportunity
pl_added->m_action = PA_LOAD; pl_added->m_action = PA_LOAD;
} }
@ -402,26 +375,22 @@ bool MPluginList::ini_refresh()
// error details logged in add() // error details logged in add()
continue; continue;
} }
else else {
{
// This plugin is already in the current list of plugins. // This plugin is already in the current list of plugins.
// Pathname already matches. Recopy desc, if specified in // Pathname already matches. Recopy desc, if specified in
// plugins.ini. // plugins.ini.
if (pl_temp.m_desc[0] != '<') if (pl_temp.m_desc[0] != '<') {
{
Q_strncpy(pl_found->m_desc, pl_temp.m_desc, sizeof pl_found->m_desc - 1); Q_strncpy(pl_found->m_desc, pl_temp.m_desc, sizeof pl_found->m_desc - 1);
pl_found->m_desc[sizeof pl_found->m_desc - 1] = '\0'; pl_found->m_desc[sizeof pl_found->m_desc - 1] = '\0';
} }
// Check the file to see if it looks like it's been modified // Check the file to see if it looks like it's been modified
// since we last loaded it. // since we last loaded it.
if (!pl_found->newer_file()) if (!pl_found->newer_file()) {
{
pl_found->m_action = PA_KEEP; pl_found->m_action = PA_KEEP;
} }
// Newer file on disk. // Newer file on disk.
else if (pl_found->m_status >= PL_OPENED) else if (pl_found->m_status >= PL_OPENED) {
{
META_DEBUG(2, "ini: Plugin '%s' has newer file on disk", pl_found->m_desc); META_DEBUG(2, "ini: Plugin '%s' has newer file on disk", pl_found->m_desc);
pl_found->m_action = PA_RELOAD; pl_found->m_action = PA_RELOAD;
} }
@ -449,16 +418,14 @@ bool MPluginList::ini_refresh()
bool MPluginList::cmd_addload(const char* args) bool MPluginList::cmd_addload(const char* args)
{ {
MPlugin pl_temp = {}; MPlugin pl_temp = {};
if (!pl_temp.cmd_parseline(args)) if (!pl_temp.cmd_parseline(args)) {
{
META_CONS("Couldn't parse 'meta load' arguments: %s", args); META_CONS("Couldn't parse 'meta load' arguments: %s", args);
return false; return false;
} }
// resolve given path into a file; accepts various "shortcut" // resolve given path into a file; accepts various "shortcut"
// pathnames. // pathnames.
if (!pl_temp.resolve()) if (!pl_temp.resolve()) {
{
// Couldn't find a matching file on disk // Couldn't find a matching file on disk
META_CONS("Couldn't resolve given path into a file: %s", pl_temp.m_file); META_CONS("Couldn't resolve given path into a file: %s", pl_temp.m_file);
return false; return false;
@ -467,24 +434,21 @@ bool MPluginList::cmd_addload(const char* args)
// Try to find plugin with this pathname in the current list of // Try to find plugin with this pathname in the current list of
// plugins. // plugins.
auto pl_found = find(pl_temp.m_pathname); auto pl_found = find(pl_temp.m_pathname);
if (pl_found) if (pl_found) {
{
// Already in list // Already in list
META_CONS("Plugin '%s' already in current list; file=%s desc='%s'", pl_temp.m_file, pl_found->m_file, pl_found->m_desc); META_CONS("Plugin '%s' already in current list; file=%s desc='%s'", pl_temp.m_file, pl_found->m_file, pl_found->m_desc);
return false; return false;
} }
// new plugin; add to list // new plugin; add to list
auto pl_added = add(&pl_temp); auto pl_added = add(&pl_temp);
if (!pl_added) if (!pl_added) {
{
META_CONS("Couldn't add plugin '%s' to list; see log", pl_temp.m_desc); META_CONS("Couldn't add plugin '%s' to list; see log", pl_temp.m_desc);
return false; return false;
} }
// try to load new plugin // try to load new plugin
pl_added->m_action = PA_LOAD; pl_added->m_action = PA_LOAD;
if (!pl_added->load(PT_ANYTIME)) if (!pl_added->load(PT_ANYTIME)) {
{
// load failed // load failed
if (pl_added->m_status == PL_OPENED) if (pl_added->m_status == PL_OPENED)
META_CONS("Opened plugin '%s', but failed to attach; see log", pl_added->m_desc); META_CONS("Opened plugin '%s', but failed to attach; see log", pl_added->m_desc);
@ -505,15 +469,13 @@ bool MPluginList::cmd_addload(const char* args)
bool MPluginList::load() bool MPluginList::load()
{ {
int n = 0; int n = 0;
if (!ini_startup()) if (!ini_startup()) {
{
META_ERROR("Problem loading plugins.ini: %s", m_inifile); META_ERROR("Problem loading plugins.ini: %s", m_inifile);
return false; return false;
} }
META_LOG("dll: Loading plugins..."); META_LOG("dll: Loading plugins...");
for (int i = 0; i < m_max_loaded_count; i++) for (int i = 0; i < m_max_loaded_count; i++) {
{
if (m_plist[i].m_status < PL_VALID) if (m_plist[i].m_status < PL_VALID)
continue; continue;
@ -534,21 +496,18 @@ bool MPluginList::refresh(PLUG_LOADTIME now)
{ {
int ndone = 0, nkept = 0, nloaded = 0, nunloaded = 0, nreloaded = 0, ndelayed = 0; int ndone = 0, nkept = 0, nloaded = 0, nunloaded = 0, nreloaded = 0, ndelayed = 0;
if (!ini_refresh()) if (!ini_refresh()) {
{
META_ERROR("dll: Problem reloading plugins.ini: %s", m_inifile); META_ERROR("dll: Problem reloading plugins.ini: %s", m_inifile);
return false; return false;
} }
META_LOG("dll: Updating plugins..."); META_LOG("dll: Updating plugins...");
for (int i = 0; i < m_max_loaded_count; i++) for (int i = 0; i < m_max_loaded_count; i++) {
{
auto iplug = &m_plist[i]; auto iplug = &m_plist[i];
if (iplug->m_status < PL_VALID) if (iplug->m_status < PL_VALID)
continue; continue;
switch (iplug->m_action) switch (iplug->m_action) {
{
case PA_KEEP: case PA_KEEP:
META_DEBUG(1, "Keeping plugin '%s'", iplug->m_desc); META_DEBUG(1, "Keeping plugin '%s'", iplug->m_desc);
iplug->m_action = PA_NONE; iplug->m_action = PA_NONE;
@ -570,8 +529,7 @@ bool MPluginList::refresh(PLUG_LOADTIME now)
break; break;
case PA_NONE: case PA_NONE:
// If previously loaded from ini, but apparently removed from new ini. // If previously loaded from ini, but apparently removed from new ini.
if (iplug->m_source == PS_INI && iplug->m_status >= PL_RUNNING) if (iplug->m_source == PS_INI && iplug->m_status >= PL_RUNNING) {
{
META_DEBUG(1, "Unloading plugin '%s'", iplug->m_desc); META_DEBUG(1, "Unloading plugin '%s'", iplug->m_desc);
iplug->m_action = PA_UNLOAD; iplug->m_action = PA_UNLOAD;
if (iplug->unload(now, PNL_INI_DELETED)) if (iplug->unload(now, PNL_INI_DELETED))
@ -614,8 +572,7 @@ bool MPluginList::refresh(PLUG_LOADTIME now)
// Re-enable any plugins currently paused. // Re-enable any plugins currently paused.
void MPluginList::unpause_all() void MPluginList::unpause_all()
{ {
for (int i = 0; i < m_max_loaded_count; i++) for (int i = 0; i < m_max_loaded_count; i++) {
{
auto iplug = &m_plist[i]; auto iplug = &m_plist[i];
if (iplug->m_status == PL_PAUSED) if (iplug->m_status == PL_PAUSED)
iplug->unpause(); iplug->unpause();
@ -626,8 +583,7 @@ void MPluginList::unpause_all()
// until changelevel. // until changelevel.
void MPluginList::retry_all(PLUG_LOADTIME now) void MPluginList::retry_all(PLUG_LOADTIME now)
{ {
for (int i = 0; i < m_max_loaded_count; i++) for (int i = 0; i < m_max_loaded_count; i++) {
{
auto iplug = &m_plist[i]; auto iplug = &m_plist[i];
if (iplug->m_action != PA_NONE) if (iplug->m_action != PA_NONE)
iplug->retry(now, PNL_DELAYED); iplug->retry(now, PNL_DELAYED);
@ -648,8 +604,7 @@ void MPluginList::show(int source_index)
META_CONS(" %*s %-*s %-4s %-4s %-*s v%-*s %-*s %-5s %-5s", WIDTH_MAX_PLUGINS, "", sizeof desc - 1, "description", "stat", "pend", META_CONS(" %*s %-*s %-4s %-4s %-*s v%-*s %-*s %-5s %-5s", WIDTH_MAX_PLUGINS, "", sizeof desc - 1, "description", "stat", "pend",
sizeof file - 1, "file", sizeof vers - 1, "ers", 2 + WIDTH_MAX_PLUGINS, "src", "load ", "unlod"); sizeof file - 1, "file", sizeof vers - 1, "ers", 2 + WIDTH_MAX_PLUGINS, "src", "load ", "unlod");
for (int i = 0; i < m_max_loaded_count; i++) for (int i = 0; i < m_max_loaded_count; i++) {
{
auto pl = &m_plist[i]; auto pl = &m_plist[i];
if (pl->m_status < PL_VALID) if (pl->m_status < PL_VALID)
continue; continue;
@ -663,13 +618,11 @@ void MPluginList::show(int source_index)
Q_strncpy(file, pl->m_file, sizeof file - 1); Q_strncpy(file, pl->m_file, sizeof file - 1);
file[sizeof file - 1] = '\0'; file[sizeof file - 1] = '\0';
if (pl->info() && pl->info()->version) if (pl->info() && pl->info()->version) {
{
Q_strncpy(vers, pl->info()->version, sizeof vers - 1); Q_strncpy(vers, pl->info()->version, sizeof vers - 1);
vers[sizeof vers - 1] = '\0'; vers[sizeof vers - 1] = '\0';
} }
else else {
{
Q_strncpy(vers, " -", sizeof vers - 1); Q_strncpy(vers, " -", sizeof vers - 1);
vers[sizeof vers - 1] = '\0'; vers[sizeof vers - 1] = '\0';
} }
@ -696,8 +649,7 @@ void MPluginList::show_client(edict_t *pEntity)
int n = 0; int n = 0;
META_CLIENT(pEntity, "Currently running plugins:"); META_CLIENT(pEntity, "Currently running plugins:");
for (int i = 0; i < m_max_loaded_count; i++) for (int i = 0; i < m_max_loaded_count; i++) {
{
auto pl = &m_plist[i]; auto pl = &m_plist[i];
if (pl->m_status != PL_RUNNING || !pl->info()) if (pl->m_status != PL_RUNNING || !pl->info())
continue; continue;
@ -719,8 +671,7 @@ bool MPluginList::found_child_plugins(int source_index) const
if (source_index <= 0) if (source_index <= 0)
return false; return false;
for (int i = 0; i < m_max_loaded_count; i++) for (int i = 0; i < m_max_loaded_count; i++) {
{
if (m_plist[i].m_status < PL_VALID) if (m_plist[i].m_status < PL_VALID)
continue; continue;
@ -736,8 +687,7 @@ void MPluginList::clear_source_plugin_index(int source_index)
if (source_index <= 0) if (source_index <= 0)
return; return;
for (int i = 0; i < m_max_loaded_count; i++) for (int i = 0; i < m_max_loaded_count; i++) {
{
if (m_plist[i].m_status < PL_VALID) if (m_plist[i].m_status < PL_VALID)
continue; continue;

View File

@ -12,8 +12,7 @@ void MPlayer::set_cvar_query(const char *cvar)
// Do not allow NULL as queried cvar since we use this as // Do not allow NULL as queried cvar since we use this as
// return value in is_querying_cvar as indication if a // return value in is_querying_cvar as indication if a
// client cvar is queried. // client cvar is queried.
if (!cvar) if (!cvar) {
{
return; return;
} }
@ -34,8 +33,7 @@ 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() const const char* MPlayer::is_querying_cvar() const
{ {
if (m_isQueried) if (m_isQueried) {
{
return g_cvarName; return g_cvarName;
} }
@ -62,8 +60,7 @@ void MPlayerList::clear_player_cvar_query(const edict_t *pEntity, const char *cv
void MPlayerList::clear_all_cvar_queries() void MPlayerList::clear_all_cvar_queries()
{ {
for (int indx = 1; indx <= gpGlobals->maxClients; indx++) for (int indx = 1; indx <= gpGlobals->maxClients; indx++) {
{
m_players[indx].clear_cvar_query(); m_players[indx].clear_cvar_query();
} }
} }

View File

@ -70,14 +70,12 @@ bool MPlugin::ini_parseline(char *line)
// Grab description. // Grab description.
// Just get the the rest of the line, minus line-termination. // Just get the the rest of the line, minus line-termination.
token = strtok_r(nullptr, "\n\r", &ptr_token); token = strtok_r(nullptr, "\n\r", &ptr_token);
if (token) if (token) {
{
token = token + strspn(token, " \t"); // skip whitespace token = token + strspn(token, " \t"); // skip whitespace
Q_strncpy(m_desc, token, sizeof m_desc - 1); Q_strncpy(m_desc, token, sizeof m_desc - 1);
m_desc[sizeof m_desc - 1] = '\0'; m_desc[sizeof m_desc - 1] = '\0';
} }
else else {
{
// If no description is specified, temporarily use plugin file, // If no description is specified, temporarily use plugin file,
// until plugin can be queried, and desc replaced with info->name. // until plugin can be queried, and desc replaced with info->name.
Q_snprintf(m_desc, sizeof m_desc, "<%s>", m_file); Q_snprintf(m_desc, sizeof m_desc, "<%s>", m_file);
@ -550,13 +548,12 @@ bool MPlugin::reload(PLUG_LOADTIME now, PL_UNLOAD_REASON reason)
// try to reload again at next opportunity // try to reload again at next opportunity
return false; return false;
} }
else {
META_DEBUG(2, "dll: Failed reload plugin '%s'; would not be able to reattach now: allowed=%s; now=%s", m_desc, str_loadable(), str_loadtime(now, SL_SIMPLE)); META_DEBUG(2, "dll: Failed reload plugin '%s'; would not be able to reattach now: allowed=%s; now=%s", m_desc, str_loadable(), str_loadtime(now, SL_SIMPLE));
// don't try to reload again later // don't try to reload again later
m_action = PA_NONE; m_action = PA_NONE;
return false; return false;
} }
}
if (m_status < PL_RUNNING) { if (m_status < PL_RUNNING) {
META_WARNING("dll: Plugin '%s' isn't running; Forcing unload plugin for reloading", m_desc); META_WARNING("dll: Plugin '%s' isn't running; Forcing unload plugin for reloading", m_desc);
@ -744,8 +741,7 @@ bool MPlugin::query()
// engine functions like AlertMessage, which have to be passed along via // engine functions like AlertMessage, which have to be passed along via
// GiveFnptrsToDll. // GiveFnptrsToDll.
auto pfn_query = (META_QUERY_FN)m_sys_module.getsym("Meta_Query"); auto pfn_query = (META_QUERY_FN)m_sys_module.getsym("Meta_Query");
if (!pfn_query) if (!pfn_query) {
{
META_ERROR("dll: Failed query plugin '%s'; Couldn't find Meta_Query(): %s", m_desc, "function not found"); META_ERROR("dll: Failed query plugin '%s'; Couldn't find Meta_Query(): %s", m_desc, "function not found");
// caller will dlclose() // caller will dlclose()
return false; return false;
@ -766,21 +762,18 @@ bool MPlugin::query()
// plugin can NOT use any g_engine functions, as they haven't been // plugin can NOT use any g_engine functions, as they haven't been
// provided yet (done next, in GiveFnptrsToDll). // provided yet (done next, in GiveFnptrsToDll).
auto pfn_init = (META_INIT_FN)m_sys_module.getsym("Meta_Init"); auto pfn_init = (META_INIT_FN)m_sys_module.getsym("Meta_Init");
if (pfn_init) if (pfn_init) {
{
pfn_init(); pfn_init();
META_DEBUG(6, "dll: Plugin '%s': Called Meta_Init()", m_desc); META_DEBUG(6, "dll: Plugin '%s': Called Meta_Init()", m_desc);
} }
else else {
{
META_DEBUG(5, "dll: no Meta_Init present in plugin '%s'", m_desc); META_DEBUG(5, "dll: no Meta_Init present in plugin '%s'", m_desc);
// don't return; not an error // don't return; not an error
} }
// pass on engine function table and globals to plugin // pass on engine function table and globals to plugin
auto pfn_give_engfuncs = (GIVE_ENGINE_FUNCTIONS_FN)m_sys_module.getsym("GiveFnptrsToDll"); auto pfn_give_engfuncs = (GIVE_ENGINE_FUNCTIONS_FN)m_sys_module.getsym("GiveFnptrsToDll");
if (!pfn_give_engfuncs) if (!pfn_give_engfuncs) {
{
META_ERROR("dll: Failed query plugin '%s'; Couldn't find GiveFnptrsToDll(): %s", m_desc, "function not found"); META_ERROR("dll: Failed query plugin '%s'; Couldn't find GiveFnptrsToDll(): %s", m_desc, "function not found");
return false; return false;
} }
@ -796,12 +789,10 @@ bool MPlugin::query()
// same reason. // same reason.
Q_memcpy(&m_mutil_funcs, &g_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) {
{
META_ERROR("dll: Failed query plugin '%s'; Meta_Query returned error", m_desc); META_ERROR("dll: Failed query plugin '%s'; Meta_Query returned error", m_desc);
} }
else else {
{
META_DEBUG(6, "dll: Plugin '%s': Called Meta_Query() successfully", m_desc); META_DEBUG(6, "dll: Plugin '%s': Called Meta_Query() successfully", m_desc);
} }
@ -820,23 +811,20 @@ bool MPlugin::query()
return false; return false;
} }
if (Q_strcmp(m_info->ifvers, META_INTERFACE_VERSION)) if (Q_strcmp(m_info->ifvers, META_INTERFACE_VERSION)) {
{
int mmajor, mminor, pmajor, pminor; int mmajor, mminor, pmajor, pminor;
META_DEBUG(3, "dll: Note: Plugin '%s' interface version didn't match; expected %s, found %s", m_desc, META_INTERFACE_VERSION, m_info->ifvers); META_DEBUG(3, "dll: Note: Plugin '%s' interface version didn't match; expected %s, found %s", m_desc, META_INTERFACE_VERSION, m_info->ifvers);
sscanf(META_INTERFACE_VERSION, "%i:%i", &mmajor, &mminor); sscanf(META_INTERFACE_VERSION, "%i:%i", &mmajor, &mminor);
sscanf(m_info->ifvers, "%i:%i", &pmajor, &pminor); sscanf(m_info->ifvers, "%i:%i", &pmajor, &pminor);
// If plugin has later interface version, it's incompatible // If plugin has later interface version, it's incompatible
// (update metamod). // (update metamod).
if (pmajor > mmajor || (pmajor == mmajor && pminor > mminor)) if (pmajor > mmajor || (pmajor == mmajor && pminor > mminor)) {
{
META_ERROR("dll: Plugin '%s' requires a newer version of Metamod (Metamod needs at least interface %s not the current %s)", m_desc, m_info->ifvers, META_INTERFACE_VERSION); META_ERROR("dll: Plugin '%s' requires a newer version of Metamod (Metamod needs at least interface %s not the current %s)", m_desc, m_info->ifvers, META_INTERFACE_VERSION);
return false; return false;
} }
// If plugin has older major interface version, it's incompatible // If plugin has older major interface version, it's incompatible
// (update plugin). // (update plugin).
if (pmajor < mmajor) if (pmajor < mmajor) {
{
META_ERROR("dll: Plugin '%s' is out of date and incompatible with this version of Metamod; please find a newer version of the plugin (plugin needs at least interface %s not the current %s)", m_desc, META_INTERFACE_VERSION, m_info->ifvers); META_ERROR("dll: Plugin '%s' is out of date and incompatible with this version of Metamod; please find a newer version of the plugin (plugin needs at least interface %s not the current %s)", m_desc, META_INTERFACE_VERSION, m_info->ifvers);
return false; return false;
} }
@ -855,8 +843,7 @@ bool MPlugin::query()
} }
// Replace temporary desc with plugin's internal name. // Replace temporary desc with plugin's internal name.
if (m_desc[0] == '<') if (m_desc[0] == '<') {
{
Q_strncpy(m_desc, m_info->name, sizeof m_desc - 1); Q_strncpy(m_desc, m_info->name, sizeof m_desc - 1);
m_desc[sizeof m_desc - 1] = '\0'; m_desc[sizeof m_desc - 1] = '\0';
} }
@ -934,29 +921,24 @@ 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 (g_GameDLL.funcs.dllapi_table && !m_gamedll_funcs.dllapi_table) if (g_GameDLL.funcs.dllapi_table && !m_gamedll_funcs.dllapi_table) {
{
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) {
{
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, g_GameDLL.funcs.dllapi_table, sizeof(DLL_FUNCTIONS)); Q_memcpy(m_gamedll_funcs.dllapi_table, g_GameDLL.funcs.dllapi_table, sizeof(DLL_FUNCTIONS));
} }
if (g_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_malloc(sizeof(NEW_DLL_FUNCTIONS)); m_gamedll_funcs.newapi_table = (NEW_DLL_FUNCTIONS *)Q_malloc(sizeof(NEW_DLL_FUNCTIONS));
if (!m_gamedll_funcs.newapi_table) if (!m_gamedll_funcs.newapi_table) {
{
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;
} }
Q_memcpy(m_gamedll_funcs.newapi_table, g_GameDLL.funcs.newapi_table, sizeof(NEW_DLL_FUNCTIONS)); Q_memcpy(m_gamedll_funcs.newapi_table, g_GameDLL.funcs.newapi_table, sizeof(NEW_DLL_FUNCTIONS));
} }
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) {
{
META_ERROR("dll: Failed attach plugin '%s': Couldn't find Meta_Attach(): %s", m_desc, "function not found"); META_ERROR("dll: Failed attach plugin '%s': Couldn't find Meta_Attach(): %s", m_desc, "function not found");
return false; return false;
} }
@ -966,8 +948,7 @@ bool MPlugin::attach(PLUG_LOADTIME now)
// get table of function tables, // get table of function tables,
// give public meta globals // give public meta globals
qboolean ret = pfn_attach(now, &meta_table, &g_metaGlobals, &m_gamedll_funcs); qboolean ret = pfn_attach(now, &meta_table, &g_metaGlobals, &m_gamedll_funcs);
if (ret != TRUE) if (ret != TRUE) {
{
META_ERROR("dll: Failed attach plugin '%s': Error from Meta_Attach(): %d", m_desc, ret); META_ERROR("dll: Failed attach plugin '%s': Error from Meta_Attach(): %d", m_desc, ret);
return false; return false;
} }
@ -1014,16 +995,14 @@ bool MPlugin::detach(PLUG_LOADTIME now, PL_UNLOAD_REASON reason)
return true; return true;
auto pfn_detach = (META_DETACH_FN)m_sys_module.getsym("Meta_Detach"); auto pfn_detach = (META_DETACH_FN)m_sys_module.getsym("Meta_Detach");
if (!pfn_detach) if (!pfn_detach) {
{
META_ERROR("dll: Error detach plugin '%s': Couldn't find Meta_Detach(): %s", m_desc, "function not found"); META_ERROR("dll: Error detach plugin '%s': Couldn't find Meta_Detach(): %s", m_desc, "function not found");
// caller will dlclose() // caller will dlclose()
return false; return false;
} }
int ret = pfn_detach(now, reason); int ret = pfn_detach(now, reason);
if (ret != TRUE) if (ret != TRUE) {
{
META_ERROR("dll: Failed detach plugin '%s': Error from Meta_Detach(): %d", m_desc, ret); META_ERROR("dll: Failed detach plugin '%s': Error from Meta_Detach(): %d", m_desc, ret);
return false; return false;
} }
@ -1146,8 +1125,7 @@ const char *MPlugin::str_status(STR_STATUS fmt) const
const char *MPlugin::str_action(STR_ACTION fmt) const const char *MPlugin::str_action(STR_ACTION fmt) const
{ {
bool show = fmt == ST_SHOW; bool show = fmt == ST_SHOW;
switch (m_action) switch (m_action) {
{
case PA_NULL: return "null"; case PA_NULL: return "null";
case PA_NONE: return show ? " - " : "none"; case PA_NONE: return show ? " - " : "none";
case PA_KEEP: return "keep"; case PA_KEEP: return "keep";

View File

@ -38,7 +38,7 @@ enum PLOAD_SOURCE : uint8
// Flags for how to word description of plugin loadtime. // Flags for how to word description of plugin loadtime.
enum STR_LOADTIME : uint8 enum STR_LOADTIME : uint8
{ {
SL_SIMPLE = 0, // single word SL_SIMPLE, // single word
SL_SHOW, // for "show" output, 5 chars SL_SHOW, // for "show" output, 5 chars
SL_ALLOWED, // when plugin is allowed to load/unload SL_ALLOWED, // when plugin is allowed to load/unload
SL_NOW, // current situation SL_NOW, // current situation

View File

@ -18,7 +18,8 @@ bool MRegCmd::call() const
void MRegCmd::disable() void MRegCmd::disable()
{ {
m_pfunction = [](){}; m_pfunction = []() {
};
m_plugid = 0; m_plugid = 0;
m_status = RG_INVALID; m_status = RG_INVALID;
} }
@ -46,8 +47,7 @@ MRegCmdList::~MRegCmdList()
MRegCmd* MRegCmdList::find(const char* name) const MRegCmd* MRegCmdList::find(const char* name) const
{ {
for (auto reg : m_list) for (auto reg : m_list) {
{
if (!Q_stricmp(reg->m_name, name)) if (!Q_stricmp(reg->m_name, name))
return reg; return reg;
} }
@ -106,17 +106,14 @@ void MRegCmdList::show() const
META_CONS("Registered plugin commands:"); META_CONS("Registered plugin commands:");
META_CONS(" %*s %-*s %-s", WIDTH_MAX_REG, "", sizeof bplug - 1, "plugin", "command"); META_CONS(" %*s %-*s %-s", WIDTH_MAX_REG, "", sizeof bplug - 1, "plugin", "command");
for (auto reg : m_list) for (auto reg : m_list) {
{ if (reg->m_status == RG_VALID) {
if (reg->m_status == RG_VALID)
{
auto iplug = g_plugins->find(reg->m_plugid); auto iplug = g_plugins->find(reg->m_plugid);
Q_strncpy(bplug, iplug ? iplug->description() : "(unknown)", sizeof bplug - 1); Q_strncpy(bplug, iplug ? iplug->description() : "(unknown)", sizeof bplug - 1);
bplug[sizeof bplug - 1] = '\0'; bplug[sizeof bplug - 1] = '\0';
} }
else else {
{
Q_strncpy(bplug, "(unloaded)", sizeof bplug - 1); Q_strncpy(bplug, "(unloaded)", sizeof bplug - 1);
bplug[sizeof bplug - 1] = '\0'; bplug[sizeof bplug - 1] = '\0';
} }
@ -137,8 +134,7 @@ void MRegCmdList::show(int plugin_id) const
META_CONS("Registered commands:"); META_CONS("Registered commands:");
for (auto reg : m_list) for (auto reg : m_list) {
{
if (reg->m_plugid != plugin_id) if (reg->m_plugid != plugin_id)
continue; continue;
@ -192,8 +188,7 @@ MRegCvar *MRegCvarList::add(cvar_t* src, MPlugin* plugin)
MRegCvar* MRegCvarList::find(const char* findname) MRegCvar* MRegCvarList::find(const char* findname)
{ {
for (auto reg : m_list) for (auto reg : m_list) {
{
if (!Q_stricmp(reg->m_cvar->name, findname)) if (!Q_stricmp(reg->m_cvar->name, findname))
return reg; return reg;
} }
@ -204,10 +199,8 @@ MRegCvar *MRegCvarList::find(const char *findname)
// Disable any cvars belonging to the given plugin (by index id). // Disable any cvars belonging to the given plugin (by index id).
void MRegCvarList::disable(int plugin_id) const void MRegCvarList::disable(int plugin_id) const
{ {
for (auto reg : m_list) for (auto reg : m_list) {
{ if (reg->m_plugid == plugin_id) {
if (reg->m_plugid == plugin_id)
{
reg->m_status = RG_INVALID; reg->m_status = RG_INVALID;
reg->m_plugid = 0; reg->m_plugid = 0;
} }
@ -223,16 +216,13 @@ void MRegCvarList::show() const
META_CONS("Registered plugin cvars:"); META_CONS("Registered plugin cvars:");
META_CONS(" %*s %-*s %-*s %*s %s", WIDTH_MAX_REG, "", sizeof bplug - 1, "plugin", sizeof bname - 1, "cvar", sizeof bval - 1, "float value", "string value"); META_CONS(" %*s %-*s %-*s %*s %s", WIDTH_MAX_REG, "", sizeof bplug - 1, "plugin", sizeof bname - 1, "cvar", sizeof bval - 1, "float value", "string value");
for (auto reg : m_list) for (auto reg : m_list) {
{ if (reg->m_status == RG_VALID) {
if (reg->m_status == RG_VALID)
{
auto plug = g_plugins->find(reg->m_plugid); auto plug = g_plugins->find(reg->m_plugid);
Q_strncpy(bplug, plug ? plug->description() : "(unknown)", sizeof bplug - 1); Q_strncpy(bplug, plug ? plug->description() : "(unknown)", sizeof bplug - 1);
bplug[sizeof bplug - 1] = '\0'; bplug[sizeof bplug - 1] = '\0';
} }
else else {
{
Q_strncpy(bplug, "(unloaded)", sizeof bplug - 1); Q_strncpy(bplug, "(unloaded)", sizeof bplug - 1);
bplug[sizeof bplug - 1] = '\0'; bplug[sizeof bplug - 1] = '\0';
} }
@ -257,8 +247,7 @@ void MRegCvarList::show(int plugin_id) const
META_CONS("%-*s %*s %s", sizeof bname - 1, "Registered cvars:", sizeof bval - 1, "float value", "string value"); META_CONS("%-*s %*s %s", sizeof bname - 1, "Registered cvars:", sizeof bval - 1, "float value", "string value");
for (auto reg : m_list) for (auto reg : m_list) {
{
if (reg->m_plugid != plugin_id) if (reg->m_plugid != plugin_id)
continue; continue;
@ -274,7 +263,6 @@ void MRegCvarList::show(int plugin_id) const
MRegMsg::MRegMsg(const char* name, int msgid, int size) : m_name(name), m_msgid(msgid), m_size(size) MRegMsg::MRegMsg(const char* name, int msgid, int size) : m_name(name), m_msgid(msgid), m_size(size)
{ {
} }
const char* MRegMsg::getname() const const char* MRegMsg::getname() const
@ -315,8 +303,7 @@ MRegMsg *MRegMsgList::add(const char *addname, int addmsgid, int addsize)
MRegMsg* MRegMsgList::find(const char* findname) MRegMsg* MRegMsgList::find(const char* findname)
{ {
for (auto msg : m_list) for (auto msg : m_list) {
{
if (!Q_strcmp(msg->m_name, findname)) if (!Q_strcmp(msg->m_name, findname))
return msg; return msg;
} }

View File

@ -7,13 +7,23 @@
// the moment, it reflects what one might normally expect to be the max // the moment, it reflects what one might normally expect to be the max
// width needed to print an index number; 4 allows 9999 (which is a damn // width needed to print an index number; 4 allows 9999 (which is a damn
// lot, if you ask me). // lot, if you ask me).
#define WIDTH_MAX_REG 4 enum
{
WIDTH_MAX_REG = 4
};
// Max number of registered user msgs we can manage. // Max number of registered user msgs we can manage.
#define MAX_REG_MSGS 256 enum
{
MAX_REG_MSGS = 256
};
// Flags to indicate if given cvar or func is part of a loaded plugin. // Flags to indicate if given cvar or func is part of a loaded plugin.
enum REG_STATUS { RG_INVALID, RG_VALID }; enum REG_STATUS
{
RG_INVALID,
RG_VALID
};
// Pointer to function registered by AddServerCommand. // Pointer to function registered by AddServerCommand.
typedef void (*REG_CMD_FN)(); typedef void (*REG_CMD_FN)();

View File

@ -158,8 +158,7 @@ void EXT_FUNC mutil_CenterSayVarargs(plid_t plid, hudtextparms_t tparms, const c
mutil_LogMessage(plid, "(centersay) %s", buf); mutil_LogMessage(plid, "(centersay) %s", buf);
for (int n = 1; n <= gpGlobals->maxClients; n++) for (int n = 1; n <= gpGlobals->maxClients; n++) {
{
auto pEntity = INDEXENT(n); auto pEntity = INDEXENT(n);
if (FNullEnt(pEntity) || pEntity->free) if (FNullEnt(pEntity) || pEntity->free)
@ -177,8 +176,7 @@ qboolean EXT_FUNC mutil_CallGameEntity(plid_t plid, const char *entStr, entvars_
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)g_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, g_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;
} }
@ -196,8 +194,7 @@ int EXT_FUNC mutil_GetUserMsgID(plid_t plid, const char* msgname, int* size)
MRegMsg* umsg = g_regMsgs->find(msgname); MRegMsg* umsg = g_regMsgs->find(msgname);
if (umsg) if (umsg) {
{
if (size) *size = umsg->getsize(); if (size) *size = umsg->getsize();
return umsg->getid(); return umsg->getid();
} }
@ -221,16 +218,14 @@ const char* EXT_FUNC mutil_GetUserMsgName(plid_t plid, int msgid, int *size)
// Guess names for any built-in g_engine messages mentioned in the SDK; // Guess names for any built-in g_engine messages mentioned in the SDK;
// from dlls/util.h. // from dlls/util.h.
if (msgid < arraysize(g_engine_msg_names)) if (msgid < arraysize(g_engine_msg_names)) {
{
if (size) *size = -1; if (size) *size = -1;
return g_engine_msg_names[msgid]; return g_engine_msg_names[msgid];
} }
MRegMsg* umsg = g_regMsgs->find(msgid); MRegMsg* umsg = g_regMsgs->find(msgid);
if (umsg) if (umsg) {
{
if (size) *size = umsg->getsize(); if (size) *size = umsg->getsize();
// 'name' is assumed to be a constant string, allocated in the // 'name' is assumed to be a constant string, allocated in the
// gamedll. // gamedll.
@ -246,8 +241,7 @@ const char* EXT_FUNC mutil_GetPluginPath(plid_t plid)
static char buf[PATH_MAX]; static char buf[PATH_MAX];
auto plug = g_plugins->find(plid); auto plug = g_plugins->find(plid);
if (!plug) if (!plug) {
{
META_ERROR("GetPluginPath: couldn't find plugin '%s'", plid->name); META_ERROR("GetPluginPath: couldn't find plugin '%s'", plid->name);
return nullptr; return nullptr;
} }
@ -263,8 +257,7 @@ const char* EXT_FUNC mutil_GetGameInfo(plid_t plid, ginfo_t type)
static char buf[MAX_STRBUF_LEN]; static char buf[MAX_STRBUF_LEN];
const char* cp; const char* cp;
switch (type) switch (type) {
{
case GINFO_NAME: case GINFO_NAME:
cp = g_GameDLL.name; cp = g_GameDLL.name;
break; break;
@ -295,14 +288,12 @@ const char* EXT_FUNC mutil_GetGameInfo(plid_t plid, ginfo_t type)
int EXT_FUNC 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)
{ {
if (!fname) if (!fname) {
{
return 1; return 1;
} }
auto pl_loaded = g_plugins->plugin_addload(plid, fname, now); auto pl_loaded = g_plugins->plugin_addload(plid, fname, now);
if (!pl_loaded) if (!pl_loaded) {
{
if (plugin_handle) if (plugin_handle)
*plugin_handle = nullptr; *plugin_handle = nullptr;
@ -321,8 +312,7 @@ int EXT_FUNC mutil_UnloadMetaPlugin(plid_t plid, const char *fname, PLUG_LOADTIM
{ {
MPlugin* findp; MPlugin* findp;
if (!fname) if (!fname) {
{
return 1; return 1;
} }
@ -348,8 +338,7 @@ int EXT_FUNC mutil_UnloadMetaPlugin(plid_t plid, const char *fname, PLUG_LOADTIM
int EXT_FUNC 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)
{ {
if (!plugin_handle) if (!plugin_handle) {
{
return 1; return 1;
} }

View File

@ -4,9 +4,6 @@
#include <dllapi.h> #include <dllapi.h>
#include <plinfo.h> #include <plinfo.h>
// max buffer size for printed messages
#define MAX_LOGMSG_LEN 1024
// For GetGameInfo: // For GetGameInfo:
enum ginfo_t enum ginfo_t
{ {

View File

@ -5,14 +5,12 @@ void EXT_FUNC meta_command_handler()
const char* cmd = CMD_ARGV(0); const char* cmd = CMD_ARGV(0);
MRegCmd* icmd = g_regCmds->find(cmd); MRegCmd* icmd = g_regCmds->find(cmd);
if (!icmd) if (!icmd) {
{
META_ERROR("Couldn't find registered plugin command: %s", cmd); META_ERROR("Couldn't find registered plugin command: %s", cmd);
return; return;
} }
if (!icmd->call()) if (!icmd->call()) {
{
META_CONS("[metamod: command '%s' unavailable; plugin unloaded]", cmd); META_CONS("[metamod: command '%s' unavailable; plugin unloaded]", cmd);
} }
} }
@ -38,8 +36,7 @@ void EXT_FUNC meta_AddServerCommand(char *cmd_name, void (*function)())
// See if this command was previously registered, ie a "reloaded" plugin. // See if this command was previously registered, ie a "reloaded" plugin.
auto cmd = g_regCmds->find(cmd_name); auto cmd = g_regCmds->find(cmd_name);
if (!cmd) if (!cmd) {
{
// If not found, add. // If not found, add.
cmd = g_regCmds->add(cmd_name, function, plug); cmd = g_regCmds->add(cmd_name, function, plug);
REG_SVR_COMMAND(cmd->getname(), g_RehldsFuncs ? cmd->gethandler() : meta_command_handler); REG_SVR_COMMAND(cmd->getname(), g_RehldsFuncs ? cmd->gethandler() : meta_command_handler);
@ -65,16 +62,14 @@ void EXT_FUNC meta_CVarRegister(cvar_t *pCvar)
META_DEBUG(4, "called: meta_CVarRegister; name=%s", pCvar->name); META_DEBUG(4, "called: meta_CVarRegister; name=%s", pCvar->name);
// try to find which plugin is registering this cvar // try to find which plugin is registering this cvar
if (!plug) if (!plug) {
{
META_DEBUG(1, "Failed to find memloc for regcvar '%s'", pCvar->name); META_DEBUG(1, "Failed to find memloc for regcvar '%s'", pCvar->name);
} }
// See if this cvar was previously registered, ie a "reloaded" plugin. // See if this cvar was previously registered, ie a "reloaded" plugin.
auto reg = g_regCvars->find(pCvar->name); auto reg = g_regCvars->find(pCvar->name);
if (!reg) if (!reg) {
{
reg = g_regCvars->add(pCvar, plug); reg = g_regCvars->add(pCvar, plug);
CVAR_REGISTER(reg->getcvar()); CVAR_REGISTER(reg->getcvar());
} }

View File

@ -36,18 +36,15 @@ C_DLLEXPORT int Server_GetBlendingInterface(int version,
// mismatch?", but this will only show in "developer" (-dev) mode. // mismatch?", but this will only show in "developer" (-dev) mode.
META_DEBUG(6, "called: Server_GetBlendingInterface; version=%d", version); META_DEBUG(6, "called: Server_GetBlendingInterface; version=%d", version);
if (missing) if (missing) {
{
META_DEBUG(6, "Skipping Server_GetBlendingInterface; was previously found missing"); META_DEBUG(6, "Skipping Server_GetBlendingInterface; was previously found missing");
return 0; return 0;
} }
if (!getblend) if (!getblend) {
{
META_DEBUG(6, "Looking up Server_GetBlendingInterface"); META_DEBUG(6, "Looking up Server_GetBlendingInterface");
getblend = (GETBLENDAPI_FN)g_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", g_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;

View File

@ -30,7 +30,6 @@ const char* LOCALINFO(char* key)
static_allocator::static_allocator(memory_protection protection) : m_protection(protection) static_allocator::static_allocator(memory_protection protection) : m_protection(protection)
{ {
} }
char* static_allocator::allocate(const size_t n) char* static_allocator::allocate(const size_t n)
@ -130,8 +129,7 @@ char *trimbuf(char *str)
void normalize_path(char* path) void normalize_path(char* path)
{ {
#ifdef _WIN32 #ifdef _WIN32
for (char* cp = path; *cp; cp++) for (char* cp = path; *cp; cp++) {
{
if (isupper(*cp)) if (isupper(*cp))
*cp = tolower(*cp); *cp = tolower(*cp);
@ -172,7 +170,6 @@ bool is_platform_postfix(const char* pf)
char* realpath(const char* file_name, char* resolved_name) char* realpath(const char* file_name, char* resolved_name)
{ {
int ret = GetFullPathName(file_name, PATH_MAX, resolved_name, nullptr); int ret = GetFullPathName(file_name, PATH_MAX, resolved_name, nullptr);
if (ret > PATH_MAX) { if (ret > PATH_MAX) {
errno = ENAMETOOLONG; errno = ENAMETOOLONG;
return nullptr; return nullptr;