Esempio n. 1
0
 internal VpkDirectory(VpkArchive parentArchive, string path, List <VpkEntry> entries)
 {
     Console.WriteLine(ParentArchive + " " + Path + " " + Entries[0].ToString());
     ParentArchive = parentArchive;
     Path          = path;
     Entries       = entries;
 }
Esempio n. 2
0
        public IEnumerable <VpkEntry> ReadEntries(VpkArchive parentArchive, string ext, string path)
        {
            while (true)
            {
                var fileName = ReadNullTerminatedString();
                if (string.IsNullOrEmpty(fileName))
                {
                    break;
                }

                var crc          = Reader.ReadUInt32();
                var preloadBytes = Reader.ReadUInt16();
                var archiveIdx   = Reader.ReadUInt16();
                var entryOffset  = Reader.ReadUInt32();
                var entryLen     = Reader.ReadUInt32();
                // skip terminator
                Reader.ReadUInt16();
                var preloadDataOffset = ( uint )Reader.BaseStream.Position;
                if (preloadBytes > 0)
                {
                    Reader.BaseStream.Position += preloadBytes;
                }

                yield return(new VpkEntry(parentArchive, crc, preloadBytes, preloadDataOffset, archiveIdx, entryOffset, entryLen, ext.ToLower(), path.ToLower(), fileName.ToLower()));
            }
        }
Esempio n. 3
0
 internal VpkEntry(VpkArchive parentArchive, uint crc, ushort preloadBytes, uint preloadDataOffset, ushort archiveIndex, uint entryOffset,
                   uint entryLength, string extension, string path, string filename)
 {
     ParentArchive     = parentArchive;
     CRC               = crc;
     PreloadBytes      = preloadBytes;
     PreloadDataOffset = preloadDataOffset;
     ArchiveIndex      = archiveIndex;
     EntryOffset       = entryOffset;
     EntryLength       = entryLength;
     Extension         = extension;
     Path              = path;
     Filename          = filename;
     HasPreloadData    = preloadBytes > 0;
 }
Esempio n. 4
0
 internal VpkEntry(VpkArchive parentArchive, uint crc, ushort preloadBytes, uint preloadDataOffset, ushort archiveIndex, uint entryOffset,
     uint entryLength, string extension, string path, string filename)
 {
     ParentArchive = parentArchive;
     CRC = crc;
     PreloadBytes = preloadBytes;
     PreloadDataOffset = preloadDataOffset;
     ArchiveIndex = archiveIndex;
     EntryOffset = entryOffset;
     EntryLength = entryLength;
     Extension = extension;
     Path = path;
     Filename = filename;
     HasPreloadData = preloadBytes > 0;
 }
Esempio n. 5
0
        public IEnumerable <VpkDirectory> ReadDirectories(VpkArchive parentArchive)
        {
            while (true)
            {
                var ext = ReadNullTerminatedString();
                if (string.IsNullOrEmpty(ext))
                {
                    break;
                }
                while (true)
                {
                    var path = ReadNullTerminatedString();
                    if (string.IsNullOrEmpty(path))
                    {
                        break;
                    }

                    var entries = ReadEntries(parentArchive, ext, path).ToList();
                    yield return(new VpkDirectory(parentArchive, path, entries));
                }
            }
        }
Esempio n. 6
0
 internal VpkDirectory(VpkArchive parentArchive, string path, List <VpkEntry> entries)
 {
     ParentArchive = parentArchive;
     Path          = path.ToLower();
     Entries       = entries;
 }
Esempio n. 7
0
        public static void Process()
        {
            const string heroesMini = @"Dota 2\Heroes\Mini\";
            const string heroesLandscape = @"Dota 2\Heroes\Landscape\";
            const string heroesPortrait = @"Dota 2\Heroes\Portrait\";
            const string items = @"Dota 2\Items\";
            const string spells = @"Dota 2\Spells\";
            string[] directories = { heroesMini, heroesLandscape, heroesPortrait, items, spells };
            Helper.BuildDirectoryTree(directories);

            // Get the path of the source
            INIFile ini = new INIFile(Globals.Paths.ConfigurationFile);
            string sourcePath = ini.INIReadValue("Game Paths", "Dota 2");

            string vpkPath = Path.Combine(sourcePath, @"dota\pak01_dir.vpk");
            const string archivePrepend = @"resource/flash3/images/{0}";

            // Get the source
            string[] valvePackages = {"heroes", @"heroes\selection", "miniheroes", "spellicons", "items"};
            foreach(string valvePackage in valvePackages)
            {
                var valveArchive = new VpkArchive();
                valveArchive.Load(vpkPath);
                foreach (var directory in valveArchive.Directories)
                {
                    string rootDirectory = string.Format(archivePrepend, valvePackage);
                    if (directory.ToString().Contains(rootDirectory)) {
                        foreach (var entry in directory.Entries)
                        {
                            string destPath = Path.Combine(Globals.Paths.Assets, @"Source\Dota 2", entry.ToString().Replace("resource/flash3/images/",""));
                            FileInfo destInfo = new FileInfo(destPath);
                            string destDirectory = destInfo.Directory.ToString();
                            if (!Directory.Exists(destDirectory))
                            {
                                Directory.CreateDirectory(destDirectory);
                                Console.WriteLine("Creating directory {0}", destDirectory);
                            }
                            if (Directory.Exists(destDirectory)) {
                                Console.WriteLine("Extracting {0}", destPath);
                                File.WriteAllBytes(destPath, entry.Data);
                            }
                        }
                    }
                }
            }

            // Copy the rest of the source assets
            // Copy jobs take the form { string output path, { string start path, bool recursion flag, string search pattern, string exclude pattern } }
            List<CopyJob> copyJobs = new List<CopyJob>
            {
                new CopyJob(heroesPortrait, Path.Combine(Globals.Paths.Assets, @"Source\Dota 2\heroes\selection"), true, "npc_dota_hero_*.png", null),
                new CopyJob(heroesLandscape, Path.Combine(Globals.Paths.Assets, @"Source\Dota 2\heroes"), false, "*.png", null),
                new CopyJob(heroesMini, Path.Combine(Globals.Paths.Assets, @"Source\Dota 2\miniheroes"), true, "*.png", null),
                new CopyJob(spells, Path.Combine(Globals.Paths.Assets, @"Source\Dota 2\spellicons"), true, "*.png", null),
                new CopyJob(items, Path.Combine(Globals.Paths.Assets, @"Source\Dota 2\items"), true, "*.png", null)
            };
            Helper.BatchFileCopy(copyJobs);

            // Rename all the things
            Helper.BatchFileRename("Dota 2");

            // Scale all the things
            // Scaling jobs take the form { string start path, string search pattern, string exclude pattern }
            List<ScalingJob> scalingJobs = new List<ScalingJob>
            {
                new ScalingJob(heroesLandscape, "*.png"),
                new ScalingJob(heroesMini, "*.png"),
                new ScalingJob(heroesPortrait, "*.png"),
                new ScalingJob(items, "*.png"),
                new ScalingJob(spells, "*.png")
            };
            Helper.BatchIMScale(scalingJobs);
        }
Esempio n. 8
0
 internal VpkDirectory(VpkArchive parentArchive, string path, List<VpkEntry> entries)
 {
     ParentArchive = parentArchive;
     Path = path;
     Entries = entries;
 }