私がしたいこと:
DirectX11 である CrySDK に基づくゲームがあり、Steam オーバーレイのようなゲーム内オーバーレイを描画したいと考えています。
-> C++ をまったく知らないので C# を書いているので、C# でこれを行う方法を探しています。
-> EasyHook と SharpDX ライブラリを使用しています。これが最善の方法だと思われるからです。
->明らかに 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.");
...
インジェクター.dll 自体は、Hooks/Graphics/Direct3D11Hook.cs という名前のこのファイルで構成されています (他の 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 ゲーム用の Steam のようなオーバーレイを作成したい、D3D のものと魔法とたわごとにフックする必要がある、dll インジェクトが機能している、パイプライン インジェクションの助けが必要