Merge upstream master
This commit is contained in:
commit
43f275889e
@ -1 +1 @@
|
||||
2.1.0
|
||||
2.2.0
|
@ -75,7 +75,7 @@ void DHooksEntityListener::OnEntityDestroyed(CBaseEntity *pEntity)
|
||||
for(int i = g_pHooks.length() -1; i >= 0; i--)
|
||||
{
|
||||
DHooksManager *manager = g_pHooks.at(i);
|
||||
if(manager->callback->entity == entity)
|
||||
if(manager->callback->hookType == HookType_Entity && manager->callback->entity == entity)
|
||||
{
|
||||
if(g_pRemoveList.length() == 0)
|
||||
{
|
||||
|
53
natives.cpp
53
natives.cpp
@ -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)
|
||||
{
|
||||
|
@ -1 +1 @@
|
||||
2.1.0-dev
|
||||
2.2.0-dev
|
||||
|
@ -40,7 +40,7 @@
|
||||
/* Basic information exposed publicly */
|
||||
#define SMEXT_CONF_NAME "DHooks"
|
||||
#define SMEXT_CONF_DESCRIPTION "Dynamic Hooks"
|
||||
#define SMEXT_CONF_VERSION "2.1.0"
|
||||
#define SMEXT_CONF_VERSION "2.2.0"
|
||||
#define SMEXT_CONF_AUTHOR "Dr!fter"
|
||||
#define SMEXT_CONF_URL "http://www.sourcemod.net/"
|
||||
#define SMEXT_CONF_LOGTAG "DHOOKS"
|
||||
|
@ -29,18 +29,18 @@
|
||||
}
|
||||
"GetMaxs"
|
||||
{
|
||||
"windows" "338"
|
||||
"linux" "339"
|
||||
"windows" "339"
|
||||
"linux" "340"
|
||||
}
|
||||
"CanUse"
|
||||
{
|
||||
"windows" "259"
|
||||
"linux" "260"
|
||||
"windows" "260"
|
||||
"linux" "261"
|
||||
}
|
||||
"CanHaveAmmo"
|
||||
{
|
||||
"windows" "97"
|
||||
"linux" "97"
|
||||
"windows" "98"
|
||||
"linux" "98"
|
||||
}
|
||||
"SetModel"
|
||||
{
|
||||
@ -49,13 +49,13 @@
|
||||
}
|
||||
"GetMaxPlayerSpeed"
|
||||
{
|
||||
"windows" "437"
|
||||
"linux" "438"
|
||||
"windows" "438"
|
||||
"linux" "439"
|
||||
}
|
||||
"GiveAmmo"
|
||||
{
|
||||
"windows" "251"
|
||||
"linux" "252"
|
||||
"windows" "252"
|
||||
"linux" "253"
|
||||
}
|
||||
"OnTakeDamage"
|
||||
{
|
||||
|
@ -54,7 +54,7 @@ public OnPluginStart()
|
||||
hGetModelName = DHookCreate(offset, HookType_Entity, ReturnType_String, ThisPointer_CBaseEntity, GetModelName);
|
||||
|
||||
offset = GameConfGetOffset(temp, "GetMaxs");
|
||||
hGetMaxs = DHookCreate(offset, HookType_Entity, ReturnType_Vector, ThisPointer_Ignore, GetMaxsPost);
|
||||
hGetMaxs = DHookCreate(offset, HookType_Entity, ReturnType_Vector, ThisPointer_Ignore);
|
||||
|
||||
offset = GameConfGetOffset(temp, "CanUse");
|
||||
hHookCanUse = DHookCreate(offset, HookType_Entity, ReturnType_Bool, ThisPointer_CBaseEntity, CanUsePost);
|
||||
@ -78,7 +78,7 @@ public OnPluginStart()
|
||||
DHookAddParam(hAcceptInput, HookParamType_Int);
|
||||
|
||||
offset = GameConfGetOffset(temp, "GetMaxPlayerSpeed");
|
||||
hGetSpeed = DHookCreate(offset, HookType_Entity, ReturnType_Float, ThisPointer_CBaseEntity, GetMaxPlayerSpeedPost);
|
||||
hGetSpeed = DHookCreate(offset, HookType_Entity, ReturnType_Float, ThisPointer_CBaseEntity);
|
||||
|
||||
offset = GameConfGetOffset(temp, "GiveAmmo");
|
||||
hGiveAmmo = DHookCreate(offset, HookType_Entity, ReturnType_Int, ThisPointer_CBaseEntity, GiveAmmo);
|
||||
@ -161,11 +161,11 @@ public OnClientPutInServer(client)
|
||||
{
|
||||
DHookEntity(hSetModel, false, client, RemovalCB);
|
||||
DHookEntity(hHookCanUse, true, client, RemovalCB);
|
||||
DHookEntity(hGetSpeed, true, client, RemovalCB);
|
||||
DHookEntity(hGetSpeed, true, client, RemovalCB, GetMaxPlayerSpeedPost);
|
||||
DHookEntity(hGiveAmmo, false, client);
|
||||
DHookEntity(hGetModelName, true, client);
|
||||
DHookEntity(hTakeDamage, false, client);
|
||||
DHookEntity(hGetMaxs, true, client, RemovalCB);
|
||||
DHookEntity(hGetMaxs, true, client, _ , GetMaxsPost);
|
||||
DHookEntity(hBloodColor, true, client);
|
||||
}
|
||||
|
||||
|
@ -216,12 +216,12 @@ native bool DHookRemoveEntityListener(ListenType type, ListenCB callback);
|
||||
* @param hooktype Type of hook
|
||||
* @param returntype Type type of return
|
||||
* @param thistype Type of this pointer or ignore (ignore can be used if not needed)
|
||||
* @param callback Callback function
|
||||
* @param callback Optional callback function, if not set here must be set when hooking.
|
||||
*
|
||||
* @return Returns setup handle for the hook.
|
||||
* @error Failed to create hook setup handle or invalid callback function.
|
||||
*/
|
||||
native Handle DHookCreate(int offset, HookType hooktype, ReturnType returntype, ThisPointerType thistype, DHookCallback callback);
|
||||
native Handle DHookCreate(int offset, HookType hooktype, ReturnType returntype, ThisPointerType thistype, DHookCallback callback=INVALID_FUNCTION);
|
||||
|
||||
/**
|
||||
* Creates a detour
|
||||
@ -298,8 +298,6 @@ native bool DHookDisableDetour(Handle setup, bool post, DHookCallback callback);
|
||||
* @noreturn
|
||||
*/
|
||||
native void DHookAddParam(Handle setup, HookParamType type, int size=-1, DHookPassFlag flag=DHookPass_ByVal, DHookRegister custom_register=DHookRegister_Default);
|
||||
//native void DHookAddParam(Handle setup, HookParamType type, int size=-1, DHookPassFlag flag=DHookPass_ByVal);
|
||||
//native DHookAddParam(Handle:setup, HookParamType:type);
|
||||
|
||||
/* Hook entity
|
||||
*
|
||||
@ -307,22 +305,24 @@ native void DHookAddParam(Handle setup, HookParamType type, int size=-1, DHookPa
|
||||
* @param post True to make the hook a post hook. (If you need to change the return value or need the return value use a post hook! If you need to change params and return use a pre and post hook!)
|
||||
* @param entity Entity index to hook on.
|
||||
* @param removalcb Callback for when the hook is removed (Entity hooks are auto-removed on entity destroyed and will call this callback)
|
||||
* @param callback Optional callback function, if not set here must be set when creating the hook.
|
||||
*
|
||||
* @error Invalid setup handle, invalid entity or invalid hook type.
|
||||
* @error Invalid setup handle, invalid entity, invalid hook type or invalid callback.
|
||||
* @return -1 on fail a hookid on success
|
||||
*/
|
||||
native int DHookEntity(Handle setup, bool post, int entity, DHookRemovalCB removalcb=INVALID_FUNCTION);
|
||||
native int DHookEntity(Handle setup, bool post, int entity, DHookRemovalCB removalcb=INVALID_FUNCTION, DHookCallback callback=INVALID_FUNCTION);
|
||||
|
||||
/* Hook gamerules
|
||||
*
|
||||
* @param setup Setup handle to use to add the hook.
|
||||
* @param post True to make the hook a post hook. (If you need to change the return value or need the return value use a post hook! If you need to change params and return use a pre and post hook!)
|
||||
* @param removalcb Callback for when the hook is removed (Game rules hooks are auto-removed on map end and will call this callback)
|
||||
* @param callback Optional callback function, if not set here must be set when creating the hook.
|
||||
*
|
||||
* @error Invalid setup handle, failing to get gamerules pointer or invalid hook type.
|
||||
* @error Invalid setup handle, failing to get gamerules pointer, invalid hook type or invalid callback.
|
||||
* @return -1 on fail a hookid on success
|
||||
*/
|
||||
native int DHookGamerules(Handle setup, bool post, DHookRemovalCB removalcb=INVALID_FUNCTION);
|
||||
native int DHookGamerules(Handle setup, bool post, DHookRemovalCB removalcb=INVALID_FUNCTION, DHookCallback callback=INVALID_FUNCTION);
|
||||
|
||||
/* Hook a raw pointer
|
||||
*
|
||||
@ -330,11 +330,12 @@ native int DHookGamerules(Handle setup, bool post, DHookRemovalCB removalcb=INVA
|
||||
* @param post True to make the hook a post hook. (If you need to change the return value or need the return value use a post hook! If you need to change params and return use a pre and post hook!)
|
||||
* @param addr This pointer address.
|
||||
* @param removalcb Callback for when the hook is removed (Entity hooks are auto-removed on entity destroyed and will call this callback)
|
||||
* @param callback Optional callback function, if not set here must be set when creating the hook.
|
||||
*
|
||||
* @error Invalid setup handle, invalid address or invalid hook type.
|
||||
* @error Invalid setup handle, invalid address, invalid hook type or invalid callback.
|
||||
* @return -1 on fail a hookid on success
|
||||
*/
|
||||
native int DHookRaw(Handle setup, bool post, Address addr, DHookRemovalCB removalcb=INVALID_FUNCTION);
|
||||
native int DHookRaw(Handle setup, bool post, Address addr, DHookRemovalCB removalcb=INVALID_FUNCTION, DHookCallback callback=INVALID_FUNCTION);
|
||||
|
||||
/* Remove hook by hook id
|
||||
*
|
||||
|
@ -104,13 +104,13 @@ void *GenerateThunk(ReturnType type)
|
||||
}
|
||||
#endif
|
||||
|
||||
DHooksManager::DHooksManager(HookSetup *setup, void *iface, IPluginFunction *remove_callback, bool post)
|
||||
DHooksManager::DHooksManager(HookSetup *setup, void *iface, IPluginFunction *remove_callback, IPluginFunction *plugincb, bool post)
|
||||
{
|
||||
this->callback = MakeHandler(setup->returnType);
|
||||
this->hookid = 0;
|
||||
this->remove_callback = remove_callback;
|
||||
this->callback->offset = setup->offset;
|
||||
this->callback->plugin_callback = setup->callback;
|
||||
this->callback->plugin_callback = plugincb;
|
||||
this->callback->returnFlag = setup->returnFlag;
|
||||
this->callback->thisType = setup->thisType;
|
||||
this->callback->post = post;
|
||||
|
2
vhook.h
2
vhook.h
@ -238,7 +238,7 @@ public:
|
||||
class DHooksManager
|
||||
{
|
||||
public:
|
||||
DHooksManager(HookSetup *setup, void *iface, IPluginFunction *remove_callback, bool post);
|
||||
DHooksManager(HookSetup *setup, void *iface, IPluginFunction *remove_callback, IPluginFunction *plugincb, bool post);
|
||||
~DHooksManager()
|
||||
{
|
||||
if(this->hookid)
|
||||
|
Loading…
Reference in New Issue
Block a user