static void WADTest()
        {
            using (WADFile wad = new WADFile("Zed.wad.client"))
            {
                wad.RemoveEntry(wad.Entries[0]);
                wad.Write("Zed.wad.client");
            }

            /*using (WADFile wad = new WADFile("Jinx.wad.client"))
             * {
             *  Dictionary<ulong, byte[]> entries = new Dictionary<ulong, byte[]>();
             *  foreach(WADEntry entry in wad.Entries)
             *  {
             *      entries.Add(entry.XXHash, entry.GetContent(true));
             *  }
             *  Parallel.ForEach(entries, (entry) =>
             *  {
             *      File.WriteAllBytes("lol//" + entry.Key.ToString(), entry.Value);
             *  });
             * }*/
            //string extractionFolder = "D:/Chewy/Desktop/WADTEST";
            //Directory.CreateDirectory(extractionFolder);

            /*using (WADFile wad = new WADFile(@"C:\Riot Games\League of Legends\RADS\projects\league_client\managedfiles\0.0.0.93\Plugins\rcp-fe-viewport\assets.wad"))
             * {
             *  wad.AddEntry(123456789, File.ReadAllBytes(@"C:\Riot Games\League of Legends\RADS\projects\league_client\managedfiles\0.0.0.93\Plugins\rcp-fe-viewport\description.json"), true);
             *  wad.AddEntry(12345678, File.ReadAllBytes(@"C:\Riot Games\League of Legends\RADS\projects\league_client\managedfiles\0.0.0.93\Plugins\rcp-fe-viewport\description.json"), true);
             *  wad.AddEntry(0, "wow");
             *  wad.Entries[0].FileRedirection = "It's like right now";
             *  wad.Write(@"C:\Riot Games\League of Legends\RADS\projects\league_client\managedfiles\0.0.0.93\Plugins\rcp-fe-viewport\assetsOHWOW.wad");
             * }*/
        }
Exemple #2
0
        private void PackWadFolders(string wadLocation)
        {
            //Loop through each WAD folder
            foreach (string wadFolder in Directory.EnumerateDirectories(wadLocation))
            {
                char   separator = Pathing.GetPathSeparator(wadFolder);
                string wadName   = wadFolder.Split(separator).Last();

                using (WADFile wad = new WADFile(3, 0))
                {
                    //Add each file to the WAD
                    foreach (string wadFolderFile in Directory.EnumerateFiles(wadFolder, "*", SearchOption.AllDirectories))
                    {
                        string path      = wadFolderFile.Replace(wadFolder + separator, "").Replace('\\', '/');
                        ulong  hash      = XXHash.XXH64(Encoding.ASCII.GetBytes(path.ToLower()));
                        string extension = Path.GetExtension(wadFolderFile);

                        wad.AddEntry(hash, File.ReadAllBytes(wadFolderFile), extension != ".wpk" && extension != ".bnk" ? true : false);
                    }

                    //After WAD creation is finished we can write the WAD to the ZIP
                    ZipArchiveEntry archiveEntry = this.Content.CreateEntry(string.Format(@"WAD\{0}", wadName));
                    wad.Write(archiveEntry.Open());
                }
            }
        }
