Raised This Month: $ Target: $400
 0% 

The Future of Zombie Plugins


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
KyleS
SourceMod Plugin Approver
Join Date: Jul 2009
Location: Segmentation Fault.
Old 01-11-2014 , 15:30   Re: The Future of Zombie Plugins
Reply With Quote #2

I wrote HookMan a few years ago (which is the implementation of this; for my forever WIP zombie plugin). It's about 250 lines and provides nearly all of the above (see attached). However, there's no security model that comes along with it. It wouldn't be hard to extend (albeit, the line count would double).

Protecting natives I don't think will pan out too well (unfortunately). Abstracting these calls can be dangerous in terms of performance. We're forced to incur either children storing auth states, or calling an auth plugin (doubling the initial overhead of the pawn native call).

The one basic rule I've tried to follow with my own set is a plugin should either be:
  1. An API Provider.
  2. Utilizer of an API.
  3. Middleware, utilize an API, and provide an API to others.
Here's an example of Middle-Ware.


PHP Code:
public RegisterHooks()
{
    
HM_RegisterHook(g_hOnClientKnockbackAddition"ZME_OnClientKnockbackAddition");
    
HM_RegisterHook(g_hOnClientKnockbackMultiplication"ZME_OnClientKnockbackMultiplication");
}

public 
ProcessThroughHooks(bool:bCheck, const String:sName[])
{
    
AddHookIfExists(bCheckg_iGlobalBitseTraceAttackPost"ZME_OnClientTraceAttack_Post"ZME_OnClientTraceAttack_PostsName);
}

public 
ZME_OnClientTraceAttack_Post(clientCliTeamattackerAttaTeaminflictorFloat:damagedamagetypeammotypehitboxhitgroup)
{
    if (!
attacker || CliTeam == eHuman || AttaTeam != eHuman || damage 0.1)
    {
        return;
    }
    
    new 
Float:fKnockBack 0.0;

    if (!
CallKnockBackForward(g_hOnClientKnockbackAdditionclientattackerinflictorhitgroupdamagefKnockBack) || \
    !
CallKnockBackForward(g_hOnClientKnockbackMultiplicationclientattackerinflictorhitgroupdamagefKnockBack) || fKnockBack == 0.0)
    {
        return;
    }
    
    
decl Float:fClientLoc[3], Float:fAttackerLoc[3];

    
GetEntPropVector(clientProp_Send"m_vecOrigin"fClientLoc);
    
GetEntPropVector(attackerProp_Send"m_vecOrigin"fAttackerLoc);
    
    
/* From Zombie:Reloaded */
    
MakeVectorFromPoints(fClientLocfAttackerLocfClientLoc);
    
NormalizeVector(fClientLocfClientLoc);
    
ScaleVector(fClientLoc, (fKnockBack * -1.0));
    
    
GetEntPropVector(clientProp_Data"m_vecAbsVelocity"fAttackerLoc);
    
AddVectors(fClientLocfAttackerLocfClientLoc);
    
    
TeleportEntity(clientNULL_VECTORNULL_VECTORfClientLoc);

While the plugin applies attributes to the client, the plugin has no logic (brain) that makes any game based decisions. The only thing the plugin does is abstract calls from a more specific API.

Example of an End User (2):
PHP Code:
public ProcessThroughHooks(bool:bCheck, const String:sName[])
{
    
AddHookIfExists(bCheckg_iGlobalBitseZombifyClientPost"ZME_OnZombifyClient_Post"ZME_OnZombifyClient_PostsName);
    
AddHookIfExists(bCheckg_iGlobalBitseHookClassApply"CM_OnClassUsed"CM_OnClassUsedsName);
    
AddHookIfExists(bCheckg_iGlobalBitseHookClientManager"CM_OnClassesChanged"CM_OnClassesChangedsName);
}

public 
ZME_OnZombifyClient_Post(clientattackerbool:bMother)
{
    if (
g_fShakeArray[client][2] == 0.0)
    {
        return;
    }
    
    new 
Handle:hShake StartMessageOne("Shake"client);    
    
    if (
hShake == INVALID_HANDLE)
    {
        return;
    }
    
    
BfWriteByte(hShake0);
    for (new 
= (sizeof(g_fShakeArray) - 1); >= 0; --i)
    {
        
BfWriteFloat(hShakeg_fShakeArray[client][i]);
    }
    
    
EndMessage();
}

public 
CM_OnClassUsed(iClientiClassiTeam)
{
    new 
iArraySize GetArraySize(g_hClassArray);

    if (!(
<= iClass iArraySize))
    {
        
CM_OnClassesChanged(CM_RegenerateClasses);
    }
    
    
GetArrayArray(g_hClassArrayiClassg_fShakeArray[iClient]);
}

public 
CM_OnClassesChanged(iClassNumber)
{
    
ClearArray(g_hClassArray);

    if (
iClassNumber == CM_RegenerateClasses)
    {
        
iClassNumber CM_NumberOfClasses();
    }
    
    if (!
iClassNumber)
    {
        return;
    }
    
    
decl String:sShakeString[64];
    new 
Float:fInfo[sizeof(g_fShakeArray[])];
    static const 
String:sScan[sizeof(fInfo)][] = { "ShakeDuration""ShakeFrequency""ShakeAmplitude" };
    
    for (new 
iiClassNumberi++)
    {
        for (new 
= (sizeof(sScan) - 1); >= 0; --k)
        {
            if (!
CM_GetString(isScan[k], sShakeStringsizeof(sShakeString)))
            {
                
fInfo[k] = 0.0;
            }
            else
            {
                
fInfo[k] = StringToFloat(sShakeString);
            }
        }

        
PushArrayArray(g_hClassArrayfInfo);
    }

The `Brain` plugin provides no API, only a feature (screen shake on infection). If the plugin is removed, the only thing the user notices is the screen no longer shakes on infection. If the plugin is loaded mid-round, if someone is infected they should have their screen shake.


Lastly, the API plugin (1) should hold no hooks with other plugins, rather stock SM features. The single thing they do is provide an API to other plugins.
PHP Code:
public RegisterMyForwards()
{
    if (
g_iGlobalBits eForwardsRegistered)
    {
        return;
    }
    
    
HM_RegisterHook(g_hGlobalTeams"ZME_OnClientArrayChangeTeam");
    
HM_RegisterHook(g_hSinglePlayerTeam"ZME_OnClientChangeTeam");
    
HM_RegisterHook(g_hSinglePlayerTeamPost"ZME_OnClientChangeTeam_Post");
    
g_iGlobalBits |= eForwardsRegistered;
}

public 
Native_OnChangeArrayClientTeam(Handle:pluginnumParams/* iPlayer A / iTeam A / iCount */
{
    
decl iPlayerArray[MAXPLAYERS+1];
    
GetNativeArray(1iPlayerArrayMAXPLAYERS+1);
    
    new 
iMaxRead GetNativeCell(2);
    new 
iTeam GetNativeCell(3);
    
    for (new 
iiMaxReadi++)
    {
        
g_iClientTeam[iPlayerArray[i]] = iTeam;
    }
    
    
Call_StartForward(g_hGlobalTeams);
    
Call_PushArray(iPlayerArrayiMaxRead);
    
Call_PushCell(iMaxRead);
    
Call_PushCell(iTeam);
    
Call_Finish();

Hopefully this helps, and makes sense.
Attached Files
File Type: inc HookMan.inc (1.8 KB, 309 views)
KyleS is offline
 



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 12:40.


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