sapphonie / StAC-tf2

steph's anticheat (StAC). a built-from-scratch sourcemod based solution to cheating in Team Fortress 2.
https://sappho.io
GNU General Public License v3.0
118 stars 21 forks source link

Add MaterialAdmin support #69

Closed MAGNAT2645 closed 3 years ago

MAGNAT2645 commented 3 years ago

Also, you probably should rewrite checkNativesEtc() (and other optional code) and use these: LibraryExists(), OnLibraryAdded() and OnLibraryRemoved() instead of GetFeatureStatus().

I usually do optional code like this:

#undef REQUIRE_PLUGIN
#tryinclude <sourcebanspp>
#tryinclude <materialadmin>
#define REQUIRE_PLUGIN

#if defined _sourcebanspp_included
bool g_bSBPP = false;
#endif

#if defined _materialadmin_included
bool g_bMA = false;
#endif

public void OnPluginStart() {
    // ...

    // Late-load support

#if defined _sourcebanspp_included
    g_bSBPP = LibraryExists( "sourcebans++" );
#endif

#if defined _materialadmin_included
    g_bMA = LibraryExists( "materialadmin" );
#endif
}

public void OnLibraryAdded(const char[] name) {
#if defined _sourcebanspp_included
    if ( StrEqual( name, "sourcebans++" ) ) {
        g_bSBPP = true;
        return;
    }
#endif

#if defined _materialadmin_included
    if ( StrEqual( name, "materialadmin" ) ) {
        g_bMA = true;
        return;
    }
#endif

    // and so on ...
}
public void OnLibraryRemoved(const char[] name) {
#if defined _sourcebanspp_included
    if ( StrEqual( name, "sourcebans++" ) ) {
        g_bSBPP = false;
        return;
    }
#endif

#if defined _materialadmin_included
    if ( StrEqual( name, "materialadmin" ) ) {
        g_bMA = false;
        return;
    }
#endif

    // and so on ...
}

#if defined _sourcebanspp_included
public void SBPP_OnBanPlayer(int iAdmin, int iTarget, int iTime, const char[] sReason) {
    // ...
}
#endif

#if defined _materialadmin_included
public void MAOnClientBanned(int iClient, int iTarget, char[] sIp, char[] sSteamID, char[] sName, int iTime, char[] sReason) {
    // ...
}
#endif

I know that this way you have to write more code, but this method allows you to compile with/without additional includes and doesn't add to the plugin binary everything (variables, forwards, natives etc.) that was not included (works like stock functions but you have to add #if defined ... manually).

Then you can use it in functions like BanUser:

#if defined _sourcebanspp_included
        if ( g_bSBPP ) {
            SBPP_BanPlayer( 0, Cl, 0, reason );
            // there's no return value for that native, so we have to just assume it worked lol
            return;
        }
#endif

#if defined _materialadmin_included
        if ( g_bMA && MABanPlayer( 0, Cl, MA_BAN_STEAM, 0, reason ) )
            return;
#endif