2
0
mirror of https://github.com/rehlds/metamod-r.git synced 2024-12-27 07:05:34 +03:00

Refactoring

This commit is contained in:
s1lent 2017-11-18 22:53:18 +07:00
parent bc64710eb8
commit 0012c7779c
No known key found for this signature in database
GPG Key ID: 0FE401DC73916B5C
10 changed files with 24 additions and 28 deletions

View File

@ -346,7 +346,7 @@ size_t CJit::compile_callback(jitdata_t* jitdata)
auto codeSize = callback.GetCodeSize();
auto ptr = m_callback_allocator.allocate(codeSize);
return (size_t)memcpy(ptr, code, codeSize);
return (size_t)Q_memcpy(ptr, code, codeSize);
}
size_t CJit::compile_tramp(size_t ptr_to_func)

View File

@ -32,7 +32,7 @@ void MM_PRE_HOOK EXT_FUNC mm_ClientDisconnect(edict_t *pEntity)
// this forward can be disabled from metamod.cpp
void MM_PRE_HOOK mm_ClientCommand(edict_t *pEntity)
{
if (!strcmp(CMD_ARGV(0), "meta")) {
if (!Q_strcmp(CMD_ARGV(0), "meta")) {
client_meta(pEntity);
}
}
@ -184,7 +184,7 @@ C_DLLEXPORT int GetEntityAPI2(DLL_FUNCTIONS *pFunctionTable, int *interfaceVersi
return FALSE;
}
memcpy(pFunctionTable, &sFunctionTable, sizeof(DLL_FUNCTIONS));
Q_memcpy(pFunctionTable, &sFunctionTable, sizeof(DLL_FUNCTIONS));
return TRUE;
}
@ -211,7 +211,7 @@ C_DLLEXPORT int GetNewDLLFunctions(NEW_DLL_FUNCTIONS *pNewFunctionTable, int *in
}
g_meta_extdll.load();
memcpy(pNewFunctionTable, &sNewFunctionTable, sizeof(NEW_DLL_FUNCTIONS));
Q_memcpy(pNewFunctionTable, &sNewFunctionTable, sizeof(NEW_DLL_FUNCTIONS));
return TRUE;
}

View File

@ -50,7 +50,7 @@ bool lookup_game_postfixes(gamedll_t *gamedll)
Q_strlcpy(pathname, gamedll->pathname);
// find extensions and skip
char *pos = strrchr(pathname, '.');
char *pos = Q_strrchr(pathname, '.');
if (pos) {
*pos = '\0';
}

View File

@ -6,7 +6,7 @@ void mdebug_to_file(const char* fmt, ...)
va_list argptr;
va_start(argptr, fmt);
vsnprintf(buf, sizeof buf, fmt, argptr);
Q_vsnprintf(buf, sizeof buf, fmt, argptr);
va_end(argptr);
FILE* fp = fopen("mdebug.log", "a");

View File

