Example #1
0
        public static unsafe ResourceNode FromSource(ResourceNode parent, DataSource source)
        {
            ResourceNode n = null;

            if ((n = GetRaw(source)) != null)
            {
                n.Initialize(parent, source);
            }
            else
            {
                //Check for compression?
                if (Compressor.IsDataCompressed(source.Address, source.Length))
                {
                    if ((*(uint *)source.Address) == YAZ0.Tag)
                    {
                        YAZ0 *cmpr = (YAZ0 *)source.Address;
                        try
                        {
                            //Expand the whole resource and initialize
                            FileMap map = FileMap.FromTempFile((int)cmpr->_unCompDataLen);
                            Compressor.Expand(cmpr, map.Address, map.Length);
                            source.Compression = CompressionType.RunLength;

                            //Check for a match
                            if ((n = GetRaw(new DataSource(map.Address, map.Length))) != null)
                            {
                                n.Initialize(parent, source, new DataSource(map));
                            }
                        }
                        catch (InvalidCompressionException e) { MessageBox.Show(e.ToString()); }
                    }
                    else
                    {
                        CompressionHeader *cmpr = (CompressionHeader *)source.Address;
                        if (Compressor.Supports(cmpr->Algorithm))
                        {
                            try
                            {
                                //Expand a portion of the data
                                byte *buffer = stackalloc byte[CompressBufferLen];
                                Compressor.Expand(cmpr, buffer, CompressBufferLen);

                                //Check for a match
                                if ((n = GetRaw(new DataSource(buffer, CompressBufferLen))) != null)
                                {
                                    //Expand the whole resource and initialize
                                    FileMap map = FileMap.FromTempFile(cmpr->ExpandedSize);
                                    Compressor.Expand(cmpr, map.Address, map.Length);
                                    source.Compression = cmpr->Algorithm;
                                    n.Initialize(parent, source, new DataSource(map));
                                }
                            }
                            catch (InvalidCompressionException e) { MessageBox.Show(e.ToString()); }
                        }
                    }
                }
            }

            return(n);
        }
Example #2
0
        public static ResourceNode FromFile(ResourceNode parent, string path, FileOptions options)
        {
            ResourceNode node = null;
            FileMap      map  = FileMap.FromFile(path, FileMapProtect.Read, 0, 0, options);

            try
            {
                DataSource source = new DataSource(map);
                if ((node = FromSource(parent, source)) == null)
                {
                    string ext = path.Substring(path.LastIndexOf('.') + 1).ToUpper(CultureInfo.InvariantCulture);

                    if (Forced.ContainsKey(ext) &&
                        (node = Activator.CreateInstance(Forced[ext]) as ResourceNode) != null)
                    {
                        FileMap uncompressedMap = Compressor.TryExpand(ref source, false);
                        if (uncompressedMap != null)
                        {
                            node.Initialize(parent, source, new DataSource(uncompressedMap));
                        }
                        else
                        {
                            node.Initialize(parent, source);
                        }
                    }
#if DEBUG
                    else
                    {
                        node = new RawDataNode(Path.GetFileNameWithoutExtension(path));
                        node.Initialize(parent, source);
                    }
#endif
                }
            }
            finally
            {
                if (node == null)
                {
                    map.Dispose();
                }
            }

            return(node);
        }
Example #3
0
        public static unsafe ResourceNode FromSource(ResourceNode parent, DataSource source)
        {
            ResourceNode n = null;

            if ((n = GetRaw(source)) != null)
            {
                n.Initialize(parent, source);
            }
            else
            {
                FileMap    uncomp = Compressor.TryExpand(ref source);
                DataSource d;
                if (uncomp != null && (n = NodeFactory.GetRaw(d = new DataSource(uncomp))) != null)
                {
                    n.Initialize(parent, source, d);
                }
            }
            return(n);
        }
