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 Threads = new List(); private List Games = new List(); 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); /* Switch weapons | CTA */ 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); game.SwitchWeaponSlotWait(); } if (hasCTABeenFound) { game.SelectSkill(SkillHand.Right, SkillType.BattleCommand); game.CastRightSkill((int)game.Hero.X, (int)game.Hero.Y); System.Threading.Thread.Sleep(250); game.SelectSkill(SkillHand.Right, SkillType.BattleOrders); game.CastRightSkill((int)game.Hero.X, (int)game.Hero.Y); } /* Move from: start of act 5, to: Red Portal game.MoveWait(5103, 5043); game.MoveWait(5110, 5064); */ /* Eldritch game.WaypointInteract(game.Objects.Find("ExpansionWaypoint"), D2Data.WaypointDestination.FrigidHighlands); game.TeleportWait(3760, 5097); game.TeleportWait(3750, 5078); List eldritchAndMinions; while ((eldritchAndMinions = game.Units.FindAll("MinionExp")) == null) System.Threading.Thread.Sleep(10); AppendText("Found: " + eldritchAndMinions.Count + " MinionExp" + Environment.NewLine); for (int i = eldritchAndMinions.Count - 1; i > 0; i--) { AppendText("Targetting: " + eldritchAndMinions[i].UID + Environment.NewLine); while (eldritchAndMinions[i].State != GameServer.NPCMode.Dead && eldritchAndMinions[i].State != GameServer.NPCMode.Dying) { AppendText("Attacking: " + eldritchAndMinions[i].UID + Environment.NewLine); game.Attack(eldritchAndMinions[i], D2Data.SkillType.Lightning); System.Threading.Thread.Sleep(250); } } */ /* 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 pindleAndMinions; while ((pindleAndMinions = game.Units.FindAll("DefiledWarrior")) == null) System.Threading.Thread.Sleep(10); AppendText("Found: " + pindleAndMinions.Count + " DefiledWarriors" + Environment.NewLine); // Go backwards down the list of units, because pindle is the last one we get for (int i = pindleAndMinions.Count-1; i > 0; i--) { AppendText("Targetting: " + pindleAndMinions[i].UID + Environment.NewLine); while (pindleAndMinions[i].State != GameServer.NPCMode.Dead && pindleAndMinions[i].State != GameServer.NPCMode.Dying) { AppendText("Attacking: " + pindleAndMinions[i].UID + Environment.NewLine); game.Attack(pindleAndMinions[i], D2Data.SkillType.Lightning); System.Threading.Thread.Sleep(250); } } //*/ // Clean up game.Clear(); } } }