1.1 --- a/extensions/sdktools/vsound.cpp Fri Mar 28 06:21:34 2008 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,309 +0,0 @@
1.4 -/**
1.5 - * vim: set ts=4 :
1.6 - * =============================================================================
1.7 - * SourceMod SDKTools Extension
1.8 - * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
1.9 - * =============================================================================
1.10 - *
1.11 - * This program is free software; you can redistribute it and/or modify it under
1.12 - * the terms of the GNU General Public License, version 3.0, as published by the
1.13 - * Free Software Foundation.
1.14 - *
1.15 - * This program is distributed in the hope that it will be useful, but WITHOUT
1.16 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.17 - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.18 - * details.
1.19 - *
1.20 - * You should have received a copy of the GNU General Public License along with
1.21 - * this program. If not, see <http://www.gnu.org/licenses/>.
1.22 - *
1.23 - * As a special exception, AlliedModders LLC gives you permission to link the
1.24 - * code of this program (as well as its derivative works) to "Half-Life 2," the
1.25 - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
1.26 - * by the Valve Corporation. You must obey the GNU General Public License in
1.27 - * all respects for all other code used. Additionally, AlliedModders LLC grants
1.28 - * this exception to all derivative works. AlliedModders LLC defines further
1.29 - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
1.30 - * or <http://www.sourcemod.net/license.php>.
1.31 - *
1.32 - * Version: $Id$
1.33 - */
1.34 -
1.35 -#include "extension.h"
1.36 -#include "CellRecipientFilter.h"
1.37 -
1.38 -static cell_t PrefetchSound(IPluginContext *pContext, const cell_t *params)
1.39 -{
1.40 - char *name;
1.41 - pContext->LocalToString(params[1], &name);
1.42 -
1.43 - engsound->PrefetchSound(name);
1.44 -
1.45 - return 1;
1.46 -}
1.47 -
1.48 -static cell_t GetSoundDuration(IPluginContext *pContext, const cell_t *params)
1.49 -{
1.50 - char *name;
1.51 - pContext->LocalToString(params[1], &name);
1.52 -
1.53 - return sp_ftoc(engsound->GetSoundDuration(name));
1.54 -}
1.55 -
1.56 -static cell_t EmitAmbientSound(IPluginContext *pContext, const cell_t *params)
1.57 -{
1.58 - cell_t entity;
1.59 - Vector pos;
1.60 - char *name;
1.61 - float vol, delay;
1.62 - int pitch, flags, level;
1.63 -
1.64 - entity = params[3];
1.65 -
1.66 - cell_t *addr;
1.67 - pContext->LocalToPhysAddr(params[2], &addr);
1.68 - pos.x = sp_ctof(addr[0]);
1.69 - pos.y = sp_ctof(addr[1]);
1.70 - pos.z = sp_ctof(addr[2]);
1.71 -
1.72 - pContext->LocalToString(params[1], &name);
1.73 -
1.74 - vol = sp_ctof(params[6]);
1.75 - level = params[4];
1.76 - flags = params[5];
1.77 - pitch = params[7];
1.78 - delay = sp_ctof(params[8]);
1.79 -
1.80 - engine->EmitAmbientSound(entity, pos, name, vol, (soundlevel_t)level, flags, pitch, delay);
1.81 -
1.82 - return 1;
1.83 -}
1.84 -
1.85 -static cell_t FadeClientVolume(IPluginContext *pContext, const cell_t *params)
1.86 -{
1.87 - int client = params[1];
1.88 - if (client < 1 || client > playerhelpers->GetMaxClients())
1.89 - {
1.90 - return pContext->ThrowNativeError("Client index %d is not valid", client);
1.91 - }
1.92 -
1.93 - IGamePlayer *player = playerhelpers->GetGamePlayer(client);
1.94 - if (!player->IsInGame())
1.95 - {
1.96 - return pContext->ThrowNativeError("Client index %d is not in game", client);
1.97 - }
1.98 -
1.99 - engine->FadeClientVolume(player->GetEdict(),
1.100 - sp_ctof(params[2]),
1.101 - sp_ctof(params[3]),
1.102 - sp_ctof(params[4]),
1.103 - sp_ctof(params[5]));
1.104 -
1.105 - return 1;
1.106 -}
1.107 -
1.108 -static cell_t StopSound(IPluginContext *pContext, const cell_t *params)
1.109 -{
1.110 - int entity = params[1];
1.111 - int channel = params[2];
1.112 -
1.113 - char *name;
1.114 - pContext->LocalToString(params[3], &name);
1.115 -
1.116 - engsound->StopSound(entity, channel, name);
1.117 -
1.118 - return 1;
1.119 -}
1.120 -
1.121 -static cell_t EmitSound(IPluginContext *pContext, const cell_t *params)
1.122 -{
1.123 - cell_t *addr, *pl_addr;
1.124 -
1.125 - CellRecipientFilter crf;
1.126 - pContext->LocalToPhysAddr(params[1], &pl_addr);
1.127 - crf.Initialize(pl_addr, params[2]);
1.128 -
1.129 - char *sample;
1.130 - pContext->LocalToString(params[3], &sample);
1.131 -
1.132 - int entity = params[4];
1.133 - int channel = params[5];
1.134 - int level = params[6];
1.135 - int flags = params[7];
1.136 - float vol = sp_ctof(params[8]);
1.137 - int pitch = params[9];
1.138 - int speakerentity = params[10];
1.139 -
1.140 - Vector *pOrigin = NULL, origin;
1.141 - Vector *pDir = NULL, dir;
1.142 -
1.143 - pContext->LocalToPhysAddr(params[11], &addr);
1.144 - if (addr != pContext->GetNullRef(SP_NULL_VECTOR))
1.145 - {
1.146 - pOrigin = &origin;
1.147 - origin.x = sp_ctof(addr[0]);
1.148 - origin.y = sp_ctof(addr[1]);
1.149 - origin.z = sp_ctof(addr[2]);
1.150 - }
1.151 -
1.152 - pContext->LocalToPhysAddr(params[12], &addr);
1.153 - if (addr != pContext->GetNullRef(SP_NULL_VECTOR))
1.154 - {
1.155 - pDir = &dir;
1.156 - dir.x = sp_ctof(addr[0]);
1.157 - dir.y = sp_ctof(addr[1]);
1.158 - dir.z = sp_ctof(addr[2]);
1.159 - }
1.160 -
1.161 - bool updatePos = params[13] ? true : false;
1.162 - float soundtime = sp_ctof(params[14]);
1.163 -
1.164 - CUtlVector<Vector> *pOrigVec = NULL;
1.165 - CUtlVector<Vector> origvec;
1.166 - if (params[0] > 14)
1.167 - {
1.168 - pOrigVec = &origvec;
1.169 - for (cell_t i = 15; i <= params[0]; i++)
1.170 - {
1.171 - Vector vec;
1.172 - pContext->LocalToPhysAddr(params[i], &addr);
1.173 - vec.x = sp_ctof(addr[0]);
1.174 - vec.y = sp_ctof(addr[1]);
1.175 - vec.z = sp_ctof(addr[2]);
1.176 - origvec.AddToTail(vec);
1.177 - }
1.178 - }
1.179 -
1.180 - /* If we're going to a "local player" and this is a dedicated server,
1.181 - * intelligently redirect each sound.
1.182 - */
1.183 -
1.184 - if (entity == -2 && engine->IsDedicatedServer())
1.185 - {
1.186 - for (cell_t i=0; i<params[2]; i++)
1.187 - {
1.188 - cell_t player[1];
1.189 - player[0] = pl_addr[i];
1.190 - crf.Reset();
1.191 - crf.Initialize(player, 1);
1.192 - engsound->EmitSound(crf,
1.193 - player[0],
1.194 - channel,
1.195 - sample,
1.196 - vol,
1.197 - (soundlevel_t)level,
1.198 - flags,
1.199 - pitch,
1.200 - pOrigin,
1.201 - pDir,
1.202 - pOrigVec,
1.203 - updatePos,
1.204 - soundtime,
1.205 - speakerentity);
1.206 - }
1.207 - } else {
1.208 - engsound->EmitSound(crf,
1.209 - entity,
1.210 - channel,
1.211 - sample,
1.212 - vol,
1.213 - (soundlevel_t)level,
1.214 - flags,
1.215 - pitch,
1.216 - pOrigin,
1.217 - pDir,
1.218 - pOrigVec,
1.219 - updatePos,
1.220 - soundtime,
1.221 - speakerentity);
1.222 - }
1.223 -
1.224 - return 1;
1.225 -}
1.226 -
1.227 -static cell_t EmitSentence(IPluginContext *pContext, const cell_t *params)
1.228 -{
1.229 - cell_t *addr;
1.230 -
1.231 - CellRecipientFilter crf;
1.232 - pContext->LocalToPhysAddr(params[1], &addr);
1.233 - crf.Initialize(addr, params[2]);
1.234 -
1.235 - int sentence = params[3];
1.236 - int entity = params[4];
1.237 - int channel = params[5];
1.238 - int level = params[6];
1.239 - int flags = params[7];
1.240 - float vol = sp_ctof(params[8]);
1.241 - int pitch = params[9];
1.242 - int speakerentity = params[10];
1.243 -
1.244 - Vector *pOrigin = NULL, origin;
1.245 - Vector *pDir = NULL, dir;
1.246 -
1.247 - pContext->LocalToPhysAddr(params[11], &addr);
1.248 - if (addr != pContext->GetNullRef(SP_NULL_VECTOR))
1.249 - {
1.250 - pOrigin = &origin;
1.251 - origin.x = sp_ctof(addr[0]);
1.252 - origin.y = sp_ctof(addr[1]);
1.253 - origin.z = sp_ctof(addr[2]);
1.254 - }
1.255 -
1.256 - pContext->LocalToPhysAddr(params[12], &addr);
1.257 - if (addr != pContext->GetNullRef(SP_NULL_VECTOR))
1.258 - {
1.259 - pDir = &dir;
1.260 - dir.x = sp_ctof(addr[0]);
1.261 - dir.y = sp_ctof(addr[1]);
1.262 - dir.z = sp_ctof(addr[2]);
1.263 - }
1.264 -
1.265 - bool updatePos = params[13] ? true : false;
1.266 - float soundtime = sp_ctof(params[14]);
1.267 -
1.268 - CUtlVector<Vector> *pOrigVec = NULL;
1.269 - CUtlVector<Vector> origvec;
1.270 - if (params[0] > 14)
1.271 - {
1.272 - pOrigVec = &origvec;
1.273 - for (cell_t i = 15; i <= params[0]; i++)
1.274 - {
1.275 - Vector vec;
1.276 - pContext->LocalToPhysAddr(params[i], &addr);
1.277 - vec.x = sp_ctof(addr[0]);
1.278 - vec.y = sp_ctof(addr[1]);
1.279 - vec.z = sp_ctof(addr[2]);
1.280 - origvec.AddToTail(vec);
1.281 - }
1.282 - }
1.283 -
1.284 - engsound->EmitSentenceByIndex(crf,
1.285 - entity,
1.286 - channel,
1.287 - sentence,
1.288 - vol,
1.289 - (soundlevel_t)level,
1.290 - flags,
1.291 - pitch,
1.292 - pOrigin,
1.293 - pDir,
1.294 - pOrigVec,
1.295 - updatePos,
1.296 - soundtime,
1.297 - speakerentity);
1.298 -
1.299 - return 1;
1.300 -}
1.301 -
1.302 -sp_nativeinfo_t g_SoundNatives[] =
1.303 -{
1.304 - {"EmitAmbientSound", EmitAmbientSound},
1.305 - {"EmitSentence", EmitSentence},
1.306 - {"EmitSound", EmitSound},
1.307 - {"FadeClientVolume", FadeClientVolume},
1.308 - {"GetSoundDuration", GetSoundDuration},
1.309 - {"PrefetchSound", PrefetchSound},
1.310 - {"StopSound", StopSound},
1.311 - {NULL, NULL},
1.312 -};