private bool CloseExternal()
        {
            if (_externalAnimationsNode != null)
            {
                if (_externalAnimationsNode.IsDirty)
                {
                    DialogResult res = MessageBox.Show(this, "You have made changes to an external file. Would you like to save those changes?", "Closing external file.", MessageBoxButtons.YesNoCancel);
                    if (((res == DialogResult.Yes) && (!SaveExternal(false))) || (res == DialogResult.Cancel))
                        return false;
                }

                ModelPanel.RemoveReference(_externalAnimationsNode);
                leftPanel._closing = true;
                leftPanel.listAnims.Items.Clear();
                leftPanel._closing = false;
                _externalAnimationsNode.Dispose();
                _externalAnimationsNode = null;

                if (SelectedBone != null)
                    SelectedBone._boneColor = SelectedBone._nodeColor = Color.Transparent;

                leftPanel.UpdateAnimations(TargetAnimType);
                SetAnimation(TargetAnimType, null);
                GetFiles(AnimType.None);
                UpdatePropDisplay();
                UpdateModel();
            }
            return true;
        }
 public static unsafe void Compact(CompressionType type, VoidPtr srcAddr, int srcLen, Stream outStream, ResourceNode r)
 {
     switch (type)
     {
         case CompressionType.LZ77: { LZ77.Compact(srcAddr, srcLen, outStream, r, false); break; }
         case CompressionType.ExtendedLZ77: { LZ77.Compact(srcAddr, srcLen, outStream, r, true); break; }
         case CompressionType.RunLength: { RunLength.Compact(srcAddr, srcLen, outStream, r); break; }
     }
 }
 public static void PrintPath(ResourceNode n)
 {
     if (n.HasChildren)
     {
         Console.WriteLine("{0}| {1}| {2}", (string.Join("...", new string[n.Level + 1]) + n.Name).PadRight(48), n.ResourceType.ToString().PadRight(10), n.Children.Count);
         Console.WriteLine(string.Join("...", new string[n.Level + 2]) + "| " + string.Join("-", new string[64 - (n.Level * 3)]));
         foreach (ResourceNode c in n.Children)
             PrintPath(c);
     }
     else
         Console.WriteLine("{0}| {1}|", (string.Join("...", new string[n.Level + 1]) + n.Name).PadRight(48),  n.ResourceType.ToString().PadRight(10));
 }
 public override void UpdateDirectory()
 {
     if (File.Exists("../info2/info.pac")) {
         string path = "../info2/info.pac";
         info_en = NodeFactory.FromFile(null, path);
         _openFilePath = path;
     } else if (File.Exists("../info2/info_en.pac")) {
         string path = "../info2/info_en.pac";
         info_en = NodeFactory.FromFile(null, path);
         _openFilePath = path;
     }
 }
        public DialogResult ShowDialog(IWin32Window owner, ResourceNode node)
        {
            _node = node;

            if (_node is ARCNode)
                txtName.MaxLength = 47;
            else
                txtName.MaxLength = 255;

            txtName.Text = node.Name;

            try { return base.ShowDialog(owner); }
            finally { _node = null; }
        }
        public static void Copy(ResourceNode scSelmap, ResourceNode muMenumain, CustomSSSCodeset sss)
        {
            ResourceNode miscData0 = muMenumain.FindChild("MiscData[0]", false);
            List<ResourceNode> chrToKeep = miscData0.FindChild("AnmChr(NW4R)", false).Children;
            Dictionary<string, string> tempFiles = new Dictionary<string, string>(chrToKeep.Count);
            foreach (ResourceNode n in chrToKeep) {
                string file = TempFiles.Create(".chr0");
                tempFiles.Add(n.Name, file);
                n.Export(file);
            }

            ResourceNode miscData80 = scSelmap.FindChild("MiscData[80]", false);
            miscData0.ReplaceRaw(miscData80.WorkingSource.Address, miscData80.WorkingSource.Length);
            miscData0.SignalPropertyChange();

            List<ResourceNode> chrToReplace = miscData0.FindChild("AnmChr(NW4R)", false).Children;
            foreach (ResourceNode n in chrToReplace) {
                string file = tempFiles[n.Name];
                n.Replace(file);
            }

            string xx_png = TempFiles.Create(".png");
            ResourceNode xx = miscData0.FindChild("Textures(NW4R)/MenSelmapIcon.XX", false);
            bool found = false;
            if (xx != null) {
                xx.Export(xx_png);
                found = true;
            } else {
                Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("BrawlStageManager.XX.png");
                if (stream != null) {
                    Image.FromStream(stream).Save(xx_png);
                    found = true;
                }
            }

            if (found) {
                foreach (ResourceNode tex in miscData0.FindChild("Textures(NW4R)", false).Children) {
                    byte icon_id;
                    if (tex.Name.StartsWith("MenSelmapIcon.") && Byte.TryParse(tex.Name.Substring(14, 2), out icon_id)) {
                        byte stage_id = sss.StageForIcon(icon_id);
                        if (icon_id != 100 && (stage_id == 0x25 || stage_id > 0x33)) {
                            tex.Replace(xx_png);
                        }
                    }
                }
            }
            File.Delete(xx_png);
        }
 private void LoadModels(ResourceNode node, List<MDL0Node> models)
 {
     switch (node.ResourceType)
     {
         case ResourceType.ARC:
         case ResourceType.U8:
         case ResourceType.U8Folder:
         case ResourceType.MRG:
         case ResourceType.BRES:
         case ResourceType.BRESGroup:
             foreach (ResourceNode n in node.Children)
                 LoadModels(n, models);
             break;
         case ResourceType.MDL0:
             AddTarget((MDL0Node)node);
             break;
     }
 }
Example #8
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 #9
0
        public static ResourceNode FindNode(ResourceNode root, string path, bool searchChildren)
        {
            if (String.IsNullOrEmpty(path))
            {
                return(root);
            }

            if (root.Name.Equals(path, StringComparison.OrdinalIgnoreCase))
            {
                return(root);
            }

            if ((path.Contains("/")) && (path.Substring(0, path.IndexOf('/')).Equals(root.Name, StringComparison.OrdinalIgnoreCase)))
            {
                return(root.FindChild(path.Substring(path.IndexOf('/') + 1), searchChildren));
            }

            return(root.FindChild(path, searchChildren));
        }
Example #10
0
        internal static ResourceNode TryParse(DataSource source, ResourceNode parent)
        {
            VoidPtr       addr   = source.Address;
            TyDataHeader *header = (TyDataHeader *)addr;

            if (header->_size != source.Length || header->_pad1 != 0 || header->_pad2 != 0 || header->_pad3 != 0 ||
                header->_pad4 != 0 || header->_dataOffset > source.Length || header->_entries <= 0 ||
                header->_dataOffset + header->_dataEntries * 4 > source.Length)
            {
                return(null);
            }

            if (!header->GetEntryName(0).StartsWith("ty"))
            {
                return(null);
            }

            return(new TyDataNode());
        }
Example #11
0
        internal virtual void Initialize(ResourceNode parent, DataSource origSource, DataSource uncompSource)
        {
            _origSource   = origSource;
            _uncompSource = uncompSource;
            _compression  = _origSource.Compression;

            if (origSource.Map != null)
            {
                _origPath = origSource.Map.FilePath;
            }

            Parent = parent;

            _children = null;
            if (!OnInitialize())
            {
                _children = new List <ResourceNode>();
            }
        }
Example #12
0
        public override void OnPopulate()
        {
            _originalHeaders.Clear();
            ARCFileHeader *entry = Header->First;

            for (int i = 0; i < Header->_numFiles; i++, entry = entry->Next)
            {
                DataSource   source      = new DataSource(entry->Data, entry->Length);
                ResourceNode createdNode = entry->Length == 0
                    ? null
                    : NodeFactory.FromSource(this, source);
                if (createdNode == null)
                {
                    createdNode = new ARCEntryNode();
                    createdNode.Initialize(this, source);
                }
                _originalHeaders.Add(createdNode, *entry);
            }
        }
Example #13
0
        public override bool OnInitialize()
        {
            if (_classNode == null)
            {
                return(false);
            }

            _className = _classNode.Name;

            HavokNode node = HavokNode;

            if (node._allSignatures.ContainsKey(_className))
            {
                _signature = HavokNode._allSignatures[_className];
            }

            node._dataSection._classCache.Add(this);

            if (_name == null)
            {
                _name = _classNode.Name;
            }

            _memberArray = new List <hkClassMemberNode>();

            //Youngest class has size for all inherited classes included
            if (_classNode._inheritance.Count > 0)
            {
                SetSizeInternal(_classNode._inheritance[0].Size);
            }

            foreach (hkClassNode c in _classNode._inheritance)
            {
                ResourceNode members = c.FindChild("Members", false);
                if (members != null)
                {
                    _memberArray.AddRange(members.Children.Select(x => x as hkClassMemberNode));
                }
            }

            return(_memberArray != null && _memberArray.Count > 0);
        }
        public override void OnPopulate()
        {
            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();
                o.dataOffset = *(ptr++);
                o.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()
                    : (ResourceNode) new RawDataNode();
                node.Initialize(this, source);
                node.Name       = name;
                node.HasChanged = false;
            }
        }
Example #15
0
        public ResourceNode FindChild(string path, bool searchChildren)
        {
            ResourceNode node = null;

            if (path.Contains("/"))
            {
                string next = path.Substring(0, path.IndexOf('/'));
                foreach (ResourceNode n in Children)
                {
                    if (n.Name != null && n.Name.Equals(next, StringComparison.OrdinalIgnoreCase))
                    {
                        if ((node = FindNode(n, path.Substring(next.Length + 1), searchChildren)) != null)
                        {
                            return(node);
                        }
                    }
                }
            }
            else
            {
                //Search direct children first
                foreach (ResourceNode n in Children)
                {
                    if (n.Name != null && n.Name.Equals(path, StringComparison.OrdinalIgnoreCase))
                    {
                        return(n);
                    }
                }
            }
            if (searchChildren)
            {
                foreach (ResourceNode n in Children)
                {
                    if ((node = n.FindChild(path, true)) != null)
                    {
                        return(node);
                    }
                }
            }

            return(null);
        }
Example #16
0
        public override void Initialize(ResourceNode parent, DataSource origSource, DataSource uncompSource)
        {
            base.Initialize(parent, origSource, uncompSource);

            if (parent != null && (parent is MRGNode || RootNode is U8Node))
            {
                _fileType      = 0;
                _fileIndex     = (short)Parent._children.IndexOf(this);
                _group         = 0;
                _redirectIndex = 0;

                if (_name == null)
                {
                    _name = GetName();
                }
            }
            else if (parent != null && !(parent is FileScanNode))
            {
                ARCFileHeader *header = (ARCFileHeader *)(origSource.Address - 0x20);
                _fileType      = header->FileType;
                _fileIndex     = header->_index;
                _group         = header->_groupIndex;
                _redirectIndex = header->_redirectIndex;

                if (_name == null)
                {
                    if (_redirectIndex != -1)
                    {
                        _resourceType = ResourceType.Redirect;
                        _name         = "Redirect → " + _redirectIndex;
                    }
                    else
                    {
                        _name = GetName();
                    }
                }
            }
            else if (_name == null)
            {
                _name = Path.GetFileName(_origPath);
            }
        }
Example #17
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 #18
0
        internal override void Initialize(ResourceNode parent, DataSource origSource, DataSource uncompSource)
        {
            base.Initialize(parent, origSource, uncompSource);

            if (parent != null)
            {
                ARCFileHeader *header = (ARCFileHeader *)(origSource.Address - 0x20);
                _fileType  = header->FileType;
                _fileIndex = header->_index;
                _fileFlags = header->_flags;
                _fileId    = header->_id;
                if (_name == null)
                {
                    _name = String.Format("{0}[{1}]", _fileType, _fileIndex);
                }
            }
            else if (_name == null)
            {
                _name = Path.GetFileName(_origPath);
            }
        }
Example #19
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 #20
0
        public override void OnRebuild(VoidPtr address, int length, bool force)
        {
            uint offset = 0x00;

            for (int i = 0; i < Children.Count; i++)
            {
                ResourceNode r = Children[i];
                r.Rebuild(address + offset, 2, true);
                offset += 2;
            }

            MasqueradeEntryNode end = new MasqueradeEntryNode(true);

            end.Rebuild(address + offset, 2, true);
            offset += 2;
            while (offset < Size)
            {
                MasqueradeEntryNode blank = new MasqueradeEntryNode(false);
                blank.Rebuild(address + offset, 2, true);
                offset += 2;
            }
        }
        internal static ResourceNode TryParse(DataSource source, ResourceNode parent)
        {
            PathingMiscData *p         = (PathingMiscData *)source.Address;
            uint             sizeCheck = PathingMiscData.HeaderSize + PathingMiscDataEntry.Size * p->_count;

            if (p->_headerSize == PathingMiscData.HeaderSize && source.Length > sizeCheck)
            {
                for (int i = 0; i < p->_count; i++)
                {
                    PathingMiscDataEntry *pe = (PathingMiscDataEntry *)(*p)[i];
                    sizeCheck += PathingMiscDataSubEntry.Size * pe->_count;
                    if (sizeCheck > source.Length)
                    {
                        return(null);
                    }
                }

                return(sizeCheck == source.Length ? new PathingMiscDataNode() : null);
            }

            return(null);
        }
Example #22
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);
        }
Example #23
0
        public T GetResource <T>(int index) where T : ResourceNode
        {
            ResourceNode folder = null;

            if (typeof(T) == typeof(RSARFileNode))
            {
                folder = FindChild("Files", false);
            }
            else if (typeof(T) == typeof(RSARTypeNode))
            {
                folder = FindChild("Types", false);
            }
            else if (typeof(T) == typeof(RSARGroupNode))
            {
                folder = FindChild("Groups", false);
            }

            if (folder != null)
            {
                return((T)folder.Children[index]);
            }
            return(null);
        }
Example #24
0
        internal static ResourceNode TryParse(DataSource source, ResourceNode parent)
        {
            int   length = source.Length;
            bint *offsets = (bint *)source.Address;
            int   index, last, current;

            for (index = 0, last = 0; last != length; index++)
            {
                if (index * 4 > source.Length)
                {
                    return(null);
                }

                current = offsets[index];
                if (current < last || current > length)
                {
                    return(null);
                }

                last = current;
            }

            // Ensure the offset is correctly bitshifted
            int offset      = offsets[0];
            int offsetCheck = 0;

            for (int i = 2; offsetCheck <= offset; i++)
            {
                offsetCheck = index << i;
                if (offsetCheck == offset)
                {
                    return(new MSBinNode());
                }
            }

            return(null);
        }
Example #25
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);
        }
        public DialogResult ShowDialog(ResourceNode o)
        {
            _target = o;

            b = new BackgroundWorker();
            b.RunWorkerCompleted += b_RunWorkerCompleted;
            b.DoWork += b_DoWork;
            b.WorkerSupportsCancellation = true;
            b.WorkerReportsProgress = false;

            _updating = true;
            Collada.ImportOptions i = BrawlLib.Properties.Settings.Default.ColladaImportOptions;
            numCacheSize.Value = i._cacheSize;
            numMinStripLen.Value = i._minStripLen;
            chkPushCacheHits.Checked = i._pushCacheHits;
            chkUseStrips.Checked = i._useTristrips;
            if (_target is MDL0Node)
            {
                if (((MDL0Node)_target)._objList != null)
                    foreach (MDL0ObjectNode w in ((MDL0Node)_target)._objList)
                        _results.Add(new ObjectOptimization(w));
                lblOldCount.Text = (_originalPointCount = ((MDL0Node)o)._numFacepoints).ToString();
            }
            else
            {
                _results.Add(new ObjectOptimization((MDL0ObjectNode)_target));
                lblOldCount.Text = (_originalPointCount = ((MDL0ObjectNode)o)._numFacepoints).ToString();
            }

            chkForceCCW.Checked = i._forceCCW;
            _updating = false;

            Optimize();

            return base.ShowDialog();
        }
        private ResourceNode CreatePath(ResourceNode parent, sbyte* str, int length)
        {
            ResourceNode current;

            int len;
            char* cPtr;
            sbyte* start, end;
            sbyte* ceil = str + length;
            while (str < ceil)
            {
                for (end = str; ((end < ceil) && (*end != '_')); end++) ;
                len = (int)end - (int)str;

                current = null;
                foreach (ResourceNode n in parent._children)
                {
                    if ((n._name.Length != len) || !(n is RSARFolderNode))
                        continue;

                    fixed (char* p = n._name)
                        for (cPtr = p, start = str; (start < end) && (*start == *cPtr); start++, cPtr++) ;

                    if (start == end)
                    {
                        current = n;
                        break;
                    }
                }
                if (current == null)
                {
                    current = new RSARFolderNode();
                    current._name = new String(str, 0, len);
                    current._parent = parent;
                    parent._children.Add(current);
                }

                str = end + 1;
                parent = current;
            }

            return parent;
        }
Example #28
0
 internal static ResourceNode TryParse(DataSource source, ResourceNode parent)
 {
     return(((BGMG *)source.Address)->_tag == BGMG.Tag ? new BGMGNode() : null);
 }
Example #29
0
        public void GetInheritance()
        {
            _inheritance = new List <hkClassNode>();
            ResourceNode current = this;

            //First, get classes inheriting this one
TOP:
            bool found = false;

            if (current != null)
            {
                foreach (HavokSectionNode section in HavokNode.Children)
                {
                    if (section._classCache != null && section != HavokNode._dataSection)
                    {
                        foreach (HavokClassNode c in section._classCache)
                        {
                            hkClassNode x = c as hkClassNode;
                            if (x != null && x != this && x.ParentClass == current.Name)
                            {
                                current = x;
                                _inheritance.Insert(0, x);
                                found = true;
                                break;
                            }
                        }
                    }

                    if (found)
                    {
                        break;
                    }
                }
            }

            if (found)
            {
                goto TOP;
            }

            current = this;

            //Now add this class and the classes it inherits
            while (current is hkClassNode)
            {
                hkClassNode cNode = (hkClassNode)current;

                _inheritance.Add(cNode);

                if (HavokNode.AssignClassParents)
                {
                    current = current.Parent;
                }

                //else if (!string.IsNullOrEmpty(cNode.ParentClass))
                //{
                //    current = null;
                //    HavokClassNode parent = HavokNode.GetClassNode(cNode.ParentClass);
                //    if (parent is hkClassNode)
                //    {
                //        current = parent;
                //    }
                //}
            }

            //Start with the eldest class, added last
            _inheritance.Reverse();
        }
        private bool LoadExternal()
        {
            dlgOpen.Filter = "All Compatible Files (*.pac, *.pcs, *.brres, *.chr0, *.srt0, *.pat0, *.vis0, *.shp0, *.scn0, *.clr0, *.mrg)|*.pac;*.pcs;*.brres;*.chr0;*.srt0;*.pat0;*.vis0;*.shp0;*.scn0;*.clr0;*.mrg";
            if (dlgOpen.ShowDialog() == DialogResult.OK)
            {
                ResourceNode node = null;
                leftPanel.listAnims.BeginUpdate();
                try
                {
                    if ((node = NodeFactory.FromFile(null, dlgOpen.FileName)) != null)
                    {
                        if (!CloseExternal())
                            return false;

                        if (!leftPanel.LoadAnims(node, TargetAnimType))
                            MessageBox.Show(this, "No animations could be found in external file.", "Error");
                        else
                        {
                            _externalAnimationsNode = node;
                            node = null;
                            //txtExtPath.Text = Path.GetFileName(dlgOpen.FileName);

                            ModelPanel.AddReference(_externalAnimationsNode);

                            return true;
                        }
                    }
                    else
                        MessageBox.Show(this, "Unable to recognize input file.");
                }
                catch (Exception x) { MessageBox.Show(this, x.ToString()); }
                finally
                {
                    if (node != null)
                        node.Dispose();
                    leftPanel.listAnims.EndUpdate();
                }
            }
            return false;
        }
