From 68a17d54f0ef26c44969a22078e237f2264a770d Mon Sep 17 00:00:00 2001 From: Retro <44505837+dankmolot@users.noreply.github.com> Date: Fri, 5 Jul 2024 17:11:36 +0300 Subject: [PATCH] Fixed `FindClosestLine` returns wrong line --- VERSION | 2 +- source/compiler.cpp | 4 ++-- source/compiler.hpp | 3 ++- source/utils.hpp | 3 ++- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/VERSION b/VERSION index ac2cdeb..7d2ed7c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.1.3 +2.1.4 diff --git a/source/compiler.cpp b/source/compiler.cpp index 71403ae..9c2d1a2 100644 --- a/source/compiler.cpp +++ b/source/compiler.cpp @@ -15,10 +15,10 @@ void yue_openlibs(void* state); using namespace MoonLoader; -std::unordered_map ParseYueLines(std::string_view code) { +std::map ParseYueLines(std::string_view code) { static std::regex YUE_LINE_REGEX("--\\s*(\\d*)\\s*$", std::regex_constants::optimize); - std::unordered_map line_map; + std::map line_map; Utils::Split(code, [&](std::string_view line, size_t num) { std::cmatch match; if (std::regex_search(line.data(), line.data() + line.size(), match, YUE_LINE_REGEX)) { diff --git a/source/compiler.hpp b/source/compiler.hpp index 7456835..bcbc2d6 100644 --- a/source/compiler.hpp +++ b/source/compiler.hpp @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -35,7 +36,7 @@ namespace MoonLoader { size_t update_date = 0; Type type; - std::unordered_map line_map; + std::map line_map; }; private: diff --git a/source/utils.hpp b/source/utils.hpp index f922cb4..c9a0f15 100644 --- a/source/utils.hpp +++ b/source/utils.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #if IS_SERVERSIDE #include @@ -219,7 +220,7 @@ namespace MoonLoader::Utils { return std::string(buf.get(), buf.get() + size - 1); // We don't want the '\0' inside } - inline std::optional FindClosestLine(const std::unordered_map& lines, int line) { + inline std::optional FindClosestLine(const std::map& lines, int line) { int closest = -1; for (auto& [key, value] : lines) { if (key > line) break;