Skip to content

Commit d7c93e2

Browse files
committed
fix: correct error handling in some tas tools
1 parent ba855f3 commit d7c93e2

File tree

4 files changed

+31
-22
lines changed

4 files changed

+31
-22
lines changed

src/Features/Tas/TasTools/AutoAimTool.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,27 @@ std::shared_ptr<TasToolParams> AutoAimTool::ParseParams(std::vector<std::string>
2222
throw TasParserArgumentCountException(this, args.size());
2323
}
2424

25-
int ticks;
26-
AngleToolsUtils::EasingType easingType;
25+
int ticks = 1;
26+
AngleToolsUtils::EasingType easingType = AngleToolsUtils::EasingType::Linear;
2727

2828
// ticks
2929
unsigned ticksPos = usesEntitySelector ? 2 : 3;
30-
try {
31-
ticks = args.size() >= ticksPos + 1 ? std::stoi(args[ticksPos]) : 1;
32-
} catch (...) {
33-
throw TasParserArgumentException(this, "ticks", args[ticksPos]);
30+
if (args.size() >= ticksPos + 1) {
31+
try {
32+
ticks = std::stoi(args[ticksPos]);
33+
} catch (...) {
34+
throw TasParserArgumentException(this, "ticks", args[ticksPos]);
35+
}
3436
}
3537

3638
// easing type
3739
unsigned typePos = usesEntitySelector ? 3 : 4;
38-
try {
39-
easingType = AngleToolsUtils::ParseEasingType(args.size() >= typePos + 1 ? args[typePos] : "linear");
40-
} catch (...) {
41-
throw TasParserArgumentException(this, "interpolation", args[typePos]);
40+
if (args.size() >= typePos + 1) {
41+
try {
42+
easingType = AngleToolsUtils::ParseEasingType(args[typePos]);
43+
} catch (...) {
44+
throw TasParserArgumentException(this, "interpolation", args[typePos]);
45+
}
4246
}
4347

4448
if (usesEntitySelector) {

src/Features/Tas/TasTools/DuckTool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void DuckTool::Apply(TasFramebulk &bulk, const TasPlayerInfo &pInfo) {
2929

3030
std::shared_ptr<TasToolParams> DuckTool::ParseParams(std::vector<std::string> vp) {
3131
if (vp.size() != 1)
32-
TasParserArgumentCountException(this, vp.size());
32+
throw TasParserArgumentCountException(this, vp.size());
3333

3434
bool enabled = true;
3535
int time = INT32_MAX;

src/Features/Tas/TasTools/LookTool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void LookTool::Apply(TasFramebulk &fb, const TasPlayerInfo &playerInfo) {
3232
std::shared_ptr<TasToolParams> LookTool::ParseParams(std::vector<std::string> vp) {
3333

3434
if (vp.size() == 0) {
35-
throw TasParserException(Utils::ssprintf("Wrong argument count for tool %s: %d", this->GetName(), vp.size()));
35+
throw TasParserArgumentCountException(this, vp.size());
3636
}
3737

3838
float pitchDelta = 0.0f;

src/Features/Tas/TasTools/SetAngleTool.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ std::shared_ptr<TasToolParams> SetAngleTool::ParseParams(std::vector<std::string
5151
std::string target;
5252
float pitch;
5353
float yaw;
54-
int ticks;
55-
AngleToolsUtils::EasingType easingType;
54+
int ticks = 1;
55+
AngleToolsUtils::EasingType easingType = AngleToolsUtils::EasingType::Linear;
5656
int i = 2;
5757

5858
if (vp[0] == "off") {
@@ -83,18 +83,23 @@ std::shared_ptr<TasToolParams> SetAngleTool::ParseParams(std::vector<std::string
8383
}
8484

8585
// ticks
86-
try {
87-
ticks = vp.size() >= (size_t)(i + 1) ? std::stoi(vp[i]) : 1;
88-
} catch (...) {
89-
throw TasParserArgumentException(this, "tick", vp[i]);
86+
if (vp.size() >= i + 1) {
87+
try {
88+
ticks = std::stoi(vp[i]);
89+
} catch (...) {
90+
throw TasParserArgumentException(this, "tick", vp[i]);
91+
}
9092
}
9193

9294
// easing type
93-
try {
94-
easingType = AngleToolsUtils::ParseEasingType(vp.size() >= (size_t)(i + 2) ? vp[i + 1] : "linear");
95-
} catch (...) {
96-
throw TasParserArgumentException(this, "interpolation", vp[i + 1]);
95+
if (vp.size() >= i + 2) {
96+
try {
97+
easingType = AngleToolsUtils::ParseEasingType(vp[i + 1]);
98+
} catch (...) {
99+
throw TasParserArgumentException(this, "interpolation", vp[i + 1]);
100+
}
97101
}
102+
98103

99104
return std::make_shared<SetAngleParams>(target, pitch, yaw, ticks, easingType);
100105
}

0 commit comments

Comments
 (0)