예제 #1
0
파일: STR.cs 프로젝트: rakisaionji/PD_Tool
        public int STRReader()
        {
            KKtIO reader = KKtIO.OpenReader(filepath + ext);

            reader.Format    = KKtMain.Format.F;
            Header.Signature = reader.ReadInt32();
            if (Header.Signature == 0x41525453)
            {
                Header          = reader.ReadHeader(true);
                STR             = new List <String>();
                POF             = KKtMain.AddPOF(Header);
                reader.Position = Header.Lenght;

                Count  = reader.ReadInt32Endian();
                Offset = reader.ReadInt32Endian();
                if (Offset == 0)
                {
                    Offset         = Count;
                    OffsetX        = reader.ReadInt64();
                    Count          = reader.ReadInt64();
                    reader.XOffset = Header.Lenght;
                    reader.Format  = KKtMain.Format.X;
                }
                reader.LongPosition = reader.IsX ? Offset + reader.XOffset : Offset;

                for (int i = 0; i < Count; i++)
                {
                    String Str = new String
                    {
                        StrOffset = reader.GetOffset(ref POF).ReadInt32Endian(),
                        ID        = reader.ReadInt32Endian()
                    };
                    if (reader.IsX)
                    {
                        Str.StrOffset += (int)OffsetX;
                    }
                    STR.Add(Str);
                }
                for (int i = 0; i < Count; i++)
                {
                    reader.LongPosition = STR[i].StrOffset + (reader.IsX ? reader.XOffset : 0);
                    STR[i] = new String {
                        ID = STR[i].ID, Str = KKtText.
                                              ToUTF8(reader.NullTerminated()), StrOffset = STR[i].StrOffset
                    };
                }
                reader.Seek(POF.Offset, 0);
                reader.ReadPOF(ref POF);
            }
            else
            {
                reader.Seek(-4, (SeekOrigin)1);
                int i = 0;
                STR = new List <String>();
                while (reader.LongPosition > 0 && reader.LongPosition < reader.LongLength)
                {
                    int a = reader.ReadInt32();
                    if (a != 0)
                    {
                        reader.Seek(-4, (SeekOrigin)1);
                        STR.Add(new String {
                            Str = KKtText.ToUTF8(reader.NullTerminated()), ID = i
                        });
                        i++;
                    }
                    else
                    {
                        break;
                    }
                }
                Count = STR.Count;
            }

            reader.Close();
            return(1);
        }
예제 #2
0
파일: STR.cs 프로젝트: rakisaionji/PD_Tool
        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();
        }