Decompile fn_13876 (UITagListBox::ParseTag)

Batch #8010 by secret: 0 byte-identical, 1 confirmed by peer review.

- fn_13876 UITagListBox::ParseTag: logic confirmed by peer review

Peer-reviewed-by: eAthena, pedrao
Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes).
This commit is contained in:
ragnarok-clanker 2026-10-31 13:29:36 +00:00
commit 8a2c45f0f6
2 changed files with 80 additions and 0 deletions

View file

@ -425,3 +425,80 @@ void UITagListBox::sub_9B9EA0(std::intptr_t argument1, std::intptr_t argument2,
this->Invalidate();
}
// GLOBAL: gl_25151
std::string infoTagOpening = "<INFO>";
// GLOBAL: gl_25152
std::string infoTagClosing = "</INFO>";
namespace {
// INLINED
std::string ItemName(int id) {
ITEM_DESC description = FindItemDescription(id);
return description.identifiedName;
}
}
// OFFSET: 0x009B94E0
// FUNCTION: fn_13876
std::pair<std::string, std::string> UITagListBox::ParseTag(std::string text, int tagIndex) {
std::pair<std::string, std::string> result;
if (text.size() == 0) {
return result;
}
if (text.find(g_textTagRegistry[tagIndex].opening) == std::string::npos) {
return result;
}
std::size_t closing = text.find(g_textTagRegistry[tagIndex].closing);
if (closing == std::string::npos) {
return result;
}
switch (g_textTagRegistry[tagIndex].type) {
case 438: {
const std::size_t opening = text.find(infoTagOpening, 0);
if (opening == std::string::npos) {
return result;
}
closing = text.find(infoTagClosing, 0);
if (closing == std::string::npos) {
return result;
}
std::string marker = infoTagOpening;
const std::size_t start = g_textTagRegistry[tagIndex].opening.size();
result.first += text.substr(start, opening - start);
result.second += text.substr(opening + marker.size(), closing - marker.size() - opening);
break;
}
case 464: {
const std::size_t opening = text.find(infoTagOpening, 0);
if (opening == std::string::npos) {
return result;
}
closing = text.find(infoTagClosing, 0);
if (closing == std::string::npos) {
return result;
}
std::string marker = infoTagOpening;
const std::size_t start = g_textTagRegistry[tagIndex].opening.size();
result.first += text.substr(start, opening - start);
result.second += text.substr(opening + marker.size(), closing - marker.size() - opening);
break;
}
case 501: {
result.first = text.substr(0, 1);
const std::size_t start = g_textTagRegistry[tagIndex].opening.size();
result.second = text.substr(start, closing - start);
std::vector<int> fields;
this->DecodeItemFields(result.second, fields);
result.first += ItemName(fields[2]);
result.first += text.substr(text.size() - 1, 1);
break;
}
}
return result;
}

View file

@ -2,8 +2,10 @@
#define RAGNAROK_SOURCE_UI_LISTS_UITAGLISTBOX_H
#include "UI/Lists/UIListBox.h"
#include "UI/TextTags.h"
#include <string>
#include <utility>
#include <vector>
struct ITEM_INFO;
@ -32,6 +34,7 @@ public:
void sub_9B9EA0(std::intptr_t argument1, std::intptr_t argument2, std::intptr_t argument3, std::intptr_t argument4);
void sub_9BC0A0(std::intptr_t type, UIWindow* sender);
std::string sub_9B8AA0(std::string text);
std::pair<std::string, std::string> ParseTag(std::string text, int tagIndex);
void sub_9BB8E0(std::string text, std::vector<STagInfoV2>& tags, int width);
int DecodeNumber(std::string text);
void DecodeItemFields(const std::string& text, std::vector<int>& fields);