internal static void ExtractDefault(Game game)
        {
            TexturePackExtractor extractor = new TexturePackExtractor();

            extractor.Extract(game.DefaultTexturePack, game);
            game.World.TextureUrl = null;
        }
        internal static void ExtractTexturePack(Game game, DownloadedItem item)
        {
            if (item.Data != null)
            {
                game.World.TextureUrl = item.Url;
                byte[] data = (byte[])item.Data;
                TexturePackExtractor extractor = new TexturePackExtractor();
                using (Stream ms = new MemoryStream(data)) {
                    extractor.Extract(ms, game);
                }

                TextureCache.Add(item.Url, data);
                TextureCache.AddETag(item.Url, item.ETag, game.ETags);
                TextureCache.AdddLastModified(item.Url, item.LastModified, game.LastModified);
            }
            else
            {
                FileStream data = TextureCache.GetStream(item.Url);
                if (data == null)                    // e.g. 404 errors
                {
                    ExtractDefault(game);
                }
                else if (item.Url != game.World.TextureUrl)
                {
                    game.World.TextureUrl = item.Url;
                    TexturePackExtractor extractor = new TexturePackExtractor();
                    extractor.Extract(data, game);
                }
            }
        }
Пример #3
0
 protected override void TextButtonClick( Game game, Widget widget )
 {
     string path = ((ButtonWidget)widget).Text;
     if( File.Exists( path ) ) {
         TexturePackExtractor extractor = new TexturePackExtractor();
         extractor.Extract( path, game );
     }
 }
        protected override void TextButtonClick( Game game, Widget widget, MouseButton mouseBtn )
        {
            if( mouseBtn != MouseButton.Left ) return;
            string file = ((ButtonWidget)widget).Text;
            string dir = Path.Combine( Program.AppDirectory, TexturePackExtractor.Dir );
            string path = Path.Combine( dir, file );
            if( !File.Exists( path ) ) return;

            int index = currentIndex;
            game.DefaultTexturePack = file;
            game.World.TextureUrl = null;
            TexturePackExtractor extractor = new TexturePackExtractor();
            extractor.Extract( path, game );
            Recreate();
            SetCurrentIndex( index );
        }
Пример #5
0
        protected override void OnLoad( EventArgs e )
        {
            #if !USE_DX
            Graphics = new OpenGLApi();
            #else
            Graphics = new Direct3D9Api( this );
            #endif
            try {
                Options.Load();
            } catch( IOException ) {
                Utils.LogWarning( "Unable to load options.txt" );
            }
            ViewDistance = Options.GetInt( "viewdist", 16, 8192, 512 );
            Keys = new KeyMap();
            InputHandler = new InputHandler( this );
            Chat = new ChatLog( this );
            Drawer2D = new GdiPlusDrawer2D( Graphics );
            defaultIb = Graphics.MakeDefaultIb();

            ModelCache = new ModelCache( this );
            ModelCache.InitCache();
            AsyncDownloader = new AsyncDownloader( skinServer );
            Graphics.PrintGraphicsInfo();
            TerrainAtlas1D = new TerrainAtlas1D( Graphics );
            TerrainAtlas = new TerrainAtlas2D( Graphics, Drawer2D );
            Animations = new Animations( this );
            TexturePackExtractor extractor = new TexturePackExtractor();
            extractor.Extract( defaultTexPack, this );
            Inventory = new Inventory( this );

            BlockInfo = new BlockInfo();
            BlockInfo.Init();
            BlockInfo.SetDefaultBlockPermissions( Inventory.CanPlace, Inventory.CanDelete );
            Map = new Map( this );
            LocalPlayer = new LocalPlayer( this );
            Players[255] = LocalPlayer;
            width = Width;
            height = Height;
            MapRenderer = new MapRenderer( this );
            MapEnvRenderer = new MapEnvRenderer( this );
            EnvRenderer = new StandardEnvRenderer( this );
            if( IPAddress == null ) {
                Network = new Singleplayer.SinglePlayerServer( this );
            } else {
                Network = new NetworkProcessor( this );
            }
            Graphics.LostContextFunction = Network.Tick;

            firstPersonCam = new FirstPersonCamera( this );
            thirdPersonCam = new ThirdPersonCamera( this );
            Camera = firstPersonCam;
            CommandManager = new CommandManager();
            CommandManager.Init( this );
            SelectionManager = new SelectionManager( this );
            ParticleManager = new ParticleManager( this );
            WeatherRenderer = new WeatherRenderer( this );
            WeatherRenderer.Init();

            Graphics.SetVSync( this, true );
            Graphics.DepthTest = true;
            Graphics.DepthTestFunc( CompareFunc.LessEqual );
            //Graphics.DepthWrite = true;
            Graphics.AlphaBlendFunc( BlendFunc.SourceAlpha, BlendFunc.InvSourceAlpha );
            Graphics.AlphaTestFunc( CompareFunc.Greater, 0.5f );
            Title = Utils.AppName;
            fpsScreen = new FpsScreen( this );
            fpsScreen.Init();
            Culling = new FrustumCulling();
            EnvRenderer.Init();
            MapEnvRenderer.Init();
            Picking = new PickingRenderer( this );

            string connectString = "Connecting to " + IPAddress + ":" + Port +  "..";
            SetNewScreen( new LoadingMapScreen( this, connectString, "Reticulating splines" ) );
            Network.Connect( IPAddress, Port );
        }
 void ExtractDefault()
 {
     TexturePackExtractor extractor = new TexturePackExtractor();
     extractor.Extract( game.DefaultTexturePack, game );
 }
        void CheckForNewTerrainAtlas()
        {
            DownloadedItem item;
            if( game.AsyncDownloader.TryGetItem( "terrain", out item ) ) {
                if( item.Data != null ) {
                    game.ChangeTerrainAtlas( (Bitmap)item.Data );
                    TextureCache.AddToCache( item.Url, (Bitmap)item.Data );
                } else if( Is304Status( item.WebEx ) ) {
                    Bitmap bmp = TextureCache.GetBitmapFromCache( item.Url );
                    if( bmp == null ) // Should never happen, but handle anyways.
                        ExtractDefault();
                    else
                        game.ChangeTerrainAtlas( bmp );
                } else {
                    ExtractDefault();
                }
            }

            if( game.AsyncDownloader.TryGetItem( "texturePack", out item ) ) {
                if( item.Data != null ) {
                    TexturePackExtractor extractor = new TexturePackExtractor();
                    extractor.Extract( (byte[])item.Data, game );
                    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 {
                        TexturePackExtractor extractor = new TexturePackExtractor();
                        extractor.Extract( data, game );
                    }
                } else {
                    ExtractDefault();
                }
            }
        }
