Пример #1
0
        private void readChat()
        {
            var chatBubblesPtr = ProcessMemory.Read <IntPtr>(GameAssemblyPtr, GameOffsets.HudManagerOffset, 0x5C, 0, 0x28, 0xC, 0x14);

            prevChatBubsVersion = ProcessMemory.Read <int>(GameAssemblyPtr, GameOffsets.HudManagerOffset, 0x5C, 0, 0x28, 0xC, 0x14, 0x10);
            var poolSize = 20; // = ProcessMemory.Read<int>(GameAssemblyPtr, 0xD0B25C, 0x5C, 0, 0x28, 0xC, 0xC)

            var numChatBubbles  = ProcessMemory.Read <int>(chatBubblesPtr, 0xC);
            var chatBubsVersion = ProcessMemory.Read <int>(chatBubblesPtr, 0x10);
            var chatBubblesAddr = ProcessMemory.Read <IntPtr>(chatBubblesPtr, 0x8) + 0x10;
            var chatBubblePtrs  = ProcessMemory.ReadArray(chatBubblesAddr, numChatBubbles);

            var newMsgs = 0;

            if (chatBubsVersion > prevChatBubsVersion) // new message has been sent
            {
                if (chatBubsVersion > poolSize)        // increments are twofold (push to and pop from pool)
                {
                    if (prevChatBubsVersion > poolSize)
                    {
                        newMsgs = (chatBubsVersion - prevChatBubsVersion) >> 1;
                    }
                    else
                    {
                        newMsgs = poolSize - prevChatBubsVersion + ((chatBubsVersion - poolSize) >> 1);
                    }
                }
                else
                {
                    newMsgs = chatBubsVersion - prevChatBubsVersion;
                }
            }
            else if (chatBubsVersion < prevChatBubsVersion) // reset
            {
                if (chatBubsVersion > poolSize)             // increments are twofold (push to and pop from pool)
                {
                    newMsgs = poolSize + ((chatBubsVersion - poolSize) >> 1);
                }
                else // single increments
                {
                    newMsgs = chatBubsVersion;
                }
            }

            prevChatBubsVersion = chatBubsVersion;

            for (var i = numChatBubbles - newMsgs; i < numChatBubbles; i++)
            {
                var msgText = ProcessMemory.ReadString(ProcessMemory.Read <IntPtr>(chatBubblePtrs[i], 0x20, 0x28));
                if (msgText.Length == 0)
                {
                    continue;
                }
                var msgSender     = ProcessMemory.ReadString(ProcessMemory.Read <IntPtr>(chatBubblePtrs[i], 0x1C, 0x28));
                var oldPlayerInfo = oldPlayerInfos[msgSender];
                ChatMessageAdded?.Invoke(this, new ChatMessageEventArgs
                {
                    Sender  = msgSender,
                    Message = msgText,
                    Color   = oldPlayerInfo.GetPlayerColor()
                });
            }
        }