Skip to content

Commit

Permalink
feat: add shooting TAS tool
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzyhau committed Oct 18, 2023
1 parent 906ee53 commit 737f47b
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Features/Tas/TasTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ TasTool *TasTool::GetInstanceByName(int slot, std::string name) {
std::vector<std::string> TasTool::priorityList = {
"check",
"use",
"shoot",
"setang",
"autoaim",
"look",
Expand Down
65 changes: 65 additions & 0 deletions src/Features/Tas/TasTools/ShootTool.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include "ShootTool.hpp"

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

ShootTool tasShootTool[2] = { {0}, {1} };

void ShootTool::Apply(TasFramebulk &bulk, const TasPlayerInfo &pInfo) {
if (params.enabled) {

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

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

uintptr_t portalgun = (uintptr_t)entityList->LookupEntity(SE(player)->active_weapon());
if (!portalgun) return;

float nextPrimaryAttack = SE(portalgun)->field<float>("m_flNextPrimaryAttack");

float currTime = pInfo.tick * pInfo.ticktime;

bool canShoot = (nextPrimaryAttack <= currTime) || params.hold;
bulk.buttonStates[params.shotPortal] = canShoot;

if (!params.spam && !params.hold) {
Reset();
}
}
}

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

bool enabled = true;
TasControllerInput button;
bool hold = false;
bool spam = false;

for (std::string param : vp) {
if (param == "off" || param == "stop") {
enabled = false;
}
else if (param == "blue") {
button = TasControllerInput::FireBlue;
}
else if (param == "orange") {
button = TasControllerInput::FireOrange;
}
else if (param == "hold") {
hold = true;
}
else if (param == "spam") {
spam = true;
}
else {
throw TasParserException(Utils::ssprintf("Incorrect parameter for tool %s: %s", this->GetName(), param.c_str()));
}
}

return std::make_shared<ShootToolParams>(enabled, button, spam, hold);
}
30 changes: 30 additions & 0 deletions src/Features/Tas/TasTools/ShootTool.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once
#include "../TasTool.hpp"
#include "../TasController.hpp"

struct ShootToolParams : public TasToolParams {

TasControllerInput shotPortal;
bool spam;
bool hold;

ShootToolParams()
: TasToolParams() {
}
ShootToolParams(bool enabled, TasControllerInput shotPortal, bool spam, bool hold)
: TasToolParams(enabled)
, shotPortal(shotPortal)
, spam(spam)
, hold(hold) {
}
};

class ShootTool : public TasToolWithParams<ShootToolParams> {
public:
ShootTool(int slot) : TasToolWithParams("shoot", slot) {}

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

extern ShootTool tasShootTool[2];
2 changes: 2 additions & 0 deletions src/SourceAutoRecord.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
<ClCompile Include="Features\Tas\TasTools\AngleToolsUtils.cpp" />
<ClCompile Include="Features\Tas\TasPlayer.cpp" />
<ClCompile Include="Features\Tas\TasScript.cpp" />
<ClCompile Include="Features\Tas\TasTools\ShootTool.cpp" />
<ClCompile Include="Features\Tas\TasTools\UseTool.cpp" />
<ClCompile Include="Features\Tas\TasTools\LookTool.cpp" />
<ClCompile Include="Features\Tas\TasTools\MoveTool.cpp" />
Expand Down Expand Up @@ -335,6 +336,7 @@
<ClInclude Include="Features\Tas\TasTools\AngleToolsUtils.hpp" />
<ClInclude Include="Features\Tas\TasPlayer.hpp" />
<ClInclude Include="Features\Tas\TasScript.hpp" />
<ClInclude Include="Features\Tas\TasTools\ShootTool.hpp" />
<ClInclude Include="Features\Tas\TasTools\UseTool.hpp" />
<ClInclude Include="Features\Tas\TasTools\LookTool.hpp" />
<ClInclude Include="Features\Tas\TasTools\MoveTool.hpp" />
Expand Down
14 changes: 13 additions & 1 deletion src/SourceAutoRecord.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,12 @@
<ClCompile Include="Features\Tas\TasTools\MoveTool.cpp">
<Filter>SourceAutoRecord\Features\Tas\TasTools</Filter>
</ClCompile>
<ClCompile Include="Features\Tas\TasTools\ShootTool.cpp">
<Filter>SourceAutoRecord\Features\Tas\TasTools</Filter>
</ClCompile>
<ClCompile Include="Features\Tas\TasTools\UseTool.cpp">
<Filter>SourceAutoRecord\Features\Tas\TasTools</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\lib\minhook\buffer.h">
Expand Down Expand Up @@ -1284,6 +1290,12 @@
<ClInclude Include="Features\Tas\TasTools\MoveTool.hpp">
<Filter>SourceAutoRecord\Features\Tas\TasTools</Filter>
</ClInclude>
<ClInclude Include="Features\Tas\TasTools\ShootTool.hpp">
<Filter>SourceAutoRecord\Features\Tas\TasTools</Filter>
</ClInclude>
<ClInclude Include="Features\Tas\TasTools\UseTool.hpp">
<Filter>SourceAutoRecord\Features\Tas\TasTools</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="SourceAutoRecord">
Expand Down Expand Up @@ -1372,4 +1384,4 @@
<Filter>lib\SFML\System</Filter>
</None>
</ItemGroup>
</Project>
</Project>

0 comments on commit 737f47b

Please sign in to comment.