private unsafe List <ChatMessage> GetMessages() { var list = new List <ChatMessage>(); uint bytesRead = 0; // Static base pointer to chat object array uint chatBasePointer = MemFunctions.ResolveNestedPointer(_client.Handle, ChatObjectsBase, 0); // Number between 0-199 (Number of messages that can be shown in the ingame chat window) uint lastChatOffset = MemFunctions.ResolveNestedPointer(_client.Handle, LastChatObject, 0); // Calculate index of first message to show uint firstChatToShow = FetchCount > lastChatOffset ? 0 : (lastChatOffset - FetchCount); for (uint chatOffset = firstChatToShow; chatOffset < lastChatOffset; chatOffset++) { // More efficient to read the whole chat structure into an object in one hit. // Object is kinda like a Union in old school C / C++ (see the object definition) var chatObj = new Chatobj(); // Structure object byte overlay pointer byte *lpChatObj = &chatObj.bytes[0]; // To pass to mem functions (number of bytes to read) int sizeofChatObj = Marshal.SizeOf(chatObj); // Read chatObj structure from PW memory into our object Mem.MemReadBytesToStruct(_client.Handle, chatBasePointer + (0x1C * chatOffset), lpChatObj, sizeofChatObj); // Actual message entry in object is just a pointer, so go retrieve the message uint chatPointer = MemFunctions.ResolveNestedPointer(_client.Handle, chatBasePointer + (0x1C * (chatOffset)) + 0x8, 0); string str = MemFunctions.MemReadUnicode(_client.Handle, chatObj.p_msg, 256, ref bytesRead).Replace("\r", "\r\n"); list.Add(new ChatMessage { Id = chatObj.msgId, Scope = (Scopes)chatObj.msgScope, Raw = str, ItemId = chatObj.itemId, }); } return(list); }
public static ElementClient[] GetClients() { var processes = Process.GetProcessesByName("elementclient"); return(processes.Select(pr => { IntPtr handle = MemFunctions.OpenProcess(pr.Id); uint playerBase = MemFunctions.ResolveNestedPointer(handle, BaseCall, 0x1C, 0x34); uint namePtr = MemFunctions.ResolveNestedPointer(handle, playerBase, NameOffset, 0); uint bytesRead = 0; return new ElementClient { Pid = pr.Id, Handle = handle, PlayerBase = playerBase, Nickname = MemFunctions.MemReadUnicode(handle, namePtr, 0x32, ref bytesRead), }; }).ToArray()); }