Skip to content

Commit 9d3da6c

Browse files
committed
Add 'preserve' configuration option
1 parent 9acbd46 commit 9d3da6c

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

types/mempatch.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ class MemoryPatch {
3232
for (auto bit : info.vecVerify) {
3333
this->vecVerify.append(bit);
3434
}
35+
for (auto bit : info.vecPreserve) {
36+
this->vecPreserve.append(bit);
37+
}
3538
this->pAddress = pAddress + (info.offset);
3639
}
3740

@@ -49,6 +52,16 @@ class MemoryPatch {
4952
SourceHook::SetMemAccess((void*) this->pAddress, vecPatch.length() * sizeof(uint8_t),
5053
SH_MEM_READ | SH_MEM_WRITE | SH_MEM_EXEC);
5154
ByteVectorWrite(vecPatch, (uint8_t*) pAddress);
55+
56+
//
57+
for (size_t i = 0; i < vecPatch.length(); i++) {
58+
uint8_t preserveBits = 0;
59+
if (i < vecPreserve.length()) {
60+
preserveBits = vecPreserve[i];
61+
}
62+
*((uint8_t*) pAddress + i) = (vecPatch[i] & ~preserveBits) | (vecRestore[i] & preserveBits);
63+
}
64+
5265
return true;
5366
}
5467

@@ -76,7 +89,7 @@ class MemoryPatch {
7689
}
7790

7891
uintptr_t pAddress;
79-
ByteVector vecPatch, vecRestore, vecVerify;
92+
ByteVector vecPatch, vecRestore, vecVerify, vecPreserve;
8093
};
8194

8295
void MemoryPatchHandler::OnHandleDestroy(HandleType_t type, void* object) {

userconf/mempatches.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ SMCResult MemPatchGameConfig::ReadSMC_KeyValue(const SMCStates *states, const ch
139139
g_CurrentPatchInfo->vecPatch = ByteVectorFromString(value);
140140
} else if (!strcmp(key, "verify")) {
141141
g_CurrentPatchInfo->vecVerify = ByteVectorFromString(value);
142+
} else if (!strcmp(key, "preserve")) {
143+
g_CurrentPatchInfo->vecPreserve = ByteVectorFromString(value);
142144
}
143145
break;
144146
default:

userconf/mempatches.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class MemPatchGameConfig : public ITextListener_SMC {
2424
public:
2525
ke::AString signature;
2626
size_t offset;
27-
ByteVector vecPatch, vecVerify;
27+
ByteVector vecPatch, vecVerify, vecPreserve;
2828
};
2929

3030
enum ParseState {

0 commit comments

Comments
 (0)