Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C#] Calling functions from classes

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Sneak
Grandmaster Cheater Supreme
Reputation: 0

Joined: 05 Nov 2008
Posts: 1895

PostPosted: Wed Nov 25, 2009 12:03 pm    Post subject: [C#] Calling functions from classes Reply with quote

How do you call functions/methods and all that BS from classes? I understand using params also, but thats not really what im looking for. Here is an example of lovelessbot by yoyonerd


Main form

Code:
using System;
using System.Threading;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace LovelessBot
{
    public partial class FormMain : Form
    {
        [DllImport("user32.dll")]
        static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk);

        [DllImport("user32.dll")]
        static extern bool UnregisterHotKey(IntPtr hWnd, int id);

        ProcessAPI procAPI = new ProcessAPI("Mooplestory");

        Thread AutoCCThread;
        Thread AutoAttackThread;
        Thread AutoLootThread;
        Thread AutoPotThread;

        public FormMain()
        {
            InitializeComponent();
            RegisterHotKey(this.Handle, 10, 0, 0x70);//F1
            RegisterHotKey(this.Handle, 20, 0, 0x71);//F2
            RegisterHotKey(this.Handle, 30, 0, 0x72);//F3
            RegisterHotKey(this.Handle, 40, 0, 0x73);//F4
        }

        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);
            switch (m.Msg)
            {
                case 0x312:
                    switch (m.WParam.ToInt32())
                    {
                        case 10:
                            if (!chboxAutoCC.Checked)
                                chboxAutoCC.Checked = true;
                            else
                                chboxAutoCC.Checked = false;
                            break;
                        case 20:
                            if (!chboxAutoAttack.Checked)
                                chboxAutoAttack.Checked = true;
                            else
                                chboxAutoAttack.Checked = false;
                            break;
                        case 30:
                            if (!chboxAutoLoot.Checked)
                                chboxAutoLoot.Checked = true;
                            else
                                chboxAutoLoot.Checked = false;
                            break;
                        case 40:
                            if (!chboxAutoPot.Checked)
                                chboxAutoPot.Checked = true;
                            else
                                chboxAutoPot.Checked = false;
                            break;
                    }
                    break;
            }
        }

        private void FormMain_Load(object sender, EventArgs e)
        {
            procAPI.OpenProcess();
        }

        private void FormMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            procAPI.CloseHandle();
        }

        private void chboxAutoCC_CheckedChanged(object sender, EventArgs e)
        {
            if (chboxAutoCC.Checked)
            {
                AutoCCThread = new Thread(new ThreadStart(AutoCCForThread));
                AutoCCThread.Start();
            }
            else
            {
                AutoCCThread.Abort();
                AutoCCThread = new Thread(new ThreadStart(AutoCCForThread));
            }
        }

        private void chboxAutoAttack_CheckedChanged(object sender, EventArgs e)
        {
            if (chboxAutoAttack.Checked)
            {
                AutoAttackThread = new Thread(new ThreadStart(AutoAttackForThread));
                AutoAttackThread.Start();
            }
            else
            {
                AutoAttackThread.Abort();
                AutoAttackThread = new Thread(new ThreadStart(AutoAttackForThread));
            }
        }

        private void chboxAutoLoot_CheckedChanged(object sender, EventArgs e)
        {
            if (chboxAutoLoot.Checked)
            {
                AutoLootThread = new Thread(new ThreadStart(AutoLootForThread));
                AutoLootThread.Start();
            }
            else
            {
                AutoLootThread.Abort();
                AutoLootThread = new Thread(new ThreadStart(AutoLootForThread));
            }
        }

        private void chboxAutoPot_CheckedChanged(object sender, EventArgs e)
        {
            if (chboxAutoPot.Checked)
            {
                txtHP.ReadOnly = true;
                txtMP.ReadOnly = true;
                new AutoPot().SetAlert();
                AutoPotThread = new Thread(new ThreadStart(AutoPotForThread));
                AutoPotThread.Start();
            }
            else
            {
                txtHP.ReadOnly = false;
                txtMP.ReadOnly = false;
                AutoPotThread.Abort();
                AutoPotThread = new Thread(new ThreadStart(AutoPotForThread));
            }
        }

        private void AutoCCForThread()
        {
            while (true)
            {
                Thread.Sleep(1500);
                new AutoCC().DetectCC(0);
            }
        }

        private void AutoAttackForThread()
        {
            while (true)
                new AutoAttack().Attack();
        }

        private void AutoLootForThread()
        {
            while (true)
                new AutoLoot().Loot();
        }

        private void AutoPotForThread()
        {
            for (; ; Thread.Sleep(500))
            {
                int MinHP = 0;
                int MinMP = 0;

                try
                {
                    MinHP = int.Parse(txtHP.Text);
                    MinMP = int.Parse(txtMP.Text);
                }
                catch
                {
                    MessageBox.Show("You have entered invalid health/mana values, application might be unstable", "Error!");
                    return;
                }

                new AutoPot().UsePotion(MinHP, MinMP);
            }
        }
    }
}


Auto Loot

Code:
using System;
using System.Threading;

namespace LovelessBot
{
    class AutoLoot
    {
        ProcessAPI procAPI = new ProcessAPI("MoopleStory");

        public void Loot()
        {
            procAPI.GetWindowHandle("MoopleStoryClass");
            procAPI.SendKey((int)APIs.VKeys.VK_Z);
            Thread.Sleep(200);
        }
    }
}

_________________
Back to top
View user's profile Send private message
gogodr
I post too much
Reputation: 125

Joined: 19 Dec 2006
Posts: 2041

PostPosted: Wed Nov 25, 2009 2:33 pm    Post subject: Reply with quote

you need to initialize an AutoLoot like

AutoLoot autoloot;

then you use it like this

autoloot.Loot();

?
-not 100% sure though
Back to top
View user's profile Send private message MSN Messenger
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Wed Nov 25, 2009 7:45 pm    Post subject: Reply with quote

Create a new class object -> go hog wild
Back to top
View user's profile Send private message
NINTENDO
Grandmaster Cheater Supreme
Reputation: 0

Joined: 02 Nov 2007
Posts: 1371

PostPosted: Thu Nov 26, 2009 2:09 pm    Post subject: Reply with quote

unless you are calling methods from a static class you must declear a instance of the class. Then you'll access the class from the reference. Easy as that.
_________________
Intel over amd yes.
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
Sneak
Grandmaster Cheater Supreme
Reputation: 0

Joined: 05 Nov 2008
Posts: 1895

PostPosted: Fri Nov 27, 2009 3:20 pm    Post subject: Reply with quote

Alright thanks Very Happy
_________________
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites