Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ VERSION=$(shell git describe --tags)
DEPS=$(OBJS:%.o=%.d)

WARNINGS=-Wall -Wno-parentheses -Wno-unknown-pragmas -Wno-delete-non-virtual-dtor -Wno-overloaded-virtual
CXXFLAGS=-std=c++17 -m32 $(WARNINGS) -I$(SDIR) -fPIC -D_GNU_SOURCE -Ilib/ffmpeg/include -Ilib/SFML/include -Ilib/curl/include -Ilib/discord-rpc/include -DSFML_STATIC -DCURL_STATICLIB
CXXFLAGS=-std=c++17 -m32 -msse2 -mfpmath=sse $(WARNINGS) -I$(SDIR) -fPIC -D_GNU_SOURCE -Ilib/ffmpeg/include -Ilib/SFML/include -Ilib/curl/include -Ilib/discord-rpc/include -DSFML_STATIC -DCURL_STATICLIB
LDFLAGS=-m32 -shared -lstdc++fs -Llib/ffmpeg/lib/linux -lavformat -lavcodec -lavutil -lswscale -lswresample -lx264 -lx265 -lvorbis -lvorbisenc -lvorbisfile -logg -lopus -lvpx -Llib/SFML/lib/linux -lsfml -Llib/curl/lib/linux -lcurl -lssl -lcrypto -lnghttp2 -Llib/discord-rpc/lib/linux -ldiscord-rpc

# Import config.mk, which can be used for optional config
Expand Down
7 changes: 5 additions & 2 deletions docs/p2tas.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ The parser is case-sensitive. All keywords are lowercase.

The file should begin with a set of properties, defined in this exact order:

