diff --git a/ext/hlsdk/eiface.h b/ext/hlsdk/eiface.h index b1ff52a..abe08c4 100644 --- a/ext/hlsdk/eiface.h +++ b/ext/hlsdk/eiface.h @@ -238,9 +238,7 @@ typedef struct enginefuncs_s { void (*pfnQueryClientCVarValue) (const edict_t *player, const char *cvarName); void (*pfnQueryClientCVarValue2) (const edict_t *player, const char *cvarName, int requestID); int (*pfnCheckParm) (const char *pchCmdLineToken, char **ppnext); -#ifdef EIFACE_2019 edict_t *(*pfnPEntityOfEntIndexAllEntities) (int iEntIndex); -#endif } enginefuncs_t; // Passed to pfnKeyValue diff --git a/inc/yapb.h b/inc/yapb.h index 6a8a994..8c77a8c 100644 --- a/inc/yapb.h +++ b/inc/yapb.h @@ -897,7 +897,7 @@ private: void pickupItem_ (); void shootBreakable_ (); - edict_t *lookupButton (const char *targetName); + edict_t *lookupButton (const char *target); edict_t *lookupBreakable (); edict_t *correctGrenadeVelocity (const char *model); diff --git a/ldscript.lds b/ldscript.lds new file mode 100644 index 0000000..356a1f5 --- /dev/null +++ b/ldscript.lds @@ -0,0 +1,10 @@ +YAPB_ABI_1.0 { + global: + Meta_*; + GiveFnptrsToDll; + GetBotAPI; + GetEntityAPI; + GetNewDLLFunctions; + local: + *; +}; diff --git a/meson.build b/meson.build index e56f69f..b1a19c3 100644 --- a/meson.build +++ b/meson.build @@ -102,7 +102,9 @@ if clang or gcc endif ldflags += [ - '-flto' + '-flto', + '-Wl,--version-script=../ldscript.lds', + '-Wl,--gc-sections' ] endif endif diff --git a/src/config.cpp b/src/config.cpp index 6194e10..4978c0e 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -457,7 +457,7 @@ void BotConfig::loadLanguageConfig () { setupMemoryFiles (); if (game.is (GameFlags::Legacy)) { - logger.message ("Bots multilingual system disabled, due to your Counter-Strike version!"); + logger.message ("Bots multilingual system disabled."); return; // dedicated server will use only english translation } String line; diff --git a/src/graph.cpp b/src/graph.cpp index 322a581..d2b8bc8 100644 --- a/src/graph.cpp +++ b/src/graph.cpp @@ -1612,6 +1612,9 @@ template bool BotGraph::loadStorage (StringRef ext, StringRef name, bool isGraph = !!(options & StorageOption::Graph); MemFile file (strings.format ("%s%s/%s", getDataDirectory (true), isGraph ? "graph" : "train", filename)); // open the file + data.clear (); + data.shrink (); + // resize data to fit the stuff auto resizeData = [&] (const size_t length) { data.resize (length); // for non-graph data the graph should be already loaded @@ -1760,8 +1763,6 @@ bool BotGraph::loadGraphData () { ExtenHeader exten {}; int32 outOptions = 0; - m_paths.clear (); - // check if loaded bool dataLoaded = loadStorage ("graph", "Graph", StorageOption::Graph, StorageVersion::Graph, m_paths, &exten, &outOptions); diff --git a/src/linkage.cpp b/src/linkage.cpp index 6915be1..72527f7 100644 --- a/src/linkage.cpp +++ b/src/linkage.cpp @@ -805,30 +805,31 @@ CR_EXPORT int GetNewDLLFunctions (newgamefuncs_t *table, int *interfaceVersion) plat.bzero (table, sizeof (newgamefuncs_t)); if (!(game.is (GameFlags::Metamod))) { - auto api_GetEntityAPI = game.lib ().resolve (__FUNCTION__); + auto api_GetNewDLLFunctions = game.lib ().resolve (__FUNCTION__); // pass other DLLs engine callbacks to function table... - if (!api_GetEntityAPI || api_GetEntityAPI (&newapi, interfaceVersion) == 0) { + if (!api_GetNewDLLFunctions || api_GetNewDLLFunctions (&newapi, interfaceVersion) == 0) { logger.error ("Could not resolve symbol \"%s\" in the game dll.", __FUNCTION__); } dllfuncs.newapi_table = &newapi; - memcpy (table, &newapi, sizeof (newgamefuncs_t)); } - table->pfnOnFreeEntPrivateData = [] (edict_t *ent) { - for (auto &bot : bots) { - if (bot->m_enemy == ent) { - bot->m_enemy = nullptr; - bot->m_lastEnemy = nullptr; + if (!game.is (GameFlags::Legacy)) { + table->pfnOnFreeEntPrivateData = [] (edict_t *ent) { + for (auto &bot : bots) { + if (bot->m_enemy == ent) { + bot->m_enemy = nullptr; + bot->m_lastEnemy = nullptr; + } } - } - if (game.is (GameFlags::Metamod)) { - RETURN_META (MRES_IGNORED); - } - newapi.pfnOnFreeEntPrivateData (ent); - }; + if (game.is (GameFlags::Metamod)) { + RETURN_META (MRES_IGNORED); + } + newapi.pfnOnFreeEntPrivateData (ent); + }; + } return HLTrue; } @@ -946,7 +947,7 @@ CR_EXPORT void Meta_Init () { # define DLL_GIVEFNPTRSTODLL CR_EXPORT void #endif -DLL_GIVEFNPTRSTODLL GiveFnptrsToDll (enginefuncs_t *functionTable, globalvars_t *glob) { +DLL_GIVEFNPTRSTODLL GiveFnptrsToDll (enginefuncs_t *table, globalvars_t *glob) { // this is the very first function that is called in the game DLL by the game. Its purpose // is to set the functions interfacing up, by exchanging the functionTable function list // along with a pointer to the engine's global variables structure pGlobals, with the game @@ -959,7 +960,7 @@ DLL_GIVEFNPTRSTODLL GiveFnptrsToDll (enginefuncs_t *functionTable, globalvars_t // initialization stuff will be done later, when we'll be certain to have a multilayer game. // get the engine functions from the game... - memcpy (&engfuncs, functionTable, sizeof (enginefuncs_t)); + memcpy (&engfuncs, table, sizeof (enginefuncs_t)); globals = glob; if (game.postload ()) { @@ -970,13 +971,13 @@ DLL_GIVEFNPTRSTODLL GiveFnptrsToDll (enginefuncs_t *functionTable, globalvars_t if (!api_GiveFnptrsToDll) { logger.fatal ("Could not resolve symbol \"%s\" in the game dll.", __FUNCTION__); } - GetEngineFunctions (functionTable, nullptr); + GetEngineFunctions (table, nullptr); // initialize dynamic linkents ents.initialize (); // give the engine functions to the other DLL... - api_GiveFnptrsToDll (functionTable, glob); + api_GiveFnptrsToDll (table, glob); } DLSYM_RETURN EntityLinkage::lookup (SharedLibrary::Handle module, const char *function) { diff --git a/src/message.cpp b/src/message.cpp index d6d1917..e0e59ec 100644 --- a/src/message.cpp +++ b/src/message.cpp @@ -134,15 +134,15 @@ void MessageDispatcher::netMsgWeaponList () { } // store away this weapon with it's ammo information... - conf.getWeaponProp (m_args[id].long_) = { - m_args[classname].chars_, - m_args[ammo_index_1].long_, - m_args[max_ammo_1].long_, - m_args[slot].long_, - m_args[slot_pos].long_, - m_args[id].long_, - m_args[flags].long_ - }; + auto &prop = conf.getWeaponProp (m_args[id].long_); + + prop.classname = m_args[classname].chars_; + prop.ammo1 = m_args[ammo_index_1].long_; + prop.ammo1Max = m_args[max_ammo_1].long_; + prop.slot = m_args[slot].long_; + prop.pos = m_args[slot_pos].long_; + prop.id = m_args[id].long_; + prop.flags = m_args[flags].long_; } void MessageDispatcher::netMsgCurWeapon () { diff --git a/src/navigate.cpp b/src/navigate.cpp index e59e1b0..64733f3 100644 --- a/src/navigate.cpp +++ b/src/navigate.cpp @@ -2993,49 +2993,52 @@ bool Bot::isOccupiedNode (int index, bool needZeroVelocity) { continue; } + // just in case, if something happend, and we're not updated yet + if (!util.isAlive (client.ent)) { + continue; + } + // do not check clients far away from us if ((pev->origin - client.origin).lengthSq () > cr::square (320.0f)) { continue; } - if (needZeroVelocity && client.ent->v.velocity.length2d () > 0.0f) { continue; } - auto bot = bots[client.ent]; + auto length = (graph[index].origin - client.origin).lengthSq (); - if (bot == this) { - continue; - } - - if (bot != nullptr) { - int occupyId = util.getShootingCone (bot->ent (), pev->origin) >= 0.7f ? bot->m_previousNodes[0] : bot->m_currentNodeIndex; - - if (index == occupyId) { - return true; - } - } - float length = (graph[index].origin - client.origin).lengthSq (); - - if (length < cr::clamp (graph[index].radius, cr::square (90.0f), cr::square (120.0f))) { + if (length < cr::clamp (cr::square (graph[index].radius), cr::square (60.0f), cr::square (90.0f))) { return true; } +#if 0 // too cpu hungry, disabled temporary + auto bot = bots[client.ent]; + + if (bot == nullptr || bot == this || !bot->m_notKilled) { + continue; + } + auto occupyId = util.getShootingCone (bot->ent (), pev->origin) >= 0.7f ? bot->m_previousNodes[0] : bot->m_currentNodeIndex; + + if (index == occupyId) { + return true; + } +#endif } return false; } -edict_t *Bot::lookupButton (const char *targetName) { +edict_t *Bot::lookupButton (const char *target) { // this function tries to find nearest to current bot button, and returns pointer to // it's entity, also here must be specified the target, that button must open. - if (strings.isEmpty (targetName)) { + if (strings.isEmpty (target)) { return nullptr; } float nearest = kInfiniteDistance; edict_t *result = nullptr; // find the nearest button which can open our target - game.searchEntities ("target", targetName, [&] (edict_t *ent) { + game.searchEntities ("target", target, [&] (edict_t *ent) { const Vector &pos = game.getEntityWorldOrigin (ent); // check if this place safe diff --git a/vc/yapb.vcxproj b/vc/yapb.vcxproj index 69abaa0..1f7a800 100644 --- a/vc/yapb.vcxproj +++ b/vc/yapb.vcxproj @@ -11,30 +11,30 @@ - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + @@ -169,7 +169,7 @@ Default true false - Default + stdcpp14 NDEBUG;%(PreprocessorDefinitions) @@ -249,6 +249,7 @@ true false true + stdcpp14 NDEBUG;%(PreprocessorDefinitions) diff --git a/vc/yapb.vcxproj.filters b/vc/yapb.vcxproj.filters index b04ec55..c9214a6 100644 --- a/vc/yapb.vcxproj.filters +++ b/vc/yapb.vcxproj.filters @@ -75,79 +75,79 @@ inc\ext\hlsdk - - inc\ext\crlib - - - inc\ext\crlib - - - inc\ext\crlib - - - inc\ext\crlib - - - inc\ext\crlib - - - inc\ext\crlib - - - inc\ext\crlib - - - inc\ext\crlib - - - inc\ext\crlib - - - inc\ext\crlib - - - inc\ext\crlib - - - inc\ext\crlib - - - inc\ext\crlib - - - inc\ext\crlib - - - inc\ext\crlib - - - inc\ext\crlib - - - inc\ext\crlib - - - inc\ext\crlib - - - inc\ext\crlib - - - inc\ext\crlib - - - inc\ext\crlib - - - inc\ext\crlib - inc - + inc\ext\crlib - + + inc\ext\crlib + + + inc\ext\crlib + + + inc\ext\crlib + + + inc\ext\crlib + + + inc\ext\crlib + + + inc\ext\crlib + + + inc\ext\crlib + + + inc\ext\crlib + + + inc\ext\crlib + + + inc\ext\crlib + + + inc\ext\crlib + + + inc\ext\crlib + + + inc\ext\crlib + + + inc\ext\crlib + + + inc\ext\crlib + + + inc\ext\crlib + + + inc\ext\crlib + + + inc\ext\crlib + + + inc\ext\crlib + + + inc\ext\crlib + + + inc\ext\crlib + + + inc\ext\crlib + + inc\ext\crlib