Skip to content

New APIs for patching + refactored patching code

Latest
Compare
Choose a tag to compare
@Lectem Lectem released this 22 Jul 17:26
· 4 commits to master since this release

Example code using the new API:

extern "C" {

static ExtraPatchAction D2GameExtraPatchActions[] = {
    { 0x6FC386D0 - D2GameImageBase, &GAME_UpdateProgress_WithDebugger, PatchAction::FunctionReplaceOriginalByPatch, &GAME_UpdateProgress_Original},
    { 0, 0, PatchAction::Ignore}, // Here because we need at least one element in the array
};

static ExtraPatchAction D2ClientExtraPatchActions[] = {
    { 0, 0, PatchAction::Ignore}, // Here because we need at least one element in the array
};

ExtraPatchAction* __cdecl D2ClientGetExtraPatchAction(int index)
{
    return &D2ClientExtraPatchActions[index];
}

__declspec(dllexport)
uint32_t __cdecl DllPreLoadHook(HookContext* ctx, const wchar_t* dllName)
{
    if (wcsicmp(dllName, L"D2Game.dll") == 0)
    {
        for (auto& p : D2GameExtraPatchActions)
        {
            ctx->ApplyPatchAction(ctx, p.originalDllOffset, p.patchData, p.action, (void**)p.detouredPatchedFunctionPointerStorageAddress);
        }
    }
    else if (wcsicmp(dllName, L"D2Client.dll") == 0)
    {
        for (auto& p : D2ClientExtraPatchActions)
        {
            ctx->ApplyPatchAction(ctx, p.originalDllOffset, p.patchData, p.action, (void**)p.detouredPatchedFunctionPointerStorageAddress);
        }
    }
    else
    {
        __debugbreak(); // Insert other dlls here if you added them in the .rc.
        return {};
    }
    return 0;
}

} // extern "C"