Skip to content

Exposed SDKCall_Server call type to use CBaseServer methods#1612

Merged
psychonic merged 1 commit intoalliedmodders:masterfrom
dragokas:master
Oct 26, 2021
Merged

Exposed SDKCall_Server call type to use CBaseServer methods#1612
psychonic merged 1 commit intoalliedmodders:masterfrom
dragokas:master

Conversation

@dragokas
Copy link
Contributor

@dragokas dragokas commented Oct 26, 2021

Successfully tested on L4D2 Linux with:

#include <sourcemod>
#include <sdktools>

Handle g_hSDK_GetNumPlayers = null;

public void OnPluginStart() {
	StartPrepSDKCall(SDKCall_Server);
	PrepSDKCall_SetSignature(SDKLibrary_Engine, "@_ZN11CBaseServer13GetNumPlayersEv", 0);
	PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain);
	g_hSDK_GetNumPlayers = EndPrepSDKCall();

	RegConsoleCmd("sm_numplayers", NumPlayers);
}

public Action NumPlayers(int client, int args)
{
	PrintToChatAll("NumPlayers: %i", SDKCall(g_hSDK_GetNumPlayers));
	PrintToServer("NumPlayers: %i", SDKCall(g_hSDK_GetNumPlayers));

	return Plugin_Handled;
}

Thanks to Nuki for providing the code.

@psychonic psychonic added the hacktoberfest-accepted opt-in for hacktoberfest prs label Oct 26, 2021
@psychonic psychonic merged commit ffc23a1 into alliedmodders:master Oct 26, 2021
SDKCall_Static, /**< Static call */
SDKCall_Entity, /**< CBaseEntity call */
SDKCall_Player, /**< CBasePlayer call */
SDKCall_Server, /**< CBaseServer call */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@psychonic was this safe to add in the middle of the enum?

@Scags
Copy link
Contributor

Scags commented Oct 26, 2021

Wouldn't putting a new enum value in the middle of the declaration ruin plugins compiled using SDKCall_GameRules, SDKCall_EntityList, and SDKCall_Raw

Edit: Shucks, Asherkin beat me by 5 seconds.

@psychonic
Copy link
Member

Gahhhhh. You're both correct.

@psychonic
Copy link
Member

I've fixed it up now in 4b58b9f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hacktoberfest-accepted opt-in for hacktoberfest prs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants