rodecomp/Source/Utility/Lexicon/LexiconBoundary.cpp
ragnarok-clanker 29ca462c8b Decompile fn_17634 (LexiconBoundary::Matches)
Batch #14130 by Yommy: 0 byte-identical, 1 confirmed by peer review.

- fn_17634 LexiconBoundary::Matches: logic confirmed by peer review

Peer-reviewed-by: KWDev, Toshiro, codeplay
Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes).
2026-11-07 06:25:53 +00:00

94 lines
3.6 KiB
C++

#include "Utility/Lexicon/LexiconBoundary.h"
#include "Utility/Lexicon/LexiconSerializer.h"
#include <cstring>
// GLOBAL: gl_24545
std::uint32_t g_lexiconByteClasses[256] = {
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0x1000000, 0x400, 0x400, 0x400, 0x400, 0x400, 0x400, 0x400,
0x10, 0x20, 0x400, 0x400, 0x400, 0x400, 0x404, 0x400,
0x10002, 0x10002, 0x10002, 0x10002, 0x10002, 0x10002, 0x10002, 0x10002,
0x10002, 0x10002, 0x400, 0x400, 0x10, 0x400, 0x20, 0x40,
0x400, 0x100002, 0x100002, 0x100002, 0x100002, 0x100002, 0x100002, 0x100002,
0x100002, 0x100002, 0x100002, 0x100002, 0x100002, 0x100002, 0x100002, 0x100002,
0x100002, 0x100002, 0x100002, 0x100002, 0x100002, 0x100002, 0x100002, 0x100002,
0x100002, 0x100002, 0x100002, 0x10, 0x400, 0x20, 0x400, 0x400,
0x400, 0x200002, 0x200002, 0x200002, 0x200002, 0x200002, 0x200002, 0x200002,
0x200002, 0x200002, 0x200002, 0x200002, 0x200002, 0x200002, 0x200002, 0x200002,
0x200002, 0x200002, 0x200002, 0x200002, 0x200002, 0x200002, 0x200002, 0x200002,
0x200002, 0x200002, 0x200002, 0x10, 0x400, 0x20, 0x400, 0,
0x20001, 0x101, 0x101, 0x101, 0x101, 0x400, 0x8101, 0x8101,
0x8101, 0x8101, 0x4101, 0x8101, 0x8101, 0x8101, 0x8101, 0x4101,
0x20001, 0x414, 0x424, 0x414, 0x424, 0x400, 0x400, 0x400,
0x4101, 0x4101, 0x4101, 0x8101, 0x8101, 0x8101, 0x8101, 0x4101,
0x1000000, 0x20001, 0x20001, 0x20001, 0x20001, 0x20001, 0x20001, 0x20001,
0x20001, 0x20001, 0x20001, 0x20001, 0x20001, 0x20001, 0x20001, 0x20001,
0x20001, 0x20001, 0x20001, 0x20001, 0x20001, 0x20001, 0x20001, 0x20001,
0x20001, 0x20001, 0x20001, 0x20001, 0x20001, 0x20001, 0x20001, 0x20001,
0x20001, 0x20001, 0x20001, 0x20001, 0x20001, 0x20001, 0x20001, 0x20001,
0x20001, 0x20001, 0x20001, 0x20001, 0x20001, 0x20001, 0x20001, 0x201,
0x2001, 0x4101, 0x2001, 0x2001, 0x101, 0x101, 0x101, 0x101,
0x101, 0x101, 0x4101, 0x2000000, 0x400, 0, 0, 0x400,
0x1001, 0x1001, 0x1001, 0x1001, 0x1001, 0x2001, 0x1, 0x4101,
0x8101, 0x8101, 0x8101, 0x8101, 0x4101, 0x4101, 0x4101, 0x400,
0x10001, 0x10001, 0x10001, 0x10001, 0x10001, 0x10001, 0x10001, 0x10001,
0x10001, 0x400, 0x400, 0x101, 0x101, 0x101, 0, 0,
};
// INLINED
static bool HasClass(std::uint32_t classes, int bit) {
return ((classes >> bit) & 1) != 0;
}
// OFFSET: 0x00AC4EA0
// FUNCTION: fn_17634
bool LexiconBoundary::Matches(unsigned char previous, unsigned char current, unsigned char options) const {
if (previous == 0xDD) {
return true;
}
if (HasClass(this->flags[previous], 0) && (this->flags[current] & 0x2100) != 0) {
return true;
}
if (current == 32) {
return true;
}
if (previous == 32) {
return false;
}
const std::uint32_t& before = this->flags[previous];
const std::uint32_t& after = this->flags[current];
if ((options & 2) != 0) {
return ((after & 0x470) != 0) == ((before & 0x470) != 0) &&
((HasClass(before, 12) && HasClass(after, 0)) || ((before & 0x470) != 0 && (after & 0x470) != 0) ||
(HasClass(before, 1) && HasClass(after, 1)));
}
if (HasClass(after, 4) && !HasClass(before, 4)) {
return false;
}
if ((after & 0x60) != 0 || HasClass(before, 4) || (HasClass(before, 12) && HasClass(after, 0))) {
return true;
}
return (HasClass(before, 10) && (after & 0x10002) != 0) || HasClass(after, 10);
}
// OFFSET: 0x00AC4A40
// FUNCTION: fn_17632
bool LexiconBoundary::Load() {
delete this->serializer;
this->serializer = new LexiconSerializer;
this->serializer->Load("..\\ftwrk.lex");
std::memcpy(this->flags, g_lexiconByteClasses, sizeof(this->flags));
return this->serializer != nullptr;
}