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

1
.gitignore vendored
View file

@ -58,3 +58,4 @@ project/yapb.vcxproj.user
*.opendb *.opendb
*.aps *.aps
*.db *.db
*.enc

View file

@ -606,7 +606,7 @@ struct Client
Vector soundPosition; // position sound was played Vector soundPosition; // position sound was played
int team; // bot team int team; // bot team
int realTeam; // real bot team in free for all mode (csdm) int team2; // real bot team in free for all mode (csdm)
int flags; // client flags int flags; // client flags
float hearingDistance; // distance this sound is heared float hearingDistance; // distance this sound is heared
@ -1237,8 +1237,8 @@ private:
bool m_economicsGood[2]; // is team able to buy anything bool m_economicsGood[2]; // is team able to buy anything
bool m_deathMsgSent; // for fakeping bool m_deathMsgSent; // for fakeping
Array <entity_t> m_activeGrenades; // holds currently active grenades in the map Array <edict_t *> m_activeGrenades; // holds currently active grenades in the map
Array <entity_t> m_trackedPlayers; // holds array of connected players, and waits the player joins team Array <edict_t *> m_trackedPlayers; // holds array of connected players, and waits the player joins team
edict_t *m_killerEntity; // killer entity for bots edict_t *m_killerEntity; // killer entity for bots
@ -1304,7 +1304,7 @@ public:
// grenades // grenades
void UpdateActiveGrenades (void); void UpdateActiveGrenades (void);
const Array <entity_t> &GetActiveGrenades (void); const Array <edict_t *> &GetActiveGrenades (void);
inline bool HasActiveGrenades (void) inline bool HasActiveGrenades (void)
{ {

View file

@ -3965,8 +3965,7 @@ public:
// //
static FORCEINLINE T *GetObject (void) static FORCEINLINE T *GetObject (void)
{ {
static T reference; return &GetReference ();
return &reference;
} }
// //

View file

@ -63,35 +63,34 @@ enum NetMsgId
NETMSG_NUM = 21 NETMSG_NUM = 21
}; };
// provides utility functions to not call original engine (less call-cost) // variable reg pair
class Engine : public Singleton <Engine> struct VarPair
{ {
public:
// variable reg pair
struct VarPair
{
VarType type; VarType type;
cvar_t reg; cvar_t reg;
bool regMissing; bool regMissing;
class ConVar *self; class ConVar *self;
}; };
// translation pair // translation pair
struct TranslatorPair struct TranslatorPair
{ {
const char *original; const char *original;
const char *translated; const char *translated;
}; };
// network message block // network message block
struct MessageBlock struct MessageBlock
{ {
int bot; int bot;
int state; int state;
int msg; int msg;
int regMsgs[NETMSG_NUM]; int regMsgs[NETMSG_NUM];
}; };
// provides utility functions to not call original engine (less call-cost)
class Engine : public Singleton <Engine>
{
private: private:
short m_drawModels[DRAW_NUM]; short m_drawModels[DRAW_NUM];
@ -186,13 +185,13 @@ public:
public: public:
// get the current time on server // get the current time on server
inline float Time (void) FORCEINLINE float Time (void)
{ {
return g_pGlobals->time; return g_pGlobals->time;
} }
// get "maxplayers" limit on server // get "maxplayers" limit on server
inline int MaxClients (void) FORCEINLINE int MaxClients (void)
{ {
return g_pGlobals->maxClients; return g_pGlobals->maxClients;
} }
@ -227,19 +226,19 @@ public:
} }
// gets edict pointer out of entity index // gets edict pointer out of entity index
inline edict_t *EntityOfIndex (const int index) FORCEINLINE edict_t *EntityOfIndex (const int index)
{ {
return static_cast <edict_t *> (m_startEntity + index); return static_cast <edict_t *> (m_startEntity + index);
}; };
// gets edict index out of it's pointer // gets edict index out of it's pointer
inline int IndexOfEntity (const edict_t *ent) FORCEINLINE int IndexOfEntity (const edict_t *ent)
{ {
return static_cast <int> (ent - m_startEntity); return static_cast <int> (ent - m_startEntity);
}; };
// verify entity isn't null // verify entity isn't null
inline bool IsNullEntity (const edict_t *ent) FORCEINLINE bool IsNullEntity (const edict_t *ent)
{ {
return !ent || !IndexOfEntity (ent); return !ent || !IndexOfEntity (ent);
} }
@ -295,7 +294,7 @@ public:
} }
// tries to set needed message id // tries to set needed message id
void TryCaptureMessage (int type, int msgId) FORCEINLINE void TryCaptureMessage (int type, int msgId)
{ {
if (type == m_msgBlock.regMsgs[msgId]) if (type == m_msgBlock.regMsgs[msgId])
SetOngoingMessageId (msgId); SetOngoingMessageId (msgId);
@ -315,11 +314,11 @@ public:
public: public:
ConVar (const char *name, const char *initval, VarType type = VT_NOSERVER, bool regMissing = false); ConVar (const char *name, const char *initval, VarType type = VT_NOSERVER, bool regMissing = false);
inline bool GetBool (void) { return m_eptr->value > 0.0f; } FORCEINLINE bool GetBool (void) { return m_eptr->value > 0.0f; }
inline int GetInt (void) { return static_cast <int> (m_eptr->value); } FORCEINLINE int GetInt (void) { return static_cast <int> (m_eptr->value); }
inline float GetFloat (void) { return m_eptr->value; } FORCEINLINE float GetFloat (void) { return m_eptr->value; }
inline const char *GetString (void) { return m_eptr->string; } FORCEINLINE const char *GetString (void) { return m_eptr->string; }
inline void SetFloat (float val) { m_eptr->value = val; } FORCEINLINE void SetFloat (float val) { m_eptr->value = val; }
inline void SetInt (int val) { SetFloat (static_cast <float> (val)); } FORCEINLINE void SetInt (int val) { SetFloat (static_cast <float> (val)); }
inline void SetString (const char *val) { g_engfuncs.pfnCvar_DirectSet (m_eptr, const_cast <char *> (val)); } FORCEINLINE void SetString (const char *val) { g_engfuncs.pfnCvar_DirectSet (m_eptr, const_cast <char *> (val)); }
}; };

