Really fix return values now... Error out when overriding return but not given one.
This commit is contained in:
parent
d655e31e95
commit
07f7869d10
10
natives.cpp
10
natives.cpp
@ -221,8 +221,6 @@ cell_t Native_SetReturn(IPluginContext *pContext, const cell_t *params)
|
|||||||
return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[1], err);
|
return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[1], err);
|
||||||
}
|
}
|
||||||
|
|
||||||
CBaseEntity *pEnt;
|
|
||||||
edict_t *pEdict;
|
|
||||||
switch(returnStruct->type)
|
switch(returnStruct->type)
|
||||||
{
|
{
|
||||||
case ReturnType_Int:
|
case ReturnType_Int:
|
||||||
@ -232,21 +230,25 @@ cell_t Native_SetReturn(IPluginContext *pContext, const cell_t *params)
|
|||||||
*(bool *)returnStruct->newResult = params[2] != 0;
|
*(bool *)returnStruct->newResult = params[2] != 0;
|
||||||
break;
|
break;
|
||||||
case ReturnType_CBaseEntity:
|
case ReturnType_CBaseEntity:
|
||||||
pEnt = UTIL_GetCBaseEntity(params[2]);
|
{
|
||||||
|
CBaseEntity *pEnt = UTIL_GetCBaseEntity(params[2]);
|
||||||
if(!pEnt)
|
if(!pEnt)
|
||||||
{
|
{
|
||||||
return pContext->ThrowNativeError("Invalid entity index passed for return value");
|
return pContext->ThrowNativeError("Invalid entity index passed for return value");
|
||||||
}
|
}
|
||||||
*(CBaseEntity **)returnStruct->newResult = pEnt;
|
*(CBaseEntity **)returnStruct->newResult = pEnt;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case ReturnType_Edict:
|
case ReturnType_Edict:
|
||||||
pEdict = gamehelpers->EdictOfIndex(params[2]);
|
{
|
||||||
|
edict_t *pEdict = gamehelpers->EdictOfIndex(params[2]);
|
||||||
if(!pEdict || pEdict->IsFree())
|
if(!pEdict || pEdict->IsFree())
|
||||||
{
|
{
|
||||||
pContext->ThrowNativeError("Invalid entity index passed for return value");
|
pContext->ThrowNativeError("Invalid entity index passed for return value");
|
||||||
}
|
}
|
||||||
*(edict_t **)returnStruct->newResult = pEdict;
|
*(edict_t **)returnStruct->newResult = pEdict;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case ReturnType_Float:
|
case ReturnType_Float:
|
||||||
*(float *)returnStruct->newResult = sp_ctof(params[2]);
|
*(float *)returnStruct->newResult = sp_ctof(params[2]);
|
||||||
break;
|
break;
|
||||||
|
51
vhook.cpp
51
vhook.cpp
@ -126,13 +126,13 @@ HookReturnStruct *GetReturnStruct(DHooksCallback *dg, const void *result)
|
|||||||
case ReturnType_Int:
|
case ReturnType_Int:
|
||||||
*(int *)res->orgResult = *(int *)result;
|
*(int *)res->orgResult = *(int *)result;
|
||||||
case ReturnType_Bool:
|
case ReturnType_Bool:
|
||||||
*(int *)res->orgResult = *(bool *)result;
|
*(bool *)res->orgResult = *(bool *)result;
|
||||||
break;
|
break;
|
||||||
case ReturnType_Float:
|
case ReturnType_Float:
|
||||||
*(float *)res->orgResult = *(float *)result;
|
*(float *)res->orgResult = *(float *)result;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
res->orgResult = *(void **)result;
|
*(void **)res->orgResult = (void *)result;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -180,6 +180,7 @@ void *Callback(DHooksCallback *dg, void **argStack)
|
|||||||
rHndl = handlesys->CreateHandle(g_HookReturnHandle, returnStruct, dg->plugin_callback->GetParentRuntime()->GetDefaultContext()->GetIdentity(), myself->GetIdentity(), NULL);
|
rHndl = handlesys->CreateHandle(g_HookReturnHandle, returnStruct, dg->plugin_callback->GetParentRuntime()->GetDefaultContext()->GetIdentity(), myself->GetIdentity(), NULL);
|
||||||
if(!rHndl)
|
if(!rHndl)
|
||||||
{
|
{
|
||||||
|
dg->plugin_callback->Cancel();
|
||||||
if(returnStruct)
|
if(returnStruct)
|
||||||
{
|
{
|
||||||
delete returnStruct;
|
delete returnStruct;
|
||||||
@ -202,6 +203,7 @@ void *Callback(DHooksCallback *dg, void **argStack)
|
|||||||
pHndl = handlesys->CreateHandle(g_HookParamsHandle, paramStruct, dg->plugin_callback->GetParentRuntime()->GetDefaultContext()->GetIdentity(), myself->GetIdentity(), NULL);
|
pHndl = handlesys->CreateHandle(g_HookParamsHandle, paramStruct, dg->plugin_callback->GetParentRuntime()->GetDefaultContext()->GetIdentity(), myself->GetIdentity(), NULL);
|
||||||
if(!pHndl)
|
if(!pHndl)
|
||||||
{
|
{
|
||||||
|
dg->plugin_callback->Cancel();
|
||||||
if(returnStruct)
|
if(returnStruct)
|
||||||
{
|
{
|
||||||
delete returnStruct;
|
delete returnStruct;
|
||||||
@ -228,42 +230,53 @@ void *Callback(DHooksCallback *dg, void **argStack)
|
|||||||
ret = CallVFunction(dg, paramStruct, g_SHPtr->GetIfacePtr());
|
ret = CallVFunction(dg, paramStruct, g_SHPtr->GetIfacePtr());
|
||||||
break;
|
break;
|
||||||
case MRES_ChangedOverride:
|
case MRES_ChangedOverride:
|
||||||
|
if(dg->returnType != ReturnType_Void)
|
||||||
|
{
|
||||||
|
if(returnStruct->isChanged)
|
||||||
|
{
|
||||||
|
ret = *(void **)returnStruct->newResult;
|
||||||
|
}
|
||||||
|
else //Throw an error if no override was set
|
||||||
|
{
|
||||||
|
g_SHPtr->SetRes(MRES_IGNORED);
|
||||||
|
IPlugin *plugin = plsys->FindPluginByContext(dg->plugin_callback->GetParentContext()->GetContext());
|
||||||
|
smutils->LogError(myself, "Plugin %s tried to override a return without a return being set", plugin->GetFilename());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
g_SHPtr->DoRecall();
|
g_SHPtr->DoRecall();
|
||||||
g_SHPtr->SetRes(MRES_SUPERCEDE);
|
g_SHPtr->SetRes(MRES_SUPERCEDE);
|
||||||
ret = CallVFunction(dg, paramStruct, g_SHPtr->GetIfacePtr());
|
CallVFunction(dg, paramStruct, g_SHPtr->GetIfacePtr());
|
||||||
if(dg->returnType != ReturnType_Void)
|
|
||||||
{
|
|
||||||
if(returnStruct->isChanged)
|
|
||||||
{
|
|
||||||
*(void **)ret = returnStruct->newResult;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case MRES_Override:
|
case MRES_Override:
|
||||||
g_SHPtr->SetRes(MRES_OVERRIDE);
|
|
||||||
if(dg->returnType != ReturnType_Void)
|
if(dg->returnType != ReturnType_Void)
|
||||||
{
|
{
|
||||||
if(returnStruct->isChanged)
|
if(returnStruct->isChanged)
|
||||||
{
|
{
|
||||||
*(void **)ret = returnStruct->newResult;
|
g_SHPtr->SetRes(MRES_OVERRIDE);
|
||||||
|
ret = *(void **)returnStruct->newResult;
|
||||||
}
|
}
|
||||||
else if(dg->post)
|
else //Throw an error if no override was set
|
||||||
{
|
{
|
||||||
*(void **)ret = returnStruct->orgResult;
|
g_SHPtr->SetRes(MRES_IGNORED);
|
||||||
|
IPlugin *plugin = plsys->FindPluginByContext(dg->plugin_callback->GetParentContext()->GetContext());
|
||||||
|
smutils->LogError(myself, "Plugin %s tried to override a return without a return being set", plugin->GetFilename());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MRES_Supercede:
|
case MRES_Supercede:
|
||||||
g_SHPtr->SetRes(MRES_SUPERCEDE);
|
|
||||||
if(dg->returnType != ReturnType_Void)
|
if(dg->returnType != ReturnType_Void)
|
||||||
{
|
{
|
||||||
if(returnStruct->isChanged)
|
if(returnStruct->isChanged)
|
||||||
{
|
{
|
||||||
*(void **)ret = returnStruct->newResult;
|
g_SHPtr->SetRes(MRES_SUPERCEDE);
|
||||||
|
ret = *(void **)returnStruct->newResult;
|
||||||
}
|
}
|
||||||
else if(dg->post)
|
else //Throw an error if no override was set
|
||||||
{
|
{
|
||||||
*(void **)ret = returnStruct->orgResult;
|
g_SHPtr->SetRes(MRES_IGNORED);
|
||||||
|
IPlugin *plugin = plsys->FindPluginByContext(dg->plugin_callback->GetParentContext()->GetContext());
|
||||||
|
smutils->LogError(myself, "Plugin %s tried to override a return without a return being set", plugin->GetFilename());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -283,7 +296,7 @@ void *Callback(DHooksCallback *dg, void **argStack)
|
|||||||
handlesys->FreeHandle(pHndl, &sec);
|
handlesys->FreeHandle(pHndl, &sec);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(dg->returnType != ReturnType_Void)
|
if(dg->returnType == ReturnType_Void || g_SHPtr->GetStatus() <= MRES_HANDLED)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user