Advertisement
Emalton

Atilla's EESpender - Modified

Apr 10th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.63 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using PlayerIOClient;
  7. using System.Threading;
  8.  
  9. namespace EESpender
  10. {
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.             System.Diagnostics.Process.GetCurrentProcess().PriorityClass = System.Diagnostics.ProcessPriorityClass.BelowNormal;
  16.             Log(LogLevel.Notice, "Accounts: " + args.Count() / 2);
  17.             for (int AccountID = 0; args.Count() > AccountID; AccountID += 2)
  18.             {
  19.                 Spend(new Profile() { Email = args[AccountID], Password = args[AccountID + 1] });
  20.             }
  21.         }
  22.         public static void Spend(Profile profile)
  23.         {
  24.             Client client;
  25.             Connection lobby;
  26.             client = PlayerIO.QuickConnect.SimpleConnect("everybody-edits-su9rn58o40itdbnw69plyw", profile.Email, profile.Password, null);
  27.             lobby = client.Multiplayer.CreateJoinRoom(client.ConnectUserId, $"Lobby{client.BigDB.Load("config", "config")["version"]}", true, null, null);
  28.  
  29.             var messages = new List<Message>();
  30.             var required = new List<Message>() { Message.Create("getMySimplePlayerObject"), Message.Create("getLobbyProperties"), Message.Create("getShop") };
  31.             lobby.OnMessage += delegate (object sender, Message e)
  32.             {
  33.                 messages.Add(e);
  34.  
  35.                 switch (e.Type)
  36.                 {
  37.                     case "connectioncomplete":
  38.                         foreach (var m in required)
  39.                         { lobby.Send(m); Thread.Sleep(512); }
  40.                         break;
  41.                     case "getShop":
  42.                         profile.CurrentShop = new Shop(e);
  43.  
  44.                         profile.CurrentShop.PriorityItems = profile.CurrentShop.ShopItems.Where(x => x.OwnedAmount == 0).Where(x => x.Price >= 0)
  45.                             .OrderByDescending(x => x.Price).Reverse().OrderByDescending(x => x.EnergySpent).OrderByDescending(x => x.IsNew).ToList();
  46.  
  47.                         if (profile.CurrentShop.PriorityItems.Count() < 1)
  48.                             profile.CurrentShop.PriorityItems = profile.CurrentShop.ShopItems.Where(x => x.Price >= 0).OrderByDescending(x => x.EnergySpent).ToList();
  49.  
  50.                         var priorityItem = profile.CurrentShop.PriorityItems[0];
  51.                         if (profile.CurrentShop.CurrentEnergy >= priorityItem.EnergyPerClick)
  52.                         {
  53.                             Log(LogLevel.Notice, string.Format("Spending {0} energy on {1}",
  54.                                                 priorityItem.EnergyPerClick * (Math.Floor((double)profile.CurrentShop.CurrentEnergy / priorityItem.EnergyPerClick)),
  55.                                                 priorityItem.SafeName));
  56.  
  57.                             lobby.Send("useAllEnergy", profile.CurrentShop.PriorityItems[0].Name);
  58.                         }
  59.                         break;
  60.                     case "getLobbyProperties":
  61.                         profile.FirstDailyLogin = (bool)e[0];
  62.                         profile.LoginStreak = (int)e[1];
  63.  
  64.                         if (profile.FirstDailyLogin && profile.LoginStreak >= 0)
  65.                         {
  66.                             for (uint i = 2; i < e.Count; i += 2)
  67.                             {
  68.                                 var x = e[i];
  69.                                 var y = e[i + 1];
  70.  
  71.                                 var nextReward = Reward.LoginReward(DateTime.Now, profile.LoginStreak + 1, true);
  72.                                 Log(LogLevel.Notice, $"Login streak! You've gained {y} {x}! Next reward is {nextReward}...");
  73.                             }
  74.                         }
  75.                         break;
  76.                     case "useEnergy":
  77.                     case "useAllEnergy":
  78.                         lobby.Send("getShop");
  79.                         break;
  80.                     case "getMySimplePlayerObject":
  81.                         profile.Username = (string)e[0];
  82.                         break;
  83.                     default:
  84.                         break;
  85.                 }
  86.             };
  87.  
  88.             var watch = new System.Diagnostics.Stopwatch();
  89.             watch.Start();
  90.             while (watch.Elapsed < TimeSpan.FromSeconds(10))
  91.             {
  92.                 try
  93.                 {
  94.                     if (!required.Select(x => x.Type).All(messages.Select(x => x.Type).Contains))
  95.                     {
  96.                         Thread.Sleep(512);
  97.                         continue;
  98.                     }
  99.  
  100.                     Log(LogLevel.Notice, string.Format("({0}) {1} | {2} | {3} ({4})",
  101.                                        DateTime.Now, profile.Username, $"{profile.CurrentShop.CurrentEnergy}/{profile.CurrentShop.MaximumEnergy}",
  102.                                        profile.CurrentShop.PriorityItems[0].SafeName,
  103.                                        $"{profile.CurrentShop.PriorityItems[0].EnergySpent}/{profile.CurrentShop.PriorityItems[0].Price}"));
  104.                     GC.Collect();
  105.                     Thread.Sleep(TimeSpan.FromSeconds(150 * 50) /* 50 energy w/ 2.5 minutes = 1 energy*/);
  106.                     Spend(profile);
  107.                 }
  108.                 catch (Exception ex)
  109.                 {
  110.                     Log(LogLevel.Error, $"Uh oh. {ex.Message} { (string.Format(", ", messages.Select(d => d.Type))) }");
  111.                     Thread.Sleep(512);
  112.                 }
  113.             }
  114.  
  115.             if (lobby.Connected)
  116.                 try { lobby.Disconnect(); } catch { }
  117.  
  118.             Log(LogLevel.Error, "Something went wrong. Reconnecting...");
  119.             Thread.Sleep(1000);
  120.             Spend(profile);
  121.         }
  122.         enum LogLevel { Notice, Warning, Error }
  123.         static void Log(LogLevel l, string message)
  124.         {
  125.             Console.WriteLine($"<EESpender> [{l.ToString().ToUpper()}] {message}");
  126.         }
  127.     }
  128.     class Shop
  129.     {
  130.         public int MaximumEnergy { get; set; }
  131.         public int CurrentEnergy { get; set; }
  132.  
  133.         public List<ShopItem> ShopItems { get; set; }
  134.         public List<ShopItem> PriorityItems { get; set; }
  135.  
  136.         public Shop(Message e)
  137.         {
  138.             MaximumEnergy = (int)e[3];
  139.             CurrentEnergy = (int)e[1];
  140.             ShopItems = new List<ShopItem>();
  141.  
  142.             for (uint i = 5; i < e.Count; i += 25)
  143.             {
  144.                 var name = (string)e[i];
  145.                 var price = (int)e[i + 2];
  146.                 var amount = (int)e[i + 3];
  147.                 var spent = (int)e[i + 4];
  148.                 var gems = (int)e[i + 5];
  149.                 var owned = (int)e[i + 6];
  150.                 var safename = (string)e[i + 8];
  151.                 var isnew = (bool)e[i + 17];
  152.  
  153.                 ShopItem item = new ShopItem()
  154.                 {
  155.                     Name = name,
  156.                     Price = price,
  157.                     EnergyPerClick = amount,
  158.                     OwnedAmount = owned,
  159.                     PriceGems = gems,
  160.                     SafeName = safename,
  161.                     EnergySpent = spent,
  162.                     IsNew = isnew
  163.                 };
  164.                 ShopItems.Add(item);
  165.             }
  166.         }
  167.  
  168.         public class ShopItem
  169.         {
  170.             public string Name { get; set; }
  171.             public int Price { get; set; }
  172.             public int EnergyPerClick { get; set; }
  173.             public int OwnedAmount { get; set; }
  174.             public int PriceGems { get; set; }
  175.             public int EnergySpent { get; set; }
  176.             public string SafeName { get; set; }
  177.             public bool IsNew { get; set; }
  178.         }
  179.     }
  180.     class Profile
  181.     {
  182.         public string Email { get; set; }
  183.         public string Password { get; set; }
  184.         public string Username { get; set; }
  185.         public int LoginStreak { get; set; }
  186.         public bool FirstDailyLogin { get; set; }
  187.         public Shop CurrentShop { get; set; }
  188.     }
  189.     static class Reward
  190.     {
  191.         public static string LoginReward(DateTime dt, int streak, bool forceRewards = false)
  192.         {
  193.             var totalDays = ((DateTime.UtcNow.AddHours((-TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).Hours)).Date) - dt).TotalDays;
  194.             var firstDailyLogin = totalDays >= 1.0;
  195.             var canGetRewards = totalDays < 2.0;
  196.  
  197.             if (forceRewards || (firstDailyLogin && canGetRewards))
  198.                 return (streak == 0) ? "10 energy" : ((streak % 7 + 1) < 8) ? 25 * (streak % 7 + 1) + " energy" :
  199.                     0 + ((streak % 28 + 1 != 14) ? ((streak % 28 + 1 != 28) ? 1u : 3u) : 2u) + " gems";
  200.  
  201.             return "nothing";
  202.         }
  203.     }
  204. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement