Solved C# Aimbot Not Finding Enemies[SOLVED]

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat
Status
Not open for further replies.

maptwo3

Newbie
Full Member
May 24, 2012
20
292
0
The program finds itself but it won't find the enemies. I've look over Fleep's source code and I cannot figure out what's wrong with it. If anyone could take a look at my code, that would be great. Here it is:

PlayerInfo.cs
C++:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Assault_Cube_Aimbot
{
  public class PlayerDataAddr
  {
    public int xMouse;
    public int yMouse;
    public int xPos;
    public int yPos;
    public int zPos;
    public int health;

    public PlayerDataAddr(int _xMouse, int _yMouse, int _xPos, int _yPos, int _zPos, int _health)
    {
      xMouse = _xMouse;
      yMouse = _yMouse;
      xPos = _xPos;
      yPos = _yPos;
      zPos = _zPos;
      health = _health;
    }
  }

  public struct PlayerData
  {
    public int baseAddress;
    public int[] multiLevel;
    public PlayerDataAddr offsets;
  }

  public struct PlayerDataVec
  {
    public float xMouse;
    public float yMouse;
    public float xPos;
    public float yPos;
    public float zPos;
    public int health;
  }
}
Form1.cs
C++:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ProcessMemoryReaderLib;
using System.Globalization;
using System.Diagnostics;

namespace Assault_Cube_Aimbot
{
  public partial class Form1 : Form
  {
    Process[] MyProcess;
    ProcessModule mainModule;
    ProcessMemoryReader Mem = new ProcessMemoryReader();
    PlayerData MainPlayer = new PlayerData();

    #region ---------Addressess-------------
    int MainPlayerBase = 0x4DF73C;
    int[] MainPlayerMultiLvl = new int[] { 0x30 };
    PlayerDataAddr MainPlayerOffsets = new PlayerDataAddr(0x10, 0x14, 0x4, 0xC, 0x8, 0xC4);

    #region ---------ENEMY Addressess-------------
    List<PlayerData> EnemyAddresses = new List<PlayerData>();
    int[] enOneMultiLevel = new int[] { 0x4, 0x364, 0x8, 0x30 };
    #endregion
    #endregion

    float PI = 3.14159265f;

    bool GameFound = false;
    bool FocusingOnEnemy = false;
    int FocusTarget = -1;

    public Form1()
    {
      InitializeComponent();
    }

    private void GameChoiceCB_SelectedIndexChanged(object sender, EventArgs e)
    {
      try
      {
        for (int i = 0; i < MyProcess.Length; i++)
        {
          if (GameChoiceCB.SelectedItem.ToString().Contains(MyProcess[i].ProcessName))
          {
            MyProcess[0] = Process.GetProcessById(int.Parse(GameChoiceCB.Text.Replace(MyProcess[i].ProcessName + "-", "")));
            mainModule = MyProcess[0].MainModule;
            Mem.ReadProcess = MyProcess[0];
            Mem.OpenProcess();
            GameFound = true;

            MainPlayer.baseAddress = MainPlayerBase;
            MainPlayer.multiLevel = MainPlayerMultiLvl;
            MainPlayer.offsets = new PlayerDataAddr(MainPlayerOffsets.xMouse, MainPlayerOffsets.yMouse, MainPlayerOffsets.xPos, MainPlayerOffsets.zPos, MainPlayerOffsets.yPos, MainPlayerOffsets.health);
            SetupEnemyVars();
          }
        }
      }
      catch(Exception ex)
      {
        MessageBox.Show("Could not connect to process" + ex.Message);
      }
    }

    private void GameChoiceCB_MouseClick(object sender, MouseEventArgs e)
    {
      GameChoiceCB.Items.Clear();
      MyProcess = Process.GetProcesses();
      for (int i = 0; i < MyProcess.Length; i++)
      {
        GameChoiceCB.Items.Add(MyProcess[i].ProcessName + "-" + MyProcess[i].Id);
      }
    }

    private void SetupEnemyVars()
    {
      PlayerData En1 = new PlayerData();
      En1.baseAddress = MyProcess[0].MainModule.BaseAddress.ToInt32() + 0x000E4E08;
      En1.multiLevel = enOneMultiLevel;
      En1.offsets = MainPlayer.offsets;
      EnemyAddresses.Add(En1);
    }

    private void Form1_Load(object sender, EventArgs e)
    {
      processTMR.Enabled = true;
    }

