From 9dadfea04ddb04f391537a69ff0fb59ebec0a7ec Mon Sep 17 00:00:00 2001 From: skuzzis <61626661+skuzzis@users.noreply.github.com> Date: Fri, 11 Oct 2024 21:10:12 +0000 Subject: [PATCH] feat(scripting/memory): Allocate/Deallocate --- src/plugins/core/scripting.h | 3 ++ src/plugins/core/scripting/memory/memory.cpp | 32 ++++++++++++++++++++ src/plugins/lua/scripting/memory/memory.cpp | 2 ++ 3 files changed, 37 insertions(+) diff --git a/src/plugins/core/scripting.h b/src/plugins/core/scripting.h index bf76c778..61660590 100644 --- a/src/plugins/core/scripting.h +++ b/src/plugins/core/scripting.h @@ -849,6 +849,9 @@ class PluginMemory void AccessVTable(int64_t offset); bool AccessedVTable(); + void Allocate(uint64_t size); + void Deallocate(); + void Clear(); void SetBool(bool value); diff --git a/src/plugins/core/scripting/memory/memory.cpp b/src/plugins/core/scripting/memory/memory.cpp index 30ccf691..4a95e1ae 100644 --- a/src/plugins/core/scripting/memory/memory.cpp +++ b/src/plugins/core/scripting/memory/memory.cpp @@ -98,46 +98,57 @@ void PluginMemory::SetBool(bool value) { *((bool*)(m_ptr)) = value; } + void PluginMemory::SetInt(int value) { *((int*)(m_ptr)) = value; } + void PluginMemory::SetInt64(int64_t value) { *((int64_t*)(m_ptr)) = value; } + void PluginMemory::SetUint(uint32_t value) { *((uint32_t*)(m_ptr)) = value; } + void PluginMemory::SetUint64(uint64_t value) { *((uint64_t*)(m_ptr)) = value; } + void PluginMemory::SetFloat(float value) { *((float*)(m_ptr)) = value; } + void PluginMemory::SetDouble(double value) { *((double*)(m_ptr)) = value; } + void PluginMemory::SetVector(Vector value) { *((Vector*)(m_ptr)) = value; } + void PluginMemory::SetVector2D(Vector2D value) { *((Vector2D*)(m_ptr)) = value; } + void PluginMemory::SetVector4D(Vector4D value) { *((Vector4D*)(m_ptr)) = value; } + void PluginMemory::SetColor(Color value) { *((Color*)(m_ptr)) = value; } + void PluginMemory::SetQAngle(QAngle value) { *((QAngle*)(m_ptr)) = value; @@ -147,51 +158,72 @@ bool PluginMemory::GetBool() { return *((bool*)(m_ptr)); } + int PluginMemory::GetInt() { return *((int*)(m_ptr)); } + int64_t PluginMemory::GetInt64() { return *((int64_t*)(m_ptr)); } + uint32_t PluginMemory::GetUint() { return *((uint32_t*)(m_ptr)); } + uint64_t PluginMemory::GetUint64() { return *((uint64_t*)(m_ptr)); } + float PluginMemory::GetFloat() { return *((float*)(m_ptr)); } + double PluginMemory::GetDouble() { return *((double*)(m_ptr)); } + Vector PluginMemory::GetVector() { return *((Vector*)(m_ptr)); } + Vector2D PluginMemory::GetVector2D() { return *((Vector2D*)(m_ptr)); } + Vector4D PluginMemory::GetVector4D() { return *((Vector4D*)(m_ptr)); } + Color PluginMemory::GetColor() { return *((Color*)(m_ptr)); } + QAngle PluginMemory::GetQAngle() { return *((QAngle*)(m_ptr)); } +void PluginMemory::Allocate(uint64_t size) +{ + m_ptr = malloc(size); +} + +void PluginMemory::Deallocate() +{ + free(m_ptr); +} + std::string PluginMemory::GetPtr() { return string_format("%p", m_ptr); diff --git a/src/plugins/lua/scripting/memory/memory.cpp b/src/plugins/lua/scripting/memory/memory.cpp index 4b8b1a28..b847d098 100644 --- a/src/plugins/lua/scripting/memory/memory.cpp +++ b/src/plugins/lua/scripting/memory/memory.cpp @@ -19,6 +19,8 @@ LoadLuaScriptingComponent( .addFunction("AccessVTableFromOffset", &PluginMemory::AccessVTableFromOffset) .addFunction("AccessedVTable", &PluginMemory::AccessedVTable) .addFunction("AccessIndex", &PluginMemory::AccessIndex) + .addFunction("Allocate", &PluginMemory::Allocate) + .addFunction("Deallocate", &PluginMemory::Deallocate) .addFunction("Clear", &PluginMemory::Clear) .addFunction("SetBool", &PluginMemory::SetBool) .addFunction("SetInt", &PluginMemory::SetInt)