Ejemplo n.º 1
0
        public bool Open(Stream stream)
        {
            try
            {
                Name.Clear();
                Msg.Clear();

                stream.Position = 0x8;
                byte[] temp = new byte[4];
                stream.Read(temp, 0, 4);
                IsLittleEndian  = Encoding.ASCII.GetString(temp) == "MSG1";
                stream.Position = 0;
                using (BinaryReader reader = Utilities.IO.OpenReadFile(stream, IsLittleEndian))
                    ParseMSG1(reader);

                return(true);
            }
            catch (Exception e)
            {
                Name.Clear();
                Msg.Clear();

                Logging.Write("PTPfactory", e.ToString());
                return(false);
            }
        }
Ejemplo n.º 2
0
        void Received(object o)
        {
            System.Threading.Interlocked.Increment(ref countReceived);
            int   j     = (int)o;
            Aio   aio   = receivers[j];
            Errno errno = aio.Result();

            if (errno != 0)
            {
                return;
            }
            Msg msg = aio.GetMsg();

            sockets[j].Receive(receivers[j]);

            uint receivedValue2;

            msg.ChopU32(out receivedValue2);
            int  receivedValue   = (int)receivedValue2;
            bool valueHasChanged = false;

            for (;;)
            {
                int oldValue = potentials[j];
                if (receivedValue + 1 < oldValue)
                {
                    int beforeExchange = System.Threading.Interlocked.CompareExchange(ref potentials[j], receivedValue + 1, oldValue);
                    if (beforeExchange == oldValue)
                    {
                        valueHasChanged = true;
                        break;
                    }
                }
                else
                {
                    break;
                }
            }
            if (valueHasChanged)
            {
                msg.Clear();
                msg.AppendU32((uint)potentials[j]);
                //sockets[j].Send(msg);
                lock (senders[j])
                {
                    senders[j].Wait();
                    senders[j].SetMsg(msg);
                    sockets[j].Send(senders[j]);
                }
            }
            else
            {
                msg.Dispose();
            }
        }
Ejemplo n.º 3
0
        public bool Open(PTP PTP, Encoding New)
        {
            Name.Clear();
            Msg.Clear();
            foreach (var a in PTP.names)
            {
                Name.Add(new Names(a.Index, a.NewName.GetTextBaseList(New).GetByteArray().ToArray()));
            }

            foreach (var a in PTP.msg)
            {
                int          Index          = a.Index;
                string       Name           = a.Name;
                MSGs.MsgType Type           = a.Type == "MSG" ? MSGs.MsgType.MSG : MSGs.MsgType.SEL;
                int          CharacterIndex = a.CharacterIndex;

                byte[] MsgBytes = a.GetNew(New);

                Msg.Add(new MSGs(Index, Name, Type, CharacterIndex, MsgBytes.ToArray()));
            }

            return(true);
        }
Ejemplo n.º 4
0
        private void ParseMSG1(BinaryReader BR)
        {
            try
            {
                byte[] buffer;

                int MSG_PointBlock_Pos = 0x20;
                BR.BaseStream.Position = 24;
                int MSG_count = BR.ReadInt32();
                BR.BaseStream.Position = MSG_PointBlock_Pos;
                List <int[]> MSGPosition = new List <int[]>();

                for (int i = 0; i < MSG_count; i++)
                {
                    int[] temp = new int[2];
                    temp[0] = BR.ReadInt32();
                    temp[1] = BR.ReadInt32();
                    MSGPosition.Add(temp);
                }

                int Name_Block_Position = BR.ReadInt32();
                int Name_Count          = BR.ReadInt32();
                BR.BaseStream.Position = Name_Block_Position + MSG_PointBlock_Pos;

                List <long> NamePosition = new List <long>();
                for (int i = 0; i < Name_Count; i++)
                {
                    NamePosition.Add(BR.ReadInt32());
                }

                for (int i = 0; i < NamePosition.Count; i++)
                {
                    BR.BaseStream.Position = NamePosition[i] + MSG_PointBlock_Pos;
                    byte        Byte  = BR.ReadByte();
                    List <byte> Bytes = new List <byte>();
                    while (Byte != 0)
                    {
                        Bytes.Add(Byte);
                        Byte = BR.ReadByte();
                    }
                    Name.Add(new Names(i, Bytes.ToArray()));
                }

                for (int i = 0; i < MSGPosition.Count; i++)
                {
                    BR.BaseStream.Position = MSG_PointBlock_Pos + MSGPosition[i][1];
                    buffer = BR.ReadBytes(24);
                    string MSG_Name = System.Text.Encoding.Default.GetString(buffer).Trim('\0');
                    if (string.IsNullOrEmpty(MSG_Name))
                    {
                        MSG_Name = "<EMPTY>";
                    }

                    byte[]       MSG_bytes = new byte[0];
                    MSGs.MsgType Type;
                    int          CharacterIndex = 0xFFFF;

                    if (MSGPosition[i][0] == 0)
                    {
                        Type = MSGs.MsgType.MSG;
                        int count = BR.ReadUInt16();
                        CharacterIndex = BR.ReadUInt16();
                        if (count > 0)
                        {
                            BR.BaseStream.Position = BR.BaseStream.Position + 4 * count;
                            int size = BR.ReadInt32();
                            MSG_bytes = BR.ReadBytes(size);
                        }
                    }
                    else if (MSGPosition[i][0] == 1)
                    {
                        Type = MSGs.MsgType.SEL;
                        BR.BaseStream.Position += 2;
                        int count = BR.ReadUInt16();
                        if (count > 0)
                        {
                            BR.BaseStream.Position += 4 * count + 4;
                            int size = BR.ReadInt32();
                            MSG_bytes = BR.ReadBytes(size);
                        }
                    }
                    else
                    {
                        Logging.Write("PersonaEditorLib", "Error: Unknown message type!");

                        return;
                    }

                    MSGs MSG = new MSGs(i, MSG_Name, Type, CharacterIndex, MSG_bytes);

                    Msg.Add(MSG);
                }
            }
            catch (Exception e)
            {
                Logging.Write("PersonaEditorLib", "Error: Parse MSG1 error!");
                Logging.Write("PersonaEditorLib", e);
                Name.Clear();
                Msg.Clear();
            }
        }