diff --git a/natives.cpp b/natives.cpp index 1a861c6..0573f94 100644 --- a/natives.cpp +++ b/natives.cpp @@ -201,7 +201,7 @@ cell_t Native_GetReturn(IPluginContext *pContext, const cell_t *params) case ReturnType_Float: return sp_ftoc(*(float *)returnStruct->orgResult); default: - return pContext->ThrowNativeError("Invalid param type (%i) to get",returnStruct->type); + return pContext->ThrowNativeError("Invalid param type (%i) to get", returnStruct->type); } return 1; } @@ -223,14 +223,13 @@ cell_t Native_SetReturn(IPluginContext *pContext, const cell_t *params) CBaseEntity *pEnt; edict_t *pEdict; - float *fpVal; switch(returnStruct->type) { case ReturnType_Int: - returnStruct->newResult = (int *)params[2]; + *(int *)returnStruct->newResult = params[2]; break; case ReturnType_Bool: - returnStruct->newResult = (bool *)(params[2]); + *(bool *)returnStruct->newResult = params[2] != 0; break; case ReturnType_CBaseEntity: 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"); } - returnStruct->newResult = pEnt; + *(CBaseEntity **)returnStruct->newResult = pEnt; break; case ReturnType_Edict: 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"); } - returnStruct->newResult = pEdict; + *(edict_t **)returnStruct->newResult = pEdict; break; case ReturnType_Float: - fpVal = new float; - *fpVal = sp_ctof(params[2]); - returnStruct->newResult = fpVal; + *(float *)returnStruct->newResult = sp_ctof(params[2]); break; default: return pContext->ThrowNativeError("Invalid param type (%i) to get",returnStruct->type); @@ -358,7 +355,7 @@ sp_nativeinfo_t g_Natives[] = //{"DHookGetReturnString", Native_GetReturnString}, //{"DHookSetReturnString", Native_SetReturnString}, {"DHookSetParamString", Native_SetParamString}, - /*{"DHookAddEntityListener", Native_AddEntityListener}, + /*{"DHookAddEntityListener", Native_AddEntityListener}, {"DHookRemoveEntityListener", Native_RemoveEntityListener}, {"DHookGetParamObjectPtrVar", Native_GetParamObjectPtrVar}, {"DHookSetParamObjectPtrVar", Native_SetParamObjectPtrVar}, diff --git a/vhook.cpp b/vhook.cpp index 0ece5ec..63ffd78 100644 --- a/vhook.cpp +++ b/vhook.cpp @@ -114,9 +114,8 @@ HookReturnStruct *GetReturnStruct(DHooksCallback *dg, const void *result) HookReturnStruct *res = new HookReturnStruct(); res->isChanged = false; res->type = dg->returnType; - res->newResult = NULL; - - float *fpVal = NULL; + res->newResult = malloc(sizeof(void *)); + res->orgResult = malloc(sizeof(void *)); if(result && dg->post) { @@ -125,17 +124,15 @@ HookReturnStruct *GetReturnStruct(DHooksCallback *dg, const void *result) //ReturnType_String, //ReturnType_Vector, case ReturnType_Int: - res->orgResult = (int *)result; + *(int *)res->orgResult = *(int *)result; case ReturnType_Bool: - res->orgResult = (bool *)result; + *(int *)res->orgResult = *(bool *)result; break; case ReturnType_Float: - res->orgResult = new float; - *fpVal = *(float *)result; - res->orgResult = fpVal; + *(float *)res->orgResult = *(float *)result; break; default: - res->orgResult = (void *)result; + res->orgResult = *(void **)result; break; } } @@ -222,7 +219,6 @@ void *Callback(DHooksCallback *dg, void **argStack) dg->plugin_callback->Execute(&result); void *ret = g_SHPtr->GetOverrideRetPtr(); - switch((MRESReturn)result) { case MRES_Handled: @@ -239,7 +235,7 @@ void *Callback(DHooksCallback *dg, void **argStack) { if(returnStruct->isChanged) { - ret = returnStruct->newResult; + *(void **)ret = returnStruct->newResult; } } break; @@ -249,11 +245,11 @@ void *Callback(DHooksCallback *dg, void **argStack) { if(returnStruct->isChanged) { - ret = returnStruct->newResult; + *(void **)ret = returnStruct->newResult; } else if(dg->post) { - ret = returnStruct->orgResult; + *(void **)ret = returnStruct->orgResult; } } break; @@ -263,11 +259,11 @@ void *Callback(DHooksCallback *dg, void **argStack) { if(returnStruct->isChanged) { - ret = returnStruct->newResult; + *(void **)ret = returnStruct->newResult; } else if(dg->post) { - ret = returnStruct->orgResult; + *(void **)ret = returnStruct->orgResult; } } break; @@ -287,5 +283,9 @@ void *Callback(DHooksCallback *dg, void **argStack) handlesys->FreeHandle(pHndl, &sec); } + if(dg->returnType != ReturnType_Void) + { + return NULL; + } return ret; } diff --git a/vhook.h b/vhook.h index bbef25b..ae581de 100644 --- a/vhook.h +++ b/vhook.h @@ -74,25 +74,8 @@ class HookReturnStruct public: ~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: ReturnType type;