diff --git a/scripting/include/sourcescramble.inc b/scripting/include/sourcescramble.inc index e5df63c..01d771a 100644 --- a/scripting/include/sourcescramble.inc +++ b/scripting/include/sourcescramble.inc @@ -42,6 +42,13 @@ methodmap MemoryPatch < Handle { property Address Address { public native get(); } + + /** + * Returns true if the patch is currently enabled, else false. + */ + property bool Enabled { + public native get(); + } }; methodmap MemoryBlock < Handle { diff --git a/types/mempatch.cpp b/types/mempatch.cpp index 1b62ec1..e7af908 100644 --- a/types/mempatch.cpp +++ b/types/mempatch.cpp @@ -63,7 +63,8 @@ class MemoryPatch { } *((uint8_t*) pAddress + i) = (vecPatch[i] & ~preserveBits) | (vecRestore[i] & preserveBits); } - + + enabled = true; return true; } @@ -74,8 +75,9 @@ class MemoryPatch { } ByteVectorWrite(vecRestore, (uint8_t*) pAddress); vecRestore.clear(); + enabled = false; } - + bool Verify() { if (!pAddress) { return false; @@ -96,6 +98,7 @@ class MemoryPatch { uintptr_t pAddress; ByteVector vecPatch, vecRestore, vecVerify, vecPreserve; + bool enabled; }; void MemoryPatchHandler::OnHandleDestroy(HandleType_t type, void* object) { @@ -190,4 +193,16 @@ cell_t sm_MemoryPatchPropAddressGet(IPluginContext *pContext, const cell_t *para #else return pContext->ThrowNativeError("MemoryPatch.Address is not implemented for 64-bit platforms"); #endif +} + +cell_t sm_MemoryIsPatchEnabled(IPluginContext *pContext, const cell_t *params) { + Handle_t hndl = static_cast(params[1]); + + MemoryPatch *pMemoryPatch; + HandleError err; + if ((err = ReadMemoryPatchHandle(hndl, &pMemoryPatch)) != HandleError_None) { + return pContext->ThrowNativeError("Invalid MemoryPatch handle %x (error %d)", hndl, err); + } + + return (cell_t)pMemoryPatch->enabled; } \ No newline at end of file diff --git a/types/mempatch.h b/types/mempatch.h index 1a7f076..6946fe0 100644 --- a/types/mempatch.h +++ b/types/mempatch.h @@ -15,6 +15,7 @@ cell_t sm_MemoryPatchEnable(IPluginContext *pContext, const cell_t *params); cell_t sm_MemoryPatchDisable(IPluginContext *pContext, const cell_t *params); cell_t sm_MemoryPatchPropAddressGet(IPluginContext *pContext, const cell_t *params); +cell_t sm_MemoryIsPatchEnabled(IPluginContext *pContext, const cell_t *params); const sp_nativeinfo_t g_MemoryPatchNatives[] = { { "MemoryPatch.CreateFromConf", sm_MemoryPatchLoadFromConfig }, @@ -25,6 +26,7 @@ const sp_nativeinfo_t g_MemoryPatchNatives[] = { { "MemoryPatch.Disable", sm_MemoryPatchDisable }, { "MemoryPatch.Address.get", sm_MemoryPatchPropAddressGet }, + { "MemoryPatch.Enabled.get", sm_MemoryIsPatchEnabled }, {NULL, NULL}, };