#hook #渲染引擎 #DirectX #黑客 #D3D12 #跨平台 #游戏

shroud

通用库,用于发现渲染引擎的渲染功能:DirectX9、DirectX10、DirectX11、DirectX12

12 个版本

0.2.3 2024年5月27日
0.2.2 2023年6月16日
0.2.1 2023年5月25日
0.1.7 2022年10月24日

游戏开发 中排名第 182

Download history 10/week @ 2024-05-19 152/week @ 2024-05-26 14/week @ 2024-06-02 4/week @ 2024-06-09 1/week @ 2024-06-16

每月下载量 834

MIT 许可证

1.5MB
1K SLoC

Crate

Shroud

通用库,用于发现常见的渲染引擎功能。支持 DirectX9 (D3D9)、DirectX10 (D3D10)、DirectX11 (D3D11)、DirectX12 (D3D12)。目前仅支持 Windows,但 OpenGL 和 Vulkan 是跨平台的候选。

目的

提供对常见渲染引擎功能的访问,以便可以挂钩/增强。例如 DirectX9 EndScene 钩子、DirectX11 Present 钩子。

变更日志

  • 0.1.0 开始作为 OpenGL 和 Vulkan 的通用库。使用 winapi 非官方 API,在 windows crate 采用之前。

  • 0.2.2 移除 OpenGl/Vulkan。有更好的解决方案来处理它们的加载器。升级到官方微软 Windows crate。

支持

  • DirectX9
  • DirectX10**
  • DirectX11
  • DirectX12

** 未测试

如何使用

在你的 cargo.toml 中指定 shroud 依赖项和希望访问的渲染引擎作为功能标志。默认情况下,所有渲染引擎都被禁用。

例如,针对 DirectX9 主机/游戏

[dependencies]
shroud = { version = "0.2.3", features = ["directx9"] }

和针对 DirectX12 主机/游戏...

[dependencies]
shroud = { version = "0.2.3", features = ["directx12"] }

注入示例 / 用例

编译为 dll 的示例代码注入提供以下演示的结果。

use windows::Win32::{
    Foundation::{BOOL, HMODULE},
    System::{Console::AllocConsole, SystemServices::DLL_PROCESS_ATTACH},
};

unsafe extern "system" fn start_routine(_parameter: *mut std::ffi::c_void) -> u32 {
    // match shroud::directx9::methods
    // match shroud::directx10::methods
    // match shroud::directx11::methods
    match shroud::directx12::methods() {
        Ok(m) => {
            println!("{m:#?}");
        }
        Err(e) => {
            println!("{e:?}");
        }
    }
    0
}

#[no_mangle]
#[allow(non_snake_case)]
pub extern "system" fn DllMain(dll_module: HMODULE, call_reason: u32, _reserved: usize) -> BOOL {
    if call_reason == DLL_PROCESS_ATTACH {
        unsafe { AllocConsole() };
        println!("Attached.");

        let thread = unsafe {
            windows::Win32::System::Threading::CreateThread(
                None,
                0,
                Some(start_routine),
                Some(dll_module.0 as *const std::ffi::c_void),
                windows::Win32::System::Threading::THREAD_CREATION_FLAGS(0),
                None,
            )
        };

        match thread {
            Ok(_handle) => {
                println!("Created thread")
            }
            Err(e) => {
                panic!("Unable to create thread {e:?}")
            }
        }
    }

    true.into()
}

DirectX9

DirectX9

DirectX10

待办...

DirectX11

DirectX11

DirectX12

DirectX12

依赖项

~128MB
~2M SLoC