Search code examples
c#functioncheat-engine

C# Open Form and run fuction at the same time


I am trying to code a memory cheat for a game but I want to create a menu so I decided to make it. And now I want that my program is opening the form and doing the cheat at the same time. Because now the cheat is doing it or otherwise the cheat is not working and the form is opening. I am pretty new in C# so sorry if I am noob ... :P

Thanks, IzzyMichiel

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Threading;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ac_client_cheat
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            Main();
        }

        public static int Pbase = 0x00509B74;
        public static int Health = 0xf8;
        public static int mgammo = 0x150;
        public static int fly = 0x44;
        public void Main()
        {
            VAMemory vam = new VAMemory("ac_client");
            int localplayer = vam.ReadInt32((IntPtr)Pbase);
            {
                while (true)
                {
                   int address = localplayer + fly;
                    float aimlock = vam.ReadFloat((IntPtr)address);
                    vam.WriteFloat((IntPtr)address, -5);

                    address = localplayer + Health;
                    vam.WriteInt32((IntPtr)address, 1337);

                    address = localplayer + mgammo;
                    vam.WriteInt32((IntPtr)address, +1337);
                }
            }
        }
    }
}

Solution

  • You can show the form and run your cheat loop simultaneously as following:

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
    
        public static int Pbase = 0x00509B74;
        public static int Health = 0xf8;
        public static int mgammo = 0x150;
        public static int fly = 0x44;
    
        /// <summary>The main entry point for the application.</summary>
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
    
            var f = new Form1();
            f.Show();
    
            VAMemory vam = new VAMemory("ac_client");
            int localplayer = vam.ReadInt32((IntPtr)Pbase);
    
            while (f.Visible) //loop while form is not closed
            {
                int address = localplayer + fly;
                float aimlock = vam.ReadFloat((IntPtr)address);
                vam.WriteFloat((IntPtr)address, -5);
    
                address = localplayer + Health;
                vam.WriteInt32((IntPtr)address, 1337);
    
                address = localplayer + mgammo;
                vam.WriteInt32((IntPtr)address, +1337);
    
                Application.DoEvents();  //Yield control to the message loop
            }
    
        }
    
        private void Form1_Load(object sender, EventArgs e)
        {
            //...
        }
    }