diff --git a/src/core/backend/PatternCache.cpp b/src/core/backend/PatternCache.cpp index 2fba081..772b561 100644 --- a/src/core/backend/PatternCache.cpp +++ b/src/core/backend/PatternCache.cpp @@ -6,6 +6,7 @@ namespace YimMenu { std::optional PatternCache::GetCachedOffsetImpl(PatternHash hash) { + std::lock_guard lock(m_Mutex); if (auto it = m_Data.find(hash.GetHash()); it != m_Data.end()) return it->second; @@ -14,11 +15,14 @@ namespace YimMenu void PatternCache::UpdateCachedOffsetImpl(PatternHash hash, int offset) { + std::lock_guard lock(m_Mutex); m_Data[hash.GetHash()] = offset; } void PatternCache::InitImpl() { + std::lock_guard lock(m_Mutex); + auto file = FileMgr::GetProjectFile("./pattern_cache.bin"); if (file.Exists()) { @@ -40,6 +44,8 @@ namespace YimMenu void PatternCache::UpdateImpl() { + std::lock_guard lock(m_Mutex); + auto file = FileMgr::GetProjectFile("./pattern_cache.bin"); std::ofstream stream(file.Path(), std::ios_base::binary); diff --git a/src/core/backend/PatternCache.hpp b/src/core/backend/PatternCache.hpp index 8bc921f..3c7ac70 100644 --- a/src/core/backend/PatternCache.hpp +++ b/src/core/backend/PatternCache.hpp @@ -7,6 +7,7 @@ namespace YimMenu { bool m_Initialized; std::unordered_map m_Data; + std::mutex m_Mutex; public: PatternCache() : diff --git a/src/core/memory/BytePatches.cpp b/src/core/memory/BytePatches.cpp index 569bf0b..70b7958 100644 --- a/src/core/memory/BytePatches.cpp +++ b/src/core/memory/BytePatches.cpp @@ -11,6 +11,9 @@ namespace YimMenu { if (m_Applied || !g_Running) return; + + std::lock_guard lock(m_Mutex); // this function should be thread-safe, but doesn't hurt + unsigned long old_protect; unsigned long temp; VirtualProtect(m_Address, m_Size, PAGE_EXECUTE_READWRITE, &old_protect); @@ -23,6 +26,9 @@ namespace YimMenu { if (!m_Applied) return; + + std::lock_guard lock(m_Mutex); + unsigned long old_protect; unsigned long temp; VirtualProtect(m_Address, m_Size, PAGE_EXECUTE_READWRITE, &old_protect); diff --git a/src/game/features/world/TimeControl.cpp b/src/game/features/world/TimeControl.cpp index aab26c1..6c2028a 100644 --- a/src/game/features/world/TimeControl.cpp +++ b/src/game/features/world/TimeControl.cpp @@ -5,9 +5,9 @@ namespace YimMenu::Features { - static IntCommand _NetworkTimeHour{"networktimehour", "Hour", "Set hour (0–23)", 0, 23, 12}; - static IntCommand _NetworkTimeMinute{"networktimeminute", "Minute", "Set minute (0–59)", 0, 59, 0}; - static IntCommand _NetworkTimeSecond{"networktimesecond", "Second", "Set second (0–59)", 0, 59, 0}; + static IntCommand _NetworkTimeHour{"networktimehour", "Hour", "Set hour (0-23)", 0, 23, 12}; + static IntCommand _NetworkTimeMinute{"networktimeminute", "Minute", "Set minute (0-59)", 0, 59, 0}; + static IntCommand _NetworkTimeSecond{"networktimesecond", "Second", "Set second (0-59)", 0, 59, 0}; class SetNetworkTime : public Command