Skip to content

Commit

Permalink
fix(input), add(bypass-length-check): Fix crashes when highlighting t…
Browse files Browse the repository at this point in the history
…ext, add new bypass length check feature
  • Loading branch information
SpaghettDev committed Jun 20, 2024
1 parent a8213b1 commit 9cc5704
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 24 deletions.
2 changes: 2 additions & 0 deletions ABOUT.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@ 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`)

### 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

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 7 additions & 1 deletion mod.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"geode": "3.0.0-beta.1",
"geode": "3.0.0-beta.2",
"gd": {
"win": "2.206"
},
Expand Down Expand Up @@ -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."
}
}
}
34 changes: 27 additions & 7 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ struct BetterTextInputNode : Modify<BetterTextInputNode, CCTextInputNode>
// 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);
Expand Down Expand Up @@ -731,9 +727,9 @@ struct BetterTextInputNode : Modify<BetterTextInputNode, CCTextInputNode>
{
if (
!BI::geode::get<bool>("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();

Expand Down Expand Up @@ -994,9 +990,30 @@ struct BetterTextInputNode : Modify<BetterTextInputNode, CCTextInputNode>
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<bool>("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<bool>("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;
Expand All @@ -1015,6 +1032,9 @@ struct BetterTextInputNode : Modify<BetterTextInputNode, CCTextInputNode>
{
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;
Expand Down
16 changes: 0 additions & 16 deletions src/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<void*>(geode::base::get() + 0x2F974), 1);
// #elif defined(GEODE_IS_MACOS)
// std::memcpy(&readMemory, reinterpret_cast<void*>(geode::base::get() + 0x2F974), 1);
// #endif
// return readMemory == 0x0475;
}
}

namespace geode
{
template<typename T>
Expand Down

0 comments on commit 9cc5704

Please sign in to comment.