Пример #8
0
        void CheckForNewTerrainAtlas()
        {
            DownloadedItem item;
            if( game.AsyncDownloader.TryGetItem( "terrain", out item ) ) {
                if( item.Data != null ) {
                    game.ChangeTerrainAtlas( (Bitmap)item.Data );
                } else {
                    TexturePackExtractor extractor = new TexturePackExtractor();
                    extractor.Extract( game.defaultTexPack, game );
                }
            }

            if( game.AsyncDownloader.TryGetItem( "texturePack", out item ) ) {
                TexturePackExtractor extractor = new TexturePackExtractor();
                if( item.Data != null ) {
                    extractor.Extract( (byte[])item.Data, game );
                } else {
                    extractor.Extract( game.defaultTexPack, game );
                }
            }
        }
Пример #9
0
        void ReadPacket( byte opcode )
        {
            reader.Remove( 1 ); // remove opcode
            lastOpcode = (PacketId)opcode;

            switch( (PacketId)opcode ) {
                case PacketId.Handshake:
                    {
                        byte protocolVer = reader.ReadUInt8();
                        ServerName = reader.ReadAsciiString();
                        ServerMotd = reader.ReadAsciiString();
                        game.LocalPlayer.SetUserType( reader.ReadUInt8() );
                        receivedFirstPosition = false;
                        game.LocalPlayer.ParseHackFlags( ServerName, ServerMotd );
                    } break;

                case PacketId.Ping:
                    break;

                case PacketId.LevelInitialise:
                    {
                        game.Map.Reset();
                        game.SetNewScreen( new LoadingMapScreen( game, ServerName, ServerMotd ) );
                        if( ServerMotd.Contains( "cfg=" ) ) {
                            ReadWomConfigurationAsync();
                        }
                        receivedFirstPosition = false;
                        gzipHeader = new GZipHeaderReader();
                        // Workaround because built in mono stream assumes that the end of stream
                        // has been reached the first time a read call returns 0. (MS.NET doesn't)
                        #if __MonoCS__
                        gzipStream = new DeflateStream( gzippedMap, true );
                        #else
                        gzipStream = new DeflateStream( gzippedMap, CompressionMode.Decompress );
                        if( OpenTK.Configuration.RunningOnMono ) {
                            Utils.LogWarning( "You are running on Mono, but this build does not support the Mono workaround." );
                            Utils.LogWarning( "You should either download the Mono compatible build or define '__MonoCS__' when targeting Mono. " +
                                             "(The Mono compiler already defines this by default)" );
                            Utils.LogWarning( "You will likely experience an 'Internal error (no progress possible) ReadInternal' exception when decompressing the map." );
                        }
                        #endif
                        mapSizeIndex = 0;
                        mapIndex = 0;
                        receiveStart = DateTime.UtcNow;
                    } break;

                case PacketId.LevelDataChunk:
                    {
                        int usedLength = reader.ReadInt16();
                        gzippedMap.Position = 0;
                        gzippedMap.SetLength( usedLength );

                        if( gzipHeader.done || gzipHeader.ReadHeader( gzippedMap ) ) {
                            if( mapSizeIndex < 4 ) {
                                mapSizeIndex += gzipStream.Read( mapSize, mapSizeIndex, 4 - mapSizeIndex );
                            }

                            if( mapSizeIndex == 4 ) {
                                if( map == null ) {
                                    int size = mapSize[0] << 24 | mapSize[1] << 16 | mapSize[2] << 8 | mapSize[3];
                                    map = new byte[size];
                                }
                                mapIndex += gzipStream.Read( map, mapIndex, map.Length - mapIndex );
                            }
                        }
                        reader.Remove( 1024 );
                        byte progress = reader.ReadUInt8();
                        game.Events.RaiseMapLoading( progress );
                    } break;

                case PacketId.LevelFinalise:
                    {
                        game.SetNewScreen( new NormalScreen( game ) );
                        int mapWidth = reader.ReadInt16();
                        int mapHeight = reader.ReadInt16();
                        int mapLength = reader.ReadInt16();

                        double loadingMs = ( DateTime.UtcNow - receiveStart ).TotalMilliseconds;
                        Utils.LogDebug( "map loading took:" + loadingMs );
                        game.Map.UseRawMap( map, mapWidth, mapHeight, mapLength );
                        game.Events.RaiseOnNewMapLoaded();
                        map = null;
                        gzipStream.Close();
                        if( sendWomId && !sentWomId ) {
                            SendChat( "/womid WoMClient-2.0.7" );
                            sentWomId = true;
                        }
                        gzipStream = null;
                        GC.Collect( 0 );
                    } break;

                case PacketId.SetBlock:
                    {
                        int x = reader.ReadInt16();
                        int y = reader.ReadInt16();
                        int z = reader.ReadInt16();
                        byte type = reader.ReadUInt8();
                        if( !game.Map.IsNotLoaded )
                            game.UpdateBlock( x, y, z, type );
                        else
                            Utils.LogWarning( "Server tried to update a block while still sending us the map!" );
                    } break;

                case PacketId.AddEntity:
                    {
                        byte entityId = reader.ReadUInt8();
                        string name = reader.ReadAsciiString();
                        AddEntity( entityId, name, name, true );
                    }  break;

                case PacketId.EntityTeleport:
                    {
                        byte entityId = reader.ReadUInt8();
                        ReadAbsoluteLocation( entityId, true );
                    } break;

                case PacketId.RelPosAndOrientationUpdate:
                    ReadRelativeLocation();
                    break;

                case PacketId.RelPosUpdate:
                    ReadRelativePosition();
                    break;

                case PacketId.OrientationUpdate:
                    ReadOrientation();
                    break;

                case PacketId.RemoveEntity:
                    {
                        byte entityId = reader.ReadUInt8();
                        Player player = game.Players[entityId];
                        if( entityId != 0xFF && player != null ) {
                            game.Events.RaiseEntityRemoved( entityId );
                            player.Despawn();
                            game.Players[entityId] = null;
                        }
                    } break;

                case PacketId.Message:
                    {
                        byte messageType = reader.ReadUInt8();
                        string text = reader.ReadChatString( ref messageType, useMessageTypes );
                        game.Chat.Add( text, (CpeMessage)messageType );
                    } break;

                case PacketId.Kick:
                    {
                        string reason = reader.ReadAsciiString();
                        game.Disconnect( "&eLost connection to the server", reason );
                        Dispose();
                    } break;

                case PacketId.SetPermission:
                    {
                        game.LocalPlayer.SetUserType( reader.ReadUInt8() );
                    } break;

                case PacketId.CpeExtInfo:
                    {
                        string appName = reader.ReadAsciiString();
                        Utils.LogDebug( "Server identified itself as: " + appName );
                        cpeServerExtensionsCount = reader.ReadInt16();
                    } break;

                case PacketId.CpeExtEntry:
                    {
                        string extName = reader.ReadAsciiString();
                        int extVersion = reader.ReadInt32();
                        Utils.LogDebug( "cpe ext: " + extName + " , " + extVersion );
                        if( extName == "HeldBlock" ) {
                            sendHeldBlock = true;
                        } else if( extName == "MessageTypes" ) {
                            useMessageTypes = true;
                        } else if( extName == "ExtPlayerList" ) {
                            UsingExtPlayerList = true;
                        } else if( extName == "PlayerClick" ) {
                            UsingPlayerClick = true;
                        } else if( extName == "EnvMapAppearance" && extVersion == 2 ) {
                            usingTexturePack = true;
                        }
                        cpeServerExtensionsCount--;

                        if( cpeServerExtensionsCount == 0 ) {
                            MakeExtInfo( Utils.AppName, clientExtensions.Length );
                            SendPacket();
                            for( int i = 0; i < clientExtensions.Length; i++ ) {
                                string name = clientExtensions[i];
                                int version = (name == "ExtPlayerList" || name == "EnvMapApperance") ? 2 : 1;
                                MakeExtEntry( name, version );
                                SendPacket();
                            }
                        }
                    } break;

                case PacketId.CpeSetClickDistance:
                    {
                        game.LocalPlayer.ReachDistance = reader.ReadInt16() / 32f;
                    } break;

                case PacketId.CpeCustomBlockSupportLevel:
                    {
                        byte supportLevel = reader.ReadUInt8();
                        MakeCustomBlockSupportLevel( 1 );
                        SendPacket();

                        if( supportLevel == 1 ) {
                            for( int i = (int)Block.CobblestoneSlab; i <= (int)Block.StoneBrick; i++ ) {
                                game.Inventory.CanPlace[i] = true;
                                game.Inventory.CanDelete[i] = true;
                            }
                            game.Events.RaiseBlockPermissionsChanged();
                        } else {
                            Utils.LogWarning( "Server's block support level is {0}, this client only supports level 1.", supportLevel );
                            Utils.LogWarning( "You won't be able to see or use blocks from levels above level 1" );
                        }
                    } break;

                case PacketId.CpeHoldThis:
                    {
                        byte blockType = reader.ReadUInt8();
                        bool canChange = reader.ReadUInt8() == 0;
                        game.Inventory.CanChangeHeldBlock = true;
                        game.Inventory.HeldBlock = (Block)blockType;
                        game.Inventory.CanChangeHeldBlock = canChange;
                    } break;

                case PacketId.CpeExtAddPlayerName:
                    {
                        short nameId = reader.ReadInt16();
                        string playerName = Utils.StripColours( reader.ReadAsciiString() );
                        string listName = reader.ReadAsciiString();
                        string groupName = reader.ReadAsciiString();
                        byte groupRank = reader.ReadUInt8();
                        if( nameId >= 0 && nameId <= 255 ) {
                            CpeListInfo oldInfo = game.CpePlayersList[nameId];
                            CpeListInfo info = new CpeListInfo( (byte)nameId, playerName, listName, groupName, groupRank );
                            game.CpePlayersList[nameId] = info;

                            if( oldInfo != null ) {
                                game.Events.RaiseCpeListInfoChanged( (byte)nameId );
                            } else {
                                game.Events.RaiseCpeListInfoAdded( (byte)nameId );
                            }
                        }
                    } break;

                case PacketId.CpeExtAddEntity:
                    {
                        byte entityId = reader.ReadUInt8();
                        string displayName = reader.ReadAsciiString();
                        string skinName = reader.ReadAsciiString();
                        AddEntity( entityId, displayName, skinName, false );
                    } break;

                case PacketId.CpeExtRemovePlayerName:
                    {
                        short nameId = reader.ReadInt16();
                        if( nameId >= 0 && nameId <= 255 ) {
                            game.Events.RaiseCpeListInfoRemoved( (byte)nameId );
                            game.CpePlayersList[nameId] = null;
                        }
                    } break;

                case PacketId.CpeMakeSelection:
                    {
                        byte selectionId = reader.ReadUInt8();
                        string label = reader.ReadAsciiString();
                        short startX = reader.ReadInt16();
                        short startY = reader.ReadInt16();
                        short startZ = reader.ReadInt16();
                        short endX = reader.ReadInt16();
                        short endY = reader.ReadInt16();
                        short endZ = reader.ReadInt16();

                        byte r = (byte)reader.ReadInt16();
                        byte g = (byte)reader.ReadInt16();
                        byte b = (byte)reader.ReadInt16();
                        byte a = (byte)reader.ReadInt16();

                        Vector3I p1 = Vector3I.Min( startX, startY, startZ, endX, endY, endZ );
                        Vector3I p2 = Vector3I.Max( startX, startY, startZ, endX, endY, endZ );
                        FastColour col = new FastColour( r, g, b, a );
                        game.SelectionManager.AddSelection( selectionId, p1, p2, col );
                    } break;

                case PacketId.CpeRemoveSelection:
                    {
                        byte selectionId = reader.ReadUInt8();
                        game.SelectionManager.RemoveSelection( selectionId );
                    } break;

                case PacketId.CpeEnvColours:
                    {
                        byte variable = reader.ReadUInt8();
                        short red = reader.ReadInt16();
                        short green = reader.ReadInt16();
                        short blue = reader.ReadInt16();
                        bool invalid = red < 0 || red > 255 || green < 0 || green > 255 || blue < 0 || blue > 255;
                        FastColour col = new FastColour( red, green, blue );

                        if( variable == 0 ) { // sky colour
                            game.Map.SetSkyColour( invalid ? Map.DefaultSkyColour : col );
                        } else if( variable == 1 ) { // clouds colour
                            game.Map.SetCloudsColour( invalid ? Map.DefaultCloudsColour : col );
                        } else if( variable == 2 ) { // fog colour
                            game.Map.SetFogColour( invalid ? Map.DefaultFogColour : col );
                        } else if( variable == 3 ) { // ambient light (shadow light)
                            game.Map.SetShadowlight( invalid ? Map.DefaultShadowlight : col );
                        } else if( variable == 4 ) { // diffuse light (sun light)
                            game.Map.SetSunlight( invalid ? Map.DefaultSunlight : col );
                        }
                    } break;

                case PacketId.CpeSetBlockPermission:
                    {
                        byte blockId = reader.ReadUInt8();
                        bool canPlace = reader.ReadUInt8() != 0;
                        bool canDelete = reader.ReadUInt8() != 0;
                        Inventory inv = game.Inventory;

                        if( blockId == 0 ) {
                            for( int i = 1; i < BlockInfo.CpeBlocksCount; i++ ) {
                                inv.CanPlace.SetNotOverridable( canPlace, i );
                                inv.CanDelete.SetNotOverridable( canDelete, i );
                            }
                        } else {
                            inv.CanPlace.SetNotOverridable( canPlace, blockId );
                            inv.CanDelete.SetNotOverridable( canDelete, blockId );
                        }
                        game.Events.RaiseBlockPermissionsChanged();
                    } break;

                case PacketId.CpeChangeModel:
                    {
                        byte playerId = reader.ReadUInt8();
                        string modelName = reader.ReadAsciiString().ToLowerInvariant();
                        Player player = game.Players[playerId];
                        if( player != null ) {
                            player.SetModel( modelName );
                        }
                    } break;

                case PacketId.CpeEnvSetMapApperance:
                    {
                        string url = reader.ReadAsciiString();
                        byte sideBlock = reader.ReadUInt8();
                        byte edgeBlock = reader.ReadUInt8();
                        short waterLevel = reader.ReadInt16();
                        game.Map.SetWaterLevel( waterLevel );
                        game.Map.SetEdgeBlock( (Block)edgeBlock );
                        game.Map.SetSidesBlock( (Block)sideBlock );
                        if( url == String.Empty ) {
                            TexturePackExtractor extractor = new TexturePackExtractor();
                            extractor.Extract( game.defaultTexPack, game );
                        } else {
                            game.Animations.Dispose();
                            if( usingTexturePack )
                                game.AsyncDownloader.DownloadData( url, true, "texturePack" );
                            else
                                game.AsyncDownloader.DownloadImage( url, true, "terrain" );

                        }
                        Utils.LogDebug( "Image url: " + url );
                    } break;

                case PacketId.CpeEnvWeatherType:
                    game.Map.SetWeather( (Weather)reader.ReadUInt8() );
                    break;

                case PacketId.CpeHackControl:
                    {
                        game.LocalPlayer.CanFly = reader.ReadUInt8() != 0;
                        game.LocalPlayer.CanNoclip = reader.ReadUInt8() != 0;
                        game.LocalPlayer.CanSpeed = reader.ReadUInt8() != 0;
                        game.LocalPlayer.CanRespawn = reader.ReadUInt8() != 0;
                        game.CanUseThirdPersonCamera = reader.ReadUInt8() != 0;
                        if( !game.CanUseThirdPersonCamera ) {
                            game.SetCamera( false );
                        }
                        float jumpHeight = reader.ReadInt16() / 32f;
                        if( jumpHeight < 0 ) jumpHeight = 1.4f;
                        game.LocalPlayer.CalculateJumpVelocity( jumpHeight );
                    } break;

                case PacketId.CpeExtAddEntity2:
                    {
                        byte entityId = reader.ReadUInt8();
                        string displayName = reader.ReadAsciiString();
                        string skinName = reader.ReadAsciiString();
                        AddEntity( entityId, displayName, skinName, true );
                    } break;

                case PacketId.CpeDefineBlock:
                case PacketId.CpeDefineLiquid:
                    {
                        byte block = reader.ReadUInt8();
                        BlockInfo info = game.BlockInfo;
                        info.ResetBlockInfo( block );

                        info.Name[block] = reader.ReadAsciiString();
                        info.CollideType[block] = (BlockCollideType)reader.ReadUInt8();
                        // TODO: Liquid collide type not properly supported.
                        info.SpeedMultiplier[block] = (float)Math.Pow( 2, (reader.ReadUInt8() - 128) / 64f );
                        info.SetTop( reader.ReadUInt8(), (Block)block );
                        info.SetSide( reader.ReadUInt8(), (Block)block );
                        info.SetBottom( reader.ReadUInt8(), (Block)block );
                        reader.ReadUInt8(); // opacity hint, but we ignore this.
                        info.BlocksLight[block] = reader.ReadUInt8() == 0;
                        reader.ReadUInt8(); // walk sound, but we ignore this.
                        info.EmitsLight[block] = reader.ReadUInt8() != 0;

                        if( opcode == (byte)PacketId.CpeDefineBlock ) {
                            byte shape = reader.ReadUInt8();
                            if( shape == 1 ) info.Height[block] = 1;
                            else if( shape == 2 ) info.Height[block] = 0.5f;
                            // TODO: upside down slab not properly supported
                            else if( shape == 3 ) info.Height[block] = 0.5f;
                            else if( shape == 4 ) info.IsSprite[block] = true;

                            byte blockDraw = reader.ReadUInt8();
                            if( blockDraw == 0 ) info.IsOpaque[block] = true;
                            else if( blockDraw == 1 ) info.IsTransparent[block] = true;
                            else if( blockDraw == 2 ) info.IsTranslucent[block] = true;
                            else if( blockDraw == 3 ) info.IsTranslucent[block] = true;

                            Console.WriteLine( block + " : " + shape + "," + blockDraw );
                        } else {
                            byte fogDensity = reader.ReadUInt8();
                            info.FogDensity[block] = fogDensity == 0 ? 0 : (fogDensity + 1) / 128f;
                            info.FogColour[block] = new FastColour(
                                reader.ReadUInt8(), reader.ReadUInt8(), reader.ReadUInt8() );
                        }
                        info.SetupCullingCache();
                    } break;

                case PacketId.CpeRemoveBlockDefinition:
                    game.BlockInfo.ResetBlockInfo( reader.ReadUInt8() );
                    break;

                default:
                    throw new NotImplementedException( "Unsupported packet:" + (PacketId)opcode );
            }
        }
