Skip to content

Commit

Permalink
fixed createpatch and undopatch
Browse files Browse the repository at this point in the history
  • Loading branch information
KillStr3aK committed Dec 12, 2023
1 parent 2ab6164 commit 13c897d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
27 changes: 26 additions & 1 deletion src/core/managers/memory_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void MemoryManager::OnAllInitialized()

for (const auto& gameConfigPatch : gameConfigPatches)
{
CreatePatch(gameConfigPatch.first.c_str(), gameConfigPatch.second.c_str());
CreatePatch(gameConfigPatch.first.c_str(), gameConfigPatch.first.c_str());
}
}

Expand All @@ -38,11 +38,18 @@ void MemoryManager::OnShutdown()
for (const auto& patch : m_memoryPatches)
{
patch.second->UndoPatch();
delete patch.second;
}
}

bool MemoryManager::CreatePatch(const char* pszSignatureName, const char* pszName)
{
if (DoesPatchExists(pszSignatureName))
{
CSSHARP_CORE_ERROR("Patch for '{}' already exists ({})", pszSignatureName, pszName);
return false;
}

CMemPatch* patch = new CMemPatch(pszSignatureName, pszName);

if (patch->PerformPatch(globals::gameConfig))
Expand All @@ -62,6 +69,24 @@ void MemoryManager::UndoPatch(const char* pszSignatureName)
}

it->second->UndoPatch();
delete it->second;
m_memoryPatches.erase(it->first);
}

bool MemoryManager::DoesPatchExists(const char* pszSignatureName)
{
auto it = m_memoryPatches.find(pszSignatureName);
return it != m_memoryPatches.end();
}

CMemPatch* MemoryManager::GetPatchByName(const char* pszSignatureName)
{
auto it = m_memoryPatches.find(pszSignatureName);
if (it == m_memoryPatches.end()) {
return nullptr;
}

return it->second;
}

void* MemoryManager::GetPatchAddress(const char* pszSignatureName)
Expand Down
8 changes: 5 additions & 3 deletions src/core/managers/memory_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ class MemoryManager : public GlobalClass {
void OnAllInitialized() override;
void OnShutdown() override;

bool CreatePatch(const char* pSignatureName, const char* pszName);
void UndoPatch(const char* pSignatureName);
bool CreatePatch(const char* pszSignatureName, const char* pszName);
void UndoPatch(const char* pszSignatureName);
bool DoesPatchExists(const char* pszSignatureName);
CMemPatch* GetPatchByName(const char* pszSignatureName);

void* GetPatchAddress(const char* pSignatureName);
void* GetPatchAddress(const char* pszSignatureName);

private:
std::unordered_map<std::string, CMemPatch*> m_memoryPatches;
Expand Down

0 comments on commit 13c897d

Please sign in to comment.