View Single Post
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 05-17-2012 , 10:58   Re: SDK Hooks 2.1 - Updated 2011-9-10
#1826

Quote:
Originally Posted by Ambit View Post
That's strange. I figured at first that my issue was that I had the parameters marked to be passed by reference (it wouldn't make sense since altering the values wouldn't do anything after the function has already run), but when I removed them I got a compiler error saying that the function signature didn't match. I assumed that I must have had it correct since as it is right now I don't get a compiler error.
The reason just removing the &s didn't work is because the correct function also changes the return type (from Action tag to no tag).

The problem is that the signatures for all the callback functions are in one gigantic funcenum (a set of callback functions with the same name) named SDKHookCB, and the compiler doesn't know which the extension expects you to use for which hook type.

For reference, here's the entire set of callback declarations, taken from the 2.1 sdkhooks.inc. The comments above each type are the hook types it applies to:
PHP Code:
funcenum SDKHookCB
{
    
// PreThink/Post
    // PostThink/Post
    
public(client),
    
    
// Spawn
    
Action:public(entity),
    
    
// GroundEntChanged
    // SpawnPost
    // Think/Post
    // VPhysicsUpdate/Post
    
public(entity),
    
    
// EndTouch
    // StartTouch
    // Touch
    
Action:public(entityother),
    
    
// EndTouchPost
    // StartTouchPost
    // TouchPost
    
public(entityother),
    
    
// SetTransmit
    
Action:public(entityclient),
    
    
// WeaponCanSwitchTo
    // WeaponCanUse
    // WeaponDrop
    // WeaponEquip
    // WeaponSwitch
    
Action:public(clientweapon),
    
    
// WeaponCanSwitchToPost
    // WeaponCanUsePost
    // WeaponDropPost
    // WeaponEquipPost
    // WeaponSwitchPost
    
public(clientweapon),
    
    
// OnTakeDamage
    // Note: Force application is dependent on game and damage type(s)
    // SDKHooks 1.0+
    
Action:public(victim, &attacker, &inflictor, &Float:damage, &damagetype),
    
// SDKHooks 2.0+
    
Action:public(victim, &attacker, &inflictor, &Float:damage, &damagetype, &weaponFloat:damageForce[3], Float:damagePosition[3]),
    
// SDKHooks 2.1+  (can check for support at runtime using GetFeatureStatus on SDKHook_DmgCustomInOTD capability.
    // DON'T attempt to access 'damagecustom' var if feature status != available
    
Action:public(victim, &attacker, &inflictor, &Float:damage, &damagetype, &weapon,
        
Float:damageForce[3], Float:damagePosition[3], damagecustom),
    
    
// OnTakeDamagePost
    
public(victimattackerinflictorFloat:damagedamagetype),
    public(
victimattackerinflictorFloat:damagedamagetypeweapon, const Float:damageForce[3], const Float:damagePosition[3]),
    
    
// FireBulletsPost
    
public(clientshots, const String:weaponname[]),
    
    
// TraceAttack
    
Action:public(victim, &attacker, &inflictor, &Float:damage, &damagetype, &ammotypehitboxhitgroup),
    
    
// TraceAttackPost
    
public(victimattackerinflictorFloat:damagedamagetypeammotypehitboxhitgroup),
    
    
// ShouldCollide
    
bool:public(entitycollisiongroupcontentsmaskbool:originalResult),
    
    
// Use
    
Action:public(entityactivatorcallerUseType:typeFloat:value),
    
    
// UsePost
    
public(entityactivatorcallerUseType:typeFloat:value),
    
    
// Reload
    
Action:public(weapon),
    
    
// Reload post
    
public(weaponbool:bSuccessful)
}; 
The only way to fix this would be to make a separate hook function and callback function for each callback type, which would break backward compatibility... and make things harder to read in general.

Quote:
Originally Posted by Ambit View Post
I also saw

Code:
int Hook_OnTakeDamage(CTakeDamageInfoHack &info);
int Hook_OnTakeDamagePost(CTakeDamageInfoHack &info);
in the source code and figured that meant that they must take the same parameters and have the same return type.
Crossing the border between the C++ and SourcePawn sides is tricky. The return value is always a cell_t when crossing, and cell_t is an int on the C++ side. However, in the actual native itself, you pass things back via references using functions in the global smutils (iirc) object, and as such, values declared as references are treated differently.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 05-17-2012 at 11:05. Reason: Spoiler block is unnecessary, as the php block folds it up
Powerlord is offline