2
0
mirror of https://github.com/rehlds/reapi.git synced 2025-03-13 14:00:19 +03:00

Update VTC API 3.0

Add natives VTC_IsClientMuted, VTC_PlaySound
This commit is contained in:
s1lentq 2016-12-25 20:16:30 +07:00
parent a6ad16fe85
commit 076fc47a5b
9 changed files with 97 additions and 26 deletions

View File

@ -44,6 +44,29 @@ native VTC_MuteClient(const index);
*/ */
native VTC_UnmuteClient(const index); native VTC_UnmuteClient(const index);
/*
* Checks whether the player is muted at this moment
*
* @param index Client index
* @return true if client is muted, false otherwise
*
*/
native bool:VTC_IsClientMuted(const index);
/*
* To play the audio file via the voice stream.
*
* @param receiver Receiver index
* @param soundFilePath The path to the sound file.
*
* @note Usage example:
* VTC_PlaySound(id, "sound/ambience/Opera.wav");
*
* @noreturn
*
*/
native VTC_PlaySound(const receiver, const soundFilePath[]);
/* /*
* Called when player started talking * Called when player started talking
* *

View File

@ -8,7 +8,7 @@
// NOTE: Use this for hookchain RG_RoundEnd with the parameter ScenarioEventEndRound:event // NOTE: Use this for hookchain RG_RoundEnd with the parameter ScenarioEventEndRound:event
#define HadRoundExpired(event) (1<<_:event) & (1<<_:ROUND_TARGET_SAVED) | (1<<_:ROUND_HOSTAGE_NOT_RESCUED) | (1<<_:ROUND_TERRORISTS_NOT_ESCAPED) | (1<<_:ROUND_VIP_NOT_ESCAPED) #define HadRoundExpired(event) (1<<_:event) & (1<<_:ROUND_TARGET_SAVED) | (1<<_:ROUND_HOSTAGE_NOT_RESCUED) | (1<<_:ROUND_TERRORISTS_NOT_ESCAPED) | (1<<_:ROUND_VIP_NOT_ESCAPED)
// bypass warning: 200 on amxmodx 1.8.2 // suppress warning: 200 on amxmodx 1.8.2
#if AMXX_VERSION_NUM < 183 #if AMXX_VERSION_NUM < 183
#define RG_CBaseAnimating_ResetSequenceInfo RG_CBaseAnimating_ResetSequence #define RG_CBaseAnimating_ResetSequenceInfo RG_CBaseAnimating_ResetSequence
#define RG_CBasePlayer_Observer_IsValidTarget RG_CBasePlayer_Observer_IsValid #define RG_CBasePlayer_Observer_IsValidTarget RG_CBasePlayer_Observer_IsValid

View File

@ -1,22 +1,23 @@
#pragma once #pragma once
#define VOICETRANSCODER_API_VERSION_MAJOR 1 #include <cstddef>
#define VOICETRANSCODER_API_VERSION_MINOR 0
template <typename ...t_args> const char VOICETRANSCODER_VERSION[] = "2017 RC";
class IVoidCallbackRegistry {
const size_t VOICETRANSCODER_API_VERSION_MAJOR = 3;
const size_t VOICETRANSCODER_API_VERSION_MINOR = 0;
template <typename ...T_ARGS>
class IEvent {
public: public:
virtual ~IVoidCallbackRegistry() {} virtual ~IEvent() {}
typedef void (*callback_t)(t_args...); typedef void (*handler_t)(T_ARGS...);
virtual void registerCallback(callback_t func) = 0; virtual void operator+=(handler_t callback) = 0;
virtual void unregisterCallback(callback_t func) = 0; virtual void operator-=(handler_t callback) = 0;
}; };
typedef IVoidCallbackRegistry<size_t> ICallbackRegistry_ClientStartSpeak;
typedef IVoidCallbackRegistry<size_t> ICallbackRegistry_ClientStopSpeak;
class IVoiceTranscoderAPI { class IVoiceTranscoderAPI {
public: public:
virtual ~IVoiceTranscoderAPI() {} virtual ~IVoiceTranscoderAPI() {}
@ -26,9 +27,12 @@ public:
virtual bool IsClientSpeaking(size_t clientIndex) = 0; virtual bool IsClientSpeaking(size_t clientIndex) = 0;
virtual ICallbackRegistry_ClientStartSpeak *ClientStartSpeak() = 0; virtual IEvent<size_t>& OnClientStartSpeak() = 0;
virtual ICallbackRegistry_ClientStopSpeak *ClientStopSpeak() = 0; virtual IEvent<size_t>& OnClientStopSpeak() = 0;
virtual void MuteClient(size_t clientIndex) = 0; virtual void MuteClient(size_t clientIndex) = 0;
virtual void UnmuteClient(size_t clientIndex) = 0; virtual void UnmuteClient(size_t clientIndex) = 0;
virtual bool IsClientMuted(size_t clientIndex) = 0;
virtual void PlaySound(size_t receiverClientIndex, const char *soundFilePath) = 0;
}; };

View File

@ -707,12 +707,12 @@ void ShowVGUIMenu(IReGameHook_ShowVGUIMenu *chain, CBasePlayer *pPlayer, int Men
int g_iClientStartSpeak, g_iClientStopSpeak; int g_iClientStartSpeak, g_iClientStopSpeak;
void ClientStartSpeak(size_t clientIndex) void OnClientStartSpeak(size_t clientIndex)
{ {
g_amxxapi.ExecuteForward(g_iClientStartSpeak, clientIndex); g_amxxapi.ExecuteForward(g_iClientStartSpeak, clientIndex);
} }
void ClientStopSpeak(size_t clientIndex) void OnClientStopSpeak(size_t clientIndex)
{ {
g_amxxapi.ExecuteForward(g_iClientStopSpeak, clientIndex); g_amxxapi.ExecuteForward(g_iClientStopSpeak, clientIndex);
} }

View File

@ -356,5 +356,5 @@ void CSGameRules_BalanceTeams(IReGameHook_CSGameRules_BalanceTeams *chain);
extern int g_iClientStartSpeak; extern int g_iClientStartSpeak;
extern int g_iClientStopSpeak; extern int g_iClientStopSpeak;
void ClientStartSpeak(size_t clientIndex); void OnClientStartSpeak(size_t clientIndex);
void ClientStopSpeak(size_t clientIndex); void OnClientStopSpeak(size_t clientIndex);

View File

@ -36,8 +36,8 @@ void OnMetaDetach()
g_hookManager.clearHandlers(); g_hookManager.clearHandlers();
if (api_cfg.hasVTC()) { if (api_cfg.hasVTC()) {
g_pVoiceTranscoderApi->ClientStartSpeak()->unregisterCallback(&ClientStartSpeak); g_pVoiceTranscoderApi->OnClientStartSpeak() -= OnClientStartSpeak;
g_pVoiceTranscoderApi->ClientStopSpeak()->unregisterCallback(&ClientStopSpeak); g_pVoiceTranscoderApi->OnClientStopSpeak() -= OnClientStopSpeak;
} }
if (api_cfg.hasReGameDLL()) { if (api_cfg.hasReGameDLL()) {
@ -56,8 +56,10 @@ void ServerActivate_Post(edict_t *pEdictList, int edictCount, int clientMax)
void ServerDeactivate_Post() void ServerDeactivate_Post()
{ {
g_pEdicts = nullptr;
api_cfg.ServerDeactivate(); api_cfg.ServerDeactivate();
g_hookManager.clearHandlers(); g_hookManager.clearHandlers();
g_pFunctionTable->pfnSpawn = DispatchSpawn; g_pFunctionTable->pfnSpawn = DispatchSpawn;
g_pFunctionTable->pfnKeyValue = KeyValue; g_pFunctionTable->pfnKeyValue = KeyValue;

View File

@ -19,7 +19,7 @@ plugin_info_t Plugin_info =
PT_NEVER, // (when) unloadable PT_NEVER, // (when) unloadable
}; };
C_DLLEXPORT int Meta_Query(char *interfaceVersion, plugin_info_t* *plinfo, mutil_funcs_t *pMetaUtilFuncs) C_DLLEXPORT int Meta_Query(char *interfaceVersion, plugin_info_t **plinfo, mutil_funcs_t *pMetaUtilFuncs)
{ {
*plinfo = &Plugin_info; *plinfo = &Plugin_info;
gpMetaUtilFuncs = pMetaUtilFuncs; gpMetaUtilFuncs = pMetaUtilFuncs;

View File

@ -25,8 +25,8 @@ bool VTC_Api_Init()
return false; return false;
} }
g_pVoiceTranscoderApi->ClientStartSpeak()->registerCallback(&ClientStartSpeak); g_pVoiceTranscoderApi->OnClientStartSpeak() += OnClientStartSpeak;
g_pVoiceTranscoderApi->ClientStopSpeak()->registerCallback(&ClientStopSpeak); g_pVoiceTranscoderApi->OnClientStopSpeak() += OnClientStopSpeak;
return true; return true;
} }

View File

@ -32,7 +32,7 @@ cell AMX_NATIVE_CALL VTC_MuteClient(AMX *amx, cell *params)
CHECK_ISPLAYER(arg_index); CHECK_ISPLAYER(arg_index);
g_pVoiceTranscoderApi->MuteClient((size_t)params[arg_index]); g_pVoiceTranscoderApi->MuteClient((size_t)params[arg_index]);
return FALSE; return TRUE;
} }
/* /*
@ -50,7 +50,47 @@ cell AMX_NATIVE_CALL VTC_UnmuteClient(AMX *amx, cell *params)
CHECK_ISPLAYER(arg_index); CHECK_ISPLAYER(arg_index);
g_pVoiceTranscoderApi->UnmuteClient((size_t)params[arg_index]); g_pVoiceTranscoderApi->UnmuteClient((size_t)params[arg_index]);
return FALSE; return TRUE;
}
/*
* Checks whether the player is muted at this moment
*
* @param index Client index
* @return true if client is muted, false otherwise
*
* native bool:VTC_IsClientMuted(const index);
*/
cell AMX_NATIVE_CALL VTC_IsClientMuted(AMX *amx, cell *params)
{
enum args_e { arg_count, arg_index };
CHECK_ISPLAYER(arg_index);
return (cell)g_pVoiceTranscoderApi->IsClientMuted((size_t)params[arg_index]);
}
/*
* To play the audio file via the voice stream.
*
* @param receiver Receiver index
* @param soundFilePath The path to the sound file.
*
* @note Usage example:
* VTC_PlaySound(id, "sound/ambience/Opera.wav");
*
* @noreturn
*
* native VTC_PlaySound(const receiver, const soundFilePath[]);
*/
cell AMX_NATIVE_CALL VTC_PlaySound(AMX *amx, cell *params)
{
enum args_e { arg_count, arg_index, arg_audio_pathfile };
CHECK_ISPLAYER(arg_index);
g_pVoiceTranscoderApi->PlaySound((size_t)params[arg_index], getAmxString(amx, params[arg_audio_pathfile]));
return TRUE;
} }
AMX_NATIVE_INFO Vtc_Natives[] = AMX_NATIVE_INFO Vtc_Natives[] =
@ -58,6 +98,8 @@ AMX_NATIVE_INFO Vtc_Natives[] =
{ "VTC_IsClientSpeaking", VTC_IsClientSpeaking }, { "VTC_IsClientSpeaking", VTC_IsClientSpeaking },
{ "VTC_MuteClient", VTC_MuteClient }, { "VTC_MuteClient", VTC_MuteClient },
{ "VTC_UnmuteClient", VTC_UnmuteClient }, { "VTC_UnmuteClient", VTC_UnmuteClient },
{ "VTC_IsClientMuted", VTC_IsClientMuted },
{ "VTC_PlaySound", VTC_PlaySound },
{ nullptr, nullptr } { nullptr, nullptr }
}; };