-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add zoom, duck, stop and cmd tas tools
- Loading branch information
Showing
11 changed files
with
312 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters