![](/img/trans.png)
[英]Capture screenshot of fullscreen DX11 program using SharpDX and EasyHook
[英]Drawing Overlay inside DX11 Game (CryEngine) with C# and EasyHook
我想做的事:
我有一個基於CrySDK的游戲,它是DirectX11,我想繪制像蒸汽覆蓋一樣的游戲覆蓋層。
- >我寫C#,因為我不知道任何C ++,所以我正在尋找在C#中做到這一點的方法。
- >我使用EasyHook和SharpDX Libaries因為看起來這是最好的方法。
- >我發現了一個參考項目 ,顯然是SC2的某種黑客攻擊,但我只對疊加部分感興趣。
- >我使用的是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; DR
想要為DX11游戲創建類似蒸汽的疊加,需要掛入D3D的東西和魔法和狗屎,得到dll注入工作,需要管道注入幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.