Skip to content

Commit

Permalink
1.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Hary309 committed Jul 12, 2022
1 parent 664d14f commit 37c5390
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 26 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

set_property(GLOBAL PROPERTY USE_FOLDERS ON)

project(hry-core VERSION 1.0.6)
project(hry-core VERSION 1.0.7)

add_subdirectory(vendor)

Expand Down
2 changes: 1 addition & 1 deletion Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = hry-core
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 1.0.6
PROJECT_NUMBER = 1.0.7

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
2 changes: 1 addition & 1 deletion include/Hry/Version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct Version
/**
* @brief Current API version
*/
constexpr inline Version ApiVersion{ 1, 0, 6 };
constexpr inline Version ApiVersion{ 1, 0, 7 };

HRY_NS_END

Expand Down
62 changes: 39 additions & 23 deletions src/Hooks/D3D11Hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,18 @@ using D3D11CreateDeviceAndSwapChain_t = decltype(D3D11CreateDeviceAndSwapChain);
using IDXGISwapChain_Present_t = decltype(IDXGISwapChainVtbl::Present);
using IDXGISwapChain_ResizeBuffers_t = decltype(IDXGISwapChainVtbl::ResizeBuffers);

static IDXGISwapChain_ResizeBuffers_t oSwapChainResizeBuffers;
static WNDPROC oWndProc;
namespace
{
WNDPROC oWndProc;

static IDXGISwapChainVtbl* swapChainVTable;
bool needUpdateInfo = true;
bool isInited = false;

static bool needUpdateInfo = true;
static bool isInited = false;
IDXGISwapChainVtbl* swapChainVTable;

static std::shared_ptr<hry::Detour> swapChainPresentHook;
std::unique_ptr<hry::Detour> swapChainPresentHook;
std::unique_ptr<hry::Detour> swapChainResizeBufferHook;
}

// original code: https://github.com/Rebzzel/kiero
IDXGISwapChainVtbl* GetSwapChainVTable()
Expand Down Expand Up @@ -195,7 +198,8 @@ HRESULT __stdcall new_IDXGISwapChain_ResizeBuffers(
needUpdateInfo = true;

D3D11Hook::OnBeforeResize.call(swapChain, width, height);
return oSwapChainResizeBuffers(swapChain, bufferCount, width, height, format, flags);
return swapChainResizeBufferHook->getOriginal<IDXGISwapChain_ResizeBuffers_t>()(
swapChain, bufferCount, width, height, format, flags);
}

bool D3D11Hook::Install()
Expand All @@ -212,7 +216,7 @@ bool D3D11Hook::Install()
Core::Logger->info("Hooking IDXGISwapChain::Present...");

swapChainPresentHook =
std::make_shared<hry::Detour>(swapChainVTable->Present, &new_IDXGISwapChain_Present);
std::make_unique<hry::Detour>(swapChainVTable->Present, &new_IDXGISwapChain_Present);


if (swapChainPresentHook->create() != hry::Detour::Status::Ok)
Expand All @@ -228,29 +232,41 @@ bool D3D11Hook::Install()
}

Core::Logger->info("Hooking IDXGISwapChain::ResizeBuffers...");
oSwapChainResizeBuffers =
HookVTableField(&swapChainVTable->ResizeBuffers, &new_IDXGISwapChain_ResizeBuffers);
swapChainResizeBufferHook =
std::make_unique<hry::Detour>(
swapChainVTable->ResizeBuffers, &new_IDXGISwapChain_ResizeBuffers);

if (swapChainResizeBufferHook->create() != hry::Detour::Status::Ok)
{
Core::Logger->error("Cannot create hook");
return false;
}

if (swapChainResizeBufferHook->enable() != hry::Detour::Status::Ok)
{
Core::Logger->error("Cannot enable hook");
return false;
}

return true;
}

void D3D11Hook::Uninstall()
{
if (swapChainVTable != nullptr)
if (swapChainPresentHook)
{
if (swapChainPresentHook)
{
Core::Logger->info("Restoring IDXGISwapChain::Present...");
swapChainPresentHook->disable();
swapChainPresentHook->remove();
swapChainPresentHook.reset();
}
Core::Logger->info("Restoring IDXGISwapChain::Present...");
swapChainPresentHook->disable();
swapChainPresentHook->remove();
swapChainPresentHook.reset();
}

if (oSwapChainResizeBuffers != nullptr)
{
Core::Logger->info("Restoring IDXGISwapChain::ResizeBuffers...");
HookVTableField(&swapChainVTable->ResizeBuffers, oSwapChainResizeBuffers);
}
if (swapChainResizeBufferHook)
{
Core::Logger->info("Restoring IDXGISwapChain::Present...");
swapChainResizeBufferHook->disable();
swapChainResizeBufferHook->remove();
swapChainResizeBufferHook.reset();
}

if (oWndProc != nullptr)
Expand Down
2 changes: 2 additions & 0 deletions src/UI/Pages/AboutPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ void AboutPage::imguiRender()
* [json](https://github.com/nlohmann/json)
* [minhook](https://github.com/TsudaKageyu/minhook)
## Changelog
* 1.0.7
* Fix crash related with Alt-Tab
* 1.0.6
* Probably fixed crash with D3D11 hook
* Disallow to use LMB as bindable key
Expand Down

0 comments on commit 37c5390

Please sign in to comment.