Raised This Month: $51 Target: $400
 12% 

DHooks (Dynamic Hooks - Dev Preview)


Post New Thread Reply   
 
Thread Tools Display Modes
Alienmario
Senior Member
Join Date: Aug 2013
Old 08-02-2015 , 09:19   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #351

Hi there. First of all, this extension has been great help. The plugin I'm making couldn't be done without it.

After weeks of trying to hook bullet spread of weapons in HL2DM I have found a solution and a little bug with this extension.

The problem lies in this function: DHookSetParamObjectPtrVarVector(hParams, 1, 28, ObjectValueType_Vector, vec) reporting:
Quote:
L 08/02/2015 - 15:030: [SM] Native "DHookSetParamObjectPtrVarVector" reported: Invalid Object value type (not a type of vector)
L 08/02/2015 - 15:030: [SM] Displaying call stack trace for plugin "customguns.smx":
while everything else seems to be correct. Reading the vector at same offset also works as expected.
I have solved this by passing 3 floats instead of the vector (I wish I realized that earlier lol) like so:
PHP Code:
    DHookSetParamObjectPtrVar(hParams128ObjectValueType_Floatvec[0]);
    
DHookSetParamObjectPtrVar(hParams132ObjectValueType_Floatvec[1]);
    
DHookSetParamObjectPtrVar(hParams136ObjectValueType_Floatvec[2]); 
Here is the full code of FireBullets hook for anyone interested:
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <dhooks>


Handle DHOOK_FireBullets;

public 
OnPluginStart()
{
    new 
Handle:gamedata LoadGameConfigFile("urgamedata");
    
    if(
gamedata == INVALID_HANDLE)
    {
        
SetFailState("Failed to find gamedata");
    }
    
    
int offset;
    
    
// void CHL2MP_Player::FireBullets ( const FireBulletsInfo_t &info )
     
offset GameConfGetOffset(gamedata"FireBullets");
    
DHOOK_FireBullets DHookCreate(offsetHookType_EntityReturnType_VoidThisPointer_CBaseEntityFireBullets);
    
DHookAddParam(DHOOK_FireBulletsHookParamType_ObjectPtr, -1DHookPass_ByVal);
    
    
CloseHandle(gamedata);
}

public 
OnClientPutInServer(client){
    
DHookEntity(DHOOK_FireBulletsfalseclient);
}


// void CHL2MP_Player::FireBullets ( const FireBulletsInfo_t &info )
/* "FireBulletsInfo_t":
     0 int m_iShots;
    4 Vector m_vecSrc;
    16 Vector m_vecDirShooting;
    28 Vector m_vecSpread;
    40 float m_flDistance;
    44 int m_iAmmoType;
    48 int m_iTracerFreq;
    52 float m_flDamage;
    56 int m_iPlayerDamage;    
    60 int m_nFlags;
    64 float m_flDamageForceScale;
    68 CBaseEntity *m_pAttacker;
    72 CBaseEntity *m_pAdditionalIgnoreEnt;
    76 bool m_bPrimaryAttack; 
*/
public MRESReturn:FireBullets(int clientHandle hParams){
    
//DHookSetParamObjectPtrVar( hParams, 1, 0, ObjectValueType_Int, 0);
    
    
float vec[3];
    
DHookGetParamObjectPtrVarVector(hParams128ObjectValueType_Vectorvec);
    
PrintToChatAll("%f %f %f"vec[0],vec[1],vec[2]); // << works
    
    
float VECTOR_CONE_5DEGREES[] = {0.043620.043620.04362};
    
//DHookSetParamObjectPtrVarVector(hParams, 1, 28, ObjectValueType_Vector, VECTOR_CONE_5DEGREES); // << fails
     
DHookSetParamObjectPtrVar(hParams128ObjectValueType_FloatVECTOR_CONE_5DEGREES[0]);
    
DHookSetParamObjectPtrVar(hParams132ObjectValueType_FloatVECTOR_CONE_5DEGREES[1]);
    
DHookSetParamObjectPtrVar(hParams136ObjectValueType_FloatVECTOR_CONE_5DEGREES[2]);
    return 
MRES_Handled;

Alienmario is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 08-08-2015 , 18:04   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #352

yea its missing check here, i guess vectors by value aren't common
Miu is offline
Dr!fter
The Salt Boss
Join Date: Mar 2007
Old 08-08-2015 , 23:45   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #353

Quote:
Originally Posted by Alienmario View Post
Hi there. First of all, this extension has been great help. The plugin I'm making couldn't be done without it.

After weeks of trying to hook bullet spread of weapons in HL2DM I have found a solution and a little bug with this extension.

The problem lies in this function: DHookSetParamObjectPtrVarVector(hParams, 1, 28, ObjectValueType_Vector, vec) reporting:
while everything else seems to be correct. Reading the vector at same offset also works as expected.
I have solved this by passing 3 floats instead of the vector (I wish I realized that earlier lol) like so:
Quote:
Originally Posted by Miu View Post
yea its missing check here, i guess vectors by value aren't common
Oops thought i replied to this. Its a bug It has support for non ptr but the first if only checks for VectorPtr
Dr!fter is offline
DeathChaos25
Senior Member
Join Date: Jan 2014
Location: Puerto Rico
Old 09-02-2015 , 12:37   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #354

So, I think I'm definitely doing something wrong here.

PHP Code:
new Handle:hSequenceSet;
public 
OnPluginStart()
{
    new 
Handle:temp LoadGameConfigFile("l4d2_direct");
    
    if (
temp == INVALID_HANDLE)
    {
        
SetFailState("Error: Gamedata not found");
    }
    
    new 
offset;
    
offset GameConfGetOffset(temp"CTerrorPlayer::SelectWeightedSequence");
    if (
offset == -1)
    {
        
CloseHandle(temp);
        
LogError("Unable to get offset for CTerrorPlayer::SelectWeightedSequence");
        return;
    }
    
hSequenceSet DHookCreate(offsetHookType_EntityReturnType_VoidThisPointer_CBaseEntityOnSequenceSet);
    
DHookAddParam(hSequenceSetHookParamType_Int);
}

public 
MRESReturn:OnSequenceSet(clientHandle:hParams)
{
    if (
IsSurvivor(client))
    {
        
PrintToChat(client"Current Sequence: #%i"DHookGetParam(hParams1));
    }
}

bool:IsSurvivor(client)
{
    return (
client && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 2);
}

public 
OnClientPutInServer(client)
{
    if (!
IsFakeClient(client))DHookEntity(hSequenceSetfalseclient);

All I am doing is hooking into the function and retrieving the value it is setting, but for some reason, the hook is preventing the function from actually setting the value, this is the function that handles the animations for survivors, but because the hook is preventing the function from working, resulting in "Jesus Pose";

Spoiler
__________________
DeathChaos25 is offline
pcmaster
AlliedModders Donor
Join Date: Sep 2009
Old 09-02-2015 , 13:33   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #355

You have to return MRES_Ignored on your hook.
__________________
Stopped hosting servers as of November 2018, no longer active around here.
pcmaster is offline
DeathChaos25
Senior Member
Join Date: Jan 2014
Location: Puerto Rico
Old 09-02-2015 , 13:44   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #356

Quote:
Originally Posted by pcmaster View Post
You have to return MRES_Ignored on your hook.
Like so?

PHP Code:
public MRESReturn:OnSequenceSet(clientHandle:hParams)
{
    if (
IsSurvivor(client))
    {
        
PrintToChat(client"Current Sequence: #%i"DHookGetParam(hParams1));
    }
    return 
MRES_Ignored;

The issue still persists even with this change.
__________________
DeathChaos25 is offline
Dr!fter
The Salt Boss
Join Date: Mar 2007
Old 09-03-2015 , 13:38   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #357

You shouldnt have to return ignored, you can try using a post hook see if it still happens. Its weird since the function should still be called. The only thing i can think of is that the param's are wrong. But i havent checked the function.
Dr!fter is offline
DeathChaos25
Senior Member
Join Date: Jan 2014
Location: Puerto Rico
Old 09-03-2015 , 14:20   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #358

Quote:
Originally Posted by Dr!fter View Post
You shouldnt have to return ignored, you can try using a post hook see if it still happens. Its weird since the function should still be called. The only thing i can think of is that the param's are wrong. But i havent checked the function.
The params should be correct, but then again, I could've probably made a mistake somewhere;
PHP Code:
CTerrorPlayer::SelectWeightedSequence(Activity
Spoiler


Decided to change it into a post hook, while also simply controling the hook with sm_hook for easier testing, but the results are the same nonetheless;
PHP Code:
public Action:HOOKME(clientargs)
{
    if (
IsSurvivor(client))
    {
        if(
clienthook[client] > 0)
        {
            
DHookRemoveHookID(clienthook[client]);
            
clienthook[client] = -1;
        }
        else 
clienthook[client] = DHookEntity(hSequenceSettrueclient);
    }

__________________
DeathChaos25 is offline
Dr!fter
The Salt Boss
Join Date: Mar 2007
Old 09-05-2015 , 22:57   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #359

Its not a void return, it returns an int.
Dr!fter is offline
Marounda
Senior Member
Join Date: Oct 2014
Old 09-16-2015 , 09:04   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #360

Quote:
Originally Posted by Dr!fter View Post
this is most likely not related to DHooks but whatever plugin uses it.
Hello,

I'm really in late and sorry to answer you at this late moment.

A lot of players crying about the spawns on my servers and i guess it's harder since some months.

Can you try to play on one of my DM Server and say me if the spawns are good for you please ?
connect 5.196.58.216:27035

I can understand it will take time, and if i can do something to thank you, say me.

I want to find a solution, but I don't know how...

As you saw my plugins, i don't have a lot of them.

Thanks in advance.

Best regards,
Marounda
__________________
MER IL ET FOU's servers on our website : http://meriletfou.fr/



Last edited by Marounda; 09-16-2015 at 09:04.
Marounda is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 08:52.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode