Example #1
0
 private static IEnumerable <string> ProcessEnvironment(FileEntry fe, PackageFileEntry pfe, Dictionary <string, object> root)
 {
     return(root.TableChildren().WhereMeta("data")
            .TableChildren().WhereMeta("others")
            .TableChildren().Where(i => EnvironmentKeys.Contains(i["key"]))
            .Entry <string>("value"));
 }
Example #2
0
        public static void DoViewFile(FileEntry entry, PackageFileEntry be = null, FormatConverter exporter = null)
        {
            try
            {
                if (entry.BundleEntries.Count == 0)
                {
                    return;
                }

                TempFile temp = GetTempFile(entry, be, exporter);
                GC.Collect();
                Process proc = new Process();
                proc.StartInfo.FileName  = "explorer";
                proc.StartInfo.Arguments = $"\"{temp.FilePath}\"";
                proc.Start();
                if (!TempFiles.ContainsKey(entry))
                {
                    TempFiles.Add(entry, temp);
                }
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
                Console.WriteLine(exc.StackTrace);
            }
        }
Example #3
0
        public void PopulateFile(List <VirtualFileDataObject.FileDescriptor> files, FileEntry parent, string path = "")
        {
            if (parent.BundleEntries.Count == 0)
            {
                return;
            }

            string name = this.OutputFullPaths ? parent.Path : path;

            VirtualFileDataObject.FileDescriptor fileDescriptor = new VirtualFileDataObject.FileDescriptor()
            {
                Name           = name,
                StreamContents = () =>
                {
                    MemoryStream     stream         = new MemoryStream();
                    PackageFileEntry maxBundleEntry = parent.MaxBundleEntry();
                    Console.WriteLine("Extracted {0} from package: {1}", name, maxBundleEntry.PackageName.ToString());
                    byte[] bytes = parent.FileBytes(maxBundleEntry);
                    if (bytes != null)
                    {
                        stream.Write(bytes, 0, bytes.Length);
                    }
                    return(stream);
                }
            };
            files.Add(fileDescriptor);
        }
Example #4
0
            public TempFile(FileEntry entry, PackageFileEntry be = null, FormatConverter converter = null, string filePath = null, bool includeInnerPath = true)
            {
                string path;

                if (includeInnerPath)
                {
                    path = entry.EntryPath.Replace("/", "\\");
                }
                else
                {
                    path = entry.Name;
                }

                if (filePath == null)
                {
                    FilePath = Path.Combine(Path.GetTempPath(), "DBV", path);
                    if (converter != null && converter.Extension != null)
                    {
                        FilePath += "." + converter.Extension;
                    }
                }
                else
                {
                    FilePath = filePath;
                }

                SaveFile(entry, FilePath, converter, be, true);

                Entry = be;
                if (converter != null)
                {
                    ExporterKey = converter.Key;
                }
            }
Example #5
0
        public PackageFileEntry MaxBundleEntry()
        {
            if (this.BundleEntries.Count == 0)
            {
                return(null);
            }

            if (this._max_entry == null)
            {
                this._max_entry = null;
                foreach (PackageFileEntry entry in this.BundleEntries)
                {
                    if (this._max_entry == null)
                    {
                        this._max_entry = entry;
                        continue;
                    }

                    if (entry.Length > this._max_entry.Length)
                    {
                        this._max_entry = entry;
                    }
                }
            }

            return(this._max_entry);
        }
            public TempFile(FileEntry entry, PackageFileEntry be = null, dynamic exporter = null)
            {
                this.Path = System.IO.Path.Combine(System.IO.Path.GetTempPath(), Definitions.TempDir, $"{entry._path.HashedString}.{entry._extension.ToString()}");

                if (exporter?.extension != null)
                {
                    this.Path += "." + exporter.extension;
                }

                object file_data = entry.FileData(be, exporter);

                if (file_data is byte[])
                {
                    File.WriteAllBytes(this.Path, (byte[])file_data);
                }
                else if (file_data is Stream)
                {
                    using (FileStream file_stream = File.Create(this.Path))
                        ((Stream)file_data).CopyTo(file_stream);

                    ((Stream)file_data).Close();
                }
                else if (file_data is string)
                {
                    File.WriteAllText(this.Path, (string)file_data);
                }
                else if (file_data is string[])
                {
                    File.WriteAllLines(this.Path, (string[])file_data);
                }

                this.Entry       = be;
                this.ExporterKey = exporter?.key;
            }
Example #7
0
        public void ExtractBundle(PackageHeader bundle, string bundle_id)
        {
            string bundle_file = Path.Combine(StaticStorage.settings.AssetsFolder, bundle_id + ".bundle");

            if (!File.Exists(bundle_file))
            {
                string error_message = "Bundle file does not exist.";
                MessageBox.Show(error_message);
                TextWriteLine(error_message);
                return;
            }
            using (FileStream fs = new FileStream(bundle_file, FileMode.Open, FileAccess.Read))
            {
                using (BinaryReader br = new BinaryReader(fs))
                {
                    for (; current_bundle_progress < current_bundle_total_progress; current_bundle_progress++)
                    {
                        PackageFileEntry be = bundle.Entries[(int)current_bundle_progress];
                        if (this.terminate)
                        {
                            break;
                        }

                        string path = Path.Combine(extract_folder, this.GetFileName(be));

                        if (StaticStorage.settings.IgnoreExistingFiles && File.Exists(path))
                        {
                            continue;
                        }

                        string folder = Path.GetDirectoryName(path);

                        if (!String.IsNullOrWhiteSpace(folder) && !Directory.Exists(folder))
                        {
                            Directory.CreateDirectory(folder);
                        }

                        if (be.Length == 0 && File.Exists(path))
                        {
                            continue;
                        }

                        fs.Position = be.Address;
                        byte[] data;
                        if (be.Length == -1)
                        {
                            data = br.ReadBytes((int)(fs.Length - fs.Position));
                        }
                        else
                        {
                            data = br.ReadBytes((int)be.Length);
                        }

                        File.WriteAllBytes(path, data);
                    }
                }
            }
        }
Example #8
0
        private static IEnumerable <string> ProcessContinents(FileEntry fe, PackageFileEntry pfe, Dictionary <string, object> root)
        {
            if (!fe.PathIds.HasUnHashed)
            {
                return(Enumerable.Empty <string>());
            }

            return(root.Keys.Select(i => string.Format("{0}/{1}/{1}", fe.Parent.EntryPath, i)));
        }
Example #9
0
 private static IEnumerable <string> ProcessSequenceManager(FileEntry fe, PackageFileEntry pfe, Dictionary <string, object> root)
 {
     return(root.Values.WhereMeta("unit").TableChildren()
            .WhereMeta("sequence").TableChildren()
            .WhereMeta("material_config")
            .Entry <string>("name")
            .Select(i => Regex.Match(i, @"^ *('|"")((?:\\\1|(?!\1).)+)\1 * $"))
            .Where(i => i != null && i.Success)
            .Select(m => m.Groups[2].Value));
 }
Example #10
0
        private static IEnumerable <string> ProcessUnit(FileEntry fe, PackageFileEntry pfe, XPathNavigator data)
        {
            var names      = data.Select(UnitFinder).Cast <XPathNavigator>().Select(i => i.Value);
            var objectPath = data.Select(UnitObjectFinder).Cast <XPathNavigator>()
                             .Select(i => i.Value)
                 // TODO: Rearrange everything until these are only generated if they truly exist.
            ;    //.AndSelect(i => i.Contains("wpn_fps") ? i + "_npc" : null);

            return(Enumerable.Concat(names, objectPath));
        }
Example #11
0
        public static TempFile CreateTempFile(FileEntry entry, PackageFileEntry be = null, FormatConverter exporter = null)
        {
            if (TempFiles.ContainsKey(entry))
            {
                DeleteTempFile(entry);
            }

            TempFile temp = new TempFile(entry, be, exporter);

            return(temp);
        }
Example #12
0
        public TempFile CreateTempFile(FileEntry entry, PackageFileEntry be = null, dynamic exporter = null)
        {
            if (this.TempFiles.ContainsKey(entry))
            {
                this.DeleteTempFile(entry);
            }

            TempFile temp = new TempFile(entry, be, exporter);

            return(temp);
        }
Example #13
0
 public object FileData(PackageFileEntry be = null, FormatConverter exporter = null)
 {
     if (exporter == null)
     {
         return(this.FileStream(be));
     }
     else
     {
         MemoryStream stream = this.FileStream(be);
         return(stream == null ? null : exporter.Export(this.FileStream(be)));
     }
 }
Example #14
0
        public void SetInspectedEntry(PackageFileEntry entry)
        {
            this.ClearEntryFields();
            DatabaseEntry db_ent = this.lookup_db.EntryFromID(entry.ID);

            this.txtPath.Text    = db_ent?.Path?.ToString();
            this.txtLang.Text    = (db_ent?.Language ?? 0) != 0 ? this.lookup_db.LanguageFromID((uint)db_ent?.Language).Name.ToString() : "";
            this.txtType.Text    = db_ent?.Extension?.ToString();
            this.txtID.Text      = entry.ID.ToString();
            this.txtLangID.Text  = (db_ent?.Language ?? 0) != 0 ? db_ent?.Language.ToString() : "";
            this.txtAddress.Text = entry.Address.ToString();
            this.txtLength.Text  = entry.Length.ToString();
        }