- `version <number>` - required, defines a version of the script file, which affects how the script is processed and executed. Currently, the newest version is 7. For more details, see [Version History](#version-history).
- `version <number>` - required, defines a version of the script file, which affects how the script is processed and executed. Currently, the newest version is 10. For more details, see [Version History](#version-history).
- `start {next} {save/next/cm/now} <name>` - required, defines a starting point for the script file playback:
- `next` - when used, playback doesn't start immediately after the given starting operation, but after the next game load. Usually used in full-game runs to run scripts right after level transition.
- `save` - starts from a save with a given `name`.
Expand Down Expand Up @@ -429,5 +429,8 @@ Stops all tools that were activated in the past tickbulks. Optionally, it accept
- Fix `decel` tool not respecting jump-based tools.
- Version 9:
- Fix `use` tool by processing some tools during input fetching.
- Version 10:
- Fix tools giving slightly different results on Linux than on Windows by computing `sinf`, `cosf` etc. in double on both.
- Fix movement and view angle tools giving slightly different results on Windows than on Linux.

Last updated during version 9 release.
Last updated during version 10 release.
2 changes: 1 addition & 1 deletion src/Features/Tas/TasParser.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#include "TasScript.hpp"

#define MAX_SCRIPT_VERSION 9
#define MAX_SCRIPT_VERSION 10

#include <iostream>
#include <string>
Expand Down
12 changes: 12 additions & 0 deletions src/Features/Tas/TasPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "Event.hpp"
#include "Variable.hpp"

#include <cfloat>
#include <climits>
#include <fstream>
#include "TasTools/JumpTool.hpp"
Expand Down Expand Up @@ -844,7 +845,18 @@ void TasPlayer::ApplyTools(TasFramebulk &fb, const TasPlayerInfo &pInfo, TasTool
for (std::string toolName : TasTool::priorityList) {
auto tool = TasTool::GetInstanceByName(slot, toolName);
if (!CanProcessTool(tool, processType)) continue;
#ifdef _M_IX86
// MSVC keeps some float intermediates on the x87, which rounds them to double; round them to
// float as with gcc and clang. Only the movement and view angle tools do float math; the others keep
// the game's setting.
bool pin = TAS_SCRIPT_VERSION_AT_LEAST(10) && (tool->GetBulkType() & (MOVEMENT | VIEWANGLES));
unsigned int oldControl = pin ? _controlfp(0, 0) : 0;
if (pin) _controlfp(_PC_24, _MCW_PC);
#endif
tool->Apply(fb, pInfo);
#ifdef _M_IX86
if (pin) _controlfp(oldControl, _MCW_PC);
#endif
}
}

Expand Down
19 changes: 15 additions & 4 deletions src/Features/Tas/TasTool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,26 @@
#include <string>
#include <vector>

// glibc's sinf etc. sometimes return a slightly different value than
// MSVC's, which computes them in double. Since version 10 the tools use
// Math::Sin etc. (float in/out, computed in double) on every platform.
// Older scripts keep the platform's own functions
#define tasSinf(x) (TAS_SCRIPT_VERSION_AT_LEAST(10) ? Math::Sin(x) : sinf(x))
#define tasCosf(x) (TAS_SCRIPT_VERSION_AT_LEAST(10) ? Math::Cos(x) : cosf(x))
#define tasAtan2f(x, y) (TAS_SCRIPT_VERSION_AT_LEAST(10) ? Math::Atan2(x, y) : atan2f(x, y))
#define tasAcosf(x) (TAS_SCRIPT_VERSION_AT_LEAST(10) ? Math::Acos(x) : acosf(x))
#define tasAsinf(x) (TAS_SCRIPT_VERSION_AT_LEAST(10) ? Math::Asin(x) : asinf(x))
#define tasPowf(x, y) (TAS_SCRIPT_VERSION_AT_LEAST(10) ? Math::Pow(x, y) : powf(x, y))

// A bunch of stuff accidentally used sin/cos directly, which led to
// inconsistent scripts between Windows and Linux since Windows has
// overloads for some functions. These helper macros dispatch to
// sinf/cosf on newer script versions for platform consistency
#define absOld(x) (TAS_SCRIPT_VERSION_AT_LEAST(3) ? fabsf(x) : abs(x)) // we noticed this one sooner lol
#define sinOld(x) (TAS_SCRIPT_VERSION_AT_LEAST(4) ? sinf(x) : sin(x))
#define cosOld(x) (TAS_SCRIPT_VERSION_AT_LEAST(4) ? cosf(x) : cos(x))
#define atan2Old(x, y) (TAS_SCRIPT_VERSION_AT_LEAST(4) ? atan2f(x, y) : atan2(x, y))
#define powOld(x, y) (TAS_SCRIPT_VERSION_AT_LEAST(4) ? powf(x, y) : pow(x, y))
#define sinOld(x) (TAS_SCRIPT_VERSION_AT_LEAST(4) ? tasSinf(x) : sin(x))
#define cosOld(x) (TAS_SCRIPT_VERSION_AT_LEAST(4) ? tasCosf(x) : cos(x))
#define atan2Old(x, y) (TAS_SCRIPT_VERSION_AT_LEAST(4) ? tasAtan2f(x, y) : atan2(x, y))
#define powOld(x, y) (TAS_SCRIPT_VERSION_AT_LEAST(4) ? tasPowf(x, y) : pow(x, y))

struct TasToolParams {
bool enabled = false;
Expand Down
4 changes: 2 additions & 2 deletions src/Features/Tas/TasTools/AbsoluteMoveTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ void AbsoluteMoveTool::Apply(TasFramebulk &fb, const TasPlayerInfo &playerInfo)
float desired = params.direction;
float rad = DEG2RAD(desired - angles.y);

float x = -sinf(rad);
float y = cosf(rad) / forward_coef;
float x = -tasSinf(rad);
float y = tasCosf(rad) / forward_coef;

x *= params.strength;
y *= params.strength;
Expand Down
16 changes: 9 additions & 7 deletions src/Features/Tas/TasTools/AngleToolsUtils.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#include "AngleToolsUtils.hpp"

#include "Features/Tas/TasPlayer.hpp"

namespace AngleToolsUtils {
float Ease(float t, EasingType easingType) {
float Ease(int slot, float t, EasingType easingType) {
if (t == 0.0f || t == 1.0f) return t;

switch (easingType) {
case Sine:
return (cosf(M_PI * t) - 1.0f) / -2.0f;
return (tasCosf(M_PI * t) - 1.0f) / -2.0f;
case Cubic:
return t < 0.5f ? 4.0f * t * t * t : 1.0f - powf(-2.0f * t + 2.0f, 3.0f) / 2.0f;
return t < 0.5f ? 4.0f * t * t * t : 1.0f - tasPowf(-2.0f * t + 2.0f, 3.0f) / 2.0f;
case Exponential:
return t < 0.5f ? powf(2.0f, 20.0f * t - 10.0f) / 2 : (2 - powf(2.0f, -20.0f * t + 10.0f)) / 2.0f;
return t < 0.5f ? tasPowf(2.0f, 20.0f * t - 10.0f) / 2 : (2 - tasPowf(2.0f, -20.0f * t + 10.0f)) / 2.0f;
default:
return t;
}
Expand All @@ -30,7 +32,7 @@ namespace AngleToolsUtils {
}
}

Vector GetInterpolatedViewAnalog(Vector currentAngles, Vector targetAngles, int easingTicks, int elapsedTicks, EasingType easingType) {
Vector GetInterpolatedViewAnalog(int slot, Vector currentAngles, Vector targetAngles, int easingTicks, int elapsedTicks, EasingType easingType) {
Vector requiredDelta = currentAngles - targetAngles;

while (requiredDelta.y < 0.0f) requiredDelta.y += 360.0f;
Expand All @@ -46,8 +48,8 @@ namespace AngleToolsUtils {
} else {
float realFactorNow = elapsedTicks / (float)easingTicks;
float realFactorNext = (elapsedTicks + 1) / (float)easingTicks;
float easeFactorNow = Ease(realFactorNow, easingType);
float easeFactorNext = Ease(realFactorNext, easingType);
float easeFactorNow = Ease(slot, realFactorNow, easingType);
float easeFactorNext = Ease(slot, realFactorNext, easingType);

// how much of the remaining angle distance we should move
float partFactor = (easeFactorNext - easeFactorNow) / (1.0f - easeFactorNow);
Expand Down
4 changes: 2 additions & 2 deletions src/Features/Tas/TasTools/AngleToolsUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace AngleToolsUtils {
Exponential,
};

float Ease(float t, EasingType easingType);
float Ease(int slot, float t, EasingType easingType);
EasingType ParseEasingType(std::string typeStr);
Vector GetInterpolatedViewAnalog(Vector currentAngles, Vector targetAngles, int easingTicks, int elapsedTicks, EasingType easingType);
Vector GetInterpolatedViewAnalog(int slot, Vector currentAngles, Vector targetAngles, int easingTicks, int elapsedTicks, EasingType easingType);
}
1 change: 1 addition & 0 deletions src/Features/Tas/TasTools/AutoAimTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ void AutoAimTool::Apply(TasFramebulk &bulk, const TasPlayerInfo &playerInfo) {
yaw *= 180.0f / M_PI;

bulk.viewAnalog = AngleToolsUtils::GetInterpolatedViewAnalog(
slot,
QAngleToVector(playerInfo.angles),
Vector{pitch, yaw},
params.easingTicks,
Expand Down
4 changes: 2 additions & 2 deletions src/Features/Tas/TasTools/DecelTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ void DecelTool::Apply(TasFramebulk &bulk, const TasPlayerInfo &playerInfo) {

// move the opposite side of your current velocity
float moveAngle = DEG2RAD(TasUtils::GetVelocityAngles(&playerInfo).x + 180 - playerInfo.angles.y + bulk.viewAnalog.x);
bulk.moveAnalog.x = -sinf(moveAngle);
bulk.moveAnalog.y = cosf(moveAngle);
bulk.moveAnalog.x = -tasSinf(moveAngle);
bulk.moveAnalog.y = tasCosf(moveAngle);

// make sure to move only the necessary amount
float maxAccel = autoStrafeTool[this->slot].GetMaxAccel(playerInfo, autoStrafeTool[this->slot].CreateWishDir(playerInfo,bulk.moveAnalog.y, bulk.moveAnalog.x));
Expand Down
32 changes: 26 additions & 6 deletions src/Features/Tas/TasTools/MoveTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,28 @@ void MoveTool::Apply(TasFramebulk &fb, const TasPlayerInfo &playerInfo) {
tasAbsoluteMoveTool[slot].Reset();
}

fb.moveAnalog.x = params.sideMove;
fb.moveAnalog.y = params.forwardMove;
float forwardMove = params.forwardMove;
float sideMove = params.sideMove;

if (params.movingByDegrees) {
forwardMove = tasCosf(params.degrees);
sideMove = tasSinf(params.degrees);

if (params.scaleAssigned) {
auto length = sqrtf((forwardMove * forwardMove) + (sideMove * sideMove));
forwardMove /= length;
sideMove /= length;
}

forwardMove *= params.scale;
sideMove *= params.scale;
}

fb.moveAnalog.x = sideMove;
fb.moveAnalog.y = forwardMove;

if (sar_tas_debug.GetBool()) {
console->Print("move %.3f %.3f\n", params.forwardMove, params.sideMove);
console->Print("move %.3f %.3f\n", forwardMove, sideMove);
}
}

Expand All @@ -41,6 +58,7 @@ std::shared_ptr<TasToolParams> MoveTool::ParseParams(std::vector<std::string> vp

float forwardMove = 0.0f;
float sideMove = 0.0f;
float degrees = 0.0f;
float scale = 1.0f;

int numberCount = 0;
Expand All @@ -58,9 +76,7 @@ std::shared_ptr<TasToolParams> MoveTool::ParseParams(std::vector<std::string> vp
throw TasParserException(Utils::ssprintf("Repeated degrees parameter for tool %s: %s", this->GetName(), param.c_str()));
}
movingByDegrees = true;
float degrees = TasParser::toFloat(param.substr(0, param.size() - 3));
forwardMove = cosf(degrees);
sideMove = sinf(degrees);
degrees = TasParser::toFloat(param.substr(0, param.size() - 3));
}

else if (param == "forward") {
Expand Down Expand Up @@ -104,6 +120,10 @@ std::shared_ptr<TasToolParams> MoveTool::ParseParams(std::vector<std::string> vp
throw TasParserException(Utils::ssprintf("Too many direction identifiers for tool %s", this->GetName()));
}

if (movingByDegrees) {
return std::make_shared<MoveToolParams>(degrees, scale, scaleAssigned);
}

if (directionsCount > 0 || scaleAssigned) {
auto length = sqrtf((forwardMove * forwardMove) + (sideMove * sideMove));
forwardMove /= length;
Expand Down
13 changes: 13 additions & 0 deletions src/Features/Tas/TasTools/MoveTool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
struct MoveToolParams : public TasToolParams {
float forwardMove = 0;
float sideMove = 0;
// `<N>deg`: the direction is computed in Apply, where the script version is known
bool movingByDegrees = false;
float degrees = 0;
float scale = 1;
bool scaleAssigned = false;
MoveToolParams()
: TasToolParams() {
}
Expand All @@ -14,6 +19,14 @@ struct MoveToolParams : public TasToolParams {
, forwardMove(forwardMove)
, sideMove(sideMove) {
}

MoveToolParams(float degrees, float scale, bool scaleAssigned)
: TasToolParams(true)
, movingByDegrees(true)
, degrees(degrees)
, scale(scale)
, scaleAssigned(scaleAssigned) {
}
};

class MoveTool : public TasToolWithParams<MoveToolParams> {
Expand Down
1 change: 1 addition & 0 deletions src/Features/Tas/TasTools/SetAngleTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ void SetAngleTool::Apply(TasFramebulk &bulk, const TasPlayerInfo &playerInfo) {
}

bulk.viewAnalog = bulk.viewAnalog + AngleToolsUtils::GetInterpolatedViewAnalog(
slot,
QAngleToVector(playerInfo.angles),
target,
params.easingTicks,
Expand Down
Loading