Пример #10
0
 void CheckForNewTerrainAtlas()
 {
     DownloadedItem item;
     game.AsyncDownloader.TryGetItem( "terrain", out item );
     if( item != null && item.Data != null ) {
         game.ChangeTerrainAtlas( (Bitmap)item.Data );
     }
     game.AsyncDownloader.TryGetItem( "texturePack", out item );
     if( item != null && item.Data != null ) {
         TexturePackExtractor extractor = new TexturePackExtractor();
         extractor.Extract( (byte[])item.Data, game );
     }
 }
Пример #11
0
		void HandleCpeEnvSetMapApperance() {
			string url = reader.ReadAsciiString();
			game.Map.SetSidesBlock( (Block)reader.ReadUInt8() );
			game.Map.SetEdgeBlock( (Block)reader.ReadUInt8() );
			game.Map.SetWaterLevel( reader.ReadInt16() );
			if( usingTexturePack ) {
				game.Map.SetCloudsLevel( reader.ReadInt16() );
				short maxViewDist = reader.ReadInt16(); // TODO: what to do with this?
			}
			
			if( url == String.Empty ) {
				TexturePackExtractor extractor = new TexturePackExtractor();
				extractor.Extract( game.defaultTexPack, game );
			} else {
				game.Animations.Dispose();
				if( usingTexturePack )
					game.AsyncDownloader.DownloadData( url, true, "texturePack" );
				else
					game.AsyncDownloader.DownloadImage( url, true, "terrain" );
				
			}
			Utils.LogDebug( "Image url: " + url );
		}