Example #15
0
        public MemoryStream FileStream(PackageFileEntry entry = null)
        {
            entry = entry ?? this.MaxBundleEntry();

            byte[] bytes = this.FileEntryBytes(entry);
            if (bytes == null)
            {
                return(null);
            }

            MemoryStream stream = new MemoryStream(bytes);

            stream.Position = 0;
            return(stream);
        }
Example #16
0
        public virtual void WriteEntry(PackageFileEntry entry)
        {
            if (ListOptions.EntryInfo.Count == 0)
            {
                return;
            }

            this.Output.Append("\t");
            for (int i = 0; i < this.ListOptions.EntryInfo.Count; i++)
            {
                ListEntryOption opt = this.ListOptions.EntryInfo[i];
                this.Output.Append((i == 0 ? "" : " - ") + opt.StringFunc(Parent, entry));
            }
            this.Output.AppendLine();
        }
Example #17
0
        private static IEnumerable <string> ProcessContinent(FileEntry fe, PackageFileEntry pfe, Dictionary <string, object> root)
        {
            var instanceNames = root.EntryTable("instances").TableChildren()
                                .Entry <string>("folder")
                                .Select(i => Regex.Replace(i, "/world$", "/"))
                                .SelectMany(bp => InstanceFilenames.Select(i => bp + i));

            var ud = root.EntryTable("statics").TableChildren()
                     .EntryTable("unit_data");

            return(instanceNames
                   .Concat(ud.Entry <string>("name"))
                   .Concat(ud.EntryTable("editable_gui").Entry <string>("font")
                           ));
        }
      public void PopulateFile(List <VirtualFileDataObject.FileDescriptor> files, FileEntry parent, string removeDirectory)
      {
          if (parent.BundleEntries.Count == 0)
          {
              return;
          }

          string name = parent.EntryPath;

          if (!OutputFullPaths && !string.IsNullOrEmpty(removeDirectory))
          {
              name = name.Replace(removeDirectory, "");
          }

          files.Add(new VirtualFileDataObject.FileDescriptor()
            {
                Name           = name,
                StreamContents = (stream) =>
                {
                    i++;
                    int total = files.Count;

                    PackageFileEntry maxBundleEntry = parent.MaxBundleEntry();

                    byte[] bytes = parent.FileBytes(maxBundleEntry);
                    if (bytes != null)
                    {
                        stream.Write(bytes, 0, bytes.Length);
                    }
                    else
                    {
                        Console.WriteLine("Failed to extract {0} from package: {1}", name, maxBundleEntry.PackageName.ToString());
                    }

                    if (Progress != null)
                    {
                        if (Progress.IsClosed)
                        {
                            throw new Exception(); //No clue how to really stop that other than exceptions lol.
                        }
                        else
                        {
                            Progress.SetProgress($"Copying {parent.EntryPath}", i, files.Count);
                        }
                    }
                }
            });
      }
Example #19
0
        public static void GenerateHashlist(string workingPath, string file, PackageFileEntry be)
        {
            using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read))
            {
                using (BinaryReader br = new BinaryReader(fs))
                {
                    byte[]           data;
                    StringBuilder    sb = new StringBuilder();
                    string[]         idstring_data;
                    HashSet <string> new_paths = new HashSet <string>();

                    fs.Position = be.Address;
                    if (be.Length == -1)
                    {
                        data = br.ReadBytes((int)(fs.Length - fs.Position));
                    }
                    else
                    {
                        data = br.ReadBytes((int)be.Length);
                    }

                    foreach (byte read in data)
                    {
                        sb.Append((char)read);
                    }

                    idstring_data = sb.ToString().Split('\0');
                    sb.Clear();

                    foreach (string idstring in idstring_data)
                    {
                        new_paths.Add(idstring);
                    }

                    new_paths.Add("idstring_lookup");
                    new_paths.Add("existing_banks");
                    new_paths.Add("engine-package");

                    HashIndex.Clear();

                    HashIndex.Load(ref new_paths);

                    HashIndex.GenerateHashList(Path.Combine(workingPath, HashlistFile));

                    new_paths.Clear();
                }
            }
        }