Example #31
0
        /// <summary>
        /// This function finds the new info.pac. It should be called whenever you change the working directory.
        /// It also clears the list of edited ("dirty") strings, and records the current names (for the "restore" button).
        /// </summary>
        public String findInfoFile()
        {
            _index = -1;

            info = info_training = null;
            _currentFile = _currentTrainingFile = null;

            string tempfile = Path.GetTempFileName();
            if (new FileInfo("MiscData[140].msbin").Exists) {
                _currentFile = "MiscData[140].msbin";
                File.Copy("MiscData[140].msbin", tempfile, true);
                info = NodeFactory.FromFile(null, tempfile) as MSBinNode;
                return "Loaded .\\MiscData[140].msbin";
            } else if (new FileInfo("\\MiscData[140].msbin").Exists) {
                _currentFile = "\\MiscData[140].msbin";
                File.Copy("\\MiscData[140].msbin", tempfile, true);
                info = NodeFactory.FromFile(null, tempfile) as MSBinNode;
                return "Loaded \\MiscData[140].msbin";
            } else {
                string[] infopaths = { "..\\..\\info2\\info.pac", "..\\..\\info2\\info_en.pac", "..\\info.pac" };

                foreach (string relativepath in infopaths) {
                    if (info == null) {
                        string s = Path.GetFullPath(relativepath);
                        if (new FileInfo(s).Exists) {
                            _currentFile = s;
                            File.Copy(s, tempfile, true);
                            info_pac = NodeFactory.FromFile(null, tempfile);
                            info = (MSBinNode)info_pac.FindChild("MiscData[140]", true);
                        }
                    }
                }

                if (info == null) {
                    return "No song list loaded";
                } else {
                    modifiedStringIndices.Clear();
                    copyIntoFileStrings();

                    // info found; try info_training in same directory
                    string trainingpath = _currentFile.Replace("info.pac", "info_training.pac").Replace("info_en.pac", "info_training_en.pac");
                    if (trainingpath != _currentFile && new FileInfo(trainingpath).Exists) {
                        _currentTrainingFile = trainingpath;
                        string tempfile_training = Path.GetTempFileName();
                        File.Copy(trainingpath, tempfile_training, true);
                        info_training_pac = NodeFactory.FromFile(null, tempfile_training);
                        info_training = (MSBinNode)info_training_pac.FindChild("MiscData[140]", true);
                        return "Loaded info.pac and info_training.pac";
                    } else {
                        return "Loaded info.pac";
                    }
                }
            }
        }
Example #32
0
 internal static ResourceNode TryParse(DataSource source, ResourceNode parent)
 {
     return(((RWAR *)source.Address)->_header._tag == RWAR.Tag ? new RWARNode() : null);
 }
Example #33
0
        public void Open(FileInfo fi, string fallbackDir = null)
        {
            LastFileCalledFor = fi.FullName;
            lblFilename.Text = Path.GetFileNameWithoutExtension(LastFileCalledFor);

            if (_rootNode != null) {
                _rootNode.Dispose();
                _rootNode = null;
            }

            if (fi.Exists) {
                _rootPath = fi.FullName;
                _rootNode = NodeFactory.FromFile(null, _rootPath);
            } else if (fallbackDir != null) {
                FileInfo fallback = new FileInfo(fallbackDir + Path.DirectorySeparatorChar + fi.Name);
                if (fallback.Exists) {
                    _rootPath = null;
                    _rootNode = NodeFactory.FromFile(null, fallback.FullName);
                }
            }
            if (LoadNames) {
                string filename = Path.GetFileNameWithoutExtension(LastFileCalledFor).ToUpper();
                int index = (from s in SongIDMap.Songs
                             where s.Filename == filename
                             select s.InfoPacIndex ?? -1)
                             .DefaultIfEmpty(-1).First();
                songNameBar.Index = index;
            } else {
                songNameBar.Index = -1;
            }
            if (LoadBrstms && _rootNode is IAudioSource) {
                grid.SelectedObject = _rootNode;
                app.TargetSource = _rootNode as IAudioSource;
                app.Enabled = grid.Enabled = true;
            } else {
                grid.SelectedObject = null;
                app.TargetSource = null;
                app.Enabled = grid.Enabled = false;
            }
        }
Example #34
0
 private MDL0Node findFirstMDL0(ResourceNode root)
 {
     if (root is MDL0Node) {
         return (MDL0Node)root;
     }
     foreach (ResourceNode node in root.Children) {
         MDL0Node result = findFirstMDL0(node);
         if (result != null) {
             return result;
         }
     }
     return null;
 }
Example #35
0
 private List<MDL0Node> findAllMDL0s(ResourceNode root)
 {
     List<MDL0Node> list = new List<MDL0Node>();
     if (root is MDL0Node) {
         list.Add((MDL0Node)root);
     } else {
         foreach (ResourceNode node in root.Children) {
             list.AddRange(findAllMDL0s(node));
         }
     }
     return list;
 }
Example #36
0
 internal static ResourceNode TryParse(DataSource source, ResourceNode parent)
 {
     return(((AIPD *)source.Address)->_tag == AIPD.Tag ? new AIPDNode() : null);
 }
 public void pnlAnim_ReferenceLoaded(ResourceNode node)
 {
     modelPanel.AddReference(node);
 }
 public override void AddChild(ResourceNode child, bool change)
 {
     if (child is MDL0GroupNode)
         LinkGroup(child as MDL0GroupNode);
     base.AddChild(child, change);
 }
 public override void RemoveChild(ResourceNode child)
 {
     if (child is MDL0GroupNode)
         UnlinkGroup(child as MDL0GroupNode);
     base.RemoveChild(child);
 }
Example #40
0
        public void Close()
        {
            if (_rootNode != null) {
                _rootNode.Dispose();
                _rootNode = null;
            }
            _rootPath = null;

            grid.SelectedObject = null;
            app.TargetSource = null;
            app.Enabled = grid.Enabled = false;
            lblFilename.Text = "";
            songNameBar.Index = -1;
        }
Example #41
0
 public void Delete()
 {
     if (_rootNode != null) {
         _rootNode.Dispose();
         _rootNode = null;
         FileOperations.Delete(_rootPath);
         Close();
     }
 }
