Пример #1
0
        public void GetStrings()
        {
            if (Parent == null)
            {
                _name = "<null>";
                return;
            }

            PAT0Node node = (PAT0Node)Parent.Parent.Parent;

            if (((PAT0TextureNode)Parent)._hasPlt && _pltFileIndex < node._paletteFiles.Count)
            {
                _plt         = node._paletteFiles[_pltFileIndex];
                _paletteNode = null;
            }

            if (((PAT0TextureNode)Parent)._hasTex && _texFileIndex < node._textureFiles.Count)
            {
                _name        = _tex = node._textureFiles[_texFileIndex];
                _textureNode = null;
            }

            if (_name == null && _plt != null)
            {
                _name = _plt;
            }

            if (_name == null)
            {
                _name = "<null>";
            }
        }
Пример #2
0
        public void ImportFolder(string inFolder)
        {
            DirectoryInfo dir = new DirectoryInfo(inFolder);

            FileInfo[] files;

            files = dir.GetFiles();
            foreach (FileInfo info in files)
            {
                string ext = Path.GetExtension(info.FullName).ToUpper();
                if (ext == ".PNG" || ext == ".TGA" || ext == ".BMP" || ext == ".JPG" || ext == ".JPEG" || ext == ".GIF" || ext == ".TIF" || ext == ".TIFF")
                {
                    using (TextureConverterDialog dlg = new TextureConverterDialog())
                    {
                        dlg.ImageSource = info.FullName;
                        dlg.ShowDialog(null, this);
                    }
                }
                else if (ext == ".TEX0")
                {
                    TEX0Node node = NodeFactory.FromFile(null, info.FullName) as TEX0Node;
                    GetOrCreateFolder <TEX0Node>().AddChild(node);
                }
                else if (ext == ".MDL0")
                {
                    MDL0Node node = NodeFactory.FromFile(null, info.FullName) as MDL0Node;
                    GetOrCreateFolder <MDL0Node>().AddChild(node);
                }
                else if (ext == ".CHR0")
                {
                    CHR0Node node = NodeFactory.FromFile(null, info.FullName) as CHR0Node;
                    GetOrCreateFolder <CHR0Node>().AddChild(node);
                }
                else if (ext == ".CLR0")
                {
                    CLR0Node node = NodeFactory.FromFile(null, info.FullName) as CLR0Node;
                    GetOrCreateFolder <CLR0Node>().AddChild(node);
                }
                else if (ext == ".SRT0")
                {
                    SRT0Node node = NodeFactory.FromFile(null, info.FullName) as SRT0Node;
                    GetOrCreateFolder <SRT0Node>().AddChild(node);
                }
                else if (ext == ".SHP0")
                {
                    SHP0Node node = NodeFactory.FromFile(null, info.FullName) as SHP0Node;
                    GetOrCreateFolder <SHP0Node>().AddChild(node);
                }
                else if (ext == ".PAT0")
                {
                    PAT0Node node = NodeFactory.FromFile(null, info.FullName) as PAT0Node;
                    GetOrCreateFolder <PAT0Node>().AddChild(node);
                }
                else if (ext == ".VIS0")
                {
                    VIS0Node node = NodeFactory.FromFile(null, info.FullName) as VIS0Node;
                    GetOrCreateFolder <VIS0Node>().AddChild(node);
                }
            }
        }
Пример #3
0
        public override void OnRebuild(VoidPtr address, int length, bool force)
        {
            PAT0Node node = (PAT0Node)Parent.Parent.Parent;

            PAT0Texture *header = (PAT0Texture *)address;

            header->_key          = _frame;
            header->_texFileIndex = ((PAT0TextureNode)Parent)._hasTex && !String.IsNullOrEmpty(_tex) ? _texFileIndex : (ushort)0;
            header->_pltFileIndex = ((PAT0TextureNode)Parent)._hasPlt && !String.IsNullOrEmpty(_plt) ? _pltFileIndex : (ushort)0;
        }
