AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [DHOOKS][TF2] block dispenser heal/ammo/metal (https://forums.alliedmods.net/showthread.php?t=259931)

arthurdead 03-15-2015 22:54

[DHOOKS][TF2] block dispenser heal/ammo/metal
 
PHP Code:

#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <dhooks>
#include <morecolors>
#include <tf2_stocks>

#pragma semicolon 1;
#pragma newdecls required;

Handle hDispenseAmmo;
Handle hDispenseMetal;
Handle hStartHealing;

Handle hDispenseAmmoCall;
Handle hDispenseMetalCall;
Handle hStartHealingCall;
Handle hRemoveHealingTargetCall;

Handle hCvar_Metal;
Handle hCvar_Ammo;
Handle hCvar_Heal;
Handle hCvar_Debug;

//412  398 CObjectDispenser::DispenseAmmo(CTFPlayer *)
//405  391 CObjectDispenser::DispenseMetal(CTFPlayer *)
//417  403 CObjectDispenser::StartHealing(CBaseEntity *)
//         CObjectDispenser::RemoveHealingTarget(CObjectDispenser *this, CBaseEntity *)

public void OnPluginStart()
{
    
Handle hGameConf LoadGameConfigFile("tf2.dispenser");
    if(
hGameConf == INVALID_HANDLESetFailState("tf2.dispenser.txt Not Found check you gamedata folder");

    
int DispenseAmmoOffset GameConfGetOffset(hGameConf"CObjectDispenser::DispenseAmmo");
    if(
DispenseAmmoOffset == -1SetFailState("Failed To Get Offset For CObjectDispenser::DispenseAmmo");

    
int DispenseMetalOffset GameConfGetOffset(hGameConf"CObjectDispenser::DispenseMetal");
    if(
DispenseMetalOffset == -1SetFailState("Failed To Get Offset For CObjectDispenser::DispenseMetal");

    
int StartHealingOffset GameConfGetOffset(hGameConf"CObjectDispenser::StartHealing");
    if(
StartHealingOffset == -1SetFailState("Failed To Get Offset For CObjectDispenser::StartHealing");

    
hDispenseAmmo DHookCreate(DispenseAmmoOffsetHookType_EntityReturnType_BoolThisPointer_CBaseEntityDispenseAmmo);
    
DHookAddParam(hDispenseAmmoHookParamType_CBaseEntity_DHookPass_ByRef);

    
hDispenseMetal DHookCreate(DispenseMetalOffsetHookType_EntityReturnType_BoolThisPointer_CBaseEntityDispenseMetal);
    
DHookAddParam(hDispenseMetalHookParamType_CBaseEntity_DHookPass_ByRef);

    
hStartHealing DHookCreate(StartHealingOffsetHookType_EntityReturnType_BoolThisPointer_CBaseEntityStartHealing);
    
DHookAddParam(hStartHealingHookParamType_CBaseEntity_DHookPass_ByRef);

    
StartPrepSDKCall(SDKCall_Entity);
    
PrepSDKCall_SetFromConf(hGameConfSDKConf_Virtual"CObjectDispenser::StartHealing");
    
PrepSDKCall_AddParameter(SDKType_CBaseEntitySDKPass_Pointer);
    
hStartHealingCall EndPrepSDKCall();
    if(
hStartHealingCall == INVALID_HANDLESetFailState("Failed To End SDKCall hStartHealingCall");

    
StartPrepSDKCall(SDKCall_Entity);
    
PrepSDKCall_SetFromConf(hGameConfSDKConf_Virtual"CObjectDispenser::DispenseAmmo");
    
PrepSDKCall_AddParameter(SDKType_CBaseEntitySDKPass_Pointer);
    
hDispenseAmmoCall EndPrepSDKCall();
    if(
hDispenseAmmoCall == INVALID_HANDLESetFailState("Failed To End SDKCall hDispenseAmmoCall");

    
StartPrepSDKCall(SDKCall_Entity);
    
PrepSDKCall_SetFromConf(hGameConfSDKConf_Virtual"CObjectDispenser::DispenseMetal");
    
PrepSDKCall_AddParameter(SDKType_CBaseEntitySDKPass_Pointer);
    
hDispenseMetalCall EndPrepSDKCall();
    if(
hDispenseMetalCall == INVALID_HANDLESetFailState("Failed To End SDKCall hDispenseMetalCall");

    
StartPrepSDKCall(SDKCall_Entity);
    
PrepSDKCall_SetFromConf(hGameConfSDKConf_Signature"CObjectDispenser::RemoveHealingTarget");
    
PrepSDKCall_AddParameter(SDKType_CBaseEntitySDKPass_Pointer);
    
hRemoveHealingTargetCall EndPrepSDKCall();
    if(
hRemoveHealingTargetCall == INVALID_HANDLESetFailState("Failed To End SDKCall hRemoveHealingTargetCall");

    
hCvar_Metal CreateConVar("dispenser_metal""1");
    
hCvar_Ammo CreateConVar("dispenser_ammo""1");
    
hCvar_Heal CreateConVar("dispenser_heal""1");
    
hCvar_Debug CreateConVar("dispenser_debug""1");

    
delete hGameConf;

    
int ent = -1
    while((
ent FindEntityByClassname(ent"obj_dispenser")) != INVALID_ENT_REFERENCE)
    {
        if(
IsValidEntity(ent)) OnSpawnPost(ent);
    }
    
/*
    ent = -1;
    while((ent = FindEntityByClassname(ent, "dispenser_touch_trigger")) != INVALID_ENT_REFERENCE)
    {
        if(IsValidEntity(ent)) OnSpawnPostTrigger(ent);
    }
    */
}

/*
public void EndTouch(int entity, int other)
{
    int owner = GetEntPropEnt(entity, Prop_Send, "m_hOwnerEntity");
    int DispenserTeam = GetEntProp(owner, Prop_Send, "m_iTeamNum");
    if((other >= 1 && other <= MaxClients) && (GetClientTeam(other) != DispenserTeam))
    {
        SDKCall(hRemoveHealingTargetCall, owner, other);
    }
}

public void StartTouch(int entity, int other)
{
    int owner = GetEntPropEnt(entity, Prop_Send, "m_hOwnerEntity");
    int DispenserTeam = GetEntProp(owner, Prop_Send, "m_iTeamNum");
    if((other >= 1 && other <= MaxClients) && (GetClientTeam(other) != DispenserTeam))
    {
        SDKCall(hStartHealingCall, owner, other);
    }
}
*/


public MRESReturn DispenseAmmo(int thispHandle hReturnHandle hParams)
{
    if(
GetConVarBool(hCvar_Debug))
    {
        
PrintDebug("DispenseAmmo"thisphReturnhParams);
    }
    if(
hReturn != INVALID_HANDLE && !GetConVarBool(hCvar_Ammo))
    {
        
DHookSetReturn(hReturnfalse);
        return 
MRES_Supercede;
    }
    return 
MRES_Ignored;
}

public 
MRESReturn DispenseMetal(int thispHandle hReturnHandle hParams)
{
    if(
GetConVarBool(hCvar_Debug))
    {
        
PrintDebug("DispenseMetal"thisphReturnhParams);
    }
    if(
hReturn != INVALID_HANDLE && !GetConVarBool(hCvar_Metal))
    {
        
DHookSetReturn(hReturnfalse);
        return 
MRES_Supercede;
    }
    return 
MRES_Ignored;
}

public 
MRESReturn StartHealing(int thispHandle hReturnHandle hParams)
{
    if(
GetConVarBool(hCvar_Debug))
    {
        
PrintDebug("StartHealing"thisphReturnhParams);
    }
    if(
hReturn != INVALID_HANDLE && !GetConVarBool(hCvar_Heal))
    {
        
DHookSetReturn(hReturnfalse);
        return 
MRES_Supercede;
    }
    return 
MRES_Ignored;
}

public 
void PrintDebug(char[] functionnameint thispHandle hReturnHandle hParams)
{
    
CPrintToChatAll("{green}----------- {blue}%s {green}----------"functionname);
    
CPrintToChatAll("{blue}hReturn {white}is {green}%i %s", ((hReturn != INVALID_HANDLE) ?  DHookGetReturn(hReturn) : 0), ((hReturn == INVALID_HANDLE) ? "{fullred}INVALID_HANDLE" ""));
    
CPrintToChatAll("{blue}hParams {white}(1) is {green}%N %s", ((hParams != INVALID_HANDLE) ?  DHookGetParam(hParams1) : 0), ((hParams == INVALID_HANDLE) ? "{fullred}INVALID_HANDLE" ""));
    
CPrintToChatAll("{blue}thisp {white}is {green}%i"thisp);
    
CPrintToChatAll("{green}--------------------------------------- \n");
}

public 
void OnEntityCreated(int entity, const char[] classname)
{
    if(
StrEqual(classname"obj_dispenser"false))
    {
        
SDKHook(entitySDKHook_SpawnPostOnSpawnPost);
    }
    
/*
    if(StrEqual(classname, "dispenser_touch_trigger", false))
    {
        SDKHook(entity, SDKHook_SpawnPost, OnSpawnPostTrigger);
    }
    */
}

public 
void OnSpawnPost(int entity)
{
    
DHookEntity(hDispenseAmmofalseentity);
    
DHookEntity(hDispenseMetalfalseentity);
    
DHookEntity(hStartHealingfalseentity);
}

/*
public void OnSpawnPostTrigger(int entity)
{
    SDKHook(entity, SDKHook_StartTouch, StartTouch);
    SDKHook(entity, SDKHook_EndTouch, EndTouch);
}
*/ 

Spoiler


only tested in linux
thisp is the dispenser
you can also make client-specific by using DHookGetParam(Handle:hParams, num);

Chdata 03-16-2015 08:40

Re: [DHOOKS][TF2] block dispenser heal/ammo/metal
 
this doesn't require a gamedata.txt that has to constantly be reupdated?

arthurdead 03-16-2015 11:53

Re: [DHOOKS][TF2] block dispenser heal/ammo/metal
 
Quote:

Originally Posted by Chdata (Post 2274437)
this doesn't require a gamedata.txt that has to constantly be reupdated?

only if valve changes CObjectDispenser ?
even if it changes you can easily find another in seconds

arthurdead 03-16-2015 17:02

Re: [DHOOKS][TF2] block dispenser heal/ammo/metal
 
added a better example

Chdata 03-17-2015 09:33

Re: [DHOOKS][TF2] block dispenser heal/ammo/metal
 
What I mean is, you didn't include one of those gamedata.txt's, and I saw GameConfGetOffset or something, and thought there was some new command to get those offsets automatically, and that the comment with the offsets was just there cause you were making sure or something.

arthurdead 03-17-2015 11:51

Re: [DHOOKS][TF2] block dispenser heal/ammo/metal
 
Quote:

Originally Posted by Chdata (Post 2274826)
What I mean is, you didn't include one of those gamedata.txt's, and I saw GameConfGetOffset or something, and thought there was some new command to get those offsets automatically, and that the comment with the offsets was just there cause you were making sure or something.

oh i see no that was just lazyness will add gamedata

arthurdead 03-18-2015 20:23

Re: [DHOOKS][TF2] block dispenser heal/ammo/metal
 
should have mentioned but you can call the individual functions with sdkcalls like so :
PHP Code:

SDKCall(hStartHealingCalldispenserclient);
SDKCall(hRemoveHealingTargetCalldispenserclient); //linux only
SDKCall(hDispenseMetalCalldispenserclient); //depleates dispenser metal
SDKCall(hDispenseAmmoCalldispenserclient); //depleates dispenser metal 

also added a non-working dispenser heal enemies thing (commented code) if you hook touch you get a beam and no heal if you hook StartTouch and get in the right spot with noclip you mighty get a beam and heal

Chdata 04-06-2015 07:27

Re: [DHOOKS][TF2] block dispenser heal/ammo/metal
 
Works pretty well. I modified it to make it so your dispenser won't dispense metal to other engies on your team if you have less than 200 metal yourself.

barel31 04-06-2015 14:20

Re: [DHOOKS][TF2] block dispenser heal/ammo/metal
 
Looking for a way to block dispensers ammo for a while.
thanks a lot.

Chdata 07-03-2015 14:11

Re: [DHOOKS][TF2] block dispenser heal/ammo/metal
 
Needs new offsets, these crash servers now if someone even tries to select building a dispenser.


All times are GMT -4. The time now is 18:27.

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