SDKTools Fixathon!
Fixed amb647 - Returning objects by reference wasn't working Various fixes for byref/pointer params and return values (including working copyback) --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401141
This commit is contained in:
parent
59f47dfd17
commit
8e5a1d58be
@ -97,10 +97,6 @@ ValveCall *CreateValveCall(void *addr,
|
||||
return NULL;
|
||||
}
|
||||
retBufSize = retBuf.size;
|
||||
if (retbuf_needs_extra)
|
||||
{
|
||||
retBufSize += size;
|
||||
}
|
||||
}
|
||||
|
||||
/* Get parameter info */
|
||||
@ -255,10 +251,6 @@ ValveCall *CreateValveVCall(unsigned int vtableIdx,
|
||||
return NULL;
|
||||
}
|
||||
retBufSize = retBuf.size;
|
||||
if (retbuf_needs_extra)
|
||||
{
|
||||
retBufSize += size;
|
||||
}
|
||||
}
|
||||
|
||||
/* Get parameter info */
|
||||
|
@ -49,14 +49,14 @@ ValvePassInfo s_params[SP_MAX_EXEC_PARAMS];
|
||||
|
||||
inline void DecodePassMethod(ValveType vtype, SDKPassMethod method, PassType &type, unsigned int &flags)
|
||||
{
|
||||
if (method == SDKPass_Pointer)
|
||||
if (method == SDKPass_Pointer || method == SDKPass_ByRef)
|
||||
{
|
||||
type = PassType_Basic;
|
||||
if (vtype == Valve_POD
|
||||
|| vtype == Valve_Float
|
||||
|| vtype == Valve_Bool)
|
||||
{
|
||||
flags = PASSFLAG_ASPOINTER;
|
||||
flags = PASSFLAG_BYVAL | PASSFLAG_ASPOINTER;
|
||||
} else {
|
||||
flags = PASSFLAG_BYVAL;
|
||||
}
|
||||
@ -72,15 +72,6 @@ inline void DecodePassMethod(ValveType vtype, SDKPassMethod method, PassType &ty
|
||||
type = PassType_Basic;
|
||||
}
|
||||
flags = PASSFLAG_BYVAL;
|
||||
} else if (method == SDKPass_ByRef) {
|
||||
if (vtype == Valve_Vector
|
||||
|| vtype == Valve_QAngle)
|
||||
{
|
||||
type = PassType_Object;
|
||||
} else {
|
||||
type = PassType_Basic;
|
||||
}
|
||||
flags = PASSFLAG_BYREF;
|
||||
}
|
||||
}
|
||||
|
||||
@ -193,10 +184,17 @@ static cell_t PrepSDKCall_AddParameter(IPluginContext *pContext, const cell_t *p
|
||||
|
||||
ValvePassInfo *info = &s_params[s_numparams++];
|
||||
info->vtype = (ValveType)params[1];
|
||||
DecodePassMethod(info->vtype, (SDKPassMethod)params[2], info->type, info->flags);
|
||||
SDKPassMethod method = (SDKPassMethod)params[2];
|
||||
DecodePassMethod(info->vtype, method, info->type, info->flags);
|
||||
info->decflags = params[3] | VDECODE_FLAG_BYREF;
|
||||
info->encflags = params[4];
|
||||
|
||||
/* Since SDKPass_ByRef acts like SDKPass_Pointer we can't allow NULL, just in case */
|
||||
if (method == SDKPass_ByRef)
|
||||
{
|
||||
info->decflags &= ~VDECODE_FLAG_ALLOWNULL;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -406,14 +404,14 @@ static cell_t SDKCall(IPluginContext *pContext, const cell_t *params)
|
||||
return engine->IndexOfEdict(pEdict);
|
||||
} else if (vc->retinfo->vtype == Valve_Bool) {
|
||||
bool *addr = (bool *)vc->retbuf;
|
||||
if (vc->retinfo->flags & PASSFLAG_BYREF)
|
||||
if (vc->retinfo->flags & PASSFLAG_ASPOINTER)
|
||||
{
|
||||
addr = *(bool **)addr;
|
||||
}
|
||||
return *addr ? 1 : 0;
|
||||
} else {
|
||||
cell_t *addr = (cell_t *)vc->retbuf;
|
||||
if (vc->retinfo->flags & PASSFLAG_BYREF)
|
||||
if (vc->retinfo->flags & PASSFLAG_ASPOINTER)
|
||||
{
|
||||
addr = *(cell_t **)addr;
|
||||
}
|
||||
|
@ -114,6 +114,7 @@ size_t ValveParamToBinParam(ValveType type,
|
||||
info->flags = flags;
|
||||
if (flags & PASSFLAG_ASPOINTER)
|
||||
{
|
||||
needs_extra = true;
|
||||
info->size = sizeof(int *);
|
||||
return sizeof(int *) + sizeof(int);
|
||||
} else {
|
||||
@ -127,6 +128,7 @@ size_t ValveParamToBinParam(ValveType type,
|
||||
info->flags = flags;
|
||||
if (flags & PASSFLAG_ASPOINTER)
|
||||
{
|
||||
needs_extra = true;
|
||||
info->size = sizeof(bool *);
|
||||
return sizeof(bool *) + sizeof(bool);
|
||||
} else {
|
||||
@ -136,13 +138,15 @@ size_t ValveParamToBinParam(ValveType type,
|
||||
}
|
||||
case Valve_Float:
|
||||
{
|
||||
info->type = PassType_Float;
|
||||
info->flags = flags;
|
||||
if (flags & PASSFLAG_ASPOINTER)
|
||||
{
|
||||
needs_extra = true;
|
||||
info->type = PassType_Basic;
|
||||
info->size = sizeof(float *);
|
||||
return sizeof(float *) + sizeof(float);
|
||||
} else {
|
||||
info->type = PassType_Float;
|
||||
info->size = sizeof(float);
|
||||
return sizeof(float);
|
||||
}
|
||||
@ -167,7 +171,7 @@ DataStatus EncodeValveParam(IPluginContext *pContext,
|
||||
|
||||
if (data->type == PassType_Basic)
|
||||
{
|
||||
v = *(Vector **)((unsigned char *)buffer + sizeof(Vector *));
|
||||
v = *(Vector **)buffer;
|
||||
} else if (data->type == PassType_Object) {
|
||||
v = (Vector *)buffer;
|
||||
}
|
||||
@ -187,7 +191,7 @@ DataStatus EncodeValveParam(IPluginContext *pContext,
|
||||
|
||||
if (data->type == PassType_Basic)
|
||||
{
|
||||
q = *(QAngle **)((unsigned char *)buffer + sizeof(QAngle *));
|
||||
q = *(QAngle **)buffer;
|
||||
} else if (data->type == PassType_Object) {
|
||||
q = (QAngle *)buffer;
|
||||
}
|
||||
@ -241,7 +245,7 @@ DataStatus EncodeValveParam(IPluginContext *pContext,
|
||||
|
||||
if (data->flags & PASSFLAG_ASPOINTER)
|
||||
{
|
||||
buffer = (char *)buffer + sizeof(void *);
|
||||
buffer = *(cell_t **)buffer;
|
||||
}
|
||||
|
||||
*addr = *(cell_t *)buffer;
|
||||
@ -255,7 +259,7 @@ DataStatus EncodeValveParam(IPluginContext *pContext,
|
||||
|
||||
if (data->flags & PASSFLAG_ASPOINTER)
|
||||
{
|
||||
buffer = (char *)buffer + sizeof(bool *);
|
||||
buffer = *(bool **)buffer;
|
||||
}
|
||||
|
||||
*addr = *(bool *)buffer ? 1 : 0;
|
||||
@ -565,7 +569,7 @@ DataStatus DecodeValveParam(IPluginContext *pContext,
|
||||
}
|
||||
if (data->flags & PASSFLAG_ASPOINTER)
|
||||
{
|
||||
*(void **)buffer = (char *)buffer + sizeof(void *);
|
||||
*(void **)buffer = (unsigned char *)_buffer + pCall->stackEnd + data->obj_offset;
|
||||
buffer = *(void **)buffer;
|
||||
}
|
||||
*(cell_t *)buffer = param;
|
||||
@ -581,7 +585,7 @@ DataStatus DecodeValveParam(IPluginContext *pContext,
|
||||
}
|
||||
if (data->flags & PASSFLAG_ASPOINTER)
|
||||
{
|
||||
*(bool **)buffer = (bool *)((char *)buffer + sizeof(bool *));
|
||||
*(bool **)buffer = (bool *)((unsigned char *)_buffer + pCall->stackEnd + data->obj_offset);
|
||||
buffer = *(bool **)buffer;
|
||||
}
|
||||
*(bool *)buffer = param ? true : false;
|
||||
|
Loading…
Reference in New Issue
Block a user