Merge remote-tracking branch 'refs/remotes/TotallyNotElite/Pathfinder'
This commit is contained in:
commit
3d32630a2c
83
.autotools
Normal file
83
.autotools
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configurations>
|
||||||
|
<configuration id="org.eclipse.linuxtools.cdt.autotools.core.configuration.build.1853436091">
|
||||||
|
<option id="configure" value="configure"/>
|
||||||
|
<option id="configdir" value=""/>
|
||||||
|
<option id="cache-file" value=""/>
|
||||||
|
<option id="help" value="false"/>
|
||||||
|
<option id="no-create" value="false"/>
|
||||||
|
<option id="quiet" value="false"/>
|
||||||
|
<option id="version" value="false"/>
|
||||||
|
<option id="host" value=""/>
|
||||||
|
<option id="build" value=""/>
|
||||||
|
<option id="target" value=""/>
|
||||||
|
<option id="prefix" value=""/>
|
||||||
|
<option id="exec-prefix" value=""/>
|
||||||
|
<option id="libdir" value=""/>
|
||||||
|
<option id="bindir" value=""/>
|
||||||
|
<option id="sbindir" value=""/>
|
||||||
|
<option id="includedir" value=""/>
|
||||||
|
<option id="datadir" value=""/>
|
||||||
|
<option id="sysconfdir" value=""/>
|
||||||
|
<option id="infodir" value=""/>
|
||||||
|
<option id="mandir" value=""/>
|
||||||
|
<option id="srcdir" value=""/>
|
||||||
|
<option id="localstatedir" value=""/>
|
||||||
|
<option id="sharedstatedir" value=""/>
|
||||||
|
<option id="libexecdir" value=""/>
|
||||||
|
<option id="oldincludedir" value=""/>
|
||||||
|
<option id="program-prefix" value=""/>
|
||||||
|
<option id="program-suffix" value=""/>
|
||||||
|
<option id="program-transform-name" value=""/>
|
||||||
|
<option id="env_vars" value=""/>
|
||||||
|
<option id="enable-maintainer-mode" value="false"/>
|
||||||
|
<flag id="CFLAGS" value="CFLAGS|CXXFLAGS">
|
||||||
|
<flagvalue id="cflags-debug" value="false"/>
|
||||||
|
<flagvalue id="cflags-gprof" value="false"/>
|
||||||
|
<flagvalue id="cflags-gcov" value="false"/>
|
||||||
|
</flag>
|
||||||
|
<option id="user" value=""/>
|
||||||
|
<option id="autogen" value="autogen.sh"/>
|
||||||
|
<option id="autogenOpts" value=""/>
|
||||||
|
</configuration>
|
||||||
|
<configuration id="org.eclipse.linuxtools.cdt.autotools.core.configuration.build.debug.1487733959">
|
||||||
|
<option id="configure" value="configure"/>
|
||||||
|
<option id="configdir" value=""/>
|
||||||
|
<option id="cache-file" value=""/>
|
||||||
|
<option id="help" value="false"/>
|
||||||
|
<option id="no-create" value="false"/>
|
||||||
|
<option id="quiet" value="false"/>
|
||||||
|
<option id="version" value="false"/>
|
||||||
|
<option id="host" value=""/>
|
||||||
|
<option id="build" value=""/>
|
||||||
|
<option id="target" value=""/>
|
||||||
|
<option id="prefix" value=""/>
|
||||||
|
<option id="exec-prefix" value=""/>
|
||||||
|
<option id="libdir" value=""/>
|
||||||
|
<option id="bindir" value=""/>
|
||||||
|
<option id="sbindir" value=""/>
|
||||||
|
<option id="includedir" value=""/>
|
||||||
|
<option id="datadir" value=""/>
|
||||||
|
<option id="sysconfdir" value=""/>
|
||||||
|
<option id="infodir" value=""/>
|
||||||
|
<option id="mandir" value=""/>
|
||||||
|
<option id="srcdir" value=""/>
|
||||||
|
<option id="localstatedir" value=""/>
|
||||||
|
<option id="sharedstatedir" value=""/>
|
||||||
|
<option id="libexecdir" value=""/>
|
||||||
|
<option id="oldincludedir" value=""/>
|
||||||
|
<option id="program-prefix" value=""/>
|
||||||
|
<option id="program-suffix" value=""/>
|
||||||
|
<option id="program-transform-name" value=""/>
|
||||||
|
<option id="env_vars" value=""/>
|
||||||
|
<option id="enable-maintainer-mode" value="false"/>
|
||||||
|
<flag id="CFLAGS" value="CFLAGS|CXXFLAGS">
|
||||||
|
<flagvalue id="cflags-debug" value="false"/>
|
||||||
|
<flagvalue id="cflags-gprof" value="false"/>
|
||||||
|
<flagvalue id="cflags-gcov" value="false"/>
|
||||||
|
</flag>
|
||||||
|
<option id="user" value="CFLAGS='-g -O0' CXXFLAGS='-g -O0'"/>
|
||||||
|
<option id="autogen" value="autogen.sh"/>
|
||||||
|
<option id="autogenOpts" value=""/>
|
||||||
|
</configuration>
|
||||||
|
</configurations>
|
3
.gitmodules
vendored
Executable file → Normal file
3
.gitmodules
vendored
Executable file → Normal file
@ -16,3 +16,6 @@
|
|||||||
[submodule "external/co-library"]
|
[submodule "external/co-library"]
|
||||||
path = external/co-library
|
path = external/co-library
|
||||||
url = https://github.com/nullworks/co-library.git
|
url = https://github.com/nullworks/co-library.git
|
||||||
|
[submodule "external/TF2_NavFile_Reader"]
|
||||||
|
path = external/TF2_NavFile_Reader
|
||||||
|
url = https://github.com/nullworks/TF2_NavFile_Reader.git
|
||||||
|
@ -110,7 +110,8 @@ target_include_directories(cathook SYSTEM PRIVATE
|
|||||||
"external/source-sdk-2013-headers/mp/src/tier1"
|
"external/source-sdk-2013-headers/mp/src/tier1"
|
||||||
"external/source-sdk-2013-headers/mp/src")
|
"external/source-sdk-2013-headers/mp/src")
|
||||||
|
|
||||||
target_include_directories(cathook PRIVATE "external/ucccccp")
|
target_include_directories(cathook PRIVATE "external/TF2_NavFile_Reader")
|
||||||
|
target_include_directories(cathook PRIVATE "external/PathFinder/src/")
|
||||||
|
|
||||||
if(EnableWarnings)
|
if(EnableWarnings)
|
||||||
target_compile_options(cathook PRIVATE -Wall -Wextra)
|
target_compile_options(cathook PRIVATE -Wall -Wextra)
|
||||||
|
1
TF2_NavFile_Reader
Submodule
1
TF2_NavFile_Reader
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 3bc452cbca4ab3dafadbf40fa44013a31f0b159a
|
1
external/PathFinder
vendored
Submodule
1
external/PathFinder
vendored
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 03bac25118aaa65822d036ac9f3b82124b681ad9
|
@ -48,6 +48,8 @@
|
|||||||
|
|
||||||
#include "core/macros.hpp"
|
#include "core/macros.hpp"
|
||||||
#include <visual/colors.hpp>
|
#include <visual/colors.hpp>
|
||||||
|
#include <CNavFile.h>
|
||||||
|
#include <astar.h>
|
||||||
|
|
||||||
#if ENABLE_VISUALS
|
#if ENABLE_VISUALS
|
||||||
#include <visual/drawing.hpp>
|
#include <visual/drawing.hpp>
|
||||||
|
@ -11,9 +11,15 @@
|
|||||||
|
|
||||||
class IClientEntity;
|
class IClientEntity;
|
||||||
|
|
||||||
|
// Fix clang gay
|
||||||
|
#if defined(__clang__)
|
||||||
|
#define NET_VAR(entity, offset, type) \
|
||||||
|
(*(reinterpret_cast<type *>(reinterpret_cast<uint64_t>(entity) + (offset))))
|
||||||
|
#elif defined(__GNUC__) || defined(__GNUG__)
|
||||||
#define NET_VAR(entity, offset, type) \
|
#define NET_VAR(entity, offset, type) \
|
||||||
(*(reinterpret_cast<type *>(reinterpret_cast<uintptr_t>(entity) + \
|
(*(reinterpret_cast<type *>(reinterpret_cast<uintptr_t>(entity) + \
|
||||||
(offset))))
|
(offset))))
|
||||||
|
#endif
|
||||||
|
|
||||||
#define NET_INT(entity, offset) NET_VAR(entity, offset, int)
|
#define NET_INT(entity, offset) NET_VAR(entity, offset, int)
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ struct BacktrackData
|
|||||||
float viewangles{ 0.0f };
|
float viewangles{ 0.0f };
|
||||||
float simtime{ 0.0f };
|
float simtime{ 0.0f };
|
||||||
Vector entorigin{ 0.0f, 0.0f, 0.0f };
|
Vector entorigin{ 0.0f, 0.0f, 0.0f };
|
||||||
|
int index{ 0 };
|
||||||
};
|
};
|
||||||
struct BestTickData
|
struct BestTickData
|
||||||
{
|
{
|
||||||
@ -40,7 +41,6 @@ void Run();
|
|||||||
void Draw();
|
void Draw();
|
||||||
void AddLatencyToNetchan(INetChannel *, float);
|
void AddLatencyToNetchan(INetChannel *, float);
|
||||||
void UpdateIncomingSequences();
|
void UpdateIncomingSequences();
|
||||||
bool shouldBacktrack();
|
|
||||||
extern int lastincomingsequencenumber;
|
extern int lastincomingsequencenumber;
|
||||||
extern int BestTick;
|
extern int BestTick;
|
||||||
extern int iBestTarget;
|
extern int iBestTarget;
|
||||||
@ -60,7 +60,7 @@ typedef boost::circular_buffer_space_optimized<CIncomingSequence> circular_buf;
|
|||||||
extern circular_buf sequences;
|
extern circular_buf sequences;
|
||||||
extern BacktrackData headPositions[32][66];
|
extern BacktrackData headPositions[32][66];
|
||||||
|
|
||||||
bool isBacktrackEnabled();
|
extern bool isBacktrackEnabled;
|
||||||
float getLatency();
|
float getLatency();
|
||||||
int getTicks();
|
int getTicks();
|
||||||
bool ValidTick(BacktrackData &i, CachedEntity *ent);
|
bool ValidTick(BacktrackData &i, CachedEntity *ent);
|
||||||
|
@ -33,7 +33,8 @@ target_sources(cathook PRIVATE
|
|||||||
"${CMAKE_CURRENT_LIST_DIR}/votelogger.cpp"
|
"${CMAKE_CURRENT_LIST_DIR}/votelogger.cpp"
|
||||||
"${CMAKE_CURRENT_LIST_DIR}/MiscTemporary.cpp"
|
"${CMAKE_CURRENT_LIST_DIR}/MiscTemporary.cpp"
|
||||||
"${CMAKE_CURRENT_LIST_DIR}/Options.cpp"
|
"${CMAKE_CURRENT_LIST_DIR}/Options.cpp"
|
||||||
"${CMAKE_CURRENT_LIST_DIR}/PlayerTools.cpp")
|
"${CMAKE_CURRENT_LIST_DIR}/PlayerTools.cpp"
|
||||||
|
"${CMAKE_CURRENT_LIST_DIR}/pathfinder.cpp")
|
||||||
|
|
||||||
add_subdirectory(core)
|
add_subdirectory(core)
|
||||||
add_subdirectory(classinfo)
|
add_subdirectory(classinfo)
|
||||||
@ -47,4 +48,4 @@ add_subdirectory(settings)
|
|||||||
|
|
||||||
if(EnableVisuals)
|
if(EnableVisuals)
|
||||||
add_subdirectory(visual)
|
add_subdirectory(visual)
|
||||||
endif()
|
endif()
|
||||||
|
@ -93,10 +93,11 @@ Timer zoomTime{};
|
|||||||
// This array will store calculated projectile/hitscan predictions
|
// This array will store calculated projectile/hitscan predictions
|
||||||
// for current frame, to avoid performing them again
|
// for current frame, to avoid performing them again
|
||||||
AimbotCalculatedData_s calculated_data_array[2048]{};
|
AimbotCalculatedData_s calculated_data_array[2048]{};
|
||||||
|
<<<<<<< Updated upstream
|
||||||
#define IsMelee GetWeaponMode() == weapon_melee
|
#define IsMelee GetWeaponMode() == weapon_melee
|
||||||
bool BacktrackAimbot()
|
bool BacktrackAimbot()
|
||||||
{
|
{
|
||||||
if (!hacks::shared::backtrack::isBacktrackEnabled() || !backtrackAimbot)
|
if (!hacks::shared::backtrack::isBacktrackEnabled || !*backtrackAimbot)
|
||||||
return false;
|
return false;
|
||||||
if (aimkey && !aimkey.isKeyDown())
|
if (aimkey && !aimkey.isKeyDown())
|
||||||
return true;
|
return true;
|
||||||
@ -142,6 +143,7 @@ bool BacktrackAimbot()
|
|||||||
current_user_cmd->buttons |= IN_ATTACK;
|
current_user_cmd->buttons |= IN_ATTACK;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The main "loop" of the aimbot.
|
// The main "loop" of the aimbot.
|
||||||
void CreateMove()
|
void CreateMove()
|
||||||
{
|
{
|
||||||
@ -162,25 +164,6 @@ void CreateMove()
|
|||||||
// the find target and aiming system. If we just call the func than toggle
|
// the find target and aiming system. If we just call the func than toggle
|
||||||
// aimkey would break so we save it to a var to use it twice
|
// aimkey would break so we save it to a var to use it twice
|
||||||
bool aimkey_status = UpdateAimkey();
|
bool aimkey_status = UpdateAimkey();
|
||||||
// Refresh our best target
|
|
||||||
CachedEntity *target_entity = RetrieveBestTarget(aimkey_status);
|
|
||||||
if (CE_BAD(target_entity) || !foundTarget)
|
|
||||||
return;
|
|
||||||
// Auto-zoom
|
|
||||||
IF_GAME(IsTF())
|
|
||||||
{
|
|
||||||
if (auto_zoom)
|
|
||||||
{
|
|
||||||
if (g_pLocalPlayer->holding_sniper_rifle)
|
|
||||||
{
|
|
||||||
zoomTime.update();
|
|
||||||
if (not g_pLocalPlayer->bZoomed)
|
|
||||||
{
|
|
||||||
current_user_cmd->buttons |= IN_ATTACK2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// check if we need to run projectile Aimbot code
|
// check if we need to run projectile Aimbot code
|
||||||
projectileAimbotRequired = false;
|
projectileAimbotRequired = false;
|
||||||
if (projectile_aimbot &&
|
if (projectile_aimbot &&
|
||||||
@ -204,8 +187,25 @@ void CreateMove()
|
|||||||
if (proj_gravity)
|
if (proj_gravity)
|
||||||
cur_proj_grav = float(proj_gravity);
|
cur_proj_grav = float(proj_gravity);
|
||||||
}
|
}
|
||||||
if (BacktrackAimbot())
|
// Refresh our best target
|
||||||
|
CachedEntity *target_entity = RetrieveBestTarget(aimkey_status);
|
||||||
|
if (CE_BAD(target_entity) || !foundTarget)
|
||||||
return;
|
return;
|
||||||
|
// Auto-zoom
|
||||||
|
IF_GAME(IsTF())
|
||||||
|
{
|
||||||
|
if (auto_zoom)
|
||||||
|
{
|
||||||
|
if (g_pLocalPlayer->holding_sniper_rifle)
|
||||||
|
{
|
||||||
|
zoomTime.update();
|
||||||
|
if (not g_pLocalPlayer->bZoomed)
|
||||||
|
{
|
||||||
|
current_user_cmd->buttons |= IN_ATTACK2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!g_IEntityList->GetClientEntity(target_entity->m_IDX))
|
if (!g_IEntityList->GetClientEntity(target_entity->m_IDX))
|
||||||
return;
|
return;
|
||||||
@ -413,50 +413,58 @@ CachedEntity *RetrieveBestTarget(bool aimkey_state)
|
|||||||
CachedEntity *ent;
|
CachedEntity *ent;
|
||||||
CachedEntity *target_highest_ent = 0;
|
CachedEntity *target_highest_ent = 0;
|
||||||
target_highest_score = -256;
|
target_highest_score = -256;
|
||||||
|
if (!hacks::shared::backtrack::isBacktrackEnabled() || projectile_mode)
|
||||||
for (int i = 0; i < HIGHEST_ENTITY; i++)
|
|
||||||
{
|
{
|
||||||
ent = ENTITY(i);
|
for (int i = 0; i < HIGHEST_ENTITY; i++)
|
||||||
if (CE_BAD(ent))
|
|
||||||
continue; // Check for null and dormant
|
|
||||||
// Check whether the current ent is good enough to target
|
|
||||||
if (IsTargetStateGood(ent))
|
|
||||||
{
|
{
|
||||||
|
ent = ENTITY(i);
|
||||||
|
if (CE_BAD(ent))
|
||||||
|
continue; // Check for null and dormant
|
||||||
|
// Check whether the current ent is good enough to target
|
||||||
|
if (IsTargetStateGood(ent))
|
||||||
|
{
|
||||||
|
|
||||||
// Distance Priority, Uses this is melee is used
|
// Distance Priority, Uses this is melee is used
|
||||||
if (GetWeaponMode() == weaponmode::weapon_melee ||
|
if (GetWeaponMode() == weaponmode::weapon_melee ||
|
||||||
(int) priority_mode == 2)
|
(int) priority_mode == 2)
|
||||||
{
|
|
||||||
scr = 4096.0f -
|
|
||||||
calculated_data_array[i].aim_position.DistTo(
|
|
||||||
g_pLocalPlayer->v_Eye);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
switch ((int) priority_mode)
|
|
||||||
{
|
{
|
||||||
case 0: // Smart Priority
|
scr = 4096.0f -
|
||||||
scr = GetScoreForEntity(ent);
|
calculated_data_array[i].aim_position.DistTo(
|
||||||
break;
|
g_pLocalPlayer->v_Eye);
|
||||||
case 1: // Fov Priority
|
}
|
||||||
scr = 360.0f - calculated_data_array[ent->m_IDX].fov;
|
else
|
||||||
break;
|
{
|
||||||
case 3: // Health Priority
|
switch ((int) priority_mode)
|
||||||
scr = 450.0f - ent->m_iHealth();
|
{
|
||||||
break;
|
case 0: // Smart Priority
|
||||||
default:
|
scr = GetScoreForEntity(ent);
|
||||||
break;
|
break;
|
||||||
|
case 1: // Fov Priority
|
||||||
|
scr = 360.0f - calculated_data_array[ent->m_IDX].fov;
|
||||||
|
break;
|
||||||
|
case 3: // Health Priority
|
||||||
|
scr = 450.0f - ent->m_iHealth();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Compare the top score to our current ents score
|
||||||
|
if (scr > target_highest_score)
|
||||||
|
{
|
||||||
|
foundTarget = true;
|
||||||
|
target_highest_score = scr;
|
||||||
|
target_highest_ent = ent;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// Compare the top score to our current ents score
|
|
||||||
if (scr > target_highest_score)
|
|
||||||
{
|
|
||||||
foundTarget = true;
|
|
||||||
target_highest_score = scr;
|
|
||||||
target_highest_ent = ent;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (hacks::shared::backtrack::iBestTarget != -1)
|
||||||
|
{
|
||||||
|
target_highest_ent = ENTITY(hacks::shared::backtrack::iBestTarget);
|
||||||
|
foundTarget = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Save the ent for future use with target lock
|
// Save the ent for future use with target lock
|
||||||
target_last = target_highest_ent;
|
target_last = target_highest_ent;
|
||||||
|
|
||||||
@ -471,6 +479,9 @@ bool IsTargetStateGood(CachedEntity *entity)
|
|||||||
{
|
{
|
||||||
PROF_SECTION(PT_aimbot_targetstatecheck);
|
PROF_SECTION(PT_aimbot_targetstatecheck);
|
||||||
|
|
||||||
|
if (hacks::shared::backtrack::isBacktrackEnabled() &&
|
||||||
|
entity->m_Type() != ENTITY_PLAYER)
|
||||||
|
return false;
|
||||||
// Checks for Players
|
// Checks for Players
|
||||||
if (entity->m_Type() == ENTITY_PLAYER)
|
if (entity->m_Type() == ENTITY_PLAYER)
|
||||||
{
|
{
|
||||||
@ -584,7 +595,7 @@ bool IsTargetStateGood(CachedEntity *entity)
|
|||||||
// Vis check + fov check
|
// Vis check + fov check
|
||||||
if (!VischeckPredictedEntity(entity))
|
if (!VischeckPredictedEntity(entity))
|
||||||
return false;
|
return false;
|
||||||
if ((float) fov > 0.0f && cd.fov > (float) fov)
|
if (*fov > 0.0f && cd.fov > *fov)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -633,7 +644,7 @@ bool IsTargetStateGood(CachedEntity *entity)
|
|||||||
// Vis and fov checks
|
// Vis and fov checks
|
||||||
if (!VischeckPredictedEntity(entity))
|
if (!VischeckPredictedEntity(entity))
|
||||||
return false;
|
return false;
|
||||||
if ((float) fov > 0.0f && cd.fov > (float) fov)
|
if (*fov > 0.0f && cd.fov > *fov)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -677,7 +688,7 @@ bool IsTargetStateGood(CachedEntity *entity)
|
|||||||
// Vis and fov check
|
// Vis and fov check
|
||||||
if (!VischeckPredictedEntity(entity))
|
if (!VischeckPredictedEntity(entity))
|
||||||
return false;
|
return false;
|
||||||
if ((float) fov > 0.0f && cd.fov > (float) fov)
|
if (*fov > 0.0f && cd.fov > *fov)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -715,17 +726,35 @@ void Aim(CachedEntity *entity)
|
|||||||
// Get hitbox num
|
// Get hitbox num
|
||||||
AimbotCalculatedData_s &cd = calculated_data_array[entity->m_IDX];
|
AimbotCalculatedData_s &cd = calculated_data_array[entity->m_IDX];
|
||||||
float minx, maxx, miny, maxy, minz, maxz, centerx, centery, centerz;
|
float minx, maxx, miny, maxy, minz, maxz, centerx, centery, centerz;
|
||||||
auto hitbox = entity->hitboxes.GetHitbox(cd.hitbox);
|
auto hitboxmin = entity->hitboxes.GetHitbox(cd.hitbox)->min;
|
||||||
|
auto hitboxmax = entity->hitboxes.GetHitbox(cd.hitbox)->max;
|
||||||
|
auto hitboxcenter = entity->hitboxes.GetHitbox(cd.hitbox)->center;
|
||||||
|
if (hacks::shared::backtrack::isBacktrackEnabled())
|
||||||
|
{
|
||||||
|
hitboxcenter =
|
||||||
|
hacks::shared::backtrack::headPositions
|
||||||
|
[entity->m_IDX][hacks::shared::backtrack::BestTick]
|
||||||
|
.hitboxes[cd.hitbox]
|
||||||
|
.center;
|
||||||
|
hitboxmin = hacks::shared::backtrack::headPositions
|
||||||
|
[entity->m_IDX][hacks::shared::backtrack::BestTick]
|
||||||
|
.hitboxes[cd.hitbox]
|
||||||
|
.min;
|
||||||
|
hitboxmax = hacks::shared::backtrack::headPositions
|
||||||
|
[entity->m_IDX][hacks::shared::backtrack::BestTick]
|
||||||
|
.hitboxes[cd.hitbox]
|
||||||
|
.max;
|
||||||
|
}
|
||||||
// get positions
|
// get positions
|
||||||
minx = hitbox->min.x;
|
minx = hitboxmin.x;
|
||||||
miny = hitbox->min.y;
|
miny = hitboxmin.y;
|
||||||
maxx = hitbox->max.x;
|
maxx = hitboxmax.x;
|
||||||
maxy = hitbox->max.y;
|
maxy = hitboxmax.y;
|
||||||
minz = hitbox->min.z;
|
minz = hitboxmin.z;
|
||||||
maxz = hitbox->max.z;
|
maxz = hitboxmax.z;
|
||||||
centerx = hitbox->center.x;
|
centerx = hitboxcenter.x;
|
||||||
centery = hitbox->center.y;
|
centery = hitboxcenter.y;
|
||||||
centerz = hitbox->center.z;
|
centerz = hitboxcenter.z;
|
||||||
|
|
||||||
// Shrink positions
|
// Shrink positions
|
||||||
std::vector<Vector> positions;
|
std::vector<Vector> positions;
|
||||||
@ -749,7 +778,7 @@ void Aim(CachedEntity *entity)
|
|||||||
positions.push_back({ maxx, maxy, centerz });
|
positions.push_back({ maxx, maxy, centerz });
|
||||||
positions.push_back({ minx, miny, centerz });
|
positions.push_back({ minx, miny, centerz });
|
||||||
positions.push_back({ maxx, maxy, centerz });
|
positions.push_back({ maxx, maxy, centerz });
|
||||||
positions.push_back(hitbox->center);
|
positions.push_back(hitboxcenter);
|
||||||
for (auto pos : positions)
|
for (auto pos : positions)
|
||||||
if (IsVectorVisible(g_pLocalPlayer->v_Eye, pos))
|
if (IsVectorVisible(g_pLocalPlayer->v_Eye, pos))
|
||||||
{
|
{
|
||||||
@ -771,7 +800,15 @@ void Aim(CachedEntity *entity)
|
|||||||
|
|
||||||
if (silent && !slow_aim)
|
if (silent && !slow_aim)
|
||||||
g_pLocalPlayer->bUseSilentAngles = true;
|
g_pLocalPlayer->bUseSilentAngles = true;
|
||||||
|
if (hacks::shared::backtrack::isBacktrackEnabled())
|
||||||
|
{
|
||||||
|
auto i = hacks::shared::backtrack::headPositions
|
||||||
|
[hacks::shared::backtrack::iBestTarget]
|
||||||
|
[hacks::shared::backtrack::BestTick];
|
||||||
|
current_user_cmd->tick_count = i.tickcount;
|
||||||
|
float &simtime = NET_FLOAT(RAW_ENT(entity), netvar.m_flSimulationTime);
|
||||||
|
simtime = i.simtime;
|
||||||
|
}
|
||||||
// Finish function
|
// Finish function
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -888,45 +925,64 @@ const Vector &PredictEntity(CachedEntity *entity)
|
|||||||
if (cd.predict_tick == tickcount)
|
if (cd.predict_tick == tickcount)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
// Players
|
if (!hacks::shared::backtrack::isBacktrackEnabled() || projectile_mode)
|
||||||
if ((entity->m_Type() == ENTITY_PLAYER))
|
|
||||||
{
|
{
|
||||||
// If using projectiles, predict a vector
|
|
||||||
if (projectileAimbotRequired)
|
// Players
|
||||||
|
if ((entity->m_Type() == ENTITY_PLAYER))
|
||||||
{
|
{
|
||||||
// Use prediction engine if user settings allow
|
// If using projectiles, predict a vector
|
||||||
if (engine_projpred)
|
if (projectileAimbotRequired)
|
||||||
result = ProjectilePrediction_Engine(
|
{
|
||||||
entity, cd.hitbox, cur_proj_speed, cur_proj_grav, 0);
|
// Use prediction engine if user settings allow
|
||||||
|
if (engine_projpred)
|
||||||
|
result = ProjectilePrediction_Engine(
|
||||||
|
entity, cd.hitbox, cur_proj_speed, cur_proj_grav, 0);
|
||||||
|
else
|
||||||
|
result = ProjectilePrediction(entity, cd.hitbox,
|
||||||
|
cur_proj_speed, cur_proj_grav,
|
||||||
|
PlayerGravityMod(entity));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
result = ProjectilePrediction(entity, cd.hitbox, cur_proj_speed,
|
{
|
||||||
cur_proj_grav,
|
// If using extrapolation, then predict a vector
|
||||||
PlayerGravityMod(entity));
|
if (extrapolate)
|
||||||
|
result = SimpleLatencyPrediction(entity, cd.hitbox);
|
||||||
|
// else just grab strait from the hitbox
|
||||||
|
else
|
||||||
|
GetHitbox(entity, cd.hitbox, result);
|
||||||
|
}
|
||||||
|
// Buildings
|
||||||
|
}
|
||||||
|
else if (entity->m_Type() == ENTITY_BUILDING)
|
||||||
|
{
|
||||||
|
result = GetBuildingPosition(entity);
|
||||||
|
// Other
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// If using extrapolation, then predict a vector
|
result = entity->m_vecOrigin();
|
||||||
if (extrapolate)
|
|
||||||
result = SimpleLatencyPrediction(entity, cd.hitbox);
|
|
||||||
// else just grab strait from the hitbox
|
|
||||||
else
|
|
||||||
GetHitbox(entity, cd.hitbox, result);
|
|
||||||
}
|
}
|
||||||
// Buildings
|
|
||||||
}
|
cd.predict_tick = tickcount;
|
||||||
else if (entity->m_Type() == ENTITY_BUILDING)
|
|
||||||
{
|
cd.fov = GetFov(g_pLocalPlayer->v_OrigViewangles, g_pLocalPlayer->v_Eye,
|
||||||
result = GetBuildingPosition(entity);
|
result);
|
||||||
// Other
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result = entity->m_vecOrigin();
|
// Players only
|
||||||
|
if ((entity->m_Type() == ENTITY_PLAYER))
|
||||||
|
{
|
||||||
|
auto hb = hacks::shared::backtrack::headPositions
|
||||||
|
[entity->m_IDX]
|
||||||
|
[hacks::shared::backtrack::BestTick];
|
||||||
|
cd.predict_tick = tickcount;
|
||||||
|
result = hb.hitboxes[cd.hitbox].center;
|
||||||
|
cd.fov = GetFov(g_pLocalPlayer->v_OrigViewangles,
|
||||||
|
g_pLocalPlayer->v_Eye, result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cd.predict_tick = tickcount;
|
|
||||||
cd.fov =
|
|
||||||
GetFov(g_pLocalPlayer->v_OrigViewangles, g_pLocalPlayer->v_Eye, result);
|
|
||||||
// Return the found vector
|
// Return the found vector
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -1114,7 +1170,16 @@ bool VischeckPredictedEntity(CachedEntity *entity)
|
|||||||
|
|
||||||
// Update info
|
// Update info
|
||||||
cd.vcheck_tick = tickcount;
|
cd.vcheck_tick = tickcount;
|
||||||
cd.visible = IsEntityVectorVisible(entity, PredictEntity(entity));
|
if (!hacks::shared::backtrack::isBacktrackEnabled() || projectile_mode)
|
||||||
|
cd.visible = IsEntityVectorVisible(entity, PredictEntity(entity));
|
||||||
|
else
|
||||||
|
cd.visible = IsVectorVisible(
|
||||||
|
g_pLocalPlayer->v_Eye,
|
||||||
|
hacks::shared::backtrack::headPositions
|
||||||
|
[entity->m_IDX][hacks::shared::backtrack::BestTick]
|
||||||
|
.hitboxes[cd.hitbox]
|
||||||
|
.center,
|
||||||
|
true);
|
||||||
return cd.visible;
|
return cd.visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,9 +45,9 @@ int ClosestDistanceHitbox(CachedEntity *target,
|
|||||||
{
|
{
|
||||||
int closest = -1;
|
int closest = -1;
|
||||||
float closest_dist = 0.0f, dist = 0.0f;
|
float closest_dist = 0.0f, dist = 0.0f;
|
||||||
for (int i = spine_0; i < spine_3; i++)
|
for (int i = pelvis; i < lowerArm_R; i++)
|
||||||
{
|
{
|
||||||
if (hacks::shared::backtrack::isBacktrackEnabled())
|
if (hacks::shared::backtrack::isBacktrackEnabled)
|
||||||
dist = g_pLocalPlayer->v_Eye.DistTo(btd.hitboxes.at(i).center);
|
dist = g_pLocalPlayer->v_Eye.DistTo(btd.hitboxes.at(i).center);
|
||||||
else
|
else
|
||||||
dist = g_pLocalPlayer->v_Eye.DistTo(
|
dist = g_pLocalPlayer->v_Eye.DistTo(
|
||||||
@ -67,7 +67,7 @@ bool unifiedCanBackstab(Vector &vecAngle, Vector min, Vector max,
|
|||||||
// Get melee range
|
// Get melee range
|
||||||
float meleeRange = re::C_TFWeaponBaseMelee::GetSwingRange(RAW_ENT(LOCAL_W));
|
float meleeRange = re::C_TFWeaponBaseMelee::GetSwingRange(RAW_ENT(LOCAL_W));
|
||||||
if (fabsf(vecAngle.y -
|
if (fabsf(vecAngle.y -
|
||||||
NET_VECTOR(RAW_ENT(besttarget), netvar.m_angEyeAngles).y) >= 50)
|
NET_VECTOR(RAW_ENT(besttarget), netvar.m_angEyeAngles).y) >= 60.0f)
|
||||||
return false;
|
return false;
|
||||||
if (!min.x && !max.x)
|
if (!min.x && !max.x)
|
||||||
return false;
|
return false;
|
||||||
@ -122,7 +122,7 @@ void CreateMove()
|
|||||||
if (!CanShoot())
|
if (!CanShoot())
|
||||||
return;
|
return;
|
||||||
CachedEntity *besttarget = nullptr;
|
CachedEntity *besttarget = nullptr;
|
||||||
if (!backtrack::isBacktrackEnabled())
|
if (!backtrack::isBacktrackEnabled)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < g_IEngine->GetMaxClients(); i++)
|
for (int i = 0; i < g_IEngine->GetMaxClients(); i++)
|
||||||
{
|
{
|
||||||
@ -173,7 +173,7 @@ void CreateMove()
|
|||||||
{
|
{
|
||||||
hacks::shared::anti_anti_aim::resolveEnt(besttarget->m_IDX);
|
hacks::shared::anti_anti_aim::resolveEnt(besttarget->m_IDX);
|
||||||
Vector angle = NET_VECTOR(RAW_ENT(LOCAL_E), netvar.m_angEyeAngles);
|
Vector angle = NET_VECTOR(RAW_ENT(LOCAL_E), netvar.m_angEyeAngles);
|
||||||
if (!backtrack::isBacktrackEnabled())
|
if (!backtrack::isBacktrackEnabled)
|
||||||
{
|
{
|
||||||
for (angle.y = -180.0f; angle.y < 180.0f; angle.y += 10.0f)
|
for (angle.y = -180.0f; angle.y < 180.0f; angle.y += 10.0f)
|
||||||
{
|
{
|
||||||
|
@ -22,10 +22,12 @@ namespace hacks::shared::backtrack
|
|||||||
{
|
{
|
||||||
void EmptyBacktrackData(BacktrackData &i);
|
void EmptyBacktrackData(BacktrackData &i);
|
||||||
std::pair<int, int> getBestEntBestTick();
|
std::pair<int, int> getBestEntBestTick();
|
||||||
|
bool shouldBacktrack();
|
||||||
|
|
||||||
BacktrackData headPositions[32][66]{};
|
BacktrackData headPositions[32][66]{};
|
||||||
int highesttick[32]{};
|
int highesttick[32]{};
|
||||||
int lastincomingsequencenumber = 0;
|
int lastincomingsequencenumber = 0;
|
||||||
static bool shouldDrawBt;
|
bool isBacktrackEnabled = false;
|
||||||
|
|
||||||
circular_buf sequences{ 2048 };
|
circular_buf sequences{ 2048 };
|
||||||
void UpdateIncomingSequences()
|
void UpdateIncomingSequences()
|
||||||
@ -48,6 +50,8 @@ void UpdateIncomingSequences()
|
|||||||
}
|
}
|
||||||
void AddLatencyToNetchan(INetChannel *ch, float Latency)
|
void AddLatencyToNetchan(INetChannel *ch, float Latency)
|
||||||
{
|
{
|
||||||
|
if (!isBacktrackEnabled)
|
||||||
|
return;
|
||||||
if (Latency > 200.0f)
|
if (Latency > 200.0f)
|
||||||
Latency -= ch->GetLatency(MAX_FLOWS);
|
Latency -= ch->GetLatency(MAX_FLOWS);
|
||||||
for (auto &seq : sequences)
|
for (auto &seq : sequences)
|
||||||
@ -69,21 +73,24 @@ void Init()
|
|||||||
|
|
||||||
int BestTick = 0;
|
int BestTick = 0;
|
||||||
int iBestTarget = -1;
|
int iBestTarget = -1;
|
||||||
|
bool istickvalid[66]{};
|
||||||
|
bool istickinvalid[66]{};
|
||||||
void Run()
|
void Run()
|
||||||
{
|
{
|
||||||
if (!enable)
|
if (!shouldBacktrack())
|
||||||
|
{
|
||||||
|
isBacktrackEnabled = false;
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
isBacktrackEnabled = true;
|
||||||
|
|
||||||
if (CE_BAD(LOCAL_E))
|
if (CE_BAD(LOCAL_E))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!shouldBacktrack())
|
for (auto &a : istickvalid)
|
||||||
{
|
a = false;
|
||||||
shouldDrawBt = false;
|
for (auto &a : istickinvalid)
|
||||||
return;
|
a = false;
|
||||||
}
|
|
||||||
shouldDrawBt = true;
|
|
||||||
|
|
||||||
CUserCmd *cmd = current_user_cmd;
|
CUserCmd *cmd = current_user_cmd;
|
||||||
float bestFov = 99999;
|
float bestFov = 99999;
|
||||||
|
|
||||||
@ -124,7 +131,7 @@ void Run()
|
|||||||
auto hdr = g_IModelInfo->GetStudiomodel(RAW_ENT(pEntity)->GetModel());
|
auto hdr = g_IModelInfo->GetStudiomodel(RAW_ENT(pEntity)->GetModel());
|
||||||
headPositions[i][cmd->command_number % getTicks()] =
|
headPositions[i][cmd->command_number % getTicks()] =
|
||||||
BacktrackData{ cmd->tick_count, hbdArray, viewangles, simtime,
|
BacktrackData{ cmd->tick_count, hbdArray, viewangles, simtime,
|
||||||
ent_orig };
|
ent_orig, cmd->command_number % getTicks() };
|
||||||
}
|
}
|
||||||
if (iBestTarget != -1 && CanShoot())
|
if (iBestTarget != -1 && CanShoot())
|
||||||
{
|
{
|
||||||
@ -151,12 +158,10 @@ void Run()
|
|||||||
void Draw()
|
void Draw()
|
||||||
{
|
{
|
||||||
#if ENABLE_VISUALS
|
#if ENABLE_VISUALS
|
||||||
if (!enable)
|
if (!isBacktrackEnabled)
|
||||||
return;
|
return;
|
||||||
if (!draw_bt)
|
if (!draw_bt)
|
||||||
return;
|
return;
|
||||||
if (!shouldDrawBt)
|
|
||||||
return;
|
|
||||||
for (int i = 0; i < g_IEngine->GetMaxClients(); i++)
|
for (int i = 0; i < g_IEngine->GetMaxClients(); i++)
|
||||||
{
|
{
|
||||||
CachedEntity *ent = ENTITY(i);
|
CachedEntity *ent = ENTITY(i);
|
||||||
@ -192,10 +197,16 @@ void Draw()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Internal only, use isBacktrackEnabled var instead
|
||||||
bool shouldBacktrack()
|
bool shouldBacktrack()
|
||||||
{
|
{
|
||||||
|
if (!*enable)
|
||||||
|
return false;
|
||||||
|
CachedEntity *wep = g_pLocalPlayer->weapon();
|
||||||
|
if (CE_BAD(wep))
|
||||||
|
return false;
|
||||||
int slot =
|
int slot =
|
||||||
re::C_BaseCombatWeapon::GetSlot(RAW_ENT(g_pLocalPlayer->weapon()));
|
re::C_BaseCombatWeapon::GetSlot(RAW_ENT(wep));
|
||||||
switch ((int) slots)
|
switch ((int) slots)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
@ -229,11 +240,6 @@ bool shouldBacktrack()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isBacktrackEnabled()
|
|
||||||
{
|
|
||||||
return *enable;
|
|
||||||
}
|
|
||||||
|
|
||||||
float getLatency()
|
float getLatency()
|
||||||
{
|
{
|
||||||
return *latency;
|
return *latency;
|
||||||
@ -246,8 +252,19 @@ int getTicks()
|
|||||||
|
|
||||||
bool ValidTick(BacktrackData &i, CachedEntity *ent)
|
bool ValidTick(BacktrackData &i, CachedEntity *ent)
|
||||||
{
|
{
|
||||||
return fabsf(NET_FLOAT(RAW_ENT(ent), netvar.m_flSimulationTime) * 1000.0f -
|
if (istickvalid[i.index])
|
||||||
getLatency() - i.simtime * 1000.0f) < 200.0f;
|
return true;
|
||||||
|
if (istickinvalid[i.index])
|
||||||
|
return false;
|
||||||
|
if (IsVectorVisible(g_pLocalPlayer->v_Eye, i.hitboxes[head].center, true))
|
||||||
|
if (fabsf(NET_FLOAT(RAW_ENT(ent), netvar.m_flSimulationTime) * 1000.0f -
|
||||||
|
getLatency() - i.simtime * 1000.0f) < 200.0f)
|
||||||
|
{
|
||||||
|
istickvalid[i.index] = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
istickinvalid[i.index] = true;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmptyBacktrackData(BacktrackData &i)
|
void EmptyBacktrackData(BacktrackData &i)
|
||||||
|
@ -45,7 +45,9 @@ int last_hb_traced = 0;
|
|||||||
Vector forward;
|
Vector forward;
|
||||||
bool CanBacktrack()
|
bool CanBacktrack()
|
||||||
{
|
{
|
||||||
CachedEntity *tar = ENTITY(hacks::shared::backtrack::iBestTarget);
|
CachedEntity *tar = (hacks::shared::backtrack::iBestTarget != -1)
|
||||||
|
? ENTITY(hacks::shared::backtrack::iBestTarget)
|
||||||
|
: nullptr;
|
||||||
if (CE_BAD(tar))
|
if (CE_BAD(tar))
|
||||||
return false;
|
return false;
|
||||||
for (auto i : hacks::shared::backtrack::headPositions[tar->m_IDX])
|
for (auto i : hacks::shared::backtrack::headPositions[tar->m_IDX])
|
||||||
@ -113,7 +115,7 @@ void CreateMove()
|
|||||||
CachedEntity *ent = FindEntInSight(EffectiveTargetingRange());
|
CachedEntity *ent = FindEntInSight(EffectiveTargetingRange());
|
||||||
|
|
||||||
// Check if can backtrack, shoot if we can
|
// Check if can backtrack, shoot if we can
|
||||||
if (!CanBacktrack() || hacks::shared::backtrack::isBacktrackEnabled())
|
if (!CanBacktrack() || hacks::shared::backtrack::isBacktrackEnabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Check if dormant or null to prevent crashes
|
// Check if dormant or null to prevent crashes
|
||||||
|
139
src/pathfinder.cpp
Normal file
139
src/pathfinder.cpp
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
#include "common.hpp"
|
||||||
|
#include "external/TF2_NavFile_Reader/CNavFile.h"
|
||||||
|
#include "external/PathFinder/src/PathFinder.h"
|
||||||
|
#include "external/PathFinder/src/AStar.h"
|
||||||
|
|
||||||
|
namespace hacks::shared::pathfinder
|
||||||
|
{
|
||||||
|
Vector loc;
|
||||||
|
//std::vector<Vector> findPath(Vector loc, Vector dest);
|
||||||
|
//bool initiatenavfile();
|
||||||
|
|
||||||
|
//CatCommand navset("nav_set", "Debug nav set",
|
||||||
|
// [](const CCommand &args) { loc = g_pLocalPlayer->v_Origin; });
|
||||||
|
|
||||||
|
//CatCommand navfind("nav_find", "Debug nav find", [](const CCommand &args) {
|
||||||
|
// std::vector<Vector> path = findPath(g_pLocalPlayer->v_Origin, loc);
|
||||||
|
// if (path.empty())
|
||||||
|
// {
|
||||||
|
// logging::Info("Pathing: No path found");
|
||||||
|
// }
|
||||||
|
// std::string output = "Pathing: Path found! Path: ";
|
||||||
|
// for (int i = 0; i < path.size(); i++)
|
||||||
|
// {
|
||||||
|
// output.append(format(path.at(i).x, ",", format(path.at(i).y)));
|
||||||
|
// }
|
||||||
|
// logging::Info(output.c_str());
|
||||||
|
//});
|
||||||
|
|
||||||
|
//CatCommand navinit("nav_init", "Debug nav init",
|
||||||
|
// [](const CCommand &args) { initiatenavfile(); });
|
||||||
|
|
||||||
|
class navNode : public AStarNode
|
||||||
|
{
|
||||||
|
// navNode()
|
||||||
|
// {
|
||||||
|
// }
|
||||||
|
|
||||||
|
// ~navNode()
|
||||||
|
// {
|
||||||
|
// }
|
||||||
|
public:
|
||||||
|
Vector vecLoc;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<navNode *> nodes;
|
||||||
|
//settings::Bool enabled{ "pathing.enabled", 0 };
|
||||||
|
|
||||||
|
bool initiatenavfile()
|
||||||
|
{
|
||||||
|
//if (!enabled)
|
||||||
|
// return false;
|
||||||
|
logging::Info("Pathing: Initiating path...");
|
||||||
|
|
||||||
|
// This will not work, please fix
|
||||||
|
std::string dir =
|
||||||
|
"/home/elite/.steam/steam/steamapps/common/Team Fortress 2/tf/maps/";
|
||||||
|
std::string levelName = g_IEngine->GetLevelName();
|
||||||
|
int dotpos = levelName.find('.');
|
||||||
|
levelName = levelName.substr(0, dotpos);
|
||||||
|
levelName.append(".nav");
|
||||||
|
dir.append(levelName);
|
||||||
|
|
||||||
|
CNavFile navData(dir.c_str());
|
||||||
|
if (!navData.m_isOK)
|
||||||
|
{
|
||||||
|
logging::Info("Pathing: Failed to parse nav file!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
std::vector<CNavArea> *areas = &navData.m_areas;
|
||||||
|
int nodeCount = areas->size();
|
||||||
|
|
||||||
|
nodes.clear();
|
||||||
|
nodes.reserve(nodeCount);
|
||||||
|
|
||||||
|
// register nodes
|
||||||
|
for (int i = 0; i < nodeCount; i++)
|
||||||
|
{
|
||||||
|
navNode *node{};
|
||||||
|
// node->setPosition(areas->at(i).m_center.x, areas->at(i).m_center.y);
|
||||||
|
node->vecLoc = areas->at(i).m_center;
|
||||||
|
nodes.push_back(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < nodeCount; ++i)
|
||||||
|
{
|
||||||
|
std::vector<NavConnect> *connections = &areas->at(i).m_connections;
|
||||||
|
int childCount = connections->size();
|
||||||
|
navNode *currNode = nodes.at(i);
|
||||||
|
for (int j = 0; j < childCount; j++)
|
||||||
|
{
|
||||||
|
currNode->addChild(nodes.at(connections->at(j).id), 1.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
logging::Info("Path init successful");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int findClosestNavSquare(Vector vec)
|
||||||
|
{
|
||||||
|
float bestDist = 999999.0f;
|
||||||
|
int bestSquare = -1;
|
||||||
|
for (int i = 0; i < nodes.size(); i++)
|
||||||
|
{
|
||||||
|
float dist = nodes.at(i)->vecLoc.DistTo(vec);
|
||||||
|
if (dist < bestDist)
|
||||||
|
{
|
||||||
|
bestDist = dist;
|
||||||
|
bestSquare = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bestSquare;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<Vector> findPath(Vector loc, Vector dest)
|
||||||
|
{
|
||||||
|
if (nodes.empty())
|
||||||
|
return std::vector<Vector>(0);
|
||||||
|
|
||||||
|
int id_loc = findClosestNavSquare(loc);
|
||||||
|
int id_dest = findClosestNavSquare(dest);
|
||||||
|
|
||||||
|
navNode &node_loc = *nodes.at(id_loc);
|
||||||
|
navNode &node_dest = *nodes.at(id_dest);
|
||||||
|
|
||||||
|
PathFinder<navNode> p;
|
||||||
|
std::vector<navNode*> pathNodes;
|
||||||
|
|
||||||
|
p.setStart(node_loc);
|
||||||
|
p.setGoal(node_dest);
|
||||||
|
|
||||||
|
p.findPath<navNode>(pathNodes);
|
||||||
|
|
||||||
|
std::vector<Vector> path;
|
||||||
|
for (int i = 0; i < pathNodes.size(); i++)
|
||||||
|
{
|
||||||
|
path.push_back(pathNodes.at(i)->vecLoc);
|
||||||
|
}
|
||||||
|
return path;
|
||||||
|
}}
|
Reference in New Issue
Block a user