diff --git a/Facepunch.Steamworks/Client/Friends.cs b/Facepunch.Steamworks/Client/Friends.cs index 00bea27..00d5f45 100644 --- a/Facepunch.Steamworks/Client/Friends.cs +++ b/Facepunch.Steamworks/Client/Friends.cs @@ -40,6 +40,7 @@ internal Friends( Client c ) { client = c; + client.RegisterCallback( OnAvatarImageLoaded ); client.RegisterCallback( OnPersonaStateChange ); client.RegisterCallback( OnGameJoinRequested ); client.RegisterCallback( OnFriendChatMessage ); @@ -237,8 +238,9 @@ public Image GetCachedAvatar( AvatarSize size, ulong steamid ) break; } - if ( imageid >= 0 && imageid <= 10 ) - return null; + if ( imageid == 1 ) return null; // Placeholder large + if ( imageid == 2 ) return null; // Placeholder medium + if ( imageid == 3 ) return null; // Placeholder small var img = new Image() { @@ -315,7 +317,7 @@ internal void Cycle() var timeOut = DateTime.Now.AddSeconds( -10 ); - for ( int i = 0; i < PersonaCallbacks.Count; i++ ) + for ( int i = PersonaCallbacks.Count-1; i >= 0; i-- ) { var cb = PersonaCallbacks[i]; @@ -338,10 +340,16 @@ private void OnPersonaStateChange( PersonaStateChange_t data ) { if ( (data.ChangeFlags & 0x0040) != 0x0040 ) return; // wait for k_EPersonaChangeAvatar - for ( int i=0; i< PersonaCallbacks.Count; i++ ) + LoadForSteamid( data.SteamID ); + + } + + void LoadForSteamid( ulong Steamid ) + { + for ( int i = PersonaCallbacks.Count - 1; i >= 0; i-- ) { var cb = PersonaCallbacks[i]; - if ( cb.SteamId != data.SteamID ) continue; + if ( cb.SteamId != Steamid ) continue; var image = GetCachedAvatar( cb.Size, cb.SteamId ); if ( image == null ) continue; @@ -355,5 +363,10 @@ private void OnPersonaStateChange( PersonaStateChange_t data ) } } + private void OnAvatarImageLoaded( AvatarImageLoaded_t data ) + { + LoadForSteamid( data.SteamID ); + } + } }