From 20aed4820f4c9855cb1ae3ad45beda00814d85da Mon Sep 17 00:00:00 2001 From: Lectem Date: Fri, 1 Mar 2024 17:16:26 +0100 Subject: [PATCH] Add patch template --- D2.Detours.patches/Template.patch.cpp | 73 +++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 D2.Detours.patches/Template.patch.cpp diff --git a/D2.Detours.patches/Template.patch.cpp b/D2.Detours.patches/Template.patch.cpp new file mode 100644 index 00000000..9fd30623 --- /dev/null +++ b/D2.Detours.patches/Template.patch.cpp @@ -0,0 +1,73 @@ +#include + +//#define DISABLE_ALL_PATCHES + +#if defined(__clang__) +#pragma clang diagnostic ignored "-Wmicrosoft-cast" +#endif + +extern "C" { + __declspec(dllexport) + constexpr int __cdecl GetBaseOrdinal() { return 10'001; } + __declspec(dllexport) + constexpr int __cdecl GetLastOrdinal() { return 10'001; } + constexpr int GetOrdinalCount() { return GetLastOrdinal() - GetBaseOrdinal() + 1; } +} + +// We are using the following letters: +// /*C*/ to mean that the function has been "Checked" and works +// /*B*/ to mean wean know it is "Broken" and needs fixing. +//` ` (spaces) to mean that it is "Unknown" wether it works or not + +static PatchAction patchActions[GetOrdinalCount()] = { + PatchAction::Ignore, // ; Not exported +}; + +extern "C" { + +__declspec(dllexport) +PatchAction __cdecl GetPatchAction(int ordinal) +{ +#ifdef DISABLE_ALL_PATCHES + return PatchAction::Ignore; +#else + if (ordinal < GetBaseOrdinal() || ordinal > GetLastOrdinal()) + return PatchAction::FunctionReplacePatchByOriginal; + + static_assert(GetOrdinalCount() == (sizeof(patchActions) / sizeof(*patchActions)), "Make sure we have the right number of ordinal patch entries"); + return ::patchActions[ordinal - GetBaseOrdinal()]; +#endif +} + +static const int D2GameImageBase = 0x6FC30000; + +static ExtraPatchAction extraPatchActions[] = { + { 0, 0, PatchAction::Ignore}, // Here because we need at least one element in the array +}; + +__declspec(dllexport) +constexpr int __cdecl GetExtraPatchActionsCount() { + +#ifdef DISABLE_ALL_PATCHES + return 0; +#else + return sizeof(extraPatchActions) / sizeof(ExtraPatchAction); +#endif +} + +__declspec(dllexport) +ExtraPatchAction* __cdecl GetExtraPatchAction(int index) +{ + return &extraPatchActions[index]; +} + +} + +#include +static_assert(std::is_same::value, "Ensure calling convention doesn't change"); +static_assert(std::is_same::value, "Ensure calling convention doesn't change"); +static_assert(std::is_same::value, "Ensure calling convention doesn't change"); + + +static_assert(std::is_same::value, "Ensure calling convention doesn't change"); +static_assert(std::is_same::value, "Ensure calling convention doesn't change");