Пример #4
0
        /// <summary>
        /// Adds an animation to the end of this one
        /// </summary>
        public void Append(PAT0Node external)
        {
            int origIntCount = FrameCount;

            FrameCount += external.FrameCount;

            foreach (PAT0EntryNode w in external.Children)
            {
                foreach (PAT0TextureNode _extEntry in w.Children)
                {
                    PAT0TextureNode _intEntry = null;
                    if ((_intEntry = (PAT0TextureNode)FindChild(w.Name + "/" + _extEntry.Name, false)) == null)
                    {
                        PAT0EntryNode wi = null;
                        if ((wi = (PAT0EntryNode)FindChild(w.Name, false)) == null)
                        {
                            AddChild(wi = new PAT0EntryNode()
                            {
                                Name = FindName(null)
                            });
                        }

                        PAT0TextureNode newIntEntry = new PAT0TextureNode(_extEntry._texFlags, _extEntry.TextureIndex);

                        wi.AddChild(newIntEntry);
                        foreach (PAT0TextureEntryNode e in _extEntry.Children)
                        {
                            PAT0TextureEntryNode q = new PAT0TextureEntryNode()
                            {
                                _frame = e._frame + origIntCount
                            };
                            newIntEntry.AddChild(q);

                            q.Texture = e.Texture;
                            q.Palette = e.Palette;
                        }
                    }
                    else
                    {
                        foreach (PAT0TextureEntryNode e in _extEntry.Children)
                        {
                            PAT0TextureEntryNode q = new PAT0TextureEntryNode()
                            {
                                _frame = e._frame + origIntCount
                            };
                            _intEntry.AddChild(q);

                            q.Texture = e.Texture;
                            q.Palette = e.Palette;
                        }
                    }
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Adds an animation opened by the user to the end of this one
        /// </summary>
        public void Append()
        {
            PAT0Node       external = null;
            OpenFileDialog o        = new OpenFileDialog();

            o.Filter = "PAT0 Animation (*.pat0)|*.pat0";
            o.Title  = "Please select an animation to append.";
            if (o.ShowDialog() == DialogResult.OK)
            {
                if ((external = (PAT0Node)NodeFactory.FromFile(null, o.FileName)) != null)
                {
                    Append(external);
                }
            }
        }
Пример #6
0
        protected internal override void OnRebuild(VoidPtr address, int length, bool force)
        {
            PAT0Node node = (PAT0Node)Parent.Parent.Parent;

            PAT0Texture *header = (PAT0Texture *)address;

            header->_key = key;

            short i = 0;

            if (((PAT0TextureNode)Parent).hasTex && !String.IsNullOrEmpty(Texture))
            {
                i = (short)node._textureFiles.IndexOf(Texture);
            }

            if (i < 0)
            {
                texFileIndex = 0;
            }
            else
            {
                texFileIndex = (ushort)i;
            }

            header->_texFileIndex = texFileIndex;

            i = 0;
            if (((PAT0TextureNode)Parent).hasPlt && !String.IsNullOrEmpty(Palette))
            {
                i = (short)node._paletteFiles.IndexOf(Palette);
            }

            if (i < 0)
            {
                pltFileIndex = 0;
            }
            else
            {
                pltFileIndex = (ushort)i;
            }

            header->_pltFileIndex = pltFileIndex;
        }
Пример #7
0
        public static BRESNode FromGIF(string file)
        {
            string   s = Path.GetFileNameWithoutExtension(file);
            BRESNode b = new BRESNode()
            {
                _name = s
            };
            PAT0Node p = new PAT0Node()
            {
                _name = s
            };

            p.CreateEntry();

            PAT0TextureNode t = p.Children[0].Children[0] as PAT0TextureNode;

            GifDecoder d = new GifDecoder();

            d.Read(file);

            int f = d.GetFrameCount();

            using (TextureConverterDialog dlg = new TextureConverterDialog())
            {
                dlg.Source = (Bitmap)d.GetFrame(0);
                if (dlg.ShowDialog(null, b) == DialogResult.OK)
                {
                    for (int i = 1; i < f; i++)
                    {
                        dlg.Source = (Bitmap)d.GetFrame(i);
                        dlg.EncodeSource();
                    }
                }
            }

            return(b);
        }
Пример #8
0
        public void ImportGIF(string file)
        {
            Action <object, DoWorkEventArgs> work = (object sender, DoWorkEventArgs e) =>
            {
                GifDecoder decoder = new GifDecoder();
                decoder.Read(file, null);
                e.Result = decoder;
            };
            Action <object, RunWorkerCompletedEventArgs> completed = (object sender, RunWorkerCompletedEventArgs e) =>
            {
                GifDecoder decoder = e.Result as GifDecoder;
                string     s       = Path.GetFileNameWithoutExtension(file);
                PAT0Node   p       = CreateResource <PAT0Node>(s);
                p._loop = true;
                p.CreateEntry();

                PAT0TextureNode      textureNode = p.Children[0].Children[0] as PAT0TextureNode;
                PAT0TextureEntryNode entry       = textureNode.Children[0] as PAT0TextureEntryNode;

                //Get the number of images in the file
                int frames = decoder.GetFrameCount();

                //The framecount will be created by adding up each image delay.
                float frameCount = 0;

                bool resized = false;
                int  w = 0, h = 0;
                Action <int, int> onResized = (newW, newH) =>
                {
                    if (resized != true)
                    {
                        w       = newW;
                        h       = newH;
                        resized = true;
                    }
                };

                using (TextureConverterDialog dlg = new TextureConverterDialog())
                {
                    using (ProgressWindow progress = new ProgressWindow(RootNode._mainForm, "GIF to PAT0 converter",
                                                                        "Converting, please wait...", true))
                    {
                        Bitmap prev = null;

                        progress.Begin(0, frames, 0);
                        for (int i = 0; i < frames; i++, entry = new PAT0TextureEntryNode())
                        {
                            if (progress.Cancelled)
                            {
                                break;
                            }

                            string name = s + "." + i;

                            dlg.ImageSource = name + ".";

                            using (Bitmap img = (Bitmap)decoder.GetFrame(i))
                            {
                                if (i == 0)
                                {
                                    dlg.LoadImages(img.Copy());
                                    dlg.Resized += onResized;
                                    if (dlg.ShowDialog(null, this) != DialogResult.OK)
                                    {
                                        return;
                                    }

                                    textureNode._hasTex = dlg.TextureData != null;
                                    textureNode._hasPlt = dlg.PaletteData != null;

                                    prev = img.Copy();
                                }
                                else
                                {
                                    //Draw the current image over the previous
                                    //This is because some GIFs use pixels of the previous frame
                                    //in order to compress the overall image data
                                    using (Graphics graphics = Graphics.FromImage(prev))
                                    {
                                        graphics.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                                        graphics.CompositingQuality = CompositingQuality.HighQuality;
                                        graphics.CompositingMode    = CompositingMode.SourceOver;
                                        graphics.SmoothingMode      = SmoothingMode.HighQuality;
                                        graphics.DrawImage(img, 0, 0, prev.Width, prev.Height);
                                    }

                                    dlg.LoadImages(prev.Copy());
                                    if (resized)
                                    {
                                        dlg.ResizeImage(w, h);
                                    }
                                    else
                                    {
                                        dlg.UpdatePreview();
                                    }

                                    dlg.EncodeSource();

                                    textureNode.AddChild(entry);
                                }
                            }

                            entry._frame = (float)Math.Round(frameCount, 2);
                            frameCount  += decoder.GetDelay(i) / 1000.0f * 60.0f;

                            if (textureNode._hasTex)
                            {
                                entry.Texture = name;
                            }

                            if (textureNode._hasPlt)
                            {
                                entry.Palette = name;
                            }

                            progress.Update(progress.CurrentValue + 1);
                        }

                        progress.Finish();
                        if (prev != null)
                        {
                            prev.Dispose();
                        }
                    }
                }

                p._numFrames = (ushort)(frameCount + 0.5f);
            };

            using (BackgroundWorker b = new BackgroundWorker())
            {
                b.DoWork             += new DoWorkEventHandler(work);
                b.RunWorkerCompleted += new RunWorkerCompletedEventHandler(completed);
                b.RunWorkerAsync();
            }
        }
Пример #9
0
        public override void OnRebuild(VoidPtr address, int length, bool force)
        {
            PAT0Pattern *header = (PAT0Pattern *)address;

            int x = 0;

            foreach (int i in _dataLens)
            {
                if (i == -1)
                {
                    _dataAddrs[x] = ((PAT0EntryNode)Parent.Children[((PAT0TextureNode)Children[x])._matIndex])._dataAddrs[((PAT0TextureNode)Children[x])._texIndex];
                }
                x++;
            }
            uint flags = 0;

            foreach (PAT0TextureNode table in Children)
            {
                table._texFlags |= PAT0Flags.Enabled;
                if (table.Children.Count > 1)
                {
                    table._texFlags &= ~PAT0Flags.FixedTexture;
                }
                else
                {
                    table._texFlags |= PAT0Flags.FixedTexture;
                }

                bool hasTex = false, hasPlt = false;

                //foreach (PAT0TextureEntryNode e in table.Children)
                //{
                //    if (e.Texture != null)
                //        hasTex = true;
                //    if (e.Palette != null)
                //        hasPlt = true;
                //}

                hasTex = table._hasTex;
                hasPlt = table._hasPlt;

                if (!hasTex)
                {
                    table._texFlags &= ~PAT0Flags.HasTexture;
                }
                else
                {
                    table._texFlags |= PAT0Flags.HasTexture;
                }
                if (!hasPlt)
                {
                    table._texFlags &= ~PAT0Flags.HasPalette;
                }
                else
                {
                    table._texFlags |= PAT0Flags.HasPalette;
                }

                if (table.Children.Count > 1)
                {
                    header->SetTexTableOffset(table.Index, _dataAddrs[table.Index]);
                    if (table._rebuild)
                    {
                        table.Rebuild(_dataAddrs[table.Index], PAT0TextureTable.Size + PAT0Texture.Size * table.Children.Count, true);
                    }
                }
                else
                {
                    PAT0TextureEntryNode entry = (PAT0TextureEntryNode)table.Children[0];
                    PAT0Node             node  = (PAT0Node)Parent;

                    short i = 0;
                    if (table._hasTex && !String.IsNullOrEmpty(entry.Texture))
                    {
                        i = (short)node._textureFiles.IndexOf(entry.Texture);
                    }

                    if (i < 0)
                    {
                        entry._texFileIndex = 0;
                    }
                    else
                    {
                        entry._texFileIndex = (ushort)i;
                    }

                    i = 0;
                    if (table._hasPlt && !String.IsNullOrEmpty(entry.Palette))
                    {
                        i = (short)node._paletteFiles.IndexOf(entry.Palette);
                    }

                    if (i < 0)
                    {
                        entry._pltFileIndex = 0;
                    }
                    else
                    {
                        entry._pltFileIndex = (ushort)i;
                    }

                    header->SetIndex(table.Index, entry._texFileIndex, false);
                    header->SetIndex(table.Index, entry._pltFileIndex, true);
                }

                flags = flags & ~((uint)0xF << (table._textureIndex * 4)) | ((uint)table._texFlags << (table._textureIndex * 4));
            }

            header->_flags = flags;
        }
Пример #10
0
 public void ApplyPAT(PAT0Node node, int index)
 {
     //Change textures
     if (_matList != null)
         foreach (MDL0MaterialNode m in _matList)
             m.ApplyPAT0(node, index);
 }
Пример #11
0
        /// <summary>
        /// Adds an animation to the end of this one
        /// </summary>
        public void Append(PAT0Node external)
        {
            int origIntCount = FrameCount;
            FrameCount += external.FrameCount;

            foreach (PAT0EntryNode w in external.Children)
                foreach (PAT0TextureNode _extEntry in w.Children)
                {
                    PAT0TextureNode _intEntry = null;
                    if ((_intEntry = (PAT0TextureNode)FindChild(w.Name + "/" + _extEntry.Name, false)) == null)
                    {
                        PAT0EntryNode wi = null;
                        if ((wi = (PAT0EntryNode)FindChild(w.Name, false)) == null)
                            AddChild(wi = new PAT0EntryNode() { Name = FindName(null) });

                        PAT0TextureNode newIntEntry = new PAT0TextureNode(_extEntry._texFlags, _extEntry.TextureIndex);

                        wi.AddChild(newIntEntry);
                        foreach (PAT0TextureEntryNode e in _extEntry.Children)
                        {
                            PAT0TextureEntryNode q = new PAT0TextureEntryNode() { _frame = e._frame + origIntCount };
                            newIntEntry.AddChild(q);

                            q.Texture = e.Texture;
                            q.Palette = e.Palette;
                        }
                    }
                    else
                    {
                        foreach (PAT0TextureEntryNode e in _extEntry.Children)
                        {
                            PAT0TextureEntryNode q = new PAT0TextureEntryNode() { _frame = e._frame + origIntCount };
                            _intEntry.AddChild(q);

                            q.Texture = e.Texture;
                            q.Palette = e.Palette;
                        }
                    }
                }
        }
        internal unsafe void ApplyPAT0(PAT0Node node, int index)
        {
            PAT0EntryNode e;

            if (node == null || index == 0)
                foreach (MDL0MaterialRefNode r in Children)
                    r.ApplyPAT0Texture(null, 0);
            else if ((e = node.FindChild(Name, false) as PAT0EntryNode) != null)
            {
                foreach (PAT0TextureNode t in e.Children)
                    if (t._textureIndex < Children.Count)
                        ((MDL0MaterialRefNode)Children[t._textureIndex]).ApplyPAT0Texture(t, index);
            }
            else
                foreach (MDL0MaterialRefNode r in Children)
                    r.ApplyPAT0Texture(null, 0);
        }
Пример #13
0
 public void UpdatePAT0Selection(PAT0Node selection)
 {
     _pat0Selection = selection;
     if (_pat0Selection == null && _srt0Selection == null)
         overObjPnl.Visible = overTexPnl.Visible = false;
     else
     {
         overObjPnl.Visible = overTexPnl.Visible = true;
         overObjPnl.Invalidate();
         overTexPnl.Invalidate();
     }
 }