コード例 #1
0
ファイル: PTP.cs プロジェクト: kurigohan0/PersonaEditor
        public PTP(BMD bmd)
        {
            foreach (var name in bmd.Name)
            {
                Names.Add(new PTPName
                {
                    Index   = name.Index,
                    OldName = name.NameBytes
                });
            }

            foreach (var msgs in bmd.Msg)
            {
                var temp = new PTPMSG
                {
                    Index          = msgs.Index,
                    Type           = msgs.Type,
                    Name           = msgs.Name,
                    CharacterIndex = msgs.NameIndex
                };

                ParseStrings(temp.Strings, msgs.MsgStrings);
                Msg.Add(temp);
            }
        }
コード例 #2
0
ファイル: PTP.cs プロジェクト: kurigohan0/PersonaEditor
        private void OpenPTP0(BinaryReader reader)
        {
            reader.ReadInt32();
            int MSGPos     = reader.ReadInt32();
            int MSGCount   = reader.ReadInt32();
            int NamesPos   = reader.ReadInt32();
            int NamesCount = reader.ReadInt32();

            reader.BaseStream.Position = NamesPos;
            for (int i = 0; i < NamesCount; i++)
            {
                int    size    = reader.ReadInt32();
                byte[] OldName = reader.ReadBytes(size);
                reader.BaseStream.Position += IOTools.Alignment(reader.BaseStream.Position, 4);

                size = reader.ReadInt32();
                string NewName = Encoding.UTF8.GetString(reader.ReadBytes(size));
                reader.BaseStream.Position += IOTools.Alignment(reader.BaseStream.Position, 4);

                Names.Add(new PTPName(i, OldName, NewName));
            }

            reader.BaseStream.Position = MSGPos;
            for (int i = 0; i < MSGCount; i++)
            {
                int    type           = reader.ReadInt32();
                byte[] buffer         = reader.ReadBytes(24);
                string Name           = Encoding.ASCII.GetString(buffer.Where(x => x != 0).ToArray());
                int    StringCount    = reader.ReadInt16();
                int    CharacterIndex = reader.ReadInt16();
                PTPMSG mSG            = new PTPMSG(i, type, Name, CharacterIndex);

                for (int k = 0; k < StringCount; k++)
                {
                    int    size   = reader.ReadInt32();
                    byte[] Prefix = reader.ReadBytes(size);
                    reader.BaseStream.Position += IOTools.Alignment(reader.BaseStream.Position, 4);

                    size = reader.ReadInt32();
                    byte[] OldString = reader.ReadBytes(size);
                    reader.BaseStream.Position += IOTools.Alignment(reader.BaseStream.Position, 4);

                    size = reader.ReadInt32();
                    byte[] Postfix = reader.ReadBytes(size);
                    reader.BaseStream.Position += IOTools.Alignment(reader.BaseStream.Position, 4);

                    size = reader.ReadInt32();
                    string NewString = Encoding.UTF8.GetString(reader.ReadBytes(size));
                    reader.BaseStream.Position += IOTools.Alignment(reader.BaseStream.Position, 16);

                    mSG.Strings.Add(new PTPMSGstr(k, NewString, Prefix, OldString, Postfix)
                    {
                        CharacterIndex = CharacterIndex
                    });
                }

                Msg.Add(mSG);
            }
        }
