From 59ecab555b16186384ca7ccdeb5e4071b93b6fa3 Mon Sep 17 00:00:00 2001 From: Benoist <14257866+Kenzzer@users.noreply.github.com> Date: Tue, 31 Mar 2026 23:28:34 +0200 Subject: [PATCH] Bump SourcePawn submodule (#2428) --- core/logic/ForwardSys.cpp | 6 ++++++ core/logic/ForwardSys.h | 1 + extensions/dhooks/DynamicHooks/hook.cpp | 23 +++++++++++++++++++---- extensions/dhooks/bandaid.h | 23 +++++++++++++++++++++++ extensions/dhooks/vhook.cpp | 25 +++++++++++++++++++++---- sourcepawn | 2 +- 6 files changed, 71 insertions(+), 9 deletions(-) create mode 100644 extensions/dhooks/bandaid.h diff --git a/core/logic/ForwardSys.cpp b/core/logic/ForwardSys.cpp index e85cf3a6..0002eaa3 100644 --- a/core/logic/ForwardSys.cpp +++ b/core/logic/ForwardSys.cpp @@ -446,6 +446,12 @@ int CForward::PushCell(cell_t cell) return SP_ERROR_NONE; } +int CForward::PushInt64(int64_t value) +{ + // Not supported yet + return SetError(SP_ERROR_PARAM); +} + int CForward::PushFloat(float number) { if (m_curparam < m_numparams) diff --git a/core/logic/ForwardSys.h b/core/logic/ForwardSys.h index cd1b3b82..3677a0ef 100644 --- a/core/logic/ForwardSys.h +++ b/core/logic/ForwardSys.h @@ -49,6 +49,7 @@ public: //ICallable virtual int PushArray(cell_t *inarray, unsigned int cells, int flags); virtual int PushString(const char *string); virtual int PushStringEx(char *buffer, size_t length, int sz_flags, int cp_flags); + virtual int PushInt64(int64_t value); virtual void Cancel(); public: //IForward virtual const char *GetForwardName(); diff --git a/extensions/dhooks/DynamicHooks/hook.cpp b/extensions/dhooks/DynamicHooks/hook.cpp index 4454ea37..55e4f8aa 100644 --- a/extensions/dhooks/DynamicHooks/hook.cpp +++ b/extensions/dhooks/DynamicHooks/hook.cpp @@ -30,6 +30,7 @@ * * Adopted to provide similar features to SourceHook by AlliedModders LLC. */ +#include "bandaid.h" // ============================================================================ // >> INCLUDES @@ -642,8 +643,15 @@ void CHook::CreateBridge() // This will still call post hooks, but will skip the original function. masm.ret(m_pCallingConvention->GetPopSize()); - void* base = smutils->GetScriptingEngine()->AllocatePageMemory(masm.length()); - masm.emitToExecutableMemory(base); + void* base = smutils->GetScriptingEngine()->AllocatePageMemory(masm.total_size()); + DhookCodeChunk chunk((uint8_t*)base, masm.total_size()); + + // Can't let dtor call happen + LinkedCode* code = (LinkedCode*)new uint8_t[sizeof(LinkedCode)]; + *((DhookCodeChunk*)&code->chunk) = chunk; + masm.emitToExecutableMemory(code); + + delete[] (uint8_t*)code; m_pBridge = base; } @@ -728,8 +736,15 @@ void CHook::CreatePostCallback() masm.jmp(Operand(ExternalAddress(&pRetAddr))); // Generate the code - void* base = smutils->GetScriptingEngine()->AllocatePageMemory(masm.length()); - masm.emitToExecutableMemory(base); + void* base = smutils->GetScriptingEngine()->AllocatePageMemory(masm.total_size()); + DhookCodeChunk chunk((uint8_t*)base, masm.total_size()); + + // Can't let dtor call happen + LinkedCode* code = (LinkedCode*)new uint8_t[sizeof(LinkedCode)]; + *((DhookCodeChunk*)&code->chunk) = chunk; + masm.emitToExecutableMemory(code); + + delete[] (uint8_t*)code; m_pNewRetAddr = base; } diff --git a/extensions/dhooks/bandaid.h b/extensions/dhooks/bandaid.h new file mode 100644 index 00000000..1805be49 --- /dev/null +++ b/extensions/dhooks/bandaid.h @@ -0,0 +1,23 @@ +#pragma once + +// Yes this is bad, but whatever dhooks will be nuked soon +#include <../vm/code-allocator.h> + +class DhookCodePool : public ke::Refcounted { +public: + uint8_t* start_; + uint8_t* ptr_; + uint8_t* end_; + size_t size_; +}; + +struct DhookCodeChunk { + DhookCodeChunk(uint8_t* addr, size_t bytes) + : address(addr) + , bytes(bytes) { + } + + uint8_t pool[sizeof(ke::RefPtr)]; + uint8_t* address; + size_t bytes; +}; \ No newline at end of file diff --git a/extensions/dhooks/vhook.cpp b/extensions/dhooks/vhook.cpp index 228d875a..21b99e50 100644 --- a/extensions/dhooks/vhook.cpp +++ b/extensions/dhooks/vhook.cpp @@ -29,6 +29,8 @@ * Version: $Id$ */ +#include "bandaid.h" + #include "vhook.h" #include "vfunc_call.h" #include "util.h" @@ -175,8 +177,16 @@ void *GenerateThunk(HookSetup* hook) masm.pop(ebp); // restore ebp masm.ret(); - void *base = g_pSM->GetScriptingEngine()->AllocatePageMemory(masm.length()); - masm.emitToExecutableMemory(base); + void* base = smutils->GetScriptingEngine()->AllocatePageMemory(masm.total_size()); + DhookCodeChunk chunk((uint8_t*)base, masm.total_size()); + + // Can't let dtor call happen + LinkedCode* code = (LinkedCode*)new uint8_t[sizeof(LinkedCode)]; + *((DhookCodeChunk*)&code->chunk) = chunk; + masm.emitToExecutableMemory(code); + + delete[] (uint8_t*)code; + return base; } #else @@ -215,8 +225,15 @@ void *GenerateThunk(HookSetup* hook) masm.addl(esp, ecx); // remove arguments masm.jmp(edx); // return to caller - void *base = g_pSM->GetScriptingEngine()->AllocatePageMemory(masm.length()); - masm.emitToExecutableMemory(base); + void* base = smutils->GetScriptingEngine()->AllocatePageMemory(masm.total_size()); + DhookCodeChunk chunk((uint8_t*)base, masm.total_size()); + + // Can't let dtor call happen + LinkedCode* code = (LinkedCode*)new uint8_t[sizeof(LinkedCode)]; + *((DhookCodeChunk*)&code->chunk) = chunk; + masm.emitToExecutableMemory(code); + + delete[] (uint8_t*)code; return base; } #endif diff --git a/sourcepawn b/sourcepawn index 37930342..b8a92930 160000 --- a/sourcepawn +++ b/sourcepawn @@ -1 +1 @@ -Subproject commit 3793034233c29b831e0148f3155372bf2c1d4d0e +Subproject commit b8a92930642efde670bc2bbbda86a622db648ade