@ -53,8 +53,7 @@ MPlugin::~MPlugin()
bool MPlugin::ini_parseline(char *line)
{
char buf[1024];
strncpy(buf, line, sizeof buf - 1);
buf[sizeof buf - 1] = '\0';
Q_strlcpy(buf, line);
// grab platform ("win32" or "linux")
char* ptr_token;
@ -282,8 +281,7 @@ char *MPlugin::resolve_dirs(const char *path, char *tempbuf, size_t maxlen) cons
// try other file prefixes in gamedir
char buf[MAX_PATH];
strncpy(buf, tempbuf, sizeof buf - 1);
buf[sizeof buf - 1] = '\0';
Q_strlcpy(buf, tempbuf);
char* found = resolve_suffix(buf, tempbuf, maxlen);
if (found)
@ -294,8 +292,7 @@ char *MPlugin::resolve_dirs(const char *path, char *tempbuf, size_t maxlen) cons
if (is_valid_path(tempbuf))
return tempbuf;
strncpy(buf, tempbuf, sizeof buf - 1);
buf[sizeof buf - 1] = '\0';
Q_strlcpy(buf, tempbuf);
// try other file prefixes for this path
return resolve_suffix(buf, tempbuf, maxlen);
@ -311,7 +308,7 @@ char *MPlugin::resolve_dirs(const char *path, char *tempbuf, size_t maxlen) cons
char* MPlugin::resolve_suffix(const char *path, char *tempbuf, size_t bufsize) const
{
if (Q_strstr(path, PLATFORM_DLEXT) && is_valid_path(path)) {
strncpy(tempbuf, path, bufsize - 1);
Q_strncpy(tempbuf, path, bufsize - 1);
tempbuf[bufsize - 1] = '\0';
return tempbuf;
}
@ -1115,7 +1112,7 @@ bool MPlugin::newer_file() const
return false;
}
time_t file_time = max(st.st_ctime, st.st_mtime);
time_t file_time = Q_max(st.st_ctime, st.st_mtime);
META_DEBUG(5, "newer_file? file=%s; load=%d, file=%d; ctime=%d, mtime=%d", m_file, m_time_loaded, file_time, st.st_ctime, st.st_mtime);
if (file_time > m_time_loaded)
return true;

View File

@ -200,7 +200,7 @@ int EXT_FUNC mutil_GetUserMsgID(plid_t plid, const char* msgname, int* size)
}
for (int n = 1; n < arraysize(g_engine_msg_names); n++) {
if (!strcmp(msgname, g_engine_msg_names[n])) {
if (!Q_strcmp(msgname, g_engine_msg_names[n])) {
if (size) *size = -1;
return n;
}
@ -361,7 +361,7 @@ const char* EXT_FUNC mutil_IsQueryingClientCvar(plid_t plid, const edict_t* pEdi
int EXT_FUNC mutil_MakeRequestId(plid_t plid)
{
//the offset is to distinguish from gamedll requests, if any
return abs(0xbeef << 16) + (++g_requestid_counter);
return Q_abs(0xbeef << 16) + (++g_requestid_counter);
}
void EXT_FUNC mutil_GetHookTables(plid_t plid, enginefuncs_t** peng, DLL_FUNCTIONS** pdll, NEW_DLL_FUNCTIONS** pnewdll)

View File

@ -27,8 +27,6 @@
#define O_BINARY 0
#endif
#elif defined(_WIN32)
#define snprintf _snprintf
#define vsnprintf _vsnprintf
#define stat64 _stat64
#define sleep(x) Sleep(x*1000)
#include <io.h>

View File

@ -14,12 +14,12 @@ char* UTIL_VarArgs(const char* format, ...)
short FixedSigned16(float value, float scale)
{
return (short)clamp(int(value * scale), SHRT_MIN, SHRT_MAX);
return (short)Q_clamp(int(value * scale), SHRT_MIN, SHRT_MAX);
}
unsigned short FixedUnsigned16(float value, float scale)
{
return (unsigned short)clamp(int(value * scale), 0, USHRT_MAX);
return (unsigned short)Q_clamp(int(value * scale), 0, USHRT_MAX);
}
void UTIL_HudMessage(edict_t* pEntity, const hudtextparms_t& textparms, const char* pMessage)
@ -52,13 +52,12 @@ void UTIL_HudMessage(edict_t* pEntity, const hudtextparms_t& textparms, const ch
if (textparms.effect == 2)
WRITE_SHORT(FixedUnsigned16(textparms.fxTime, 1 << 8));
if (strlen(pMessage) < 512) {
if (Q_strlen(pMessage) < 512) {
WRITE_STRING(pMessage);
}
else {
char tmp[512];
strncpy(tmp, pMessage, sizeof tmp - 1);
tmp[sizeof tmp - 1] = '\0';
Q_strlcpy(tmp, pMessage);
WRITE_STRING(tmp);
}
MESSAGE_END();

View File

@ -159,7 +159,7 @@ module_handle_t CSysModule::load(const char *filepath)
m_handle = dlopen(filepath, RTLD_NOW | RTLD_LOCAL | RTLD_DEEPBIND);
char buf[1024], dummy[1024], path[260];
sprintf(buf, "/proc/%i/maps", getpid());
Q_sprintf(buf, "/proc/%i/maps", getpid());
FILE* fp = fopen(buf, "r");

View File

@ -36,9 +36,9 @@ char* trimbuf(char* str)
for (ibuf = str; *ibuf && (byte)(*ibuf) < (byte)0x80 && isspace(*ibuf); ++ibuf)
;
int i = strlen(ibuf);
int i = Q_strlen(ibuf);
if (str != ibuf)
memmove(str, ibuf, i);
Q_memmove(str, ibuf, i);
while (--i >= 0) {
if (!isspace(str[i]))
@ -177,7 +177,9 @@ char* full_gamedir_path(const char* path, char* fullpath)
if (is_abs_path(path)) {
Q_strlcpy(buf, path);
}
else snprintf(buf, sizeof buf, "%s/%s", g_GameDLL.gamedir, path);
else {
Q_snprintf(buf, sizeof buf, "%s/%s", g_GameDLL.gamedir, path);
}
// Remove relative path components, if possible.
if (!realpath(buf, fullpath)) {
@ -197,7 +199,7 @@ void NORETURN Sys_Error(const char *error, ...)
static char text[1024];
va_start(argptr, error);
vsnprintf(text, sizeof(text), error, argptr);
Q_vsnprintf(text, sizeof(text), error, argptr);
va_end(argptr);
META_CONS("FATAL ERROR (shutting down): %s\n", text);