Merge upstream master

This commit is contained in:
Peace-Maker
2018-04-19 02:09:01 +02:00
10 changed files with 75 additions and 41 deletions
+43 -10
View File
@@ -28,14 +28,26 @@ bool GetHandleIfValidOrError(HandleType_t type, void **object, IPluginContext *p
return true;
}
//native Handle:DHookCreate(offset, HookType:hooktype, ReturnType:returntype, ThisPointerType:thistype, DHookCallback:callback);
cell_t Native_CreateHook(IPluginContext *pContext, const cell_t *params)
IPluginFunction *GetCallback(IPluginContext *pContext, HookSetup * setup, const cell_t *params, unsigned int callback_index)
{
if(!pContext->GetFunctionById(params[5]))
IPluginFunction *ret = NULL;
if (params[0] >= callback_index)
{
return pContext->ThrowNativeError("Failed to retrieve function by id");
ret = pContext->GetFunctionById(params[callback_index]);
}
if (!ret && setup->callback)
{
ret = setup->callback;
}
return ret;
}
//native Handle:DHookCreate(offset, HookType:hooktype, ReturnType:returntype, ThisPointerType:thistype, DHookCallback:callback = INVALID_FUNCTION); // Callback is now optional here.
cell_t Native_CreateHook(IPluginContext *pContext, const cell_t *params)
{
HookSetup *setup = new HookSetup((ReturnType)params[3], PASSFLAG_BYVAL, (HookType)params[2], (ThisPointerType)params[4], params[1], pContext->GetFunctionById(params[5]));
Handle_t hndl = handlesys->CreateHandle(g_HookSetupHandle, setup, pContext->GetIdentity(), myself->GetIdentity(), NULL);
@@ -341,7 +353,7 @@ cell_t Native_DisableDetour(IPluginContext *pContext, const cell_t *params)
return RemoveDetourPluginHook(hookType, pDetour, callback);
}
// native DHookEntity(Handle:setup, bool:post, entity, DHookRemovalCB:removalcb);
// native DHookEntity(Handle:setup, bool:post, entity, DHookRemovalCB:removalcb, DHookCallback:callback = INVALID_FUNCTION); // Both callbacks are optional
cell_t Native_HookEntity(IPluginContext *pContext, const cell_t *params)
{
HookSetup *setup;
@@ -377,7 +389,14 @@ cell_t Native_HookEntity(IPluginContext *pContext, const cell_t *params)
return pContext->ThrowNativeError("Invalid entity passed %i", params[2]);
}
DHooksManager *manager = new DHooksManager(setup, pEnt, pContext->GetFunctionById(params[4]), post);
IPluginFunction *cb = GetCallback(pContext, setup, params, 5);
if (!cb)
{
pContext->ThrowNativeError("Failed to hook entity %i, no callback provided", params[2]);
}
DHooksManager *manager = new DHooksManager(setup, pEnt, pContext->GetFunctionById(params[4]), cb, post);
if(!manager->hookid)
{
@@ -389,7 +408,7 @@ cell_t Native_HookEntity(IPluginContext *pContext, const cell_t *params)
return manager->hookid;
}
// native DHookGamerules(Handle:setup, bool:post, DHookRemovalCB:removalcb);
// native DHookGamerules(Handle:setup, bool:post, DHookRemovalCB:removalcb, DHookCallback:callback = INVALID_FUNCTION); // Both callbacks are optional
cell_t Native_HookGamerules(IPluginContext *pContext, const cell_t *params)
{
HookSetup *setup;
@@ -427,7 +446,14 @@ cell_t Native_HookGamerules(IPluginContext *pContext, const cell_t *params)
return pContext->ThrowNativeError("Could not get gamerules pointer");
}
DHooksManager *manager = new DHooksManager(setup, rules, pContext->GetFunctionById(params[3]), post);
IPluginFunction *cb = GetCallback(pContext, setup, params, 4);
if (!cb)
{
pContext->ThrowNativeError("Failed to hook gamerules, no callback provided");
}
DHooksManager *manager = new DHooksManager(setup, rules, pContext->GetFunctionById(params[3]), cb, post);
if(!manager->hookid)
{
@@ -439,7 +465,7 @@ cell_t Native_HookGamerules(IPluginContext *pContext, const cell_t *params)
return manager->hookid;
}
// DHookRaw(Handle:setup, bool:post, Address:addr, DHookRemovalCB:removalcb);
// DHookRaw(Handle:setup, bool:post, Address:addr, DHookRemovalCB:removalcb, DHookCallback:callback = INVALID_FUNCTION); // Both callbacks are optional
cell_t Native_HookRaw(IPluginContext *pContext, const cell_t *params)
{
HookSetup *setup;
@@ -476,7 +502,14 @@ cell_t Native_HookRaw(IPluginContext *pContext, const cell_t *params)
return pContext->ThrowNativeError("Invalid address passed");
}
DHooksManager *manager = new DHooksManager(setup, iface, pContext->GetFunctionById(params[4]), post);
IPluginFunction *cb = GetCallback(pContext, setup, params, 5);
if (!cb)
{
pContext->ThrowNativeError("Failed to hook address, no callback provided");
}
DHooksManager *manager = new DHooksManager(setup, iface, pContext->GetFunctionById(params[4]), cb, post);
if(!manager->hookid)
{