From 284a5ece871ae87435bd8f8d7c2857e680d89443 Mon Sep 17 00:00:00 2001 From: Jesse <69196954+ThisAMJ@users.noreply.github.com> Date: Sat, 13 Apr 2024 22:48:05 +1000 Subject: [PATCH] feat: `check holding` optional ent selector too --- docs/p2tas.md | 4 +-- src/Features/Tas/TasTools/CheckTool.cpp | 39 ++++++++++++++++++++++++- src/Features/Tas/TasTools/CheckTool.hpp | 5 ++-- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/docs/p2tas.md b/docs/p2tas.md index fb978d3f8..f6f0c2d4e 100644 --- a/docs/p2tas.md +++ b/docs/p2tas.md @@ -264,10 +264,10 @@ This tool decelerates the player as fast as possible towards the speed, in units ### `check` tool ```cs -check {pos } {posepsilon } {ang } {angepsilon } +check {pos } {posepsilon } {ang } {angepsilon } {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 diff --git a/src/Features/Tas/TasTools/CheckTool.cpp b/src/Features/Tas/TasTools/CheckTool.cpp index 78ff1a6e3..85bdbe843 100644 --- a/src/Features/Tas/TasTools/CheckTool.cpp +++ b/src/Features/Tas/TasTools/CheckTool.cpp @@ -1,4 +1,5 @@ #include "CheckTool.hpp" +#include "Features/EntityList.hpp" #include "Features/Tas/TasParser.hpp" #include "Modules/Console.hpp" @@ -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("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()) { @@ -87,6 +112,7 @@ std::shared_ptr CheckTool::ParseParams(std::vector v std::optional pos = {}; std::optional ang = {}; + std::optional holding = {}; std::optional posepsilon = {}; std::optional angepsilon = {}; @@ -105,6 +131,17 @@ std::shared_ptr CheckTool::ParseParams(std::vector 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"); @@ -130,5 +167,5 @@ std::shared_ptr CheckTool::ParseParams(std::vector v } } - return std::make_shared(pos, ang, posepsilon ? *posepsilon : DEFAULT_POS_EPSILON, angepsilon ? *angepsilon : DEFAULT_ANG_EPSILON); + return std::make_shared(pos, ang, holding, posepsilon ? *posepsilon : DEFAULT_POS_EPSILON, angepsilon ? *angepsilon : DEFAULT_ANG_EPSILON); } diff --git a/src/Features/Tas/TasTools/CheckTool.hpp b/src/Features/Tas/TasTools/CheckTool.hpp index b81007204..e406120e7 100644 --- a/src/Features/Tas/TasTools/CheckTool.hpp +++ b/src/Features/Tas/TasTools/CheckTool.hpp @@ -12,12 +12,13 @@ struct CheckToolParams : public TasToolParams { , angepsilon(DEFAULT_ANG_EPSILON) {} - CheckToolParams(std::optional pos, std::optional ang, float posepsilon, float angepsilon) - : TasToolParams(true), pos(pos), ang(ang), posepsilon(posepsilon), angepsilon(angepsilon) + CheckToolParams(std::optional pos, std::optional ang, std::optional holding, float posepsilon, float angepsilon) + : TasToolParams(true), pos(pos), ang(ang), holding(holding), posepsilon(posepsilon), angepsilon(angepsilon) {} std::optional pos; std::optional ang; // roll ignored + std::optional holding; float posepsilon; float angepsilon; };