Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong lines in errors + crash on changing moonloader_detour_getinfo #19

Merged
merged 2 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.3
2.1.4
4 changes: 2 additions & 2 deletions source/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ void yue_openlibs(void* state);

using namespace MoonLoader;

std::unordered_map<int, int> ParseYueLines(std::string_view code) {
std::map<int, int> ParseYueLines(std::string_view code) {
static std::regex YUE_LINE_REGEX("--\\s*(\\d*)\\s*$", std::regex_constants::optimize);

std::unordered_map<int, int> line_map;
std::map<int, int> 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)) {
Expand Down
3 changes: 2 additions & 1 deletion source/compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <unordered_map>
#include <unordered_set>
#include <map>
#include <string>
#include <string_view>
#include <optional>
Expand Down Expand Up @@ -35,7 +36,7 @@ namespace MoonLoader {
size_t update_date = 0;
Type type;

std::unordered_map<int, int> line_map;
std::map<int, int> line_map;
};

private:
Expand Down
2 changes: 2 additions & 0 deletions source/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ void Core::Initialize(GarrysMod::Lua::ILuaInterface* LUA) {

cvar = InterfacePointers::Cvar();
if (cvar == nullptr) throw std::runtime_error("failed to get ICvar interface");

g_pCVar = cvar;
for (ConVar* convar : moonloader_convars)
cvar->RegisterConCommand(convar);

Expand Down
3 changes: 2 additions & 1 deletion source/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <optional>
#include <memory>
#include <unordered_map>
#include <map>

#if IS_SERVERSIDE
#include <GarrysMod/FactoryLoader.hpp>
Expand Down Expand Up @@ -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<int> FindClosestLine(const std::unordered_map<int, int>& lines, int line) {
inline std::optional<int> FindClosestLine(const std::map<int, int>& lines, int line) {
int closest = -1;
for (auto& [key, value] : lines) {
if (key > line) break;
Expand Down