generated from YimMenu/YimMenuV2
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pointer Cache and Other Enhancements (#216)
* Pointer Cache * Fixes/Enhancements
- Loading branch information
Showing
53 changed files
with
2,237 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include "PatternCache.hpp" | ||
#include "core/filemgr/FileMgr.hpp" | ||
|
||
namespace YimMenu | ||
{ | ||
std::optional<int> PatternCache::GetCachedOffsetImpl(PatternHash hash) | ||
{ | ||
if (auto it = m_Data.find(hash.GetHash()); it != m_Data.end()) | ||
return it->second; | ||
|
||
return std::nullopt; | ||
} | ||
|
||
void PatternCache::UpdateCachedOffsetImpl(PatternHash hash, int offset) | ||
{ | ||
m_Data[hash.GetHash()] = offset; | ||
} | ||
|
||
void PatternCache::InitImpl() | ||
{ | ||
auto file = FileMgr::GetProjectFile("./pattern_cache.bin"); | ||
if (file.Exists()) | ||
{ | ||
std::ifstream stream(file.Path(), std::ios_base::binary); | ||
while (!stream.eof()) | ||
{ | ||
std::uint64_t hash; | ||
int offset; | ||
|
||
stream.read(reinterpret_cast<char*>(&hash), sizeof(hash)); | ||
stream.read(reinterpret_cast<char*>(&offset), sizeof(offset)); | ||
|
||
m_Data.emplace(hash, offset); | ||
} | ||
} | ||
|
||
m_Initialized = true; | ||
} | ||
|
||
void PatternCache::UpdateImpl() | ||
{ | ||
auto file = FileMgr::GetProjectFile("./pattern_cache.bin"); | ||
std::ofstream stream(file.Path(), std::ios_base::binary); | ||
|
||
for (auto& [h, offset] : m_Data) | ||
{ | ||
auto hash = h; | ||
stream.write(reinterpret_cast<char*>(&hash), sizeof(hash)); | ||
stream.write(reinterpret_cast<char*>(&offset), sizeof(offset)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#pragma once | ||
#include "core/memory/PatternHash.hpp" | ||
|
||
namespace YimMenu | ||
{ | ||
class PatternCache | ||
{ | ||
bool m_Initialized; | ||
std::unordered_map<std::uint64_t, int> m_Data; | ||
public: | ||
|
||
PatternCache() : | ||
m_Initialized(false) | ||
{ | ||
} | ||
|
||
static void Init() | ||
{ | ||
GetInstance().InitImpl(); | ||
} | ||
|
||
static void Update() | ||
{ | ||
GetInstance().UpdateImpl(); | ||
} | ||
|
||
static std::optional<int> GetCachedOffset(PatternHash hash) | ||
{ | ||
return GetInstance().GetCachedOffsetImpl(hash); | ||
} | ||
|
||
static void UpdateCachedOffset(PatternHash hash, int offset) | ||
{ | ||
GetInstance().UpdateCachedOffsetImpl(hash, offset); | ||
} | ||
|
||
static bool IsInitialized() | ||
{ | ||
return GetInstance().m_Initialized; | ||
} | ||
|
||
private: | ||
static PatternCache& GetInstance() | ||
{ | ||
static PatternCache Instance; | ||
return Instance; | ||
} | ||
|
||
void InitImpl(); | ||
void UpdateImpl(); | ||
std::optional<int> GetCachedOffsetImpl(PatternHash hash); | ||
void UpdateCachedOffsetImpl(PatternHash hash, int offset); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.