Пример #1
0
        private static KAnimElement AddAnimElement(KAnimFrame parent, int hash)
        {
            KAnimElement element = new KAnimElement(parent);

            element.SymbolHash  = hash;
            element.FrameNumber = 0;
            element.FolderHash  = hash;
            element.Flags       = 0;
            element.Alpha       = 1.0f;
            element.Red         = 1.0f;
            element.Green       = 1.0f;
            element.Blue        = 1.0f;
            element.M00         = 1f;
            element.M10         = 0f;
            element.M01         = 0f;
            element.M11         = 1f;
            element.M02         = 0f;
            element.M12         = 0f;
            element.Unused      = 0;

            parent.Elements.Add(element);
            return(element);
        }
Пример #2
0
        public static bool WriteAnim(string animFile, KAnim anim)
        {
            try
            {
                using (FileStream file = new FileStream(animFile, FileMode.Create))
                    using (BinaryWriter writer = new BinaryWriter(file))
                    {
                        writer.Write(Encoding.ASCII.GetBytes(ANIM_HEADER));

                        writer.Write(anim.Version);
                        writer.Write(anim.FrameCount);
                        writer.Write(anim.ElementCount);
                        writer.Write(anim.BankCount);

                        for (int b = 0; b < anim.BankCount; b++)
                        {
                            KAnimBank bank = anim.Banks[b];

                            writer.WriteKString(bank.Name);
                            writer.Write(bank.Hash);
                            writer.Write(bank.Rate);
                            writer.Write(bank.FrameCount);

                            for (int f = 0; f < bank.FrameCount; f++)
                            {
                                KAnimFrame frame = bank.Frames[f];

                                writer.Write(frame.X);
                                writer.Write(frame.Y);
                                writer.Write(frame.Width);
                                writer.Write(frame.Height);
                                writer.Write(frame.ElementCount);

                                for (int e = 0; e < frame.ElementCount; e++)
                                {
                                    KAnimElement element = frame.Elements[e];

                                    writer.Write(element.SymbolHash);
                                    writer.Write(element.FrameNumber);
                                    writer.Write(element.FolderHash);
                                    writer.Write(element.Flags);
                                    writer.Write(element.Alpha);
                                    writer.Write(element.Blue);
                                    writer.Write(element.Green);
                                    writer.Write(element.Red);
                                    writer.Write(element.M00);
                                    writer.Write(element.M10);
                                    writer.Write(element.M01);
                                    writer.Write(element.M11);
                                    writer.Write(element.M02);
                                    writer.Write(element.M12);
                                    writer.Write(element.Unused);
                                }
                            }
                        }

                        writer.Write(anim.MaxVisSymbols);

                        int numHashes = anim.BankNames.Count;
                        writer.Write(numHashes);
                        foreach (KeyValuePair <int, string> kvp in anim.BankNames)
                        {
                            writer.Write(kvp.Key);
                            writer.WriteKString(kvp.Value);
                        }
                    }

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Пример #3
0
        public static KAnim ReadAnim(string animFile)
        {
            if (!File.Exists(animFile))
            {
                throw new ArgumentException("The given file does not exist.");
            }

            using (FileStream file = new FileStream(animFile, FileMode.Open))
                using (BinaryReader reader = new BinaryReader(file))
                {
                    // Verify header
                    string header = Encoding.ASCII.GetString(reader.ReadBytes(ANIM_HEADER.Length));
                    if (header != ANIM_HEADER)
                    {
                        throw new Exception("Header is not valid.");
                    }

                    // Parse Anim
                    KAnim anim = new KAnim();

                    anim.Version      = reader.ReadInt32();
                    anim.FrameCount   = reader.ReadInt32();
                    anim.ElementCount = reader.ReadInt32();
                    anim.BankCount    = reader.ReadInt32();

                    for (int a = 0; a < anim.BankCount; a++)
                    {
                        KAnimBank bank = new KAnimBank(anim);

                        bank.Name       = reader.ReadKString();
                        bank.Hash       = reader.ReadInt32();
                        bank.Rate       = reader.ReadSingle();
                        bank.FrameCount = reader.ReadInt32();

                        for (int f = 0; f < bank.FrameCount; f++)
                        {
                            KAnimFrame frame = new KAnimFrame(bank);

                            frame.X            = reader.ReadSingle();
                            frame.Y            = reader.ReadSingle();
                            frame.Width        = reader.ReadSingle();
                            frame.Height       = reader.ReadSingle();
                            frame.ElementCount = reader.ReadInt32();

                            for (int e = 0; e < frame.ElementCount; e++)
                            {
                                KAnimElement element = new KAnimElement(frame);

                                element.SymbolHash  = reader.ReadInt32();
                                element.FrameNumber = reader.ReadInt32();
                                element.FolderHash  = reader.ReadInt32();
                                element.Flags       = reader.ReadInt32();
                                element.Alpha       = reader.ReadSingle();
                                element.Blue        = reader.ReadSingle();
                                element.Green       = reader.ReadSingle();
                                element.Red         = reader.ReadSingle();
                                element.M00         = reader.ReadSingle();
                                element.M10         = reader.ReadSingle();
                                element.M01         = reader.ReadSingle();
                                element.M11         = reader.ReadSingle();
                                element.M02         = reader.ReadSingle();
                                element.M12         = reader.ReadSingle();
                                element.Unused      = reader.ReadSingle();

                                frame.Elements.Add(element);
                            }

                            bank.Frames.Add(frame);
                        }

                        anim.Banks.Add(bank);
                    }

                    anim.MaxVisSymbols = reader.ReadInt32();

                    // Read Anim Hashes
                    int numHashes = reader.ReadInt32();
                    for (int h = 0; h < numHashes; h++)
                    {
                        int    hash = reader.ReadInt32();
                        string str  = reader.ReadKString();
                        anim.BankNames[hash] = str;
                    }

                    return(anim);
                }
        }