Exemple #3
0
        public void UninstallMod(ModFile mod)
        {
            Log.Information("Uninstalling Mod: " + mod.GetID());
            List <ulong> modFiles = new List <ulong>(this.Index.ModEntryMap[mod.GetID()]);
            Dictionary <string, WADFile> wadFiles = new Dictionary <string, WADFile>();

            this.Index.StartEdit();

            //In this loop we remove the installed WAD entries
            foreach (ulong modFile in modFiles)
            {
                List <string> modFileWadFiles = this.Index.Mod[modFile];

                //Initialize WAD files for entry deletion
                foreach (string modFileWadFile in modFileWadFiles)
                {
                    if (!wadFiles.ContainsKey(modFileWadFile))
                    {
                        wadFiles.Add(modFileWadFile, new WADFile(string.Format(@"{0}\{1}", OVERLAY_FOLDER, modFileWadFile)));
                    }

                    WADFile wad = wadFiles[modFileWadFile];
                    wad.RemoveEntry(modFile);
                }

                this.Index.RemoveModFile(modFile, mod.GetID());
            }

            //Now we need to either delete empty WAD files or fill the ones from which we removed the entries with original files
            //if the modified ones are the same as original then we need to delete those too
            foreach (KeyValuePair <string, WADFile> wadFile in wadFiles)
            {
                //If the WAD isn't being used by any other mod or is empty we can delete it
                if (!this.Index.WadModMap[wadFile.Key].Any(x => x != mod.GetID()) ||
                    wadFile.Value.Entries.Count == 0)
                {
                    wadFile.Value.Dispose();
                    File.Delete(string.Format(@"{0}\{1}", OVERLAY_FOLDER, wadFile.Key));
                }
                //If it's used by some other mods we need to merge it into the original WAD
                else
                {
                    string  gameWadPath    = string.Format(@"{0}\{1}", this.LeagueFolder, wadFile.Key);
                    string  overlayWadPath = string.Format(@"{0}\{1}", OVERLAY_FOLDER, wadFile.Key);
                    WADFile originalWad    = new WADFile(gameWadPath);

                    using (WADFile mergedWad = WADMerger.Merge(originalWad, wadFile.Value))
                    {
                        mergedWad.Write(overlayWadPath + ".temp");
                    }

                    wadFile.Value.Dispose();
                    File.Delete(overlayWadPath);
                    File.Move(overlayWadPath + ".temp", overlayWadPath);
                }
            }

            this.Database.ChangeModState(mod.GetID(), false);
            this.Index.RemoveMod(mod.GetID());
            this.Index.EndEdit();
        }
Exemple #4
0
        private void WriteModWADFiles(ModFile mod)
        {
            Action <KeyValuePair <string, WADFile> > writeWadFileDelegate = new Action <KeyValuePair <string, WADFile> >(WriteWadFile);

            if (Config.Get <bool>("ParallelWadInstallation"))
            {
                ParallelOptions parallelOptions = new ParallelOptions()
                {
                    MaxDegreeOfParallelism = Environment.ProcessorCount
                };

                Parallel.ForEach(mod.WadFiles, parallelOptions, (modWadFile) =>
                {
                    writeWadFileDelegate.Invoke(modWadFile);
                });
            }
            else
            {
                foreach (KeyValuePair <string, WADFile> modWadFile in mod.WadFiles)
                {
                    writeWadFileDelegate.Invoke(modWadFile);
                }
            }

            void WriteWadFile(KeyValuePair <string, WADFile> modWadFile)
            {
                string wadPath           = this.Index.FindWADPath(modWadFile.Key);
                string overlayModWadPath = string.Format(@"{0}\{1}", OVERLAY_FOLDER, wadPath);
                string gameModWadPath    = string.Format(@"{0}\{1}", this.LeagueFolder, wadPath);

                //Check if the WAD already exists, if it does, we need to merge the 2 WADs
                //if it doesnt, then we need to copy it from the game directory
                if (!File.Exists(overlayModWadPath))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(overlayModWadPath));

                    WADFile baseWad           = new WADFile(gameModWadPath);
                    bool    returnedModdedWad = false;
                    using (WADFile mergedWad = WADMerger.Merge(baseWad, modWadFile.Value, out returnedModdedWad))
                    {
                        mergedWad.Write(overlayModWadPath);
                    }

                    if (returnedModdedWad)
                    {
                        baseWad.Dispose();
                    }
                    else
                    {
                        modWadFile.Value.Dispose();
                    }
                }
                else
                {
                    File.Move(overlayModWadPath, overlayModWadPath + ".temp");

                    using (WADFile mergedWad = WADMerger.Merge(new WADFile(overlayModWadPath + ".temp"), modWadFile.Value))
                    {
                        mergedWad.Write(overlayModWadPath);
                    }

                    //Delete temp wad file
                    File.Delete(overlayModWadPath + ".temp");
                    modWadFile.Value.Dispose();
                }
            }
        }