View Single Post
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 08-22-2022 , 20:12   Re: [TF2] No ammo from dispenser?
Reply With Quote #2

There maybe is that kind plugin, but I did not find.

I quickly peek TF2 server.dll libary (...and source)

I found these, I'm not 100% sure these are correct.
PHP Code:
Windows
407 DispenseAmmo_sub_10469720

Linux
420    CObjectDispenser
::DispenseAmmo(CTFPlayer *)

bool CObjectDispenser::DispenseAmmoCTFPlayer *pPlayer 
Then try with DHooks to hook "obj_dispenser", block that callback.

*edit
There maybe are better methods than this one.

*edit
Here plugin for Windows OS. I have not tested Linux offset
PHP Code:

#include <dhooks>

DynamicHook DHook;
int offset 407;        // Windows 407, Linux 420 ?

public void OnPluginStart()
{
    
// bool CObjectDispenser::DispenseAmmo( CTFPlayer *pPlayer )

    
DHook = new DynamicHook(offsetHookType_EntityReturnType_BoolThisPointer_CBaseEntity);

    if(
DHook == INVALID_HANDLE)
    {
        
SetFailState("DynamicHook failed to create with offset %i"offset);
    }

    
DHook.AddParam(HookParamType_CBaseEntity_DHookPass_ByVal);
    
HookEventEx("player_builtobject"player_builtobject);
}


public 
void player_builtobject(Event event, const char[] namebool dontBroadcast)
{
/*
Server event "player_builtobject", Tick 3871:
- "userid" = "2"
- "object" = "0"
- "index" = "231"
*/

    //if(StrEqual(classname, "obj_dispenser"), true)

    
if(event.GetInt("object") == 0)
    {
        
int client GetClientOfUserId(event.GetInt("userid"));

        if(!
client || CheckCommandAccess(client"DispenseAmmo_Access"ADMFLAG_RCON))
            return;

        
int entity event.GetInt("index");

        
// fake event executed ?
        
if(entity <= MaxClients || !IsValidEntity(entity))
            return;

        
DHook.HookEntity(Hook_PreentityDispenseAmmo);
    }
}


public 
MRESReturn DispenseAmmo(int pThisDHookReturn hReturnDHookParam hParams)
{
    if(!
hParams.Get(0) || hParams.IsNull(1))
        return 
MRES_Ignored;

    
int client hParams.Get(1);

    if(
client <= || client MaxClients)
        return 
MRES_Ignored;


    if(
CheckCommandAccess(client"DispenseAmmo_Access"ADMFLAG_RCON))
        return 
MRES_Ignored;


    
//PrintToServer("DispenseAmmo NOPE %N", client);

    
hReturn.Value false;

    return 
MRES_Supercede;

__________________
Do not Private Message @me

Last edited by Bacardi; 08-23-2022 at 05:01. Reason: fixed offsets
Bacardi is offline