Example #1
0
    /*private void ProcessFolder(IParent folder)
     * {
     *  foreach (IChild child in folder.Children.Values)
     *  {
     *      if (child is FileEntry)
     *          this.ProcessFile(child as FileEntry);
     *      else if (child is IParent)
     *          this.ProcessFolder(child as IParent);
     *  }
     * }*/

    private void WriteFile(FileEntry entry, byte[] byt = null)
    {
        Idstring ids = HashIndex.Get(entry.Path);

        if (entry.BundleEntries.Count == 0 || this.ExtractedPaths.Contains(ids))
        {
            return;
        }

        string path   = Path.Combine(this.OutputPath, entry.Path);
        string folder = Path.GetDirectoryName(path);

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

        byte[] bytes = byt ?? entry.FileBytes() ?? new byte[0];

        File.WriteAllBytes(path, bytes);
        this.ExtractedPaths.Add(ids);
    }
Example #2
0
        public static void GetFilepath(DatabaseEntry dbEntry, out Idstring path, out Idstring language, out Idstring extension, PackageDatabase BundleDB = null)
        {
            path = dbEntry.Path;

            if (dbEntry.Language != 0)
            {
                if (BundleDB == null)
                {
                    language = new Idstring(dbEntry.Language);
                }
                else
                {
                    language = BundleDB.LanguageFromID(dbEntry.Language)?.Name ?? new Idstring(dbEntry.Language.ToString(), true);
                }
            }
            else
            {
                language = null;
            }

            extension = dbEntry.Extension;
        }
