A2S: Zuff's allmighty OCD fixing.

This commit is contained in:
zaCade 2019-06-13 14:43:07 +02:00
parent f166ca9f6c
commit 8c808be870
3 changed files with 78 additions and 29 deletions

View File

@ -8,7 +8,7 @@ builder.SetBuildFolder('package')
# Add any folders you need to this list # Add any folders you need to this list
folder_list = [ folder_list = [
'addons/sourcemod/extensions', 'addons/sourcemod/extensions',
#'addons/sourcemod/scripting/include', 'addons/sourcemod/scripting/include',
#'addons/sourcemod/gamedata', #'addons/sourcemod/gamedata',
#'addons/sourcemod/configs', #'addons/sourcemod/configs',
] ]
@ -29,9 +29,9 @@ def CopyFiles(src, dest, files):
builder.AddCopy(source_path, dest_entry) builder.AddCopy(source_path, dest_entry)
# Include files # Include files
#CopyFiles('include', 'addons/sourcemod/scripting/include', CopyFiles('include', 'addons/sourcemod/scripting/include',
# [ 'sample.inc', ] [ 'A2SFixes.inc', ]
#) )
# GameData files # GameData files
#CopyFiles('gamedata', 'addons/sourcemod/gamedata', #CopyFiles('gamedata', 'addons/sourcemod/gamedata',

View File

@ -62,14 +62,15 @@ ConVar g_A2SIncludeSourceTV("a2s_includesourcetv", "0", FCVAR_NONE, "Include Sou
char *NewBuf; char *NewBuf;
char *OldBuf; char *OldBuf;
struct PlayerInfo { int g_iFakePlayers = 0;
struct PlayerInfo
{
char Name[32]; char Name[32];
long Score; long Score;
float Time; float Time;
}; };
int g_FakePlayers = 0;
/** /**
* @brief * @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++) for (int index = 0; index <= SM_MAXPLAYERS; index++)
{ {
IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(index); IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(index);
if (pPlayer != NULL && pPlayer->IsConnected() && (!pPlayer->IsSourceTV() || g_A2SIncludeSourceTV.GetInt())) if (pPlayer != NULL && pPlayer->IsConnected() && (!pPlayer->IsSourceTV() || g_A2SIncludeSourceTV.GetInt()))
{
iPlayers++; iPlayers++;
} }
}
iPlayers += g_FakePlayers; iPlayers += g_iFakePlayers;
// Correct playercount // Correct playercount
memset(NewBuf, iPlayers, 1); 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) 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; int iPlayers = 0;
PlayerInfo PlayerList[SM_MAXPLAYERS]; 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 PlayerReplyPacket.WriteByte(iPlayers); // Number of players
for (int index = 0; index < iPlayers; index++) 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 * @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; return 1;
} }
/** /**
* @brief * @brief
*/ */
const sp_nativeinfo_t MyNatives[] = const sp_nativeinfo_t g_ExtensionNatives[] =
{ {
{"FakePlayers", FakePlayers}, {"A2S_SetFakePlayerCount", SetFakePlayerCount},
{NULL, NULL}, {NULL, NULL},
}; };
void A2SFixes::SDK_OnAllLoaded()
{
sharesys->AddNatives(myself, MyNatives);
}
/** /**
* @brief This is called after the initial loading sequence has been processed. * @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. */ sharesys->AddNatives(myself, g_ExtensionNatives);
return META_REGCVAR(pVar); sharesys->RegisterLibrary(myself, "A2SFixes");
} }
/** /**
@ -283,3 +286,12 @@ bool A2SFixes::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlen, bool
return true; return true;
} }
/**
* @brief
*/
bool A2SFixes::RegisterConCommandBase(ConCommandBase *pVar)
{
/* Always call META_REGCVAR instead of going through the engine. */
return META_REGCVAR(pVar);
}

37
include/A2SFixes.inc Normal file
View File

@ -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