View file

@ -100,8 +100,6 @@ typedef struct
int iHitgroup; // 0 == generic, non zero is specific body part int iHitgroup; // 0 == generic, non zero is specific body part
} TraceResult; } TraceResult;
typedef edict_t *entity_t;
typedef uint32 CRC32_t; typedef uint32 CRC32_t;
// Engine hands this to DLLs for functionality callbacks // Engine hands this to DLLs for functionality callbacks

View file

@ -137,18 +137,18 @@ public:
return m_ptr; return m_ptr;
} }
template <typename R> R GetFuncAddr (const char *function) inline void *GetFuncAddr (const char *function)
{ {
#ifdef PLATFORM_WIN32 #ifdef PLATFORM_WIN32
return reinterpret_cast <R> (GetProcAddress (GetHandle <HMODULE> (), function)); return reinterpret_cast <void *> (GetProcAddress (static_cast <HMODULE> (m_ptr), function));
#else #else
return reinterpret_cast <R> (dlsym (m_ptr, function)); return reinterpret_cast <void *> (dlsym (m_ptr, function));
#endif #endif
} }
template <typename R> R GetHandle (void) inline void *GetHandle (void)
{ {
return (R) m_ptr; return m_ptr;
} }
inline bool IsLoaded (void) const inline bool IsLoaded (void) const

View file

