Raised This Month: $ Target: $400
 0% 

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


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 



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 18:27.


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