예제 #1
0
        public static byte[] Merge(Sector[] Sectors)
        {
            byte[] Header = new byte[] { 0x54, 0x4A, 0x53, 0x32, 0x31, 0x30, 0x30, 0x00 }; //Signature + Version

            //Diff all Sectors
            Sector DATA = null;

            Sector[] Other = new Sector[0];
            Sector[] TJS   = new Sector[0];
            foreach (Sector sec in Sectors)
            {
                switch (sec.SectorType)
                {
                case SectorType.DATA:
                    DATA = sec;
                    break;

                case SectorType.Other:
                    Append(ref Other, sec);
                    break;

                case SectorType.TJS2:
                    Append(ref TJS, sec);
                    break;
                }
            }

            //Data Segment and Header
            byte[] OutTJS2 = new byte[Header.Length + 4];
            Header.CopyTo(OutTJS2, 0);
            Append(ref OutTJS2, DATA.Generate());

            //Others Segments
            Append(ref OutTJS2, Commom.GenDW((uint)Other.Length));
            foreach (Sector sec in Other)
            {
                Append(ref OutTJS2, sec.Generate());
            }

            //TJS2 Segments
            Append(ref OutTJS2, Commom.GenDW((uint)TJS.Length));
            foreach (Sector sec in TJS)
            {
                Append(ref OutTJS2, sec.Generate());
            }

            //Last Header Information, File Length
            Commom.GenDW((uint)OutTJS2.Length).CopyTo(OutTJS2, 0x08);

            return(OutTJS2);
        }
예제 #2
0
        internal byte[] Generate()
        {
            //Create new Variable
            byte[] sector = new byte[FullLength];

            //Write Signature
            Encoding.ASCII.GetBytes(Type).CopyTo(sector, 0);

            //Write Header (Content Length)
            Commom.GenDW((uint)Content.Length).CopyTo(sector, 0x04);

            //Write Content
            Array.Copy(Content, 0, sector, 0x08, Content.Length);

            //Return
            return(sector);
        }
예제 #3
0
        public static void SetContent(ref Sector sector, string[] Strings)
        {
            if (sector.Type != "DATA")
            {
                throw new Exception("Sector Type Not Supported");
            }
            byte[] Data = sector.Content;

            //Load Positions
            uint StrPos;

            FindStringPos(out StrPos, Data);
            uint EndPos = FindStrEnd(StrPos, Data);

            //Copy Int Non-String Data
            byte[] Values = new byte[StrPos];
            Array.Copy(Data, 0, Values, 0, Values.Length);

            byte[] StringTable = new byte[4];
            Commom.GenDW((uint)Strings.Length).CopyTo(StringTable, 0);//String Count

            //Generate String Table
            foreach (string String in Strings)
            {
                uint   StrLen   = Round((uint)String.Length * 2, 4);
                byte[] StrEntry = new byte[StrLen + 4];
                Commom.GenDW((uint)String.Length).CopyTo(StrEntry, 0);
                Encoding.Unicode.GetBytes(String).CopyTo(StrEntry, 4);
                Append(ref StringTable, StrEntry);
            }

            //Copy Object Values
            byte[] OBJS = new byte[Data.Length - EndPos];
            Array.Copy(Data, EndPos, OBJS, 0, OBJS.Length);

            //Generate Sector Content
            byte[] NewContent = new byte[Values.Length + StringTable.Length + OBJS.Length];
            Values.CopyTo(NewContent, 0);
            StringTable.CopyTo(NewContent, Values.Length);
            OBJS.CopyTo(NewContent, Values.Length + StringTable.Length);

            //Return
            sector.Content = NewContent;
        }