@ -57,6 +57,7 @@
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
<PlatformToolset>v120_xp</PlatformToolset> <PlatformToolset>v120_xp</PlatformToolset>
<UseOfMfc>false</UseOfMfc> <UseOfMfc>false</UseOfMfc>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
@ -131,6 +132,8 @@
<BufferSecurityCheck>false</BufferSecurityCheck> <BufferSecurityCheck>false</BufferSecurityCheck>
<FloatingPointModel>Strict</FloatingPointModel> <FloatingPointModel>Strict</FloatingPointModel>
<StringPooling>true</StringPooling> <StringPooling>true</StringPooling>
<InlineFunctionExpansion>Default</InlineFunctionExpansion>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile> </ClCompile>
<ResourceCompile> <ResourceCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
@ -178,13 +181,13 @@
</Midl> </Midl>
<ClCompile> <ClCompile>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion> <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<IntrinsicFunctions>false</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed> <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<EnableFiberSafeOptimizations>false</EnableFiberSafeOptimizations> <EnableFiberSafeOptimizations>false</EnableFiberSafeOptimizations>
<AdditionalIncludeDirectories>..\mmgr;..\include\engine;..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>..\mmgr;..\include\engine;..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>NDEBUG;WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>NDEBUG;WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ExceptionHandling>false</ExceptionHandling> <ExceptionHandling>false</ExceptionHandling>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet> <EnableEnhancedInstructionSet>AdvancedVectorExtensions</EnableEnhancedInstructionSet>
<PrecompiledHeaderFile> <PrecompiledHeaderFile>
</PrecompiledHeaderFile> </PrecompiledHeaderFile>
<PrecompiledHeaderOutputFile>.\release\inf\yapb.pch</PrecompiledHeaderOutputFile> <PrecompiledHeaderOutputFile>.\release\inf\yapb.pch</PrecompiledHeaderOutputFile>
@ -207,6 +210,7 @@
<OmitFramePointers>true</OmitFramePointers> <OmitFramePointers>true</OmitFramePointers>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<StringPooling>true</StringPooling>
</ClCompile> </ClCompile>
<ResourceCompile> <ResourceCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>

View file

@ -291,7 +291,7 @@ void Bot::AvoidGrenades (void)
m_avoidGrenade = NULL; m_avoidGrenade = NULL;
m_needAvoidGrenade = 0; m_needAvoidGrenade = 0;
} }
Array <entity_t> activeGrenades = bots.GetActiveGrenades (); Array <edict_t *> activeGrenades = bots.GetActiveGrenades ();
// find all grenades on the map // find all grenades on the map
FOR_EACH_AE (activeGrenades, it) FOR_EACH_AE (activeGrenades, it)
@ -354,7 +354,7 @@ bool Bot::IsBehindSmokeClouds (edict_t *ent)
return false; return false;
const Vector &betweenUs = (ent->v.origin - pev->origin).Normalize (); 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 // find all grenades on the map
FOR_EACH_AE (activeGrenades, it) FOR_EACH_AE (activeGrenades, it)
@ -2861,7 +2861,7 @@ void Bot::ChooseAimDirection (void)
if (m_trackingEdict == m_lastEnemy) if (m_trackingEdict == m_lastEnemy)
{ {
if (m_timeNextTracking < engine.Time ()) if (m_timeNextTracking < engine.Time ())
changePredictedEnemy = IsAlive (m_lastEnemy); changePredictedEnemy = false;
} }
if (changePredictedEnemy) if (changePredictedEnemy)
@ -2869,7 +2869,7 @@ void Bot::ChooseAimDirection (void)
m_lookAt = waypoints.GetPath (GetAimingWaypoint (m_lastEnemyOrigin))->origin; m_lookAt = waypoints.GetPath (GetAimingWaypoint (m_lastEnemyOrigin))->origin;
m_camp = m_lookAt; m_camp = m_lookAt;
m_timeNextTracking = engine.Time () + 2.0f; m_timeNextTracking = engine.Time () + 1.25f;
m_trackingEdict = m_lastEnemy; m_trackingEdict = m_lastEnemy;
} }
else else
@ -3005,7 +3005,7 @@ void Bot::ThinkFrame (void)
CheckMessageQueue (); // check for pending messages CheckMessageQueue (); // check for pending messages
// remove voice icon // 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 SwitchChatterIcon (false); // hide icon
if (botMovement) if (botMovement)
@ -6048,6 +6048,9 @@ bool Bot::IsBombDefusing (const Vector &bombOrigin)
{ {
// this function finds if somebody currently defusing the bomb. // this function finds if somebody currently defusing the bomb.
if (!g_bombPlanted)
return false;
bool defusingInProgress = false; bool defusingInProgress = false;
for (int i = 0; i < engine.MaxClients (); i++) 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++) for (int i = 0; i < NETMSG_NUM; i++)
m_msgBlock.regMsgs[i] = NETMSG_UNDEFINED; 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) 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_SIMPLE] = PRECACHE_MODEL (ENGINE_STR ("sprites/laserbeam.spr"));
m_drawModels[DRAW_ARROW] = PRECACHE_MODEL (ENGINE_STR ("sprites/arrow1.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_localEntity = NULL;
m_startEntity = startEntity; m_startEntity = startEntity;
} }
@ -254,7 +257,9 @@ float Engine::GetWaveLength (const char *fileName)
bool Engine::IsDedicatedServer (void) bool Engine::IsDedicatedServer (void)
{ {
// return true if server is dedicated server, false otherwise // 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) const char *Engine::GetModName (void)
@ -980,8 +985,6 @@ void Engine::ProcessMesageCapture (void *ptr)
} }
else if (!g_bombPlanted && FStrEq (strVal, "#Bomb_Planted")) else if (!g_bombPlanted && FStrEq (strVal, "#Bomb_Planted"))
{ {
waypoints.SetBombPosition ();
g_bombPlanted = g_bombSayString = true; g_bombPlanted = g_bombSayString = true;
g_timeBombPlanted = Time (); g_timeBombPlanted = Time ();
@ -998,6 +1001,7 @@ void Engine::ProcessMesageCapture (void *ptr)
bot->ChatterMessage (Chatter_WhereIsTheBomb); bot->ChatterMessage (Chatter_WhereIsTheBomb);
} }
} }
waypoints.SetBombPosition ();
} }
else if (bot != NULL && FStrEq (strVal, "#Switch_To_BurstFire")) else if (bot != NULL && FStrEq (strVal, "#Switch_To_BurstFire"))
bot->m_weaponBurstMode = BM_ON; bot->m_weaponBurstMode = BM_ON;
@ -1017,19 +1021,19 @@ void Engine::ProcessMesageCapture (void *ptr)
if (playerIndex >= 0 && playerIndex <= MaxClients ()) if (playerIndex >= 0 && playerIndex <= MaxClients ())
{ {
#ifndef XASH_CSDM #ifndef XASH_CSDM
Client &cl = g_clients[playerIndex - 1]; Client &client = g_clients[playerIndex - 1];
if (intVal == 1) if (intVal == 1)
cl.realTeam = TERRORIST; client.team2 = TERRORIST;
else if (intVal == 2) else if (intVal == 2)
cl.realTeam = CT; client.team2 = CT;
else else
cl.realTeam = SPECTATOR; client.team2 = SPECTATOR;
if (yb_csdm_mode.GetInt () == 2) if (yb_csdm_mode.GetInt () == 2)
cl.team = playerIndex; client.team = playerIndex;
else else
cl.team = cl.realTeam; client.team = client.team2;
#endif #endif
} }
break; break;

