Fix returns
This commit is contained in:
parent
ae3ca716ce
commit
d655e31e95
13
natives.cpp
13
natives.cpp
@ -223,14 +223,13 @@ cell_t Native_SetReturn(IPluginContext *pContext, const cell_t *params)
|
|||||||
|
|
||||||
CBaseEntity *pEnt;
|
CBaseEntity *pEnt;
|
||||||
edict_t *pEdict;
|
edict_t *pEdict;
|
||||||
float *fpVal;
|
|
||||||
switch(returnStruct->type)
|
switch(returnStruct->type)
|
||||||
{
|
{
|
||||||
case ReturnType_Int:
|
case ReturnType_Int:
|
||||||
returnStruct->newResult = (int *)params[2];
|
*(int *)returnStruct->newResult = params[2];
|
||||||
break;
|
break;
|
||||||
case ReturnType_Bool:
|
case ReturnType_Bool:
|
||||||
returnStruct->newResult = (bool *)(params[2]);
|
*(bool *)returnStruct->newResult = params[2] != 0;
|
||||||
break;
|
break;
|
||||||
case ReturnType_CBaseEntity:
|
case ReturnType_CBaseEntity:
|
||||||
pEnt = UTIL_GetCBaseEntity(params[2]);
|
pEnt = UTIL_GetCBaseEntity(params[2]);
|
||||||
@ -238,7 +237,7 @@ cell_t Native_SetReturn(IPluginContext *pContext, const cell_t *params)
|
|||||||
{
|
{
|
||||||
return pContext->ThrowNativeError("Invalid entity index passed for return value");
|
return pContext->ThrowNativeError("Invalid entity index passed for return value");
|
||||||
}
|
}
|
||||||
returnStruct->newResult = pEnt;
|
*(CBaseEntity **)returnStruct->newResult = pEnt;
|
||||||
break;
|
break;
|
||||||
case ReturnType_Edict:
|
case ReturnType_Edict:
|
||||||
pEdict = gamehelpers->EdictOfIndex(params[2]);
|
pEdict = gamehelpers->EdictOfIndex(params[2]);
|
||||||
@ -246,12 +245,10 @@ cell_t Native_SetReturn(IPluginContext *pContext, const cell_t *params)
|
|||||||
{
|
{
|
||||||
pContext->ThrowNativeError("Invalid entity index passed for return value");
|
pContext->ThrowNativeError("Invalid entity index passed for return value");
|
||||||
}
|
}
|
||||||
returnStruct->newResult = pEdict;
|
*(edict_t **)returnStruct->newResult = pEdict;
|
||||||
break;
|
break;
|
||||||
case ReturnType_Float:
|
case ReturnType_Float:
|
||||||
fpVal = new float;
|
*(float *)returnStruct->newResult = sp_ctof(params[2]);
|
||||||
*fpVal = sp_ctof(params[2]);
|
|
||||||
returnStruct->newResult = fpVal;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return pContext->ThrowNativeError("Invalid param type (%i) to get",returnStruct->type);
|
return pContext->ThrowNativeError("Invalid param type (%i) to get",returnStruct->type);
|
||||||
|
30
vhook.cpp
30
vhook.cpp
@ -114,9 +114,8 @@ HookReturnStruct *GetReturnStruct(DHooksCallback *dg, const void *result)
|
|||||||
HookReturnStruct *res = new HookReturnStruct();
|
HookReturnStruct *res = new HookReturnStruct();
|
||||||
res->isChanged = false;
|
res->isChanged = false;
|
||||||
res->type = dg->returnType;
|
res->type = dg->returnType;
|
||||||
res->newResult = NULL;
|
res->newResult = malloc(sizeof(void *));
|
||||||
|
res->orgResult = malloc(sizeof(void *));
|
||||||
float *fpVal = NULL;
|
|
||||||
|
|
||||||
if(result && dg->post)
|
if(result && dg->post)
|
||||||
{
|
{
|
||||||
@ -125,17 +124,15 @@ HookReturnStruct *GetReturnStruct(DHooksCallback *dg, const void *result)
|
|||||||
//ReturnType_String,
|
//ReturnType_String,
|
||||||
//ReturnType_Vector,
|
//ReturnType_Vector,
|
||||||
case ReturnType_Int:
|
case ReturnType_Int:
|
||||||
res->orgResult = (int *)result;
|
*(int *)res->orgResult = *(int *)result;
|
||||||
case ReturnType_Bool:
|
case ReturnType_Bool:
|
||||||
res->orgResult = (bool *)result;
|
*(int *)res->orgResult = *(bool *)result;
|
||||||
break;
|
break;
|
||||||
case ReturnType_Float:
|
case ReturnType_Float:
|
||||||
res->orgResult = new float;
|
*(float *)res->orgResult = *(float *)result;
|
||||||
*fpVal = *(float *)result;
|
|
||||||
res->orgResult = fpVal;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
res->orgResult = (void *)result;
|
res->orgResult = *(void **)result;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -222,7 +219,6 @@ void *Callback(DHooksCallback *dg, void **argStack)
|
|||||||
dg->plugin_callback->Execute(&result);
|
dg->plugin_callback->Execute(&result);
|
||||||
|
|
||||||
void *ret = g_SHPtr->GetOverrideRetPtr();
|
void *ret = g_SHPtr->GetOverrideRetPtr();
|
||||||
|
|
||||||
switch((MRESReturn)result)
|
switch((MRESReturn)result)
|
||||||
{
|
{
|
||||||
case MRES_Handled:
|
case MRES_Handled:
|
||||||
@ -239,7 +235,7 @@ void *Callback(DHooksCallback *dg, void **argStack)
|
|||||||
{
|
{
|
||||||
if(returnStruct->isChanged)
|
if(returnStruct->isChanged)
|
||||||
{
|
{
|
||||||
ret = returnStruct->newResult;
|
*(void **)ret = returnStruct->newResult;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -249,11 +245,11 @@ void *Callback(DHooksCallback *dg, void **argStack)
|
|||||||
{
|
{
|
||||||
if(returnStruct->isChanged)
|
if(returnStruct->isChanged)
|
||||||
{
|
{
|
||||||
ret = returnStruct->newResult;
|
*(void **)ret = returnStruct->newResult;
|
||||||
}
|
}
|
||||||
else if(dg->post)
|
else if(dg->post)
|
||||||
{
|
{
|
||||||
ret = returnStruct->orgResult;
|
*(void **)ret = returnStruct->orgResult;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -263,11 +259,11 @@ void *Callback(DHooksCallback *dg, void **argStack)
|
|||||||
{
|
{
|
||||||
if(returnStruct->isChanged)
|
if(returnStruct->isChanged)
|
||||||
{
|
{
|
||||||
ret = returnStruct->newResult;
|
*(void **)ret = returnStruct->newResult;
|
||||||
}
|
}
|
||||||
else if(dg->post)
|
else if(dg->post)
|
||||||
{
|
{
|
||||||
ret = returnStruct->orgResult;
|
*(void **)ret = returnStruct->orgResult;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -287,5 +283,9 @@ void *Callback(DHooksCallback *dg, void **argStack)
|
|||||||
handlesys->FreeHandle(pHndl, &sec);
|
handlesys->FreeHandle(pHndl, &sec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(dg->returnType != ReturnType_Void)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
19
vhook.h
19
vhook.h
@ -74,25 +74,8 @@ class HookReturnStruct
|
|||||||
public:
|
public:
|
||||||
~HookReturnStruct()
|
~HookReturnStruct()
|
||||||
{
|
{
|
||||||
if(this->isChanged && this->newResult)
|
|
||||||
{
|
|
||||||
if(this->type == ReturnType_CharPtr)
|
|
||||||
{
|
|
||||||
delete (char *)this->newResult;
|
|
||||||
}
|
|
||||||
else if(this->type == ReturnType_VectorPtr)
|
|
||||||
{
|
|
||||||
delete (Vector *)this->newResult;
|
|
||||||
}
|
|
||||||
else if(this->type == ReturnType_Float)
|
|
||||||
{
|
|
||||||
if(this->orgResult)
|
|
||||||
{
|
|
||||||
free(this->orgResult);
|
|
||||||
}
|
|
||||||
free(this->newResult);
|
free(this->newResult);
|
||||||
}
|
free(this->orgResult);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
ReturnType type;
|
ReturnType type;
|
||||||
|
Loading…
Reference in New Issue
Block a user