Skip to content

Commit

Permalink
Merge branch 'dx12'
Browse files Browse the repository at this point in the history
  • Loading branch information
maximegmd committed Dec 18, 2020
2 parents 909934b + 000ebac commit 941778b
Show file tree
Hide file tree
Showing 12 changed files with 1,736 additions and 39 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ This plugin fixes some Cyberpunk 2077 issues and adds some features.
| Remove pedestrians and traffic | Removes most of the pedestrians and traffic |
| Disable Async Compute | Disables async compute, this can give a boost on older GPUs ( nvidia 10xx series for example)|
| Disable Antialiasing TAA | Disables antialiasing, not recommended but you do what you want! |
| Imgui overlay | Adds an overlay to draw whatever UI you want on top of the game |

### Upcoming

Expand Down
3 changes: 2 additions & 1 deletion src/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#include <windows.h>
#include <filesystem>
#include "Image.h"

struct Image;
struct Options
{
static void Initialize(HMODULE aModule);
Expand All @@ -26,6 +26,7 @@ struct Options
float GPUMemoryPoolFraction{ 1.f };
std::filesystem::path Path;
std::string ExeName;
Image GameImage;

private:

Expand Down
17 changes: 17 additions & 0 deletions src/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
#include <DbgHelp.h>
#include <spdlog/spdlog.h>
#include <kiero/kiero.h>
#include <overlay/Overlay.h>
#include <MinHook.h>
#include <thread>

#include "Image.h"
#include "Options.h"
Expand All @@ -27,6 +29,8 @@ void OptionsInitPatch(Image* apImage);

void Initialize(HMODULE mod)
{
MH_Initialize();

Options::Initialize(mod);
const auto& options = Options::Get();

Expand Down Expand Up @@ -65,8 +69,21 @@ void Initialize(HMODULE mod)
if (options.DumpGameOptions)
OptionsInitPatch(&image);

Overlay::Initialize(&image);

MH_EnableHook(MH_ALL_HOOKS);

std::thread t([]()
{
if (kiero::init(kiero::RenderType::D3D12) != kiero::Status::Success)
{
spdlog::error("Kiero failed!");
}
else
Overlay::Get().Hook();
});
t.detach();

spdlog::default_logger()->flush();
}

Expand Down
78 changes: 46 additions & 32 deletions src/kiero/kiero.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "kiero.h"
#include <Windows.h>
#include <assert.h>
#include <spdlog/spdlog.h>

#if KIERO_INCLUDE_D3D9
# include <d3d9.h>
Expand Down Expand Up @@ -44,6 +45,7 @@

static kiero::RenderType::Enum g_renderType = kiero::RenderType::None;
static uint150_t* g_methodsTable = NULL;
static uintptr_t g_commandQueueOffset = 0;

kiero::Status::Enum kiero::init(RenderType::Enum _renderType)
{
Expand Down Expand Up @@ -374,21 +376,21 @@ kiero::Status::Enum kiero::init(RenderType::Enum _renderType)
return Status::ModuleNotFoundError;
}

void* CreateDXGIFactory;
if ((CreateDXGIFactory = ::GetProcAddress(libDXGI, "CreateDXGIFactory")) == NULL)
{
::DestroyWindow(window);
::UnregisterClass(windowClass.lpszClassName, windowClass.hInstance);
return Status::UnknownError;
}

IDXGIFactory* factory;
if (((long(__stdcall*)(const IID&, void**))(CreateDXGIFactory))(__uuidof(IDXGIFactory), (void**)&factory) < 0)
{
::DestroyWindow(window);
::UnregisterClass(windowClass.lpszClassName, windowClass.hInstance);
return Status::UnknownError;
}
void* CreateDXGIFactory;
if ((CreateDXGIFactory = ::GetProcAddress(libDXGI, "CreateDXGIFactory")) == NULL)
{
::DestroyWindow(window);
::UnregisterClass(windowClass.lpszClassName, windowClass.hInstance);
return Status::UnknownError;
}

IDXGIFactory* factory;
if (((long(__stdcall*)(const IID&, void**))(CreateDXGIFactory))(__uuidof(IDXGIFactory), (void**)&factory) < 0)
{
::DestroyWindow(window);
::UnregisterClass(windowClass.lpszClassName, windowClass.hInstance);
return Status::UnknownError;
}

IDXGIAdapter* adapter;
if (factory->EnumAdapters(0, &adapter) == DXGI_ERROR_NOT_FOUND)
Expand All @@ -398,21 +400,21 @@ kiero::Status::Enum kiero::init(RenderType::Enum _renderType)
return Status::UnknownError;
}

void* D3D12CreateDevice;
if ((D3D12CreateDevice = ::GetProcAddress(libD3D12, "D3D12CreateDevice")) == NULL)
{
::DestroyWindow(window);
::UnregisterClass(windowClass.lpszClassName, windowClass.hInstance);
return Status::UnknownError;
}

ID3D12Device* device;
if (((long(__stdcall*)(IUnknown*, D3D_FEATURE_LEVEL, const IID&, void**))(D3D12CreateDevice))(adapter, D3D_FEATURE_LEVEL_11_0, __uuidof(ID3D12Device), (void**)&device) < 0)
{
::DestroyWindow(window);
::UnregisterClass(windowClass.lpszClassName, windowClass.hInstance);
return Status::UnknownError;
}
void* D3D12CreateDevice;
if ((D3D12CreateDevice = ::GetProcAddress(libD3D12, "D3D12CreateDevice")) == NULL)
{
::DestroyWindow(window);
::UnregisterClass(windowClass.lpszClassName, windowClass.hInstance);
return Status::UnknownError;
}

ID3D12Device* device;
if (((long(__stdcall*)(IUnknown*, D3D_FEATURE_LEVEL, const IID&, void**))(D3D12CreateDevice))(adapter, D3D_FEATURE_LEVEL_11_0, __uuidof(ID3D12Device), (void**)&device) < 0)
{
::DestroyWindow(window);
::UnregisterClass(windowClass.lpszClassName, windowClass.hInstance);
return Status::UnknownError;
}

D3D12_COMMAND_QUEUE_DESC queueDesc;
queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
Expand Down Expand Up @@ -478,6 +480,13 @@ kiero::Status::Enum kiero::init(RenderType::Enum _renderType)
return Status::UnknownError;
}

auto valueToFind = reinterpret_cast<uintptr_t>(commandQueue);
auto* swapChainPtr = reinterpret_cast<uintptr_t*>(swapChain);

auto addr = std::find(swapChainPtr, swapChainPtr + 512, valueToFind);

g_commandQueueOffset = reinterpret_cast<uintptr_t>(addr) - reinterpret_cast<uintptr_t>(swapChainPtr);

g_methodsTable = (uint150_t*)::calloc(150, sizeof(uint150_t));
::memcpy(g_methodsTable, *(uint150_t**)device, 44 * sizeof(uint150_t));
::memcpy(g_methodsTable + 44, *(uint150_t**)commandQueue, 19 * sizeof(uint150_t));
Expand All @@ -486,7 +495,6 @@ kiero::Status::Enum kiero::init(RenderType::Enum _renderType)
::memcpy(g_methodsTable + 44 + 19 + 9 + 60, *(uint150_t**)swapChain, 18 * sizeof(uint150_t));

#if KIERO_USE_MINHOOK
MH_Initialize();
#endif

device->Release();
Expand Down Expand Up @@ -724,4 +732,10 @@ kiero::RenderType::Enum kiero::getRenderType()
uint150_t* kiero::getMethodsTable()
{
return g_methodsTable;
}
}

uintptr_t kiero::getCommandQueueOffset()
{
return g_commandQueueOffset;
}

5 changes: 3 additions & 2 deletions src/kiero/kiero.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
#define KIERO_INCLUDE_D3D9 0 // 1 if you need D3D9 hook
#define KIERO_INCLUDE_D3D10 0 // 1 if you need D3D10 hook
#define KIERO_INCLUDE_D3D11 0 // 1 if you need D3D11 hook
#define KIERO_INCLUDE_D3D12 0 // 1 if you need D3D12 hook
#define KIERO_INCLUDE_D3D12 1 // 1 if you need D3D12 hook
#define KIERO_INCLUDE_OPENGL 0 // 1 if you need OpenGL hook
#define KIERO_INCLUDE_VULKAN 0 // 1 if you need Vulkan hook
#define KIERO_USE_MINHOOK 0 // 1 if you will use kiero::bind function
#define KIERO_USE_MINHOOK 1 // 1 if you will use kiero::bind function

#define KIERO_ARCH_X64 0
#define KIERO_ARCH_X86 0
Expand Down Expand Up @@ -73,6 +73,7 @@ namespace kiero

RenderType::Enum getRenderType();
uint150_t* getMethodsTable();
uintptr_t getCommandQueueOffset();
}

#endif // __KIERO_H__
Loading

0 comments on commit 941778b

Please sign in to comment.