diff --git a/ext/crlib b/ext/crlib index b85bbe1..313311c 160000 --- a/ext/crlib +++ b/ext/crlib @@ -1 +1 @@ -Subproject commit b85bbe10b45bcadbcb325664fac5c511a6b868e3 +Subproject commit 313311c8612ce2a70c616f7187358c397d32765a diff --git a/inc/support.h b/inc/support.h index 399dda1..e3eded0 100644 --- a/inc/support.h +++ b/inc/support.h @@ -20,7 +20,7 @@ private: SmallArray > m_tags {}; HashMap m_weaponAlias {}; - Detour m_sendToDetour { "ws2_32.dll", "sendto", sendto }; + Detour m_sendToDetour { }; public: BotSupport (); diff --git a/inc/yapb.h b/inc/yapb.h index 0a1e112..6414fa2 100644 --- a/inc/yapb.h +++ b/inc/yapb.h @@ -687,6 +687,7 @@ private: int m_lastPredictIndex { kInvalidNodeIndex }; // last predicted path index int m_lastPredictLength {}; // last predicted path length + int m_pickupType {}; // type of entity which needs to be used/picked up float m_headedTime {}; float m_prevTime {}; // time previously checked movement speed @@ -766,7 +767,6 @@ private: bool m_defuseNotified {}; // bot is notified about bomb defusion bool m_jumpSequence {}; // next path link will be jump link - Pickup m_pickupType {}; // type of entity which needs to be used/picked up PathWalk m_pathWalk {}; // pointer to current node from path Dodge m_combatStrafeDir {}; // direction to strafe Fight m_fightStyle {}; // combat style to use diff --git a/src/botlib.cpp b/src/botlib.cpp index a648909..4bc7168 100644 --- a/src/botlib.cpp +++ b/src/botlib.cpp @@ -316,7 +316,7 @@ void Bot::updatePickups () { } edict_t *pickupItem = nullptr; - Pickup pickupType = Pickup::None; + int32_t pickupType = Pickup::None; Vector pickupPos = nullptr; m_pickupItem = nullptr; diff --git a/src/support.cpp b/src/support.cpp index 0ad3a01..cf662b2 100644 --- a/src/support.cpp +++ b/src/support.cpp @@ -477,6 +477,23 @@ void BotSupport::installSendTo () { if (!game.isDedicated ()) { return; } + using SendToHandle = decltype (sendto); + SendToHandle *sendToAddress = sendto; + + // linux workaround with sendto + if (!plat.win && !plat.arm) { + SharedLibrary engineLib {}; + engineLib.locate (reinterpret_cast (engfuncs.pfnPrecacheModel)); + + if (engineLib) { + auto address = engineLib.resolve ("sendto"); + + if (address != nullptr) { + sendToAddress = address; + } + } + } + m_sendToDetour.initialize ("ws2_32.dll", "sendto", sendToAddress); // enable only on modern games if (game.is (GameFlags::Modern) && (plat.nix || plat.win) && !plat.arm && !m_sendToDetour.detoured ()) { @@ -518,12 +535,12 @@ int32_t BotSupport::sendTo (int socket, const void *message, size_t length, int }; auto packet = reinterpret_cast (message); + constexpr int32_t packetLength = 5; // player replies response - if (length > 5 && packet[0] == 0xff && packet[1] == 0xff && packet[2] == 0xff && packet[3] == 0xff) { - + if (length > packetLength && memcmp (packet, "\xff\xff\xff\xff", packetLength - 1) == 0) { if (packet[4] == 'D') { - QueryBuffer buffer (packet, length, 5); + QueryBuffer buffer { packet, length, packetLength }; auto count = buffer.read (); for (uint8_t i = 0; i < count; ++i) { @@ -537,7 +554,7 @@ int32_t BotSupport::sendTo (int socket, const void *message, size_t length, int return send (buffer.data ()); } else if (packet[4] == 'I') { - QueryBuffer buffer (packet, length, 5); + QueryBuffer buffer { packet, length, packetLength }; buffer.skip (); // protocol // skip server name, folder, map game @@ -553,7 +570,7 @@ int32_t BotSupport::sendTo (int socket, const void *message, size_t length, int return send (buffer.data ()); } else if (packet[4] == 'm') { - QueryBuffer buffer (packet, length, 5); + QueryBuffer buffer { packet, length, packetLength }; buffer.shiftToEnd (); // shift to the end of buffer buffer.write (0); // zero out bot count