Skip to content

Commit

Permalink
feat: check holding
Browse files Browse the repository at this point in the history
optional ent selector too
  • Loading branch information
ThisAMJ committed Apr 14, 2024
1 parent f261b00 commit 284a5ec
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
4 changes: 2 additions & 2 deletions docs/p2tas.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,10 @@ This tool decelerates the player as fast as possible towards the speed, in units
### `check` tool

```cs
check {pos <x> <y> <z>} {posepsilon <number>} {ang <pitch> <yaw>} {angepsilon <number>}
check {pos <x> <y> <z>} {posepsilon <number>} {ang <pitch> <yaw>} {angepsilon <number>} {holding [entity_selector]}
```

This tool can be used to perform a check on player's position and view angles. If position and view angles differ by more than given epsilon, the TAS script is restarted. The tool will restart until the number of automatic restarts surpasses the one defined by a `sar_tas_check_max_replays` console variable.
This tool can be used to perform a check on player's position or view angles. If position or view angles differ by more than given epsilon, the TAS script is restarted. It can also be used to check if the player is holding an item, with an optional entity selector. The tool will restart until the number of automatic restarts surpasses the number defined by the `sar_tas_check_max_replays` console variable.

### `duck` tool

Expand Down
39 changes: 38 additions & 1 deletion src/Features/Tas/TasTools/CheckTool.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "CheckTool.hpp"
#include "Features/EntityList.hpp"
#include "Features/Tas/TasParser.hpp"
#include "Modules/Console.hpp"

Expand Down Expand Up @@ -38,6 +39,30 @@ void CheckTool::Apply(TasFramebulk &fb, const TasPlayerInfo &info) {
}
}

if (params.holding) {
auto player = server->GetPlayer(info.slot + 1);
if (player) {
auto held = player->field<CBaseHandle>("m_hAttachedObject");
if (held) {
if (params.holding.value().size() != 0) {
CEntInfo *entity = entityList->QuerySelector(params.holding.value().c_str());
if (entity != NULL) {
// Check if they are the same entity
int entSerial = held.GetSerialNumber(), entSerial2 = entity->m_SerialNumber;
if (entSerial != entSerial2) {
console->Print("Player was holding the wrong object!\n");
shouldReplay = true;
}
}

}
} else {
console->Print("Player was not holding an object!\n");
shouldReplay = true;
}
}
}

if (shouldReplay) {
int replays = tasPlayer->playbackInfo.autoReplayCount;
if (replays < sar_tas_check_max_replays.GetInt()) {
Expand Down Expand Up @@ -87,6 +112,7 @@ std::shared_ptr<TasToolParams> CheckTool::ParseParams(std::vector<std::string> v

std::optional<Vector> pos = {};
std::optional<QAngle> ang = {};
std::optional<std::string> holding = {};
std::optional<float> posepsilon = {};
std::optional<float> angepsilon = {};

Expand All @@ -105,6 +131,17 @@ std::shared_ptr<TasToolParams> CheckTool::ParseParams(std::vector<std::string> v
}
ang = parseAng(vp, i+1);
i += 3;
} else if (vp[i] == "holding") {
if (holding) {
throw TasParserException("Duplicate holding given to check tool");
}
if (vp.size() - i < 2) {
holding = "";
i += 1;
} else {
holding = vp[i+1];
i += 2;
}
} else if (vp[i] == "posepsilon") {
if (posepsilon) {
throw TasParserException("Duplicate position epsilon given to check tool");
Expand All @@ -130,5 +167,5 @@ std::shared_ptr<TasToolParams> CheckTool::ParseParams(std::vector<std::string> v
}
}

return std::make_shared<CheckToolParams>(pos, ang, posepsilon ? *posepsilon : DEFAULT_POS_EPSILON, angepsilon ? *angepsilon : DEFAULT_ANG_EPSILON);
return std::make_shared<CheckToolParams>(pos, ang, holding, posepsilon ? *posepsilon : DEFAULT_POS_EPSILON, angepsilon ? *angepsilon : DEFAULT_ANG_EPSILON);
}
5 changes: 3 additions & 2 deletions src/Features/Tas/TasTools/CheckTool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ struct CheckToolParams : public TasToolParams {
, angepsilon(DEFAULT_ANG_EPSILON)
{}

CheckToolParams(std::optional<Vector> pos, std::optional<QAngle> ang, float posepsilon, float angepsilon)
: TasToolParams(true), pos(pos), ang(ang), posepsilon(posepsilon), angepsilon(angepsilon)
CheckToolParams(std::optional<Vector> pos, std::optional<QAngle> ang, std::optional<std::string> holding, float posepsilon, float angepsilon)
: TasToolParams(true), pos(pos), ang(ang), holding(holding), posepsilon(posepsilon), angepsilon(angepsilon)
{}

std::optional<Vector> pos;
std::optional<QAngle> ang; // roll ignored
std::optional<std::string> holding;
float posepsilon;
float angepsilon;
};
Expand Down

0 comments on commit 284a5ec

Please sign in to comment.