    private void processTMR_Tick(object sender, EventArgs e)
    {
      if (GameFound)
      {
        int playerBase = Mem.ReadMultiLevelPointer(MainPlayer.baseAddress, 4, MainPlayer.multiLevel);
        XPosLBL.Text = "Xpos: " + Mem.ReadFloat(playerBase + MainPlayer.offsets.xPos);
        YPosLBL.Text = "Ypos: " + Mem.ReadFloat(playerBase + MainPlayer.offsets.yPos);
        ZPosLBL.Text = "Zpos: " + Mem.ReadFloat(playerBase + MainPlayer.offsets.zPos);

        int hotKey = ProcessMemoryReaderApi.GetKeyState(02); //RIGHT MOUSE
        if ((hotKey & 0x8000) != 0)
        {
          FocusingOnEnemy = true;
          Aimbot();
        }
        else
        {
          FocusingOnEnemy = false;
          FocusTarget = -1;
        }
      }
      
      try
      {
        if (MyProcess != null)
        {
          if (MyProcess[0].HasExited)
            GameFound = false;
        }
      }

      catch (Exception ex)
      {
        MessageBox.Show("There was an error " + ex.Message);
      }
    }

    private PlayerDataVec GetPlayerData(PlayerData updatePlayer)
    {
      PlayerDataVec playerRet = new PlayerDataVec();
      int playerBase = Mem.ReadMultiLevelPointer(updatePlayer.baseAddress, 4, updatePlayer.multiLevel);
      playerRet.xMouse = Mem.ReadFloat(playerBase + updatePlayer.offsets.xMouse);
      playerRet.yMouse = Mem.ReadFloat(playerBase + updatePlayer.offsets.yMouse);
      playerRet.xPos = Mem.ReadFloat(playerBase + updatePlayer.offsets.xPos);
      playerRet.yPos = Mem.ReadFloat(playerBase + updatePlayer.offsets.yPos);
      playerRet.zPos = Mem.ReadFloat(playerBase + updatePlayer.offsets.zPos);
      playerRet.health = Mem.ReadInt(playerBase + updatePlayer.offsets.health);

      return playerRet;
    }

    private void Aimbot()
    {
      PlayerDataVec playerDataVec = GetPlayerData(MainPlayer);
      List<PlayerDataVec> enemiesDataVec = new List<PlayerDataVec>();

      for (int i = 0; i < EnemyAddresses.Count; i++)
      {
        PlayerDataVec enemyDataVector = GetPlayerData(EnemyAddresses[i]);
        enemiesDataVec.Add(enemyDataVector);
      }

      if (playerDataVec.health > 0)
      {
        int target = 0;
        if (FocusingOnEnemy && FocusTarget != -1)
        {
          if (enemiesDataVec[FocusTarget].health > 0)
            target = FocusTarget;
          else target = FindClosestEnemyIndex(enemiesDataVec.ToArray(), playerDataVec);

          if (target != -1)
          {
            FocusTarget = target;
            if (enemiesDataVec[target].health > 0)
              AimAtTarget(enemiesDataVec[target], playerDataVec);
          }
        }
      }
    }

    private void AimAtTarget(PlayerDataVec enemyDataVector, PlayerDataVec playerDataVector)
    {
      float pitchX = (float)Math.Atan2(enemyDataVector.zPos - playerDataVector.zPos,
        Get3dDistance(enemyDataVector, playerDataVector))
        * 180 / PI;

      float yawY = -(float)Math.Atan2(enemyDataVector.xPos - playerDataVector.xPos, enemyDataVector.yPos - playerDataVector.yPos)
        / PI * 180 + 180;

      int playerBase = Mem.ReadMultiLevelPointer(MainPlayer.baseAddress, 4, MainPlayer.multiLevel);

      Mem.WriteFloat(playerBase + MainPlayer.offsets.xMouse, yawY);
      Mem.WriteFloat(playerBase + MainPlayer.offsets.yMouse, pitchX);
    }

    private int FindClosestEnemyIndex(PlayerDataVec[] enemiesDataVec, PlayerDataVec myPosition)
    {
      float[] distances = new float[enemiesDataVec.Length];
      for (int i = 0; i < enemiesDataVec.Length; i++)
      {
        if (enemiesDataVec[i].health > 0)
          distances[i] = Get3dDistance(enemiesDataVec[i], myPosition);
        else
          distances[i] = float.MaxValue;
      }

      float[] newDistances = new float[distances.Length];
      Array.Copy(distances, newDistances, distances.Length);
      Array.Sort(newDistances);

      for (int i = 0; i < distances.Length; i++)
      {
        if (distances[i] == newDistances[0])
          return i;
      }
      return -1;
    }
    private float Get3dDistance(PlayerDataVec to, PlayerDataVec from)
    {
      return (float)(Math.Sqrt(
        ((to.xPos - from.xPos) * (to.xPos - from.xPos)) +
        ((to.yPos - from.yPos) * (to.yPos - from.yPos)) +
        ((to.zPos - from.zPos) * (to.zPos - from.zPos))));
    }
  }
}
I really don't see what I did wrong, but Fleep's aimbot works just fine for me, but mine cannot find the enemy.

Thanks.

Virus scan:
https://www.virustotal.com/file/a15790cc8b4a0eb18d0ae524b4fe34936372d6639814cd8b46fafef89bef7d92/analysis/1343041946/
 

Attachments

Fleep

Founder
Meme Tier VIP
May 20, 2012
572
11,023
6
Ok then I believe that is fixed here is the only small mistake you had within your Aimbot() method, my comments should clear that up.

C++:
    private void Aimbot()
    {
      PlayerDataVec playerDataVec = GetPlayerData(MainPlayer);
      List<PlayerDataVec> enemiesDataVec = new List<PlayerDataVec>();

      for (int i = 0; i < EnemyAddresses.Count; i++)
      {
        PlayerDataVec enemyDataVector = GetPlayerData(EnemyAddresses[i]);
        enemiesDataVec.Add(enemyDataVector);
      }

      if (playerDataVec.health > 0)
      {
        int target = 0;
        if (FocusingOnEnemy && FocusTarget != -1)
        {
          if (enemiesDataVec[FocusTarget].health > 0)
            target = FocusTarget;
          else target = FindClosestEnemyIndex(enemiesDataVec.ToArray(), playerDataVec);
          //This wasnt supposed to be here but below where i put it :) 
          //if (target != -1)
          //{
          //  FocusTarget = target;
          //  if (enemiesDataVec[target].health > 0)
          //    AimAtTarget(enemiesDataVec[target], playerDataVec);
          //}
        }
        //was missing this else also
        else
          target = FindClosestEnemyIndex(enemiesDataVec.ToArray(), playerDataVec);


        if (target != -1)
        {
          FocusTarget = target;
          if (enemiesDataVec[target].health > 0)
            AimAtTarget(enemiesDataVec[target], playerDataVec);
        }


      }
    }
Otherwise good code throughout :)

Fleep
 

Fleep

Founder
Meme Tier VIP
May 20, 2012
572
11,023
6
Hey mapTwo Ive had a quick look and still cant see the problem myself, if you still havent fixed it please upload your solution in a zip and il take a look at it.

Fleep
 

maptwo3

Newbie
Full Member
May 24, 2012
20
292
0
That did it. Thanks for the help. One thing I was wondering though. Do you know if it's possible to not have all the enemy bots values hard coded? That way you can play against a bunch more but not have to go through and find all their locations?
 

Fleep

Founder
Meme Tier VIP
May 20, 2012
572
11,023
6
maptwo3 said:
That did it. Thanks for the help. One thing I was wondering though. Do you know if it's possible to not have all the enemy bots values hard coded? That way you can play against a bunch more but not have to go through and find all their locations?
Yes I'm sure that can be done but I havent myself, although I think that will only work when you share the games memory with a DLL. So your pretty much stuck to C++ with code injection.

Fleep
 

maptwo3

Newbie
Full Member
May 24, 2012
20
292
0
Ok. Do you think that will be included in your "more complex" C++ version?
 

Fleep

Founder
Meme Tier VIP
May 20, 2012
572
11,023
6
maptwo3 said:
Ok. Do you think that will be included in your "more complex" C++ version?
If I can figure out how to do it then yes.

Fleep
 

Fleep

Founder
Meme Tier VIP
May 20, 2012
572
11,023
6
maptwo3 said:
Sounds good. Also just wanted to say thanks for the tutorials.
Your welcome, I remember you being one of my first subscribers so Im happy to help out.
Locking this now as solved :)
Fleep
 
Status
Not open for further replies.
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Community Mods League of Legends Accounts