Esempio n. 1
0
 public void WriteZipEntry( ZipEntry entry, byte[] data )
 {
     entry.CompressedDataSize = (int)entry.UncompressedDataSize;
     entry.LocalHeaderOffset = (int)stream.Position;
     entries[entriesCount++] = entry;
     WriteLocalFileEntry( entry, data, data.Length );
 }
        void ProcessZipEntry( string filename, byte[] data, ZipEntry entry )
        {
            MemoryStream stream = new MemoryStream( data );
            ModelCache cache = game.ModelCache;

            // Ignore directories: convert x/name to name and x\name to name.
            string name = filename.ToLower();
            int i = name.LastIndexOf( '\\' );
            if( i >= 0 ) name = name.Substring( i + 1, name.Length - 1 - i );
            i = name.LastIndexOf( '/' );
            if( i >= 0 ) name = name.Substring( i + 1, name.Length - 1 - i );

            switch( name ) {
                case "terrain.png":
                    Bitmap atlas = Platform.ReadBmp( stream );
                    if( !game.ChangeTerrainAtlas( atlas ) ) atlas.Dispose();
                    break;
                case "clouds.png":
                case "cloud.png":
                    game.UpdateTexture( ref game.CloudsTex, data, false ); break;
                case "gui.png":
                    game.UpdateTexture( ref game.GuiTex, data, false ); break;
                case "gui_classic.png":
                    game.UpdateTexture( ref game.GuiClassicTex, data, false ); break;
                case "icons.png":
                    game.UpdateTexture( ref game.IconsTex, data, false ); break;
                case "particles.png":
                    game.UpdateTexture( ref game.ParticleManager.ParticlesTexId,
                                  data, false ); break;
                case "default.png":
                    SetFontBitmap( game, stream ); break;
            }
            game.Events.RaiseTextureChanged( name, data );
        }
 void ProcessZipEntry( string filename, byte[] data, ZipEntry entry )
 {
     MemoryStream stream = new MemoryStream( data );
     ModelCache cache = game.ModelCache;
     IGraphicsApi api = game.Graphics;
     switch( filename ) {
         case "terrain.png":
             game.ChangeTerrainAtlas( new Bitmap( stream ) ); break;
         case "mob/chicken.png":
         case "chicken.png":
             UpdateTexture( ref cache.ChickenTexId, stream, false ); break;
         case "mob/creeper.png":
         case "creeper.png":
             UpdateTexture( ref cache.CreeperTexId, stream, false ); break;
         case "mob/pig.png":
         case "pig.png":
             UpdateTexture( ref cache.PigTexId, stream, false ); break;
         case "mob/sheep.png":
         case "sheep.png":
             UpdateTexture( ref cache.SheepTexId, stream, false ); break;
         case "mob/skeleton.png":
         case "skeleton.png":
             UpdateTexture( ref cache.SkeletonTexId, stream, false ); break;
         case "mob/spider.png":
         case "spider.png":
             UpdateTexture( ref cache.SpiderTexId, stream, false ); break;
         case "mob/zombie.png":
         case "zombie.png":
             UpdateTexture( ref cache.ZombieTexId, stream, false ); break;
         case "mob/sheep_fur.png":
         case "sheep_fur.png":
             UpdateTexture( ref cache.SheepFurTexId, stream, false ); break;
         case "char.png":
             UpdateTexture( ref cache.HumanoidTexId, stream, true ); break;
         case "clouds.png":
         case "cloud.png":
             UpdateTexture( ref game.CloudsTextureId, stream, false ); break;
         case "rain.png":
             UpdateTexture( ref game.RainTextureId, stream, false ); break;
         case "snow.png":
             UpdateTexture( ref game.SnowTextureId, stream, false ); break;
         case "animations.png":
         case "animation.png":
             game.Animations.SetAtlas( new Bitmap( stream ) ); break;
         case "animations.txt":
         case "animation.txt":
             StreamReader reader = new StreamReader( stream );
             game.Animations.ReadAnimationsDescription( reader );
             break;
         case "default.png":
             SetFontBitmap( game, stream );
             break;
     }
 }
Esempio n. 4
0
        public void WriteNewEntry( string filename, byte[] data, int dataLength )
        {
            ZipEntry entry = new ZipEntry();
            entry.UncompressedDataSize = dataLength;
            entry.Crc32 = CRC32( data, dataLength );
            entry.CompressedDataSize = dataLength;
            entry.LocalHeaderOffset = (int)stream.Position;

            entry.Filename = filename;
            entries[entriesCount++] = entry;
            WriteLocalFileEntry( entry, data, dataLength );
        }
Esempio n. 5
0
        static void ProcessZipEntry( string filename, byte[] data, ZipEntry entry )
        {
            string path = Path.Combine( Program.AppDirectory, "CS_Update" );
            path = Path.Combine( path, Path.GetFileName( filename ) );
            File.WriteAllBytes( path, data );

            try {
                File.SetLastWriteTimeUtc( path, PatchTime );
            } catch( IOException ex ) {
                ErrorHandler.LogError( "I/O exception when trying to set modified time for: " + filename, ex );
            } catch( UnauthorizedAccessException ex ) {
                ErrorHandler.LogError( "Permissions exception when trying to set modified time for: " + filename, ex );
            }
        }
Esempio n. 6
0
        void WriteLocalFileEntry( ZipEntry entry, byte[] data, int length )
        {
            writer.Write( 0x04034b50 ); // signature
            writer.Write( (ushort)20 ); // version needed
            writer.Write( (ushort)0 );  // bitflags
            writer.Write( (ushort)0 );  // compression method
            writer.Write( 0 );          // last modified
            writer.Write( entry.Crc32 );
            writer.Write( entry.CompressedDataSize );
            writer.Write( entry.UncompressedDataSize );
            writer.Write( (ushort)entry.Filename.Length );
            writer.Write( (ushort)0 );  // extra field length
            for( int i = 0; i < entry.Filename.Length; i++ )
                writer.Write( (byte)entry.Filename[i] );

            writer.Write( data, 0, length );
        }
Esempio n. 7
0
 void ProcessZipEntry_Modern( string filename, byte[] data, ZipEntry entry )
 {
     entry.Filename = ResourceList.GetFile( filename );
     switch( filename ) {
         case "assets/minecraft/textures/environment/snow.png":
             if( !existing.Contains( "snow.png" ) )
                 writer.WriteZipEntry( entry, data );
             break;
         case "assets/minecraft/textures/entity/chicken.png":
             if( !existing.Contains( "chicken.png" ) )
                 writer.WriteZipEntry( entry, data );
             break;
         case "assets/minecraft/textures/blocks/water_still.png":
             PatchDefault( data, 0 );
             break;
         case "assets/minecraft/textures/blocks/lava_still.png":
             PatchCycle( data, 16 );
             break;
         case "assets/minecraft/textures/blocks/fire_layer_1.png":
             PatchDefault( data, 32 );
             break;
     }
 }
Esempio n. 8
0
        void ProcessZipEntry_Classic( string filename, byte[] data, ZipEntry entry )
        {
            if( !filename.EndsWith( ".png", comp ) ) return;
            entry.Filename = ResourceList.GetFile( filename );

            if( entry.Filename != "terrain.png" ) {
                if( entry.Filename == "gui.png" )
                    entry.Filename = "gui_classic.png";
                if( !existing.Contains( entry.Filename ) )
                    writer.WriteZipEntry( entry, data );
                return;
            } else if( !existing.Contains( "terrain.png" ) ){
                using( Bitmap dstBitmap = new Bitmap( new MemoryStream( data ) ),
                      maskBitmap = new Bitmap( new MemoryStream( pngTerrainPatch ) ) ) {
                    PatchImage( dstBitmap, maskBitmap );
                    writer.WriteNewImage( dstBitmap, "terrain.png" );
                }
            }
        }
Esempio n. 9
0
 void ExtractExisting( string filename, byte[] data, ZipEntry entry )
 {
     filename = ResourceList.GetFile( filename );
     entry.Filename = filename;
     existing.Add( filename );
     entries.Add( entry );
     datas.Add( data );
 }
        void ProcessZipEntry( string filename, byte[] data, ZipEntry entry )
        {
            MemoryStream stream = new MemoryStream( data );

            if( filename == "default.png" ) {
                if( fontPng ) return;
                Bitmap bmp = new Bitmap( stream );
                Drawer.SetFontBitmap( bmp );
                useBitmappedFont = !Options.GetBool( OptionsKey.ArialChatFont, false );
                fontPng = true;
            } else if( filename == "terrain.png" ) {
                if( terrainPng ) return;
                using( Bitmap bmp = new Bitmap( stream ) )
                    MakeClassicTextures( bmp );
                terrainPng = true;
            }
        }
 void ProcessZipEntry( string filename, byte[] data, ZipEntry entry )
 {
 }
 void ProcessZipEntry( string filename, byte[] data, ZipEntry entry )
 {
     MemoryStream stream = new MemoryStream( data );
     using( Bitmap bmp = new Bitmap( stream ) ) {
         using( FastBitmap fastBmp = new FastBitmap( bmp, true ) ) {
             elementSize = bmp.Width / 16;
             dirtBmp = new Bitmap( elementSize, elementSize );
             dirtFastBmp = new FastBitmap( dirtBmp, true );
             FastBitmap.MovePortion( elementSize * 2, 0, 0, 0, fastBmp, dirtFastBmp, elementSize );
         }
     }
     useTexture = true;
 }
        void ProcessZipEntry( string filename, byte[] data, ZipEntry entry )
        {
            MemoryStream stream = new MemoryStream( data );
            ModelCache cache = game.ModelCache;

            // Ignore directories: convert x/name to name and x\name to name.
            string name = filename.ToLower();
            int i = name.LastIndexOf( '\\' );
            if( i >= 0 ) name = name.Substring( i + 1, name.Length - 1 - i );
            i = name.LastIndexOf( '/' );
            if( i >= 0 ) name = name.Substring( i + 1, name.Length - 1 - i );

            switch( name ) {
                case "terrain.png":
                    Bitmap atlas = Platform.ReadBmp( stream );
                    if( !game.ChangeTerrainAtlas( atlas ) ) atlas.Dispose();
                    break;
                case "chicken.png":
                    UpdateTexture( ref cache.ChickenTexId, stream, false ); break;
                case "creeper.png":
                    UpdateTexture( ref cache.CreeperTexId, stream, false ); break;
                case "pig.png":
                    UpdateTexture( ref cache.PigTexId, stream, false ); break;
                case "sheep.png":
                    UpdateTexture( ref cache.SheepTexId, stream, false ); break;
                case "skeleton.png":
                    UpdateTexture( ref cache.SkeletonTexId, stream, false ); break;
                case "spider.png":
                    UpdateTexture( ref cache.SpiderTexId, stream, false ); break;
                case "zombie.png":
                    UpdateTexture( ref cache.ZombieTexId, stream, false ); break;
                case "sheep_fur.png":
                    UpdateTexture( ref cache.SheepFurTexId, stream, false ); break;
                case "char.png":
                    UpdateTexture( ref cache.HumanoidTexId, stream, true ); break;
                case "clouds.png":
                case "cloud.png":
                    UpdateTexture( ref game.CloudsTexId, stream, false ); break;
                case "rain.png":
                    UpdateTexture( ref game.RainTexId, stream, false ); break;
                case "snow.png":
                    UpdateTexture( ref game.SnowTexId, stream, false ); break;
                case "gui.png":
                    UpdateTexture( ref game.GuiTexId, stream, false ); break;
                case "gui_classic.png":
                    UpdateTexture( ref game.GuiClassicTexId, stream, false ); break;
                case "animations.png":
                case "animation.png":
                    game.Animations.SetAtlas( Platform.ReadBmp( stream ) ); break;
                case "animations.txt":
                case "animation.txt":
                    StreamReader reader = new StreamReader( stream );
                    game.Animations.ReadAnimationsDescription( reader );
                    break;
                case "particles.png":
                    UpdateTexture( ref game.ParticleManager.ParticlesTexId,
                                  stream, false ); break;
                case "default.png":
                    SetFontBitmap( game, stream ); break;
            }

            if( !name.EndsWith( ".png" ) ) return;
            string tex = name.Substring( 0, name.Length - 4 );
            game.Events.RaiseTextureChanged( tex );
        }
Esempio n. 14
0
 static void ProcessZipEntry( string filename, byte[] data, ZipEntry entry )
 {
     string path = Path.Combine( "CS_Update", Path.GetFileName( filename ) );
     File.WriteAllBytes( path, data );
 }
Esempio n. 15
0
        void ReadCentralDirectory( BinaryReader reader, ZipEntry[] entries )
        {
            ZipEntry entry;
            entry.CentralHeaderOffset = (int)( reader.BaseStream.Position - 4 );
            reader.ReadUInt16(); // OS
            ushort versionNeeded = reader.ReadUInt16();
            ushort flags = reader.ReadUInt16();
            ushort compressionMethod = reader.ReadUInt16();
            reader.ReadUInt32(); // last modified
            uint crc32 = reader.ReadUInt32();
            int compressedSize = reader.ReadInt32();
            int uncompressedSize = reader.ReadInt32();
            ushort fileNameLen = reader.ReadUInt16();
            ushort extraFieldLen = reader.ReadUInt16();

            ushort fileCommentLen = reader.ReadUInt16();
            ushort diskNum = reader.ReadUInt16();
            ushort internalAttributes = reader.ReadUInt16();
            uint externalAttributes = reader.ReadUInt32();
            int localHeaderOffset = reader.ReadInt32();
            string fileName = enc.GetString( reader.ReadBytes( fileNameLen ) );
            reader.ReadBytes( extraFieldLen );
            reader.ReadBytes( fileCommentLen );

            entry.CompressedDataSize = compressedSize;
            entry.UncompressedDataSize = uncompressedSize;
            entry.LocalHeaderOffset = localHeaderOffset;
            entry.Filename = fileName;
            entry.Crc32 = crc32;
            entries[index++] = entry;
        }
Esempio n. 16
0
        void ReadLocalFileHeader( BinaryReader reader, ZipEntry entry )
        {
            ushort versionNeeded = reader.ReadUInt16();
            ushort flags = reader.ReadUInt16();
            ushort compressionMethod = reader.ReadUInt16();
            reader.ReadUInt32(); // last modified
            reader.ReadUInt32(); // CRC 32

            int compressedSize = reader.ReadInt32();
            if( compressedSize == 0 ) compressedSize = entry.CompressedDataSize;
            int uncompressedSize = reader.ReadInt32();
            if( uncompressedSize == 0 ) uncompressedSize = entry.UncompressedDataSize;
            ushort fileNameLen = reader.ReadUInt16();
            ushort extraFieldLen = reader.ReadUInt16();
            string fileName = enc.GetString( reader.ReadBytes( fileNameLen ) );
            if( !ShouldProcessZipEntry( fileName ) ) return;

            reader.ReadBytes( extraFieldLen );
            if( versionNeeded > 20 )
                Utils.LogDebug( "May not be able to properly extract a .zip enty with a version later than 2.0" );

            byte[] data = DecompressEntry( reader, compressionMethod, compressedSize, uncompressedSize );
            if( data != null )
                ProcessZipEntry( fileName, data, entry );
        }
Esempio n. 17
0
        void WriteCentralDirectoryHeaderEntry( ZipEntry entry )
        {
            writer.Write( 0x02014b50 ); // signature
            writer.Write( (ushort)20 ); // version
            writer.Write( (ushort)20 ); // version needed
            writer.Write( (ushort)0 );  // bitflags
            writer.Write( (ushort)0 );  // compression method
            writer.Write( 0 );          // last modified
            writer.Write( entry.Crc32 );
            writer.Write( entry.CompressedDataSize );
            writer.Write( entry.UncompressedDataSize );

            writer.Write( (ushort)entry.Filename.Length );
            writer.Write( (ushort)0 );  // extra field length
            writer.Write( (ushort)0 );  // file comment length
            writer.Write( (ushort)0 );  // disk number
            writer.Write( (ushort)0 );  // internal attributes
            writer.Write( 0 );          // external attributes
            writer.Write( entry.LocalHeaderOffset );
            for( int i = 0; i < entry.Filename.Length; i++ )
                writer.Write( (byte)entry.Filename[i] );
        }
Esempio n. 18
0
 void ProcessZipEntry_Modern( string filename, byte[] data, ZipEntry entry )
 {
     switch( filename ) {
         case "assets/minecraft/textures/environment/snow.png":
             entry.Filename = "snow.png";
             writer.WriteZipEntry( entry, data );
             break;
         case "assets/minecraft/textures/entity/chicken.png":
             entry.Filename = "mob/chicken.png";
             writer.WriteZipEntry( entry, data );
             break;
         case "assets/minecraft/textures/blocks/water_still.png":
             PatchDefault( data, 0 );
             break;
         case "assets/minecraft/textures/blocks/lava_still.png":
             PatchCycle( data, 16 );
             break;
         case "assets/minecraft/textures/blocks/fire_layer_1.png":
             PatchDefault( data, 32 );
             break;
     }
 }
Esempio n. 19
0
        void ProcessZipEntry_Classic( string filename, byte[] data, ZipEntry entry )
        {
            if( writer.entries == null )
                writer.entries = new ZipEntry[reader.entries.Length];
            if( filename != "terrain.png" ) {
                writer.WriteZipEntry( entry, data );
                return;
            }

            using( Bitmap dstBitmap = new Bitmap( new MemoryStream( data ) ),
                  maskBitmap = new Bitmap( new MemoryStream( pngTerrainPatch ) ) ) {
                PatchImage( dstBitmap, maskBitmap );
                writer.WriteNewImage( dstBitmap, "terrain.png" );
            }
        }
        void ProcessZipEntry_Classic( string filename, byte[] data, ZipEntry entry )
        {
            if( writer.entries == null )
                writer.entries = new ZipEntry[reader.entries.Length];
            if( !filename.EndsWith( ".png", comp ) ) return;

            if( filename != "terrain.png" ) {
                int lastSlash = filename.LastIndexOf( '/' );
                if( lastSlash >= 0 )
                    entry.Filename = filename.Substring( lastSlash + 1 );
                if( entry.Filename == "gui.png" )
                    entry.Filename = "gui_classic.png";
                writer.WriteZipEntry( entry, data );
                return;
            }

            using( Bitmap dstBitmap = new Bitmap( new MemoryStream( data ) ),
                  maskBitmap = new Bitmap( new MemoryStream( pngTerrainPatch ) ) ) {
                PatchImage( dstBitmap, maskBitmap );
                writer.WriteNewImage( dstBitmap, "terrain.png" );
            }
        }