mirror of
https://github.com/alliedmodders/amxmodx.git
synced 2025-01-26 05:38:04 +03:00
The prepare*Array functions now have a third "bool copyBack" parameter which defaults to false and specifies whether the array should be copied from plugin space to core / module space after function execution (=whether the original array should be updated)
This commit is contained in:
parent
768ea7519f
commit
34abaa1d56
@ -128,6 +128,8 @@ cell CForward::execute(cell *params, ForwardPreparedArray *preparedArrays)
|
|||||||
else if (m_ParamTypes[i] == FP_ARRAY)
|
else if (m_ParamTypes[i] == FP_ARRAY)
|
||||||
{
|
{
|
||||||
// copy back
|
// copy back
|
||||||
|
if (preparedArrays[params[i]].copyBack)
|
||||||
|
{
|
||||||
cell *tmp = physAddrs[i];
|
cell *tmp = physAddrs[i];
|
||||||
if (preparedArrays[params[i]].type == Type_Cell)
|
if (preparedArrays[params[i]].type == Type_Cell)
|
||||||
{
|
{
|
||||||
@ -142,6 +144,7 @@ cell CForward::execute(cell *params, ForwardPreparedArray *preparedArrays)
|
|||||||
amx_Release(iter->pPlugin->getAMX(), realParams[i]);
|
amx_Release(iter->pPlugin->getAMX(), realParams[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// decide what to do (based on exectype and retval)
|
// decide what to do (based on exectype and retval)
|
||||||
switch (m_ExecType)
|
switch (m_ExecType)
|
||||||
@ -190,6 +193,7 @@ cell CSPForward::execute(cell *params, ForwardPreparedArray *preparedArrays)
|
|||||||
{
|
{
|
||||||
if (isFree)
|
if (isFree)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
const int STRINGEX_MAXLENGTH = 128;
|
const int STRINGEX_MAXLENGTH = 128;
|
||||||
|
|
||||||
cell realParams[FORWARD_MAX_PARAMS];
|
cell realParams[FORWARD_MAX_PARAMS];
|
||||||
@ -258,6 +262,8 @@ cell CSPForward::execute(cell *params, ForwardPreparedArray *preparedArrays)
|
|||||||
else if (m_ParamTypes[i] == FP_ARRAY)
|
else if (m_ParamTypes[i] == FP_ARRAY)
|
||||||
{
|
{
|
||||||
// copy back
|
// copy back
|
||||||
|
if (preparedArrays[params[i]].copyBack)
|
||||||
|
{
|
||||||
cell *tmp = physAddrs[i];
|
cell *tmp = physAddrs[i];
|
||||||
if (preparedArrays[params[i]].type == Type_Cell)
|
if (preparedArrays[params[i]].type == Type_Cell)
|
||||||
{
|
{
|
||||||
@ -272,6 +278,7 @@ cell CSPForward::execute(cell *params, ForwardPreparedArray *preparedArrays)
|
|||||||
amx_Release(m_Amx, realParams[i]);
|
amx_Release(m_Amx, realParams[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
@ -288,11 +295,12 @@ int CForwardMngr::registerForward(const char *funcName, ForwardExecType et, int
|
|||||||
|
|
||||||
int CForwardMngr::registerSPForward(int func, AMX *amx, int numParams, const ForwardParam *paramTypes)
|
int CForwardMngr::registerSPForward(int func, AMX *amx, int numParams, const ForwardParam *paramTypes)
|
||||||
{
|
{
|
||||||
int retVal = (m_SPForwards.size() << 1) | 1;
|
int retVal = -1;
|
||||||
CSPForward *pForward;
|
CSPForward *pForward;
|
||||||
if (!m_FreeSPForwards.empty())
|
if (!m_FreeSPForwards.empty())
|
||||||
{
|
{
|
||||||
pForward = m_SPForwards[m_FreeSPForwards.front() >> 1];
|
retVal = m_FreeSPForwards.front();
|
||||||
|
pForward = m_SPForwards[retVal >> 1];
|
||||||
pForward->Set(func, amx, numParams, paramTypes);
|
pForward->Set(func, amx, numParams, paramTypes);
|
||||||
if (pForward->getFuncsNum() == 0)
|
if (pForward->getFuncsNum() == 0)
|
||||||
return -1;
|
return -1;
|
||||||
@ -300,6 +308,7 @@ int CForwardMngr::registerSPForward(int func, AMX *amx, int numParams, const For
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
retVal = (m_SPForwards.size() << 1) | 1;
|
||||||
pForward = new CSPForward();
|
pForward = new CSPForward();
|
||||||
if (!pForward)
|
if (!pForward)
|
||||||
return -1;
|
return -1;
|
||||||
@ -491,22 +500,23 @@ cell executeForwards(int id, ...)
|
|||||||
return g_forwards.executeForwards(id, params);
|
return g_forwards.executeForwards(id, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
cell CForwardMngr::prepareArray(void *ptr, unsigned int size, ForwardArrayElemType type)
|
cell CForwardMngr::prepareArray(void *ptr, unsigned int size, ForwardArrayElemType type, bool copyBack)
|
||||||
{
|
{
|
||||||
m_TmpArrays[m_TmpArraysNum].ptr = ptr;
|
m_TmpArrays[m_TmpArraysNum].ptr = ptr;
|
||||||
m_TmpArrays[m_TmpArraysNum].size = size;
|
m_TmpArrays[m_TmpArraysNum].size = size;
|
||||||
m_TmpArrays[m_TmpArraysNum].type = type;
|
m_TmpArrays[m_TmpArraysNum].type = type;
|
||||||
|
m_TmpArrays[m_TmpArraysNum].copyBack = copyBack;
|
||||||
return m_TmpArraysNum++;
|
return m_TmpArraysNum++;
|
||||||
}
|
}
|
||||||
|
|
||||||
cell prepareCellArray(cell *ptr, unsigned int size)
|
cell prepareCellArray(cell *ptr, unsigned int size, bool copyBack)
|
||||||
{
|
{
|
||||||
return g_forwards.prepareArray((void*)ptr, size, Type_Cell);
|
return g_forwards.prepareArray((void*)ptr, size, Type_Cell, copyBack);
|
||||||
}
|
}
|
||||||
|
|
||||||
cell prepareCharArray(char *ptr, unsigned int size)
|
cell prepareCharArray(char *ptr, unsigned int size, bool copyBack)
|
||||||
{
|
{
|
||||||
return g_forwards.prepareArray((void*)ptr, size, Type_Char);
|
return g_forwards.prepareArray((void*)ptr, size, Type_Char, copyBack);
|
||||||
}
|
}
|
||||||
|
|
||||||
void unregisterSPForward(int id)
|
void unregisterSPForward(int id)
|
||||||
|
@ -79,6 +79,7 @@ struct ForwardPreparedArray
|
|||||||
void *ptr;
|
void *ptr;
|
||||||
ForwardArrayElemType type;
|
ForwardArrayElemType type;
|
||||||
unsigned int size;
|
unsigned int size;
|
||||||
|
bool copyBack;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Normal forward
|
// Normal forward
|
||||||
@ -185,7 +186,8 @@ public:
|
|||||||
int getParamsNum(int id) const; // get num of params of a forward
|
int getParamsNum(int id) const; // get num of params of a forward
|
||||||
int getFuncsNum(int id) const; // get num of found functions of a forward
|
int getFuncsNum(int id) const; // get num of found functions of a forward
|
||||||
ForwardParam getParamType(int id, int paramId) const;
|
ForwardParam getParamType(int id, int paramId) const;
|
||||||
cell prepareArray(void *ptr, unsigned int size, ForwardArrayElemType type); // prepare array
|
cell prepareArray(void *ptr, unsigned int size, ForwardArrayElemType type,
|
||||||
|
bool copyBack); // prepare array
|
||||||
};
|
};
|
||||||
|
|
||||||
// (un)register forward
|
// (un)register forward
|
||||||
@ -197,8 +199,8 @@ void unregisterSPForward(int id);
|
|||||||
// execute forwards
|
// execute forwards
|
||||||
cell executeForwards(int id, ...);
|
cell executeForwards(int id, ...);
|
||||||
// prepare array
|
// prepare array
|
||||||
cell prepareCellArray(cell *ptr, unsigned int size);
|
cell prepareCellArray(cell *ptr, unsigned int size, bool copyBack = false);
|
||||||
cell prepareCharArray(char *ptr, unsigned int size);
|
cell prepareCharArray(char *ptr, unsigned int size, bool copyBack = false);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user