Example #42
0
        void modelPanel1_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Effect == DragDropEffects.Copy) {
                string newpath = ((string[])e.Data.GetData(DataFormats.FileDrop))[0];
                using (ResourceNode newroot = NodeFactory.FromFile(null, newpath)) {
                    if (newroot is ARCNode) {
                        string basePath = _path;
                        if (Path.HasExtension(basePath)) {
                            basePath = basePath.Substring(0, basePath.LastIndexOf('.'));
                        }
                        FileInfo pac = new FileInfo(basePath + ".pac");
                        FileInfo pcs = new FileInfo(basePath + ".pcs");

                        bool cont = true;
                        if (pac.Exists || pcs.Exists) {
                            cont = (DialogResult.OK == MessageBox.Show(
                                "Replace " + pac.Name + "/" + pcs.Name + "?",
                                "Overwrite?",
                                MessageBoxButtons.OKCancel));
                        }
                        if (!cont) return;

                        if (_root != null) {
                            _root.Dispose();
                            _root = null;
                        }
                        pac.Directory.Create();
                        (newroot as ARCNode).ExportPAC(pac.FullName);
                        (newroot as ARCNode).ExportPCS(pcs.FullName);

                        if (ParentForm is CostumeManager) {
                            (ParentForm as CostumeManager).updateCostumeSelectionPane();
                        }

                        LoadFile(_path);
                    } else {
                        MessageBox.Show("Invalid format: root node is not an ARC archive.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
Example #43
0
 public void Replace(string filepath)
 {
     if (FileOpen) {
         if (_rootNode != null) {
             _rootNode.Dispose(); // Close the file before overwriting it!
             _rootNode = null;
         }
     }
     copyBrstm(filepath, LastFileCalledFor);
     Open(new FileInfo(LastFileCalledFor));
 }
Example #44
0
        public void Apply(ResourceNode node)
        {
            string _name = name.Text;
            KeyframeEntry kfe = null;
            MDL0Node model = null;
            MDL0Node _targetModel = null;
            if (Port.Checked)
            {
                MessageBox.Show("Please open the model you want to port the animations to.\nThen open the model the animations work normally for.");
                OpenFileDialog dlgOpen = new OpenFileDialog();
                OpenFileDialog dlgOpen2 = new OpenFileDialog();
                dlgOpen.Filter = dlgOpen2.Filter = "MDL0 Model (*.mdl0)|*.mdl0";
                dlgOpen.Title = "Select the model to port the animations to...";
                dlgOpen2.Title = "Select the model the animations are for...";
                if (dlgOpen.ShowDialog() == DialogResult.OK)
                {
                    _targetModel = (MDL0Node)NodeFactory.FromFile(null, dlgOpen.FileName);
                    if (dlgOpen2.ShowDialog() == DialogResult.OK)
                        model = (MDL0Node)NodeFactory.FromFile(null, dlgOpen2.FileName);
                }
            }
            Vector3 scale = new Vector3(ScaleX.Value, ScaleY.Value, ScaleZ.Value);
            Vector3 rot = new Vector3(RotateX.Value, RotateY.Value, RotateZ.Value);
            Vector3 trans = new Vector3(TranslateX.Value, TranslateY.Value, TranslateZ.Value);
            ResourceNode[] CHR0 = node.FindChildrenByType(null, ResourceType.CHR0);
            foreach (CHR0Node n in CHR0)
            {
                if (NameContains.Checked && !n.Name.Contains(targetName.Text))
                    continue;

                if (editLoop.Checked)
                    n.Loop = enableLoop.Checked;

                if (Rename.Checked)
                    n.Name = newName.Text;

                if (ChangeVersion.Checked)
                    n.Version = Version.SelectedIndex + 4;

                if (Port.Checked && _targetModel != null && model != null)
                    n.Port(_targetModel, model);

                if (copyKeyframes.Checked)
                {
                    CHR0EntryNode _copyNode = n.FindChild(keyframeCopy.Text, false) as CHR0EntryNode;

                    if (n.FindChild(_name, false) == null)
                    {
                        if (!String.IsNullOrEmpty(_name))
                        {
                            CHR0EntryNode c = new CHR0EntryNode();
                            c._numFrames = n.FrameCount;
                            c.Name = _name;

                            if (_copyNode != null)
                                for (int x = 0; x < _copyNode._numFrames; x++)
                                    for (int i = 0x10; i < 0x19; i++)
                                        if ((kfe = _copyNode.GetKeyframe((KeyFrameMode)i, x)) != null)
                                            c.SetKeyframe((KeyFrameMode)i, x, kfe._value);

                            n.AddChild(c);
                        }
                    }
                }

                CHR0EntryNode entry = n.FindChild(_name, false) as CHR0EntryNode;
                if (entry == null)
                {
                    entry = new CHR0EntryNode() { _name = _name };
                    n.AddChild(entry);
                }
                AnimationFrame anim;
                bool hasKeyframe = false;
                int numFrames = entry.FrameCount;
                int low = 0x10, high = 0x13;
                if (ScaleReplace.Checked)
                {
                    for (int x = 0; x < numFrames; x++)
                        for (int i = low; i < high; i++)
                            if (entry.GetKeyframe((KeyFrameMode)i, x) != null)
                                entry.RemoveKeyframe((KeyFrameMode)i, x);

                    entry.SetKeyframeOnlyScale(0, scale);
                }
                else if (ScaleClear.Checked)
                {
                    for (int x = 0; x < numFrames; x++)
                        for (int i = low; i < high; i++)
                            if (entry.GetKeyframe((KeyFrameMode)i, x) != null)
                                entry.RemoveKeyframe((KeyFrameMode)i, x);
                }
                else if (ScaleAdd.Checked)
                {
                    for (int x = 0; x < numFrames; x++)
                        for (int i = low; i < high; i++)
                            if ((kfe = entry.GetKeyframe((KeyFrameMode)i, x)) != null)
                            {
                                if (i == low)
                                    kfe._value += scale._x;
                                else if (i == low + 1)
                                    kfe._value += scale._y;
                                else if (i == high - 1)
                                    kfe._value += scale._z;
                                hasKeyframe = true;
                            }
                    if (!hasKeyframe)
                    {
                        anim = entry.GetAnimFrame(0);
                        Vector3 newScale = anim.Scale;
                        scale._x += newScale._x;
                        scale._y += newScale._y;
                        scale._z += newScale._z;
                        entry.SetKeyframeOnlyScale(0, scale);
                    }
                }
                else if (ScaleSubtract.Checked)
                {
                    for (int x = 0; x < numFrames; x++)
                        for (int i = low; i < high; i++)
                            if ((kfe = entry.GetKeyframe((KeyFrameMode)i, x)) != null)
                            {
                                if (i == low)
                                    kfe._value -= scale._x;
                                else if (i == low + 1)
                                    kfe._value -= scale._y;
                                else if (i == high - 1)
                                    kfe._value -= scale._z;
                                hasKeyframe = true;
                            }
                    if (!hasKeyframe)
                    {
                        anim = entry.GetAnimFrame(0);
                        Vector3 newScale = anim.Scale;
                        scale._x = newScale._x - scale._x;
                        scale._y = newScale._y - scale._y;
                        scale._z = newScale._z - scale._z;
                        entry.SetKeyframeOnlyScale(0, scale);
                    }
                }
                else if (ScaleMultiply.Checked)
                {
                    for (int x = 0; x < numFrames; x++)
                        for (int i = low; i < high; i++)
                            if ((kfe = entry.GetKeyframe((KeyFrameMode)i, x)) != null)
                            {
                                if (i == low)
                                    kfe._value *= scale._x;
                                else if (i == low + 1)
                                    kfe._value *= scale._y;
                                else if (i == high - 1)
                                    kfe._value *= scale._z;
                                hasKeyframe = true;
                            }
                    if (!hasKeyframe)
                    {
                        anim = entry.GetAnimFrame(0);
                        Vector3 newScale = anim.Scale;
                        scale._x *= newScale._x;
                        scale._y *= newScale._y;
                        scale._z *= newScale._z;
                        entry.SetKeyframeOnlyScale(0, scale);
                    }
                }
                else if (ScaleDivide.Checked)
                {
                    for (int x = 0; x < numFrames; x++)
                        for (int i = low; i < high; i++)
                            if ((kfe = entry.GetKeyframe((KeyFrameMode)i, x)) != null)
                            {
                                if (i == low && scale._x != 0)
                                    kfe._value /= scale._x;
                                else if (i == low + 1 && scale._y != 0)
                                    kfe._value /= scale._y;
                                else if (i == high - 1 && scale._z != 0)
                                    kfe._value /= scale._z;
                                hasKeyframe = true;
                            }
                    if (!hasKeyframe)
                    {
                        anim = entry.GetAnimFrame(0);
                        Vector3 newScale = anim.Scale;
                        if (scale._x != 0)
                            scale._x = newScale._x / scale._x;
                        if (scale._y != 0)
                            scale._y = newScale._y / scale._y;
                        if (scale._z != 0)
                            scale._z = newScale._z / scale._z;
                        entry.SetKeyframeOnlyScale(0, scale);
                    }
                }

                low = 0x13; high = 0x16;
                if (RotateReplace.Checked)
                {
                    for (int x = 0; x < numFrames; x++)
                        for (int i = low; i < high; i++)
                            if (entry.GetKeyframe((KeyFrameMode)i, x) != null)
                                entry.RemoveKeyframe((KeyFrameMode)i, x);

                    entry.SetKeyframeOnlyRot(0, rot);
                }
                else if (RotateClear.Checked)
                {
                    for (int x = 0; x < numFrames; x++)
                        for (int i = low; i < high; i++)
                            if (entry.GetKeyframe((KeyFrameMode)i, x) != null)
                                entry.RemoveKeyframe((KeyFrameMode)i, x);
                }
                else if (RotateAdd.Checked)
                {
                    for (int x = 0; x < numFrames; x++)
                        for (int i = low; i < high; i++)
                            if ((kfe = entry.GetKeyframe((KeyFrameMode)i, x)) != null)
                            {
                                if (i == low)
                                    kfe._value += rot._x;
                                else if (i == low + 1)
                                    kfe._value += rot._y;
                                else if (i == high - 1)
                                    kfe._value += rot._z;
                                hasKeyframe = true;
                            }
                    if (!hasKeyframe)
                    {
                        anim = entry.GetAnimFrame(0);
                        Vector3 newRotate = anim.Rotation;
                        rot._x += newRotate._x;
                        rot._y += newRotate._y;
                        rot._z += newRotate._z;
                        entry.SetKeyframeOnlyRot(0, rot);
                    }
                }
                else if (RotateSubtract.Checked)
                {
                    for (int x = 0; x < numFrames; x++)
                        for (int i = low; i < high; i++)
                            if ((kfe = entry.GetKeyframe((KeyFrameMode)i, x)) != null)
                            {
                                if (i == low)
                                    kfe._value -= rot._x;
                                else if (i == low + 1)
                                    kfe._value -= rot._y;
                                else if (i == high - 1)
                                    kfe._value -= rot._z;
                                hasKeyframe = true;
                            }
                    if (!hasKeyframe)
                    {
                        anim = entry.GetAnimFrame(0);
                        Vector3 newRotate = anim.Rotation;
                        rot._x = newRotate._x - rot._x;
                        rot._y = newRotate._y - rot._y;
                        rot._z = newRotate._z - rot._z;
                        entry.SetKeyframeOnlyRot(0, rot);
                    }
                }
                else if (RotateMultiply.Checked)
                {
                    for (int x = 0; x < numFrames; x++)
                        for (int i = low; i < high; i++)
                            if ((kfe = entry.GetKeyframe((KeyFrameMode)i, x)) != null)
                            {
                                if (i == low)
                                    kfe._value *= rot._x;
                                else if (i == low + 1)
                                    kfe._value *= rot._y;
                                else if (i == high - 1)
                                    kfe._value *= rot._z;
                                hasKeyframe = true;
                            }
                    if (!hasKeyframe)
                    {
                        anim = entry.GetAnimFrame(0);
                        Vector3 newRotate = anim.Rotation;
                        rot._x *= newRotate._x;
                        rot._y *= newRotate._y;
                        rot._z *= newRotate._z;
                        entry.SetKeyframeOnlyRot(0, rot);
                    }
                }
                else if (RotateDivide.Checked)
                {
                    for (int x = 0; x < numFrames; x++)
                        for (int i = low; i < high; i++)
                            if ((kfe = entry.GetKeyframe((KeyFrameMode)i, x)) != null)
                            {
                                if (i == low && rot._x != 0)
                                    kfe._value /= rot._x;
                                else if (i == low + 1 && rot._y != 0)
                                    kfe._value /= rot._y;
                                else if (i == high - 1 && rot._z != 0)
                                    kfe._value /= rot._z;
                                hasKeyframe = true;
                            }
                    if (!hasKeyframe)
                    {
                        anim = entry.GetAnimFrame(0);
                        Vector3 newRotate = anim.Rotation;
                        if (rot._x != 0)
                            rot._x = newRotate._x / rot._x;
                        if (rot._y != 0)
                            rot._y = newRotate._y / rot._y;
                        if (rot._z != 0)
                            rot._z = newRotate._z / rot._z;
                        entry.SetKeyframeOnlyRot(0, rot);
                    }
                }

                low = 0x16; high = 0x19;
                if (TranslateReplace.Checked)
                {
                    for (int x = 0; x < numFrames; x++)
                        for (int i = 0x10; i < high; i++)
                            if (entry.GetKeyframe((KeyFrameMode)i, x) != null)
                                entry.RemoveKeyframe((KeyFrameMode)i, x);

                    entry.SetKeyframeOnlyTrans(0, trans);
                }
                else if (TranslateClear.Checked)
                {
                    for (int x = 0; x < numFrames; x++)
                        for (int i = low; i < high; i++)
                            if (entry.GetKeyframe((KeyFrameMode)i, x) != null)
                                entry.RemoveKeyframe((KeyFrameMode)i, x);
                }
                else if (TranslateAdd.Checked)
                {
                    for (int x = 0; x < numFrames; x++)
                        for (int i = low; i < high; i++)
                            if ((kfe = entry.GetKeyframe((KeyFrameMode)i, x)) != null)
                            {
                                if (i == low)
                                    kfe._value += trans._x;
                                else if (i == low + 1)
                                    kfe._value += trans._y;
                                else if (i == high - 1)
                                    kfe._value += trans._z;
                                hasKeyframe = true;
                            }
                    if (!hasKeyframe)
                    {
                        anim = entry.GetAnimFrame(0);
                        Vector3 newTranslate = anim.Translation;
                        trans._x += newTranslate._x;
                        trans._y += newTranslate._y;
                        trans._z += newTranslate._z;
                        entry.SetKeyframeOnlyTrans(0, trans);
                    }
                }
                else if (TranslateSubtract.Checked)
                {
                    for (int x = 0; x < numFrames; x++)
                        for (int i = low; i < high; i++)
                            if ((kfe = entry.GetKeyframe((KeyFrameMode)i, x)) != null)
                            {
                                if (i == low)
                                    kfe._value -= trans._x;
                                else if (i == low + 1)
                                    kfe._value -= trans._y;
                                else if (i == high - 1)
                                    kfe._value -= trans._z;
                                hasKeyframe = true;
                            }
                    if (!hasKeyframe)
                    {
                        anim = entry.GetAnimFrame(0);
                        Vector3 newTranslate = anim.Translation;
                        trans._x = newTranslate._x - trans._x;
                        trans._y = newTranslate._y - trans._y;
                        trans._z = newTranslate._z - trans._z;
                        entry.SetKeyframeOnlyTrans(0, trans);
                    }
                }
                else if (TranslateMultiply.Checked)
                {
                    for (int x = 0; x < numFrames; x++)
                        for (int i = low; i < high; i++)
                            if ((kfe = entry.GetKeyframe((KeyFrameMode)i, x)) != null)
                            {
                                if (i == low)
                                    kfe._value *= trans._x;
                                else if (i == low + 1)
                                    kfe._value *= trans._y;
                                else if (i == high - 1)
                                    kfe._value *= trans._z;
                                hasKeyframe = true;
                            }
                    if (!hasKeyframe)
                    {
                        anim = entry.GetAnimFrame(0);
                        Vector3 newTranslate = anim.Translation;
                        trans._x *= newTranslate._x;
                        trans._y *= newTranslate._y;
                        trans._z *= newTranslate._z;
                        entry.SetKeyframeOnlyTrans(0, trans);
                    }
                }
                else if (TranslateDivide.Checked)
                {
                    for (int x = 0; x < numFrames; x++)
                        for (int i = low; i < high; i++)
                            if ((kfe = entry.GetKeyframe((KeyFrameMode)i, x)) != null)
                            {
                                if (i == low && trans._x != 0)
                                    kfe._value /= trans._x;
                                else if (i == low + 1 && trans._y != 0)
                                    kfe._value /= trans._y;
                                else if (i == high - 1 && trans._z != 0)
                                    kfe._value /= trans._z;
                                hasKeyframe = true;
                            }
                    if (!hasKeyframe)
                    {
                        anim = entry.GetAnimFrame(0);
                        Vector3 newTranslate = anim.Translation;
                        if (trans._x != 0)
                            trans._x = newTranslate._x / trans._x;
                        if (trans._y != 0)
                            trans._y = newTranslate._y / trans._y;
                        if (trans._z != 0)
                            trans._z = newTranslate._z / trans._z;
                        entry.SetKeyframeOnlyTrans(0, trans);
                    }
                }
            }
        }
Example #45
0
 internal static ResourceNode TryParse(DataSource source, ResourceNode parent)
 {
     return(((BRESHeader *)source.Address)->_tag == BRESHeader.Tag ? new BRRESNode() : null);
 }
 public override void UpdateDirectory()
 {
     if (File.Exists("../menu2/sc_selcharacter.pac")) {
         string path = "../menu2/sc_selcharacter.pac";
         common5 = null;
         sc_selcharacter = NodeFactory.FromFile(null, path);
         _openFilePath = path;
     } else if (File.Exists("../menu2/sc_selcharacter_en.pac")) {
         string path = "../menu2/sc_selcharacter_en.pac";
         common5 = null;
         sc_selcharacter = NodeFactory.FromFile(null, path);
         _openFilePath = path;
     } else if (File.Exists("../system/common5.pac")) {
         string path = "../system/common5.pac";
         common5 = NodeFactory.FromFile(null, path);
         sc_selcharacter = common5.FindChild("sc_selcharacter_en", false);
         _openFilePath = path;
     } else if (File.Exists("../system/common5_en.pac")) {
         string path = "../system/common5_en.pac";
         common5 = NodeFactory.FromFile(null, path);
         sc_selcharacter = common5.FindChild("sc_selcharacter_en", false);
         _openFilePath = path;
     } else {
         common5 = null;
         sc_selcharacter = null;
     }
     label1.Text = sc_selcharacter != null ? Path.GetFileName(_openFilePath) : "Could not load common5 or sc_selcharacter.";
 }
 public override ResourceNode MainTEX0For(ResourceNode brres, int charNum, int costumeNum)
 {
     string path = "Textures(NW4R)/MenSelchrFaceB." + (charNum * 10 + costumeNum + 1).ToString("D3");
     return brres.FindChild(path, false);
 }
Example #48
0
 internal static ResourceNode TryParse(DataSource source, ResourceNode parent)
 {
     return(((Parameter *)source.Address)->_tag == Parameter.TagMVPM ? new MVPMNode() : null);
 }
Example #49
0
        public override void WriteParams(System.Xml.XmlWriter writer, Dictionary <HavokClassNode, int> classNodes)
        {
            writer.WriteStartElement("hkparam");
            writer.WriteAttributeString("name", "name");
            writer.WriteString(Name);
            writer.WriteEndElement();

            writer.WriteStartElement("hkparam");
            writer.WriteAttributeString("name", "parent");
            writer.WriteString(_parent is HavokClassNode
                ? HavokXML.GetObjectName(classNodes, _parent as HavokClassNode)
                : "null");
            writer.WriteEndElement();

            writer.WriteStartElement("hkparam");
            writer.WriteAttributeString("name", "objectSize");
            writer.WriteString(Size.ToString(CultureInfo.InvariantCulture));
            writer.WriteEndElement();

            writer.WriteStartElement("hkparam");
            writer.WriteAttributeString("name", "numImplementedInterfaces");
            writer.WriteString(InterfaceCount.ToString(CultureInfo.InvariantCulture));
            writer.WriteEndElement();

            ResourceNode enums = FindChild("Enums", false);

            writer.WriteStartElement("hkparam");
            writer.WriteAttributeString("name", "declaredEnums");
            writer.WriteAttributeString("numelements", enums == null ? "0" : enums.Children.Count.ToString());
            {
                if (enums != null)
                {
                    foreach (hkClassEnumNode e in enums.Children)
                    {
                        e.WriteParams(writer, classNodes);
                    }
                }
            }
            writer.WriteEndElement();

            ResourceNode members = FindChild("Members", false);

            writer.WriteStartElement("hkparam");
            writer.WriteAttributeString("name", "declaredMembers");
            writer.WriteAttributeString("numelements", members == null ? "0" : members.Children.Count.ToString());
            {
                if (members != null)
                {
                    foreach (hkClassMemberNode e in members.Children)
                    {
                        e.WriteParams(writer, classNodes);
                    }
                }
            }
            writer.WriteEndElement();

            writer.WriteComment(" defaults SERIALIZE_IGNORED ");
            writer.WriteComment(" attributes SERIALIZE_IGNORED ");

            writer.WriteStartElement("hkparam");
            writer.WriteAttributeString("name", "flags");
            writer.WriteString(Flags.ToString(CultureInfo.InvariantCulture));
            writer.WriteEndElement();

            writer.WriteStartElement("hkparam");
            writer.WriteAttributeString("name", "describedVersion");
            writer.WriteString(Version.ToString(CultureInfo.InvariantCulture));
            writer.WriteEndElement();
        }
Example #50
0
        private unsafe void Load(int index, int program)
        {
            if (TKContext.CurrentContext == null)
            {
                return;
            }

            Source = null;

            if (Texture != null)
            {
                Texture.Delete();
            }
            Texture = new GLTexture();
            Texture.Bind(index, program);

            Bitmap bmp = null;

            if (_folderWatcher.EnableRaisingEvents && !String.IsNullOrEmpty(_folderWatcher.Path))
            {
                bmp = SearchDirectory(_folderWatcher.Path + Name);
            }

            if (bmp == null && TKContext.CurrentContext._states.ContainsKey("_Node_Refs"))
            {
                List <ResourceNode> nodes    = TKContext.CurrentContext._states["_Node_Refs"] as List <ResourceNode>;
                List <ResourceNode> searched = new List <ResourceNode>(nodes.Count);
                TEX0Node            tNode    = null;

                foreach (ResourceNode n in nodes)
                {
                    ResourceNode node = n.RootNode;
                    if (searched.Contains(node))
                    {
                        continue;
                    }
                    searched.Add(node);

                    //Search node itself first
                    if ((tNode = node.FindChild("Textures(NW4R)/" + Name, true) as TEX0Node) != null)
                    {
                        Source = tNode;
                        Texture.Attach(tNode, _palette);
                        return;
                    }
                    else //Then search the directory
                    {
                        bmp = SearchDirectory(node._origPath);
                    }

                    if (bmp != null)
                    {
                        break;
                    }
                }
                searched.Clear();
            }

            if (bmp != null)
            {
                Texture.Attach(bmp);
            }
            else
            {
                Texture.Default();
            }
        }
 public override void AddChild(ResourceNode child)
 {
     base.AddChild(child);
     //Sort(false);
 }
        public override void RemoveChild(ResourceNode child)
        {
            base.RemoveChild(child);

            if (!_updating && Model._autoMetal && MetalMaterial != null && !this.isMetal)
                MetalMaterial.UpdateAsMetal();
        }
Example #53
0
        public override void OnPopulate()
        {
            //Enumerate entries, attaching them to the files.
            RSARHeader *rsar          = Header;
            SYMBHeader *symb          = rsar->SYMBBlock;
            sbyte *     offset        = (sbyte *)symb + 8;
            buint *     stringOffsets = symb->StringOffsets;

            VoidPtr baseAddr = (VoidPtr)rsar->INFOBlock + 8;
            ruint * typeList = (ruint *)baseAddr;

            //Iterate through group types
            for (int i = 0; i < 5; i++)
            {
                _infoCache[i] = new List <RSAREntryNode>();
                Type t = null;

                RuintList *list = (RuintList *)((uint)baseAddr + typeList[i]);
                sbyte *    str, end;

                switch (i)
                {
                case 0: t = typeof(RSARSoundNode); break;

                case 1: t = typeof(RSARBankNode); break;

                case 2: t = typeof(RSARPlayerInfoNode); break;

                case 3: continue;                         //Files

                case 4: t = typeof(RSARGroupNode); break; //Last group entry is null
                }

                for (int x = 0; x < list->_numEntries; x++)
                {
                    VoidPtr addr = list->Get(baseAddr, x);

                    ResourceNode  parent = this;
                    RSAREntryNode n      = Activator.CreateInstance(t) as RSAREntryNode;
                    n._origSource = n._uncompSource = new DataSource(addr, 0);
                    n._infoIndex  = x;

                    if (i == 4 && x == list->_numEntries - 1)
                    {
                        n._name    = "<null>";
                        n._parent  = this;
                        _nullGroup = n as RSARGroupNode;
                    }
                    else
                    {
                        str = offset + stringOffsets[n.StringId];

                        for (end = str; *end != 0; end++)
                        {
                            ;
                        }
                        while ((--end > str) && (*end != '_'))
                        {
                            ;
                        }

                        if (end > str)
                        {
                            parent  = CreatePath(parent, str, (int)end - (int)str);
                            n._name = new String(end + 1);
                        }
                        else
                        {
                            n._name = new String(str);
                        }
                    }

                    n.Initialize(parent, addr, 0);
                    _infoCache[i].Add(n);
                }
            }
            ftr = *(INFOFooter *)((uint)baseAddr + typeList[5]);

            foreach (RSARFileNode n in Files)
            {
                if (!(n is RSARExtFileNode))
                {
                    n.GetName();
                }
            }

            _rootIds   = new int[4];
            _symbCache = new List <SYMBMaskEntry> [4];
            bint *offsets = (bint *)((VoidPtr)symb + 12);

            for (int i = 0; i < 4; i++)
            {
                _symbCache[i] = new List <SYMBMaskEntry>();
                SYMBMaskHeader *hdr = (SYMBMaskHeader *)((VoidPtr)symb + 8 + offsets[i]);
                //Console.WriteLine("Root Index = " + hdr->_rootId);
                _rootIds[i] = hdr->_rootId;
                for (int x = 0; x < hdr->_numEntries; x++)
                {
                    SYMBMaskEntry *e = &hdr->Entries[x];
                    _symbCache[i].Add(*e);
                    //Console.WriteLine(String.Format("[{5}] {0}, {1}, {2} - {4}", e->_bit != -1 ? e->_bit.ToString().PadLeft(3) : "   ", e->_leftId != -1 ? e->_leftId.ToString().PadLeft(3) : "   ", e->_rightId != -1 ? e->_rightId.ToString().PadLeft(3) : "   ", e->_index != -1 ? e->_index.ToString().PadLeft(3) : "   ", new string(offset + stringOffsets[e->_stringId]), x.ToString().PadLeft(3)));
                }
            }
            //Sort(true);
        }
        internal static int CompareNodes(ResourceNode n1, ResourceNode n2)
        {
            bool is1Folder = n1 is RSARFolderNode;
            bool is2Folder = n2 is RSARFolderNode;

            if (is1Folder != is2Folder)
                return is1Folder ? -1 : 1;

            return String.Compare(n1._name, n2._name);
        }
Example #55
0
 internal static ResourceNode TryParse(DataSource source, ResourceNode parent)
 {
     return(source.Tag == "TBCL" ? new TBCLNode() : null);
 }
 public void TextureFrom(ResourceNode node, int charNum, int costumeNum)
 {
     Texture = node == null ? null : GetTEX0Func(node, charNum, costumeNum) as TEX0Node;
 }
Example #57
0
 internal static ResourceNode TryParse(DataSource source, ResourceNode parent)
 {
     return(((RSTC *)source.Address)->_tag == RSTC.Tag ? new RSTCNode() : null);
 }
Example #58
0
        public static int LookupCompare(ResourceNode n1, ResourceNode n2)
        {
            if (((MoveDefLookupOffsetNode)n1).DataOffset < ((MoveDefLookupOffsetNode)n2).DataOffset)
                return -1;
            if (((MoveDefLookupOffsetNode)n1).DataOffset > ((MoveDefLookupOffsetNode)n2).DataOffset)
                return 1;

            return 0;
        }
Example #59
0
 internal static ResourceNode TryParse(DataSource source, ResourceNode parent)
 {
     return(((HKXHeader *)source.Address)->_tag1 == HKXHeader.Tag1 ? new HavokNode() : null);
 }
Example #60
0
        public void LoadFile(string path)
        {
            if (_root != null) {
                _root.Dispose();
                _root = null;
            }
            if (path == null) {
                return;
            }

            _path = path;
            _charString = getCharString(path);

            comboBox1.Items.Clear();
            modelPanel1.ClearAll();
            modelPanel1.Invalidate();
            this.Text = new FileInfo(path).Name;

            try {
                //if (!File.Exists(path)) path = Settings.Default.FallbackBrawlRoot + '\\' + path.Substring(path.IndexOf("fighter"));
                _root = NodeFactory.FromFile(null, path);
                List<MDL0Node> models = findAllMDL0s(_root);
                if (models.Count > 0) {
                    comboBox1.Items.AddRange(models.ToArray());
                    comboBox1.SelectedIndex = 0;
                }
            } catch (IOException) {

            }
        }