Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions scripting/include/sourcescramble.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 17 additions & 2 deletions types/mempatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ class MemoryPatch {
}
*((uint8_t*) pAddress + i) = (vecPatch[i] & ~preserveBits) | (vecRestore[i] & preserveBits);
}


enabled = true;
return true;
}

Expand All @@ -74,8 +75,9 @@ class MemoryPatch {
}
ByteVectorWrite(vecRestore, (uint8_t*) pAddress);
vecRestore.clear();
enabled = false;
}

bool Verify() {
if (!pAddress) {
return false;
Expand All @@ -96,6 +98,7 @@ class MemoryPatch {

uintptr_t pAddress;
ByteVector vecPatch, vecRestore, vecVerify, vecPreserve;
bool enabled;
};

void MemoryPatchHandler::OnHandleDestroy(HandleType_t type, void* object) {
Expand Down Expand Up @@ -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<Handle_t>(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;
}
2 changes: 2 additions & 0 deletions types/mempatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -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},
};