fixed stack corruption in sound code

This commit is contained in:
jeefo 2016-03-12 19:56:09 +03:00
commit a27d39a394
13 changed files with 155 additions and 143 deletions

View file

@ -291,7 +291,7 @@ void Bot::AvoidGrenades (void)
m_avoidGrenade = NULL;
m_needAvoidGrenade = 0;
}
Array <entity_t> activeGrenades = bots.GetActiveGrenades ();
Array <edict_t *> activeGrenades = bots.GetActiveGrenades ();
// find all grenades on the map
FOR_EACH_AE (activeGrenades, it)
@ -354,7 +354,7 @@ bool Bot::IsBehindSmokeClouds (edict_t *ent)
return false;
const Vector &betweenUs = (ent->v.origin - pev->origin).Normalize ();
Array <entity_t> activeGrenades = bots.GetActiveGrenades ();
Array <edict_t *> activeGrenades = bots.GetActiveGrenades ();
// find all grenades on the map
FOR_EACH_AE (activeGrenades, it)
@ -2861,7 +2861,7 @@ void Bot::ChooseAimDirection (void)
if (m_trackingEdict == m_lastEnemy)
{
if (m_timeNextTracking < engine.Time ())
changePredictedEnemy = IsAlive (m_lastEnemy);
changePredictedEnemy = false;
}
if (changePredictedEnemy)
@ -2869,7 +2869,7 @@ void Bot::ChooseAimDirection (void)
m_lookAt = waypoints.GetPath (GetAimingWaypoint (m_lastEnemyOrigin))->origin;
m_camp = m_lookAt;
m_timeNextTracking = engine.Time () + 2.0f;
m_timeNextTracking = engine.Time () + 1.25f;
m_trackingEdict = m_lastEnemy;
}
else
@ -3005,7 +3005,7 @@ void Bot::ThinkFrame (void)
CheckMessageQueue (); // check for pending messages
// remove voice icon
if (g_lastRadioTime[g_clients[engine.IndexOfEntity (GetEntity ()) - 1].realTeam] + Random.Float (0.8f, 2.1f) < engine.Time ())
if (g_lastRadioTime[g_clients[engine.IndexOfEntity (GetEntity ()) - 1].team2] + Random.Float (0.8f, 2.1f) < engine.Time ())
SwitchChatterIcon (false); // hide icon
if (botMovement)
@ -6048,6 +6048,9 @@ bool Bot::IsBombDefusing (const Vector &bombOrigin)
{
// this function finds if somebody currently defusing the bomb.
if (!g_bombPlanted)
return false;
bool defusingInProgress = false;
for (int i = 0; i < engine.MaxClients (); i++)

View file

@ -19,6 +19,13 @@ Engine::Engine (void)
for (int i = 0; i < NETMSG_NUM; i++)
m_msgBlock.regMsgs[i] = NETMSG_UNDEFINED;
m_isBotCommand = false;
m_argumentCount = 0;
memset (m_arguments, 0, sizeof (m_arguments));
m_cvars.RemoveAll ();
m_language.RemoveAll ();
}
Engine::~Engine (void)
@ -37,10 +44,6 @@ void Engine::Precache (edict_t *startEntity)
m_drawModels[DRAW_SIMPLE] = PRECACHE_MODEL (ENGINE_STR ("sprites/laserbeam.spr"));
m_drawModels[DRAW_ARROW] = PRECACHE_MODEL (ENGINE_STR ("sprites/arrow1.spr"));
m_isBotCommand = false;
m_argumentCount = 0;
m_arguments[0] = 0x0;
m_localEntity = NULL;
m_startEntity = startEntity;
}
@ -254,7 +257,9 @@ float Engine::GetWaveLength (const char *fileName)
bool Engine::IsDedicatedServer (void)
{
// return true if server is dedicated server, false otherwise
return g_engfuncs.pfnIsDedicatedServer () > 0;
static bool dedicated = g_engfuncs.pfnIsDedicatedServer () > 0;
return dedicated;
}
const char *Engine::GetModName (void)
@ -980,8 +985,6 @@ void Engine::ProcessMesageCapture (void *ptr)
}
else if (!g_bombPlanted && FStrEq (strVal, "#Bomb_Planted"))
{
waypoints.SetBombPosition ();
g_bombPlanted = g_bombSayString = true;
g_timeBombPlanted = Time ();
@ -998,6 +1001,7 @@ void Engine::ProcessMesageCapture (void *ptr)
bot->ChatterMessage (Chatter_WhereIsTheBomb);
}
}
waypoints.SetBombPosition ();
}
else if (bot != NULL && FStrEq (strVal, "#Switch_To_BurstFire"))
bot->m_weaponBurstMode = BM_ON;
@ -1017,19 +1021,19 @@ void Engine::ProcessMesageCapture (void *ptr)
if (playerIndex >= 0 && playerIndex <= MaxClients ())
{
#ifndef XASH_CSDM
Client &cl = g_clients[playerIndex - 1];
Client &client = g_clients[playerIndex - 1];
if (intVal == 1)
cl.realTeam = TERRORIST;
client.team2 = TERRORIST;
else if (intVal == 2)
cl.realTeam = CT;
client.team2 = CT;
else
cl.realTeam = SPECTATOR;
client.team2 = SPECTATOR;
if (yb_csdm_mode.GetInt () == 2)
cl.team = playerIndex;
client.team = playerIndex;
else
cl.team = cl.realTeam;
client.team = client.team2;
#endif
}
break;

