2
0
mirror of https://github.com/rehlds/metamod-r.git synced 2025-05-18 17:38:21 +03:00

Final refactoring

This commit is contained in:
asmodai 2017-01-17 00:30:02 +03:00
parent 333918455c
commit f392c42e7e
9 changed files with 96 additions and 107 deletions

View File

@ -115,7 +115,7 @@ bool MConfig::load(const char* fn)
} }
META_DEBUG(2, "Loading from config file: %s", loadfile); META_DEBUG(2, "Loading from config file: %s", loadfile);
for (ln = 1; !feof(fp) && fgets(line, sizeof(line), fp); ln++) for (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;

View File

@ -109,12 +109,12 @@ bool setup_gamedll(gamedll_t *gamedll)
#endif #endif
META_DEBUG(4, "Checking for old version game DLL name '%s'.\n", knownfn); META_DEBUG(4, "Checking for old version game DLL name '%s'.\n", knownfn);
Q_snprintf(gamedll->pathname, sizeof(gamedll->pathname), "dlls/%s", knownfn); Q_snprintf(gamedll->pathname, sizeof gamedll->pathname, "dlls/%s", knownfn);
// Check if the gamedll file exists. If not, try to install it from the cache. // Check if the gamedll file exists. If not, try to install it from the cache.
if (!valid_gamedir_file(gamedll->pathname)) if (!valid_gamedir_file(gamedll->pathname))
{ {
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);
install_gamedll(gamedll->pathname, gamedll->real_pathname); install_gamedll(gamedll->pathname, gamedll->real_pathname);
} }
} }
@ -124,7 +124,7 @@ bool setup_gamedll(gamedll_t *gamedll)
return false; return false;
} }
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);
// get filename from pathname // get filename from pathname
char *cp = Q_strrchr(gamedll->pathname, '/'); char *cp = Q_strrchr(gamedll->pathname, '/');
@ -135,8 +135,8 @@ bool setup_gamedll(gamedll_t *gamedll)
gamedll->file = cp; gamedll->file = cp;
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';
gamedll->desc = known->desc; gamedll->desc = known->desc;
META_LOG("Recognized game '%s'; using dllfile '%s'", gamedll->name, gamedll->file); META_LOG("Recognized game '%s'; using dllfile '%s'", gamedll->name, gamedll->file);

View File

@ -219,7 +219,7 @@ bool meta_init_gamedll(void)
char gamedir[PATH_MAX]; char gamedir[PATH_MAX];
char *cp; char *cp;
Q_memset(&g_GameDLL, 0, sizeof(g_GameDLL)); Q_memset(&g_GameDLL, 0, sizeof g_GameDLL);
GET_GAME_DIR(gamedir); GET_GAME_DIR(gamedir);
normalize_pathname(gamedir); normalize_pathname(gamedir);
@ -260,7 +260,7 @@ bool meta_init_gamedll(void)
Q_snprintf(g_GameDLL.gamedir, sizeof g_GameDLL.gamedir, "%s/%s", buf, gamedir); Q_snprintf(g_GameDLL.gamedir, sizeof g_GameDLL.gamedir, "%s/%s", buf, gamedir);
Q_strncpy(g_GameDLL.name, gamedir, sizeof g_GameDLL.name - 1); Q_strncpy(g_GameDLL.name, gamedir, sizeof g_GameDLL.name - 1);
g_GameDLL.name[sizeof(g_GameDLL.name) - 1] = '\0'; g_GameDLL.name[sizeof g_GameDLL.name - 1] = '\0';
} }
META_DEBUG(3, "Game: %s", g_GameDLL.name); META_DEBUG(3, "Game: %s", g_GameDLL.name);

View File

