Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Attribute"></param>
        /// <param name="Values"></param>
        public static void GenerateBuffer(GX_Attribute Attribute, List <float[]> Values)
        {
            switch (Attribute.AttributeName)
            {
            case GXAttribName.GX_VA_PNMTXIDX:
            case GXAttribName.GX_VA_TEX0MTXIDX:
            case GXAttribName.GX_VA_TEX1MTXIDX:
            case GXAttribName.GX_VA_TEX2MTXIDX:
            case GXAttribName.GX_VA_TEX3MTXIDX:
            case GXAttribName.GX_VA_TEX4MTXIDX:
            case GXAttribName.GX_VA_TEX5MTXIDX:
            case GXAttribName.GX_VA_TEX6MTXIDX:
            case GXAttribName.GX_VA_TEX7MTXIDX:
            case GXAttribName.GX_VA_CLR0:
            case GXAttribName.GX_VA_CLR1:
                Attribute.AttributeType = GXAttribType.GX_DIRECT;
                break;
            }

            OptimizeCompression(Attribute, Values);

            MemoryStream o = new MemoryStream();

            using (BinaryWriterExt Writer = new BinaryWriterExt(o))
            {
                Writer.BigEndian = true;
                foreach (float[] ob in Values)
                {
                    foreach (var v in ob)
                    {
                        WriteData(Writer, v, Attribute.CompType, Attribute.Scale);
                    }
                }
                Writer.Align(0x20);
            }

            if (Attribute.Buffer == null)
            {
                Attribute.Buffer = new HSDAccessor();
            }

            Attribute.Buffer._s.SetData(o.ToArray());

            o.Dispose();
        }
Beispiel #2
0
        public byte[] ToBuffer()
        {
            MemoryStream o = new MemoryStream();

            using (BinaryWriterExt writer = new BinaryWriterExt(o))
            {
                writer.BigEndian = true;
                foreach (GX_PrimitiveGroup g in Primitives)
                {
                    g.Write(writer, Attributes.ToArray());
                }
                writer.Write((byte)0);

                writer.Align(0x20);
            }

            byte[] bytes = o.ToArray();
            o.Dispose();

            return(bytes);
        }
        /// <summary>
        ///
        /// </summary>
        private void SaveFighterAnimationFile()
        {
            // rendering files not loaded
            if (string.IsNullOrEmpty(AJFilePath))
            {
                return;
            }

            // make sure okay to overwrite
            if (MessageBox.Show($"Is it okay to overwrite {AJFilePath}?", "Save Animation File Changes?", MessageBoxButtons.YesNoCancel) != DialogResult.Yes)
            {
                return;
            }

            // collect used symbols from all actions
            var usedSymbols = AllActions.Select(e => e.Symbol);

            // generate new aj file
            Dictionary <string, Tuple <int, int> > animOffsets = new Dictionary <string, Tuple <int, int> >();

            using (MemoryStream ajBuffer = new MemoryStream())
                using (BinaryWriterExt w = new BinaryWriterExt(ajBuffer))
                {
                    // collect used symbols
                    foreach (var sym in usedSymbols)
                    {
                        if (sym != null)
                        {
                            if (SymbolToAnimation.ContainsKey(sym) && !animOffsets.ContainsKey(sym))
                            {
                                // write animation
                                var anim = SymbolToAnimation[sym];
                                animOffsets.Add(sym, new Tuple <int, int>((int)ajBuffer.Position, anim.Length));
                                w.Write(anim);
                                w.Align(0x20, 0xFF);
                            }
                            else
                            if (!animOffsets.ContainsKey(sym))
                            {
                                // animation not found
                                MessageBox.Show($"\"{sym}\" animation not found", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                animOffsets.Add(sym, new Tuple <int, int>(0, 0));
                            }
                        }
                    }

                    // dump to file
                    File.WriteAllBytes(AJFilePath, ajBuffer.ToArray());
                }


            int index = 0;

            foreach (var a in AllActions)
            {
                // don't write subroutines
                if (a.Subroutine)
                {
                    continue;
                }

                // get embedded script
                var ftcmd = new SBM_FighterCommand();
                ftcmd._s = _node.Accessor._s.GetEmbeddedStruct(0x18 * index, ftcmd.TrimmedSize);

                // update symbol name
                ftcmd.Name = a.Symbol;

                if (a.Symbol == null)
                {
                    continue;
                }

                // offset
                var ofst = animOffsets[a.Symbol];

                // update action offset and size
                a.AnimOffset = ofst.Item1;
                a.AnimSize   = ofst.Item2;

                // update file offset and size
                ftcmd.AnimationOffset = a.AnimOffset;
                ftcmd.AnimationSize   = a.AnimSize;

                // resize if needed
                if (_node.Accessor._s.Length <= 0x18 * index + 0x18)
                {
                    _node.Accessor._s.Resize(0x18 * index + 0x18);
                }

                // update script
                _node.Accessor._s.SetEmbededStruct(0x18 * index, ftcmd._s);
                index++;
            }

            MainForm.Instance.SaveDAT();
        }