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

[DHOOKS][TF2] block dispenser heal/ammo/metal


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
arthurdead
Senior Member
Join Date: Jul 2013
Old 03-15-2015 , 22:54   [DHOOKS][TF2] block dispenser heal/ammo/metal
Reply With Quote #1

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);

Last edited by arthurdead; 03-18-2015 at 20:24.
arthurdead is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 03-16-2015 , 08:40   Re: [DHOOKS][TF2] block dispenser heal/ammo/metal
Reply With Quote #2

this doesn't require a gamedata.txt that has to constantly be reupdated?
__________________
Chdata is offline
arthurdead
Senior Member
Join Date: Jul 2013
Old 03-16-2015 , 11:53   Re: [DHOOKS][TF2] block dispenser heal/ammo/metal
Reply With Quote #3

Quote:
Originally Posted by Chdata View Post
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

Last edited by arthurdead; 03-16-2015 at 13:26.
arthurdead is offline
arthurdead
Senior Member
Join Date: Jul 2013
Old 03-16-2015 , 17:02   Re: [DHOOKS][TF2] block dispenser heal/ammo/metal
Reply With Quote #4

added a better example
arthurdead is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 03-17-2015 , 09:33   Re: [DHOOKS][TF2] block dispenser heal/ammo/metal
Reply With Quote #5

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.
__________________
Chdata is offline
arthurdead
Senior Member
Join Date: Jul 2013
Old 03-17-2015 , 11:51   Re: [DHOOKS][TF2] block dispenser heal/ammo/metal
Reply With Quote #6

Quote:
Originally Posted by Chdata View Post
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 is offline
arthurdead
Senior Member
Join Date: Jul 2013
Old 03-18-2015 , 20:23   Re: [DHOOKS][TF2] block dispenser heal/ammo/metal
Reply With Quote #7

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

Last edited by arthurdead; 03-18-2015 at 20:48.
arthurdead is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 04-06-2015 , 07:27   Re: [DHOOKS][TF2] block dispenser heal/ammo/metal
Reply With Quote #8

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.
__________________
Chdata is offline
barel31
Member
Join Date: Mar 2011
Old 04-06-2015 , 14:20   Re: [DHOOKS][TF2] block dispenser heal/ammo/metal
Reply With Quote #9

Looking for a way to block dispensers ammo for a while.
thanks a lot.
barel31 is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 07-03-2015 , 14:11   Re: [DHOOKS][TF2] block dispenser heal/ammo/metal
Reply With Quote #10

Needs new offsets, these crash servers now if someone even tries to select building a dispenser.
__________________
Chdata 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 00:01.


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