Remove functions now in util and fix more object related issues.
This commit is contained in:
parent
c3bc30ece3
commit
1fe19fc823
33
natives.cpp
33
natives.cpp
@ -1,4 +1,5 @@
|
||||
#include "natives.h"
|
||||
#include "util.h"
|
||||
|
||||
bool GetHandleIfValidOrError(HandleType_t type, void **object, IPluginContext *pContext, cell_t param)
|
||||
{
|
||||
@ -17,36 +18,6 @@ bool GetHandleIfValidOrError(HandleType_t type, void **object, IPluginContext *p
|
||||
return true;
|
||||
}
|
||||
|
||||
void * GetObjectAddr(HookParamType type, unsigned int flags, void **params, size_t offset)
|
||||
{
|
||||
#ifdef WIN32
|
||||
if(type == HookParamType_Object)
|
||||
return (void *)((intptr_t)params + offset);
|
||||
#elif POSIX
|
||||
if(type == HookParamType_Object && !(flags & PASSFLAG_ODTOR)) //Objects are passed by rrefrence if they contain destructors.
|
||||
return (void *)((intptr_t)params + offset);
|
||||
#endif
|
||||
return *(void **)((intptr_t)params + offset);
|
||||
|
||||
}
|
||||
|
||||
size_t GetParamOffset(HookParamsStruct *paramStruct, unsigned int index)
|
||||
{
|
||||
size_t offset = 0;
|
||||
for (unsigned int i = 0; i < index; i++)
|
||||
{
|
||||
#ifndef WIN32
|
||||
if (paramStruct->dg->params.at(i).type == HookParamType_Object && (paramStruct->dg->params.at(i).flags & PASSFLAG_ODTOR)) //Passed by refrence
|
||||
{
|
||||
offset += sizeof(void *);
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
offset += paramStruct->dg->params.at(i).size;
|
||||
}
|
||||
return offset;
|
||||
}
|
||||
|
||||
//native Handle:DHookCreate(offset, HookType:hooktype, ReturnType:returntype, ThisPointerType:thistype, DHookCallback:callback);
|
||||
cell_t Native_CreateHook(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
@ -639,7 +610,7 @@ cell_t Native_SetParamString(IPluginContext *pContext, const cell_t *params)
|
||||
if(paramStruct->isChanged[index])
|
||||
delete *(char **)addr;
|
||||
|
||||
paramStruct->newParams[index] = new char[strlen(value)+1];
|
||||
*(char **)addr = new char[strlen(value)+1];
|
||||
strcpy(*(char **)addr, value);
|
||||
paramStruct->isChanged[index] = true;
|
||||
}
|
||||
|
@ -11,8 +11,4 @@ extern HandleType_t g_HookSetupHandle;
|
||||
extern HandleType_t g_HookParamsHandle;
|
||||
extern HandleType_t g_HookReturnHandle;
|
||||
extern ke::Vector<DHooksManager *> g_pHooks;
|
||||
|
||||
size_t GetParamOffset(HookParamsStruct *params, unsigned int index);
|
||||
void * GetObjectAddr(HookParamType type, unsigned int flags, void **params, size_t offset);
|
||||
|
||||
#endif
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
#include "vhook.h"
|
||||
#include "extension.h"
|
||||
#include "natives.h"
|
||||
#include "util.h"
|
||||
|
||||
#define PARAMINFO_SWITCH(passType) \
|
||||
paramInfo[i].flags = dg->params.at(i).flags; \
|
||||
|
62
vhook.cpp
62
vhook.cpp
@ -1,5 +1,6 @@
|
||||
#include "vhook.h"
|
||||
#include "vfunc_call.h"
|
||||
#include "util.h"
|
||||
|
||||
SourceHook::IHookManagerAutoGen *g_pHookManager = NULL;
|
||||
|
||||
@ -12,6 +13,7 @@ using namespace SourceHook;
|
||||
#else
|
||||
#define OBJECT_OFFSET (sizeof(void *)*2)
|
||||
#endif
|
||||
|
||||
DHooksManager::DHooksManager(HookSetup *setup, void *iface, IPluginFunction *remove_callback, bool post)
|
||||
{
|
||||
this->callback = MakeHandler(setup->returnType);
|
||||
@ -93,10 +95,6 @@ bool SetupHookManager(ISmmAPI *ismm)
|
||||
return g_pHookManager != NULL;
|
||||
}
|
||||
|
||||
size_t GetParamTypeSize(HookParamType type)
|
||||
{
|
||||
return sizeof(void *);
|
||||
}
|
||||
SourceHook::PassInfo::PassType GetParamTypePassType(HookParamType type)
|
||||
{
|
||||
switch(type)
|
||||
@ -108,14 +106,10 @@ SourceHook::PassInfo::PassType GetParamTypePassType(HookParamType type)
|
||||
}
|
||||
return SourceHook::PassInfo::PassType_Basic;
|
||||
}
|
||||
|
||||
size_t GetStackArgsSize(DHooksCallback *dg)
|
||||
{
|
||||
size_t res = 0;
|
||||
for(int i = dg->params.size() - 1; i >= 0; i--)
|
||||
{
|
||||
res += dg->params.at(i).size;
|
||||
}
|
||||
|
||||
size_t res = GetParamsSize(dg);
|
||||
#ifdef WIN32
|
||||
if(dg->returnType == ReturnType_Vector)//Account for result vector ptr.
|
||||
#else
|
||||
@ -126,6 +120,40 @@ size_t GetStackArgsSize(DHooksCallback *dg)
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
HookParamsStruct::~HookParamsStruct()
|
||||
{
|
||||
if (this->orgParams != NULL)
|
||||
{
|
||||
free(this->orgParams);
|
||||
}
|
||||
if (this->isChanged != NULL)
|
||||
{
|
||||
free(this->isChanged);
|
||||
}
|
||||
if (this->newParams != NULL)
|
||||
{
|
||||
for (int i = dg->params.size() - 1; i >= 0; i--)
|
||||
{
|
||||
size_t offset = GetParamOffset(this, i);
|
||||
void *addr = (void **)((intptr_t)this->newParams + offset);
|
||||
|
||||
if (*(void **)addr == NULL)
|
||||
continue;
|
||||
|
||||
if (dg->params.at(i).type == HookParamType_VectorPtr)
|
||||
{
|
||||
delete *(SDKVector **)addr;
|
||||
}
|
||||
else if (dg->params.at(i).type == HookParamType_CharPtr)
|
||||
{
|
||||
delete *(char **)addr;
|
||||
}
|
||||
}
|
||||
free(this->newParams);
|
||||
}
|
||||
}
|
||||
|
||||
HookParamsStruct *GetParamStruct(DHooksCallback *dg, void **argStack, size_t argStackSize)
|
||||
{
|
||||
HookParamsStruct *params = new HookParamsStruct();
|
||||
@ -144,15 +172,23 @@ HookParamsStruct *GetParamStruct(DHooksCallback *dg, void **argStack, size_t arg
|
||||
params->orgParams = (void **)malloc(argStackSize-OBJECT_OFFSET);
|
||||
memcpy(params->orgParams, argStack+OBJECT_OFFSET, argStackSize-OBJECT_OFFSET);
|
||||
}
|
||||
params->newParams = (void **)malloc(dg->params.size() * sizeof(void *));
|
||||
size_t paramsSize = GetParamsSize(dg);
|
||||
|
||||
params->newParams = (void **)malloc(paramsSize);
|
||||
params->isChanged = (bool *)malloc(dg->params.size() * sizeof(bool));
|
||||
for(int i = 0; i < (int)dg->params.size(); i++)
|
||||
|
||||
for (unsigned int i = 0; i < dg->params.size(); i++)
|
||||
{
|
||||
params->newParams[i] = NULL;
|
||||
params->isChanged[i] = false;
|
||||
}
|
||||
|
||||
for(unsigned int i = 0; i < paramsSize; i++)
|
||||
{
|
||||
*(void **)((intptr_t)params->newParams + i) = NULL;
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
HookReturnStruct *GetReturnStruct(DHooksCallback *dg)
|
||||
{
|
||||
HookReturnStruct *res = new HookReturnStruct();
|
||||
|
34
vhook.h
34
vhook.h
@ -275,39 +275,7 @@ public:
|
||||
this->dg = NULL;
|
||||
this->isChanged = NULL;
|
||||
}
|
||||
~HookParamsStruct()
|
||||
{
|
||||
if(this->orgParams != NULL)
|
||||
{
|
||||
free(this->orgParams);
|
||||
}
|
||||
if(this->isChanged != NULL)
|
||||
{
|
||||
free(this->isChanged);
|
||||
}
|
||||
if(this->newParams != NULL)
|
||||
{
|
||||
for(int i = dg->params.size() - 1; i >= 0 ; i--)
|
||||
{
|
||||
if(this->newParams[i] == NULL)
|
||||
continue;
|
||||
|
||||
if(dg->params.at(i).type == HookParamType_VectorPtr)
|
||||
{
|
||||
delete (SDKVector *)this->newParams[i];
|
||||
}
|
||||
else if(dg->params.at(i).type == HookParamType_CharPtr)
|
||||
{
|
||||
delete (char *)this->newParams[i];
|
||||
}
|
||||
else if(dg->params.at(i).type == HookParamType_Float)
|
||||
{
|
||||
delete (float *)this->newParams[i];
|
||||
}
|
||||
}
|
||||
free(this->newParams);
|
||||
}
|
||||
}
|
||||
~HookParamsStruct();
|
||||
public:
|
||||
void **orgParams;
|
||||
void **newParams;
|
||||
|
Loading…
Reference in New Issue
Block a user