Пример #12
0
        protected override void OnLoad( EventArgs e )
        {
            #if !USE_DX
            Graphics = new OpenGLApi();
            #else
            Graphics = new Direct3D9Api( this );
            #endif
            Graphics.MakeGraphicsInfo();

            Options.Load();
            ViewDistance = Options.GetInt( OptionsKey.ViewDist, 16, 4096, 512 );
            InputHandler = new InputHandler( this );
            Chat = new ChatLog( this );
            Chat.FontSize = Options.GetInt( OptionsKey.FontSize, 6, 30, 12 );
            defaultIb = Graphics.MakeDefaultIb();
            MouseSensitivity = Options.GetInt( OptionsKey.Sensitivity, 1, 100, 30 );
            BlockInfo = new BlockInfo();
            BlockInfo.Init();
            ChatLines = Options.GetInt( OptionsKey.ChatLines, 1, 30, 12 );
            ModelCache = new ModelCache( this );
            ModelCache.InitCache();
            AsyncDownloader = new AsyncDownloader( skinServer );
            Drawer2D = new GdiPlusDrawer2D( Graphics );
            Drawer2D.UseBitmappedChat = !Options.GetBool( OptionsKey.ArialChatFont, false );

            TerrainAtlas1D = new TerrainAtlas1D( Graphics );
            TerrainAtlas = new TerrainAtlas2D( Graphics, Drawer2D );
            Animations = new Animations( this );
            TexturePackExtractor extractor = new TexturePackExtractor();
            extractor.Extract( defaultTexPack, this );
            Inventory = new Inventory( this );

            BlockInfo.SetDefaultBlockPermissions( Inventory.CanPlace, Inventory.CanDelete );
            Map = new Map( this );
            LocalPlayer = new LocalPlayer( this );
            LocalPlayer.SpeedMultiplier = Options.GetInt( OptionsKey.Speed, 1, 50, 10 );
            Players[255] = LocalPlayer;
            width = Width;
            height = Height;
            MapRenderer = new MapRenderer( this );
            MapEnvRenderer = new MapEnvRenderer( this );
            EnvRenderer = new StandardEnvRenderer( this );
            if( IPAddress == null ) {
                Network = new Singleplayer.SinglePlayerServer( this );
            } else {
                Network = new NetworkProcessor( this );
            }
            Graphics.LostContextFunction = Network.Tick;

            firstPersonCam = new FirstPersonCamera( this );
            thirdPersonCam = new ThirdPersonCamera( this );
            forwardThirdPersonCam = new ForwardThirdPersonCamera( this );
            Camera = firstPersonCam;
            CommandManager = new CommandManager();
            CommandManager.Init( this );
            SelectionManager = new SelectionManager( this );
            ParticleManager = new ParticleManager( this );
            WeatherRenderer = new WeatherRenderer( this );
            WeatherRenderer.Init();

            bool vsync = Options.GetBool( OptionsKey.VSync, true );
            Graphics.SetVSync( this, vsync );
            Graphics.DepthTest = true;
            Graphics.DepthTestFunc( CompareFunc.LessEqual );
            //Graphics.DepthWrite = true;
            Graphics.AlphaBlendFunc( BlendFunc.SourceAlpha, BlendFunc.InvSourceAlpha );
            Graphics.AlphaTestFunc( CompareFunc.Greater, 0.5f );
            fpsScreen = new FpsScreen( this );
            fpsScreen.Init();
            Culling = new FrustumCulling();
            EnvRenderer.Init();
            MapEnvRenderer.Init();
            Picking = new PickingRenderer( this );

            string connectString = "Connecting to " + IPAddress + ":" + Port +  "..";
            Graphics.WarnIfNecessary( Chat );
            SetNewScreen( new LoadingMapScreen( this, connectString, "Reticulating splines" ) );
            Network.Connect( IPAddress, Port );
        }