View file

@ -850,7 +850,7 @@ void InitConfig (void)
enum Lang { Lang_Original, Lang_Translate } langState = static_cast <Lang> (2); enum Lang { Lang_Original, Lang_Translate } langState = static_cast <Lang> (2);
char buffer[1024]; char buffer[1024];
Engine::TranslatorPair temp = {"", ""}; TranslatorPair temp = {"", ""};
while (fp.GetBuffer (line, 255)) while (fp.GetBuffer (line, 255))
{ {
@ -2217,21 +2217,23 @@ void StartFrame (void)
// code below is executed only on dedicated server // 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 (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 ())) if (IsNullString (yb_password_key.GetString ()) && IsNullString (yb_password.GetString ()))
g_clients[i].flags &= ~CF_ADMIN; client.flags &= ~CF_ADMIN;
else if (strcmp (yb_password.GetString (), INFOKEY_VALUE (GET_INFOKEYBUFFER (g_clients[i].ent), const_cast <char *> (yb_password_key.GetString ())))) 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)); 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)); 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 // case it's a bot asking for a client command, we handle it like we do for bot commands
va_list ap; va_list ap;
char buffer[1024]; char buffer[MAX_PRINT_BUFFER];
va_start (ap, format); va_start (ap, format);
_vsnprintf (buffer, sizeof (buffer), format, ap); _vsnprintf (buffer, SIZEOF_CHAR (buffer), format, ap);
va_end (ap); va_end (ap);
// is the target entity an official bot, or a third party bot ? // 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) if (g_isMetamod)
RETURN_META (MRES_SUPERCEDE); // prevent bots to be forced to issue client commands RETURN_META (MRES_SUPERCEDE); // prevent bots to be forced to issue client commands
@ -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 ()); AddLogEntry (true, LL_FATAL | LL_IGNORE, "Mod that you has started, not supported by this bot (gamedir: %s)", engine.GetModName ());
#endif #endif
g_funcPointers = g_gameLib->GetFuncAddr <FuncPointers_t> ("GiveFnptrsToDll"); g_funcPointers = static_cast <FuncPointers_t> (g_gameLib->GetFuncAddr ("GiveFnptrsToDll"));
g_entityAPI = g_gameLib->GetFuncAddr <EntityAPI_t> ("GetEntityAPI"); g_entityAPI = static_cast <EntityAPI_t> (g_gameLib->GetFuncAddr ("GetEntityAPI"));
g_getNewEntityAPI = g_gameLib->GetFuncAddr <NewEntityAPI_t> ("GetNewDLLFunctions"); g_getNewEntityAPI = static_cast <NewEntityAPI_t> (g_gameLib->GetFuncAddr ("GetNewDLLFunctions"));
g_serverBlendingAPI = g_gameLib->GetFuncAddr <BlendAPI_t> ("Server_GetBlendingInterface"); g_serverBlendingAPI = static_cast <BlendAPI_t> (g_gameLib->GetFuncAddr ("Server_GetBlendingInterface"));
if (!g_funcPointers || !g_entityAPI) if (!g_funcPointers || !g_entityAPI)
TerminateOnMalloc (); TerminateOnMalloc ();
@ -3119,29 +3121,27 @@ DLL_ENTRYPOINT
if (DLL_DETACHING) if (DLL_DETACHING)
{ {
FreeLibraryMemory (); // free everything that's freeable FreeLibraryMemory (); // free everything that's freeable
delete g_gameLib; // if dynamic link library of mod is load, free it delete g_gameLib; // if dynamic link library of mod is load, free it
} }
DLL_RETENTRY; // the return data type is OS specific too 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)
//if (addr == NULL || (g_gameFlags & GAME_OFFICIAL_CSBOT)) *addr = static_cast <EntityPtr_t> (g_gameLib->GetFuncAddr (name));
addr = g_gameLib->GetFuncAddr <EntityPtr_t > (name);
if (addr == NULL) if (*addr == NULL)
return; return;
addr (pev); (*addr) (pev);
} }
#define LINK_ENTITY(entityName) \ #define LINK_ENTITY(entityName) \
SHARED_LIBRARAY_EXPORT void entityName (entvars_t *pev) \ SHARED_LIBRARAY_EXPORT void entityName (entvars_t *pev) \
{ \ { \
static EntityPtr_t addr = NULL; \ static EntityPtr_t addr; \
LinkEntity_Helper (addr, #entityName, pev); \ LinkEntity_Helper (&addr, #entityName, pev); \
} \ } \
// entities in counter-strike... // 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; 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 // the array associated with the entity
if (engine.IsNullEntity (ent) || IsNullString (sample)) if (engine.IsNullEntity (ent) || IsNullString (sample))
return; // reliability check return;
const Vector &origin = engine.GetAbsOrigin (ent); const Vector &origin = engine.GetAbsOrigin (ent);
int index = engine.IndexOfEntity (ent) - 1; 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)) if (!(g_clients[i].flags & CF_USED) || !(g_clients[i].flags & CF_ALIVE))
continue; continue;
float distance = (g_clients[i].ent->v.origin - origin).GetLengthSquared (); float distance = (g_clients[i].origin - origin).GetLength ();
// now find nearest player // now find nearest player
if (distance < nearestDistance) 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) if (strncmp ("player/bhit_flesh", sample, 17) == 0 || strncmp ("player/headshot", sample, 15) == 0)
{ {
// hit/fall sound? // hit/fall sound?
client->hearingDistance = 768.0f * volume; client.hearingDistance = 768.0f * volume;
client->timeSoundLasting = engine.Time () + 0.5f; client.timeSoundLasting = engine.Time () + 0.5f;
client->soundPosition = origin; client.soundPosition = origin;
} }
else if (strncmp ("items/gunpickup", sample, 15) == 0) else if (strncmp ("items/gunpickup", sample, 15) == 0)
{ {
// weapon pickup? // weapon pickup?
client->hearingDistance = 768.0f * volume; client.hearingDistance = 768.0f * volume;
client->timeSoundLasting = engine.Time () + 0.5f; client.timeSoundLasting = engine.Time () + 0.5f;
client->soundPosition = origin; client.soundPosition = origin;
} }
else if (strncmp ("weapons/zoom", sample, 12) == 0) else if (strncmp ("weapons/zoom", sample, 12) == 0)
{ {
// sniper zooming? // sniper zooming?
client->hearingDistance = 512.0f * volume; client.hearingDistance = 512.0f * volume;
client->timeSoundLasting = engine.Time () + 0.1f; client.timeSoundLasting = engine.Time () + 0.1f;
client->soundPosition = origin; client.soundPosition = origin;
} }
else if (strncmp ("items/9mmclip", sample, 13) == 0) else if (strncmp ("items/9mmclip", sample, 13) == 0)
{ {
// ammo pickup? // ammo pickup?
client->hearingDistance = 512.0f * volume; client.hearingDistance = 512.0f * volume;
client->timeSoundLasting = engine.Time () + 0.1f; client.timeSoundLasting = engine.Time () + 0.1f;
client->soundPosition = origin; client.soundPosition = origin;
} }
else if (strncmp ("hostage/hos", sample, 11) == 0) else if (strncmp ("hostage/hos", sample, 11) == 0)
{ {
// CT used hostage? // CT used hostage?
client->hearingDistance = 1024.0f * volume; client.hearingDistance = 1024.0f * volume;
client->timeSoundLasting = engine.Time () + 5.0f; client.timeSoundLasting = engine.Time () + 5.0f;
client->soundPosition = origin; client.soundPosition = origin;
} }
else if (strncmp ("debris/bustmetal", sample, 16) == 0 || strncmp ("debris/bustglass", sample, 16) == 0) else if (strncmp ("debris/bustmetal", sample, 16) == 0 || strncmp ("debris/bustglass", sample, 16) == 0)
{ {
// broke something? // broke something?
client->hearingDistance = 1024.0f * volume; client.hearingDistance = 1024.0f * volume;
client->timeSoundLasting = engine.Time () + 2.0f; client.timeSoundLasting = engine.Time () + 2.0f;
client->soundPosition = origin; client.soundPosition = origin;
} }
else if (strncmp ("doors/doormove", sample, 14) == 0) else if (strncmp ("doors/doormove", sample, 14) == 0)
{ {
// someone opened a door // someone opened a door
client->hearingDistance = 1024.0f * volume; client.hearingDistance = 1024.0f * volume;
client->timeSoundLasting = engine.Time () + 3.0f; client.timeSoundLasting = engine.Time () + 3.0f;
client->soundPosition = origin; client.soundPosition = origin;
} }
} }
@ -800,29 +805,29 @@ void SoundSimulateUpdate (int playerIndex)
if (playerIndex < 0 || playerIndex >= engine.MaxClients ()) if (playerIndex < 0 || playerIndex >= engine.MaxClients ())
return; // reliability check return; // reliability check
Client *client = &g_clients[playerIndex]; Client &client = g_clients[playerIndex];
float hearDistance = 0.0f; float hearDistance = 0.0f;
float timeSound = 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; hearDistance = 2048.0f;
timeSound = engine.Time () + 0.3f; 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; hearDistance = 512.0f;
timeSound = engine.Time () + 0.5f; 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; hearDistance = 512.0f;
timeSound = engine.Time () + 0.5f; 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; hearDistance = 1024.0f;
timeSound = engine.Time () + 0.3f; timeSound = engine.Time () + 0.3f;
@ -835,7 +840,7 @@ void SoundSimulateUpdate (int playerIndex)
if (mp_footsteps.GetBool ()) if (mp_footsteps.GetBool ())
{ {
// moves fast enough? // 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; timeSound = engine.Time () + 0.3f;
} }
} }
@ -844,22 +849,22 @@ void SoundSimulateUpdate (int playerIndex)
return; // didn't issue sound? return; // didn't issue sound?
// some sound already associated // 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 // override it with new
client->hearingDistance = hearDistance; client.hearingDistance = hearDistance;
client->timeSoundLasting = timeSound; client.timeSoundLasting = timeSound;
client->soundPosition = client->ent->v.origin; client.soundPosition = client.ent->v.origin;
} }
} }
else else
{ {
// just remember it // just remember it
client->hearingDistance = hearDistance; client.hearingDistance = hearDistance;
client->timeSoundLasting = timeSound; client.timeSoundLasting = timeSound;
client->soundPosition = client->ent->v.origin; client.soundPosition = client.ent->v.origin;
} }
} }

View file

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