コード例 #3
0
ファイル: PTP.cs プロジェクト: kurigohan0/PersonaEditor
        private void OpenXmlPTP(Stream stream)
        {
            XDocument xDoc = XDocument.Load(stream, LoadOptions.PreserveWhitespace);

            XElement MSG1Doc = xDoc.Element("MSG1");

            foreach (var NAME in MSG1Doc.Element("CharacterNames").Elements())
            {
                int    Index         = Convert.ToInt32(NAME.Attribute("Index").Value);
                string OldNameSource = NAME.Element("OldNameSource").Value;
                string NewName       = NAME.Element("NewName").Value;

                Names.Add(new PTPName(Index, OldNameSource, NewName));
            }

            foreach (var Message in MSG1Doc.Element("MSG").Elements())
            {
                int    Index = Convert.ToInt32(Message.Attribute("Index").Value);
                int    Type  = Message.Element("Type").Value == "MSG" ? 0 : 1;
                string Name  = Message.Element("Name").Value;
                int    CharacterNameIndex = Convert.ToInt32(Message.Element("CharacterNameIndex").Value);

                PTPMSG temp = new PTPMSG(Index, Type, Name, CharacterNameIndex);
                Msg.Add(temp);

                foreach (var Strings in Message.Element("MessageStrings").Elements())
                {
                    int    StringIndex = Convert.ToInt32(Strings.Attribute("Index").Value);
                    string NewString   = Strings.Element("NewString").Value;

                    PTPMSGstr temp2 = new PTPMSGstr(StringIndex, NewString)
                    {
                        CharacterIndex = CharacterNameIndex
                    };
                    temp.Strings.Add(temp2);

                    foreach (var Prefix in Strings.Elements("PrefixBytes"))
                    {
                        int    PrefixIndex = Convert.ToInt32(Prefix.Attribute("Index").Value);
                        string PrefixType  = Prefix.Attribute("Type").Value;
                        string PrefixBytes = Prefix.Value;

                        temp2.Prefix.Add(new TextBaseElement(PrefixType == "Text" ? true : false, StringTool.SplitString(PrefixBytes, '-')));
                    }

                    foreach (var Old in Strings.Elements("OldStringBytes"))
                    {
                        int    OldIndex = Convert.ToInt32(Old.Attribute("Index").Value);
                        string OldType  = Old.Attribute("Type").Value;
                        string OldBytes = Old.Value;

                        temp2.OldString.Add(new TextBaseElement(OldType == "Text" ? true : false, StringTool.SplitString(OldBytes, '-')));
                    }

                    foreach (var Postfix in Strings.Elements("PostfixBytes"))
                    {
                        int    PostfixIndex = Convert.ToInt32(Postfix.Attribute("Index").Value);
                        string PostfixType  = Postfix.Attribute("Type").Value;
                        string PostfixBytes = Postfix.Value;

                        temp2.Postfix.Add(new TextBaseElement(PostfixType == "Text" ? true : false, StringTool.SplitString(PostfixBytes, '-')));
                    }
                }
            }
        }
コード例 #4
0
ファイル: PTP.cs プロジェクト: kurigohan0/PersonaEditor
        private bool Open(Stream stream)
        {
            try
            {
                BinaryReader reader = new BinaryReader(stream);
                stream.Position = 0;
                if (Encoding.ASCII.GetString(reader.ReadBytes(4)) == "PTP0")
                {
                    Names.Clear();
                    Msg.Clear();

                    int MSGPos     = reader.ReadInt32();
                    int MSGCount   = reader.ReadInt32();
                    int NamesPos   = reader.ReadInt32();
                    int NamesCount = reader.ReadInt32();

                    stream.Position = NamesPos;
                    for (int i = 0; i < NamesCount; i++)
                    {
                        int    size    = reader.ReadInt32();
                        byte[] OldName = reader.ReadBytes(size);
                        stream.Position += IOTools.Alignment(stream.Position, 4);

                        size = reader.ReadInt32();
                        string NewName = Encoding.UTF8.GetString(reader.ReadBytes(size));
                        stream.Position += IOTools.Alignment(stream.Position, 4);

                        Names.Add(new PTPName(i, OldName, NewName));
                    }

                    stream.Position = MSGPos;
                    for (int i = 0; i < MSGCount; i++)
                    {
                        int    type           = reader.ReadInt32();
                        byte[] buffer         = reader.ReadBytes(24);
                        string Name           = Encoding.ASCII.GetString(buffer.Where(x => x != 0).ToArray());
                        int    StringCount    = reader.ReadInt16();
                        int    CharacterIndex = reader.ReadInt16();
                        PTPMSG mSG            = new PTPMSG(i, type, Name, CharacterIndex);

                        for (int k = 0; k < StringCount; k++)
                        {
                            int    size   = reader.ReadInt32();
                            byte[] Prefix = reader.ReadBytes(size);
                            stream.Position += IOTools.Alignment(stream.Position, 4);

                            size = reader.ReadInt32();
                            byte[] OldString = reader.ReadBytes(size);
                            stream.Position += IOTools.Alignment(stream.Position, 4);

                            size = reader.ReadInt32();
                            byte[] Postfix = reader.ReadBytes(size);
                            stream.Position += IOTools.Alignment(stream.Position, 4);

                            size = reader.ReadInt32();
                            string NewString = Encoding.UTF8.GetString(reader.ReadBytes(size));
                            stream.Position += IOTools.Alignment(stream.Position, 16);

                            mSG.Strings.Add(new PTPMSGstr(k, NewString, Prefix, OldString, Postfix)
                            {
                                CharacterIndex = CharacterIndex
                            });
                        }

                        Msg.Add(mSG);
                    }

                    return(true);
                }

                return(false);
            }
            catch (Exception e)
            {
                Names.Clear();
                Msg.Clear();
                //  Logging.Write("PTPfactory", e.ToString());
                return(false);
            }
        }