I have written a little application for gathering information about the character the player is currently playing. And I wanted to hook up to EndScene.
I used the code APoc gave as a example in the WhiteMagic Thread.
The Code Looks like:
Code:
using System;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using WhiteMagic;
namespace WoWInfo
{
publicpartialclassMain : Form,IProcessSelectorNotifier
{
privateProcess WoWProcess;
public Main()
{
InitializeComponent();
Process.EnterDebugMode();
}
privatevoid Main_Load(object sender, EventArgs e)
{
Process[] wowWins = Process.GetProcessesByName("wow");
if (wowWins.Count() == 0)
{
// No wow windows open
MessageBox.Show("Could not find WoW");
Close();
}
else
{
// Open Process Selector
WoWSelector sel = newWoWSelector(wowWins, this);
sel.ShowDialog();
}
}
publicvoid ProcessSelectionComplete(Process proc)
{
// A Async callback of the Process Selector
WoWProcess = proc;
}
// Hook the EndScene
privatevoid button1_Click(object sender, EventArgs e)
{
IntPtr endSceneAddr = DirectX.GetEndScenePointerManaged();
Magic.Instance.Detours.CreateAndApply(Magic.Instance.RegisterDelegate<EndSceneDelegate>(endSceneAddr), EndSceneHandler, "EndScene");
}
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
publicdelegateintEndSceneDelegate(IntPtr instance);
privatestaticreadonlyEndSceneDelegate EndSceneHandler = EndScene;
privatestaticint EndScene(IntPtr instance)
{
MessageBox.Show("EndScene");
return (int)Magic.Instance.Detours["EndScene"].CallOriginal(instance);
}
}
}
Everyting works great, except that the EndScene methood never gets called.
Is there some special ASM code i have to inject to make the callback work.
Thank you for all help, misz.