From 37a352ac5465cb4f4068b617a18471447ae10837 Mon Sep 17 00:00:00 2001 From: jeefo Date: Wed, 14 Sep 2016 15:40:42 +0300 Subject: [PATCH] re-added support for hl-1.1.0.4 & cs beta 6.6 minimum. --- include/corelib.h | 12 ++++++++++++ include/engine.h | 8 +++++--- source/basecode.cpp | 9 ++------- source/engine.cpp | 20 ++++++++++++++++---- source/interface.cpp | 26 ++++++++++++++------------ source/manager.cpp | 6 +++++- source/support.cpp | 2 +- 7 files changed, 55 insertions(+), 28 deletions(-) diff --git a/include/corelib.h b/include/corelib.h index fccbae6..4cc1d59 100644 --- a/include/corelib.h +++ b/include/corelib.h @@ -66,6 +66,18 @@ static inline char *A_strdup (const char *str) return strcpy (new char[strlen (str) + 1], str); } +// From metamod-p +static inline bool A_IsValidCodePointer (const void *ptr) +{ +#ifdef _WIN32 + if (IsBadCodePtr (reinterpret_cast (ptr))) + return false; +#endif + + // do not check on linux + return true; +} + // // Title: Utility Classes Header // diff --git a/include/engine.h b/include/engine.h index 7e7ee6f..e8695c2 100644 --- a/include/engine.h +++ b/include/engine.h @@ -68,8 +68,10 @@ struct VarPair { VarType type; cvar_t reg; - bool regMissing; class ConVar *self; + + bool regMissing; + const char *regVal; }; // translation pair @@ -167,7 +169,7 @@ public: void IssueBotCommand (edict_t *ent, const char *fmt, ...); // adds cvar to registration stack - void PushVariableToStack (const char *variable, const char *value, VarType varType, bool regMissing, ConVar *self); + void PushVariableToStack (const char *variable, const char *value, VarType varType, bool regMissing, const char *regVal, ConVar *self); // sends local registration stack for engine registration void PushRegisteredConVarsToEngine (bool gameVars = false); @@ -312,7 +314,7 @@ public: cvar_t *m_eptr; 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, const char *regVal = nullptr); FORCEINLINE bool GetBool (void) { return m_eptr->value > 0.0f; } FORCEINLINE int GetInt (void) { return static_cast (m_eptr->value); } diff --git a/source/basecode.cpp b/source/basecode.cpp index 5c6bd08..d65081f 100644 --- a/source/basecode.cpp +++ b/source/basecode.cpp @@ -31,7 +31,7 @@ ConVar yb_best_weapon_picker_type ("yb_best_weapon_picker_type", "2"); // game console variables ConVar mp_c4timer ("mp_c4timer", nullptr, VT_NOREGISTER); -ConVar mp_buytime ("mp_buytime", nullptr, VT_NOREGISTER); +ConVar mp_buytime ("mp_buytime", nullptr, VT_NOREGISTER, true, "1"); ConVar mp_footsteps ("mp_footsteps", nullptr, VT_NOREGISTER); ConVar sv_gravity ("sv_gravity", nullptr, VT_NOREGISTER); @@ -5995,13 +5995,8 @@ void Bot::EquipInBuyzone (int buyState) { // this function is gets called when bot enters a buyzone, to allow bot to buy some stuff - bool checkBuyTime = false; - - if (mp_buytime.m_eptr != nullptr) - checkBuyTime = (g_timeRoundStart + Random.Float (10.0f, 20.0f) + mp_buytime.GetFloat () < engine.Time ()); - // if bot is in buy zone, try to buy ammo for this weapon... - if (m_seeEnemyTime + 5.0f < engine.Time () && m_lastEquipTime + 15.0f < engine.Time () && m_inBuyZone && checkBuyTime && !g_bombPlanted && m_moneyAmount > g_botBuyEconomyTable[0]) + if (m_seeEnemyTime + 5.0f < engine.Time () && m_lastEquipTime + 15.0f < engine.Time () && m_inBuyZone && (g_timeRoundStart + Random.Float (10.0f, 20.0f) + mp_buytime.GetFloat () < engine.Time ()) && !g_bombPlanted && m_moneyAmount > g_botBuyEconomyTable[0]) { m_buyingFinished = false; m_buyState = buyState; diff --git a/source/engine.cpp b/source/engine.cpp index b0bf264..124de7f 100644 --- a/source/engine.cpp +++ b/source/engine.cpp @@ -321,6 +321,10 @@ void Engine::RegisterCmd (const char * command, void func (void)) // that for every "command_name" server command it receives, it should call the function // pointed to by "function" in order to handle it. + // check for hl pre 1.1.0.4, as it's doesn't have pfnAddServerCommand + if (!A_IsValidCodePointer (g_engfuncs.pfnAddServerCommand)) + AddLogEntry (true, LL_FATAL, "YaPB's minimum HL engine version is 1.1.0.4 and minimum Counter-Strike Beta 6.6. Please update your engine version."); + g_engfuncs.pfnAddServerCommand (const_cast (command), func); } @@ -479,7 +483,7 @@ void Engine::IssueCmd (const char *fmt, ...) g_engfuncs.pfnServerCommand (string); } -void Engine::PushVariableToStack (const char *variable, const char *value, VarType varType, bool regMissing, ConVar *self) +void Engine::PushVariableToStack (const char *variable, const char *value, VarType varType, bool regMissing, const char *regVal, ConVar *self) { // this function adds globally defined variable to registration stack @@ -489,6 +493,7 @@ void Engine::PushVariableToStack (const char *variable, const char *value, VarTy pair.reg.name = const_cast (variable); pair.reg.string = const_cast (value); pair.regMissing = regMissing; + pair.regVal = regVal; int engineFlags = FCVAR_EXTDLL; @@ -530,10 +535,17 @@ void Engine::PushRegisteredConVarsToEngine (bool gameVars) if (ptr->regMissing && ptr->self->m_eptr == nullptr) { + if (ptr->reg.string == nullptr && ptr->regVal != nullptr) + { + ptr->reg.string = const_cast (ptr->regVal); + ptr->reg.flags |= FCVAR_SERVER; + } g_engfuncs.pfnCVarRegister (&ptr->reg); ptr->self->m_eptr = g_engfuncs.pfnCVarGetPointer (ptr->reg.name); } - InternalAssert (ptr->self->m_eptr != nullptr); // ensure game var exists + + if (!ptr->self->m_eptr) + engine.Printf ("Got nullptr on cvar %s!", ptr->reg.name); } } } @@ -1056,7 +1068,7 @@ void Engine::ProcessMessageCapture (void *ptr) m_msgBlock.state++; // and finally update network message state } -ConVar::ConVar (const char *name, const char *initval, VarType type, bool regMissing) : m_eptr (nullptr) +ConVar::ConVar (const char *name, const char *initval, VarType type, bool regMissing, const char *regVal) : m_eptr (nullptr) { - engine.PushVariableToStack (name, initval, type, regMissing, this); + engine.PushVariableToStack (name, initval, type, regMissing, regVal, this); } diff --git a/source/interface.cpp b/source/interface.cpp index 93d207d..5ca1bd4 100644 --- a/source/interface.cpp +++ b/source/interface.cpp @@ -16,7 +16,7 @@ ConVar yb_password_key ("yb_password_key", "_ybpw"); ConVar yb_language ("yb_language", "en"); ConVar yb_version ("yb_version", PRODUCT_VERSION, VT_READONLY); -ConVar mp_startmoney ("mp_startmoney", nullptr, VT_NOREGISTER); +ConVar mp_startmoney ("mp_startmoney", nullptr, VT_NOREGISTER, true, "800"); int BotCommandHandler (edict_t *ent, const char *arg0, const char *arg1, const char *arg2, const char *arg3, const char *arg4, const char *arg5, const char *self) { @@ -2370,8 +2370,10 @@ void pfnClientCommand (edict_t *ent, char const *format, ...) va_end (ap); // is the target entity an official bot, or a third party bot ? - if (ent->v.flags & FL_FAKECLIENT) + if (IsValidBot (ent)) { + engine.IssueBotCommand (ent, buffer); + if (g_gameFlags & GAME_METAMOD) RETURN_META (MRES_SUPERCEDE); // prevent bots to be forced to issue client commands @@ -2463,7 +2465,7 @@ void pfnMessageBegin (int msgDest, int msgType, const float *origin, edict_t *ed if (g_gameFlags & GAME_METAMOD) RETURN_META (MRES_IGNORED); - MESSAGE_BEGIN (msgDest, msgType, origin, ed); + g_engfuncs.pfnMessageBegin (msgDest, msgType, origin, ed); } void pfnMessageEnd (void) @@ -2473,7 +2475,7 @@ void pfnMessageEnd (void) if (g_gameFlags & GAME_METAMOD) RETURN_META (MRES_IGNORED); - MESSAGE_END (); + g_engfuncs.pfnMessageEnd (); // send latency fix bots.SendDeathMsgFix (); @@ -2495,7 +2497,7 @@ void pfnWriteByte (int value) if (g_gameFlags & GAME_METAMOD) RETURN_META (MRES_IGNORED); - WRITE_BYTE (value); + g_engfuncs.pfnWriteByte (value); } void pfnWriteChar (int value) @@ -2506,7 +2508,7 @@ void pfnWriteChar (int value) if (g_gameFlags & GAME_METAMOD) RETURN_META (MRES_IGNORED); - WRITE_CHAR (value); + g_engfuncs.pfnWriteChar (value); } void pfnWriteShort (int value) @@ -2517,7 +2519,7 @@ void pfnWriteShort (int value) if (g_gameFlags & GAME_METAMOD) RETURN_META (MRES_IGNORED); - WRITE_SHORT (value); + g_engfuncs.pfnWriteShort (value); } void pfnWriteLong (int value) @@ -2528,7 +2530,7 @@ void pfnWriteLong (int value) if (g_gameFlags & GAME_METAMOD) RETURN_META (MRES_IGNORED); - WRITE_LONG (value); + g_engfuncs.pfnWriteLong (value); } void pfnWriteAngle (float value) @@ -2539,7 +2541,7 @@ void pfnWriteAngle (float value) if (g_gameFlags & GAME_METAMOD) RETURN_META (MRES_IGNORED); - WRITE_ANGLE (value); + g_engfuncs.pfnWriteAngle (value); } void pfnWriteCoord (float value) @@ -2550,7 +2552,7 @@ void pfnWriteCoord (float value) if (g_gameFlags & GAME_METAMOD) RETURN_META (MRES_IGNORED); - WRITE_COORD (value); + g_engfuncs.pfnWriteCoord (value); } void pfnWriteString (const char *sz) @@ -2561,7 +2563,7 @@ void pfnWriteString (const char *sz) if (g_gameFlags & GAME_METAMOD) RETURN_META (MRES_IGNORED); - WRITE_STRING (sz); + g_engfuncs.pfnWriteString (sz); } void pfnWriteEntity (int value) @@ -2572,7 +2574,7 @@ void pfnWriteEntity (int value) if (g_gameFlags & GAME_METAMOD) RETURN_META (MRES_IGNORED); - WRITE_ENTITY (value); + g_engfuncs.pfnWriteEntity (value); } int pfnCmd_Argc (void) diff --git a/source/manager.cpp b/source/manager.cpp index 0228bb9..b52ae87 100644 --- a/source/manager.cpp +++ b/source/manager.cpp @@ -1283,6 +1283,10 @@ void Bot::StartGame (void) return; #endif + // cs prior beta 7.0 uses hud-based motd, so press fire once + if (g_gameFlags & GAME_LEGACY) + pev->button |= IN_ATTACK; + // handle counter-strike stuff here... if (m_startAction == GSM_TEAM_SELECT) { @@ -1321,7 +1325,7 @@ void Bot::StartGame (void) // bot has now joined the game (doesn't need to be started) m_notStarted = false; - + // check for greeting other players, since we connected if (Random.Int (0, 100) < 20) ChatMessage (CHAT_WELCOME); diff --git a/source/support.cpp b/source/support.cpp index 9939e21..9ab57ea 100644 --- a/source/support.cpp +++ b/source/support.cpp @@ -12,7 +12,7 @@ ConVar yb_display_menu_text ("yb_display_menu_text", "1"); ConVar mp_roundtime ("mp_roundtime", nullptr, VT_NOREGISTER); -ConVar mp_freezetime ("mp_freezetime", nullptr, VT_NOREGISTER, true); +ConVar mp_freezetime ("mp_freezetime", nullptr, VT_NOREGISTER, true, "0"); uint16 FixedUnsigned16 (float value, float scale) {