diff --git a/src/component/gsc.cpp b/src/component/gsc.cpp index 7514d5b..0c15570 100644 --- a/src/component/gsc.cpp +++ b/src/component/gsc.cpp @@ -188,7 +188,6 @@ namespace gsc std::string string(answer); string += " haha funny"s; - printf((string + "\n"s).data()); game::Scr_AddIString(game::SCRIPTINSTANCE_SERVER, string.data()); }); @@ -210,13 +209,6 @@ namespace gsc { game::pathnode_t* node = game::Scr_GetPathnode(game::SCRIPTINSTANCE_SERVER); - printf("Node: %d\n" + node->constant.type); - printf("Node: %f\n", node->constant.fRadius); - - printf("Node Targetname %s\n", SL_ConvertToString( game::SCRIPTINSTANCE_SERVER, node->constant.targetname)); - - printf("0\n"); - game::Scr_AddPathnode(game::SCRIPTINSTANCE_SERVER, node); }); @@ -256,7 +248,7 @@ namespace gsc method::add("entitytest", [](game::scr_entref_s ent) { - if (ent.classnum != 0) + if (ent.classnum != game::CLASS_NUM_ENTITY) { return; } @@ -265,6 +257,86 @@ namespace gsc game::Scr_AddEntity(game::SCRIPTINSTANCE_SERVER, ent2); }); + + method::add("getlinkednodes", [](game::scr_entref_s ent) + { + if (ent.classnum != game::CLASS_NUM_PATHNODE) + { + return; + } + + auto primary_node = &(*game::gameWorldCurrent)->path.nodes[ent.entnum]; + + game::Scr_MakeArray(game::SCRIPTINSTANCE_SERVER); + + for (auto i = 0; i < primary_node->constant.totalLinkCount; i++) + { + auto linked_node = &(*game::gameWorldCurrent)->path.nodes[primary_node->constant.Links[i].nodeNum]; + + game::Scr_AddPathnode(game::SCRIPTINSTANCE_SERVER, linked_node); + game::Scr_AddArray(game::SCRIPTINSTANCE_SERVER); + } + }); + + method::add("getnodenumber", [](game::scr_entref_s ent) + { + if (ent.classnum != game::CLASS_NUM_PATHNODE) + { + return; + } + + auto node = &(*game::gameWorldCurrent)->path.nodes[ent.entnum]; + + auto entnum = node - (*game::gameWorldCurrent)->path.nodes; + + game::Scr_AddInt(game::SCRIPTINSTANCE_SERVER, entnum); + }); + + function::add("getnodebynumber", []() + { + auto node_num = game::Scr_GetInt(game::SCRIPTINSTANCE_SERVER, 0); + + if (node_num < 0 || node_num >= game::g_path->actualNodeCount) + { + return; + } + + auto node = &(*game::gameWorldCurrent)->path.nodes[node_num]; + + game::Scr_AddPathnode(game::SCRIPTINSTANCE_SERVER, node); + }); + + function::add("generatepath", []() + { + auto path = std::make_unique(); + + float start_pos[3] = {}; + + float goal_pos[3] = {}; + + auto team = game::TEAM_ALLIES; + + game::Scr_GetVector(game::SCRIPTINSTANCE_SERVER, 0, start_pos); + game::Scr_GetVector(game::SCRIPTINSTANCE_SERVER, 1, goal_pos); + + auto success = game::Path_FindPath(path.get(), team, start_pos, goal_pos, true); + + if (!success) + { + return; + } + + game::Scr_MakeArray(game::SCRIPTINSTANCE_SERVER); + + for (auto i = 0; i < path->wPathLen; i++) + { + auto node_in_path = &(*game::gameWorldCurrent)->path.nodes[path->pts[i].iNodeNum]; + + game::Scr_AddPathnode(game::SCRIPTINSTANCE_SERVER, node_in_path); + game::Scr_AddArray(game::SCRIPTINSTANCE_SERVER); + } + }); + } private: diff --git a/src/game/game.cpp b/src/game/game.cpp index a968b46..3654dbe 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -282,11 +282,8 @@ namespace game void Scr_AddPathnode(scriptInstance_t inst, pathnode_t* node) { - printf("Scr_AddPathnode Targetname %s\n", SL_ConvertToString(game::SCRIPTINSTANCE_SERVER, node->constant.targetname)); int entnum = node - (*gameWorldCurrent)->path.nodes; - printf("1 entnum: %d\n", entnum); int entid = Scr_GetEntityId(inst, entnum, CLASS_NUM_PATHNODE, 0); - printf("2 entid: %d\n", entid); Scr_AddEntityNum(inst, entid); } @@ -380,6 +377,26 @@ namespace game return Dvar_RegisterVariant(name, game::DVAR_TYPE_STRING, flags, dvar_value, limits, desc); } + int Path_FindPath(path_t* pPath, team_t eTeam, float* vStartPos, float* vGoalPos, int bAllowNegotiationLinks) + { + static const auto call_addr = SELECT(0x0, 0x4CF280); + + int answer; + + __asm + { + push bAllowNegotiationLinks; + push vGoalPos; + push vStartPos; + mov edx, eTeam; + mov ecx, pPath; + call call_addr; + mov answer, eax; + } + + return answer; + } + namespace plutonium { } diff --git a/src/game/game.hpp b/src/game/game.hpp index 3caf9c6..916f47b 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -51,6 +51,8 @@ namespace game void Scr_AddArrayStringIndexed(scriptInstance_t inst, unsigned short id); //testing const char* SL_ConvertToString(scriptInstance_t inst, int id); //testing + int Path_FindPath(path_t* pPath, team_t eTeam, float* vStartPos, float* vGoalPos, int bAllowNegotiationLinks); + template class symbol { diff --git a/src/game/structs.hpp b/src/game/structs.hpp index e7f3e75..441da2b 100644 --- a/src/game/structs.hpp +++ b/src/game/structs.hpp @@ -1417,7 +1417,7 @@ namespace game float fOrientLerp; }; - enum nodeType : __int32 + enum nodeType { NODE_BADNODE = 0x0, NODE_PATHNODE = 0x1, @@ -1550,4 +1550,41 @@ namespace game PathData path; }; + struct PathLinkInfo + { + unsigned __int16 from; + unsigned __int16 to; + unsigned __int16 prev; + unsigned __int16 next; + }; + + struct pathsort_t + { + pathnode_t* node; + float metric; + float distMetric; + }; + + struct pathlocal_t_circle + { + float origin[3]; + float maxDist; + float maxDistSq; + float maxHeight; + float maxHeightSq; + int typeFlags; + pathsort_t* nodes; + int maxNodes; + int nodeCount; + }; + + struct __declspec(align(128)) pathlocal_t + { + PathLinkInfo pathLinkInfoArray[2048]; + int pathLinkInfoArrayInited; + unsigned int actualNodeCount; + unsigned int extraNodes; + unsigned int originErrors; + pathlocal_t_circle circle; + }; } \ No newline at end of file diff --git a/src/game/symbols.hpp b/src/game/symbols.hpp index 8bfc366..7945494 100644 --- a/src/game/symbols.hpp +++ b/src/game/symbols.hpp @@ -19,6 +19,8 @@ namespace game WEAK symbol gameWorldCurrent{ 0x0, 0x8E1D80 }; + WEAK symbol g_path{ 0x0, 0x1F2F700 }; + WEAK symbol g_entities{ 0x0, 0x176C6F0 }; namespace plutonium