View file

@ -850,7 +850,7 @@ void InitConfig (void)
enum Lang { Lang_Original, Lang_Translate } langState = static_cast <Lang> (2);
char buffer[1024];
Engine::TranslatorPair temp = {"", ""};
TranslatorPair temp = {"", ""};
while (fp.GetBuffer (line, 255))
{
@ -2217,21 +2217,23 @@ void StartFrame (void)
// code below is executed only on dedicated server
if (engine.IsDedicatedServer () && !engine.IsNullEntity (player) && (player->v.flags & FL_CLIENT) && !(player->v.flags & FL_FAKECLIENT))
{
if (g_clients[i].flags & CF_ADMIN)
Client &client = g_clients[i];
if (client.flags & CF_ADMIN)
{
if (IsNullString (yb_password_key.GetString ()) && IsNullString (yb_password.GetString ()))
g_clients[i].flags &= ~CF_ADMIN;
else if (strcmp (yb_password.GetString (), INFOKEY_VALUE (GET_INFOKEYBUFFER (g_clients[i].ent), const_cast <char *> (yb_password_key.GetString ()))))
client.flags &= ~CF_ADMIN;
else if (strcmp (yb_password.GetString (), INFOKEY_VALUE (GET_INFOKEYBUFFER (client.ent), const_cast <char *> (yb_password_key.GetString ()))))
{
g_clients[i].flags &= ~CF_ADMIN;
client.flags &= ~CF_ADMIN;
engine.Printf ("Player %s had lost remote access to yapb.", STRING (player->v.netname));
}
}
else if (!(g_clients[i].flags & CF_ADMIN) && !IsNullString (yb_password_key.GetString ()) && !IsNullString (yb_password.GetString ()))
else if (!(client.flags & CF_ADMIN) && !IsNullString (yb_password_key.GetString ()) && !IsNullString (yb_password.GetString ()))
{
if (strcmp (yb_password.GetString (), INFOKEY_VALUE (GET_INFOKEYBUFFER (g_clients[i].ent), const_cast <char *> (yb_password_key.GetString ()))) == 0)
if (strcmp (yb_password.GetString (), INFOKEY_VALUE (GET_INFOKEYBUFFER (client.ent), const_cast <char *> (yb_password_key.GetString ()))) == 0)
{
g_clients[i].flags |= CF_ADMIN;
client.flags |= CF_ADMIN;
engine.Printf ("Player %s had gained full remote access to yapb.", STRING (player->v.netname));
}
}
@ -2386,14 +2388,14 @@ void pfnClientCommand (edict_t *ent, char const *format, ...)
// case it's a bot asking for a client command, we handle it like we do for bot commands
va_list ap;
char buffer[1024];
char buffer[MAX_PRINT_BUFFER];
va_start (ap, format);
_vsnprintf (buffer, sizeof (buffer), format, ap);
_vsnprintf (buffer, SIZEOF_CHAR (buffer), format, ap);
va_end (ap);
// is the target entity an official bot, or a third party bot ?
if (IsValidBot (ent) || (ent->v.flags & FL_DORMANT))
if (ent->v.flags & FL_FAKECLIENT)
{
if (g_isMetamod)
RETURN_META (MRES_SUPERCEDE); // prevent bots to be forced to issue client commands
@ -2887,7 +2889,7 @@ SHARED_LIBRARAY_EXPORT int GetEngineFunctions (enginefuncs_t *functionTable, int
{
if (g_isMetamod)
memset (functionTable, 0, sizeof (enginefuncs_t));
functionTable->pfnChangeLevel = pfnChangeLevel;
functionTable->pfnFindEntityByString = pfnFindEntityByString;
functionTable->pfnEmitSound = pfnEmitSound;
@ -2909,7 +2911,7 @@ SHARED_LIBRARAY_EXPORT int GetEngineFunctions (enginefuncs_t *functionTable, int
functionTable->pfnCmd_Argc = pfnCmd_Argc;
functionTable->pfnSetClientMaxspeed = pfnSetClientMaxspeed;
functionTable->pfnAlertMessage = pfnAlertMessage;
return TRUE;
}
@ -3095,10 +3097,10 @@ DLL_GIVEFNPTRSTODLL GiveFnptrsToDll (enginefuncs_t *functionTable, globalvars_t
AddLogEntry (true, LL_FATAL | LL_IGNORE, "Mod that you has started, not supported by this bot (gamedir: %s)", engine.GetModName ());
#endif
g_funcPointers = g_gameLib->GetFuncAddr <FuncPointers_t> ("GiveFnptrsToDll");
g_entityAPI = g_gameLib->GetFuncAddr <EntityAPI_t> ("GetEntityAPI");
g_getNewEntityAPI = g_gameLib->GetFuncAddr <NewEntityAPI_t> ("GetNewDLLFunctions");
g_serverBlendingAPI = g_gameLib->GetFuncAddr <BlendAPI_t> ("Server_GetBlendingInterface");
g_funcPointers = static_cast <FuncPointers_t> (g_gameLib->GetFuncAddr ("GiveFnptrsToDll"));
g_entityAPI = static_cast <EntityAPI_t> (g_gameLib->GetFuncAddr ("GetEntityAPI"));
g_getNewEntityAPI = static_cast <NewEntityAPI_t> (g_gameLib->GetFuncAddr ("GetNewDLLFunctions"));
g_serverBlendingAPI = static_cast <BlendAPI_t> (g_gameLib->GetFuncAddr ("Server_GetBlendingInterface"));
if (!g_funcPointers || !g_entityAPI)
TerminateOnMalloc ();
@ -3119,29 +3121,27 @@ DLL_ENTRYPOINT
if (DLL_DETACHING)
{
FreeLibraryMemory (); // free everything that's freeable
delete g_gameLib; // if dynamic link library of mod is load, free it
}
DLL_RETENTRY; // the return data type is OS specific too
}
static void LinkEntity_Helper (EntityPtr_t &addr, const char *name, entvars_t *pev)
void LinkEntity_Helper (EntityPtr_t *addr, const char *name, entvars_t *pev)
{
// here we're see an ugliest hack :)
//if (addr == NULL || (g_gameFlags & GAME_OFFICIAL_CSBOT))
addr = g_gameLib->GetFuncAddr <EntityPtr_t > (name);
if (*addr == NULL)
*addr = static_cast <EntityPtr_t> (g_gameLib->GetFuncAddr (name));
if (addr == NULL)
if (*addr == NULL)
return;
addr (pev);
(*addr) (pev);
}
#define LINK_ENTITY(entityName) \
SHARED_LIBRARAY_EXPORT void entityName (entvars_t *pev) \
{ \
static EntityPtr_t addr = NULL; \
LinkEntity_Helper (addr, #entityName, pev); \
static EntityPtr_t addr; \
LinkEntity_Helper (&addr, #entityName, pev); \
} \
// entities in counter-strike...

View file

@ -1488,7 +1488,7 @@ void BotManager::UpdateActiveGrenades (void)
}
}
const Array <entity_t> &BotManager::GetActiveGrenades (void)
const Array <edict_t *> &BotManager::GetActiveGrenades (void)
{
return m_activeGrenades;
}

View file

@ -714,7 +714,7 @@ void SoundAttachToClients (edict_t *ent, const char *sample, float volume)
// the array associated with the entity
if (engine.IsNullEntity (ent) || IsNullString (sample))
return; // reliability check
return;
const Vector &origin = engine.GetAbsOrigin (ent);
int index = engine.IndexOfEntity (ent) - 1;
@ -729,7 +729,7 @@ void SoundAttachToClients (edict_t *ent, const char *sample, float volume)
if (!(g_clients[i].flags & CF_USED) || !(g_clients[i].flags & CF_ALIVE))
continue;
float distance = (g_clients[i].ent->v.origin - origin).GetLengthSquared ();
float distance = (g_clients[i].origin - origin).GetLength ();
// now find nearest player
if (distance < nearestDistance)
@ -739,56 +739,61 @@ void SoundAttachToClients (edict_t *ent, const char *sample, float volume)
}
}
}
Client *client = &g_clients[index];
// in case of worst case
if (index < 0 || index >= engine.MaxClients ())
index = 0;
Client &client = g_clients[index];
if (strncmp ("player/bhit_flesh", sample, 17) == 0 || strncmp ("player/headshot", sample, 15) == 0)
{
// hit/fall sound?
client->hearingDistance = 768.0f * volume;
client->timeSoundLasting = engine.Time () + 0.5f;
client->soundPosition = origin;
client.hearingDistance = 768.0f * volume;
client.timeSoundLasting = engine.Time () + 0.5f;
client.soundPosition = origin;
}
else if (strncmp ("items/gunpickup", sample, 15) == 0)
{
// weapon pickup?
client->hearingDistance = 768.0f * volume;
client->timeSoundLasting = engine.Time () + 0.5f;
client->soundPosition = origin;
client.hearingDistance = 768.0f * volume;
client.timeSoundLasting = engine.Time () + 0.5f;
client.soundPosition = origin;
}
else if (strncmp ("weapons/zoom", sample, 12) == 0)
{
// sniper zooming?
client->hearingDistance = 512.0f * volume;
client->timeSoundLasting = engine.Time () + 0.1f;
client->soundPosition = origin;
client.hearingDistance = 512.0f * volume;
client.timeSoundLasting = engine.Time () + 0.1f;
client.soundPosition = origin;
}
else if (strncmp ("items/9mmclip", sample, 13) == 0)
{
// ammo pickup?
client->hearingDistance = 512.0f * volume;
client->timeSoundLasting = engine.Time () + 0.1f;
client->soundPosition = origin;
client.hearingDistance = 512.0f * volume;
client.timeSoundLasting = engine.Time () + 0.1f;
client.soundPosition = origin;
}
else if (strncmp ("hostage/hos", sample, 11) == 0)
{
// CT used hostage?
client->hearingDistance = 1024.0f * volume;
client->timeSoundLasting = engine.Time () + 5.0f;
client->soundPosition = origin;
client.hearingDistance = 1024.0f * volume;
client.timeSoundLasting = engine.Time () + 5.0f;
client.soundPosition = origin;
}
else if (strncmp ("debris/bustmetal", sample, 16) == 0 || strncmp ("debris/bustglass", sample, 16) == 0)
{
// broke something?
client->hearingDistance = 1024.0f * volume;
client->timeSoundLasting = engine.Time () + 2.0f;
client->soundPosition = origin;
client.hearingDistance = 1024.0f * volume;
client.timeSoundLasting = engine.Time () + 2.0f;
client.soundPosition = origin;
}
else if (strncmp ("doors/doormove", sample, 14) == 0)
{
// someone opened a door
client->hearingDistance = 1024.0f * volume;
client->timeSoundLasting = engine.Time () + 3.0f;
client->soundPosition = origin;
client.hearingDistance = 1024.0f * volume;
client.timeSoundLasting = engine.Time () + 3.0f;
client.soundPosition = origin;
}
}
@ -800,29 +805,29 @@ void SoundSimulateUpdate (int playerIndex)
if (playerIndex < 0 || playerIndex >= engine.MaxClients ())
return; // reliability check
Client *client = &g_clients[playerIndex];
Client &client = g_clients[playerIndex];
float hearDistance = 0.0f;
float timeSound = 0.0f;
if (client->ent->v.oldbuttons & IN_ATTACK) // pressed attack button?
if (client.ent->v.oldbuttons & IN_ATTACK) // pressed attack button?
{
hearDistance = 2048.0f;
timeSound = engine.Time () + 0.3f;
}
else if (client->ent->v.oldbuttons & IN_USE) // pressed used button?
else if (client.ent->v.oldbuttons & IN_USE) // pressed used button?
{
hearDistance = 512.0f;
timeSound = engine.Time () + 0.5f;
}
else if (client->ent->v.oldbuttons & IN_RELOAD) // pressed reload button?
else if (client.ent->v.oldbuttons & IN_RELOAD) // pressed reload button?
{
hearDistance = 512.0f;
timeSound = engine.Time () + 0.5f;
}
else if (client->ent->v.movetype == MOVETYPE_FLY) // uses ladder?
else if (client.ent->v.movetype == MOVETYPE_FLY) // uses ladder?
{
if (fabsf (client->ent->v.velocity.z) > 50.0f)
if (fabsf (client.ent->v.velocity.z) > 50.0f)
{
hearDistance = 1024.0f;
timeSound = engine.Time () + 0.3f;
@ -835,7 +840,7 @@ void SoundSimulateUpdate (int playerIndex)
if (mp_footsteps.GetBool ())
{
// moves fast enough?
hearDistance = 1280.0f * (client->ent->v.velocity.GetLength2D () / 260.0f);
hearDistance = 1280.0f * (client.ent->v.velocity.GetLength2D () / 260.0f);
timeSound = engine.Time () + 0.3f;
}
}
@ -844,22 +849,22 @@ void SoundSimulateUpdate (int playerIndex)
return; // didn't issue sound?
// some sound already associated
if (client->timeSoundLasting > engine.Time ())
if (client.timeSoundLasting > engine.Time ())
{
if (client->hearingDistance <= hearDistance)
if (client.hearingDistance <= hearDistance)
{
// override it with new
client->hearingDistance = hearDistance;
client->timeSoundLasting = timeSound;
client->soundPosition = client->ent->v.origin;
client.hearingDistance = hearDistance;
client.timeSoundLasting = timeSound;
client.soundPosition = client.ent->v.origin;
}
}
else
{
// just remember it
client->hearingDistance = hearDistance;
client->timeSoundLasting = timeSound;
client->soundPosition = client->ent->v.origin;
client.hearingDistance = hearDistance;
client.timeSoundLasting = timeSound;
client.soundPosition = client.ent->v.origin;
}
}

View file

@ -2428,7 +2428,6 @@ void Waypoint::SetBombPosition (bool shouldReset)
return;
}
edict_t *ent = NULL;
while (!engine.IsNullEntity (ent = FIND_ENTITY_BY_CLASSNAME (ent, "grenade")))