4

我想做的事:

我有一个基于 CrySDK 的游戏,它是 DirectX11,我想绘制一个类似蒸汽覆盖的游戏覆盖。

-> 我写 C# 因为我不懂任何 C++,所以我正在寻找在 C# 中执行此操作的方法。

-> 我使用 EasyHook 和 SharpDX 库,因为这似乎是最好的方法。

-> 我找到了一个参考项目,它显然是 SC2 的某种 hack,但我只是对覆盖部分感兴趣。

-> 我使用 Visual Studio 2013

-> 现在,如果我能在游戏中随机绘制东西,我会很高兴

到目前为止我做了什么:

我正在查看 google 和 SO 搜索结果,问题是,这些东西是 C++、C 或其他,结果来自 2010 年,与当前的 dx11 不是最新的,包含死链接或由于任何其他原因无法使用. 这涵盖了我自己发现的 95%,一些有用的提示已包含在我的代码中。

我设法创建了一个 Injector.dll 并将其注入到游戏中(至少我认为它是注入的,到目前为止还没有任何可用的结果)

我有的:

进行注入的文件:

...                
// Try inject thingy

            EasyHook.Config.Register("Star Citizen Noise.sc Client Overlay",
                                    //         "Direct3D9Hook.dll",
                                             "SharpDX.dll",
                                             "SharpDX.Direct3D11.dll",
                                             "Injector.dll");

            // Do the inject
            RemoteHooking.Inject(scProcess.Id, InjectionOptions.DoNotRequireStrongName, "Injector.dll", "Injector.dll", "Star Citizen Noise.sc Injector.dll");
            Console.WriteLine("DLL Injected.");
...

injector.dll 本身由这个文件组成,称为 Hooks/Graphics/Direct3D11Hook.cs(我试图保持与 oter sc2 参考项目相似的结构)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Runtime.InteropServices;
using EasyHook;
using SharpDX;
using SharpDX.Direct3D11;
using Rectangle = SharpDX.Rectangle;

namespace Injector.Hooks.Graphics
{
    public class Direct3D11Hook : HookBase
    {

        private Device device = null;

        [UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true)]
        private delegate Result EndSceneDelegate(IntPtr devicePointer);

        public delegate void EndSceneEventDelegate(ref IntPtr devicePointer);
        public event EndSceneEventDelegate OnEndScene;

        private Result EndScene(IntPtr devicePointer)
        {
            try
            {
                //this.Log.LogMethodSignatureTypesAndValues(devicePointer);

                //GetOrCreateDevice
                if (this.device == null)
                    this.device = Device.FromPointer<Device>(devicePointer);

                if (this.OnEndScene != null)
                    this.OnEndScene(ref devicePointer);

                System.Drawing.Graphics g = System.Drawing.Graphics.FromHdc(devicePointer);
                //System.Drawing.Graphics g = System.Drawing.Graphics.FromHwndInternal(devicePointer);

                // lets try to draw something
                Pen myPen = new Pen(System.Drawing.Color.Pink, 4);
                System.Drawing.Point P1 = new System.Drawing.Point(50, 50);
                System.Drawing.Point P2 = new System.Drawing.Point(500, 500);
                g.DrawLine(myPen, P1, P2);
                g.Dispose();
                //this.device.EndScene();

                return Result.Ok;
            }
            catch (SharpDXException ex)
            {
                //Log.Warn(ex);
                Console.WriteLine(ex);
                return ex.ResultCode;
            }
            catch (Exception ex)
            {
                //this.Log.Fatal(ex);
                Console.WriteLine(ex);
                return Result.UnexpectedFailure;
            }
        }

        public override void Install()
        {
            try
            {
                EndSceneDelegate esd = new EndSceneDelegate(this.EndScene);

            }
            catch (Exception)
            {

                throw;
            }
        }

        public override void Uninstall()
        {

        }

    }
}

在这里,我尝试为 EndScene 函数提供覆盖函数,因为我认为这是我需要的地方。不用说,似乎什么也没画。

委托定义有点像参考项目的复制粘贴,但是我还没有弄清楚如何将我的函数实际挂钩到渲染管道和/或对可能有助于我的事业的事件做出反应。

还有这个巨大的文件[ https://github.com/jasonpang/Starcraft2Hook/blob/master/Game/Hooks/Graphics/Direct3D9.cs]定义了似乎适用于DX9的函数地址,我不认为DX11也可以复制粘贴使用,请问DX11应该有新的功能地址吧?我怎样才能找到那些?我需要看哪里?SharpDX 可以帮助我吗?

TL;博士

想要为 DX11 游戏创建类似蒸汽的覆盖,需要连接 D3D 的东西和魔法和狗屎,让 dll 注入工作,需要管道注入方面的帮助

4

0 回答 0