|
| 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 | +} |
0 commit comments