[5.1] ChatReader C# menu

Shout-Out

User Tag List

Results 1 to 2 of 2
  1. #1
    GobVs's Avatar Member
    Reputation
    3
    Join Date
    Feb 2013
    Posts
    5
    Thanks G/R
    0/2
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [5.1] ChatReader C#

    Hello!
    I want to write a program, which will read addon messages from chat (f.e. DBM messages) and output them to console.
    I've got this:
    Code:
    //MemoryReader.cs
    using System;
    using System.Diagnostics;
    using System.Linq;
    using System.Runtime.InteropServices;
    using System.Text;
    
    [StructLayout(LayoutKind.Sequential)]
    public struct WowChatMsg
    {
        public ulong SenderGuid;
        public uint Unknown;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 48)]
        public byte[] _SenderName;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3000)]
        public byte[] _FormattedMessage;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3000)]
        public byte[] _Text;
        public uint MessageType;
        public uint ChannelNumber;
        public uint Sequence;
        uint _Time;
        static readonly DateTime UnixEpochStart = new DateTime(1970, 1, 1, 0, 0, 0, 0);
        public string SenderName
        {
            get
            {
                return Encoding.UTF8.GetString(_SenderName.TakeWhile(b => b != 0).ToArray());
            }
        }
        public string FormattedMessage
        {
            get
            {
                return Encoding.UTF8.GetString(_Text.TakeWhile(b => b != 0).ToArray());
            }
        }
        public string Text
        {
            get
            {
                return Encoding.UTF8.GetString(_Text.TakeWhile(b => b != 0).ToArray());
            }
        }
        public DateTime Time
        {
            get
            {
                return UnixEpochStart.AddSeconds(_Time);
            }
        }
        public static int Size
        {
            get
            {
                return Marshal.SizeOf(typeof(WowChatMsg));
            }
        }
    }
    
    class MemoryReader : IDisposable
    {
        [DllImport("kernel32.dll", SetLastError = true)]
        static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [Out] byte[] lpBuffer, IntPtr nSize, IntPtr lpNumberOfBytesRead);
    
        Process process;
        public IntPtr BaseAddress
        {
            get
            {
                return process.MainModule.BaseAddress;
            }
        }
    
        public MemoryReader()
        {
            var tempP = Process.GetProcessesByName("Wow-64");
            if (tempP.Length == 0)
            {
                Console.WriteLine("Couldn't find working process");
                Console.ReadKey();
                Process.GetCurrentProcess().Kill();
            }
            process = tempP[0];
        }
    
        ~MemoryReader()
        {
            process.Close();
            process.Dispose();
        }
    
        public void Dispose()
        {
            process.Close();
            process.Dispose();
            GC.SuppressFinalize(this);
        }
    
        public T ReadStruct<T>(IntPtr offset) where T : struct
        {
            byte[] result = new byte[Marshal.SizeOf(typeof(T))];
            ReadProcessMemory(process.Handle, offset, result, new IntPtr(result.Length), IntPtr.Zero);
            GCHandle handle = GCHandle.Alloc(result, GCHandleType.Pinned);
            var returnObject = (T)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(T));
            handle.Free();
            return returnObject;
        }
    }
    Code:
    //Program.cs
    using System;
    
    class Program
    {
        static int Main(string[] args)
        {
            ChatReadWorkaround crw = new ChatReadWorkaround();
            crw.Init();
            return 0;
        }
    }
    
    class ChatReadWorkaround
    {
        const int ChatBufferStart_x64 = 0x1007AD0;
        const int ChatBufferPos_x64 = 0x1061068;
        const int ChatBufferSize = 60;
        int Pos;
        MemoryReader mr;
    
        public void Init()
        {
            mr = new MemoryReader();
            Pos = mr.ReadStruct<int>(mr.BaseAddress + ChatBufferPos_x64);
            BeginRead();
        }
    
        void ReadMessages()
        {
            int newPos = mr.ReadStruct<int>(mr.BaseAddress + ChatBufferPos_x64);
    
            if (newPos == Pos)
                return;
    
            if (newPos < Pos)
            {
                for (; Pos < ChatBufferSize; Pos++)
                    AddChatMessage();
                Pos = 0;
            }
            for (; Pos < newPos; Pos++)
                AddChatMessage();
        }
    
        void AddChatMessage()
        {
            IntPtr msgPtr = mr.BaseAddress + ChatBufferStart_x64 + WowChatMsg.Size * Pos;
            WowChatMsg msg = mr.ReadStruct<WowChatMsg>(msgPtr);
            Console.WriteLine("[{0:HH:mm:ss}][{1}]: {2}", msg.Time, msg.SenderName, msg.Text);
        }
    
        void BeginRead()
        {
            for (; ; )
                ReadMessages();
        }
    }
    It fails with reading only players' messages (whispers, lfg messages etc.), but ignoring npc yells and addons' messages, which i need.
    Any thoughts on how to fix it?

    [5.1] ChatReader C#
  2. #2
    Frosttall's Avatar Active Member
    Reputation
    64
    Join Date
    Feb 2011
    Posts
    261
    Thanks G/R
    16/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're trying to read the chat which is sent by the server. Messages sent from monsters or addons aren't that kind of messages.

    My first approach would be to use FrameManagement to read the content of the frame 'ChatFrame1'.

All times are GMT -5. The time now is 11:05 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search