Example #4
0
        public static ResourceNode FromFile(ResourceNode parent, string path, FileOptions options, Type t)
        {
            ResourceNode node = null;
            FileMap      map  = FileMap.FromFile(path, FileMapProtect.Read, 0, 0, options);

            try
            {
                DataSource source = new DataSource(map);

                bool supportsCompression = true;
                if (!(t is null))
                {
                    ResourceNode n = Activator.CreateInstance(t) as ResourceNode;
                    supportsCompression = n?.supportsCompression ?? true;
                }

                if ((node = FromSource(parent, source, t, supportsCompression)) == null)
                {
                    string ext = path.Substring(path.LastIndexOf('.') + 1).ToUpper(CultureInfo.InvariantCulture);

                    if (!(t is null) && (node = Activator.CreateInstance(t) as ResourceNode) != null ||
                        ForcedExtensions.ContainsKey(ext) &&
                        (node = Activator.CreateInstance(ForcedExtensions[ext]) as ResourceNode) != null)
                    {
                        FileMap uncompressedMap = Compressor.TryExpand(ref source, false);
                        if (uncompressedMap != null)
                        {
                            node.Initialize(parent, source, new DataSource(uncompressedMap));
                        }
                        else
                        {
                            node.Initialize(parent, source);
                        }
                    }
                    else
                    {
                        node = new RawDataNode(Path.GetFileName(path));
                        node.Initialize(parent, source);
                    }
                }
            }
Example #5
0
        //Parser commands must initialize the node before returning.
        public unsafe static ResourceNode FromFile(ResourceNode parent, string path, FileOptions options = FileOptions.RandomAccess)
        {
            ResourceNode node = null;
            FileMap      map  = FileMap.FromFile(path, FileMapProtect.Read, 0, 0, options);

            try
            {
                DataSource source = new DataSource(map);
                if ((node = FromSource(parent, source)) == null)
                {
                    string ext = path.Substring(path.LastIndexOf('.') + 1).ToUpper();
                    if (Forced.ContainsKey(ext))
                    {
                        node = Activator.CreateInstance(Forced[ext]) as ResourceNode;
                        FileMap uncomp = Compressor.TryExpand(ref source, false);
                        if (uncomp != null)
                        {
                            node.Initialize(parent, source, new DataSource(uncomp));
                        }
                        else
                        {
                            node.Initialize(parent, source);
                        }
                    }
                    else if (UseRawDataNode)
                    {
                        (node = new RawDataNode(Path.GetFileNameWithoutExtension(path))).Initialize(parent, source);
                    }
                }
            }
            finally
            {
                if (node == null)
                {
                    map.Dispose();
                }
            }
            return(node);
        }
        public override void OnPopulate()
        {
            VoidPtr baseAddress = WorkingUncompressed.Address + sizeof(Common2TblHeader);

            int               dataLength  = Header->_DataLength;
            VoidPtr           offsetTable = baseAddress + dataLength + Header->_OffCount * 4;
            VoidPtr           stringList  = offsetTable + Header->_DataTable * 8;
            List <OffsetPair> offsets     = new List <OffsetPair>();

            bint *ptr = (bint *)offsetTable;

            for (int i = 0; i < Header->_DataTable; i++)
            {
                OffsetPair o = new OffsetPair
                {
                    dataOffset = *ptr++,
                    nameOffset = *ptr++
                };
                offsets.Add(o);
            }

            offsets = offsets.OrderBy(o => o.dataOffset).ToList();
            for (int i = 1; i < offsets.Count; i++)
            {
                offsets[i - 1].dataEnd = offsets[i].dataOffset;
            }

            offsets[offsets.Count - 1].dataEnd = dataLength;

            foreach (OffsetPair o in offsets)
            {
                if (o.dataEnd <= o.dataOffset)
                {
                    throw new Exception("Invalid data length (less than data offset) in common2 data");
                }

                DataSource   source = new DataSource(baseAddress + o.dataOffset, o.dataEnd - o.dataOffset);
                string       name   = new string((sbyte *)stringList + o.nameOffset);
                ResourceNode node   =
                    name.StartsWith("eventStage") ? new EventMatchNode()
                    : name.StartsWith("allstar") ? new AllstarStageTblNode()
                    : name.StartsWith("simpleStage") ? new ClassicStageTblNode()
                    : name == "sndBgmTitleData" ? new SndBgmTitleDataNode()
                    : (ResourceNode) new ClassicStageTblSizeTblNode();
                node.Initialize(this, source);
                node.Name       = name;
                node.HasChanged = false;
            }
        }
Example #7
0
        public static unsafe ResourceNode FromSource(ResourceNode parent, DataSource source)
        {
            ResourceNode n = null;

            if ((n = GetRaw(source)) != null)
            {
                n.Initialize(parent, source);
            }
            else
            {
                //Check for compression?
                if (Compressor.IsDataCompressed(source.Address, source.Length))
                {
                    CompressionHeader *cmpr = (CompressionHeader *)source.Address;
                    try
                    {
                        //Expand a portion of the data
                        byte *buffer = stackalloc byte[CompressBufferLen];
                        Compressor.Expand(cmpr, buffer, CompressBufferLen);

                        //Check for a match
                        if ((n = GetRaw(new DataSource(buffer, CompressBufferLen))) != null)
                        {
                            //Expand the whole resource and initialize
                            FileMap map = FileMap.FromTempFile(cmpr->ExpandedSize);
                            Compressor.Expand(cmpr, map.Address, map.Length);
                            source.Compression = cmpr->Algorithm;
                            n.Initialize(parent, source, new DataSource(map));
                        }
                    }
                    catch (InvalidCompressionException) { }
                }
            }

            return(n);
        }
Example #8
0
        public static ResourceNode FromSource(ResourceNode parent, DataSource source)
        {
            ResourceNode n = null;

            if ((n = GetRaw(source)) != null)
            {
                n.Initialize(parent, source);
            }
            else
            {
                FileMap uncomp = Compressor.TryExpand(ref source);
                if (uncomp != null)
                {
                    DataSource d = new DataSource(uncomp);
                    n = GetRaw(d);
                    n?.Initialize(parent, source, d);
                }
            }

            return(n);
        }
Example #9
0
        protected override void OnPopulate()
        {
            RSARHeader *rsar   = Header;
            INFOHeader *info   = Header->INFOBlock;
            VoidPtr     offset = &info->_collection;
            RuintList * list   = (RuintList *)info->_collection[_listIndex];
            int         count  = list->_numEntries;

            Type t;

            switch (_listIndex)
            {
            case 2:
                t = typeof(RSARTypeNode);
                break;  //Types

            case 3:     //Files
                INFOFileHeader * fileHeader;
                INFOFileEntry *  fileEntry;
                RuintList *      entryList;
                INFOGroupHeader *group;
                INFOGroupEntry * gEntry;
                RuintList *      groupList = info->Groups;
                RSARFileNode     n;
                DataSource       source;

                for (int i = 0; i < count; i++)
                {
                    fileHeader = (INFOFileHeader *)list->Get(offset, i);
                    entryList  = fileHeader->GetList(offset);
                    if (entryList->_numEntries == 0)
                    {
                        //Must be external file.
                        n            = new RSARExtFileNode();
                        n._fileIndex = i;
                        n.Initialize(this, fileHeader, 0);
                    }
                    else
                    {
                        //use first entry
                        fileEntry = (INFOFileEntry *)entryList->Get(offset, 0);
                        //Find group with matching ID
                        group = (INFOGroupHeader *)groupList->Get(offset, fileEntry->_groupId);
                        //Find group entry with matching index
                        gEntry = (INFOGroupEntry *)group->GetCollection(offset)->Get(offset, fileEntry->_index);

                        //Create node and parse
                        source = new DataSource((int)rsar + group->_headerOffset + gEntry->_headerOffset, gEntry->_headerLength);
                        if ((n = NodeFactory.GetRaw(source) as RSARFileNode) == null)
                        {
                            n = new RSARFileNode();
                        }

                        n._audioSource = new DataSource((int)rsar + group->_dataOffset + gEntry->_dataOffset, gEntry->_dataLength);
                        n._fileIndex   = i;
                        n.Initialize(this, source);
                    }
                }

                return;

            case 4:
                t = typeof(RSARGroupNode);
                break;     //Groups

            default:
                return;
            }


            for (int i = 0; i < count; i++)
            {
                ResourceNode node = Activator.CreateInstance(t) as ResourceNode;
                node.Initialize(this, list->Get(offset, i), 0);
            }

            base.OnPopulate();
        }