nosoop / SM-TFCustomAttributeStarterPack

A collection of plugins to be used with the TF2 Custom Attribute framework.
MIT License
19 stars 10 forks source link

Can you add this in? (This fixes if you attack a Dead Ringer Spy) #17

Closed ctf2w-crafting closed 4 years ago

ctf2w-crafting commented 4 years ago
#pragma semicolon 1
#include <sourcemod>

#include <dhooks>

#pragma newdecls required

#include <stocksoup/tf/entity_prop_stocks>
#include <tf_custom_attributes>

public void OnPluginStart() {
    Handle hGameConf = LoadGameConfigFile("tf2.cattr_starterpack");
    if (!hGameConf) {
        SetFailState("Failed to load gamedata (tf2.cattr_starterpack).");
    }

    Handle dtRemoveDisguise = DHookCreateFromConf(hGameConf,
            "CTFWeaponBaseGun::ShouldRemoveDisguiseOnPrimaryAttack()");
    DHookEnableDetour(dtRemoveDisguise, true, OnShouldRemoveDisguiseOnPrimaryAttackPost);

    delete hGameConf;
}

public MRESReturn OnShouldRemoveDisguiseOnPrimaryAttackPost(int weapon, Handle hReturn) {
    int owner = TF2_GetEntityOwner(weapon);
    bool remove = DHookGetReturn(hReturn);
    if (!IsValidClient(owner) || !remove || !TF2CustAttr_GetInt(weapon, "keep disguise on attack")) {
        return MRES_Ignored;
    }

    DHookSetReturn(hReturn, false);
    return MRES_ChangedOverride;
}

bool IsValidClient(int client, bool replaycheck = true) {
    if(client <= 0 || client > MaxClients) return false;
    if(!IsClientInGame(client)) return false;
    if(!IsClientConnected(client)) return false;
    if(GetEntProp(client, Prop_Send, "m_bIsCoaching")) return false;
    if(replaycheck) {
        if(IsClientSourceTV(client) || IsClientReplay(client)) return false;
    }
    return true;
}
nosoop commented 4 years ago

Not as-is.

Could you elaborate on the current behavior and the proposed fix? I don't see anything related to attacking Dead Ringer Spies.

nosoop commented 4 years ago

Upon further discussion this seems to just be an opinionated change on the client validity check; nothing related to DR Spies.