Example #20
0
        public string GetFileName(PackageFileEntry be)
        {
            string path;

            if (!cached_paths.ContainsKey(be.ID))
            {
                path = String.Format("unknown_{0:x}.bin", be.ID);
                DatabaseEntry ne = StaticStorage.Index.EntryFromID(be.ID);
                if (ne != null)
                {
                    path = ne.Path.UnHashed ?? String.Format("{0:x}", ne.Path);

                    if (ne.Language != 0)
                    {
                        if (StaticStorage.Index.LanguageFromID(ne.Language) != null)
                        {
                            string lang_ext = StaticStorage.Index.LanguageFromID(ne.Language).Name.UnHashed;
                            path += String.Format(".{0}", (lang_ext != null ? lang_ext : ne.Language.ToString("x")));
                        }
                        else
                        {
                            path += String.Format(".{0:x}", ne.Language);
                        }
                    }

                    string extension = ne.Extension.UnHashed ?? String.Format("{0:x}", ne.Extension);

                    if (!list && StaticStorage.settings.ExtensionConversion.ContainsKey(extension))
                    {
                        extension = StaticStorage.settings.ExtensionConversion[extension];
                    }

                    path += "." + extension;
                }
                cached_paths[be.ID] = path;
            }
            else
            {
                path = cached_paths[be.ID];
            }

            return(path);
        }
Example #21
0
        public TempFile GetTempFile(FileEntry file, PackageFileEntry entry = null, dynamic exporter = null)
        {
            TempFile path;

            if (!this.TempFiles.ContainsKey(file) || this.TempFiles[file].Disposed || !File.Exists(this.TempFiles[file].Path) || this.TempFiles[file].ExporterKey != exporter?.key || this.TempFiles[file].Entry != entry)
            {
                if (this.TempFiles.ContainsKey(file))
                {
                    this.DeleteTempFile(file);
                }

                path = this.CreateTempFile(file, entry, exporter);
            }
            else
            {
                path = this.TempFiles[file];
            }

            return(path);
        }
Example #22
0
        public static TempFile GetTempFile(FileEntry file, PackageFileEntry entry = null, FormatConverter exporter = null)
        {
            TempFile path;

            if (!TempFiles.ContainsKey(file) || TempFiles[file].Disposed || !File.Exists(TempFiles[file].FilePath) || (exporter != null && TempFiles[file].ExporterKey != exporter.Key) || TempFiles[file].Entry != entry)
            {
                if (TempFiles.ContainsKey(file))
                {
                    DeleteTempFile(file);
                }

                path = CreateTempFile(file, entry, exporter);
            }
            else
            {
                path = TempFiles[file];
            }

            return(path);
        }
