diff --git a/reapi/extra/amxmodx/scripting/include/reapi_addons.inc b/reapi/extra/amxmodx/scripting/include/reapi_addons.inc index b10e9a8..d46bcc6 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_addons.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_addons.inc @@ -44,6 +44,29 @@ native VTC_MuteClient(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 * diff --git a/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc b/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc index 679a67c..07e2eb1 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc @@ -8,7 +8,7 @@ // 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) -// bypass warning: 200 on amxmodx 1.8.2 +// suppress warning: 200 on amxmodx 1.8.2 #if AMXX_VERSION_NUM < 183 #define RG_CBaseAnimating_ResetSequenceInfo RG_CBaseAnimating_ResetSequence #define RG_CBasePlayer_Observer_IsValidTarget RG_CBasePlayer_Observer_IsValid @@ -469,7 +469,7 @@ enum GamedllFunc_CSGameRules RG_CSGameRules_GetPlayerSpawnSpot, /* - * Description: the player has changed userinfo; can change it now + * Description: the player has changed userinfo; can change it now * Params: (const index, infobuffer[]) */ RG_CSGameRules_ClientUserInfoChanged, diff --git a/reapi/include/vtc_api.h b/reapi/include/vtc_api.h index 7ed3916..598d925 100644 --- a/reapi/include/vtc_api.h +++ b/reapi/include/vtc_api.h @@ -1,22 +1,23 @@ #pragma once -#define VOICETRANSCODER_API_VERSION_MAJOR 1 -#define VOICETRANSCODER_API_VERSION_MINOR 0 +#include -template -class IVoidCallbackRegistry { +const char VOICETRANSCODER_VERSION[] = "2017 RC"; + +const size_t VOICETRANSCODER_API_VERSION_MAJOR = 3; +const size_t VOICETRANSCODER_API_VERSION_MINOR = 0; + +template +class IEvent { 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 unregisterCallback(callback_t func) = 0; + virtual void operator+=(handler_t callback) = 0; + virtual void operator-=(handler_t callback) = 0; }; -typedef IVoidCallbackRegistry ICallbackRegistry_ClientStartSpeak; -typedef IVoidCallbackRegistry ICallbackRegistry_ClientStopSpeak; - class IVoiceTranscoderAPI { public: virtual ~IVoiceTranscoderAPI() {} @@ -26,9 +27,12 @@ public: virtual bool IsClientSpeaking(size_t clientIndex) = 0; - virtual ICallbackRegistry_ClientStartSpeak *ClientStartSpeak() = 0; - virtual ICallbackRegistry_ClientStopSpeak *ClientStopSpeak() = 0; + virtual IEvent& OnClientStartSpeak() = 0; + virtual IEvent& OnClientStopSpeak() = 0; virtual void MuteClient(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; }; diff --git a/reapi/src/hook_callback.cpp b/reapi/src/hook_callback.cpp index 2340f09..85849da 100644 --- a/reapi/src/hook_callback.cpp +++ b/reapi/src/hook_callback.cpp @@ -707,12 +707,12 @@ void ShowVGUIMenu(IReGameHook_ShowVGUIMenu *chain, CBasePlayer *pPlayer, int Men int g_iClientStartSpeak, g_iClientStopSpeak; -void ClientStartSpeak(size_t clientIndex) +void OnClientStartSpeak(size_t clientIndex) { g_amxxapi.ExecuteForward(g_iClientStartSpeak, clientIndex); } -void ClientStopSpeak(size_t clientIndex) +void OnClientStopSpeak(size_t clientIndex) { g_amxxapi.ExecuteForward(g_iClientStopSpeak, clientIndex); } diff --git a/reapi/src/hook_callback.h b/reapi/src/hook_callback.h index 167fab0..f56f7ed 100644 --- a/reapi/src/hook_callback.h +++ b/reapi/src/hook_callback.h @@ -356,5 +356,5 @@ void CSGameRules_BalanceTeams(IReGameHook_CSGameRules_BalanceTeams *chain); extern int g_iClientStartSpeak; extern int g_iClientStopSpeak; -void ClientStartSpeak(size_t clientIndex); -void ClientStopSpeak(size_t clientIndex); +void OnClientStartSpeak(size_t clientIndex); +void OnClientStopSpeak(size_t clientIndex); diff --git a/reapi/src/main.cpp b/reapi/src/main.cpp index 5880014..f329805 100644 --- a/reapi/src/main.cpp +++ b/reapi/src/main.cpp @@ -36,8 +36,8 @@ void OnMetaDetach() g_hookManager.clearHandlers(); if (api_cfg.hasVTC()) { - g_pVoiceTranscoderApi->ClientStartSpeak()->unregisterCallback(&ClientStartSpeak); - g_pVoiceTranscoderApi->ClientStopSpeak()->unregisterCallback(&ClientStopSpeak); + g_pVoiceTranscoderApi->OnClientStartSpeak() -= OnClientStartSpeak; + g_pVoiceTranscoderApi->OnClientStopSpeak() -= OnClientStopSpeak; } if (api_cfg.hasReGameDLL()) { @@ -56,8 +56,10 @@ void ServerActivate_Post(edict_t *pEdictList, int edictCount, int clientMax) void ServerDeactivate_Post() { + g_pEdicts = nullptr; api_cfg.ServerDeactivate(); g_hookManager.clearHandlers(); + g_pFunctionTable->pfnSpawn = DispatchSpawn; g_pFunctionTable->pfnKeyValue = KeyValue; diff --git a/reapi/src/meta_api.cpp b/reapi/src/meta_api.cpp index 7efd971..08df9ff 100644 --- a/reapi/src/meta_api.cpp +++ b/reapi/src/meta_api.cpp @@ -19,7 +19,7 @@ plugin_info_t Plugin_info = 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; gpMetaUtilFuncs = pMetaUtilFuncs; diff --git a/reapi/src/mods/mod_vtc_api.cpp b/reapi/src/mods/mod_vtc_api.cpp index f54df41..ae826a6 100644 --- a/reapi/src/mods/mod_vtc_api.cpp +++ b/reapi/src/mods/mod_vtc_api.cpp @@ -25,8 +25,8 @@ bool VTC_Api_Init() return false; } - g_pVoiceTranscoderApi->ClientStartSpeak()->registerCallback(&ClientStartSpeak); - g_pVoiceTranscoderApi->ClientStopSpeak()->registerCallback(&ClientStopSpeak); + g_pVoiceTranscoderApi->OnClientStartSpeak() += OnClientStartSpeak; + g_pVoiceTranscoderApi->OnClientStopSpeak() += OnClientStopSpeak; return true; } diff --git a/reapi/src/natives/natives_addons.cpp b/reapi/src/natives/natives_addons.cpp index 7e19258..e277cd1 100644 --- a/reapi/src/natives/natives_addons.cpp +++ b/reapi/src/natives/natives_addons.cpp @@ -32,7 +32,7 @@ cell AMX_NATIVE_CALL VTC_MuteClient(AMX *amx, cell *params) CHECK_ISPLAYER(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); 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[] = @@ -58,6 +98,8 @@ AMX_NATIVE_INFO Vtc_Natives[] = { "VTC_IsClientSpeaking", VTC_IsClientSpeaking }, { "VTC_MuteClient", VTC_MuteClient }, { "VTC_UnmuteClient", VTC_UnmuteClient }, + { "VTC_IsClientMuted", VTC_IsClientMuted }, + { "VTC_PlaySound", VTC_PlaySound }, { nullptr, nullptr } };