Skip to content

Commit

Permalink
Add new natives rh_is_paused, rh_set_pause (#1)
Browse files Browse the repository at this point in the history
* Add natives about pause

* Fix crash when g_RehldsData->SetPaused() be called

* host_pause

* Fix doc

* Update natives_misc.cpp

* Update reapi_engine.inc
  • Loading branch information
jonathan-up authored Jul 28, 2024
1 parent 472d279 commit 0e6a620
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
21 changes: 21 additions & 0 deletions reapi/extra/amxmodx/scripting/include/reapi_engine.inc
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,27 @@ native rh_get_net_from(output[], len);
*/
native rh_get_client_connect_time(const index);

/*
* Checks if server paused
*
* @return Returns true if paused, otherwise false.
*/
native bool:rh_is_paused();

/*
* Set server pause state
*
* @param st Pause state, true: server will be paused, false: unpause(if paused)
* @param host If it is 1, the native will call 'Host_Pause()'
*
* @note rh_set_paused(true, true) just like set pausable to 1 and execute client command 'pause'
* @note rh_set_paused(true, false) only set g_psv.paused
* @note It's best not to use rh_set_paused(false, false), bad things will happen
*
* @noreturn
*/
native rh_set_pause(const bool:st, const bool:host = true);

/*
* Checks if a specific entity is fully packed in a given frame for a host client.
*
Expand Down
1 change: 1 addition & 0 deletions reapi/include/cssdk/engine/rehlds_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ struct RehldsFuncs_t {
void(*RemoveExtDll)(void *hModule);
void(*RemoveCvarListener)(const char *var_name, cvar_callback_t func);
ENTITYINIT(*GetEntityInit)(char *pszClassName);
void(*Host_Pause)(bool setPause);

// Read functions
int(*MSG_ReadChar)();
Expand Down
10 changes: 10 additions & 0 deletions reapi/include/cssdk/engine/rehlds_interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,14 @@ class IRehldsServerData {
virtual void SetName(const char* name) = 0;
virtual class ISteamGameServer *GetSteamGameServer() = 0;
virtual struct netadr_s *GetNetFrom() = 0;
virtual double GetOldTime() = 0;
virtual void SetNetFrom(struct netadr_s *from) = 0;
virtual void SetWorldmapCrc(uint32 crcValue) = 0;
virtual void SetDecalNameNum(int num) = 0;

virtual bool IsActive() = 0;
virtual void SetActive(bool state) = 0;

virtual bool IsPaused() = 0;
virtual void SetPaused(bool state) = 0;
};
36 changes: 36 additions & 0 deletions reapi/src/natives/natives_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3722,6 +3722,40 @@ cell AMX_NATIVE_CALL rh_is_entity_fullpacked(AMX *amx, cell *params)
return FALSE;
}

/*
* Checks if server paused
*
* @return Returns true if paused, otherwise false.
*
* native bool:rh_is_paused();
*/
cell AMX_NATIVE_CALL rh_is_paused(AMX *amx, cell *params)
{
return g_RehldsData->IsPaused() ? TRUE : FALSE;
}

/*
* Set server pause state
*
* @param st pause state
*
* @noreturn
*
* native rh_set_paused(const bool:st);
*/
cell AMX_NATIVE_CALL rh_set_pause(AMX *amx, cell *params)
{
enum { arg_count, arg_st, arg_host };
bool isPause = params[arg_st] != 0;

g_RehldsData->SetPaused(isPause);
if (params[arg_host] != 0)
{
g_RehldsFuncs->Host_Pause(isPause);
}
return TRUE;
}

AMX_NATIVE_INFO Misc_Natives_RH[] =
{
{ "rh_set_mapname", rh_set_mapname },
Expand All @@ -3734,6 +3768,8 @@ AMX_NATIVE_INFO Misc_Natives_RH[] =
{ "rh_get_realtime", rh_get_realtime },
{ "rh_is_entity_fullpacked", rh_is_entity_fullpacked },
{ "rh_get_client_connect_time", rh_get_client_connect_time },
{ "rh_is_paused", rh_is_paused },
{ "rh_set_pause", rh_set_pause },

{ nullptr, nullptr }
};
Expand Down

0 comments on commit 0e6a620

Please sign in to comment.