diff --git a/ClassicalSharp/Network/INetworkProcessor.cs b/ClassicalSharp/Network/INetworkProcessor.cs index 2804019d6..4c67e3037 100644 --- a/ClassicalSharp/Network/INetworkProcessor.cs +++ b/ClassicalSharp/Network/INetworkProcessor.cs @@ -91,7 +91,6 @@ namespace ClassicalSharp { void DownloadTexturePack( string url ) { if( game.DeniedUrls.HasUrl( url ) ) return; - game.Animations.Dispose(); DateTime lastModified = TextureCache.GetLastModifiedFromCache( url ); if( url.Contains( ".zip" ) ) @@ -117,20 +116,24 @@ namespace ClassicalSharp { DownloadedItem item; if( game.AsyncDownloader.TryGetItem( "terrain", out item ) ) { if( item.Data != null ) { - Bitmap bmp = (Bitmap)item.Data; + Bitmap bmp = (Bitmap)item.Data; + game.World.TextureUrl = item.Url; + game.Animations.Dispose(); + if( !FastBitmap.CheckFormat( bmp.PixelFormat ) ) { Utils.LogDebug( "Converting terrain atlas to 32bpp image" ); game.Drawer2D.ConvertTo32Bpp( ref bmp ); } game.ChangeTerrainAtlas( bmp ); - TextureCache.AddToCache( item.Url, bmp ); - game.World.TextureUrl = item.Url; + TextureCache.AddToCache( item.Url, bmp ); } else if( Is304Status( item.WebEx ) ) { Bitmap bmp = TextureCache.GetBitmapFromCache( item.Url ); - if( bmp == null ) // Should never happen, but handle anyways. + if( bmp == null ) {// Should never happen, but handle anyways. ExtractDefault(); - else if( item.Url != game.World.TextureUrl ) + } else if( item.Url != game.World.TextureUrl ) { + game.Animations.Dispose(); game.ChangeTerrainAtlas( bmp ); + } if( bmp != null ) game.World.TextureUrl = item.Url; } else { @@ -140,15 +143,18 @@ namespace ClassicalSharp { if( game.AsyncDownloader.TryGetItem( "texturePack", out item ) ) { if( item.Data != null ) { + game.World.TextureUrl = item.Url; + game.Animations.Dispose(); + TexturePackExtractor extractor = new TexturePackExtractor(); extractor.Extract( (byte[])item.Data, game ); - TextureCache.AddToCache( item.Url, (byte[])item.Data ); - game.World.TextureUrl = item.Url; + TextureCache.AddToCache( item.Url, (byte[])item.Data ); } else if( Is304Status( item.WebEx ) ) { byte[] data = TextureCache.GetDataFromCache( item.Url ); if( data == null ) { // Should never happen, but handle anyways. ExtractDefault(); } else if( item.Url != game.World.TextureUrl ) { + game.Animations.Dispose(); TexturePackExtractor extractor = new TexturePackExtractor(); extractor.Extract( data, game ); }