Пример #13
0
        protected void CheckAsyncResources()
        {
            DownloadedItem item;
            if( game.AsyncDownloader.TryGetItem( "terrain", out item ) ) {
                if( item.Data != null ) {
                    Bitmap bmp = (Bitmap)item.Data;
                    game.World.TextureUrl = item.Url;
                    game.Events.RaiseTexturePackChanged();

                    if( !FastBitmap.CheckFormat( bmp.PixelFormat ) ) {
                        Utils.LogDebug( "Converting terrain atlas to 32bpp image" );
                        game.Drawer2D.ConvertTo32Bpp( ref bmp );
                    }
                    if( !game.ChangeTerrainAtlas( bmp ) ) { bmp.Dispose(); return; }
                    TextureCache.AddToCache( item.Url, bmp );
                    TextureCache.AddETagToCache( item.Url, item.ETag, game.ETags );
                } else if( item.ResponseCode == HttpStatusCode.NotModified ) {
                    Bitmap bmp = TextureCache.GetBitmapFromCache( item.Url );
                    if( bmp == null ) {// Should never happen, but handle anyways.
                        ExtractDefault();
                    } else if( item.Url != game.World.TextureUrl ) {
                        game.Events.RaiseTexturePackChanged();
                        if( !game.ChangeTerrainAtlas( bmp ) ) { bmp.Dispose(); return; }
                    }

                    if( bmp != null ) game.World.TextureUrl = item.Url;
                } else {
                    ExtractDefault();
                }
            }

            if( game.AsyncDownloader.TryGetItem( "texturePack", out item ) ) {
                if( item.Data != null ) {
                    game.World.TextureUrl = item.Url;

                    TexturePackExtractor extractor = new TexturePackExtractor();
                    extractor.Extract( (byte[])item.Data, game );
                    TextureCache.AddToCache( item.Url, (byte[])item.Data );
                    TextureCache.AddETagToCache( item.Url, item.ETag, game.ETags );
                } else if( item.ResponseCode == HttpStatusCode.NotModified ) {
                    byte[] data = TextureCache.GetDataFromCache( item.Url );
                    if( data == null ) { // Should never happen, but handle anyways.
                        ExtractDefault();
                    } else if( item.Url != game.World.TextureUrl ) {
                        TexturePackExtractor extractor = new TexturePackExtractor();
                        extractor.Extract( data, game );
                    }

                    if( data != null ) game.World.TextureUrl = item.Url;
                } else {
                    ExtractDefault();
                }
            }
        }
