Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Conquer Online 2 > CO2 Programming
You last visited: Today at 15:20

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



C# EasyHook calling the original function crashes the program

Discussion on C# EasyHook calling the original function crashes the program within the CO2 Programming forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Aug 2006
Posts: 21
Received Thanks: 0
C# EasyHook calling the original function crashes the program

Can anyone help me identify why this function always crashes the game?

I have been following tutorials on easyhook to hook the jump function 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 so there is no jump. When I try to call the original function after performing my function in hkJump(x,y), the game crashes?

What is wrong with my code.

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);
            }
        }
    }
matt69 is offline  
Old 12/20/2016, 16:38   #2
 
elite*gold: 0
Join Date: Dec 2016
Posts: 32
Received Thanks: 10
I think you should use strackflow on Google
VestaPlay is offline  
Old 12/20/2016, 18:16   #3
 
elite*gold: 0
Join Date: Jul 2014
Posts: 402
Received Thanks: 540
Isn't "jump" a method on a "Player" class or something?
If so, you probably need to change the signature from:
Code:
[UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true)]
public unsafe delegate int dJumpFunction([MarshalAs(UnmanagedType.I4)] int x, [MarshalAs(UnmanagedType.I4)] int y);
to:
Code:
[UnmanagedFunctionPointer(CallingConvention.ThisCall, CharSet = CharSet.Unicode, SetLastError = true)]
public unsafe delegate int dJumpFunction(IntPtr instance, [MarshalAs(UnmanagedType.I4)] int x, [MarshalAs(UnmanagedType.I4)] int y);
And, of course, adjust your "hkJump" function accordingly.
Best Coder 2014 is offline  
Thanks
1 User
Old 12/21/2016, 02:35   #4
 
elite*gold: 0
Join Date: Aug 2006
Posts: 21
Received Thanks: 0
Quote:
Originally Posted by Best Coder 2014 View Post
Isn't "jump" a method on a "Player" class or something?
If so, you probably need to change the signature from:
Code:
[UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true)]
public unsafe delegate int dJumpFunction([MarshalAs(UnmanagedType.I4)] int x, [MarshalAs(UnmanagedType.I4)] int y);
to:
Code:
[UnmanagedFunctionPointer(CallingConvention.ThisCall, CharSet = CharSet.Unicode, SetLastError = true)]
public unsafe delegate int dJumpFunction(IntPtr instance, [MarshalAs(UnmanagedType.I4)] int x, [MarshalAs(UnmanagedType.I4)] int y);
And, of course, adjust your "hkJump" function accordingly.
Thank you, this worked. However, I dont understand why i needed an IntPtr as a parameter since ollydbg guessed the function only needed two parameters?

How did you know to put that there? What did I miss?
matt69 is offline  
Old 12/21/2016, 10:06   #5
 
elite*gold: 0
Join Date: Jul 2014
Posts: 402
Received Thanks: 540
Quote:
Originally Posted by matt69 View Post
Thank you, this worked. However, I dont understand why i needed an IntPtr as a parameter since ollydbg guessed the function only needed two parameters?

How did you know to put that there? What did I miss?
My guess is that OllyDbg probably isn't able to distinguish between an "StdCall" function with two parameters and a "ThisCall" function with three parameters. The reason is that they are pretty much identical, the only difference is that a "ThisCall" function has a "hidden" instance parameter which is passed in the ECX register.

If you look for places where the jump function is called, you'll probably find something like:
Code:
mov ecx, <instance>
push <y>
push <x>
call <jump>
The "mov ecx, ..." part is what indicates that the function being called is actually a "ThisCall" function with three parameters, and not an "StdCall" function with two parameters.
Best Coder 2014 is offline  
Thanks
2 Users
Reply


Similar Threads Similar Threads
Help me with calling a game function in DLL (crash)
05/12/2013 - General Coding - 1 Replies
Heya, Gonna make it short, my game crashes when i call my function, the address of the function is fine. I hope someone here can tell me what's wrong. Code: if(msg == "Cast4"){ typedef int ( __stdcall *Spellcast)(DWORD , DWORD); Spellcast castmyspell = (Spellcast)0x00B908F0; castmyspell(6, 0); }
Need some help calling function for height
07/27/2011 - Perfect World - 2 Replies
Hey there, for some reason I keep crashing upon trying to call this function and it's really pissing me off. I was wondering if somebody could give me some advice as to what I'm doing wrong :( The function is being called inside a function starting at address 0x465730 in PWI The function I'm looking for is called twice here, namely at 0x4657C7 and 0x465879. The code where it is called looks something like this: http://img94.imageshack.us/img94/9867/coordfuncti on.png Now, I'm...
Help, calling an ingame function
03/13/2010 - General Coding - 2 Replies
Im trying with my dll to set off the "set stat function". The one that u press when you add a stat point to str, dex or what ever. My goal is to make players able to set there Stats to whatever they use to have from an earlier saved point. So if you play against different sort of mobs or players you reform your stats to be suetable for that sertan task in just 1 second right where you stand. Im thinking this is very useful for many ppl here. So now i could use help with the actuall call of...
Help with calling this function!
03/13/2010 - 12Sky2 - 6 Replies
First off: sorry for my poor english! Im trying with my dll to set off the "set stat function". The one that u press when you add a stat point to str, dex or what ever. My goal is to make players able to set there Stats to whatever they use to have from an earlier saved point. So if you play against different sort of mobs or players you reform your stats to be suetable for that sertan task in just 1 second right where you stand. Im thinking this is very useful for many ppl here. So now i...
Calling function in a game
03/29/2009 - General Coding - 1 Replies
Hai guise, I'm a stupid morron but how can I make a hook in c++ that will use Gameplay::GetMoney(); to return the current amount of Gold I have? http://www.bilderkiste.org/show/original/0bba0c93 80a21de4810c1429cbc287c9/call.jpg



All times are GMT +1. The time now is 15:22.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.