fix: occupied point check radius calculated incorrectly

fix: occupied point calculation takes too much cpu power
fix: buffer overrun in messaging processing
fix: running bots on hlds 3111e (cs 1.5) on linux*
build: added back correct ldscript for gcc and clang

* for some reason only gcc-compiled binaries working on centos5.8 and hlds 3.1.1.1e. clang binaries crashing immediately, so if you want to run bot on ancient os and/or hlds you need to recompile with gcc, as default linux binaries built with clang.
This commit is contained in:
dmitry 2021-09-10 19:42:24 +03:00
commit f55730ac6d
No known key found for this signature in database
GPG key ID: 8297CE728B7A7E37
11 changed files with 162 additions and 146 deletions

View file

@ -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

View file

@ -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);

10
ldscript.lds Normal file
View file

@ -0,0 +1,10 @@
YAPB_ABI_1.0 {
global:
Meta_*;
GiveFnptrsToDll;
GetBotAPI;
GetEntityAPI;
GetNewDLLFunctions;
local:
*;
};

View file

@ -102,7 +102,9 @@ if clang or gcc
endif
ldflags += [
'-flto'
'-flto',
'-Wl,--version-script=../ldscript.lds',
'-Wl,--gc-sections'
]
endif
endif

View file

@ -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;

View file

@ -1612,6 +1612,9 @@ template <typename U> 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 <Path> ("graph", "Graph", StorageOption::Graph, StorageVersion::Graph, m_paths, &exten, &outOptions);

View file

