From b606b78cda674f029bc366106980249f396f232f Mon Sep 17 00:00:00 2001 From: jeefo Date: Wed, 3 Aug 2022 23:59:57 +0300 Subject: [PATCH] improve: use ScoreAttrib message to detect if bot is a VIP or not. (#356) This should resolve problems with bot behavior, when plugins changes VIP player model to something else. --- inc/message.h | 7 ++++++- src/botlib.cpp | 4 ---- src/manager.cpp | 2 -- src/message.cpp | 32 ++++++++++++++++++++++++++++---- 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/inc/message.h b/inc/message.h index 366b161..d0df5ad 100644 --- a/inc/message.h +++ b/inc/message.h @@ -31,7 +31,8 @@ CR_DECLARE_SCOPED_ENUM (NetMsg, FlashBat = 20, Fashlight = 21, ItemStatus = 22, - ScoreInfo = 23 + ScoreInfo = 23, + ScoreAttrib = 24 ) // vgui menus (since latest steam updates is obsolete, but left for old cs) @@ -118,6 +119,10 @@ private: void netMsgNVGToggle (); void netMsgFlashBat (); void netMsgScoreInfo (); + void netMsgScoreAttrib (); + +private: + Bot *pickBot (int32 index); public: MessageDispatcher (); diff --git a/src/botlib.cpp b/src/botlib.cpp index 9e537c2..a6150e9 100644 --- a/src/botlib.cpp +++ b/src/botlib.cpp @@ -3001,10 +3001,6 @@ void Bot::update () { m_team = game.getTeam (ent ()); m_healthValue = cr::clamp (pev->health, 0.0f, 100.0f); - if (game.mapIs (MapFlags::Assassination) && !m_isVIP) { - m_isVIP = util.isPlayerVIP (ent ()); - } - if (m_team == Team::Terrorist && game.mapIs (MapFlags::Demolition)) { m_hasC4 = !!(pev->weapons & cr::bit (Weapon::C4)); diff --git a/src/manager.cpp b/src/manager.cpp index 20c5977..2de2541 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -1235,7 +1235,6 @@ void Bot::newRound () { m_navTimeset = game.time (); m_team = game.getTeam (ent ()); - m_isVIP = false; resetPathSearchType (); @@ -1243,7 +1242,6 @@ void Bot::newRound () { m_states = 0; clearTasks (); - m_isVIP = false; m_isLeader = false; m_hasProgressBar = false; m_canChooseAimDirection = true; diff --git a/src/message.cpp b/src/message.cpp index a3af3d0..b283e74 100644 --- a/src/message.cpp +++ b/src/message.cpp @@ -331,10 +331,7 @@ void MessageDispatcher::netMsgScoreInfo () { if (m_args.length () < min) { return; } - auto &client = util.getClient (m_args[index].long_ - 1); - - // get the bot in this msg - auto bot = bots[client.ent]; + auto bot = pickBot (index); // if we're have bot, set the kd ratio if (bot != nullptr) { @@ -342,6 +339,25 @@ void MessageDispatcher::netMsgScoreInfo () { } } +void MessageDispatcher::netMsgScoreAttrib () { + // this message updates the scoreboard attribute for the specified player + + enum args { index = 0, flags = 1, min = 2 }; + + // check the minimum states + if (m_args.length () < min) { + return; + } + auto bot = pickBot (index); + + // if we're have bot, set the vip state + if (bot != nullptr) { + constexpr int32 kPlayerIsVIP = cr::bit (2); + + bot->m_isVIP = !!(m_args[flags].long_ & kPlayerIsVIP); + } +} + void MessageDispatcher::netMsgBarTime () { enum args { enabled = 0, min = 1 }; @@ -426,6 +442,7 @@ MessageDispatcher::MessageDispatcher () { addWanted ("NVGToggle", NetMsg::NVGToggle, &MessageDispatcher::netMsgNVGToggle); addWanted ("FlashBat", NetMsg::FlashBat, &MessageDispatcher::netMsgFlashBat); addWanted ("ScoreInfo", NetMsg::ScoreInfo, &MessageDispatcher::netMsgScoreInfo); + addWanted ("ScoreAttrib", NetMsg::ScoreAttrib, &MessageDispatcher::netMsgScoreAttrib); // we're need next messages IDs but we're won't handle them, so they will be removed from wanted list as soon as they get engine IDs addWanted ("BotVoice", NetMsg::BotVoice, nullptr); @@ -542,3 +559,10 @@ void MessageDispatcher::ensureMessages () { int32 MessageDispatcher::id (NetMsg msg) { return m_maps[msg]; } + +Bot *MessageDispatcher::pickBot (int32 index) { + const auto &client = util.getClient (m_args[index].long_ - 1); + + // get the bot in this msg + return bots[client.ent]; +}