2
0
mirror of https://github.com/rehlds/metamod-r.git synced 2025-01-13 15:18:19 +03:00

Add extra filed for esp to meta globals

This commit is contained in:
asmodai 2017-06-26 18:26:13 +03:00
parent 06535237da
commit eef29cb742
2 changed files with 16 additions and 11 deletions

View File

@ -33,6 +33,7 @@ private:
mg_status = 8, mg_status = 8,
mg_orig_ret = 12, mg_orig_ret = 12,
mg_over_ret = 16, mg_over_ret = 16,
mg_esp_save = 20
}; };
enum enum
@ -53,7 +54,7 @@ CForwardCallbackJIT::CForwardCallbackJIT(jitdata_t* jitdata) : m_jitdata(jitdata
void CForwardCallbackJIT::naked_main() void CForwardCallbackJIT::naked_main()
{ {
jit_debug("Enter %s\n", m_jitdata->name); //jit_debug("Enter %s\n", m_jitdata->name);
// prologue // prologue
push(ebx); push(ebx);
@ -96,14 +97,14 @@ void CForwardCallbackJIT::naked_main()
else else
sub(esp, framesize); sub(esp, framesize);
size_t mg_backup = framesize - xmmreg_size - sizeof(int); size_t mg_backup = framesize - sizeof(meta_globals_t);
// setup globals ptr and backup old data // setup globals ptr and backup old data
mov(globals, size_t(&g_metaGlobals)); mov(globals, size_t(&g_metaGlobals));
movaps(xmm0, xmmword_ptr[globals]); movaps(xmm0, xmmword_ptr[globals]);
mov(eax, dword_ptr[globals + xmmreg_size]); movq(xmm1, qword_ptr[globals + xmmreg_size]);
movaps(xmmword_ptr[esp + mg_backup + sizeof(int)], xmm0); movaps(xmmword_ptr[esp + mg_backup + sizeof(int) * 2], xmm0);
mov(dword_ptr[esp + mg_backup], eax); movq(qword_ptr[esp + mg_backup], xmm1);
// call metamod's pre hook if present // call metamod's pre hook if present
if (m_jitdata->mm_hook && m_jitdata->mm_hook_time == P_PRE) { if (m_jitdata->mm_hook && m_jitdata->mm_hook_time == P_PRE) {
@ -152,7 +153,7 @@ void CForwardCallbackJIT::naked_main()
mov(dword_ptr[globals + mg_prev_mres], eax); mov(dword_ptr[globals + mg_prev_mres], eax);
} }
jit_debug("Calling pre [%s] for plug [%s]\n", m_jitdata->name, plug->description()); //jit_debug("Calling pre [%s] for plug [%s]\n", m_jitdata->name, plug->description());
call_func(ecx); call_func(ecx);
mov(edx, dword_ptr[globals + mg_mres]); mov(edx, dword_ptr[globals + mg_mres]);
@ -233,7 +234,7 @@ void CForwardCallbackJIT::naked_main()
mov(dword_ptr[globals + mg_prev_mres], eax); mov(dword_ptr[globals + mg_prev_mres], eax);
} }
jit_debug("Calling post [%s] for plug [%s]\n", m_jitdata->name, plug->description()); //jit_debug("Calling post [%s] for plug [%s]\n", m_jitdata->name, plug->description());
call_func(ecx); call_func(ecx);
mov(edx, dword_ptr[globals + mg_mres]); mov(edx, dword_ptr[globals + mg_mres]);
@ -258,10 +259,10 @@ void CForwardCallbackJIT::naked_main()
call_func(ecx); call_func(ecx);
} }
movaps(xmm0, xmmword_ptr[esp + mg_backup + sizeof(int)]); movaps(xmm0, xmmword_ptr[esp + mg_backup + sizeof(int) * 2]);
mov(eax, dword_ptr[esp + mg_backup]); movq(xmm1, qword_ptr[esp + mg_backup]);
movaps(xmmword_ptr[globals], xmm0); movaps(xmmword_ptr[globals], xmm0);
mov(dword_ptr[globals + xmmreg_size], eax); movq(qword_ptr[globals + xmmreg_size], xmm1);
if (m_jitdata->has_ret) { if (m_jitdata->has_ret) {
mov(eax, dword_ptr[esp + orig_ret]); mov(eax, dword_ptr[esp + orig_ret]);
@ -273,7 +274,7 @@ void CForwardCallbackJIT::naked_main()
mov(esp, ebp); mov(esp, ebp);
pop(ebp); pop(ebp);
pop(ebx); pop(ebx);
jit_debug("Leave %s\n", m_jitdata->name); //jit_debug("Leave %s\n", m_jitdata->name);
ret(); ret();
} }

View File

@ -47,6 +47,10 @@ struct meta_globals_t
META_RES status; // readable; "highest" return flag so far META_RES status; // readable; "highest" return flag so far
void *orig_ret; // readable; return value from "real" function void *orig_ret; // readable; return value from "real" function
void *override_ret; // readable; return value from overriding/superceding plugin void *override_ret; // readable; return value from overriding/superceding plugin
#ifdef METAMOD_CORE
int esp_save;
#endif
}; };
extern meta_globals_t *gpMetaGlobals; extern meta_globals_t *gpMetaGlobals;