using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Net;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
using TD.SandDock;
using VKontakte;

namespace Gsome
{
	public class AttackControl : DockControl
	{
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.components != null)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}

		private void InitializeComponent()
		{
			this.trndWallLuch = new TreeNode("Пускать лучепонос");
			this.trndWallGraffiti = new TreeNode("Постить граффити");
			this.trndWallAudio = new TreeNode("Постить аудио");
			this.trndWallVideo = new TreeNode("Постить видео");
			this.trndWall = new TreeNode("Стена", new TreeNode[]
			{
				this.trndWallLuch,
				this.trndWallGraffiti,
				this.trndWallAudio,
				this.trndWallVideo
			});
			this.trndTopicsExist = new TreeNode("Пячить существующие");
			this.trndTopicsNew = new TreeNode("Создавать новые");
			this.trndTopics = new TreeNode("Обсуждения", new TreeNode[]
			{
				this.trndTopicsExist,
				this.trndTopicsNew
			});
			this.trndAlbumsExist = new TreeNode("Пячить существующие");
			this.trndAlbumsNew = new TreeNode("Создавать новые");
			this.trndAlbums = new TreeNode("Альбомы", new TreeNode[]
			{
				this.trndAlbumsExist,
				this.trndAlbumsNew
			});
			this.trndAudioLuch = new TreeNode("Лучепонос в названии");
			this.trndAudio = new TreeNode("Аудио", new TreeNode[]
			{
				this.trndAudioLuch
			});
			this.trndVideoExist = new TreeNode("Пячить существующие");
			this.trndVideoNew = new TreeNode("Добавлять новые");
			this.trndVideo = new TreeNode("Видео", new TreeNode[]
			{
				this.trndVideoExist,
				this.trndVideoNew
			});
			this.trConfigs = new TreeView();
			this.spltcon = new SplitContainer();
			this.txtLog = new RichTextBox();
			this.tlpCommands = new TableLayoutPanel();
			this.btnGsom = new Button();
			this.btnStop = new Button();
			this.chkLogAutoScroll = new CheckBox();
			this.spltcon.Panel1.SuspendLayout();
			this.spltcon.Panel2.SuspendLayout();
			this.spltcon.SuspendLayout();
			this.tlpCommands.SuspendLayout();
			base.SuspendLayout();
			this.trConfigs.CheckBoxes = true;
			this.trConfigs.Dock = DockStyle.Fill;
			this.trConfigs.Location = new Point(0, 0);
			this.trConfigs.Name = "trConfigs";
			this.trConfigs.Nodes.AddRange(new TreeNode[]
			{
				this.trndWall,
				this.trndTopics,
				this.trndAlbums,
				this.trndAudio,
				this.trndVideo
			});
			this.trConfigs.Size = new Size(155, 131);
			this.trConfigs.TabIndex = 0;
			this.tlpCommands.SetColumnSpan(this.spltcon, 3);
			this.spltcon.Dock = DockStyle.Fill;
			this.spltcon.FixedPanel = FixedPanel.Panel1;
			this.spltcon.Location = new Point(3, 26);
			this.spltcon.Name = "spltcon";
			this.spltcon.Panel1.Controls.Add(this.trConfigs);
			this.spltcon.Panel2.Controls.Add(this.txtLog);
			this.spltcon.Panel2.Padding = new Padding(1);
			this.spltcon.Panel2.Paint += this.spltcon_Panel2_Paint;
			this.spltcon.Size = new Size(546, 415);
			this.spltcon.SplitterDistance = 120;
			this.spltcon.TabIndex = 1;
			this.txtLog.BackColor = SystemColors.Window;
			this.txtLog.BorderStyle = System.Windows.Forms.BorderStyle.None;
			this.txtLog.Dock = DockStyle.Fill;
			this.txtLog.Font = new Font("Courier New", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 204);
			this.txtLog.Location = new Point(1, 1);
			this.txtLog.Name = "txtLog";
			this.txtLog.ReadOnly = true;
			this.txtLog.Size = new Size(420, 413);
			this.txtLog.TabIndex = 1;
			this.txtLog.Text = "";
			this.txtLog.WordWrap = false;
			this.txtLog.LinkClicked += this.txtLog_LinkClicked;
			this.tlpCommands.AutoSizeMode = AutoSizeMode.GrowAndShrink;
			this.tlpCommands.ColumnCount = 3;
			this.tlpCommands.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100f));
			this.tlpCommands.ColumnStyles.Add(new ColumnStyle());
			this.tlpCommands.ColumnStyles.Add(new ColumnStyle());
			this.tlpCommands.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 20f));
			this.tlpCommands.Controls.Add(this.spltcon, 0, 1);
			this.tlpCommands.Controls.Add(this.btnGsom, 2, 2);
			this.tlpCommands.Controls.Add(this.btnStop, 1, 2);
			this.tlpCommands.Controls.Add(this.chkLogAutoScroll, 0, 0);
			this.tlpCommands.Dock = DockStyle.Fill;
			this.tlpCommands.Location = new Point(0, 0);
			this.tlpCommands.Name = "tlpCommands";
			this.tlpCommands.RowCount = 3;
			this.tlpCommands.RowStyles.Add(new RowStyle());
			this.tlpCommands.RowStyles.Add(new RowStyle(SizeType.Percent, 100f));
			this.tlpCommands.RowStyles.Add(new RowStyle());
			this.tlpCommands.Size = new Size(552, 475);
			this.tlpCommands.TabIndex = 3;
			this.btnGsom.Enabled = false;
			this.btnGsom.Location = new Point(464, 447);
			this.btnGsom.Name = "btnGsom";
			this.btnGsom.Size = new Size(85, 25);
			this.btnGsom.TabIndex = 0;
			this.btnGsom.Text = "Gsom!";
			this.btnGsom.UseVisualStyleBackColor = true;
			this.btnGsom.Click += this.btnGsom_Click;
			this.btnStop.Enabled = false;
			this.btnStop.Location = new Point(373, 447);
			this.btnStop.Name = "btnStop";
			this.btnStop.Size = new Size(85, 25);
			this.btnStop.TabIndex = 1;
			this.btnStop.Text = "Стоп";
			this.btnStop.UseVisualStyleBackColor = true;
			this.btnStop.Click += this.btnStop_Click;
			this.chkLogAutoScroll.Anchor = AnchorStyles.Right;
			this.chkLogAutoScroll.AutoSize = true;
			this.chkLogAutoScroll.Checked = true;
			this.chkLogAutoScroll.CheckState = CheckState.Checked;
			this.tlpCommands.SetColumnSpan(this.chkLogAutoScroll, 3);
			this.chkLogAutoScroll.Location = new Point(426, 3);
			this.chkLogAutoScroll.Name = "chkLogAutoScroll";
			this.chkLogAutoScroll.Size = new Size(123, 17);
			this.chkLogAutoScroll.TabIndex = 2;
			this.chkLogAutoScroll.Text = "Автоскролинг лога";
			this.chkLogAutoScroll.UseVisualStyleBackColor = true;
			base.Controls.Add(this.tlpCommands);
			base.Name = "AttackControl";
			base.Size = new Size(552, 475);
			this.spltcon.Panel1.ResumeLayout(false);
			this.spltcon.Panel2.ResumeLayout(false);
			this.spltcon.ResumeLayout(false);
			this.tlpCommands.ResumeLayout(false);
			this.tlpCommands.PerformLayout();
			base.ResumeLayout(false);
		}

		public int WallMessagesCount
		{
			get
			{
				return this.wallmsgCount;
			}
		}

		public int TopicsCount
		{
			get
			{
				return this.topicsCount;
			}
		}

		public int TopicsAnswersCount
		{
			get
			{
				return this.topicsAnswersCount;
			}
		}

		public int AlbumsCount
		{
			get
			{
				return this.albumsCount;
			}
		}

		public int PhotosCount
		{
			get
			{
				return this.photosCount;
			}
		}

		public int AudiosCount
		{
			get
			{
				return this.audiosCount;
			}
		}

		public int VideosCount
		{
			get
			{
				return this.videosCount;
			}
		}

		public int VideosCommentsCount
		{
			get
			{
				return this.videosCommentsCount;
			}
		}

		public bool IsPrepearing { get; private set; }

		public int PrepearingProgress { get; private set; }

		public bool IsActive { get; private set; }

		public string AimName
		{
			get
			{
				return this.aimName;
			}
		}

		public int AimId
		{
			get
			{
				return this.aimId;
			}
		}

		public static AttackControl Create(int aimId, List<VKClient> clients)
		{
			VKClient vkclient = clients[AttackControl.rnd.Next(0, clients.Count)];
			string text;
			if (aimId < 0)
			{
				text = VKClient.GetGroupName(vkclient.Account, aimId);
			}
			else
			{
				text = VKClient.GetPersonName(vkclient.Account, aimId);
			}
			AttackControl attackControl = new AttackControl();
			attackControl.aimName = text;
			attackControl.aimId = aimId;
			attackControl.Clients = clients;
			if (aimId > 0)
			{
				attackControl.trConfigs.Nodes.Remove(attackControl.trndTopics);
				attackControl.trConfigs.Nodes.Remove(attackControl.trndAlbums);
				attackControl.trConfigs.Nodes.Remove(attackControl.trndAudio);
				attackControl.trConfigs.Nodes.Remove(attackControl.trndVideo);
			}
			string text2 = string.Empty;
			foreach (char c in text)
			{
				if (char.IsLetter(c) || char.IsDigit(c) || c == '-' || c == ',' || c == '.' || c == ' ')
				{
					text2 += c;
				}
			}
			text2 = text2.Trim();
			if (text2.Length > 30)
			{
				text2 = text2.Substring(0, 27) + "...";
			}
			attackControl.TabText = ((text2.Length > 0) ? text2 : text);
			attackControl.LogWriteInfo("Цель: {0} http://vkontakte.ru/{1}{2}", new object[]
			{
				text,
				(aimId < 0) ? "club" : "id",
				Math.Abs(aimId)
			});
			return attackControl;
		}

		private AttackControl()
		{
			this.InitializeComponent();
			this.dLogWrite = new AttackControl.LogWriteCallBack(this.LogWrite);
			this.trndWall.Checked = Configurations.Wall.Enabled;
			this.trndWallLuch.Checked = Configurations.Wall.Lucheponos;
			this.trndWallGraffiti.Checked = Configurations.Wall.PostGraffiti;
			this.trndWallAudio.Checked = Configurations.Wall.PostAudio;
			this.trndWallVideo.Checked = Configurations.Wall.PostVideo;
			this.trndTopics.Checked = Configurations.Topics.Enabled;
			this.trndTopicsExist.Checked = Configurations.Topics.CreateNewTopics;
			this.trndTopicsNew.Checked = Configurations.Topics.CreateNewTopics;
			this.trndAlbums.Checked = Configurations.Albums.Enabled;
			this.trndAlbumsExist.Checked = Configurations.Albums.PhotosUploadToExist;
			this.trndAlbumsNew.Checked = Configurations.Albums.CreateNew;
			this.trndAudio.Checked = Configurations.Audio.Enabled;
			this.trndAudioLuch.Checked = Configurations.Audio.Rename;
			this.trndVideo.Checked = Configurations.Video.Enabled;
			this.trndVideoExist.Checked = Configurations.Video.CommentExist;
			this.trndVideoNew.Checked = Configurations.Video.AddNew;
		}

		public void Prepare()
		{
			this.thrPrep = new Thread(new ThreadStart(this._Prepare))
			{
				IsBackground = true
			};
			this.thrPrep.Start();
		}

		private void _Prepare()
		{
			this.IsPrepearing = true;
			if (this.aimId < 0)
			{
				List<VKClient> list = new List<VKClient>();
				bool flag = true;
				int num = 1000 / this.Clients.Count;
				List<VKClient> list2 = new List<VKClient>(this.Clients);
				foreach (VKClient vkclient in list2)
				{
					if (this.stopAllThreads)
					{
						return;
					}
					vkclient.EnterGroup(this.aimId);
					int[] personGroups = vkclient.GetPersonGroups(vkclient.Account.ID);
					if (Array.Exists<int>(personGroups, (int id) => id == this.aimId))
					{
						this.LogWrite("{0} вступил в группу, http://vkontakte.ru/id{1}", new object[]
						{
							vkclient.Account.Name,
							vkclient.Account.ID
						});
						list.Add(vkclient);
					}
					else
					{
						this.LogWriteError("{0} НЕ вступил в группу, http://vkontakte.ru/id{1}", new object[]
						{
							vkclient.Account.Name,
							vkclient.Account.ID
						});
						if (flag && MessageBox.Show("Вступление в группу с первого аккаунта не прошло успешно.\r\nВозможно группа загрыта, продолжить вступление с остальных аккаунтов?", "Ошибка вступления в группу", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
						{
							this.LogWriteInfo("Вступление в группу прервано.", new object[0]);
							this.IsPrepearing = false;
							return;
						}
						this.Clients.Remove(vkclient);
					}
					flag = false;
					this.PrepearingProgress += num;
				}
				int count = list.Count;
				if (count != 0)
				{
					this.ExcludePauseInterval = 100 * this.Clients.Count;
					this.LogWriteInfo("Сканируем обсуждения", new object[0]);
					try
					{
						this.PrepearingProgress = 0;
						List<TopicInfo> list3 = new List<TopicInfo>();
						int num2 = -1;
						int num3 = -1;
						int grabMaxCount = Configurations.Topics.GrabMaxCount;
						int num4 = 1;
						int num5 = 0;
						while ((num4 <= num3 || num3 == -1) && (num4 - 1) * 50 < grabMaxCount)
						{
							if (this.stopAllThreads)
							{
								return;
							}
							TopicInfo[] groupTopics = list[num5].GetGroupTopics(this.aimId, num4, ref num2);
							if (num3 == -1)
							{
								this.LogWrite("В группе {0} oбсуждений", new object[]
								{
									num2
								});
								num3 = ((num2 > grabMaxCount) ? ((int)Math.Ceiling((double)grabMaxCount / 50.0)) : ((int)Math.Ceiling((double)num2 / 50.0)));
								if (num3 == 0)
								{
									num3 = 1;
								}
								Thread.Sleep(500);
								num = 1000 / num3;
							}
							foreach (TopicInfo item in groupTopics)
							{
								if (!Configurations.Topics.RecognizeByKey || !AttackControl.ContainsKey(item.Title, item.AuthorID))
								{
									if (Configurations.Topics.NoAttackTodayCreated)
									{
										DateTime creationDate = item.CreationDate;
										if (creationDate.Date == DateTime.UtcNow.Date)
										{
											goto IL_35D;
										}
									}
									list3.Add(item);
									if (Configurations.General.FullLog)
									{
										this.LogWrite("Обсуждение \"{0}\" создано {1:d} {1:t}, http://vkontakte.ru/topic{2}_{3}", new object[]
										{
											item.Title,
											item.CreationDate,
											item.OwnerID,
											item.ID
										});
									}
								}
								IL_35D:;
							}
							this.PrepearingProgress += num;
							if (num4 < num3)
							{
								Thread.Sleep(1000 / count);
							}
							num4++;
							num5 = (num5 + 1) % count;
						}
						this.Topics = list3.ToArray();
					}
					catch (Exception ex)
					{
						this.LogWriteError(ex.Message, new object[0]);
					}
					this.LogWriteInfo("Сканируем альбомы", new object[0]);
					try
					{
						this.PrepearingProgress = 0;
						int grabMaxCount2 = Configurations.Albums.GrabMaxCount;
						int num6 = list[AttackControl.rnd.Next(0, count)].GetAlbumsCount(this.aimId);
						int num7 = (num6 > grabMaxCount2) ? ((int)Math.Ceiling((double)grabMaxCount2 / 50.0)) : ((int)Math.Ceiling((double)num6 / 50.0));
						if (num7 == 0)
						{
							num7 = 1;
						}
						num = 1000 / num7;
						this.LogWrite("В группе {0} альбомов", new object[]
						{
							num6
						});
						Thread.Sleep(1000);
						List<AlbumInfo> list4 = new List<AlbumInfo>();
						int num8 = 0;
						int num9 = 0;
						while (num8 < num6 && num8 < grabMaxCount2)
						{
							if (this.stopAllThreads)
							{
								return;
							}
							AlbumInfo[] array2 = list[num9].Get50Albums(this.aimId, num8);
							foreach (AlbumInfo item2 in array2)
							{
								if (item2.PhotosCount < 501)
								{
									if (Configurations.Albums.RecognizeByKey)
									{
										string description = item2.Description;
										DateTime creationDate2 = item2.CreationDate;
										if (AttackControl.ContainsKey(description, creationDate2.GetHashCode()))
										{
											goto IL_5BA;
										}
									}
									if (Configurations.Albums.NoAttackTodayCreated)
									{
										DateTime creationDate3 = item2.CreationDate;
										if (creationDate3.Date == DateTime.UtcNow.Date)
										{
											goto IL_5BA;
										}
									}
									list4.Add(item2);
									if (Configurations.General.FullLog)
									{
										this.LogWrite("Альбом \"{0}\" содержит {1} фото, cоздан {2:d}, http://vkontakte.ru/album{3}_{4}", new object[]
										{
											item2.Name,
											item2.PhotosCount,
											item2.CreationDate,
											this.aimId,
											item2.ID
										});
									}
								}
								IL_5BA:;
							}
							this.PrepearingProgress += num;
							Thread.Sleep(1000 / count);
							num8 += 50;
							num9 = (num9 + 1) % count;
						}
						this.Albums = list4.ToArray();
					}
					catch (Exception ex2)
					{
						this.LogWriteError(ex2.Message, new object[0]);
					}
					this.LogWriteInfo("Сканируем видео", new object[0]);
					try
					{
						this.PrepearingProgress = 0;
						int grabMaxCount3 = Configurations.Video.GrabMaxCount;
						List<VideoInfo> list5 = new List<VideoInfo>();
						int num10 = 0;
						list[AttackControl.rnd.Next(0, count)].Get100Videos(this.aimId, 0, out num10);
						this.LogWrite("В группе {0} видео", new object[]
						{
							num10
						});
						int num11 = (num10 > grabMaxCount3) ? ((int)Math.Ceiling((double)grabMaxCount3 / 100.0)) : ((int)Math.Ceiling((double)num10 / 100.0));
						if (num11 == 0)
						{
							num11 = 1;
						}
						num = 1000 / num11;
						int num12 = num10 - 100;
						if (num12 < 0)
						{
							num12 = 0;
						}
						int num13 = 0;
						while (!this.stopAllThreads)
						{
							VideoInfo[] array4 = list[num13].Get100Videos(this.aimId, num12);
							num13 = (num13 + 1) % count;
							for (int k = array4.Length - 1; k >= 0; k--)
							{
								VideoInfo item3 = array4[k];
								if (!Configurations.Video.NoAttackTodayCreated || !(item3.LoadDate == DateTime.UtcNow.Date))
								{
									if (Configurations.General.FullLog)
									{
										this.LogWrite("Видео \"{0}\" добавлено {1:d}, http://vkontakte.ru/video{2}_{3}", new object[]
										{
											item3.Name,
											item3.LoadDate,
											item3.OwnerID,
											item3.ID
										});
									}
									list5.Add(item3);
								}
							}
							this.PrepearingProgress += num;
							Thread.Sleep(1000 / count);
							num12 -= 100;
							if (num12 <= 0 || num10 - num12 >= grabMaxCount3)
							{
								this.Videos = list5.ToArray();
								goto IL_822;
							}
						}
						return;
					}
					catch (Exception ex3)
					{
						this.LogWriteError(ex3.Message, new object[0]);
					}
					goto IL_822;
				}
				this.LogWriteError("Ни один аккаунт не вступил в группу, сканирование прервано.", new object[0]);
				this.IsPrepearing = false;
				return;
			}
			IL_822:
			this.PrepearingProgress = 100;
			GC.Collect();
			this.LogWriteInfo("Информация о группе собрана, жми \"Gsom!\" для отаке.", new object[0]);
			base.Invoke(new AttackControl.Proc(delegate()
			{
				this.btnGsom.Enabled = true;
			}));
			this.IsPrepearing = false;
		}

		private void LogWrite(string s, params object[] p)
		{
			this.LogWrite(s, Color.Black, p);
		}

		private void LogWriteInfo(string i, params object[] p)
		{
			this.LogWrite(i, Color.Green, p);
		}

		private void LogWriteError(string err, params object[] p)
		{
			this.LogWrite(err, Color.Red, p);
		}

		private void LogWrite(string msg, Color color, params object[] p)
		{
			if (!this.txtLog.IsDisposed)
			{
				if (this.txtLog.InvokeRequired)
				{
					base.Invoke(this.dLogWrite, new object[]
					{
						msg,
						color,
						p
					});
					return;
				}
				this.txtLog.SelectionLength = 0;
				this.txtLog.SelectionStart = this.txtLog.TextLength;
				this.txtLog.SelectionColor = Color.Gray;
				this.txtLog.AppendText(string.Format("{0:t} ", DateTime.Now));
				this.txtLog.SelectionColor = color;
				this.txtLog.AppendText(string.Format(msg.Replace("\r\n", " ") + "\r\n", p));
				if (this.chkLogAutoScroll.Checked)
				{
					this.txtLog.ScrollToCaret();
				}
			}
		}

		private void spltcon_Panel2_Paint(object sender, PaintEventArgs e)
		{
			Control control = sender as Control;
			if (TextBoxRenderer.IsSupported)
			{
				TextBoxRenderer.DrawTextBox(e.Graphics, control.ClientRectangle, TextBoxState.Normal);
				return;
			}
			e.Graphics.DrawRectangle(SystemPens.ActiveBorder, 0, 0, control.ClientRectangle.Width - 1, control.ClientRectangle.Height - 1);
		}

		private void txtLog_LinkClicked(object sender, LinkClickedEventArgs e)
		{
			try
			{
				Process.Start(e.LinkText);
			}
			catch
			{
			}
		}

		private void btnGsom_Click(object sender, EventArgs e)
		{
			this.btnGsom.Enabled = false;
			Application.DoEvents();
			this.stopAllThreads = false;
			this.threads = new Thread[]
			{
				new Thread(new ThreadStart(this.PostWallMessages))
				{
					IsBackground = true
				},
				new Thread(new ThreadStart(this.CreateNewTopics))
				{
					IsBackground = true
				},
				new Thread(new ThreadStart(this.PostTopicsAnswers))
				{
					IsBackground = true
				},
				new Thread(new ThreadStart(this.CreateAlbums))
				{
					IsBackground = true
				},
				new Thread(new ThreadStart(this.PhotosUpload))
				{
					IsBackground = true
				},
				new Thread(new ThreadStart(this.AudioUpload))
				{
					IsBackground = true
				},
				new Thread(new ThreadStart(this.VideosAdd))
				{
					IsBackground = true
				},
				new Thread(new ThreadStart(this.CommentVideos))
				{
					IsBackground = true
				}
			};
			this.LogWriteInfo("GSOM!", new object[0]);
			foreach (Thread thread in this.threads)
			{
				thread.Start();
			}
			this.btnStop.Enabled = true;
			this.IsActive = true;
		}

		private void btnStop_Click(object sender, EventArgs e)
		{
			this.btnStop.Enabled = false;
			Application.DoEvents();
			this.stopAllThreads = true;
			while (this.thrPrep != null && this.thrPrep.IsAlive)
			{
				Application.DoEvents();
				Thread.Sleep(100);
			}
			if (this.threads != null)
			{
				foreach (Thread thread in this.threads)
				{
					while (thread.IsAlive)
					{
						Application.DoEvents();
						Thread.Sleep(100);
					}
				}
			}
			this.threads = null;
			this.btnGsom.Enabled = true;
			this.IsActive = false;
		}

		private void PostWallMessages()
		{
			int num = Configurations.Wall.Audio.Length;
			int num2 = Configurations.Wall.Videos.Length;
			int num3 = Configurations.Wall.Graffities.Length;
			GsomFormats gsomFormats = GsomFormats.Default;
			if (Configurations.General.AddExtraLines)
			{
				gsomFormats |= GsomFormats.InsertExtraLines;
			}
			if (Configurations.General.AddAsciiImages)
			{
				gsomFormats |= GsomFormats.UseMultiLineMessages;
			}
			if (Configurations.General.RandomCase)
			{
				gsomFormats |= GsomFormats.RandomCase;
			}
			int num4 = Configurations.Wall.TimeDelay;
			int id = this.aimId;
			List<VKClient> list = new List<VKClient>(this.Clients);
			Queue<AttackControl.ExcudedVKClient> queue = new Queue<AttackControl.ExcudedVKClient>();
			List<int> list2 = new List<int>();
			bool flag = false;
			for (;;)
			{
				flag = false;
				VKClient vkclient = null;
				try
				{
					int num5 = 0;
					while (!this.stopAllThreads)
					{
						if (this.trndWall.Checked)
						{
							if (list.Count > 0)
							{
								vkclient = list[num5];
								num5 = (num5 + 1) % list.Count;
								list2.Clear();
								if (this.trndWallLuch.Checked)
								{
									list2.Add(1);
								}
								if (this.trndWallGraffiti.Checked && num3 > 0)
								{
									list2.Add(2);
								}
								if (this.trndWallAudio.Checked && num > 0)
								{
									list2.Add(3);
								}
								if (this.trndWallVideo.Checked && num2 > 0)
								{
									list2.Add(4);
								}
								if (list2.Count > 0)
								{
									int index = AttackControl.rnd.Next(0, list2.Count);
									try
									{
										switch (list2[index])
										{
										case 1:
											vkclient.PostWallMessage(id, AttackControl.ggen.Generate(Configurations.Wall.MessageLength, gsomFormats));
											break;
										case 2:
											vkclient.PostWallGraffiti(id, Files.GetFile(Configurations.Wall.Graffities[AttackControl.rnd.Next(0, num3)]));
											break;
										case 3:
											vkclient.PostWallMessage(id, Configurations.Wall.Audio[AttackControl.rnd.Next(0, num)]);
											break;
										case 4:
											vkclient.PostWallMessage(id, Configurations.Wall.Videos[AttackControl.rnd.Next(0, num2)]);
											break;
										}
										this.wallmsgCount++;
									}
									catch (CaptchaIgnoredException)
									{
									}
								}
								Thread.Sleep(num4 / list.Count);
							}
							else
							{
								Thread.Sleep(1000);
							}
							while (queue.Count > 0)
							{
								if ((DateTime.Now - queue.Peek().ExcludeTime).TotalSeconds < (double)this.ExcludePauseInterval)
								{
									break;
								}
								VKClient @base = queue.Dequeue().Base;
								list.Add(@base);
								this.LogWrite("Стена> Аккаунт {0} восстановлен.", new object[]
								{
									@base.Account.Name
								});
							}
						}
						else
						{
							Thread.Sleep(1000);
						}
					}
				}
				catch (BlankErrorException ex)
				{
					this.LogWriteError("Стена({0})> {1}", new object[]
					{
						vkclient.Account.Name,
						ex.Message
					});
					int code = ex.Code;
					if (code != 0)
					{
						if (code != 3 && code != 9)
						{
							list.Remove(vkclient);
							queue.Enqueue(new AttackControl.ExcudedVKClient(vkclient));
							this.LogWrite("Стена> Аккаунт {0} временно исключен.", new object[]
							{
								vkclient.Account.Name
							});
						}
						else
						{
							list.Remove(vkclient);
							this.LogWrite("Стена> Аккаунт {0} исключен.", new object[]
							{
								vkclient.Account.Name
							});
						}
					}
					else
					{
						if (Configurations.General.AutoDelays)
						{
							num4 += 200;
							this.LogWrite("Стена> Времменая задержка повышена на 200мс и составляет {0}мс.", new object[]
							{
								num4
							});
						}
						this.LogWrite("Стена> Попячивание временно приостановлено.", new object[0]);
						DateTime now = DateTime.Now;
						while ((DateTime.Now - now).TotalSeconds < 15.0)
						{
							if (this.stopAllThreads)
							{
								return;
							}
							Thread.Sleep(1000);
						}
						this.LogWrite("Стена> Попячивание возобновлено.", new object[0]);
					}
					flag = true;
				}
				catch (CaptchaCanceledException ex2)
				{
					this.LogWriteError("Стена({0})> Капча отменена.", new object[]
					{
						vkclient.Account.Name,
						ex2.Message
					});
					list.Remove(vkclient);
					queue.Enqueue(new AttackControl.ExcudedVKClient(vkclient));
					this.LogWrite("Стена> Аккаунт {0} временно исключен.", new object[]
					{
						vkclient.Account.Name
					});
					flag = true;
				}
				catch (AuthorizationFailedException)
				{
					this.LogWriteError("Стена({0})> Ошибка авторизации.", new object[]
					{
						vkclient.Account.Name
					});
					list.Remove(vkclient);
					this.LogWrite("Стена> Аккаунт {0} исключен.", new object[]
					{
						vkclient.Account.Name
					});
					flag = true;
				}
				catch (WebException ex3)
				{
					this.LogWriteError("Стена({0})> {1}", new object[]
					{
						vkclient.Account.Name,
						ex3.Message
					});
					flag = true;
				}
				if (list.Count == 0 && queue.Count == 0)
				{
					break;
				}
				if (flag)
				{
					Thread.Sleep(num4);
				}
				if (!flag)
				{
					goto Block_8;
				}
			}
			this.LogWriteError("Стена> Все аккаунты исключены, попячивание остановлено.", new object[0]);
			return;
			Block_8:
			if (this.trndWall.Checked)
			{
				this.LogWriteInfo("Стена> Попячивание остановлено.", new object[0]);
			}
		}

		private void CreateNewTopics()
		{
			int num = this.aimId;
			if (num > 0)
			{
				return;
			}
			GsomFormats gsomFormats = GsomFormats.Default;
			if (Configurations.General.AddExtraLines)
			{
				gsomFormats |= GsomFormats.InsertExtraLines;
			}
			if (Configurations.General.AddAsciiImages)
			{
				gsomFormats |= GsomFormats.UseMultiLineMessages;
			}
			if (Configurations.General.RandomCase)
			{
				gsomFormats |= GsomFormats.RandomCase;
			}
			int num2 = Configurations.Topics.CreationTimeDelay;
			List<VKClient> list = new List<VKClient>(this.Clients);
			Queue<AttackControl.ExcudedVKClient> queue = new Queue<AttackControl.ExcudedVKClient>();
			bool flag = false;
			for (;;)
			{
				flag = false;
				VKClient vkclient = null;
				try
				{
					int num3 = 0;
					while (!this.stopAllThreads)
					{
						if (this.trndTopics.Checked && this.trndTopicsNew.Checked)
						{
							if (list.Count > 0)
							{
								vkclient = list[num3];
								num3 = (num3 + 1) % list.Count;
								try
								{
									vkclient.CreateTopic(num, AttackControl.InsertKey(AttackControl.ggen.Generate(Configurations.Topics.TitleLength, gsomFormats ^ GsomFormats.InsertExtraLines ^ GsomFormats.UseMultiLineMessages), vkclient.Account.ID), AttackControl.ggen.Generate(Configurations.Topics.PostLength, gsomFormats));
									this.topicsCount++;
								}
								catch (CaptchaIgnoredException)
								{
								}
								Thread.Sleep(num2 / list.Count);
							}
							else
							{
								Thread.Sleep(1000);
							}
							while (queue.Count > 0)
							{
								if ((DateTime.Now - queue.Peek().ExcludeTime).TotalSeconds < (double)this.ExcludePauseInterval)
								{
									break;
								}
								VKClient @base = queue.Dequeue().Base;
								list.Add(@base);
								this.LogWrite("Обсуждения-создание> Аккаунт {0} восстановлен.", new object[]
								{
									@base.Account.Name
								});
							}
						}
						else
						{
							Thread.Sleep(1000);
						}
					}
				}
				catch (BlankErrorException ex)
				{
					this.LogWriteError("Обсуждения-создание({0})> {1}", new object[]
					{
						vkclient.Account.Name,
						ex.Message
					});
					int code = ex.Code;
					switch (code)
					{
					case -2:
						break;
					case -1:
						goto IL_2BD;
					case 0:
					{
						if (Configurations.General.AutoDelays)
						{
							num2 += 200;
							this.LogWrite("Обсуждения-создание> Времменая задержка повышена на 200мс и составляет {0}мс.", new object[]
							{
								num2
							});
						}
						this.LogWrite("Обсуждения-создание> Попячивание временно приостановлено.", new object[0]);
						DateTime now = DateTime.Now;
						while ((DateTime.Now - now).TotalSeconds < 15.0)
						{
							if (this.stopAllThreads)
							{
								return;
							}
							Thread.Sleep(1000);
						}
						this.LogWrite("Обсуждения-создание> Попячивание возобновлено.", new object[0]);
						goto IL_2F9;
					}
					default:
						if (code != 9)
						{
							goto IL_2BD;
						}
						break;
					}
					list.Remove(vkclient);
					this.LogWrite("Обсуждения-создание> Аккаунт {0} исключен.", new object[]
					{
						vkclient.Account.Name
					});
					goto IL_2F9;
					IL_2BD:
					list.Remove(vkclient);
					queue.Enqueue(new AttackControl.ExcudedVKClient(vkclient));
					this.LogWrite("Обсуждения-создание> Аккаунт {0} временно исключен.", new object[]
					{
						vkclient.Account.Name
					});
					IL_2F9:
					flag = true;
				}
				catch (CaptchaCanceledException ex2)
				{
					this.LogWriteError("Обсуждения-создание({0})> Капча отменена.", new object[]
					{
						vkclient.Account.Name,
						ex2.Message
					});
					list.Remove(vkclient);
					queue.Enqueue(new AttackControl.ExcudedVKClient(vkclient));
					this.LogWrite("Обсуждения-создание> Аккаунт {0} временно исключен.", new object[]
					{
						vkclient.Account.Name
					});
					flag = true;
				}
				catch (AuthorizationFailedException)
				{
					this.LogWriteError("Обсуждения-создание({0})> Ошибка авторизации.", new object[]
					{
						vkclient.Account.Name
					});
					list.Remove(vkclient);
					this.LogWrite("Обсуждения-создание> Аккаунт {0} исключен.", new object[]
					{
						vkclient.Account.Name
					});
					flag = true;
				}
				catch (WebException ex3)
				{
					this.LogWriteError("Обсуждения-создание({0})> {1}", new object[]
					{
						vkclient.Account.Name,
						ex3.Message
					});
					flag = true;
				}
				if (list.Count == 0 && queue.Count == 0)
				{
					break;
				}
				if (flag)
				{
					Thread.Sleep(num2);
				}
				if (!flag)
				{
					goto Block_9;
				}
			}
			this.LogWriteError("Обсуждения-создание> Все аккаунты исключены, попячивание остановлено.", new object[0]);
			return;
			Block_9:
			if (this.trndTopics.Checked && this.trndTopicsNew.Checked)
			{
				this.LogWriteInfo("Обсуждения-создание> Попячивание остановлено.", new object[0]);
			}
		}

		private void PostTopicsAnswers()
		{
			int num = this.aimId;
			if (num > 0)
			{
				return;
			}
			if (this.Topics == null || this.Topics.Length == 0)
			{
				return;
			}
			GsomFormats gsomFormats = GsomFormats.Default;
			if (Configurations.General.AddExtraLines)
			{
				gsomFormats |= GsomFormats.InsertExtraLines;
			}
			if (Configurations.General.AddAsciiImages)
			{
				gsomFormats |= GsomFormats.UseMultiLineMessages;
			}
			if (Configurations.General.RandomCase)
			{
				gsomFormats |= GsomFormats.RandomCase;
			}
			int num2 = Configurations.Topics.AnswerTimeDelay;
			List<VKClient> list = new List<VKClient>(this.Clients);
			Queue<AttackControl.ExcudedVKClient> queue = new Queue<AttackControl.ExcudedVKClient>();
			int num3 = 0;
			if (Configurations.Topics.RandomAnswerStart)
			{
				num3 = AttackControl.rnd.Next(0, this.Topics.Length);
			}
			int num4 = -1;
			VKClient vkclient = null;
			bool flag = false;
			for (;;)
			{
				flag = false;
				try
				{
					while (!this.stopAllThreads)
					{
						if (this.trndTopics.Checked && this.trndTopicsExist.Checked)
						{
							if (list.Count > 0)
							{
								num4 = (num4 + 1) % list.Count;
								vkclient = list[num4];
								try
								{
									if (vkclient.PostTopicAnswer(this.Topics[num3], AttackControl.ggen.Generate(Configurations.Topics.AnswerLength, gsomFormats)))
									{
										this.topicsAnswersCount++;
									}
								}
								catch (CaptchaIgnoredException)
								{
								}
								if (this.topicsAnswersCount % 20 == 0)
								{
									num3 = (num3 + 1) % this.Topics.Length;
								}
								Thread.Sleep(num2 / list.Count);
							}
							else
							{
								Thread.Sleep(1000);
							}
							while (queue.Count > 0)
							{
								if ((DateTime.Now - queue.Peek().ExcludeTime).TotalSeconds < (double)this.ExcludePauseInterval)
								{
									break;
								}
								VKClient @base = queue.Dequeue().Base;
								list.Add(@base);
								this.LogWrite("Обсуждения-ответы> Аккаунт {0} восстановлен.", new object[]
								{
									@base.Account.Name
								});
							}
						}
						else
						{
							Thread.Sleep(1000);
						}
					}
				}
				catch (BlankErrorException ex)
				{
					this.LogWriteError("Обсуждения-ответы({0})> {1}", new object[]
					{
						vkclient.Account.Name,
						ex.Message
					});
					int code = ex.Code;
					if (code != 0)
					{
						if (code != 9)
						{
							list.Remove(vkclient);
							queue.Enqueue(new AttackControl.ExcudedVKClient(vkclient));
							this.LogWrite("Обсуждения-ответы> Аккаунт {0} временно исключен.", new object[]
							{
								vkclient.Account.Name
							});
						}
						else
						{
							list.Remove(vkclient);
							this.LogWrite("Обсуждения-ответы> Аккаунт {0} исключен.", new object[]
							{
								vkclient.Account.Name
							});
						}
					}
					else if (Configurations.General.AutoDelays)
					{
						num2 += 200;
						this.LogWrite("Обсуждения-ответы> Времменая задержка повышена на 200мс и составляет {0}мс.", new object[]
						{
							num2
						});
					}
					else
					{
						Thread.Sleep(1000);
					}
					flag = true;
				}
				catch (CaptchaCanceledException ex2)
				{
					this.LogWriteError("Обсуждения-ответы({0})> Капча отменена.", new object[]
					{
						vkclient.Account.Name,
						ex2.Message
					});
					list.Remove(vkclient);
					queue.Enqueue(new AttackControl.ExcudedVKClient(vkclient));
					this.LogWrite("Обсуждения-ответы> Аккаунт {0} временно исключен.", new object[]
					{
						vkclient.Account.Name
					});
					flag = true;
				}
				catch (AuthorizationFailedException)
				{
					this.LogWriteError("Обсуждения-ответы({0})> Ошибка авторизации.", new object[]
					{
						vkclient.Account.Name
					});
					list.Remove(vkclient);
					this.LogWrite("Обсуждения-ответы> Аккаунт {0} исключен.", new object[]
					{
						vkclient.Account.Name
					});
					flag = true;
				}
				catch (WebException ex3)
				{
					this.LogWriteError("Обсуждения-ответы({0})> {1}", new object[]
					{
						vkclient.Account.Name,
						ex3.Message
					});
					flag = true;
				}
				if (list.Count == 0 && queue.Count == 0)
				{
					break;
				}
				if (flag)
				{
					Thread.Sleep(num2);
				}
				if (!flag)
				{
					goto Block_11;
				}
			}
			this.LogWriteError("Обсуждения-ответы> Все аккаунты исключены, попячивание остановлено.", new object[0]);
			return;
			Block_11:
			if (this.trndTopics.Checked && this.trndTopicsExist.Checked)
			{
				this.LogWriteInfo("Обсуждения-ответы> Попячивание остановлено.", new object[0]);
			}
		}

		private void CreateAlbums()
		{
			int num = this.aimId;
			if (num > 0)
			{
				return;
			}
			int num2 = Configurations.Albums.Photos.Length;
			int timeDelay = Configurations.Wall.TimeDelay;
			List<VKClient> list = new List<VKClient>(this.Clients);
			Queue<AttackControl.ExcudedVKClient> queue = new Queue<AttackControl.ExcudedVKClient>();
			GsomFormats gsomFormats = GsomFormats.Default;
			if (Configurations.General.RandomCase)
			{
				gsomFormats |= GsomFormats.RandomCase;
			}
			if (Configurations.General.AddExtraLines)
			{
				gsomFormats |= GsomFormats.InsertExtraLines;
			}
			if (Configurations.General.AddAsciiImages)
			{
				gsomFormats |= GsomFormats.UseMultiLineMessages;
			}
			bool flag = false;
			for (;;)
			{
				flag = false;
				VKClient vkclient = null;
				try
				{
					int num3 = 0;
					while (!this.stopAllThreads)
					{
						if (this.trndAlbums.Checked && this.trndAlbumsNew.Checked)
						{
							if (list.Count > 0)
							{
								vkclient = list[num3];
								num3 = (num3 + 1) % list.Count;
								AlbumInfo album = vkclient.CreateAlbum(num, AttackControl.ggen.Phrases[AttackControl.rnd.Next(0, AttackControl.ggen.Phrases.Count)], AttackControl.InsertKey(AttackControl.ggen.Generate(Configurations.Albums.DescriptionLength, gsomFormats), DateTime.UtcNow.Date.GetHashCode()));
								try
								{
									if (num2 > 0)
									{
										vkclient.UploadPhotos(album, new List<byte[]>
										{
											Files.GetFile(Configurations.Albums.Photos[AttackControl.rnd.Next(0, num2)])
										}, true);
									}
								}
								catch (CaptchaCanceledException)
								{
									this.LogWriteError("Альбомы-создание({0})> Капча отменена, фото не добавлено в новый альбом.", new object[]
									{
										vkclient.Account.Name
									});
								}
								catch (CaptchaIgnoredException)
								{
									this.LogWriteError("Альбомы-создание({0})> Капча игнорирована, фото не добавлено в новый альбом.", new object[]
									{
										vkclient.Account.Name
									});
								}
								this.albumsCount++;
								Thread.Sleep(timeDelay / list.Count);
							}
							else
							{
								Thread.Sleep(1000);
							}
							while (queue.Count > 0)
							{
								if ((DateTime.Now - queue.Peek().ExcludeTime).TotalSeconds < (double)this.ExcludePauseInterval)
								{
									break;
								}
								VKClient @base = queue.Dequeue().Base;
								list.Add(@base);
								this.LogWrite("Альбомы-создание> Аккаунт {0} восстановлен.", new object[]
								{
									@base.Account.Name
								});
							}
						}
						else
						{
							Thread.Sleep(1000);
						}
					}
				}
				catch (BlankErrorException ex)
				{
					this.LogWriteError("Альбомы-создание({0})> {1}", new object[]
					{
						vkclient.Account.Name,
						ex.Message
					});
					int code = ex.Code;
					switch (code)
					{
					case -2:
						break;
					case -1:
						goto IL_351;
					case 0:
					{
						this.LogWrite("Альбомы-создание> Попячивание временно приостановлено.", new object[0]);
						DateTime now = DateTime.Now;
						while ((DateTime.Now - now).TotalSeconds < 1800.0)
						{
							if (this.stopAllThreads)
							{
								return;
							}
							Thread.Sleep(1000);
						}
						this.LogWrite("Альбомы-создание> Попячивание возобновлено.", new object[0]);
						goto IL_38D;
					}
					default:
						if (code != 9 && code != 1602)
						{
							goto IL_351;
						}
						break;
					}
					list.Remove(vkclient);
					this.LogWrite("Альбомы-создание> Аккаунт {0} исключен.", new object[]
					{
						vkclient.Account.Name
					});
					goto IL_38D;
					IL_351:
					list.Remove(vkclient);
					queue.Enqueue(new AttackControl.ExcudedVKClient(vkclient));
					this.LogWrite("Альбомы-создание> Аккаунт {0} временно исключен.", new object[]
					{
						vkclient.Account.Name
					});
					IL_38D:
					flag = true;
				}
				catch (AuthorizationFailedException)
				{
					this.LogWriteError("Альбомы-создание({0})> Ошибка авторизации.", new object[]
					{
						vkclient.Account.Name
					});
					list.Remove(vkclient);
					this.LogWrite("Альбомы-создание> Аккаунт {0} исключен.", new object[]
					{
						vkclient.Account.Name
					});
					flag = true;
				}
				catch (WebException ex2)
				{
					this.LogWriteError("Альбомы-создание({0})> {1}", new object[]
					{
						vkclient.Account.Name,
						ex2.Message
					});
					flag = true;
				}
				if (list.Count == 0 && queue.Count == 0)
				{
					break;
				}
				if (flag)
				{
					Thread.Sleep(timeDelay);
				}
				if (!flag)
				{
					goto Block_9;
				}
			}
			this.LogWriteError("Альбомы-создание> Все аккаунты исключены, попячивание остановлено.", new object[0]);
			return;
			Block_9:
			if (this.trndAlbums.Checked && this.trndAlbumsNew.Checked)
			{
				this.LogWriteInfo("Альбомы-создание> Попячивание остановлено", new object[0]);
			}
		}

		private void PhotosUpload()
		{
			int num = this.aimId;
			if (num > 0)
			{
				return;
			}
			if (this.Albums == null || this.Albums.Length == 0)
			{
				return;
			}
			int num2 = Configurations.Albums.Photos.Length;
			if (num2 == 0)
			{
				return;
			}
			int photosUploadTimeDelay = Configurations.Albums.PhotosUploadTimeDelay;
			List<VKClient> list = new List<VKClient>(this.Clients);
			AlbumInfo album = this.Albums[0];
			int num3 = 0;
			int num4 = 0;
			while (num3 < this.Albums.Length && !this.stopAllThreads)
			{
				if (!this.trndAlbums.Checked || !this.trndAlbumsExist.Checked)
				{
					goto IL_25C;
				}
				VKClient vkclient = list[num4];
				album = this.Albums[num3];
				if (album.PhotosCount < 500)
				{
					try
					{
						List<byte[]> list2 = new List<byte[]>();
						while (list2.Count < 3)
						{
							list2.Add(Files.GetFile(Configurations.Albums.Photos[AttackControl.rnd.Next(0, num2)]));
						}
						FileSaveInfo sv_info = vkclient.UploadPhotos(album, list2, true);
						this.photosCount += 3;
						while (!this.stopAllThreads)
						{
							if (this.trndAlbums.Checked && this.trndAlbumsExist.Checked)
							{
								if (Configurations.Albums.PhotosAlwaysUpload)
								{
									vkclient.UploadPhotos(album, list2, true);
								}
								else
								{
									VKClient.SavePhoto(sv_info);
								}
								this.photosCount += 3;
								Thread.Sleep(photosUploadTimeDelay);
							}
							else
							{
								Thread.Sleep(1000);
							}
						}
						goto IL_266;
					}
					catch (BlankErrorException ex)
					{
						if (ex.Code == 21)
						{
							album.PhotosCount = 501;
							this.LogWrite("Альбомы-загрузка> \"{0}\" заполнен.", new object[]
							{
								album.Name
							});
							num3++;
						}
						else
						{
							this.LogWriteError("Альбомы-загрузка({0})> \"{1}\" - {2}.", new object[]
							{
								vkclient.Account.Name,
								album.Name,
								ex.Message
							});
						}
						goto IL_266;
					}
					catch (WebException ex2)
					{
						this.LogWriteError("Альбомы-загрузка({0})> \"{1}\" - {2}.", new object[]
						{
							vkclient.Account.Name,
							album.Name,
							ex2.Message
						});
						goto IL_266;
					}
					catch (CaptchaCanceledException)
					{
						this.LogWriteError("Альбомы-загрузка({0})> \"{1}\" - Игнорирована капча.", new object[]
						{
							vkclient.Account.Name,
							album.Name
						});
						goto IL_266;
					}
					catch (CaptchaIgnoredException)
					{
						goto IL_266;
					}
					goto IL_25C;
				}
				IL_266:
				num4 = (num4 + 1) % list.Count;
				continue;
				IL_25C:
				Thread.Sleep(1000);
				goto IL_266;
			}
			if (this.trndAlbums.Checked && this.trndAlbumsExist.Checked)
			{
				this.LogWriteInfo("Альбомы-загрузка> Попячивание остановлено", new object[0]);
			}
		}

		private void AudioUpload()
		{
			int num = this.aimId;
			if (num > 0)
			{
				return;
			}
			int num2 = Configurations.Audio.AudioFiles.Length;
			if (num2 == 0)
			{
				return;
			}
			GsomFormats gsomFormats = GsomFormats.Default;
			if (Configurations.General.RandomCase)
			{
				gsomFormats |= GsomFormats.RandomCase;
			}
			int num3 = Configurations.Audio.TimeDelay;
			List<VKClient> list = new List<VKClient>(this.Clients);
			Queue<AttackControl.ExcudedVKClient> queue = new Queue<AttackControl.ExcudedVKClient>();
			bool flag = false;
			for (;;)
			{
				flag = false;
				VKClient vkclient = null;
				try
				{
					int num4 = 0;
					while (!this.stopAllThreads)
					{
						if (this.trndAudio.Checked)
						{
							if (list.Count > 0)
							{
								vkclient = list[num4];
								num4 = (num4 + 1) % list.Count;
								try
								{
									if (this.trndAudioLuch.Checked)
									{
										vkclient.UploadAudio(num, Files.GetFile(Configurations.Audio.AudioFiles[AttackControl.rnd.Next(0, num2)]), true, AttackControl.ggen.Generate(Configurations.Audio.PerformerLength, gsomFormats), AttackControl.ggen.Generate(Configurations.Audio.TitleLength, gsomFormats));
									}
									else
									{
										vkclient.UploadAudio(num, Files.GetFile(Configurations.Audio.AudioFiles[AttackControl.rnd.Next(0, num2)]), true);
									}
									this.audiosCount++;
								}
								catch (CaptchaIgnoredException)
								{
								}
								Thread.Sleep(num3 / list.Count);
							}
							else
							{
								Thread.Sleep(1000);
							}
							while (queue.Count > 0)
							{
								if ((DateTime.Now - queue.Peek().ExcludeTime).TotalSeconds < (double)this.ExcludePauseInterval)
								{
									break;
								}
								VKClient @base = queue.Dequeue().Base;
								list.Add(@base);
								this.LogWrite("Аудио> Аккаунт {0} восстановлен.", new object[]
								{
									@base.Account.Name
								});
							}
						}
						else
						{
							Thread.Sleep(1000);
						}
					}
				}
				catch (BlankErrorException ex)
				{
					this.LogWriteError("Аудио({0})> {1}", new object[]
					{
						vkclient.Account.Name,
						ex.Message
					});
					int code = ex.Code;
					if (code != 0)
					{
						if (code != 9)
						{
							switch (code)
							{
							case 1805:
							case 1807:
								goto IL_2B5;
							}
							list.Remove(vkclient);
							queue.Enqueue(new AttackControl.ExcudedVKClient(vkclient));
							this.LogWrite("Аудио> Аккаунт {0} временно исключен.", new object[]
							{
								vkclient.Account.Name
							});
							goto IL_323;
						}
						IL_2B5:
						list.Remove(vkclient);
						this.LogWrite("Аудио> Аккаунт {0} исключен.", new object[]
						{
							vkclient.Account.Name
						});
					}
					else
					{
						if (Configurations.General.AutoDelays)
						{
							num3 += 200;
							this.LogWrite("Аудио> Времменая задержка повышена на 200мс и составляет {0}мс.", new object[]
							{
								num3
							});
						}
						this.LogWrite("Аудио> Попячивание временно приостановлено.", new object[0]);
						DateTime now = DateTime.Now;
						while ((DateTime.Now - now).TotalSeconds < 15.0)
						{
							if (this.stopAllThreads)
							{
								return;
							}
							Thread.Sleep(1000);
						}
						this.LogWrite("Аудио> Попячивание возобновлено.", new object[0]);
					}
					IL_323:
					flag = true;
				}
				catch (CaptchaCanceledException ex2)
				{
					this.LogWriteError("Аудио({0})> Капча отменена.", new object[]
					{
						vkclient.Account.Name,
						ex2.Message
					});
					list.Remove(vkclient);
					queue.Enqueue(new AttackControl.ExcudedVKClient(vkclient));
					this.LogWrite("Аудио> Аккаунт {0} временно исключен.", new object[]
					{
						vkclient.Account.Name
					});
					flag = true;
				}
				catch (AuthorizationFailedException)
				{
					this.LogWriteError("Аудио({0})> Ошибка авторизации.", new object[]
					{
						vkclient.Account.Name
					});
					list.Remove(vkclient);
					this.LogWrite("Аудио> Аккаунт {0} исключен.", new object[]
					{
						vkclient.Account.Name
					});
					flag = true;
				}
				catch (WebException ex3)
				{
					this.LogWriteError("Аудио({0})> {1}", new object[]
					{
						vkclient.Account.Name,
						ex3.Message
					});
					flag = true;
				}
				if (list.Count == 0 && queue.Count == 0)
				{
					break;
				}
				if (flag)
				{
					Thread.Sleep(num3);
				}
				if (!flag)
				{
					goto Block_8;
				}
			}
			this.LogWriteError("Аудио> Все аккаунты исключены, попячивание остановлено.", new object[0]);
			return;
			Block_8:
			if (this.trndAudio.Checked)
			{
				this.LogWriteInfo("Аудио> Попячивание остановлено.", new object[0]);
			}
		}

		private void VideosAdd()
		{
			int num = this.aimId;
			if (num > 0)
			{
				return;
			}
			int num2 = Configurations.Video.Videos.Length;
			if (num2 == 0)
			{
				return;
			}
			int num3 = Configurations.Video.AddTimeDelay;
			List<VKClient> list = new List<VKClient>(this.Clients);
			Queue<AttackControl.ExcudedVKClient> queue = new Queue<AttackControl.ExcudedVKClient>();
			int num4 = -1;
			VKClient vkclient = null;
			bool flag = false;
			for (;;)
			{
				flag = false;
				try
				{
					while (!this.stopAllThreads)
					{
						if (this.trndVideo.Checked && this.trndVideoNew.Checked)
						{
							if (list.Count > 0)
							{
								num4 = (num4 + 1) % list.Count;
								vkclient = list[num4];
								try
								{
									vkclient.AddVideo(num, Configurations.Video.Videos[AttackControl.rnd.Next(0, num2)], Configurations.Video.UseAjax);
									this.videosCount++;
								}
								catch (CaptchaIgnoredException)
								{
								}
								Thread.Sleep(num3 / list.Count);
							}
							else
							{
								Thread.Sleep(1000);
							}
							while (queue.Count > 0)
							{
								if ((DateTime.Now - queue.Peek().ExcludeTime).TotalSeconds < (double)this.ExcludePauseInterval)
								{
									break;
								}
								VKClient @base = queue.Dequeue().Base;
								list.Add(@base);
								this.LogWrite("Видео-добавление> Аккаунт {0} восстановлен.", new object[]
								{
									@base.Account.Name
								});
							}
						}
						else
						{
							Thread.Sleep(1000);
						}
					}
				}
				catch (BlankErrorException ex)
				{
					this.LogWriteError("Видео-добавление({0})> {1}", new object[]
					{
						vkclient.Account.Name,
						ex.Message
					});
					int code = ex.Code;
					if (code != 0)
					{
						if (code != 9 && code != 1602)
						{
							list.Remove(vkclient);
							queue.Enqueue(new AttackControl.ExcudedVKClient(vkclient));
							this.LogWrite("Видео-добавление> Аккаунт {0} временно исключен.", new object[]
							{
								vkclient.Account.Name
							});
						}
						else
						{
							list.Remove(vkclient);
							this.LogWrite("Видео-добавление> Аккаунт {0} исключен.", new object[]
							{
								vkclient.Account.Name
							});
						}
					}
					else if (Configurations.General.AutoDelays)
					{
						num3 += 200;
						this.LogWrite("Видео-добавление> Времменая задержка повышена на 200мс и составляет {0}мс.", new object[]
						{
							num3
						});
					}
					flag = true;
				}
				catch (CaptchaCanceledException ex2)
				{
					this.LogWriteError("Видео-добавление({0})> Капча отменена.", new object[]
					{
						vkclient.Account.Name,
						ex2.Message
					});
					list.Remove(vkclient);
					queue.Enqueue(new AttackControl.ExcudedVKClient(vkclient));
					this.LogWrite("Видео-добавление> Аккаунт {0} временно исключен.", new object[]
					{
						vkclient.Account.Name
					});
					flag = true;
				}
				catch (AuthorizationFailedException)
				{
					this.LogWriteError("Видео-добавление({0})> Ошибка авторизации.", new object[]
					{
						vkclient.Account.Name
					});
					list.Remove(vkclient);
					this.LogWrite("Видео-добавление> Аккаунт {0} исключен.", new object[]
					{
						vkclient.Account.Name
					});
					flag = true;
				}
				catch (WebException ex3)
				{
					this.LogWriteError("Видео-добавление({0})> {1}", new object[]
					{
						vkclient.Account.Name,
						ex3.Message
					});
					flag = true;
				}
				if (list.Count == 0 && queue.Count == 0)
				{
					break;
				}
				if (flag)
				{
					Thread.Sleep(num3);
				}
				if (!flag)
				{
					goto Block_7;
				}
			}
			this.LogWriteError("Видео-добавление> Все аккаунты исключены, попячивание остановлено.", new object[0]);
			return;
			Block_7:
			if (this.trndVideo.Checked && this.trndVideoNew.Checked)
			{
				this.LogWriteInfo("Видео-добавление> Попячивание остановлено.", new object[0]);
			}
		}

		private void CommentVideos()
		{
			int num = this.aimId;
			if (num > 0)
			{
				return;
			}
			if (this.Videos == null || this.Videos.Length == 0)
			{
				return;
			}
			GsomFormats gsomFormats = GsomFormats.Default;
			if (Configurations.General.AddExtraLines)
			{
				gsomFormats |= GsomFormats.InsertExtraLines;
			}
			if (Configurations.General.AddAsciiImages)
			{
				gsomFormats |= GsomFormats.UseMultiLineMessages;
			}
			if (Configurations.General.RandomCase)
			{
				gsomFormats |= GsomFormats.RandomCase;
			}
			int num2 = Configurations.Video.CommentTimeDelay;
			List<VKClient> list = new List<VKClient>(this.Clients);
			Queue<AttackControl.ExcudedVKClient> queue = new Queue<AttackControl.ExcudedVKClient>();
			int num3 = 0;
			if (Configurations.Video.RandomCommentStart)
			{
				num3 = AttackControl.rnd.Next(0, this.Videos.Length);
			}
			int num4 = -1;
			VKClient vkclient = null;
			bool flag = false;
			for (;;)
			{
				flag = false;
				try
				{
					while (!this.stopAllThreads)
					{
						if (this.trndVideo.Checked && this.trndVideoExist.Checked)
						{
							if (list.Count > 0)
							{
								num4 = (num4 + 1) % list.Count;
								vkclient = list[num4];
								try
								{
									if (vkclient.PostVideoComment(this.Videos[num3], AttackControl.ggen.Generate(Configurations.Topics.AnswerLength, gsomFormats)))
									{
										this.videosCommentsCount++;
									}
								}
								catch (CaptchaIgnoredException)
								{
								}
								if (this.videosCommentsCount % 20 == 0)
								{
									num3 = (num3 + 1) % this.Videos.Length;
								}
								Thread.Sleep(num2 / list.Count);
							}
							else
							{
								Thread.Sleep(1000);
							}
							while (queue.Count > 0)
							{
								if ((DateTime.Now - queue.Peek().ExcludeTime).TotalSeconds < (double)this.ExcludePauseInterval)
								{
									break;
								}
								VKClient @base = queue.Dequeue().Base;
								list.Add(@base);
								this.LogWrite("Видео-комментарии> Аккаунт {0} восстановлен.", new object[]
								{
									@base.Account.Name
								});
							}
						}
						else
						{
							Thread.Sleep(1000);
						}
					}
				}
				catch (BlankErrorException ex)
				{
					this.LogWriteError("Видео-комментарии({0})> {1}", new object[]
					{
						vkclient.Account.Name,
						ex.Message
					});
					int code = ex.Code;
					if (code != 0)
					{
						if (code != 9)
						{
							list.Remove(vkclient);
							queue.Enqueue(new AttackControl.ExcudedVKClient(vkclient));
							this.LogWrite("Видео-комментарии> Аккаунт {0} временно исключен.", new object[]
							{
								vkclient.Account.Name
							});
						}
						else
						{
							list.Remove(vkclient);
							this.LogWrite("Видео-комментарии> Аккаунт {0} исключен.", new object[]
							{
								vkclient.Account.Name
							});
						}
					}
					else if (Configurations.General.AutoDelays)
					{
						num2 += 200;
						this.LogWrite("Видео-комментарии> Времменая задержка повышена на 200мс и составляет {0}мс.", new object[]
						{
							num2
						});
					}
					else
					{
						Thread.Sleep(1000);
					}
					flag = true;
				}
				catch (CaptchaCanceledException ex2)
				{
					this.LogWriteError("Видео-комментарии({0})> Капча отменена.", new object[]
					{
						vkclient.Account.Name,
						ex2.Message
					});
					list.Remove(vkclient);
					queue.Enqueue(new AttackControl.ExcudedVKClient(vkclient));
					this.LogWrite("Видео-комментарии> Аккаунт {0} временно исключен.", new object[]
					{
						vkclient.Account.Name
					});
					flag = true;
				}
				catch (AuthorizationFailedException)
				{
					this.LogWriteError("Видео-комментарии({0})> Ошибка авторизации.", new object[]
					{
						vkclient.Account.Name
					});
					list.Remove(vkclient);
					this.LogWrite("Видео-комментарии> Аккаунт {0} исключен.", new object[]
					{
						vkclient.Account.Name
					});
					flag = true;
				}
				catch (WebException ex3)
				{
					HttpWebResponse httpWebResponse = ex3.Response as HttpWebResponse;
					this.LogWriteError("Видео-комментарии({0})> {1}", new object[]
					{
						vkclient.Account.Name,
						ex3.Message
					});
					if (ex3.Status == WebExceptionStatus.ProtocolError && httpWebResponse.StatusCode == HttpStatusCode.BadRequest && Configurations.General.AutoDelays)
					{
						num2 += 200;
						this.LogWrite("Видео-комментарии> Времменая задержка повышена на 200мс и составляет {0}мс.", new object[]
						{
							num2
						});
					}
					else
					{
						Thread.Sleep(1000);
					}
					flag = true;
				}
				if (list.Count == 0 && queue.Count == 0)
				{
					break;
				}
				if (flag)
				{
					Thread.Sleep(num2);
				}
				if (!flag)
				{
					goto Block_11;
				}
			}
			this.LogWriteError("Видео-комментарии> Все аккаунты исключены, попячивание остановлено.", new object[0]);
			return;
			Block_11:
			if (this.trndVideo.Checked && this.trndVideoExist.Checked)
			{
				this.LogWriteInfo("Видео-комментарии> Попячивание остановлено.", new object[0]);
			}
		}

		public static string InsertKey(string s, int key)
		{
			int num = AttackControl.rnd.Next(2, 9);
			string text = key.ToString();
			s = s.Replace("\r", "");
			int i = 0;
			int num2 = 0;
			while (i < text.Length)
			{
				int num3 = (int)(text[i] - '0');
				if (s.Length < num2)
				{
					s = s.PadRight(num2);
				}
				s = s.Insert(num2, char.ConvertFromUtf32(num3 + 97));
				i++;
				num2 += num;
			}
			s = s.Insert(0, char.ConvertFromUtf32(num + 97));
			s = s.Replace("\n", "\r\n");
			return s;
		}

		public static bool ContainsKey(string s, int key)
		{
			s = s.Replace("\r\n", "\n");
			if (s.Length == 0)
			{
				return false;
			}
			string text = key.ToString();
			int num = (int)(s[0] - 'a');
			if (2 > num || num > 9)
			{
				return false;
			}
			int i = 0;
			int num2 = 1;
			while (i < text.Length)
			{
				if (s.Length <= num2)
				{
					return false;
				}
				int num3 = (int)(text[i] - '0');
				int num4 = (int)(s[num2] - 'a');
				if (num3 != num4)
				{
					return false;
				}
				i++;
				num2 += num;
			}
			return true;
		}

		protected override void OnClosing(CancelEventArgs e)
		{
			this.btnStop_Click(null, null);
			base.OnClosing(e);
			GC.Collect();
		}

		private const int InactiveThreadTimeInterval = 1000;

		private IContainer components;

		private TreeView trConfigs;

		private SplitContainer spltcon;

		private TableLayoutPanel tlpCommands;

		private Button btnGsom;

		private Button btnStop;

		private TreeNode trndWallLuch;

		private TreeNode trndWallGraffiti;

		private TreeNode trndWallAudio;

		private TreeNode trndWallVideo;

		private TreeNode trndWall;

		private TreeNode trndTopicsExist;

		private TreeNode trndTopicsNew;

		private TreeNode trndTopics;

		private TreeNode trndAlbumsExist;

		private TreeNode trndAlbumsNew;

		private TreeNode trndAlbums;

		private TreeNode trndAudioLuch;

		private TreeNode trndAudio;

		private TreeNode trndVideoExist;

		private TreeNode trndVideoNew;

		private TreeNode trndVideo;

		private RichTextBox txtLog;

		private CheckBox chkLogAutoScroll;

		private List<VKClient> Clients;

		private AlbumInfo[] Albums;

		private TopicInfo[] Topics;

		private VideoInfo[] Videos;

		private static Random rnd = new Random();

		private static Gsom ggen = new Gsom(Configurations.General.Library, Encoding.Default);

		private string aimName;

		private volatile int aimId;

		private volatile int wallmsgCount;

		private volatile int topicsCount;

		private volatile int topicsAnswersCount;

		private volatile int albumsCount;

		private volatile int photosCount;

		private volatile int audiosCount;

		private volatile int videosCount;

		private volatile int videosCommentsCount;

		private Thread thrPrep;

		private AttackControl.LogWriteCallBack dLogWrite;

		private volatile int ExcludePauseInterval;

		private volatile bool stopAllThreads;

		private Thread[] threads;

		private delegate void Proc();

		private delegate void LogWriteCallBack(string msg, Color color, params object[] p);

		private struct ExcudedVKClient
		{
			public ExcudedVKClient(VKClient client)
			{
				this.Base = client;
				this.ExcludeTime = DateTime.Now;
			}

			public VKClient Base;

			public DateTime ExcludeTime;
		}
	}
}
