Fixed avatars sometimes not loading

This commit is contained in:
Garry Newman 2018-03-21 12:39:43 +00:00
parent e8a59e3a10
commit e94866828a

View File

@ -40,6 +40,7 @@ internal Friends( Client c )
{
client = c;
client.RegisterCallback<AvatarImageLoaded_t>( OnAvatarImageLoaded );
client.RegisterCallback<PersonaStateChange_t>( OnPersonaStateChange );
client.RegisterCallback<GameRichPresenceJoinRequested_t>( OnGameJoinRequested );
client.RegisterCallback<GameConnectedFriendChatMsg_t>( 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 );
}
}
}