/// <summary>
        /// Reads in a packet that has been sent from another user via SendP2PPacket..
        /// </summary>
        public unsafe static P2Packet?ReadP2PPacket(int channel = 0)
        {
            uint size = 0;

            if (!Internal.IsP2PPacketAvailable(ref size, channel))
            {
                return(null);
            }

            var buffer = Helpers.TakeBuffer((int)size);

            fixed(byte *p = buffer)
            {
                SteamId steamid = 1;

                if (!Internal.ReadP2PPacket((IntPtr)p, (uint)buffer.Length, ref size, ref steamid, channel) || size == 0)
                {
                    return(null);
                }

                var data = new byte[size];

                Array.Copy(buffer, 0, data, 0, size);

                return(new P2Packet
                {
                    SteamId = steamid,
                    Data = data
                });
            }
        }
        /// <summary>
        /// returns the image in RGBA format
        /// </summary>
        public static Data.Image?GetImage(int image)
        {
            if (image == -1)
            {
                return(null);
            }
            if (image == 0)
            {
                return(null);
            }

            var i = new Data.Image();

            if (!GetImageSize(image, out i.Width, out i.Height))
            {
                return(null);
            }

            var size = i.Width * i.Height * 4;

            var buf = Helpers.TakeBuffer((int)size);

            if (!Internal.GetImageRGBA(image, buf, (int)size))
            {
                return(null);
            }

            i.Data = new byte[size];
            Array.Copy(buf, 0, i.Data, 0, size);
            return(i);
        }
        static unsafe void OnFriendChatMessage(GameConnectedFriendChatMsg_t data)
        {
            if (OnChatMessage == null)
            {
                return;
            }

            var friend = new Friend(data.SteamIDUser);

            var buffer = Helpers.TakeBuffer(1024 * 32);
            var type   = ChatEntryType.ChatMsg;

            fixed(byte *ptr = buffer)
            {
                var len = Internal.GetFriendMessage(data.SteamIDUser, data.MessageID, (IntPtr)ptr, buffer.Length, ref type);

                if (len == 0 && type == ChatEntryType.Invalid)
                {
                    return;
                }

                var typeName = type.ToString();
                var message  = Encoding.UTF8.GetString(buffer, 0, len);

                OnChatMessage(friend, typeName, message);
            }
        }
Example #4
0
        public static Image?GetImage(int image)
        {
            Image?nullable;
            Image?nullable1;

            if (image == -1)
            {
                nullable  = null;
                nullable1 = nullable;
            }
            else if (image != 0)
            {
                Image image1 = new Image();
                if (SteamUtils.GetImageSize(image, out image1.Width, out image1.Height))
                {
                    uint   width    = image1.Width * image1.Height * 4;
                    byte[] numArray = Helpers.TakeBuffer((int)width);
                    if (SteamUtils.Internal.GetImageRGBA(image, numArray, (int)width))
                    {
                        image1.Data = new Byte[width];
                        Array.Copy(numArray, (long)0, image1.Data, (long)0, (long)width);
                        nullable1 = new Image?(image1);
                    }
                    else
                    {
                        nullable  = null;
                        nullable1 = nullable;
                    }
                }
                else
                {
                    nullable  = null;
                    nullable1 = nullable;
                }
            }
            else
            {
                nullable  = null;
                nullable1 = nullable;
            }
            return(nullable1);
        }
Example #5
-1
        static private unsafe void OnLobbyChatMessageRecievedAPI(LobbyChatMsg_t callback)
        {
            SteamId       steamid       = default;
            ChatEntryType chatEntryType = default;
            var           buffer        = Helpers.TakeBuffer(1024 * 4);

            fixed(byte *p = buffer)
            {
                var readData = Internal.GetLobbyChatEntry(callback.SteamIDLobby, (int)callback.ChatID, ref steamid, (IntPtr)p, buffer.Length, ref chatEntryType);

                if (readData > 0)
                {
                    OnChatMessage?.Invoke(new Lobby(callback.SteamIDLobby), new Friend(steamid), Encoding.UTF8.GetString(buffer, 0, readData));
                }
            }
        }