diff --git a/ABOUT.md b/ABOUT.md index f04c176..0af346f 100644 --- a/ABOUT.md +++ b/ABOUT.md @@ -8,6 +8,8 @@ The CCTextInputNode implementation Robert was too lazy to implement. - Better text input™️ - Ctrl+A, Ctrl + Left/Right Arrow, Shift + Left/Right Arrow, Home, End and a bunch more hotkeys - Esc to deselect an input node +- Ability to bypass character filter (can be disabled) +- Ability to bypass max input length (can be disabled) Ya that's pretty much it for now, at least. diff --git a/CHANGELOG.md b/CHANGELOG.md index baf47c5..69ccca1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [v4.1.0-beta] - 2024-06-19 +### Added + +- Ability to bypass max input length (can be disabled) + ### Changed - How the AlertFix works, again... Checks for touch priority if the layer has a touch priority, if not then it falls back to Z order (it was also causing a crash in `LevelEditLayer`) @@ -14,7 +18,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Fixed - Crash in level editor +- Pasting text bypassing allowed characters filter - Space character weirdness in `CCTextInputNode`s with `CCLabelBMFont`s +- More crashes! (when highlighting text) ## [v4.0.0-beta] - 2024-06-13 diff --git a/README.md b/README.md index 0900e7e..1ad7e54 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ Brings Windows-like input options to `CCTextInputNode`s. - Better text input™️ - Ctrl+A, Ctrl + Left/Right Arrow, Shift + Left/Right Arrow, Home, End and a bunch more hotkeys - Esc to deselect an input node +- Ability to bypass character filter (can be disabled) +- Ability to bypass max input length (can be disabled) ## Image diff --git a/mod.json b/mod.json index 0cbd97b..2bc5623 100644 --- a/mod.json +++ b/mod.json @@ -1,5 +1,5 @@ { - "geode": "3.0.0-beta.1", + "geode": "3.0.0-beta.2", "gd": { "win": "2.206" }, @@ -30,6 +30,12 @@ "default": true, "name": "Allow any character", "description": "Allows inputting any character (even ones not allowed) into input nodes." + }, + "bypass-length-check": { + "type": "bool", + "default": true, + "name": "Bypass length check", + "description": "Allows inserting however many characters into an input node." } } } \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 15b4068..28e8241 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -104,10 +104,6 @@ struct BetterTextInputNode : Modify // a space or not, which we fix below (i think CCTextInputNode is very ass) if (m_fields->m_string.length() >= 2) { - // ??? - if (m_fields->m_pos > m_fields->m_string.length() - 1) - m_fields->m_pos = -1; - // what's to the right of the cursor int pos = m_fields->m_pos == -1 ? m_fields->m_string.length() - 1 : m_fields->m_pos; const auto& cursorTextLabelInfo = getTextLabelInfoFromPos(m_fields->m_pos); @@ -731,9 +727,9 @@ struct BetterTextInputNode : Modify { if ( !BI::geode::get("allow-any-character") && - BI::gd::isVanillaInput() && std::string_view(this->m_allowedChars).find(character) == std::string_view::npos - ) return; + ) + return; const bool wasHighlighting = m_fields->m_highlighted.isHighlighting(); @@ -994,9 +990,30 @@ struct BetterTextInputNode : Modify void setAndUpdateString(const std::string& str) { // the position is modified in the call to setString - const int prevPos = m_fields->m_pos; + int prevPos = m_fields->m_pos; m_fields->m_string = str; + if (!BI::geode::get("allow-any-character")) + std::erase_if( + m_fields->m_string, + [&](char c) -> bool { + return std::string_view(this->m_allowedChars).find(c) == std::string_view::npos; + } + ); + + if ( + !BI::geode::get("bypass-length-check") && + this->m_maxLabelLength != 0 && + m_fields->m_string.length() >= this->m_maxLabelLength + ) { + m_fields->m_string = m_fields->m_string.substr(0, this->m_maxLabelLength); + m_fields->m_string.resize(this->m_maxLabelLength); + + // sorry... + if (m_fields->m_pos >= m_fields->m_string.length()) + prevPos = -1; + } + CCTextInputNode::setString(str); m_fields->m_pos = prevPos; @@ -1015,6 +1032,9 @@ struct BetterTextInputNode : Modify { m_fields->m_use_update_blink_pos = true; + if (pos >= m_fields->m_string.length()) + pos = -1; + this->updateBlinkLabelToChar(pos); m_fields->m_use_update_blink_pos = false; diff --git a/src/utils.hpp b/src/utils.hpp index d009727..35e61a1 100644 --- a/src/utils.hpp +++ b/src/utils.hpp @@ -153,22 +153,6 @@ namespace BI } } - namespace gd - { - inline bool isVanillaInput() - { - return true; -// std::uintptr_t readMemory; - -// #ifdef GEODE_IS_WINDOWS -// std::memcpy(&readMemory, reinterpret_cast(geode::base::get() + 0x2F974), 1); -// #elif defined(GEODE_IS_MACOS) -// std::memcpy(&readMemory, reinterpret_cast(geode::base::get() + 0x2F974), 1); -// #endif -// return readMemory == 0x0475; - } - } - namespace geode { template