All pastes #587219 Raw Edit

Someone

public text v1 · immutable
#587219 ·published 2007-06-24 11:22 UTC
rendered paste body
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Text;
using System.Threading;
using System.Windows.Forms;

using Chief;

using D2Data;

namespace ChiefSpam
{
    public partial class Form1 : Form
    {
        private Process[] Processes = Process.GetProcessesByName("Diablo II");
        private Process SelectedProcess;

        private List<Thread> Threads = new List<Thread>();
        private List<int> Games = new List<int>();

        public Form1()
        {
            InitializeComponent();

            this.comboBox1.DataSource       = this.Processes;
            this.comboBox1.ValueMember      = "Id";
            this.comboBox1.DisplayMember    = "MainWindowTitle";

            System.Windows.Forms.Timer myTimer = new System.Windows.Forms.Timer();
            myTimer.Interval = 200;
            myTimer.Tick += new EventHandler(myTimer_Tick);
            myTimer.Start();
        }

        void myTimer_Tick(object sender, EventArgs e)
        {
            if (this.comboBox1.Items.Count != this.Processes.Length)
                this.comboBox1.DataSource = this.Processes;

            this.Processes = Process.GetProcessesByName("Diablo II");

            this.SelectedProcess = comboBox1.SelectedItem as Process;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (this.SelectedProcess == null)
            {
                MessageBox.Show("You must select a Diablo II window to attach to.", "TristHelper", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (this.Games.Contains(this.SelectedProcess.Id))
            {
                MessageBox.Show("Already attached to this window!", "TristHelper", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            else
                this.Games.Add(this.SelectedProcess.Id);

            Thread thread = new Thread(new ThreadStart(GameThread));
            thread.Start();
            this.Threads.Add(thread);
            //GameThread();
        }

        delegate void SetAppendTextCallback(string text);
        private void AppendText(string text)
        {
            // InvokeRequired required compares the thread ID of the
            // calling thread to the thread ID of the creating thread.
            // If these threads are different, it returns true.
            if (this.richTextBox1.InvokeRequired)
            {
                SetAppendTextCallback d = new SetAppendTextCallback(AppendText);
                this.Invoke(d, new object[] { text });
            }
            else
            {
                this.richTextBox1.AppendText(text);
                this.richTextBox1.ScrollToCaret();
            }
        }

        protected override void Dispose(bool disposing)
        {
            foreach (Thread thread in this.Threads)
                thread.Abort();

            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void GameThread()
        {
            Chief.Game game = new Chief.Game();

            game.Attach(this.SelectedProcess);
            AppendText("Attached" + Environment.NewLine);

            System.Threading.Thread.Sleep(250);

            Chief.PacketConfirmation waitForGo = delegate(object packet)
                {
                    string msg = (packet as GameClient.SendMessage).Message;
                    if (msg.ToLower() == "go")
                        return true;
                    else
                        return false;
                };

            game.WaitForPacket(D2Packets.GameClientPacket.SendMessage, waitForGo, 60 * 60 * 1000);

            AppendText("Started" + Environment.NewLine);

            //AppendText("Hero UID: " + game.Hero.UID + Environment.NewLine);
            //AppendText("       X: " + game.Hero.X + Environment.NewLine);
            //AppendText("       Y: " + game.Hero.Y + Environment.NewLine);

            List<SkillType> Prebuffs = new List<SkillType>();

            #region Sorceress
            // Use the best possible ice armor
            if (game.Hero.Skills.ContainsKey(SkillType.ChillingArmor))
                Prebuffs.Add(SkillType.ChillingArmor);
            else if (game.Hero.Skills.ContainsKey(SkillType.ShiverArmor))
                Prebuffs.Add(SkillType.ShiverArmor);
            else if (game.Hero.Skills.ContainsKey(SkillType.FrozenArmor))
                Prebuffs.Add(SkillType.FrozenArmor);

            if (game.Hero.Skills.ContainsKey(SkillType.ThunderStorm))
                Prebuffs.Add(SkillType.ThunderStorm);
            #endregion

            #region Paladin
            if (game.Hero.Skills.ContainsKey(SkillType.HolyShield))
                Prebuffs.Add(SkillType.HolyShield);
            #endregion

            #region Barbarian
            if (game.Hero.Skills.ContainsKey(SkillType.BattleCommand))
                Prebuffs.Add(SkillType.BattleCommand);
            if (game.Hero.Skills.ContainsKey(SkillType.BattleOrders))
                Prebuffs.Add(SkillType.BattleOrders);
            if (game.Hero.Skills.ContainsKey(SkillType.Shout))
                Prebuffs.Add(SkillType.Shout);
            #endregion

            #region Assasin
            if (game.Hero.Skills.ContainsKey(SkillType.Fade))
                Prebuffs.Add(SkillType.Fade);
            if (game.Hero.Skills.ContainsKey(SkillType.BurstOfSpeed))
                Prebuffs.Add(SkillType.BurstOfSpeed);
            #endregion

            #region Druid
            if (game.Hero.Skills.ContainsKey(SkillType.CycloneArmor))
                Prebuffs.Add(SkillType.CycloneArmor);
            // If he has Oak Sage AND doesn't have HeartOfTheWolverine
            if (game.Hero.Skills.ContainsKey(SkillType.OakSage) && !game.Hero.Skills.ContainsKey(SkillType.HeartOfWolverine))
                Prebuffs.Add(SkillType.OakSage);
            else if (game.Hero.Skills.ContainsKey(SkillType.HeartOfWolverine))
                Prebuffs.Add(SkillType.HeartOfWolverine);
            #endregion

            /* Move from: start of act 5, to: next to WP
             */
            game.MoveWait(5103, 5043);
            game.MoveWait(5110, 5064);

            /* Eldritch
             */
            game.WaypointInteractWait(game.Objects.Find("ExpansionWaypoint"), D2Data.WaypointDestination.FrigidHighlands);

            /* Prebuff
             */
            /* Detect CTA
             */
            bool hasCTA = game.Hero.IsWearingItem(delegate(Item item)
                {
                    if (item.Runeword == BaseRuneword.GetByName("Call to Arms"))
                        return true;

                    return false;
                });

            if (hasCTA)
            {
                AppendText("Trying to switch to CTA" + Environment.NewLine);

                bool hasCTABeenFound = false;

                for (int tries = 0; tries < 10; tries++)
                {
                    if (game.Hero.GetItemAt(EquipmentLocation.LeftHand) != null)
                        if (game.Hero.GetItemAt(EquipmentLocation.LeftHand).Runeword == BaseRuneword.GetByName("Call to Arms"))
                            hasCTABeenFound = true;

                    if (game.Hero.GetItemAt(EquipmentLocation.RightHand) != null)
                        if (game.Hero.GetItemAt(EquipmentLocation.RightHand).Runeword == BaseRuneword.GetByName("Call to Arms"))
                            hasCTABeenFound = true;

                    if (hasCTABeenFound)
                        break;

                    if (tries == 9)
                    {
                        AppendText("Tried switching to CTA 10 times, failed!" + Environment.NewLine);
                        break;
                    }

                    game.SwitchWeaponSlotWait();
                }

                if (hasCTABeenFound)
                {
                    game.CastSkillOnSelf(SkillType.BattleCommand);
                    System.Threading.Thread.Sleep(250);

                    game.CastSkillOnSelf(SkillType.BattleOrders);
                    System.Threading.Thread.Sleep(1000);

                    game.SwitchWeaponSlotWait();
                }
            }

            AppendText("Casting buffs" + Environment.NewLine);

            foreach (SkillType skill in Prebuffs)
            {
                game.CastSkillOnSelf(skill);

                System.Threading.Thread.Sleep(250);
            }

            /* Kill Eldritch
             */
            game.TeleportWait(3760, 5097);
            game.TeleportWait(3750, 5078);

            List<NPC> eldritchAndMinions;

            while ((eldritchAndMinions = game.Units.FindAll(NPCCode.MinionExp)) == null)
                System.Threading.Thread.Sleep(10);

            AppendText("Found: " + eldritchAndMinions.Count + " MinionExp" + Environment.NewLine);

            game.Kill(eldritchAndMinions, SkillType.Lightning, 250, 15000);

            /* Shenk
             */

            // Back to WP
            game.TeleportWait(3760, 5097);
            game.TeleportWait(3784, 5111);

            // Down to Shenk
            game.TeleportWait(3801, 5103);
            game.TeleportWait(3828, 5106);
            game.TeleportWait(3855, 5109);
            game.TeleportWait(3878, 5113);
            game.TeleportWait(3891, 5125);

            List<NPC> overseers;

            while ((overseers = game.Units.FindAll(NPCCode.OverSeer)) == null)
                System.Threading.Thread.Sleep(10);

            AppendText("Found: " + overseers.Count + " OverSeer" + Environment.NewLine);

            game.Kill(overseers, SkillType.Lightning, 250, 15000);

            // Back up to WP
            game.TeleportWait(3855, 5109);
            game.TeleportWait(3828, 5106);
            game.TeleportWait(3801, 5103);
            game.TeleportWait(3784, 5111);

            game.WaypointInteractWait(game.Objects.Find("ExpansionWildernessWaypoint"), D2Data.WaypointDestination.Harrogath);
            //*/

            /* Pindle
             */
            game.MoveWait(5119, 5090);
            game.MoveWait(5131, 5108);
            game.MoveWait(5119, 5120);

            game.PortalInteract(game.Objects.Find("PermanentTownPortal"));

            game.TeleportWait(10064, 13293);
            game.TeleportWait(10063, 13268);
            game.TeleportWait(10058, 13238);

            List<NPC> pindleAndMinions;

            while ((pindleAndMinions = game.Units.FindAll(NPCCode.DefiledWarrior)) == null)
                System.Threading.Thread.Sleep(10);

            AppendText("Found: " + pindleAndMinions.Count + " DefiledWarrior" + Environment.NewLine);

            game.Kill(pindleAndMinions, SkillType.Lightning, 250, 15000);
            //*/

            AppendText("All done, cleaning up!" + Environment.NewLine);

            // Clean up
            game.Clear();
        }
    }
}