FINALLY fixed followbot movement.
This commit is contained in:
parent
e67b22781a
commit
e2b53b65f3
1
detach
1
detach
@ -27,6 +27,7 @@ if grep -q $(realpath bin/libcathook.so) /proc/${arr[$1]}/maps; then
|
||||
-ex "set \$dlclose = (int(*)(void*)) dlclose" \
|
||||
-ex "set \$library = \$dlopen(\"$(realpath libcathook.so)\", 6)" \
|
||||
-ex "print \$library" \
|
||||
-ex "sharedlibrary ." \
|
||||
-ex "call \$dlclose(\$library)" \
|
||||
-ex "call \$dlclose(\$library)" \
|
||||
-ex "continue" \
|
||||
|
8
makefile
8
makefile
@ -1,4 +1,4 @@
|
||||
CXX=g++
|
||||
CXX=g++-6
|
||||
CXXFLAGS=-std=gnu++14 -D_GLIBCXX_USE_CXX11_ABI=0 -D_POSIX=1 -DRAD_TELEMETRY_DISABLED -DLINUX=1 -D_LINUX=1 -DPOSIX=1 -DGNUC=1 -D_DEVELOPER=1 -DNO_MALLOC_OVERRIDE -O3 -g3 -ggdb -w -shared -Wall -Wno-unknown-pragmas -fmessage-length=0 -m32 -fvisibility=hidden -fPIC
|
||||
SDKFOLDER=$(realpath source-sdk-2013/mp/src)
|
||||
SIMPLE_IPC_DIR = $(realpath simple-ipc/src/include)
|
||||
@ -6,7 +6,7 @@ INCLUDES=-I$(SIMPLE_IPC_DIR) -I$(SDKFOLDER)/public -I$(SDKFOLDER)/mathlib -I$(SD
|
||||
CXXFLAGS += $(INCLUDES)
|
||||
LIB_DIR=lib
|
||||
LDFLAGS=-m32 -fno-gnu-unique -D_GLIBCXX_USE_CXX11_ABI=0 -shared -L$(realpath $(LIB_DIR))
|
||||
LDLIBS=-static -l:libstdc++.so.6 -l:libc.so.6 -ltier0 -lvstdlib
|
||||
LDLIBS=-static -l:libc.so.6 -l:libstdc++.so.6 -ltier0 -lvstdlib
|
||||
SRC_DIR = src
|
||||
OUT_NAME = libcathook.so
|
||||
TARGET_DIR = bin
|
||||
@ -37,4 +37,6 @@ clean:
|
||||
find . -type f -name '*.d' -delete
|
||||
rm -rf ./bin
|
||||
|
||||
-include $(DEPENDS)
|
||||
ifneq ($(MAKECMDGOALS), clean)
|
||||
-include $(DEPENDS)
|
||||
endif
|
@ -8,12 +8,14 @@
|
||||
#include <pthread.h>
|
||||
|
||||
#include "hack.h"
|
||||
#include "logging.h"
|
||||
|
||||
pthread_mutex_t mutex_quit;
|
||||
pthread_t thread_main;
|
||||
|
||||
bool IsStopping(pthread_mutex_t* mutex_quit_l) {
|
||||
if (!pthread_mutex_trylock(mutex_quit_l)) {
|
||||
logging::Info("Shutting down, unlocking mutex");
|
||||
pthread_mutex_unlock(mutex_quit_l);
|
||||
return true;
|
||||
} else {
|
||||
@ -25,10 +27,13 @@ bool IsStopping(pthread_mutex_t* mutex_quit_l) {
|
||||
void* MainThread(void* arg) {
|
||||
pthread_mutex_t* mutex_quit_l = (pthread_mutex_t*) arg;
|
||||
hack::Initialize();
|
||||
logging::Info("Init done...");
|
||||
while (!IsStopping(mutex_quit_l)) {
|
||||
hack::Think();
|
||||
}
|
||||
logging::Info("Shutting down...");
|
||||
hack::Shutdown();
|
||||
logging::Shutdown();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -40,6 +45,7 @@ void __attribute__((constructor)) attach() {
|
||||
}
|
||||
|
||||
void __attribute__((destructor)) detach() {
|
||||
logging::Info("Detaching");
|
||||
pthread_mutex_unlock(&mutex_quit);
|
||||
pthread_join(thread_main, 0);
|
||||
}
|
||||
|
@ -178,13 +178,16 @@ void hack::Think() {
|
||||
void hack::Shutdown() {
|
||||
if (hack::shutdown) return;
|
||||
hack::shutdown = true;
|
||||
logging::Shutdown();
|
||||
logging::Info("Killing hooks..");
|
||||
if (hooks::hkPanel) hooks::hkPanel->Kill();
|
||||
if (hooks::hkClientMode) hooks::hkClientMode->Kill();
|
||||
if (hooks::hkClient) hooks::hkClient->Kill();
|
||||
if (hooks::hkMatSurface) hooks::hkMatSurface->Kill();
|
||||
if (hooks::hkNetChannel) hooks::hkNetChannel->Kill();
|
||||
if (hooks::hkStudioRender) hooks::hkStudioRender->Kill();
|
||||
logging::Info("Unregistering convars..");
|
||||
ConVar_Unregister();
|
||||
logging::Info("Shutting down killsay...");
|
||||
hacks::shared::killsay::Shutdown();
|
||||
logging::Info("Success..");
|
||||
}
|
||||
|
@ -88,6 +88,7 @@ int HealingPriority(int idx) {
|
||||
bool CanHeal(int idx) {
|
||||
CachedEntity* ent = ENTITY(idx);
|
||||
if (!ent) return false;
|
||||
if (CE_BAD(ent)) return false;
|
||||
if (ent->m_Type != ENTITY_PLAYER) return false;
|
||||
if (g_IEngine->GetLocalPlayer() == idx) return false;
|
||||
if (!ent->m_bAlivePlayer) return false;
|
||||
|
@ -14,6 +14,7 @@ namespace hacks { namespace shared { namespace followbot {
|
||||
unsigned follow_steamid { 0 };
|
||||
Vector last_direction;
|
||||
float lost_time { 0 };
|
||||
float idle_time { 0 };
|
||||
int following_idx { 0 };
|
||||
|
||||
CatCommand move_to_crosshair("fb_move_to_point", "Moves a bot (or all bots) to crosshair", [](const CCommand& args) {
|
||||
@ -27,35 +28,57 @@ CatCommand follow_entity("fb_follow_entity", "Follows entity with specified enti
|
||||
});
|
||||
CatVar bot(CV_SWITCH, "fb_bot", "0", "This player is a bot", "Set to 1 in followbots' configs");
|
||||
|
||||
// I've spent 2 days on writing this method.
|
||||
// I couldn't succeed.
|
||||
// Just removed everything and put movement fix code from createmove here.
|
||||
std::pair<float, float> ComputeMove(const Vector& a, const Vector& b) {
|
||||
Vector diff = (b - a);
|
||||
if (diff.Length() == 0) return { 0, 0 };
|
||||
float v_cos = diff.x / diff.Length();
|
||||
float rad = acos(v_cos);
|
||||
if (diff.y < 0) rad = -rad;
|
||||
const float x = diff.x;
|
||||
const float y = diff.y;
|
||||
Vector vsilent(x, y, 0);
|
||||
float speed = sqrt(vsilent.x * vsilent.x + vsilent.y * vsilent.y);
|
||||
Vector ang;
|
||||
VectorAngles(vsilent, ang);
|
||||
float yaw = DEG2RAD(ang.y - g_pUserCmd->viewangles.y);
|
||||
return { cos(yaw) * 450, -sin(yaw) * 450 };
|
||||
}
|
||||
|
||||
// I've removed that too early.
|
||||
void PrintDebug() {
|
||||
|
||||
const Vector& a = LOCAL_E->m_vecOrigin;
|
||||
const Vector& b = last_direction;
|
||||
|
||||
Vector diff = (b - a);
|
||||
if (diff.Length() == 0) return;
|
||||
AddSideString(format("dx: ", diff.x));
|
||||
AddSideString(format("dy: ", diff.y));
|
||||
//float v_cos = diff.x / diff.Length();
|
||||
//float rad = acos(v_cos);
|
||||
//if (diff.y < 0) rad = 2 * PI - rad;
|
||||
//AddSideString(format("angle: ", rad / PI, " PI"));
|
||||
float yan = g_Settings.last_angles.y;
|
||||
float yaw = DEG2RAD(yan);
|
||||
float rad_diff = yaw - rad;
|
||||
//g_pUserCmd->forwardmove = std::cos(rad_diff) * 450.0f;
|
||||
//g_pUserCmd->sidemove = -std::sin(rad_diff) * 450.0f;
|
||||
//float deg_move = DEG2RAD(g_pUserCmd->viewangles.y);
|
||||
// xcosA + ysinA
|
||||
// xsinA + ycosA
|
||||
const float x = diff.x / diff.Length();
|
||||
const float y = diff.y / diff.Length();
|
||||
AddSideString(format("yaw: ", yaw / PI, " PI"));
|
||||
//float rad_diff = yaw - rad;
|
||||
//AddSideString(format("diff: ", rad_diff / PI, " PI"));
|
||||
|
||||
const float xmove = (std::cos(yaw) * x + std::sin(yaw) * y);
|
||||
const float ymove = (yaw < 0 ? 1 : 1) * (std::sin(yaw) * x + std::cos(yaw) * y);
|
||||
const float movesum = std::abs(xmove) + std::abs(ymove);
|
||||
|
||||
return { (xmove / movesum) * 450.0f, (ymove / movesum) * 450.0f };
|
||||
auto move = ComputeMove(a, b);
|
||||
AddSideString(format("forward: ", move.first));
|
||||
AddSideString(format("side: ", move.second));
|
||||
}
|
||||
|
||||
void WalkTo(const Vector& vector) {
|
||||
if (CE_VECTOR(LOCAL_E, netvar.vVelocity).IsZero(1.0f)) {
|
||||
if (!idle_time) idle_time = g_GlobalVars->curtime;
|
||||
if (LOCAL_E->m_vecOrigin.DistTo(vector) > 200.0f) {
|
||||
if (!g_pLocalPlayer->bZoomed)
|
||||
g_pUserCmd->buttons |= IN_JUMP;
|
||||
if (g_GlobalVars->curtime - idle_time > 2.0f) {
|
||||
if (!g_pLocalPlayer->bZoomed)
|
||||
g_pUserCmd->buttons |= IN_JUMP;
|
||||
}
|
||||
} else {
|
||||
idle_time = 0;
|
||||
}
|
||||
}
|
||||
auto result = ComputeMove(LOCAL_E->m_vecOrigin, last_direction);
|
||||
|
@ -21,8 +21,8 @@ CatVar logo(CV_SWITCH, "logo", "1", "Show logo", "Show cathook text in top left
|
||||
void PaintTraverse_hook(void* p, unsigned int vp, bool fr, bool ar) {
|
||||
#if DEBUG_SEGV == true
|
||||
if (!segvcatch::handler_fpe || !segvcatch::handler_segv) {
|
||||
segvcatch::init_segv();
|
||||
segvcatch::init_fpe();
|
||||
//segvcatch::init_segv();
|
||||
//segvcatch::init_fpe();
|
||||
}
|
||||
#endif
|
||||
SEGV_BEGIN;
|
||||
|
Reference in New Issue
Block a user