From 87548b9af9e53aa501ddcb8797238a434d8a4156 Mon Sep 17 00:00:00 2001 From: asmodai Date: Fri, 6 Jan 2017 22:11:28 +0300 Subject: [PATCH] Some cosmetic fixes --- metamod/src/api_info.h | 9 +++++---- metamod/src/callback_jit.cpp | 26 ++++++++++++++------------ metamod/src/callback_jit.h | 2 +- metamod/src/meta_eiface.cpp | 2 +- metamod/src/metamod.cpp | 2 +- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/metamod/src/api_info.h b/metamod/src/api_info.h index eda530c..308eae7 100644 --- a/metamod/src/api_info.h +++ b/metamod/src/api_info.h @@ -1,9 +1,10 @@ #pragma once -#include "types_meta.h" - -#define P_PRE 0 // plugin function called before gamedll -#define P_POST 1 // plugin function called after gamedll +enum +{ + P_PRE, // plugin function called before gamedll + P_POST, // plugin function called after gamedll +}; struct api_info_t { diff --git a/metamod/src/callback_jit.cpp b/metamod/src/callback_jit.cpp index c38c41d..8fd3f33 100644 --- a/metamod/src/callback_jit.cpp +++ b/metamod/src/callback_jit.cpp @@ -25,7 +25,7 @@ class CForwardCallbackJIT : public jitasm::functionhas_ret ? 8 : 0; + auto mg_backup = m_jitdata->has_ret ? 8 /* orig + over */ : 0; auto framesize = mg_backup + sizeof(meta_globals_t); if (m_jitdata->has_varargs) { + size_t buf_offset = framesize; + sub(esp, framesize += MAX_STRBUF_LEN); // format varargs lea(edx, dword_ptr[ebp + 8 + m_jitdata->args_count * 4]); // varargs ptr - lea(eax, dword_ptr[esp + mg_backup + sizeof(meta_globals_t)]); // buf ptr + lea(eax, dword_ptr[esp + buf_offset]); // buf ptr mov(ecx, size_t(vsnprintf)); push(edx); - push(dword_ptr[ebp + 8 + (m_jitdata->args_count - 1) * 4]); // last arg of pfn (format) + push(dword_ptr[ebp + 8 + (m_jitdata->args_count - 1) * 4]); // last arg of pfn (format string) push(MAX_STRBUF_LEN); push(eax); call(ecx); @@ -80,7 +82,7 @@ void CForwardCallbackJIT::naked_main() else sub(esp, framesize); - // setup globals ptr + // setup globals ptr and backup old data mov(globals, size_t(&g_metaGlobals)); movups(xmm0, xmmword_ptr[globals]); mov(eax, dword_ptr[globals + 16]); @@ -256,25 +258,25 @@ void CForwardCallbackJIT::naked_main() void CForwardCallbackJIT::call_func(jitasm::Frontend::Reg32 addr) { - const size_t normal_args_count = m_jitdata->args_count - (m_jitdata->has_varargs ? 1u : 0u); - const size_t strbuf_stack_offset = (m_jitdata->has_ret ? 8u : 0u) + sizeof(meta_globals_t); + 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 ? 8u : 0u) + sizeof(meta_globals_t); - // push formatted buf + // push formatted buf instead of format string if (m_jitdata->has_varargs) { - lea(eax, dword_ptr[esp + strbuf_stack_offset]); + lea(eax, dword_ptr[esp + strbuf_offset]); push(eax); } // push normal args - for (size_t j = normal_args_count; j > 0; j--) - push(dword_ptr[ebp + 8 + (j - 1) * 4]); + for (size_t j = fixed_args_count; j > 0; j--) + push(dword_ptr[ebp + 8 + (j - 1) * sizeof(int)]); // call call(addr); // pop stack if (m_jitdata->args_count) - add(esp, m_jitdata->args_count * 4); + add(esp, m_jitdata->args_count * sizeof(int)); } class CSimpleJmp : public jitasm::function diff --git a/metamod/src/callback_jit.h b/metamod/src/callback_jit.h index ebddde8..6151b1e 100644 --- a/metamod/src/callback_jit.h +++ b/metamod/src/callback_jit.h @@ -5,11 +5,11 @@ struct jitdata_t { size_t pfn_original; + size_t pfn_offset; // from fn table uint8 args_count; bool has_ret; bool has_varargs; uint8 mm_hook_time; - size_t pfn_offset; // from fn table size_t mm_hook; MPlugin* plugins; diff --git a/metamod/src/meta_eiface.cpp b/metamod/src/meta_eiface.cpp index 23c5b99..51758d9 100644 --- a/metamod/src/meta_eiface.cpp +++ b/metamod/src/meta_eiface.cpp @@ -8,7 +8,7 @@ void meta_new_dll_functions_t::set_from(NEW_DLL_FUNCTIONS* _pFuncs) void meta_new_dll_functions_t::copy_to(NEW_DLL_FUNCTIONS *_pFuncs) const { #if 0 - // TODO: Implemented check regamedll + // TODO: Implement regamedll check // exit #endif diff --git a/metamod/src/metamod.cpp b/metamod/src/metamod.cpp index 4133fd4..fe43521 100644 --- a/metamod/src/metamod.cpp +++ b/metamod/src/metamod.cpp @@ -44,7 +44,7 @@ void metamod_startup() const char *cp; META_CONS(" "); - META_CONS(" Metamod version %s Copyright (c) 2001-2016 Will Day (modification ReHLDS Team)", APP_VERSION_STRD); + META_CONS(" Metamod version %s Copyright (c) 2001-2016 Will Day (modification by ReHLDS Team)", APP_VERSION_STRD); META_CONS(" Metamod comes with ABSOLUTELY NO WARRANTY; for details type `meta gpl'."); META_CONS(" This is free software, and you are welcome to redistribute it"); META_CONS(" under certain conditions; type `meta gpl' for details.");