-2

So I am trying to make a bot application, trying to see how I can do certain things in c#. I am not trying to cheat or so, it is a mobile game that I am running on a emulator. This is not an application that I am trying to sell or in any way profit from, this is simply a task for me to learn how to do these kind of things.

Any how, when I launch the application the memory goes up to 16 mb instantly, also I am trying to make a loop until a stop button has been clicked.

I make functions for every single action and I am using a timer to run all the functions to scan if a pixel gets detected, but the application is running slowly and taking up a lot of memory, I feel like this kind of "looping" is not the proper way to do this kind of action, I have tried the while method as well.

Anybody who is willing to tell me what I am doing?

Pastebin

private void timer1_Tick(object sender, EventArgs e)
{
    if (timer1.Enabled == true)
    {
        // Checking if we entered Dragon's B10
        if (inDungeon == false)
        {
            GoToDungeon();
        }

        // Starting battle
        autoSumPoint = AutoIt.AutoItX.PixelGetColor(2078, 61); // 0xF1EECF
        if (autoSumPoint == 0xF1EECF)
        {
            StartBattle();
        }
        else
        {
            GoToDungeon();
        }

        // Starting auto-play
        autoSumPoint = AutoIt.AutoItX.PixelGetColor(2296, 969); // 0xFFFFFF
        if (autoSumPoint == 0xFFFFFF)
        {
            AutoCheck();
        }

        // Starting battle
        autoSumPoint = AutoIt.AutoItX.PixelGetColor(2755, 489); // 0xF1EECF
        if (autoSumPoint == 0xF1EECF)
        {
            PauseCheck();
        }

        // Checking for defeat
        if (defeatChecked == false)
        {
            DefeatCheck();
        }

        // Checking for defeat
        if (defeatChecked == false)
        {
            DefeatCheck();
        }

        // Checking for victory
        if (victoryChecked == false)
        {
            VictoryCheck();
        }

        // Checking for replay
        autoSumPoint = AutoIt.AutoItX.PixelGetColor(2602, 587); // 0xF3C761
        if (autoSumPoint == 0xF3C761)
        {
            ReplayCheck();
        }

        // Checking for refill
        if (energyRefilled == false)
        {
            RefillCheck();
        }
    }
}
Tweath
  • 124
  • 6
  • 24
  • Take a look at [Reducing memory usage of .NET applications?](https://stackoverflow.com/q/1343374). Also see [C# memory usage](https://stackoverflow.com/q/3803003) which discusses how tricky it actually is to measure your app's memory use. – dbc Oct 01 '17 at 20:02

1 Answers1

0

I would consider changing the delay between each tick of the timer, so that it doesn't burn up your CPU.

private void timer1_Tick(object sender, EventArgs e)
{
    if (timer1.Enabled == true)
    {
        // Checking if we entered Dragon's B10
        if (inDungeon == false)
        {
            GoToDungeon();
        }

        // Starting battle
        autoSumPoint = AutoIt.AutoItX.PixelGetColor(2078, 61); // 0xF1EECF
        if (autoSumPoint == 0xF1EECF)
        {
            StartBattle();
        }
        else
        {
            GoToDungeon();
        }

        // Starting auto-play
        autoSumPoint = AutoIt.AutoItX.PixelGetColor(2296, 969); // 0xFFFFFF
        if (autoSumPoint == 0xFFFFFF)
        {
            AutoCheck();
        }

        // Starting battle
        autoSumPoint = AutoIt.AutoItX.PixelGetColor(2755, 489); // 0xF1EECF
        if (autoSumPoint == 0xF1EECF)
        {
            PauseCheck();
        }

        // Checking for defeat
        if (defeatChecked == false)
        {
            DefeatCheck();
        }

        // Checking for defeat
        if (defeatChecked == false)
        {
            DefeatCheck();
        }

        // Checking for victory
        if (victoryChecked == false)
        {
            VictoryCheck();
        }

        // Checking for replay
        autoSumPoint = AutoIt.AutoItX.PixelGetColor(2602, 587); // 0xF3C761
        if (autoSumPoint == 0xF3C761)
        {
            ReplayCheck();
        }

        // Checking for refill
        if (energyRefilled == false)
        {
            RefillCheck();
        }
    }
    System.Threading.Thread.Sleep(1000)//causes it to wait 1 second after each tick before the next one to reduce CPU usage
}

See if that helps you!

Techcraft7 :)

Techcraft7
  • 129
  • 2
  • 12
  • So I have adjusted the speed of the timer's interval to 1000 and added the thread sleep, it still makes the application laggy when moving it around. What I was thinking is that the looping process of the application is wrongly used, I believe there is another method to make the loop much smoother. – Tweath Oct 01 '17 at 20:18
  • Try using a separate thread but Invoke an action so you don't get an Exception thrown (learned this the hard way) – Techcraft7 Oct 01 '17 at 20:22