无法在组合框中选择项目

时间:2020-10-01 08:30:28

标签: c# combobox

我正在继续学习如何制作瞄准机器人的教程(即使用它来为CSGO制作目标)。由于无法添加该组合框以选择该应用程序,因此我无法对其进行尝试。这是用于组合框的所有代码。

这是组合框的代码

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

            try
            {

                for (int i = 0; i < MyProcess.Length; i++)
                {
                    if (comboBox1.SelectedItem.ToString().Contains(MyProcess[i].ProcessName))
                    {
                        MyProcess[0] = Process.GetProcessById(int.Parse(comboBox1.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.ypos, MainPlayerOffsets.zpos, MainPlayerOffsets.health);

                        SetupEnemyVars();
                    }
                }

            }

            catch (Exception ex)

            {
                MessageBox.Show("Could not Conncet to Process" + ex.Message);
            }

        }

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

        }

这是其余的代码。我给计时器命名为“ processTMR_Tick” 它会在下半部分。查看我的评论以获取有关主题的更多信息

namespace Hack_client
{
    public partial class Form1 : Form
    {

        Process[] MyProcess;
        ProcessModule mainModule;
        ProcessMemoryReader Mem = new ProcessMemoryReader();
        PlayerData MainPlayer = new PlayerData();

        #region ------Addresses------

        int MainPlayerBase = 0xD3AC5C;
        int[] MainPlayerMultiLvl = new int[] { 0x0 };
        PlayerDataAddr MainPlayerOffsets = new PlayerDataAddr(0xB380, 0x99D, 0x134, 0x13C, 0x138, 0xFC);

        #region -----ENEMY Address-----

        List<PlayerData> EnemyAddresses = new List<PlayerData>();
        int[] enOneMultiLevel = new int[] {0xED, 0x0};

        #endregion
        #endregion  

        float PI = 3.14159265f;

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


        public Form1()
        {
            InitializeComponent();
        }

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

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

            try
            {

                for (int i = 0; i < MyProcess.Length; i++)
                {
                    if (comboBox1.SelectedItem.ToString().Contains(MyProcess[i].ProcessName))
                    {
                        MyProcess[0] = Process.GetProcessById(int.Parse(comboBox1.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.ypos, MainPlayerOffsets.zpos, MainPlayerOffsets.health);

                        SetupEnemyVars();
                    }
                }

            }

            catch (Exception ex)

            {
                MessageBox.Show("Could not Conncet to Process" + ex.Message);
            }

        }

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

        }

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

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void processTMR_Tick(object sender, EventArgs e)
        {
            if (Gamefound) 
            {
                int playerBase = Mem.ReadMultiLevelPointer(MainPlayer.baseAddress, 0, 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);
                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 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);
                }

                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 playerDataVec) 
        {
            float pitchX = (float)Math.Atan2(enemyDataVector.zpos - playerDataVec.zpos, Get3dDistance(enemyDataVector, playerDataVec))
                * 180 / PI;

            float yawY = -(float)Math.Atan2(enemyDataVector.xpos - playerDataVec.xpos, enemyDataVector.ypos - playerDataVec.ypos)
                / PI * 180 + 180;

            int playerBase = Mem.ReadMultiLevelPointer(MainPlayer.baseAddress, 0, MainPlayerMultiLvl);

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

        }

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

            float [] newDistance = new float[distance.Length];
            Array.Copy(distance, newDistance, distance.Length);
            Array.Sort(newDistance);

            for (int i = 0; i < enemiesDataVec.Length; i++)
            {
                if (distance[i] == newDistance[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.zpos - from.ypos) * (to.xpos - from.ypos)) +
                ((to.xpos - from.zpos) * (to.xpos - from.zpos))
                ));

        }
        
        private PlayerDataVec GetPlayerData(PlayerData updatePlayer) 
        {
            PlayerDataVec playerRet = new PlayerDataVec();
            int playerBase = Mem.ReadMultiLevelPointer(updatePlayer.baseAddress, 0, MainPlayerMultiLvl);
            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 label5_Click(object sender, EventArgs e)
        {

        }
    }
}

0 个答案:

没有答案