Exemple #1
0
        public static void OnSpeech(Packet pvSrc, PacketHandlerEventArgs args)
        {
            MessageType type      = (MessageType)pvSrc.ReadByte();
            ushort      hue       = pvSrc.ReadUInt16();
            ushort      font      = pvSrc.ReadUInt16();
            string      lang      = pvSrc.ReadString(4);
            string      text      = "";
            ArrayList   keys      = null;
            long        txtOffset = 0;

            World.Player.SpeechHue = hue;

            if ((type & MessageType.Encoded) != 0)
            {
                int value = pvSrc.ReadInt16();
                int count = (value & 0xFFF0) >> 4;
                keys = new ArrayList();
                keys.Add((ushort)value);

                for (int i = 0; i < count; ++i)
                {
                    if ((i & 1) == 0)
                    {
                        keys.Add(pvSrc.ReadByte());
                    }
                    else
                    {
                        keys.Add(pvSrc.ReadByte());
                        keys.Add(pvSrc.ReadByte());
                    }
                }

                txtOffset = pvSrc.Position;
                text      = pvSrc.ReadUTF8StringSafe();
                type     &= ~MessageType.Encoded;
            }
            else
            {
                txtOffset = pvSrc.Position;
                text      = pvSrc.ReadUnicodeStringSafe();
            }

            text = text.Trim();

            if (text.Length > 0)
            {
                if (text[0] != '-')
                {
                    if (ClientCommunication.TranslateEnabled && text[0] != '[' && text[0] != ']')
                    {
                        StringBuilder sb     = new StringBuilder(512);
                        uint          outLen = 512;

                        ClientCommunication.TranslateDo(text, sb, ref outLen);

                        text = sb.ToString();

                        pvSrc.Seek(txtOffset, System.IO.SeekOrigin.Begin);
                        if (keys != null && keys.Count > 0)
                        {
                            pvSrc.WriteUTF8Null(text);
                        }
                        else
                        {
                            pvSrc.WriteBigUniNull(text);
                        }
                        pvSrc.UnderlyingStream.SetLength(pvSrc.Position);
                    }

                    Macros.MacroManager.Action(new Macros.SpeechAction(type, hue, font, lang, keys, text));
                }
                else
                {
                    text = text.Substring(1);
                    string[]        split = text.Split(' ', '\t');
                    CommandCallback call  = (CommandCallback)m_List[split[0]];
                    if (call != null)
                    {
                        string[] param = new String[split.Length - 1];
                        for (int i = 0; i < param.Length; i++)
                        {
                            param[i] = split[i + 1];
                        }
                        call(param);

                        args.Block = true;
                    }
                }
            }
        }