Skip to content

Commit 0d7072b

Browse files
committed
feat: move to point tool
1 parent 4d488ab commit 0d7072b

File tree

3 files changed

+100
-0
lines changed

3 files changed

+100
-0
lines changed

src/Features/Tas/TasTool.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ std::vector<std::string> TasTool::priorityList = {
3131
"move",
3232
"strafe",
3333
"decel",
34+
"moveto",
3435
};
3536

3637
TasTool::TasTool(const char *name, int slot)
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#include "MoveToTool.hpp"
2+
3+
#include "Features/Tas/TasParser.hpp"
4+
#include "Modules/Console.hpp"
5+
#include "Modules/Server.hpp"
6+
#include "StrafeTool.hpp"
7+
8+
MoveToTool moveToTool[2] = {{0}, {1}};
9+
10+
std::shared_ptr<TasToolParams> MoveToTool::ParseParams(std::vector<std::string> args) {
11+
// if (args.size() == 1) {
12+
// throw TasParserException(Utils::ssprintf("Wrong argument count for tool %s: %d", this->GetName(), args.size()));
13+
// }
14+
if (args[0] == "off") {
15+
return std::make_shared<TasToolParams>(false);
16+
}
17+
18+
float x;
19+
float y;
20+
21+
try {
22+
x = std::stof(args[0]);
23+
} catch (...) {
24+
throw TasParserException(Utils::ssprintf("Bad x value for tool %s: %s", this->GetName(), args[0].c_str()));
25+
}
26+
27+
try {
28+
y = std::stof(args[1]);
29+
} catch (...) {
30+
throw TasParserException(Utils::ssprintf("Bad y value for tool %s: %s", this->GetName(), args[1].c_str()));
31+
}
32+
33+
return std::make_shared<MoveToParams>(Vector{x, y});
34+
}
35+
36+
void MoveToTool::Apply(TasFramebulk &bulk, const TasPlayerInfo &player) {
37+
if (!params.enabled) return;
38+
39+
auto player_pos = player.position;
40+
player_pos.z = 0;
41+
42+
float dist = Math::Distance(player_pos, this->params.point);
43+
44+
Vector vec;
45+
vec = this->params.point - player_pos;
46+
47+
// absmov
48+
auto angles = player.angles;
49+
angles.y -= bulk.viewAnalog.x;
50+
angles.x -= bulk.viewAnalog.y;
51+
52+
float forward_coef;
53+
if (fabsf(angles.x) >= 30.0f && !player.willBeGrounded) {
54+
forward_coef = cosOld(DEG2RAD(angles.x));
55+
} else {
56+
forward_coef = 1.0f;
57+
}
58+
59+
float x = vec.x;
60+
float y = vec.y / forward_coef;
61+
62+
if (y > 1.0f) {
63+
// We can't actually move this fast. Scale the movement down so 'y'
64+
// is within the allowed range
65+
x /= y;
66+
y = 1.0f;
67+
}
68+
69+
bulk.moveAnalog.x = x;
70+
bulk.moveAnalog.y = y;
71+
72+
if (dist < 1 && autoStrafeTool->GetVelocityAfterMove(player, x, y).Length2D() < 1) {
73+
params.enabled = false;
74+
}
75+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#pragma once
2+
3+
#include "../TasTool.hpp"
4+
#include "Utils/SDK/Math.hpp"
5+
6+
struct MoveToParams : public TasToolParams {
7+
MoveToParams()
8+
: TasToolParams(false) {}
9+
10+
MoveToParams(Vector point)
11+
: TasToolParams(true)
12+
, point(point) {}
13+
14+
Vector point;
15+
};
16+
17+
class MoveToTool : public TasToolWithParams<MoveToParams> {
18+
public:
19+
MoveToTool(int slot)
20+
: TasToolWithParams("moveto", slot) {}
21+
22+
virtual std::shared_ptr<TasToolParams> ParseParams(std::vector<std::string>);
23+
virtual void Apply(TasFramebulk &bulk, const TasPlayerInfo &pInfo);
24+
};

0 commit comments

Comments
 (0)