private void ApplyButton_Click(object sender, RoutedEventArgs e)
        {
            //Opens the config, applies the patch of the users co-ordinates
            using (Stream stream = File.Open(Path.Combine("HUD", MainWindow.current_version, "HUDConfig.bin"), FileMode.Open))
            {
                byte[] ReplacedBytes = _selectedItem.ReplaceCoordinates(new Tuple<int, int>(XOnePos.Byte, XTwoPos.Byte),
                                                               new Tuple<int, int>(YOnePos.Byte, YTwoPos.Byte));
                stream.Position = _selectedItem.Position;
                stream.Write(ReplacedBytes, 0, ReplacedBytes.Length);
            }

            //Save the file into the RAF archive
            RAFMasterFileList list = new RAFMasterFileList(_LeagueLocation);
            var HUDConfig = list.SearchFileEntries("Clarity_RenderUI.bin")[0];
            HUDConfig.ReplaceContent(File.ReadAllBytes(Path.Combine("HUD", MainWindow.current_version, "HUDConfig.bin")));
            HUDConfig.RAFArchive.SaveRAFFile();

            MessageBox.Show("HUD has been updated! Test it out in a custom game first.");
        }
        private bool ExpandRAF(string fileDirectory)
        {
            LogTextBox("Loading RAF Packages in " + fileDirectory);
            RAFMasterFileList list = new RAFMasterFileList(fileDirectory);
            LogTextBox("Expanding RAF packages. This will take a while (~20-30 minutes)...");
            LogTextBox("During this time computer performance may be affected. While patching, running applications should be closed or not in-use");
            int i = 0;
            foreach (var x in list.FileDictFull)
            {   
                string FileLastWritten = "";
                var RAFFile = x.Value[0];
                string n = Path.Combine(Client.ExecutingDirectory, "RADS", "lol_game_client");
                foreach (string Directories in RAFFile.FileName.Split('/'))
                {
                    if (!Directories.Contains('.'))
                    {
                        if (!Directory.Exists(Path.Combine(n, Directories)))
                        {
                            Directory.CreateDirectory(Path.Combine(n, Directories));
                        }
                        n = Path.Combine(n, Directories);
                    }
                    else
                    {
                        BinaryWriter Writer = null;
                        try
                        {
                            Writer = new BinaryWriter(File.OpenWrite(Path.Combine(n, Directories)));

                            // Writer raw data                
                            Writer.Write(RAFFile.GetContent());
                            Writer.Flush();
                            Writer.Close();
                            FileLastWritten = Path.Combine(n, Directories);
                        }
                        catch
                        {
                            LogTextBox("Unable to write " + Path.Combine(n, Directories));
                        }
                    }
                }
                LogTextBox("(" + i + "/" + list.FileDictFull.Count + ") " + (((decimal)i / (decimal)list.FileDictFull.Count) * 100).ToString("N2") + "%");
                i += 1;
            }
            return true;
        }
        private void Worker_DoWork(object sender, DoWorkEventArgs e)
        {
            //Don't read the config again if it already exists
            if (File.Exists(Path.Combine("HUD", MainWindow.current_version, "HUDConfig.bin")))
                return;

            //Read the config from the RAF archives and copy it to the folder we created
            RAFMasterFileList list = new RAFMasterFileList(_LeagueLocation);
            var HUDConfig = list.SearchFileEntries("Clarity_RenderUI.bin")[0];
            File.WriteAllBytes(Path.Combine("HUD", MainWindow.current_version, "HUDConfig.bin"), HUDConfig.GetContent());
            File.Copy(Path.Combine("HUD", MainWindow.current_version, "HUDConfig.bin"), Path.Combine("HUD", MainWindow.current_version, "HUDConfig.bin.bak"));
        }
        private void ResetButton_Click(object sender, RoutedEventArgs e)
        {
            //Replaces the current HUDConfig with the backed-up one and resets the window
            RAFMasterFileList list = new RAFMasterFileList(_LeagueLocation);
            var HUDConfig = list.SearchFileEntries("Clarity_RenderUI.bin")[0];
            HUDConfig.ReplaceContent(File.ReadAllBytes(Path.Combine("HUD", MainWindow.current_version, "HUDConfig.bin.bak")));
            HUDConfig.RAFArchive.SaveRAFFile();

            File.Delete(Path.Combine("HUD", MainWindow.current_version, "HUDConfig.bin"));
            File.Copy(Path.Combine("HUD", MainWindow.current_version, "HUDConfig.bin.bak"), Path.Combine("HUD", MainWindow.current_version, "HUDConfig.bin"));

            MessageBox.Show("HUD has been reset.");
            HUDWindow window = new HUDWindow(_location);
            window.Show();
            this.Close();
        }
 public RAFArchiveWrapper(RAFMasterFileList rafArch)
 {
     r = rafArch;
 }
 public RAFFileListEntryWrapper(RAFMasterFileList.RAFSearchResult result)
 {
     e = result.value;
     SearchPhrase = result.searchPhrase;
 }
        // Replacement for individual raf reading and individual filetype searching
        // Provide the directory of RADS\projects\lol_game_client\filearchives or the equivalent
        private bool ReadRAFs(DirectoryInfo dir, Logger logger)
        {
            try
            {
                RAFMasterFileList rafFiles = new RAFMasterFileList(dir.FullName);
                logger.Event("Opening the 'filearchives' directory: " + dir.FullName);
                foreach (RAFMasterFileList.RAFSearchResult result in rafFiles.SearchFileEntries(new string[] { ".dds", ".skn", ".skl", ".inibin", "animations.list", ".anm" }, RAFMasterFileList.RAFSearchType.All))
                {
                    RAFFileListEntry e = result.value;

                    // Split off the actual file name from the full path
                    String name = e.FileName.Substring(e.FileName.LastIndexOf('/') + 1).ToLower();

                    switch (result.searchPhrase)
                    {
                        case ".dds":
                            // Try to parse out unwanted textures.
                            if (!e.FileName.ToLower().Contains("loadscreen") &&
                                !e.FileName.ToLower().Contains("circle") &&
                                !e.FileName.ToLower().Contains("square") &&
                                e.FileName.ToLower().Contains("data") &&
                                e.FileName.ToLower().Contains("characters"))
                            {
                                // Check that the file isn't already in the dictionary
                                if (!textures.ContainsKey(name))
                                {
                                    textures.Add(name, e);
                                }
                                else
                                {
                                    logger.Warning("Duplicate texture " + name + ": " + e.FileName);
                                }
                            }
                            break;

                        case ".skn":
                            if (!skns.ContainsKey(name))
                            {
                                skns.Add(name, e);
                            }
                            else
                            {
                                logger.Warning("Duplicate skn " + name + ": " + e.FileName);
                            }
                            break;

                        case ".skl":
                            if (!skls.ContainsKey(name))
                            {
                                skls.Add(name, e);
                            }
                            else
                            {
                                logger.Warning("Duplicate skn " + name + ": " + e.FileName);
                            }
                            break;

                        case ".inibin":
                            // Try to only read champion inibins
                            if (e.FileName.ToLower().Contains("data") &&
                                e.FileName.ToLower().Contains("characters"))
                            {
                                inibins.Add(e);
                            }
                            else
                            {
                                logger.Warning("Excluding inibin " + name + ": " + e.FileName);
                            }
                            break;

                        case "animations.list":
                            // Riot changed their directory structure for some skins.
                            // Originally, champion Animation.list files were stored in a directory structure like
                            // "*/ChampionName/Animation.list".  Now, some are stored like
                            // "*/ChampionName/Skins/Skin01/Animation.list".

                            if (e.FileName.ToLower().Contains("skin") == false &&
                                e.FileName.ToLower().Contains("base") == false)
                            {
                                // Original Case.

                                // Remove the file name.
                                name = e.FileName.Remove(e.FileName.LastIndexOf('/'));

                                // Remove proceeding directories to get the parent directory
                                name = name.Substring(name.LastIndexOf('/') + 1).ToLower();
                            }
                            else
                            {
                                // Newer Case.
                                string path = e.FileName.ToString();
                                string[] splitPath = path.Split('/');

                                // Sanity
                                if (splitPath.Length > 3)
                                {
                                    name = splitPath[splitPath.Length - 4].ToLower();
                                }
                            }

                            // Store.
                            if (!animationLists.ContainsKey(name))
                            {
                                animationLists.Add(name, e);
                            }
                            else
                            {
                                logger.Warning("Duplicate animation list " + name + ": " + e.FileName);
                            }
                            break;

                        case ".anm":
                            // Remove the .anm extension.
                            name = name.Remove(name.Length - 4);

                            if (!animations.ContainsKey(name))
                            {
                                animations.Add(name, e);
                            }
                            else
                            {
                                logger.Warning("Duplicate anm " + name + ": " + e.FileName);
                            }
                            break;
                    }
                }

            }
            catch (Exception e)
            {
                // Something went wrong. Most likely the RAF read failed due to a bad directory.
                logger.Error("Failed to open RAFs");
                logger.Error(e.Message);
                return false;
            }

            return true;
        }