Skip to content

Commit 9cc5704

Browse files
committed
fix(input), add(bypass-length-check): Fix crashes when highlighting text, add new bypass length check feature
1 parent a8213b1 commit 9cc5704

File tree

6 files changed

+44
-24
lines changed

6 files changed

+44
-24
lines changed

ABOUT.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ The CCTextInputNode implementation Robert was too lazy to implement.
88
- Better text input™️
99
- Ctrl+A, Ctrl + Left/Right Arrow, Shift + Left/Right Arrow, Home, End and a bunch more hotkeys
1010
- Esc to deselect an input node
11+
- Ability to bypass character filter (can be disabled)
12+
- Ability to bypass max input length (can be disabled)
1113

1214
Ya that's pretty much it for now, at least.
1315

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,20 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [v4.1.0-beta] - 2024-06-19
99

10+
### Added
11+
12+
- Ability to bypass max input length (can be disabled)
13+
1014
### Changed
1115

1216
- 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`)
1317

1418
### Fixed
1519

1620
- Crash in level editor
21+
- Pasting text bypassing allowed characters filter
1722
- Space character weirdness in `CCTextInputNode`s with `CCLabelBMFont`s
23+
- More crashes! (when highlighting text)
1824

1925
## [v4.0.0-beta] - 2024-06-13
2026

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Brings Windows-like input options to `CCTextInputNode`s.
88
- Better text input™️
99
- Ctrl+A, Ctrl + Left/Right Arrow, Shift + Left/Right Arrow, Home, End and a bunch more hotkeys
1010
- Esc to deselect an input node
11+
- Ability to bypass character filter (can be disabled)
12+
- Ability to bypass max input length (can be disabled)
1113

1214
## Image
1315

mod.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"geode": "3.0.0-beta.1",
2+
"geode": "3.0.0-beta.2",
33
"gd": {
44
"win": "2.206"
55
},
@@ -30,6 +30,12 @@
3030
"default": true,
3131
"name": "Allow any character",
3232
"description": "Allows inputting any character (even ones not allowed) into input nodes."
33+
},
34+
"bypass-length-check": {
35+
"type": "bool",
36+
"default": true,
37+
"name": "Bypass length check",
38+
"description": "Allows inserting however many characters into an input node."
3339
}
3440
}
3541
}

src/main.cpp

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,6 @@ struct BetterTextInputNode : Modify<BetterTextInputNode, CCTextInputNode>
104104
// a space or not, which we fix below (i think CCTextInputNode is very ass)
105105
if (m_fields->m_string.length() >= 2)
106106
{
107-
// ???
108-
if (m_fields->m_pos > m_fields->m_string.length() - 1)
109-
m_fields->m_pos = -1;
110-
111107
// what's to the right of the cursor
112108
int pos = m_fields->m_pos == -1 ? m_fields->m_string.length() - 1 : m_fields->m_pos;
113109
const auto& cursorTextLabelInfo = getTextLabelInfoFromPos(m_fields->m_pos);
@@ -731,9 +727,9 @@ struct BetterTextInputNode : Modify<BetterTextInputNode, CCTextInputNode>
731727
{
732728
if (
733729
!BI::geode::get<bool>("allow-any-character") &&
734-
BI::gd::isVanillaInput() &&
735730
std::string_view(this->m_allowedChars).find(character) == std::string_view::npos
736-
) return;
731+
)
732+
return;
737733

738734
const bool wasHighlighting = m_fields->m_highlighted.isHighlighting();
739735

@@ -994,9 +990,30 @@ struct BetterTextInputNode : Modify<BetterTextInputNode, CCTextInputNode>
994990
void setAndUpdateString(const std::string& str)
995991
{
996992
// the position is modified in the call to setString
997-
const int prevPos = m_fields->m_pos;
993+
int prevPos = m_fields->m_pos;
998994
m_fields->m_string = str;
999995

996+
if (!BI::geode::get<bool>("allow-any-character"))
997+
std::erase_if(
998+
m_fields->m_string,
999+
[&](char c) -> bool {
1000+
return std::string_view(this->m_allowedChars).find(c) == std::string_view::npos;
1001+
}
1002+
);
1003+
1004+
if (
1005+
!BI::geode::get<bool>("bypass-length-check") &&
1006+
this->m_maxLabelLength != 0 &&
1007+
m_fields->m_string.length() >= this->m_maxLabelLength
1008+
) {
1009+
m_fields->m_string = m_fields->m_string.substr(0, this->m_maxLabelLength);
1010+
m_fields->m_string.resize(this->m_maxLabelLength);
1011+
1012+
// sorry...
1013+
if (m_fields->m_pos >= m_fields->m_string.length())
1014+
prevPos = -1;
1015+
}
1016+
10001017
CCTextInputNode::setString(str);
10011018

10021019
m_fields->m_pos = prevPos;
@@ -1015,6 +1032,9 @@ struct BetterTextInputNode : Modify<BetterTextInputNode, CCTextInputNode>
10151032
{
10161033
m_fields->m_use_update_blink_pos = true;
10171034

1035+
if (pos >= m_fields->m_string.length())
1036+
pos = -1;
1037+
10181038
this->updateBlinkLabelToChar(pos);
10191039

10201040
m_fields->m_use_update_blink_pos = false;

src/utils.hpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -153,22 +153,6 @@ namespace BI
153153
}
154154
}
155155

156-
namespace gd
157-
{
158-
inline bool isVanillaInput()
159-
{
160-
return true;
161-
// std::uintptr_t readMemory;
162-
163-
// #ifdef GEODE_IS_WINDOWS
164-
// std::memcpy(&readMemory, reinterpret_cast<void*>(geode::base::get() + 0x2F974), 1);
165-
// #elif defined(GEODE_IS_MACOS)
166-
// std::memcpy(&readMemory, reinterpret_cast<void*>(geode::base::get() + 0x2F974), 1);
167-
// #endif
168-
// return readMemory == 0x0475;
169-
}
170-
}
171-
172156
namespace geode
173157
{
174158
template<typename T>

0 commit comments

Comments
 (0)