QuestionWhat's Wrong with This Code?

Posts 110 of 10 · Page 1 of 1
What's Wrong with This Code?
Code:
using System;using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;


namespace VAM_Bhop_Tut
{
    class Program
    {


        public static int aLocalPlayer = 0x00A8D53C;
        public static int oFlags = 0x100;
        public static int aJump = 0x04F457EC;


        public static string process = "csgo";
        public static int bClient;


        [DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true)]
        public static extern int GetAsyncKeyState(int vKey);


        static void Main(string[] args)
        {


            VAMemory vam = new VAMemory(process);


            if (GetModuleAddy())
            {
                int fJump = bClient + aJump;
                aLocalPlayer = bClient + aLocalPlayer;
                int LocalPlayer = vam.ReadInt32((IntPtr)aLocalPlayer);


                int aFlags = LocalPlayer + oFlags;


                while (true)
                {
                    if (GetAsyncKeyState(32) > 0)
                    {


                        Console.WriteLine("Pressing Space");
                    }
                    while (GetAsyncKeyState(32) > 0)
                    {


                        int Flags = vam.ReadInt32((IntPtr)aFlags);


                        if (Flags == 257)
                        {


                            vam.WriteInt32((IntPtr)fJump, 5);
                            Thread.Sleep(10);
                            vam.WriteInt32((IntPtr)fJump, 4);


                            Console.Clear();
                            Console.WriteLine("Jumping", Console.ForegroundColor = ConsoleColor.Green);


                        }
                    }
                    Console.Clear();
                    Console.WriteLine("Standing", Console.ForegroundColor = ConsoleColor.Yellow);
                    Thread.Sleep(10);


                }


            }


        }


        static bool GetModuleAddy()
        {
            try
            {
                Process[] p = Process.GetProcessesByName(process);


                if (p.Length > 0)
                {


                    foreach (ProcessModule m in p[0].Modules)
                    {


                        if (m.ModuleName == "client.dll")
                        {
                            bClient = (int)m.BaseAddress;
                            return true;
                        }
                        
                    }
                    return true;
                }


                else
                {
                    return false;
                }
            }






            catch (Exception ex)
            {
                return false;
            }
        }
            
        }








}


- - - Updated - - -

After some research... I think I've found the cause. It's the GetASyncKeyState, it's not working, it's not detecting when I press Space :/

How do you create a properly working one in C#?
Code:
[DllImport("user32.dll")]
public static extern short GetAsyncKeyState(int vKey);
Quote Originally Posted by Koolsami7 View Post
Code:
[DllImport("user32.dll")]
public static extern short GetAsyncKeyState(int vKey);
Nope, not working
Quote Originally Posted by OVOMobZai View Post
Code:
using System;using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;


namespace VAM_Bhop_Tut
{
    class Program
    {


        public static int aLocalPlayer = 0x00A8D53C;
        public static int oFlags = 0x100;
        public static int aJump = 0x04F457EC;


        public static string process = "csgo";
        public static int bClient;


        [DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true)]
        public static extern int GetAsyncKeyState(int vKey);


        static void Main(string[] args)
        {


            VAMemory vam = new VAMemory(process);


            if (GetModuleAddy())
            {
                int fJump = bClient + aJump;
                aLocalPlayer = bClient + aLocalPlayer;
                int LocalPlayer = vam.ReadInt32((IntPtr)aLocalPlayer);


                int aFlags = LocalPlayer + oFlags;


                while (true)
                {
                    if (GetAsyncKeyState(32) > 0)
                    {


                        Console.WriteLine("Pressing Space");
                    }
                    while (GetAsyncKeyState(32) > 0)
                    {


                        int Flags = vam.ReadInt32((IntPtr)aFlags);


                        if (Flags == 257)
                        {


                            vam.WriteInt32((IntPtr)fJump, 5);
                            Thread.Sleep(10);
                            vam.WriteInt32((IntPtr)fJump, 4);


                            Console.Clear();
                            Console.WriteLine("Jumping", Console.ForegroundColor = ConsoleColor.Green);


                        }
                    }
                    Console.Clear();
                    Console.WriteLine("Standing", Console.ForegroundColor = ConsoleColor.Yellow);
                    Thread.Sleep(10);


                }


            }


        }


        static bool GetModuleAddy()
        {
            try
            {
                Process[] p = Process.GetProcessesByName(process);


                if (p.Length > 0)
                {


                    foreach (ProcessModule m in p[0].Modules)
                    {


                        if (m.ModuleName == "client.dll")
                        {
                            bClient = (int)m.BaseAddress;
                            return true;
                        }
                        
                    }
                    return true;
                }


                else
                {
                    return false;
                }
            }






            catch (Exception ex)
            {
                return false;
            }
        }
            
        }








}


- - - Updated - - -

After some research... I think I've found the cause. It's the GetASyncKeyState, it's not working, it's not detecting when I press Space :/

How do you create a properly working one in C#?
This might be useful

http://www.mpgh.net/forum/showthread.php?t=120656
Quote Originally Posted by Lols12342 View Post
I tried reading it but I still don't understand. When I write VK_KEY it says it's invalid, what should I define the public static extern... etc as? Right now it's : public static extern short GetAsyncKeyState(int vKey);
Code:
[DllImport("user32.dll")]
        static extern ushort GetAsyncKeyState(int vKey);

        public static bool IsKeyPushedDown(System.Windows.Forms.Keys vKey)
        {
            return 0 != (GetAsyncKeyState((int)vKey) & 0x8000);
        }
There you go.
Please drop that yellow font of yours, can't read it
Quote Originally Posted by Block4o View Post
Code:
[DllImport("user32.dll")]
        static extern ushort GetAsyncKeyState(int vKey);

        public static bool IsKeyPushedDown(System.Windows.Forms.Keys vKey)
        {
            return 0 != (GetAsyncKeyState((int)vKey) & 0x8000);
        }
There you go.
Please drop that yellow font of yours, can't read it
Thank you man! This worked. Can you explain to me what this snippet of code is doing?
The problem with the code is that you pasted it without a single clue of what you are doing. Learn a coding language before you try to use it.
Quote Originally Posted by goochguy View Post
The problem with the code is that you pasted it without a single clue of what you are doing. Learn a coding language before you try to use it.
I did not "paste" any of this code. I wrote it all. Is it my code? No. But did I make sure to understand every line of code I re-wrote? Yes.
Been over a week since last update/bump after answers, assuming solved.

/Closed.
Posts 110 of 10 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?