From 8c808be8701b9219f46e3d8529b44bbbd28b1e9e Mon Sep 17 00:00:00 2001 From: zaCade Date: Thu, 13 Jun 2019 14:43:07 +0200 Subject: [PATCH] A2S: Zuff's allmighty OCD fixing. --- PackageScript | 8 +++--- extension.cpp | 62 ++++++++++++++++++++++++++------------------ include/A2SFixes.inc | 37 ++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 29 deletions(-) create mode 100644 include/A2SFixes.inc diff --git a/PackageScript b/PackageScript index d3d460c..1b7210a 100644 --- a/PackageScript +++ b/PackageScript @@ -8,7 +8,7 @@ builder.SetBuildFolder('package') # Add any folders you need to this list folder_list = [ 'addons/sourcemod/extensions', - #'addons/sourcemod/scripting/include', + 'addons/sourcemod/scripting/include', #'addons/sourcemod/gamedata', #'addons/sourcemod/configs', ] @@ -29,9 +29,9 @@ def CopyFiles(src, dest, files): builder.AddCopy(source_path, dest_entry) # Include files -#CopyFiles('include', 'addons/sourcemod/scripting/include', -# [ 'sample.inc', ] -#) +CopyFiles('include', 'addons/sourcemod/scripting/include', + [ 'A2SFixes.inc', ] +) # GameData files #CopyFiles('gamedata', 'addons/sourcemod/gamedata', diff --git a/extension.cpp b/extension.cpp index 538c4fb..848dc8a 100644 --- a/extension.cpp +++ b/extension.cpp @@ -62,14 +62,15 @@ ConVar g_A2SIncludeSourceTV("a2s_includesourcetv", "0", FCVAR_NONE, "Include Sou char *NewBuf; char *OldBuf; -struct PlayerInfo { +int g_iFakePlayers = 0; + +struct PlayerInfo +{ char Name[32]; long Score; float Time; }; -int g_FakePlayers = 0; - /** * @brief */ @@ -122,11 +123,14 @@ DETOUR_DECL_STATIC6(Detour_SendTo, int, int, s, char *, buf, int, len, int, flag for (int index = 0; index <= SM_MAXPLAYERS; index++) { IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(index); + if (pPlayer != NULL && pPlayer->IsConnected() && (!pPlayer->IsSourceTV() || g_A2SIncludeSourceTV.GetInt())) + { iPlayers++; + } } - iPlayers += g_FakePlayers; + iPlayers += g_iFakePlayers; // Correct playercount memset(NewBuf, iPlayers, 1); @@ -147,14 +151,6 @@ DETOUR_DECL_STATIC6(Detour_SendTo, int, int, s, char *, buf, int, len, int, flag if (memcmp(buf, A2S_PLAYER_REPLY, 5) == 0) { - char PlayerReply[1024 * 6]; - bf_write PlayerReplyPacket(PlayerReply, sizeof(PlayerReply)); - - PlayerReplyPacket.Reset(); // Build up the packet as a bitbuffer so we can use the nice helper functions to do the work for us - - PlayerReplyPacket.WriteLong(-1); // FF FF FF FF - PlayerReplyPacket.WriteByte(68); // 44 - int iPlayers = 0; PlayerInfo PlayerList[SM_MAXPLAYERS]; @@ -185,6 +181,14 @@ DETOUR_DECL_STATIC6(Detour_SendTo, int, int, s, char *, buf, int, len, int, flag } } + char PlayerReply[1024 * 6]; + bf_write PlayerReplyPacket(PlayerReply, sizeof(PlayerReply)); + + PlayerReplyPacket.Reset(); // Build up the packet as a bitbuffer so we can use the nice helper functions to do the work for us + + PlayerReplyPacket.WriteLong(-1); // FF FF FF FF + PlayerReplyPacket.WriteByte(68); // 44 + PlayerReplyPacket.WriteByte(iPlayers); // Number of players for (int index = 0; index < iPlayers; index++) @@ -204,26 +208,21 @@ DETOUR_DECL_STATIC6(Detour_SendTo, int, int, s, char *, buf, int, len, int, flag /** * @brief */ -cell_t FakePlayers(IPluginContext *pContext, const cell_t *params) +cell_t SetFakePlayerCount(IPluginContext *pContext, const cell_t *params) { - g_FakePlayers = params[1]; + g_iFakePlayers = params[1]; return 1; } /** * @brief */ -const sp_nativeinfo_t MyNatives[] = +const sp_nativeinfo_t g_ExtensionNatives[] = { - {"FakePlayers", FakePlayers}, - {NULL, NULL}, + {"A2S_SetFakePlayerCount", SetFakePlayerCount}, + {NULL, NULL}, }; -void A2SFixes::SDK_OnAllLoaded() -{ - sharesys->AddNatives(myself, MyNatives); -} - /** * @brief This is called after the initial loading sequence has been processed. * @@ -261,10 +260,14 @@ void A2SFixes::SDK_OnUnload() } } -bool A2SFixes::RegisterConCommandBase(ConCommandBase *pVar) +/** + * @brief This is called once all known extensions have been loaded. + * Note: It is is a good idea to add natives here, if any are provided. + */ +void A2SFixes::SDK_OnAllLoaded() { - /* Always call META_REGCVAR instead of going through the engine. */ - return META_REGCVAR(pVar); + sharesys->AddNatives(myself, g_ExtensionNatives); + sharesys->RegisterLibrary(myself, "A2SFixes"); } /** @@ -282,4 +285,13 @@ bool A2SFixes::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlen, bool ConVar_Register(0, this); return true; +} + +/** + * @brief + */ +bool A2SFixes::RegisterConCommandBase(ConCommandBase *pVar) +{ + /* Always call META_REGCVAR instead of going through the engine. */ + return META_REGCVAR(pVar); } \ No newline at end of file diff --git a/include/A2SFixes.inc b/include/A2SFixes.inc new file mode 100644 index 0000000..67a9970 --- /dev/null +++ b/include/A2SFixes.inc @@ -0,0 +1,37 @@ +#if defined _A2SFixes_included + #endinput +#endif +#define _A2SFixes_included + +/** + * Check if clients usertype is legit. + * + * @param count The amount of fakes to set. + * + * @return Always true. + */ +native bool A2S_SetFakePlayerCount(int count); + + +public Extension __ext_A2SFixes = +{ + name = "A2SFixes", + file = "A2SFixes.ext", +#if defined AUTOLOAD_EXTENSIONS + autoload = 1, +#else + autoload = 0, +#endif +#if defined REQUIRE_EXTENSIONS + required = 1, +#else + required = 0, +#endif +}; + +#if !defined REQUIRE_EXTENSIONS +public __ext_A2SFixes_SetNTVOptional() +{ + MarkNativeAsOptional("A2S_SetFakePlayerCount"); +} +#endif