Example #23
0
        private byte[] FileEntryBytes(PackageFileEntry entry)
        {
            if (entry == null)
            {
                return(null);
            }

            string bundle_path;

            if (!File.Exists(bundle_path = System.IO.Path.Combine(this.ParentBrowser.WorkingDirectory, entry.Parent.Name.HashedString + ".bundle")))
            {
                Console.WriteLine("Bundle: {0}, does not exist", bundle_path);
                return(null);
            }

            try
            {
                using (FileStream fs = new FileStream(bundle_path, FileMode.Open, FileAccess.Read))
                {
                    using (BinaryReader br = new BinaryReader(fs))
                    {
                        if (entry.Length != 0)
                        {
                            fs.Position = entry.Address;
                            return(br.ReadBytes((int)(entry.Length == -1 ? fs.Length - fs.Position : entry.Length)));
                        }
                        else
                        {
                            return(new byte[0]);
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
                Console.WriteLine(exc.StackTrace);
            }

            return(null);
        }
Example #24
0
        public void ListBundle(PackageHeader bundle, string bundle_id)
        {
            this.ListOutput.WriteBundle(bundle, bundle_id);

            if (this.ListOutput.ListOptions.EntryInfo.Count > 0)
            {
                for (; current_bundle_progress < current_bundle_total_progress; current_bundle_progress++)
                {
                    PackageFileEntry be = bundle.Entries[(int)current_bundle_progress];
                    if (this.terminate)
                    {
                        break;
                    }

                    this.ListOutput.WriteEntry(be);
                }
            }
            else
            {
                current_bundle_progress++;
            }
        }
Example #25
0
        public override void WriteEntry(PackageFileEntry entry)
        {
            if (ListOptions.EntryInfo.Count == 0)
            {
                return;
            }

            if (this.WriteEmptyBundleColumns && this.ListOptions.BundleInfo.Count > 0)
            {
                for (int i = 0; i < this.ListOptions.BundleInfo.Count - 1; i++)
                {
                    this.Output.Append(",");
                }
            }

            for (int i = 0; i < this.ListOptions.EntryInfo.Count; i++)
            {
                ListEntryOption opt = this.ListOptions.EntryInfo[i];
                this.Output.Append((i == 0 && this.ListOptions.BundleInfo.Count == 0 ? "" : ",") + "\"" + opt.StringFunc(Parent, entry) + "\"");
            }
            this.Output.AppendLine();
            this.WriteEmptyBundleColumns = true;
        }
Example #26
0
        public object FileData(PackageFileEntry be = null, dynamic exporter = null)
        {
            if (exporter == null)
            {
                return(this.FileStream(be));
            }
            else
            {
                MemoryStream stream = this.FileStream(be);

                if (exporter != null && !((exporter.GetType().GetMethod("export") != null) || exporter.export != null))
                {
                    throw new InvalidDataException("Inputted exporter does not contain a method definition for export!");
                }

                if (stream == null)
                {
                    return(null);
                }
                object data = exporter.export(stream);
                //stream.Close();
                return(data);
            }
        }
Example #27
0
        private static IEnumerable <string> ProcessWorld(FileEntry fe, PackageFileEntry pfe, Dictionary <string, object> root)
        {
            IEnumerable <string> subordinateFiles = null;

            if (fe.PathIds.HasUnHashed)
            {
                subordinateFiles = ScriptDataQuery.Concat(
                    root.EntryTable("ai_nav_graphs").Entry <string>("file"),
                    root.EntryTable("brush").Entry <string>("file"),
                    root.EntryTable("sounds").Entry <string>("file"),
                    root.EntryTable("world_camera").Entry <string>("file"),
                    root.EntryTable("world_data").Entry <string>("continents_file"),
                    Enumerable.Repeat("cover_data", 1)
                    ).Select(i => fe.Parent.EntryPath + "/" + i);
            }

            var env = root.EntryTable("environment");

            return(ScriptDataQuery.Concat(
                       env.EntryTable("environment_areas").TableChildren().Entry <string>("environment"),
                       env.EntryTable("environment_values").Entry <string>("environment"),
                       env.EntryTable("effects").TableChildren().Entry <string>("name"),
                       subordinateFiles));
        }
 public PackageFileViewModel(PackageFileEntry entry) => _entry = entry;
Example #29
0
        public void ViewFile(FileEntry entry, PackageFileEntry be = null)
        {
            try
            {
                if (entry.BundleEntries.Count == 0)
                {
                    return;
                }

                string  typ      = Definitions.TypeFromExtension(entry._extension.ToString());
                dynamic exporter = null;

                if (ScriptActions.Converters.ContainsKey(typ))
                {
                    SaveOptionsDialog dlg    = new SaveOptionsDialog(typ);
                    DialogResult      dlgres = dlg.ShowModal();

                    if (dlgres == DialogResult.Cancel)
                    {
                        return;
                    }
                    exporter = dlg.SelectedExporter;
                }

                //Thread thread = new Thread(() =>
                //{
                TempFile temp = this.GetTempFile(entry, be, exporter);
                //{
                GC.Collect();
                ProcessStartInfo pi = new ProcessStartInfo(temp.Path);

                pi.UseShellExecute = true;
                if (General.IsLinux)
                {
                    pi.Arguments = temp.Path;
                    pi.FileName  = "xdg-open";
                }
                else
                {
                    pi.FileName = temp.Path;
                }

                Process proc = Process.Start(pi);
                //temp.RunProcess = proc;
                if (!this.TempFiles.ContainsKey(entry))
                {
                    this.TempFiles.Add(entry, temp);
                }

                /*if (proc == null)//seconds -> milliseconds
                 *  Thread.Sleep(20 * 1000);
                 * proc?.WaitForExit();
                 * while((!(proc?.HasExited ?? true)))
                 * { }
                 *
                 * if (General.IsLinux && (proc?.ExitCode == 3 || proc?.ExitCode == 4))
                 *  Console.WriteLine("No default file association for filetype {0}", Path.GetExtension(temp.Path));
                 *
                 * while (!this.IsFileAvailable(temp.Path))
                 * {
                 *  Console.WriteLine("Waiting on file");
                 * }
                 * }
                 * this.TempFiles.Remove(entry);*/
                //});
                //thread.IsBackground = true;
                //thread.Start();
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
                Console.WriteLine(exc.StackTrace);
            }
        }
Example #30
0
 public static void GenerateHashlist(string workingPath, string file, PackageFileEntry be)
 {
     ReadHashlistAndLoad(file, be);
     HashIndex.GenerateHashList(Path.Combine(workingPath, HashlistFile));
 }