Example #3
0
        public List <object> ChildObjects(Idstring pck = null)
        {
            List <object> objs = new List <object>();

            foreach (KeyValuePair <string, IChild> kvp in this.Children)
            {
                if (kvp.Value is IParent && (pck == null || ((IParent)kvp.Value).ContainsAnyBundleEntries(pck)))
                {
                    objs.Add(kvp.Value);
                }
            }

            foreach (KeyValuePair <string, IChild> kvp in this.Children)
            {
                if (kvp.Value is IChild && (!(kvp.Value is FileEntry) || pck == null || ((FileEntry)kvp.Value).BundleEntries.FindIndex(item => item.Parent.Name.Equals(pck)) != -1) && !(kvp.Value is IParent))
                {
                    objs.Add(kvp.Value);
                }
            }

            return(objs);
        }
        public List <object> ChildObjects(Idstring pck = null)
        {
            List <object> objs     = new List <object>();
            var           children = Children.Values;

            foreach (var child in children)
            {
                if (child is FolderEntry entry && (pck == null || entry.ContainsAnyBundleEntries(pck)))
                {
                    objs.Add(child);
                }
            }

            foreach (var child in children)
            {
                if ((!(child is FileEntry entry) || pck == null || entry.BundleEntries.ContainsKey(pck)) && !(child is FolderEntry))
                {
                    objs.Add(child);
                }
            }

            return(objs);
        }
        public bool ContainsAnyBundleEntries(Idstring package = null)
        {
            foreach (KeyValuePair <string, IEntry> entry in Children)
            {
                if (entry.Value is FolderEntry)
                {
                    FolderEntry _entry = entry.Value as FolderEntry;
                    if (_entry.ContainsAnyBundleEntries(package))
                    {
                        return(true);
                    }
                }
                else if (entry.Value is FileEntry)
                {
                    FileEntry _entry = entry.Value as FileEntry;
                    if (_entry.BundleEntries.Count != 0 && (package != null ? _entry.BundleEntries.ContainsKey(package) : true))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #6
0
        /*public void AddToTree(TreeViewItem item, string package)
         * {
         *  foreach (KeyValuePair<string, FolderStruct> entry in this.folders)
         *  {
         *      if (!entry.Value.ContainsAnyBundleEntries() && !entry.Value.ContainsAnyBundleEntries(package))
         *          continue;
         *
         *      TreeViewItem treeItem = new TreeViewItem()
         *      {
         *          Header = entry.Key,
         *          Tag = entry.Value,
         *          HeaderTemplate = item.HeaderTemplate
         *      };
         *      item.Items.Add(treeItem);
         *      entry.Value.AddToTree(treeItem);
         *  }
         * }*/

        /*public void AddToBreadcrumb(BreadcrumbItem brdItem)
         * {
         *  foreach (KeyValuePair<string, FolderStruct> entry in this.folders)
         *  {
         *      if (!entry.Value.ContainsAnyBundleEntries())
         *          continue;
         *
         *      BreadcrumbItem subBrdItem = new BreadcrumbItem()
         *      {
         *          Header = entry.Key,
         *          Tag = entry.Value,
         *          Image = (ImageSource)App.Current.FindResource("Icon_FolderClosed")
         *      };
         *      brdItem.Items.Add(subBrdItem);
         *      entry.Value.AddToBreadcrumb(subBrdItem);
         *  }
         * }*/

        public bool ContainsAnyBundleEntries(Idstring package = null)
        {
            foreach (KeyValuePair <string, IChild> entry in this._children)
            {
                if (entry.Value is IParent)
                {
                    IParent _entry = entry.Value as IParent;
                    if (_entry.ContainsAnyBundleEntries(package))
                    {
                        return(true);
                    }
                }
                else if (entry.Value is FileEntry)
                {
                    FileEntry _entry = entry.Value as FileEntry;
                    if (_entry.BundleEntries.Count != 0 && (package != null ? _entry.BundleEntries.FindIndex(ent => ent.Parent.Name.Equals(package)) != -1 : true))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #7
0
        public void AddToTree(TreeItem item, Idstring pck = null)
        {
            foreach (KeyValuePair <string, IChild> entry in this._children)
            {
                if (entry.Value is IParent)
                {
                    IParent _entry = entry.Value as IParent;

                    if (pck != null && !_entry.ContainsAnyBundleEntries(pck))
                    {
                        continue;
                    }

                    TreeItem treeItem = new TreeItem()
                    {
                        Text  = entry.Key,
                        Image = this.Icon,
                        Tag   = entry.Value
                    };
                    item.Children.Add(treeItem);
                    _entry.AddToTree(treeItem, pck);
                }
            }
        }
Example #8
0
    private void ProcessWorld(FileEntry file)
    {
        foreach (KeyValuePair <string, IChild> child in file.Parent.Children)
        {
            if (child.Value is FileEntry)
            {
                this.WriteFile(child.Value as FileEntry);
            }
        }

        this.WriteFile(file);
        this.ProcessScriptData(file, new List <XMLTagLookup> {
            new XMLTagLookup {
                node_name = "environment_values", value = new[] { "environment" }, Converter = (hash) => { return(hash + ".environment"); }
            }
        });

        string   continents_file = Path.Combine(Path.GetDirectoryName(file.Path), "continents").Replace("\\", "/");
        Idstring ids             = HashIndex.Get(continents_file);
        var      t_ids           = new Tuple <Idstring, Idstring, Idstring>(ids, new Idstring(0), HashIndex.Get("continents"));

        if (this._browser.RawFiles.ContainsKey(t_ids))
        {
            FileEntry c_file = this._browser.RawFiles[t_ids];
            this.WriteFile(c_file);

            string xml = ScriptActions.GetConverter("scriptdata", "script_cxml").export(c_file.FileStream(), true);

            XmlDocument doc = new XmlDocument();

            try
            {
                doc.LoadXml(xml);
                foreach (XmlNode child in doc.ChildNodes[0])
                {
                    this.ProcessFile(Path.Combine(Path.GetDirectoryName(file.Path), string.Format("{0}/{0}.continent", child.Attributes.GetNamedItem("name").Value)).Replace("\\", "/"));
                }
            }
            catch (Exception exc)
            {
                this.error_output.Write("Exception occured on file: {0}\n", c_file.Path);
                if (xml != null)
                {
                    this.error_output.Write(xml + "\n");
                }
                this.error_output.Write(exc.Message + "\n");
                this.error_output.Write(exc.StackTrace + "\n");
                this.error_output.Flush();
                return;
            }
        }
        else
        {
            this.error_output.Write("Continents file {0} does not exist!\n", continents_file);
        }

        string   mission_file = Path.Combine(Path.GetDirectoryName(file.Path), "mission").Replace("\\", "/");
        Idstring m_ids        = HashIndex.Get(mission_file);
        var      t_m_ids      = new Tuple <Idstring, Idstring, Idstring>(m_ids, new Idstring(0), HashIndex.Get("mission"));

        if (this._browser.RawFiles.ContainsKey(t_m_ids))
        {
            FileEntry m_file = this._browser.RawFiles[t_m_ids];
            this.WriteFile(m_file);

            string xml = ScriptActions.GetConverter("scriptdata", "script_cxml").export(m_file.FileStream(), true);

            XmlDocument doc = new XmlDocument();

            try
            {
                doc.LoadXml(xml);
                foreach (XmlNode child in doc.ChildNodes[0])
                {
                    this.ProcessFile(Path.Combine(Path.GetDirectoryName(file.Path), string.Format("{0}.mission", child.Attributes.GetNamedItem("file").Value)).Replace("\\", "/"));
                }
            }
            catch (Exception exc)
            {
                this.error_output.Write("Exception occured on file: {0}\n", m_file.Path);
                if (xml != null)
                {
                    this.error_output.Write(xml + "\n");
                }
                this.error_output.Write(exc.Message + "\n");
                this.error_output.Write(exc.StackTrace + "\n");
                this.error_output.Flush();
                return;
            }
        }
        else
        {
            this.error_output.Write("Mission file {0} does not exist!\n", continents_file);
        }

        this.error_output.Flush();
    }
Example #9
0
        protected void ReadFile(BinaryReader _br)
        {
            br = _br;
            uint bnk_count = br.ReadUInt32();

            //Skip second count
            br.BaseStream.Position += 4;
            uint bnk_offset      = br.ReadUInt32();
            uint section_pointer = br.ReadUInt32();
            uint unknown1        = br.ReadUInt32();

            uint sound_count = br.ReadUInt32();

            //Skip second count
            br.BaseStream.Position += 4;
            uint sound_offset = br.ReadUInt32();

            //Skips section pointer, unknown1, unknown2
            br.BaseStream.Position += 12;

            uint u_count = br.ReadUInt32();

            //Skip second count
            br.BaseStream.Position += 4;
            uint u_offset = br.ReadUInt32();

            br.BaseStream.Position = bnk_offset;

            for (int i = 0; i < bnk_count; i++)
            {
                br.BaseStream.Position += 4;
                uint position = br.ReadUInt32();
                this.SeekPush();
                br.BaseStream.Position = position;
                Soundbanks.Add(this.ReadString());
                this.SeekPop();
            }

            br.BaseStream.Position = sound_offset;

            Dictionary <ulong, uint> sound_lookups = new Dictionary <ulong, uint>();

            for (int i = 0; i < sound_count; i++)
            {
                uint  id   = (uint)br.ReadUInt64();
                ulong hash = br.ReadUInt64();
                if (sound_lookups.ContainsKey(hash))
                {
                    uint other_id = sound_lookups[hash];
                    continue;
                }

                sound_lookups.Add(hash, id);
            }

            br.BaseStream.Position = u_offset;

            for (int i = 0; i < u_count; i++)
            {
                ulong hash = br.ReadUInt64();
                br.BaseStream.Position += 4;
                uint string_pos = br.ReadUInt32();
                this.SeekPush();
                br.BaseStream.Position = string_pos;
                string str = this.ReadString();
                this.SeekPop();
                if (!sound_lookups.ContainsKey(hash))
                {
                    continue;
                }
                uint id = sound_lookups[hash];
                if (SoundLookups.ContainsKey(id))
                {
                    continue;
                }

                Idstring ids = HashIndex.Get(hash);

                SoundLookups.Add(id, new Tuple <string, Idstring>(id.ToString() != str ? str : null, ids));
            }
        }
 public ListBundle(Idstring ids)
 {
     Ids  = ids;
     Name = ids.ToString();
 }
Example #11
0
 public MassUnitHeader(Idstring Unit, List <Vector3> Positions, List <Quaternion> Rotations)
 {
     this.Unit      = Unit;
     this.Positions = Positions;
     this.Rotations = Rotations;
 }