@ -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 <decltype (&GetNewDLLFunctions)> (__FUNCTION__);
auto api_GetNewDLLFunctions = game.lib ().resolve <decltype (&GetNewDLLFunctions)> (__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) {

View file

@ -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 () {

View file

@ -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

View file

@ -11,30 +11,30 @@
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\ext\crlib\cr-array.h" />
<ClInclude Include="..\ext\crlib\cr-basic.h" />
<ClInclude Include="..\ext\crlib\cr-binheap.h" />
<ClInclude Include="..\ext\crlib\cr-color.h" />
<ClInclude Include="..\ext\crlib\cr-complete.h" />
<ClInclude Include="..\ext\crlib\cr-deque.h" />
<ClInclude Include="..\ext\crlib\cr-hashmap.h" />
<ClInclude Include="..\ext\crlib\cr-files.h" />
<ClInclude Include="..\ext\crlib\cr-detour.h" />
<ClInclude Include="..\ext\crlib\cr-http.h" />
<ClInclude Include="..\ext\crlib\cr-lambda.h" />
<ClInclude Include="..\ext\crlib\cr-library.h" />
<ClInclude Include="..\ext\crlib\cr-logger.h" />
<ClInclude Include="..\ext\crlib\cr-math.h" />
<ClInclude Include="..\ext\crlib\cr-memory.h" />
<ClInclude Include="..\ext\crlib\cr-movable.h" />
<ClInclude Include="..\ext\crlib\cr-override.h" />
<ClInclude Include="..\ext\crlib\cr-platform.h" />
<ClInclude Include="..\ext\crlib\cr-random.h" />
<ClInclude Include="..\ext\crlib\cr-string.h" />
<ClInclude Include="..\ext\crlib\cr-twin.h" />
<ClInclude Include="..\ext\crlib\cr-ulz.h" />
<ClInclude Include="..\ext\crlib\cr-uniqueptr.h" />
<ClInclude Include="..\ext\crlib\cr-vector.h" />
<ClInclude Include="..\ext\crlib\crlib\cr-array.h" />
<ClInclude Include="..\ext\crlib\crlib\cr-basic.h" />
<ClInclude Include="..\ext\crlib\crlib\cr-binheap.h" />
<ClInclude Include="..\ext\crlib\crlib\cr-color.h" />
<ClInclude Include="..\ext\crlib\crlib\cr-complete.h" />
<ClInclude Include="..\ext\crlib\crlib\cr-deque.h" />
<ClInclude Include="..\ext\crlib\crlib\cr-detour.h" />
<ClInclude Include="..\ext\crlib\crlib\cr-files.h" />
<ClInclude Include="..\ext\crlib\crlib\cr-hashmap.h" />
<ClInclude Include="..\ext\crlib\crlib\cr-http.h" />
<ClInclude Include="..\ext\crlib\crlib\cr-lambda.h" />
<ClInclude Include="..\ext\crlib\crlib\cr-library.h" />
<ClInclude Include="..\ext\crlib\crlib\cr-logger.h" />
<ClInclude Include="..\ext\crlib\crlib\cr-math.h" />
<ClInclude Include="..\ext\crlib\crlib\cr-memory.h" />
<ClInclude Include="..\ext\crlib\crlib\cr-movable.h" />
<ClInclude Include="..\ext\crlib\crlib\cr-override.h" />
<ClInclude Include="..\ext\crlib\crlib\cr-platform.h" />
<ClInclude Include="..\ext\crlib\crlib\cr-random.h" />
<ClInclude Include="..\ext\crlib\crlib\cr-string.h" />
<ClInclude Include="..\ext\crlib\crlib\cr-twin.h" />
<ClInclude Include="..\ext\crlib\crlib\cr-ulz.h" />
<ClInclude Include="..\ext\crlib\crlib\cr-uniqueptr.h" />
<ClInclude Include="..\ext\crlib\crlib\cr-vector.h" />
<ClInclude Include="..\ext\hlsdk\const.h" />
<ClInclude Include="..\ext\hlsdk\eiface.h" />
<ClInclude Include="..\ext\hlsdk\extdll.h" />
@ -169,7 +169,7 @@
<InlineFunctionExpansion>Default</InlineFunctionExpansion>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<DisableLanguageExtensions>false</DisableLanguageExtensions>
<LanguageStandard>Default</LanguageStandard>
<LanguageStandard>stdcpp14</LanguageStandard>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
@ -249,6 +249,7 @@
<StringPooling>true</StringPooling>
<BufferSecurityCheck>false</BufferSecurityCheck>
<FunctionLevelLinking>true</FunctionLevelLinking>
<LanguageStandard>stdcpp14</LanguageStandard>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>

View file

@ -75,79 +75,79 @@
<ClInclude Include="..\ext\hlsdk\util.h">
<Filter>inc\ext\hlsdk</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\cr-array.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\cr-basic.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\cr-binheap.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\cr-color.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\cr-complete.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\cr-files.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\cr-http.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\cr-lambda.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\cr-library.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\cr-logger.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\cr-math.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\cr-movable.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\cr-platform.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\cr-random.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\cr-string.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\cr-twin.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\cr-ulz.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\cr-uniqueptr.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\cr-vector.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\cr-detour.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\cr-hashmap.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\cr-deque.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\inc\module.h">
<Filter>inc</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\cr-memory.h">
<ClInclude Include="..\ext\crlib\crlib\cr-array.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\cr-override.h">
<ClInclude Include="..\ext\crlib\crlib\cr-basic.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\crlib\cr-binheap.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\crlib\cr-color.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\crlib\cr-complete.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\crlib\cr-deque.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\crlib\cr-detour.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\crlib\cr-files.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\crlib\cr-hashmap.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\crlib\cr-http.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\crlib\cr-lambda.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\crlib\cr-library.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\crlib\cr-logger.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\crlib\cr-math.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\crlib\cr-memory.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\crlib\cr-movable.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\crlib\cr-override.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\crlib\cr-platform.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\crlib\cr-random.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\crlib\cr-string.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\crlib\cr-twin.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\crlib\cr-ulz.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\crlib\cr-uniqueptr.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
<ClInclude Include="..\ext\crlib\crlib\cr-vector.h">
<Filter>inc\ext\crlib</Filter>
</ClInclude>
</ItemGroup>