Skip to content

Commit

Permalink
add zoom, duck, stop and cmd tas tools
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzyhau committed Nov 4, 2023
1 parent f56d5c2 commit 22ae2dd
Show file tree
Hide file tree
Showing 11 changed files with 312 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Features/Tas/TasTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ TasTool *TasTool::GetInstanceByName(int slot, std::string name) {

std::vector<std::string> TasTool::priorityList = {
"check",
"cmd",
"stop",
"use",
"duck",
"zoom",
"shoot",
"setang",
"autoaim",
Expand Down
31 changes: 31 additions & 0 deletions src/Features/Tas/TasTools/CommandTool.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "CommandTool.hpp"

#include "Modules/Engine.hpp"
#include "Modules/Server.hpp"
#include "Features/Tas/TasParser.hpp"
#include "Features/Tas/TasPlayer.hpp"

CommandTool commandTool[2] = {{0}, {1}};

void CommandTool::Apply(TasFramebulk &bulk, const TasPlayerInfo &pInfo) {
if (params.enabled) {
engine->ExecuteCommand(params.command.c_str(), true);
params.enabled = false;
}
}

std::shared_ptr<TasToolParams> CommandTool::ParseParams(std::vector<std::string> vp) {
if (vp.size() == 0)
throw TasParserException(Utils::ssprintf("Wrong argument count for tool %s: %d", this->GetName(), vp.size()));

std::string command;

for (const std::string &str : vp) {
if (!command.empty()) {
command += " ";
}
command += str;
}

return std::make_shared<CommandToolParams>(true, command);
}
26 changes: 26 additions & 0 deletions src/Features/Tas/TasTools/CommandTool.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once
#include "../TasTool.hpp"

struct CommandToolParams : public TasToolParams {
CommandToolParams()
: TasToolParams() {
}
CommandToolParams(bool enabled, std::string command)
: TasToolParams(enabled)
, command(command) {
}

std::string command;
};

class CommandTool : public TasToolWithParams<CommandToolParams> {
public:
CommandTool(int slot)
: TasToolWithParams("cmd", slot) {
}

virtual std::shared_ptr<TasToolParams> ParseParams(std::vector<std::string>);
virtual void Apply(TasFramebulk &bulk, const TasPlayerInfo &pInfo);
};

extern CommandTool commandTool[2];
51 changes: 51 additions & 0 deletions src/Features/Tas/TasTools/DuckTool.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include "DuckTool.hpp"

#include "Modules/Engine.hpp"
#include "Modules/Server.hpp"
#include "Features/Tas/TasParser.hpp"
#include "Features/Tas/TasPlayer.hpp"

DuckTool duckTool[2] = {{0}, {1}};

void DuckTool::Apply(TasFramebulk &bulk, const TasPlayerInfo &pInfo) {
if (!params.enabled) {
return;
}

if (this->updated) {
elapsedTicks = 0;
this->updated = false;
}

if (elapsedTicks >= params.time) {
params.enabled = false;
return;
}

bulk.buttonStates[TasControllerInput::Crouch] = true;

elapsedTicks++;
}

std::shared_ptr<TasToolParams> DuckTool::ParseParams(std::vector<std::string> vp) {
if (vp.size() != 1)
throw TasParserException(Utils::ssprintf("Wrong argument count for tool %s: %d", this->GetName(), vp.size()));

bool enabled = true;
int time = INT32_MAX;

if (vp[0] == "on") {
enabled = true;
} else if (vp[0] == "off") {
enabled = false;
time = 0;
} else{
try {
time = std::stoi(vp[0]);
} catch (...) {
throw TasParserException(Utils::ssprintf("Incorrect parameter for tool %s: %s", this->GetName(), vp[0].c_str()));
}
}

return std::make_shared<DuckToolParams>(enabled, time);
}
29 changes: 29 additions & 0 deletions src/Features/Tas/TasTools/DuckTool.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once
#include "../TasTool.hpp"

struct DuckToolParams : public TasToolParams {
DuckToolParams()
: TasToolParams() {
}
DuckToolParams(bool enabled, int time)
: TasToolParams(enabled)
, time(time) {
}

int time = 0;
};

class DuckTool : public TasToolWithParams<DuckToolParams> {
public:
DuckTool(int slot)
: TasToolWithParams("duck", slot) {
}

virtual std::shared_ptr<TasToolParams> ParseParams(std::vector<std::string>);
virtual void Apply(TasFramebulk &bulk, const TasPlayerInfo &pInfo);

private:
int elapsedTicks;
};

extern DuckTool duckTool[2];
35 changes: 35 additions & 0 deletions src/Features/Tas/TasTools/StopTool.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "StopTool.hpp"

#include "Modules/Engine.hpp"
#include "Modules/Server.hpp"
#include "Features/Tas/TasParser.hpp"
#include "Features/Tas/TasPlayer.hpp"

StopTool stopTool[2] = {{0}, {1}};

void StopTool::Apply(TasFramebulk &bulk, const TasPlayerInfo &pInfo) {
if (params.enabled) {
for (TasTool *tool : TasTool::GetList(pInfo.slot)) {

bool toolJustRequested = false;
for (auto toolCmd : bulk.toolCmds) {
if (tool == toolCmd.tool) {
toolJustRequested = true;
break;
}
}

if (!toolJustRequested) {
tool->Reset();
}
}
params.enabled = false;
}
}

std::shared_ptr<TasToolParams> StopTool::ParseParams(std::vector<std::string> vp) {
if (vp.size() > 0)
throw TasParserException(Utils::ssprintf("Wrong argument count for tool %s: %d", this->GetName(), vp.size()));

return std::make_shared<StopToolParams>(true);
}
23 changes: 23 additions & 0 deletions src/Features/Tas/TasTools/StopTool.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once
#include "../TasTool.hpp"

struct StopToolParams : public TasToolParams {
StopToolParams()
: TasToolParams() {
}
StopToolParams(bool enabled)
: TasToolParams(enabled) {
}
};

class StopTool : public TasToolWithParams<StopToolParams> {
public:
StopTool(int slot)
: TasToolWithParams("stop", slot) {
}

virtual std::shared_ptr<TasToolParams> ParseParams(std::vector<std::string>);
virtual void Apply(TasFramebulk &bulk, const TasPlayerInfo &pInfo);
};

extern StopTool stopTool[2];
49 changes: 49 additions & 0 deletions src/Features/Tas/TasTools/ZoomTool.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "ZoomTool.hpp"

#include "Modules/Engine.hpp"
#include "Modules/Server.hpp"
#include "Features/Tas/TasParser.hpp"
#include "Features/Tas/TasPlayer.hpp"

ZoomTool zoomTool[2] = {{0}, {1}};

void ZoomTool::Apply(TasFramebulk &bulk, const TasPlayerInfo &pInfo) {
if (params.enabled) {
params.enabled = false;

void *player = server->GetPlayer(pInfo.slot + 1);

if (player == nullptr || (int)player == -1) return;

bool isZoomedIn = SE(player)->field<CBaseHandle>("m_hZoomOwner");

if (
(params.zoomType == ZoomType::In && !isZoomedIn) ||
(params.zoomType == ZoomType::Out && isZoomedIn) ||
params.zoomType == ZoomType::Toggle
) {
bulk.buttonStates[TasControllerInput::Zoom] = true;
}
}
}

std::shared_ptr<TasToolParams> ZoomTool::ParseParams(std::vector<std::string> vp) {
if (vp.size() != 1)
throw TasParserException(Utils::ssprintf("Wrong argument count for tool %s: %d", this->GetName(), vp.size()));

ZoomType type;

if (vp[0] == "in") {
type = ZoomType::In;
}
else if (vp[0] == "out") {
type = ZoomType::Out;
}
else if (vp[0] == "toggle") {
type = ZoomType::Toggle;
} else {
throw TasParserException(Utils::ssprintf("Bad parameter for tool %s: %s", this->GetName(), vp[0].c_str()));
}

return std::make_shared<ZoomToolParams>(true, type);
}
32 changes: 32 additions & 0 deletions src/Features/Tas/TasTools/ZoomTool.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once
#include "../TasTool.hpp"

enum ZoomType {
In,
Out,
Toggle
};

struct ZoomToolParams : public TasToolParams {
ZoomToolParams()
: TasToolParams() {
}
ZoomToolParams(bool enabled, ZoomType zoomType)
: TasToolParams(enabled)
, zoomType(zoomType) {
}

ZoomType zoomType = In;
};

class ZoomTool : public TasToolWithParams<ZoomToolParams> {
public:
ZoomTool(int slot)
: TasToolWithParams("zoom", slot) {
}

virtual std::shared_ptr<TasToolParams> ParseParams(std::vector<std::string>);
virtual void Apply(TasFramebulk &bulk, const TasPlayerInfo &pInfo);
};

extern ZoomTool zoomTool[2];
8 changes: 8 additions & 0 deletions src/SourceAutoRecord.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,14 @@
<ClCompile Include="Features\Tas\TasTools\AngleToolsUtils.cpp" />
<ClCompile Include="Features\Tas\TasPlayer.cpp" />
<ClCompile Include="Features\Tas\TasScript.cpp" />
<ClCompile Include="Features\Tas\TasTools\CommandTool.cpp" />
<ClCompile Include="Features\Tas\TasTools\DuckTool.cpp" />
<ClCompile Include="Features\Tas\TasTools\ShootTool.cpp" />
<ClCompile Include="Features\Tas\TasTools\StopTool.cpp" />
<ClCompile Include="Features\Tas\TasTools\UseTool.cpp" />
<ClCompile Include="Features\Tas\TasTools\LookTool.cpp" />
<ClCompile Include="Features\Tas\TasTools\MoveTool.cpp" />
<ClCompile Include="Features\Tas\TasTools\ZoomTool.cpp" />
<ClCompile Include="Features\WindowResizer.cpp" />
<ClCompile Include="Games\ApertureTag.cpp" />
<ClCompile Include="Games\Portal2.cpp" />
Expand Down Expand Up @@ -338,10 +342,14 @@
<ClInclude Include="Features\Tas\TasTools\AngleToolsUtils.hpp" />
<ClInclude Include="Features\Tas\TasPlayer.hpp" />
<ClInclude Include="Features\Tas\TasScript.hpp" />
<ClInclude Include="Features\Tas\TasTools\CommandTool.hpp" />
<ClInclude Include="Features\Tas\TasTools\DuckTool.hpp" />
<ClInclude Include="Features\Tas\TasTools\ShootTool.hpp" />
<ClInclude Include="Features\Tas\TasTools\StopTool.hpp" />
<ClInclude Include="Features\Tas\TasTools\UseTool.hpp" />
<ClInclude Include="Features\Tas\TasTools\LookTool.hpp" />
<ClInclude Include="Features\Tas\TasTools\MoveTool.hpp" />
<ClInclude Include="Features\Tas\TasTools\ZoomTool.hpp" />
<ClInclude Include="Features\WindowResizer.hpp" />
<ClInclude Include="Games\ApertureTag.hpp" />
<ClInclude Include="Games\Portal2.hpp" />
Expand Down
24 changes: 24 additions & 0 deletions src/SourceAutoRecord.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,18 @@
<ClCompile Include="Features\Routing\StepSlopeBoostDebug.cpp">
<Filter>SourceAutoRecord\Features\Routing</Filter>
</ClCompile>
<ClCompile Include="Features\Tas\TasTools\StopTool.cpp">
<Filter>SourceAutoRecord\Features\Tas\TasTools</Filter>
</ClCompile>
<ClCompile Include="Features\Tas\TasTools\CommandTool.cpp">
<Filter>SourceAutoRecord\Features\Tas\TasTools</Filter>
</ClCompile>
<ClCompile Include="Features\Tas\TasTools\DuckTool.cpp">
<Filter>SourceAutoRecord\Features\Tas\TasTools</Filter>
</ClCompile>
<ClCompile Include="Features\Tas\TasTools\ZoomTool.cpp">
<Filter>SourceAutoRecord\Features\Tas\TasTools</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\lib\minhook\buffer.h">
Expand Down Expand Up @@ -1302,6 +1314,18 @@
<ClInclude Include="Features\Routing\StepSlopeBoostDebug.hpp">
<Filter>SourceAutoRecord\Features\Routing</Filter>
</ClInclude>
<ClInclude Include="Features\Tas\TasTools\StopTool.hpp">
<Filter>SourceAutoRecord\Features\Tas\TasTools</Filter>
</ClInclude>
<ClInclude Include="Features\Tas\TasTools\CommandTool.hpp">
<Filter>SourceAutoRecord\Features\Tas\TasTools</Filter>
</ClInclude>
<ClInclude Include="Features\Tas\TasTools\DuckTool.hpp">
<Filter>SourceAutoRecord\Features\Tas\TasTools</Filter>
</ClInclude>
<ClInclude Include="Features\Tas\TasTools\ZoomTool.hpp">
<Filter>SourceAutoRecord\Features\Tas\TasTools</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="SourceAutoRecord">
Expand Down

0 comments on commit 22ae2dd

Please sign in to comment.