Progress on path generating code.

Add readfile and writefile builtins. Attempt to  print GSC callstack.
This commit is contained in:
JezuzLizard
2023-04-14 20:12:11 -07:00
parent f0ffd59c58
commit e0114bb4de
8 changed files with 771 additions and 10 deletions

View File

@ -14,7 +14,7 @@ namespace ai
namespace
{
/*
int __cdecl Path_AStarAlgorithm_CustomSearchInfo_FindPath_(path_t *pPath, team_t eTeam, const float *vStartPos, pathnode_t *pNodeFrom, const float *vGoalPos, int bAllowNegotiationLinks, CustomSearchInfo_FindPath *searchInfo, int bIncludeGoalInPath, pathnode_t *bIgnoreBadPlaces)
int __cdecl Path_AStarAlgorithm_CustomSearchInfo_FindPath_(path_t *pPath, team_t eTeam, const float *vStartPos, pathnode_t *pNodeFrom, const float *vGoalPos, int bAllowNegotiationLinks, CustomSearchInfo_FindPath *searchInfo, int bIgnoreBadplaces, pathnode_t *nodeTo)
{
float *returnVGoaPosl; // edx
int nodeLinkIndex; // ebx
@ -77,7 +77,7 @@ namespace ai
{
while ( 1 )
{
if ( bIncludeGoalInPath || !returnEndNode->constant.Links[nodeLinkIndex].ubBadPlaceCount[eTeam] )
if ( bIgnoreBadplaces || !returnEndNode->constant.Links[nodeLinkIndex].ubBadPlaceCount[eTeam] )
{
endNodeLinks = returnEndNode->constant.Links;
nodeNum = endNodeLinks[nodeLinkIndex].nodeNum;
@ -167,6 +167,157 @@ namespace ai
}
*/
int Path_AStarAlgorithm_CustomSearchInfo_FindPath_custom(game::path_t* pPath, game::team_t eTeam, const float* vStartPos, game::pathnode_t* pNodeFrom, const float* vGoalPos, int bAllowNegotiationLinks, game::CustomSearchInfo_FindPath* searchInfo, int bIgnoreBadplaces, game::pathnode_t* nodeTo)
{
float* returnVGoaPosl; // edx
int nodeLinkIndex; // ebx
game::pathnode_t* returnStartNode; // ecx
game::pathnode_t* returnEndNode; // edi
game::pathlink_s* endNodeLinks; // eax
int nodeNum; // esi
float* endNodeLinkDist; // eax
game::pathnode_t* pSuccessor; // esi
float v17; // xmm0_4
game::pathnode_t* v18; // eax
game::pathnode_t* v19; // eax
float v20; // xmm1_4
long double v21; // st7
float v22; // xmm3_4
float v23; // xmm0_4
float v24; // xmm1_4
float v25; // xmm2_4
float v26; // xmm0_4
float v27; // xmm1_4
float v28; // xmm1_4
game::pathnode_t* pInsert; // eax
game::pathnode_t* v30; // ecx
game::pathnode_t* v31; // eax
int success; // eax
float v33; // [esp+10h] [ebp-8Ch]
int linkCount; // [esp+14h] [ebp-88h]
float negotiationOverlapCost; // [esp+18h] [ebp-84h]
game::pathnode_t topParent; // [esp+1Ch] [ebp-80h] BYREF
returnVGoaPosl = (float*)vGoalPos;
nodeLinkIndex = 0;
if (vGoalPos)
{
*game::g_pathAttemptGoalPos[0] = vGoalPos[0];
*game::g_pathAttemptGoalPos[1] = vGoalPos[1];
*game::g_pathAttemptGoalPos[2] = vGoalPos[2];
}
else
{
*game::g_pathAttemptGoalPos[0] = 0.0f;
*game::g_pathAttemptGoalPos[1] = 0.0f;
*game::g_pathAttemptGoalPos[2] = 0.0f;
}
returnStartNode = pNodeFrom;
pNodeFrom->transient.iSearchFrame = ++game::level->iSearchFrame;
returnEndNode = pNodeFrom;
pNodeFrom->transient.pParent = &topParent;
pNodeFrom->transient.pNextOpen = 0;
pNodeFrom->transient.pPrevOpen = &topParent;
pNodeFrom->transient.fCost = 0.0;
topParent.transient.pNextOpen = pNodeFrom;
while (returnEndNode != searchInfo->m_pNodeTo)
{
topParent.transient.pNextOpen = returnEndNode->transient.pNextOpen;
if (topParent.transient.pNextOpen)
topParent.transient.pNextOpen->transient.pPrevOpen = &topParent;
linkCount = 0;
if (returnEndNode->dynamic.wLinkCount > 0)
{
while (1)
{
if (bIgnoreBadplaces || !returnEndNode->constant.Links[nodeLinkIndex].ubBadPlaceCount[eTeam])
{
endNodeLinks = returnEndNode->constant.Links;
nodeNum = endNodeLinks[nodeLinkIndex].nodeNum;
endNodeLinkDist = &endNodeLinks[nodeLinkIndex].fDist;
pSuccessor = &(*game::gameWorldCurrent)->path.nodes[nodeNum];
if (returnEndNode->constant.type != game::NODE_NEGOTIATION_BEGIN || pSuccessor->constant.type != game::NODE_NEGOTIATION_END || !returnEndNode->dynamic.wOverlapCount && !pSuccessor->dynamic.wOverlapCount)
{
if (pSuccessor->transient.iSearchFrame != game::level->iSearchFrame)
{
pSuccessor->transient.iSearchFrame = game::level->iSearchFrame;
negotiationOverlapCost = searchInfo->negotiationOverlapCost;
v20 = vGoalPos[1] - pSuccessor->constant.vOrigin[1];
v21 = sqrtf((float)((float)(*vGoalPos - pSuccessor->constant.vOrigin[0]) * (float)(*vGoalPos - pSuccessor->constant.vOrigin[0])) + (float)(v20 * v20));
v22 = pSuccessor->constant.minUseDistSq;
if (v22 <= 1.0 || (v23 = searchInfo->startPos[0] - pSuccessor->constant.vOrigin[0], v24 = searchInfo->startPos[1] - pSuccessor->constant.vOrigin[1], v25 = searchInfo->startPos[2] - pSuccessor->constant.vOrigin[2], v22 <= (float)((float)((float)(v23 * v23) + (float)(v24 * v24)) + (float)(v25 * v25))))
{
v26 = v21 + (double)pSuccessor->dynamic.userCount * negotiationOverlapCost;
}
else
{
v33 = v21 + (double)pSuccessor->dynamic.userCount * negotiationOverlapCost;
v26 = negotiationOverlapCost + v33;
}
pSuccessor->transient.fHeuristic = v26;
v17 = returnEndNode->constant.Links[nodeLinkIndex].fDist + returnEndNode->transient.fCost;
LABEL_25:
v27 = pSuccessor->transient.fHeuristic;
pSuccessor->transient.pParent = returnEndNode;
pSuccessor->transient.fCost = v17;
v28 = v27 + v17;
pInsert = &topParent;
if (topParent.transient.pNextOpen)
{
do
{
v30 = pInsert->transient.pNextOpen;
if ((float)(v30->transient.fHeuristic + v30->transient.fCost) >= v28)
break;
pInsert = pInsert->transient.pNextOpen;
} while (v30->transient.pNextOpen);
}
pSuccessor->transient.pPrevOpen = pInsert;
pSuccessor->transient.pNextOpen = pInsert->transient.pNextOpen;
pInsert->transient.pNextOpen = pSuccessor;
v31 = pSuccessor->transient.pNextOpen;
if (v31)
v31->transient.pPrevOpen = pSuccessor;
goto LABEL_30;
}
v17 = returnEndNode->transient.fCost + *endNodeLinkDist;
if (v17 < pSuccessor->transient.fCost)
{
v18 = pSuccessor->transient.pPrevOpen;
if (v18)
{
v18->transient.pNextOpen = pSuccessor->transient.pNextOpen;
v19 = pSuccessor->transient.pNextOpen;
if (v19)
v19->transient.pPrevOpen = pSuccessor->transient.pPrevOpen;
}
goto LABEL_25;
}
}
}
LABEL_30:
++nodeLinkIndex;
if (++linkCount >= returnEndNode->dynamic.wLinkCount)
{
returnVGoaPosl = (float*)vGoalPos;
returnStartNode = pNodeFrom;
break;
}
}
}
nodeLinkIndex = 0;
returnEndNode->transient.pPrevOpen = 0;
returnEndNode = topParent.transient.pNextOpen;
if (!topParent.transient.pNextOpen)
return 0;
}
if (pPath)
success = game::Path_GeneratePath(pPath, eTeam, vStartPos, returnVGoaPosl, returnStartNode, returnEndNode, 1, bAllowNegotiationLinks);
else
success = 1;
return success;
}
/*
//Original
int __userpurge Path_FindPathFromTo@<eax>(float *startPos@<eax>, pathnode_t *pNodeTo@<edx>, path_t *pPath, team_t eTeam, pathnode_t *pNodeFrom, float *vGoalPos, int bAllowNegotiationLinks, int bIgnoreBadplaces)
@ -196,7 +347,7 @@ namespace ai
info.startPos[0] = startPos[0];
info.startPos[1] = startPos[1];
info.startPos[2] = startPos[2];
result = game::Path_AStarAlgorithm_CustomSearchInfo_FindPath_(pPath, eTeam, startPos, pNodeFrom, vGoalPos, bAllowNegotiationLinks, &info, bIgnoreBadplaces, pNodeTo);
result = Path_AStarAlgorithm_CustomSearchInfo_FindPath_custom(pPath, eTeam, startPos, pNodeFrom, vGoalPos, bAllowNegotiationLinks, &info, bIgnoreBadplaces, pNodeTo);
return result;
}
@ -234,7 +385,7 @@ namespace ai
game::pathnode_t* pNodeFrom = game::Path_NearestNodeNotCrossPlanes(-2, maxNodes, vStartPos, nodes.get(), 192.0f, 0.0f, 0.0f, 0.0f, &returnCount, game::NEAREST_NODE_DO_HEIGHT_CHECK);
if (pNodeTo && pNodeFrom)
{
result = game::Path_FindPathFromTo(vStartPos, pNodeTo, pPath, eTeam, pNodeFrom, vGoalPos, bAllowNegotiationLinks, 0);
result = Path_FindPathFromTo_custom(vStartPos, pNodeTo, pPath, eTeam, pNodeFrom, vGoalPos, bAllowNegotiationLinks, 0);
}
else
{

0
src/component/debug.cpp Normal file
View File

View File

@ -260,6 +260,25 @@ namespace gsc
game::Scr_AddEntity(game::SCRIPTINSTANCE_SERVER, ent2);
});
function::add("writefile", []()
{
const auto path = game::Scr_GetString(game::SCRIPTINSTANCE_SERVER, 0);
const auto data = game::Scr_GetString(game::SCRIPTINSTANCE_SERVER, 1);
auto append = false;
if (game::Scr_GetNumParam(game::SCRIPTINSTANCE_SERVER) > 2)
{
append = game::Scr_GetInt(game::SCRIPTINSTANCE_SERVER, 2);
}
game::Scr_AddInt(game::SCRIPTINSTANCE_SERVER, utils::io::write_file(path, data, append));
});
gsc::function::add("readfile", []()
{
const auto path = game::Scr_GetString(game::SCRIPTINSTANCE_SERVER, 0);
game::Scr_AddString(game::SCRIPTINSTANCE_SERVER, utils::io::read_file(path).c_str());
});
}
private:

View File

@ -5,13 +5,55 @@
#include <utils/io.hpp>
#include <utils/hook.hpp>
#include <utils/string.hpp>
namespace test
{
utils::hook::detour gscr_spawn_hook;
namespace
{
game::dvar_s* custom_dvar;
game::dvar_s* custom_string_dvar;
void print_script_callstack(const char* msg, game::scriptInstance_t inst)
{
int i; // [esp+4h] [ebp-4h]
printf("******* Callstack for %s *******\n", msg);
game::Scr_PrintPrevCodePos(game::function_stack[inst].pos, inst, game::CON_CHANNEL_DONT_FILTER, 0);
auto function_count = game::gScrVmPub[inst].function_count;
if (function_count)
{
for (i = function_count - 1; i >= 1; --i)
{
printf("Info: called from:\n");
game::Scr_PrintPrevCodePos(
game::gScrVmPub[inst].function_frame_start[i].fs.pos,
inst,
game::CON_CHANNEL_DONT_FILTER,
game::gScrVmPub[inst].function_frame_start[i].fs.localId == 0);
}
printf("started from:\n");
game::Scr_PrintPrevCodePos(game::gScrVmPub[inst].function_frame_start[0].fs.pos, inst, game::CON_CHANNEL_DONT_FILTER, 1u);
}
printf("************************************\n");
}
void gscr_spawn_stub()
{
auto classname = game::Scr_GetConstString(game::SCRIPTINSTANCE_SERVER, 0);
float origin[3] = {};
game::Scr_GetVector(game::SCRIPTINSTANCE_SERVER, 1, origin);
if (classname == game::scr_const->script_origin)
{
print_script_callstack(utils::string::va("GScr_Spawn() classname: script_origin at: (%f, %f, %f)", origin[0], origin[1], origin[2]), game::SCRIPTINSTANCE_SERVER);
}
gscr_spawn_hook.invoke<void>();
}
}
class component final : public component_interface
@ -44,7 +86,17 @@ namespace test
//printf("Biggie Spam McCheese\n");
});
gscr_spawn_hook.create(0x517630, gscr_spawn_stub);
//Disable AI print spam
utils::hook::nop(0x4BAB7D, 5);
utils::hook::nop(0x4BAAFA, 5);
//Disable asset loading print spam
utils::hook::nop(0x48D9D9, 5);
//Disable unknown dvar spam
utils::hook::nop(0x5F04AF, 5);
}
private: