diff --git a/core/interfaces/IPluginFunction.h b/core/interfaces/IPluginFunction.h index c77e9552..8002cd9e 100644 --- a/core/interfaces/IPluginFunction.h +++ b/core/interfaces/IPluginFunction.h @@ -8,6 +8,7 @@ namespace SourceMod #define SMFUNC_COPYBACK_NONE (0) /* Never copy an array back */ #define SMFUNC_COPYBACK_ONCE (1<<0) /* Copy an array back after call */ #define SMFUNC_COPYBACK_ALWAYS (1<<1) /* Copy an array back after subsequent calls (forwards) */ + #define SMFUNC_ARRAY_NOINIT (1<<2) /* The array is not copied at first, but copyback is performed */ /** * @brief Represents what a function needs to implement in order to be callable. diff --git a/core/systems/CFunction.cpp b/core/systems/CFunction.cpp index 18d01909..851f51be 100644 --- a/core/systems/CFunction.cpp +++ b/core/systems/CFunction.cpp @@ -114,7 +114,10 @@ int CFunction::PushArray(cell_t *inarray, unsigned int cells, cell_t **phys_addr if (inarray) { - memcpy(info->phys_addr, inarray, sizeof(cell_t) * cells); + if (!(copyback & SMFUNC_ARRAY_NOINIT)) + { + memcpy(info->phys_addr, inarray, sizeof(cell_t) * cells); + } info->orig_addr = inarray; } else { info->orig_addr = info->phys_addr; @@ -257,7 +260,7 @@ int CFunction::Execute(cell_t *result, IFunctionCopybackReader *reader) } } _skipcopy: - base->HeapRelease(temp_info[numparams].local_addr); + base->HeapPop(temp_info[numparams].local_addr); temp_info[numparams].marked = false; } diff --git a/core/systems/ForwardSys.cpp b/core/systems/ForwardSys.cpp index 428bf31c..99ecdf51 100644 --- a/core/systems/ForwardSys.cpp +++ b/core/systems/ForwardSys.cpp @@ -418,7 +418,7 @@ void CForward::_Int_PushArray(cell_t *inarray, unsigned int cells, int flags) for (iter=m_functions.begin(); iter!=m_functions.end(); iter++) { func = (*iter); - func->PushArray(NULL, cells, NULL, flags); + func->PushArray(inarray, cells, NULL, flags|SMFUNC_ARRAY_NOINIT); } m_CopyBacks.recopy[m_CopyBacks.numrecopy++] = m_curparam; m_CopyBacks.orig_addrs[m_curparam] = inarray;