Пример #14
0
 protected void ExtractDefault()
 {
     TexturePackExtractor extractor = new TexturePackExtractor();
     extractor.Extract( game.DefaultTexturePack, game );
     game.World.TextureUrl = null;
 }
		void HandleCpeEnvSetMapApperance() {
			string url = reader.ReadAsciiString();
			game.Map.SetSidesBlock( (Block)reader.ReadUInt8() );
			game.Map.SetEdgeBlock( (Block)reader.ReadUInt8() );
			game.Map.SetEdgeLevel( reader.ReadInt16() );
			if( usingTexturePack ) {
				// TODO: proper envmapappearance version 2 support
				game.Map.SetCloudsLevel( reader.ReadInt16() );
				short maxViewDist = reader.ReadInt16(); // TODO: what to do with this?
			}
			
			if( url == String.Empty ) {
				TexturePackExtractor extractor = new TexturePackExtractor();
				extractor.Extract( game.DefaultTexturePack, game );
			} else if( Utils.IsUrlPrefix( url ) ) {
				if( !game.AcceptedUrls.HasAccepted( url ) ) {
					game.AsyncDownloader.RetrieveContentLength( url, true, "CL_" + url );
					game.ShowWarning( new WarningScreen(
						game, "CL_" + url, "Do you want to download the server's terrain image?",
						DownloadTexturePack, null, WarningScreenTick,
						"The terrain image is located at:", url,
						"Terrain image size: Determining..." ) );
				} else {
					DownloadTexturePack( url );
				}
			}
			Utils.LogDebug( "Image url: " + url );
		}
Пример #16
0
        public override void Execute( CommandReader reader )
        {
            string path = reader.NextAll();
            if( String.IsNullOrEmpty( path ) ) return;

            try {
                TexturePackExtractor extractor = new TexturePackExtractor();
                extractor.Extract( path, game );
            } catch( FileNotFoundException ) {
                game.Chat.Add( "&e/client texturepack: Couldn't find file \"" + path + "\"" );
            }
        }