Skip to content

Debugger: spawn monsters by id, and fix truncated UTF-8 names - #240

Open
devtejasx wants to merge 2 commits into
ThePhrozenKeep:masterfrom
devtejasx:feat/debugger-spawn-by-id-113
Open

devtejasx wants to merge 2 commits into
ThePhrozenKeep:masterfrom
devtejasx:feat/debugger-spawn-by-id-113

Conversation

@devtejasx

Copy link
Copy Markdown
Contributor

Two small debugger changes, one commit each.

Spawn by id (#113). The unit spawner only had a combo box of names, so reaching a given monstats or superuniques row meant scrolling through hundreds of entries, and rows that share a name (lots of "Fallen", "Zombie", ...) couldn't be told apart.

  • The combo boxes now show <id>: <name>.
  • Each spawner gets an id input that selects the row directly, clamped to the table's record count.

This covers the "SuperUnique monster by id" and "Normal monster by id" items in #113.

Truncated names. GetUTF8CharBufferFromStringIndex sized its buffer at exactly 3 bytes per character and passed size - 2 to toUtf, which stops once count - 1 bytes are used. So:

  • a 1-character name came back empty,
  • names of 3-byte characters lost their last character (中文 became 中),
  • an empty string made an empty vector, so the count was size_t(-2) and toUtf wrote its terminator through the null data() pointer.

The buffer now has 3 extra bytes, enough for the last character and never empty.

I can't build the project here (no 32-bit MSVC), so I checked both parts outside it: the new helpers compile with g++ -Wall -Wextra against a stub ImGui::InputInt and give the expected labels and clamping. A host model of toUtf's loop converts "", "A", "Ab", "Andariel", "é", "中" and "中文" in full with the new size, and reproduces all three problems with the old one.

Refs #113

GetUTF8CharBufferFromStringIndex sized its buffer at exactly 3 bytes
per character and passed size - 2 as the toUtf capacity. toUtf stops
once (count - 1) bytes are used, so that was too small to hold the
whole string:

- a 1-character name came back empty (size 3, count 1),
- names of 3-byte characters lost their last character
  ("中文" became "中"),
- an empty string made an empty vector, so count was size_t(-2) and
  toUtf wrote the terminator through its null data() pointer, which
  ImGui then read as the label.

Add 3 bytes so the last character always fits and the buffer is never
empty. Checked with a host model of toUtf's loop over "", "A", "Ab",
"Andariel", "é", "中" and "中文": all now convert in full.
The unit spawner only offered a combo box of names, so getting to a
given monstats or superuniques row meant scrolling through hundreds of
entries, and rows that share a display name (many monsters are just
"Fallen" or "Zombie") could not be told apart.

- Show "<id>: <name>" in both combo boxes.
- Add an id input under each spawner that selects the row directly,
  clamped to the table's record count.

Covers the "SuperUnique monster by id" and "Normal monster by id" items
of ThePhrozenKeep#113.

The project only builds with 32-bit MSVC, which this machine does not
have; the new helpers were compiled with g++ -Wall -Wextra against a
stub ImGui::InputInt and checked for the label text and the clamping.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant