diff options
Diffstat (limited to 'src/input_common/drivers/tas_input.cpp')
-rw-r--r-- | src/input_common/drivers/tas_input.cpp | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/src/input_common/drivers/tas_input.cpp b/src/input_common/drivers/tas_input.cpp index 5bdd5dac3..944e141bf 100644 --- a/src/input_common/drivers/tas_input.cpp +++ b/src/input_common/drivers/tas_input.cpp @@ -23,7 +23,7 @@ enum class Tas::TasAxis : u8 { }; // Supported keywords and buttons from a TAS file -constexpr std::array<std::pair<std::string_view, TasButton>, 20> text_to_tas_button = { +constexpr std::array<std::pair<std::string_view, TasButton>, 18> text_to_tas_button = { std::pair{"KEY_A", TasButton::BUTTON_A}, {"KEY_B", TasButton::BUTTON_B}, {"KEY_X", TasButton::BUTTON_X}, @@ -40,8 +40,9 @@ constexpr std::array<std::pair<std::string_view, TasButton>, 20> text_to_tas_but {"KEY_DDOWN", TasButton::BUTTON_DOWN}, {"KEY_SL", TasButton::BUTTON_SL}, {"KEY_SR", TasButton::BUTTON_SR}, - {"KEY_CAPTURE", TasButton::BUTTON_CAPTURE}, - {"KEY_HOME", TasButton::BUTTON_HOME}, + // These buttons are disabled to avoid TAS input from activating hotkeys + // {"KEY_CAPTURE", TasButton::BUTTON_CAPTURE}, + // {"KEY_HOME", TasButton::BUTTON_HOME}, {"KEY_ZL", TasButton::TRIGGER_ZL}, {"KEY_ZR", TasButton::TRIGGER_ZR}, }; @@ -105,10 +106,16 @@ void Tas::LoadTasFile(size_t player_index, size_t file_index) { continue; } - const auto num_frames = std::stoi(seg_list[0]); - while (frame_no < num_frames) { - commands[player_index].emplace_back(); - frame_no++; + try { + const auto num_frames = std::stoi(seg_list[0]); + while (frame_no < num_frames) { + commands[player_index].emplace_back(); + frame_no++; + } + } catch (const std::invalid_argument&) { + LOG_ERROR(Input, "Invalid argument: '{}' at command {}", seg_list[0], frame_no); + } catch (const std::out_of_range&) { + LOG_ERROR(Input, "Out of range: '{}' at command {}", seg_list[0], frame_no); } TASCommand command = { @@ -233,10 +240,21 @@ TasAnalog Tas::ReadCommandAxis(const std::string& line) const { } } - const float x = std::stof(seg_list.at(0)) / 32767.0f; - const float y = std::stof(seg_list.at(1)) / 32767.0f; + if (seg_list.size() < 2) { + LOG_ERROR(Input, "Invalid axis data: '{}'", line); + return {}; + } - return {x, y}; + try { + const float x = std::stof(seg_list.at(0)) / 32767.0f; + const float y = std::stof(seg_list.at(1)) / 32767.0f; + return {x, y}; + } catch (const std::invalid_argument&) { + LOG_ERROR(Input, "Invalid argument: '{}'", line); + } catch (const std::out_of_range&) { + LOG_ERROR(Input, "Out of range: '{}'", line); + } + return {}; } u64 Tas::ReadCommandButtons(const std::string& line) const { |