Can anyone help me identify why this function always crashes the game?
I have been following tutorials on easyhook and the game seems to crash when i call the original function. The program enters hkJump(x,y) and I can read the parameters correctly just fine. However, if I dont call the original function then the game doesnt call it either since I have hooked it to my function. When I try to call the original function after performing my function in hkJump(x,y), the game crashes?
Is there any flaw in what I have written.
Please help
Code:
public class Main : IEntryPoint
{
static IntPtr JumpAddress = new IntPtr(0x51478B);
static COInterface Interface;
static LocalHook JumpHook;
static String ChannelName;
public Main(RemoteHooking.IContext InContext, String InChannelName)
{
Interface = RemoteHooking.IpcConnectClient<COInterface>(InChannelName);
Interface.Log("DLL Injected into target process.");
}
public unsafe void Run(RemoteHooking.IContext InContext, String InChannelName)
{
try
{
Interface.Log("Running hook");
JumpHook = LocalHook.Create(JumpAddress, new dJumpFunction(hkJump), this);
JumpHook.ThreadACL.SetExclusiveACL(new Int32[] { 0 });
Interface.Log("Jump function hooked");
} catch ( Exception e )
{
Interface.ReportException(e);
}
try
{
RemoteHooking.WakeUpProcess();
} catch(Exception e) {
Interface.ReportException(e);
}
while (true)
{
Thread.Sleep(1000);
}
}
[UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true)]
public unsafe delegate int dJumpFunction([MarshalAs(UnmanagedType.I4)] int x, [MarshalAs(UnmanagedType.I4)] int y);
public static unsafe dJumpFunction oDispatchMessage = (dJumpFunction)Marshal.GetDelegateForFunctionPointer(JumpAddress, typeof(dJumpFunction));
static int hkJump([MarshalAs(UnmanagedType.I4)] int x, [MarshalAs(UnmanagedType.I4)] int y )
{
try
{
Interface.Log("X=" + x + ", Y=" + y);
return oDispatchMessage(x, y);
} catch(Exception e)
{
Interface.ReportException(e);
return oDispatchMessage(x, y);
}
}
}