From a3288cc353ec65bb3c9a03ad611bfd4a72c4adab Mon Sep 17 00:00:00 2001 From: jeefo Date: Thu, 6 Oct 2022 17:01:18 +0300 Subject: [PATCH] fix: prevent loading graphs with less than 8 nodes (brokes pathfinder) fix: prevent running A* with less than 8 nodes (in case converted one) fix: trying to play with graph author/modified stuff per #374 --- src/graph.cpp | 23 +++++++++++------------ src/navigate.cpp | 6 ++++++ vc/yapb.vcxproj.filters | 6 +++--- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/graph.cpp b/src/graph.cpp index c6785f4..0f58408 100644 --- a/src/graph.cpp +++ b/src/graph.cpp @@ -1739,7 +1739,7 @@ template bool BotGraph::loadStorage (StringRef ext, StringRef name, } // check the count - if (hdr.length == 0 || hdr.length > kMaxNodes) { + if (hdr.length == 0 || hdr.length > kMaxNodes || hdr.length < kMaxNodeLinks) { if (tryReload ()) { return true; } @@ -1831,7 +1831,7 @@ bool BotGraph::loadGraphData () { } if ((outOptions & StorageOption::Official) || strncmp (exten.author, "official", 8) == 0 || strlen (exten.author) < 2) { - m_graphAuthor.assign (product.folder); + m_graphAuthor.assign (product.name); } else { m_graphAuthor.assign (exten.author); @@ -1867,40 +1867,39 @@ bool BotGraph::canDownload () { bool BotGraph::saveGraphData () { auto options = StorageOption::Graph | StorageOption::Exten; - String author; + String editorName; if (game.isNullEntity (m_editor) && !m_graphAuthor.empty ()) { - author = m_graphAuthor; + editorName = m_graphAuthor; if (!game.isDedicated ()) { options |= StorageOption::Recovered; } } else if (!game.isNullEntity (m_editor)) { - author = m_editor->v.netname.chars (); + editorName = m_editor->v.netname.chars (); } else { - author = product.name; + editorName = product.name; } // mark as official - if (author.startsWith (product.name)) { + if (editorName.startsWith (product.name)) { options |= StorageOption::Official; } - ExtenHeader exten {}; // only modify the author if no author currenlty assigned to graph file - if (m_graphAuthor.empty ()) { - strings.copy (exten.author, author.chars (), cr::bufsize (exten.author)); + if (m_graphAuthor.empty () || strings.isEmpty (m_extenHeader.author)) { + strings.copy (exten.author, editorName.chars (), cr::bufsize (exten.author)); } else { strings.copy (exten.author, m_extenHeader.author, cr::bufsize (exten.author)); } // only update modified by, if name differs - if (m_graphAuthor != author && strncmp (m_extenHeader.author, m_extenHeader.modified, cr::bufsize (m_extenHeader.author)) != 0) { - strings.copy (exten.modified, author.chars (), cr::bufsize (exten.author)); + if (m_graphAuthor != editorName && !strings.isEmpty (m_extenHeader.author)) { + strings.copy (exten.modified, editorName.chars (), cr::bufsize (exten.author)); } exten.mapSize = getBspSize (); diff --git a/src/navigate.cpp b/src/navigate.cpp index f9fc261..4ec1728 100644 --- a/src/navigate.cpp +++ b/src/navigate.cpp @@ -1404,6 +1404,12 @@ void Bot::findPath (int srcIndex, int destIndex, FindPath pathType /*= FindPath: return; } + // astar needs some nodes to work with + if (graph.length () < kMaxNodeLinks) { + logger.error ("A* Search for bot \"%s\" has failed due to too small number of nodes (%d). Seems to be graph is broken.", pev->netname.chars (), graph.length ()); + return; + } + // holders for heuristic functions static Lambda gcalc, hcalc; diff --git a/vc/yapb.vcxproj.filters b/vc/yapb.vcxproj.filters index 1cc44f3..4ec3323 100644 --- a/vc/yapb.vcxproj.filters +++ b/vc/yapb.vcxproj.filters @@ -13,12 +13,12 @@ {bec0fb46-08b4-4bfa-900c-d279a933ff77} - - {5e73b918-f42b-4df9-bbe9-918289e44ad2} - {f6a0fc04-bdf5-479b-8e5a-85eae698541e} + + {5e73b918-f42b-4df9-bbe9-918289e44ad2} +