Example #1
0
        public void Pack(string file)
        {
            Files = null;
            FT    = false;
            string[] files = Directory.GetFiles(file);
            Files = new FARCFile[files.Length];

            for (int i = 0; i < files.Length; i++)
            {
                Files[i] = new FARCFile {
                    Name = files[i]
                };
                string ext = Path.GetExtension(files[i]).ToLower();
                if (ext == ".a3da" || ext == ".mot" || ext == ".vag")
                {
                    Signature = Farc.FArc;
                }
            }
            files = null;

            KKtIO writer = KKtIO.OpenWriter(file + ".farc", true);

            if (Signature == Farc.FArc)
            {
                writer.Write(Text.ToASCII("FArc"));
            }
            else if (Signature == Farc.FArC)
            {
                writer.Write(Text.ToASCII("FArC"));
            }
            else
            {
                writer.Write(Text.ToASCII("FARC"));
            }

            KKtIO HeaderWriter = new KKtIO(new MemoryStream());

            for (int i = 0; i < 3; i++)
            {
                HeaderWriter.Write((byte)0x00);
            }
            if (Signature == Farc.FArc)
            {
                HeaderWriter.Write((byte)0x20);
            }
            else if (Signature == Farc.FArC)
            {
                HeaderWriter.Write((byte)0x10);
            }
            else if (Signature == Farc.FARC)
            {
                HeaderWriter.Write((byte)0x06);
                for (int i = 0; i < 7; i++)
                {
                    HeaderWriter.Write((byte)0x00);
                }
                HeaderWriter.Write((byte)0x40);
                for (int i = 0; i < 8; i++)
                {
                    HeaderWriter.Write((byte)0x00);
                }
            }
            for (int i = 0; i < Files.Length; i++)
            {
                for (int i1 = 0; i1 < Path.GetFileName(Files[i].Name).Length +
                     (Signature == Farc.FArc ? 0x09 : 0x0D); i1++)
                {
                    HeaderWriter.Write((byte)0x00);
                }
            }
            writer.WriteEndian((uint)HeaderWriter.Length, true);
            writer.Write(HeaderWriter.ToArray());
            HeaderWriter = null;

            int Align = (int)Main.Align(writer.Position, 0x10) - (int)writer.Position;

            for (int i1 = 0; i1 < Align; i1++)
            {
                if (Signature == Farc.FArc)
                {
                    writer.Write((byte)0x00);
                }
                else
                {
                    writer.Write((byte)0x78);
                }
            }

            for (int i = 0; i < Files.Length; i++)
            {
                CompressStuff(i, ref Files, ref writer);
            }

            if (Signature == Farc.FARC)
            {
                writer.Seek(0x1C, 0);
            }
            else
            {
                writer.Seek(0x0C, 0);
            }
            for (int i = 0; i < Files.Length; i++)
            {
                writer.Write(Text.ToUTF8(Path.GetFileName(Files[i].Name) + "\0"));
                writer.WriteEndian(Files[i].Offset, true);
                if (Signature != Farc.FArc)
                {
                    writer.WriteEndian(Files[i].SizeComp, true);
                }
                writer.WriteEndian(Files[i].SizeUnc, true);
            }
            writer.Close();
        }
Example #2
0
        public void STRWriter()
        {
            uint  Offset        = 0;
            uint  CurrentOffset = 0;
            KKtIO writer        = KKtIO.OpenWriter(filepath + ((int)Header.Format > 5 ? ".str" : ".bin"), true);

            writer.Format = Header.Format;
            POF           = new KKtMain.POF {
                Offsets = new List <int>(), POFOffsets = new List <long>()
            };
            writer.IsBE = writer.Format == KKtMain.Format.F2BE;

            if ((int)writer.Format > 1)
            {
                writer.Seek(0x40, 0);
                writer.WriteEndian(Count);
                writer.GetOffset(ref POF).WriteEndian(0x80);
                writer.Seek(0x80, 0);
                for (int i = 0; i < STR.Count; i++)
                {
                    writer.GetOffset(ref POF).Write(0x00);
                    writer.WriteEndian(STR[i].ID);
                }
                writer.Align(16);
            }
            else
            {
                for (int i = 0; i < Count; i++)
                {
                    writer.Write(0x00);
                }
                writer.Align(32);
            }
            List <string> UsedSTR    = new List <string>();
            List <int>    UsedSTRPos = new List <int>();

            int[] STRPos = new int[Count];
            for (int i1 = 0; i1 < Count; i1++)
            {
                if (UsedSTR.Contains(STR[i1].Str))
                {
                    for (int i2 = 0; i2 < Count; i2++)
                    {
                        if (UsedSTR[i2] == STR[i1].Str)
                        {
                            STRPos[i1] = UsedSTRPos[i2];
                            break;
                        }
                    }
                }
                else
                {
                    STRPos[i1] = (int)writer.Position;
                    UsedSTRPos.Add(STRPos[i1]);
                    UsedSTR.Add(STR[i1].Str);
                    writer.Write(STR[i1].Str + "\0");
                }
            }
            if (writer.Format > KKtMain.Format.F)
            {
                writer.Align(16);
                Offset = (uint)writer.Position;
                writer.Seek(0x80, 0);
            }
            else
            {
                writer.Seek(0, 0);
            }
            for (int i1 = 0; i1 < Count; i1++)
            {
                writer.WriteEndian(STRPos[i1]);
                if (writer.Format > KKtMain.Format.F)
                {
                    writer.Seek(4, (SeekOrigin)1);
                }
            }

            if (writer.Format > KKtMain.Format.F)
            {
                writer.Seek(Offset, 0);
                writer.Write(ref POF, 1);
                CurrentOffset = (uint)writer.Length;
                writer.WriteEOFC(0);
                Header.IsBE        = writer.IsBE;
                Header.Lenght      = 0x40;
                Header.DataSize    = (int)(CurrentOffset - Header.Lenght);
                Header.Signature   = 0x41525453;
                Header.SectionSize = (int)(Offset - Header.Lenght);
                writer.Seek(0, 0);
                writer.Write(Header);
            }
            writer.Close();
        }