コード例 #1
0
        public void SetNextNeededUsername(HypixelFriend friend)
        {
            HypixelFriend?nullable = GetNextNeededUsername();

            if (nullable.HasValue)
            {
                friends.Remove(nullable.Value);
                friends.Add(friend);
            }
            else
            {
                friends.Add(friend);
            }
            return;
        }
コード例 #2
0
        public void ToggleVisible()
        {
            open = !open;

            SizeUpdater_Tick(null, null);

            if (open)
            {
                if (BackgroundImage != null)
                {
                    BackgroundImage.Dispose();
                    BackgroundImage = null;
                }
                BackgroundImage = GetMCWindowImage();
                if (!Data.player.loaded)
                {
                    JObject structure = Post(FRIENDAPI, null);
                    JArray  entries   = structure["records"] as JArray;

                    foreach (var friend in entries)
                    {
                        string        fUUID     = friend["uuidReceiver"].ToString();
                        HypixelFriend newFriend = new HypixelFriend(fUUID);
                        Data.player.AddFriend(newFriend); // uses cached names
                    }

                    Console.WriteLine("[MARS] Got friend UUIDs.");
                    Data.player.loaded = true;
                }
            }
            if (!open)
            {
                if (BackgroundImage != null)
                {
                    BackgroundImage.Dispose();
                    BackgroundImage = null;
                }
            }
        }
コード例 #3
0
        public static HypixelSelf Deserialize(string dat)
        {
            JArray      json = JArray.Parse(dat);
            HypixelSelf self = new HypixelSelf();

            self.fakeFriends = new List <HypixelFriend>();
            foreach (JToken obj in json)
            {
                string UUID   = obj.Value <string>("UUID");
                string name   = obj.Value <string>("name");
                bool   loaded = bool.Parse(obj.Value <string>("loaded"));

                HypixelFriend f = new HypixelFriend(UUID);
                if (loaded)
                {
                    f.SetName(name);
                }

                self.fakeFriends.Add(f);
            }
            return(self);
        }
コード例 #4
0
        public void AddFriend(HypixelFriend friend)
        {
            if (!friend.loaded && fakeFriends != null)
            {
                // Check fakeFriends to find a possibly loaded name.
                if (fakeFriends.Any(f => f.UUID.Equals(friend.UUID)))
                {
                    // If found, apply to friend object.
                    HypixelFriend fake = fakeFriends.First
                                             (f => f.UUID.Equals(friend.UUID));
                    if (fake.loaded)
                    {
                        friend.SetName(fake.name);
                    }
                }
            }

            if (!friends.Any(f => f.UUID.Equals(friend.UUID)) &&
                !friend.UUID.Equals(Data.mcUUID))
            {
                friends.Add(friend);
            }
        }
コード例 #5
0
        // Every call downloads friend info if not present.
        private void FriendUpdateTimer_Tick(object sender, EventArgs e)
        {
            if (Data.player == null)
            {
                return;
            }

            HypixelSelf   self = Data.player;
            HypixelFriend?_f   = self.GetNextNeededUsername();

            if (_f.HasValue)
            {
                // Fetch username from UUID.
                HypixelFriend f        = _f.Value;
                string        UUID     = f.UUID;
                JObject       items    = Post(PROFILEAPI, UUID);
                string        username = items["name"].ToString();

                string saved     = HEAD_PATH + UUID + ".png";
                string savedFull = HEAD_PATH + UUID + "_FULL.png";

                if (!File.Exists(saved))
                {
                    // Contains skin information encoded in Base64.
                    string infoB64 = items["properties"][0]["value"].ToString();
                    byte[] infoBytes = Convert.FromBase64String(infoB64);
                    string info = Encoding.Default.GetString(infoBytes);
                    JToken textures = JObject.Parse(info)["textures"];
                    Bitmap loadedSkin = null; bool hasSkin = true;
                    // SKIN field is missing if no skin.
                    try { string _ = textures["SKIN"].ToString(); }
                    catch (Exception) { hasSkin = false; }
                    if (hasSkin)
                    {
                        using (WebClient wc = new WebClient())
                        {
                            wc.DownloadFile(textures["SKIN"]["url"].ToString(), savedFull);
                            using (Image img = Image.FromFile(savedFull))
                            {
                                loadedSkin = new Bitmap(8, 8);
                                using (Graphics gr = Graphics.FromImage(loadedSkin))
                                {
                                    gr.DrawImage(img, 0, 0, new Rectangle
                                                     (8, 8, 8, 8), GraphicsUnit.Pixel);
                                }
                            }
                        }
                    }
                    else
                    {
                        // Just make it a black head.
                        loadedSkin = new Bitmap(8, 8);
                        using (var g = Graphics.FromImage(loadedSkin))
                            g.FillRectangle(Brushes.Black, 0, 0, 8, 8);
                    }

                    using (loadedSkin)
                        using (Bitmap temp = new Bitmap(loadedSkin))
                            temp.Save(saved);
                }

                f.SetName(username);
                self.SetNextNeededUsername(f);
                Console.WriteLine("[MARS] Fetched friend info for {0}. {1}/{2} done.",
                                  username, self.LoadedCount(), self.Count());
            }
        }