Skip to content
Merged
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
32 changes: 16 additions & 16 deletions source/export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,21 @@ FunctionPatcherStatus FPAddFunctionPatch(function_replacement_data_t *function_d
return FUNCTION_PATCHER_RESULT_UNKNOWN_ERROR;
}

auto &functionData = functionDataOpt.value();

// PatchFunction calls OSFatal on fatal errors.
// If this function returns false the target function was not patched
// Usually this means the target RPL is not (yet) loaded.
auto patchResult = PatchFunction(functionData);
if (outHasBeenPatched) {
*outHasBeenPatched = patchResult;
}

if (outHandle) {
*outHandle = functionData->getHandle();
}

{
std::lock_guard lock(gPatchedFunctionsMutex);
auto &functionData = functionDataOpt.value();
// PatchFunction calls OSFatal on fatal errors.
// If this function returns false the target function was not patched
// Usually this means the target RPL is not (yet) loaded.
auto patchResult = PatchFunction(functionData);
if (outHasBeenPatched) {
*outHasBeenPatched = patchResult;
}

if (outHandle) {
*outHandle = functionData->getHandle();
}

gPatchedFunctions.push_back(std::move(functionData));

OSMemoryBarrier();
Expand Down Expand Up @@ -96,7 +95,8 @@ FunctionPatcherStatus FPRemoveFunctionPatch(PatchedFunctionHandle handle) {
return FUNCTION_PATCHER_RESULT_PATCH_NOT_FOUND;
}

if (toBeRemoved->isPatched) {
bool functionWasPatched = toBeRemoved->isPatched;
if (functionWasPatched) {
// Restore function patches that were done after the patch we actually want to restore.
for (auto &cur : std::ranges::reverse_view(toBeTempRestored)) {
RestoreFunction(cur);
Expand All @@ -108,7 +108,7 @@ FunctionPatcherStatus FPRemoveFunctionPatch(PatchedFunctionHandle handle) {

gPatchedFunctions.erase(gPatchedFunctions.begin() + erasePosition);

if (toBeRemoved->isPatched) {
if (functionWasPatched) {
// Apply the other patches again
for (auto &cur : toBeTempRestored) {
PatchFunction(cur);
Expand Down