@ -188,10 +188,10 @@ 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 nullptr; return pl_found;
} }
auto pl_added = add(&pl_temp); auto pl_added = add(&pl_temp);
@ -224,7 +224,7 @@ MPlugin* MPluginList::find_empty_slot()
{ {
for (int i = 0; i < MAX_PLUGINS; i++) { for (int i = 0; i < MAX_PLUGINS; i++) {
if (m_plist[i].m_status == PL_EMPTY) { if (m_plist[i].m_status == PL_EMPTY) {
if (i > m_max_loaded_count) if (i >= m_max_loaded_count)
m_max_loaded_count = i + 1; m_max_loaded_count = i + 1;
return &m_plist[i]; return &m_plist[i];
@ -295,7 +295,7 @@ bool MPluginList::ini_startup()
} }
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;
@ -308,9 +308,9 @@ bool MPluginList::ini_startup()
// Parse directly into next entry in array // Parse directly into next entry in array
if (!m_plist[n].ini_parseline(line)) if (!m_plist[n].ini_parseline(line))
{ {
META_ERROR("ini: Skipping malformed line %d of %s", ln, m_inifile);
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))
{ {
@ -367,7 +367,7 @@ bool MPluginList::ini_refresh()
} }
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;
@ -378,7 +378,7 @@ bool MPluginList::ini_refresh()
*cp = '\0'; *cp = '\0';
// Parse into a temp plugin // Parse into a temp plugin
Q_memset(&pl_temp, 0, sizeof(pl_temp)); Q_memset(&pl_temp, 0, sizeof 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);
@ -676,8 +676,8 @@ void MPluginList::show(int source_index)
else else
META_CONS("Child plugins:"); META_CONS("Child plugins:");
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++)
{ {
@ -688,25 +688,25 @@ void MPluginList::show(int source_index)
if (source_index > 0 && pl->m_source_plugin_index != source_index) if (source_index > 0 && pl->m_source_plugin_index != source_index)
continue; continue;
Q_strncpy(desc, pl->m_desc, sizeof(desc) - 1); Q_strncpy(desc, pl->m_desc, sizeof desc - 1);
desc[sizeof(desc) - 1] = '\0'; desc[sizeof desc - 1] = '\0';
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->m_info && pl->m_info->version) if (pl->m_info && pl->m_info->version)
{ {
Q_strncpy(vers, pl->m_info->version, sizeof(vers) - 1); Q_strncpy(vers, pl->m_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';
} }
META_CONS(" [%*d] %-*s %-4s %-4s %-*s v%-*s %-*s %-5s %-5s", WIDTH_MAX_PLUGINS, pl->m_index, META_CONS(" [%*d] %-*s %-4s %-4s %-*s v%-*s %-*s %-5s %-5s", WIDTH_MAX_PLUGINS, pl->m_index,
sizeof(desc) - 1, desc, pl->str_status(ST_SHOW), pl->str_action(SA_SHOW), sizeof(file) - 1, file, sizeof(vers) - 1, vers, sizeof desc - 1, desc, pl->str_status(ST_SHOW), pl->str_action(SA_SHOW), sizeof file - 1, file, sizeof vers - 1, vers,
2 + WIDTH_MAX_PLUGINS, pl->str_source(SO_SHOW), pl->str_loadable(SL_SHOW), pl->str_unloadable(SL_SHOW)); 2 + WIDTH_MAX_PLUGINS, pl->str_source(SO_SHOW), pl->str_loadable(SL_SHOW), pl->str_unloadable(SL_SHOW));
if (pl->m_status == PL_RUNNING) if (pl->m_status == PL_RUNNING)

View File

@ -1,5 +1,12 @@
#include "precompiled.h" #include "precompiled.h"
const char* g_platform_postfixes[] = {
"_i386.so",
"_i486.so",
"_i586.so",
"_i686.so",
};
// Parse a line from plugins.ini into a plugin. // Parse a line from plugins.ini into a plugin.
bool MPlugin::ini_parseline(char *_line) bool MPlugin::ini_parseline(char *_line)
{ {
@ -15,7 +22,7 @@ bool MPlugin::ini_parseline(char *_line)
return false; return false;
} }
if (line[0] == '#' || line[0] == ';' || Q_strncmp(line, "//", 2) ) { if (line[0] == '#' || line[0] == ';' || !Q_strncmp(line, "//", 2)) {
META_DEBUG(7, "ini: Ignoring commented line: %s", line); META_DEBUG(7, "ini: Ignoring commented line: %s", line);
return false; return false;
} }
@ -57,7 +64,7 @@ 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(NULL, "\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
@ -140,7 +147,7 @@ bool MPlugin::plugin_parseline(const char *fname, int loader_index)
//grab description //grab description
//temporarily use plugin file until plugin can be queried //temporarily use plugin file until plugin can be queried
Q_snprintf(m_desc, sizeof(m_desc), "<%s>", m_file); Q_snprintf(m_desc, sizeof m_desc, "<%s>", m_file);
//make full pathname //make full pathname
full_gamedir_path(m_filename, m_pathname); full_gamedir_path(m_filename, m_pathname);
@ -196,7 +203,7 @@ bool MPlugin::cmd_parseline(const char *line)
{ {
// 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);
} }
// Make full pathname (from gamedir if relative, remove "..", // Make full pathname (from gamedir if relative, remove "..",
@ -336,8 +343,8 @@ char *MPlugin::resolve_prefix(char *path) const
{ {
struct stat st; struct stat st;
char *cp, *fname; char *cp, *fname;
char dname[PATH_MAX ]; char dname[PATH_MAX];
static char buf[PATH_MAX ]; static char buf[PATH_MAX];
char *found; char *found;
// try "mm_" prefix FIRST. // try "mm_" prefix FIRST.
@ -382,62 +389,45 @@ char *MPlugin::resolve_prefix(char *path) const
// path_i386.so, path_i486.so, etc (if linux) // path_i386.so, path_i486.so, etc (if linux)
char *MPlugin::resolve_suffix(char *path) const char *MPlugin::resolve_suffix(char *path) const
{ {
char *found = nullptr;
auto check = [](const char* path) -> char*
{
struct stat st; struct stat st;
static char buf[PATH_MAX ];
char *found; if (stat(path, &st) == 0 && S_ISREG(st.st_mode)) {
static char buf[PATH_MAX];
strncpy(buf, path, sizeof buf - 1);
buf[sizeof buf - 1];
return buf;
}
return nullptr;
};
if (Q_strstr(path, PLATFORM_DLEXT)) {
return check(path);
}
char tmpbuf[PATH_MAX];
Q_snprintf(tmpbuf, sizeof tmpbuf, "%s%s", path, PLATFORM_DLEXT);
if ((found = check(tmpbuf))) return found;
// Hmm, recursion. // Hmm, recursion.
if (!Q_strstr(path, "_mm")) if (!Q_strstr(path, "_mm"))
{ {
char *tmpbuf; Q_snprintf(tmpbuf, sizeof tmpbuf, "%s_mm", path);
Q_snprintf(buf, sizeof buf, "%s_mm", path); if ((found = resolve_suffix(tmpbuf))) return found;
tmpbuf = Q_strdup(buf);
found = resolve_suffix(tmpbuf);
Q_free(tmpbuf);
if (found) return found;
} }
else if (!Q_strstr(path, "_MM"))
{
char *tmpbuf;
Q_snprintf(buf, sizeof buf, "%s_MM", path);
tmpbuf = Q_strdup(buf);
found = resolve_suffix(tmpbuf);
Q_free(tmpbuf);
if (found) return found;
}
#ifdef _WIN32
Q_snprintf(buf, sizeof buf, "%s.dll", path);
#else
Q_snprintf(buf, sizeof buf, "%s.so", path);
#endif
if (stat(buf, &st) == 0 && S_ISREG(st.st_mode))
return buf;
#ifndef _WIN32 #ifndef _WIN32
Q_snprintf(buf, sizeof buf, "%s_i386.so", path); for (size_t i = 0; i < arraysize(g_platform_suffixes); i++) {
if (stat(buf, &st) == 0 && S_ISREG(st.st_mode)) Q_snprintf(tmpbuf, sizeof tmpbuf, "%s%s", path, g_platform_suffixes[i]);
return buf; if ((found = check(tmpbuf))) return found;
}
Q_snprintf(buf, sizeof buf, "%s_i486.so", path);
if (stat(buf, &st) == 0 && S_ISREG(st.st_mode))
return buf;
Q_snprintf(buf, sizeof buf, "%s_i586.so", path);
if (stat(buf, &st) == 0 && S_ISREG(st.st_mode))
return buf;
Q_snprintf(buf, sizeof buf, "%s_i686.so", path);
if (stat(buf, &st) == 0 && S_ISREG(st.st_mode))
return buf;
Q_snprintf(buf, sizeof buf, "%s_amd64.so", path);
if (stat(buf, &st) == 0 && S_ISREG(st.st_mode))
return buf;
#endif #endif
return NULL; return nullptr;
} }
// Check if a passed string starts with a known platform postfix. // Check if a passed string starts with a known platform postfix.
@ -445,11 +435,11 @@ char *MPlugin::resolve_suffix(char *path) const
// Linux and Win32. // Linux and Win32.
static bool is_platform_postfix(char *pf) static bool is_platform_postfix(char *pf)
{ {
if (!pf) { if (pf) {
if (!Q_strncmp(pf, "_i386.", 6)) return true; for (size_t i = 0; i < arraysize(g_platform_postfixes); i++) {
if (!Q_strncmp(pf, "_i486.", 6)) return true; if (!Q_strcmp(pf, g_platform_postfixes[i]))
if (!Q_strncmp(pf, "_i586.", 6)) return true; return true;
if (!Q_strncmp(pf, "_i686.", 6)) return true; }
} }
return false; return false;
} }
@ -473,36 +463,35 @@ bool MPlugin::platform_match(MPlugin *other) const
if (m_status == PL_EMPTY || other->m_status == PL_EMPTY) if (m_status == PL_EMPTY || other->m_status == PL_EMPTY)
return false; return false;
if (Q_strcmp(m_file, other->m_file) == 0) if (!Q_strcmp(m_file, other->m_file))
return true; return true;
if (m_status >= PL_OPENED && other->m_status >= PL_OPENED && Q_strcmp(m_info->logtag, other->m_info->logtag) == 0) if (m_status >= PL_OPENED && other->m_status >= PL_OPENED && !Q_strcmp(m_info->logtag, other->m_info->logtag))
return true; return true;
if (*m_desc != '\0' && Q_stricmp(m_desc, other->m_desc) == 0) if (*m_desc != '\0' && !Q_stricmp(m_desc, other->m_desc))
return true; return true;
end = Q_strrchr(m_file, '_'); end = Q_strrchr(m_file, '_');
if (end == NULL || !is_platform_postfix(end)) end = Q_strrchr(m_file, '.'); if (!end || !is_platform_postfix(end)) end = Q_strrchr(m_file, '.');
other_end = Q_strrchr(other->m_file, '_'); other_end = Q_strrchr(other->m_file, '_');
if (other_end == NULL || !is_platform_postfix(other_end)) if (!other_end || !is_platform_postfix(other_end))
other_end = Q_strrchr(other->m_file, '.'); other_end = Q_strrchr(other->m_file, '.');
if (end == NULL || other_end == NULL) if (!end || !other_end)
return false; return false;
prefixlen = end - m_file; prefixlen = end - m_file;
if ((other_end - other->m_file) != prefixlen) if (other_end - other->m_file != prefixlen)
return false; return false;
if (Q_strncmp(m_file, other->m_file, prefixlen) == 0) if (!Q_strncmp(m_file, other->m_file, prefixlen))
return true; return true;
return false; return false;
} }
// Load a plugin; query, check allowed time, attach. // Load a plugin; query, check allowed time, attach.
bool MPlugin::load(PLUG_LOADTIME now) bool MPlugin::load(PLUG_LOADTIME now)
{ {
@ -983,7 +972,7 @@ bool MPlugin::detach(PLUG_LOADTIME now, PL_UNLOAD_REASON reason)
META_DETACH_FN pfn_detach; META_DETACH_FN pfn_detach;
// If we have no handle, i.e. no dll loaded, we return true because the // If we have no handle, i.e. no dll loaded, we return true because the
// dll is obviously detached. We shouldn't call DLSYM() with a NULL // dll is obviously detached. We shouldn't call DLSYM() with a nullptr
// handle since this will DLSYM() ourself. // handle since this will DLSYM() ourself.
if (!m_sys_module.gethandle()) if (!m_sys_module.gethandle())
return true; return true;
@ -1167,7 +1156,7 @@ void show_table(const char* table_name, table_t* table, info_t* info_begin, bool
for (auto n = info_begin; n->name[0] != '\0'; n++) { for (auto n = info_begin; n->name[0] != '\0'; n++) {
if (*(size_t *)(size_t(table) + n->offset)) { if (*(size_t *)(size_t(table) + n->offset)) {
META_CONS(" %s%s", n->name, post ? "_Post" : ""); META_CONS(" %s%s", Q_strstr(n->name, "::") + 2, post ? "_Post" : "");
count++; count++;
} }
} }
@ -1290,8 +1279,8 @@ const char *MPlugin::str_action(STR_ACTION fmt) const
switch (m_action) switch (m_action)
{ {
case PA_NULL: case PA_NULL:
if (fmt == SA_SHOW) return "NULL"; if (fmt == SA_SHOW) return "nullptr";
else return "null"; else return "nullptr";
case PA_NONE: case PA_NONE:
if (fmt == SA_SHOW) return " - "; if (fmt == SA_SHOW) return " - ";
else return "none"; else return "none";
@ -1404,7 +1393,7 @@ const char *MPlugin::str_source(STR_SOURCE fmt) const
else else
{ {
if (fmt == SO_SHOW) return UTIL_VarArgs("pl%d", m_source_plugin_index); if (fmt == SO_SHOW) return UTIL_VarArgs("pl%d", m_source_plugin_index);
else return UTIL_VarArgs("plugin [%d]", m_source_plugin_index); else return UTIL_VarArgs("plugin [%s]", g_plugins.find(m_source_plugin_index)->m_desc);
} }
default: default:
if (fmt == SO_SHOW) return UTIL_VarArgs("UNK%d", m_source); if (fmt == SO_SHOW) return UTIL_VarArgs("UNK%d", m_source);

View File

@ -255,7 +255,7 @@ void MRegCvarList::show(int plugin_id) const
int total_count = 0; int total_count = 0;
char bname[30 + 1], bval[15 + 1]; // +1 for term null char bname[30 + 1], bval[15 + 1]; // +1 for term null
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)
{ {
@ -264,8 +264,8 @@ void MRegCvarList::show(int plugin_id) const
Q_strncpy(bname, reg->m_cvar->name, sizeof bname - 1); Q_strncpy(bname, reg->m_cvar->name, sizeof bname - 1);
bname[sizeof bname - 1] = '\0'; bname[sizeof bname - 1] = '\0';
Q_snprintf(bval, sizeof(bval), "%f", reg->m_cvar->value); Q_snprintf(bval, sizeof bval, "%f", reg->m_cvar->value);
META_CONS(" %-*s %*s %s", sizeof(bname) - 1, bname, sizeof(bval) - 1, bval, reg->m_cvar->string); META_CONS(" %-*s %*s %s", sizeof bname - 1, bname, sizeof bval - 1, bval, reg->m_cvar->string);
total_count++; total_count++;
} }
@ -340,12 +340,12 @@ void MRegMsgList::show()
int total_count = 0; int total_count = 0;
char bname[25 + 1]; // +1 for term null char bname[25 + 1]; // +1 for term null
META_CONS("%-*s %5s %5s", sizeof(bname) - 1, "Game registered user msgs:", "msgid", "size"); META_CONS("%-*s %5s %5s", sizeof bname - 1, "Game registered user msgs:", "msgid", "size");
for (auto msg : m_list) { for (auto msg : m_list) {
Q_strncpy(bname, msg->m_name, sizeof bname - 1); Q_strncpy(bname, msg->m_name, sizeof bname - 1);
bname[sizeof bname - 1] = '\0'; bname[sizeof bname - 1] = '\0';
META_CONS(" %-*s %3d %3d", sizeof(bname) - 1, bname, msg->m_msgid, msg->m_size); META_CONS(" %-*s %3d %3d", sizeof bname - 1, bname, msg->m_msgid, msg->m_size);
total_count++; total_count++;
} }

View File

@ -10,7 +10,7 @@ module_handle_t CSysModule::load(const char* filepath)
m_handle = LoadLibrary(filepath); m_handle = LoadLibrary(filepath);
MODULEINFO module_info; MODULEINFO module_info;
if (GetModuleInformation(GetCurrentProcess(), m_handle, &module_info, sizeof(module_info))) { if (GetModuleInformation(GetCurrentProcess(), m_handle, &module_info, sizeof module_info)) {
m_base = (uintptr_t)module_info.lpBaseOfDll; m_base = (uintptr_t)module_info.lpBaseOfDll;
m_size = module_info.SizeOfImage; m_size = module_info.SizeOfImage;
} }

View File

@ -6,7 +6,7 @@ char *UTIL_VarArgs(char *format, ...)
static char string[1024]; static char string[1024];
va_start(argptr, format); va_start(argptr, format);
Q_vsnprintf(string, sizeof(string), format, argptr); Q_vsnprintf(string, sizeof string, format, argptr);
va_end(argptr); va_end(argptr);
return string; return string;

View File

@ -81,8 +81,8 @@ char* full_gamedir_path(const char* path, char* fullpath)
if (!realpath(buf, fullpath)) if (!realpath(buf, fullpath))
{ {
META_DEBUG(4, "Unable to get realpath for '%s': %s", buf, str_os_error()); META_DEBUG(4, "Unable to get realpath for '%s': %s", buf, str_os_error());
Q_strncpy(fullpath, path, sizeof(fullpath) - 1); Q_strncpy(fullpath, path, sizeof fullpath - 1);
fullpath[sizeof(fullpath) - 1] = '\0'; fullpath[sizeof fullpath - 1] = '\0';
} }
// Replace backslashes, etc. // Replace backslashes, etc.