From 5e5ee2a1cd5117ec329b12b32b1f4a2b865ef972 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 2 Jan 2016 22:51:38 +1100 Subject: [PATCH] Allow changing jump height and fov again. --- ClassicalSharp/2D/Screens/FpsScreen.cs | 2 +- .../2D/Screens/Menu/HacksSettingsScreen.cs | 37 ++++++++++++++----- .../2D/Screens/Menu/OptionsScreen.cs | 10 ++++- ClassicalSharp/2D/Screens/Menu/PauseScreen.cs | 1 - ClassicalSharp/Commands/DefaultCommands.cs | 4 +- ClassicalSharp/Entities/LocalPlayer.cs | 12 ++---- ClassicalSharp/Game/Game.cs | 2 +- ClassicalSharp/Game/InputHandler.cs | 2 +- .../Network/NetworkProcessor.CPE.cs | 1 + ClassicalSharp/Network/NetworkProcessor.cs | 1 + 10 files changed, 45 insertions(+), 27 deletions(-) diff --git a/ClassicalSharp/2D/Screens/FpsScreen.cs b/ClassicalSharp/2D/Screens/FpsScreen.cs index 66f7dd14e..bd11e5f53 100644 --- a/ClassicalSharp/2D/Screens/FpsScreen.cs +++ b/ClassicalSharp/2D/Screens/FpsScreen.cs @@ -115,7 +115,7 @@ namespace ClassicalSharp { lastZoomFov = game.ZoomFieldOfView; int index = 0; text.Clear(); - int defFov = Options.GetInt( OptionsKey.FieldOfView, 1, 179, 70 ); + int defFov = Options.GetInt( OptionsKey.FieldOfView, 1, 150, 70 ); if( lastZoomFov != defFov ) text.Append( ref index, "Zoom fov " ) .AppendNum( ref index, lastZoomFov ).Append( ref index, " " ); diff --git a/ClassicalSharp/2D/Screens/Menu/HacksSettingsScreen.cs b/ClassicalSharp/2D/Screens/Menu/HacksSettingsScreen.cs index 2d974ed9c..87b3bd7d1 100644 --- a/ClassicalSharp/2D/Screens/Menu/HacksSettingsScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/HacksSettingsScreen.cs @@ -32,6 +32,10 @@ namespace ClassicalSharp { (g, v) => { g.CameraClipping = v == "yes"; Options.Set( OptionsKey.CameraClipping, v == "yes" ); } ), + Make( -140, 50, "Jump height", OnWidgetClick, + g => g.LocalPlayer.JumpHeight.ToString(), + (g, v) => g.LocalPlayer.CalculateJumpVelocity( Single.Parse( v ) ) ), + // Column 2 Make( 140, -100, "Liquids breakable", OnWidgetClick, g => g.LiquidsBreakable ? "yes" : "no", @@ -39,21 +43,16 @@ namespace ClassicalSharp { Options.Set( OptionsKey.LiquidsBreakable, v == "yes" ); } ), Make( 140, -50, "Pushback placing", OnWidgetClick, - g => g.LocalPlayer.PushbackPlacing - && g.LocalPlayer.CanPushbackBlocks ? "yes" : "no", - (g, v) => { - if( g.LocalPlayer.CanPushbackBlocks) { - g.LocalPlayer.PushbackPlacing = v == "yes"; - Options.Set( OptionsKey.PushbackPlacing, v == "yes" ); - } - }), + g => g.LocalPlayer.PushbackPlacing ? "yes" : "no", + (g, v) => { g.LocalPlayer.PushbackPlacing = v == "yes"; + Options.Set( OptionsKey.PushbackPlacing, v == "yes" ); }), Make( 140, 0, "Noclip slide", OnWidgetClick, g => g.LocalPlayer.NoclipSlide ? "yes" : "no", (g, v) => { g.LocalPlayer.NoclipSlide = v == "yes"; Options.Set( OptionsKey.NoclipSlide, v == "yes" ); } ), - Make( -140, 50, "Field of view", OnWidgetClick, + Make( 140, 50, "Field of view", OnWidgetClick, g => g.FieldOfView.ToString(), (g, v) => { g.FieldOfView = Int32.Parse( v ); Options.Set( OptionsKey.FieldOfView, v ); @@ -69,13 +68,26 @@ namespace ClassicalSharp { new BooleanValidator(), new RealValidator( 0.1f, 50 ), new BooleanValidator(), + new RealValidator( 0.1f, 1024f ), new BooleanValidator(), new BooleanValidator(), new BooleanValidator(), - new IntegerValidator( 1, 179 ), + new IntegerValidator( 1, 150 ), }; okayIndex = buttons.Length - 1; + game.Events.HackPermissionsChanged += CheckHacksAllowed; + } + + void CheckHacksAllowed( object sender, EventArgs e ) { + for( int i = 0; i < buttons.Length; i++ ) { + if( buttons[i] == null ) continue; + buttons[i].Disabled = false; + } + LocalPlayer p = game.LocalPlayer; + bool globalHacks = p.CanAnyHacks && p.HacksEnabled; + buttons[3].Disabled = !globalHacks || !p.CanSpeed; + buttons[5].Disabled = !globalHacks || !p.CanPushbackBlocks; } ButtonWidget Make( int x, int y, string text, Action onClick, @@ -86,5 +98,10 @@ namespace ClassicalSharp { widget.SetValue = setter; return widget; } + + public override void Dispose() { + base.Dispose(); + game.Events.HackPermissionsChanged -= CheckHacksAllowed; + } } } \ No newline at end of file diff --git a/ClassicalSharp/2D/Screens/Menu/OptionsScreen.cs b/ClassicalSharp/2D/Screens/Menu/OptionsScreen.cs index 9035c8bc0..19600c50e 100644 --- a/ClassicalSharp/2D/Screens/Menu/OptionsScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/OptionsScreen.cs @@ -15,6 +15,11 @@ namespace ClassicalSharp { buttons = new ButtonWidget[] { // Column 1 + !network.IsSinglePlayer ? null : + Make( -140, -200, "Click distance", OnWidgetClick, + g => g.LocalPlayer.ReachDistance.ToString(), + (g, v) => g.LocalPlayer.ReachDistance = Single.Parse( v ) ), + Make( -140, -150, "Use sound", OnWidgetClick, g => g.UseSound ? "yes" : "no", (g, v) => { g.UseSound = v == "yes"; @@ -80,10 +85,11 @@ namespace ClassicalSharp { (g, w) => g.SetNewScreen( new PauseScreen( g ) ) ), null, }; - buttons[2].Metadata = typeof(NameMode); - buttons[3].Metadata = typeof(FpsLimitMethod); + buttons[3].Metadata = typeof(NameMode); + buttons[4].Metadata = typeof(FpsLimitMethod); validators = new MenuInputValidator[] { + network.IsSinglePlayer ? new RealValidator(1, 1024) : null, new BooleanValidator(), new BooleanValidator(), new EnumValidator(), diff --git a/ClassicalSharp/2D/Screens/Menu/PauseScreen.cs b/ClassicalSharp/2D/Screens/Menu/PauseScreen.cs index caff877da..127f6055c 100644 --- a/ClassicalSharp/2D/Screens/Menu/PauseScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/PauseScreen.cs @@ -61,7 +61,6 @@ namespace ClassicalSharp { buttons[i].Disabled = false; } if( !game.LocalPlayer.CanAnyHacks ) { - buttons[2].Disabled = true; // hack permissions buttons[3].Disabled = true; // env settings buttons[8].Disabled = true; // select texture pack } diff --git a/ClassicalSharp/Commands/DefaultCommands.cs b/ClassicalSharp/Commands/DefaultCommands.cs index 002be6f06..46e3041b5 100644 --- a/ClassicalSharp/Commands/DefaultCommands.cs +++ b/ClassicalSharp/Commands/DefaultCommands.cs @@ -91,14 +91,12 @@ namespace ClassicalSharp.Commands { game.Chat.Add( "Currently not targeting a block" ); } else { game.Chat.Add( "Currently targeting at: " + pos.BlockPos ); + game.Chat.Add( "ID of block targeted: " + game.Map.SafeGetBlock( pos.BlockPos ) ); } } else if( Utils.CaselessEquals( property, "dimensions" ) ) { game.Chat.Add( "map width: " + game.Map.Width ); game.Chat.Add( "map height: " + game.Map.Height ); game.Chat.Add( "map length: " + game.Map.Length ); - } else if( Utils.CaselessEquals( property, "jumpheight" ) ) { - float jumpHeight = game.LocalPlayer.JumpHeight; - game.Chat.Add( jumpHeight.ToString( "F2" ) + " blocks" ); } else { game.Chat.Add( "&e/client info: Unrecognised property: \"&f" + property + "&e\"." ); } diff --git a/ClassicalSharp/Entities/LocalPlayer.cs b/ClassicalSharp/Entities/LocalPlayer.cs index 38331df85..e03e37b9c 100644 --- a/ClassicalSharp/Entities/LocalPlayer.cs +++ b/ClassicalSharp/Entities/LocalPlayer.cs @@ -56,7 +56,7 @@ namespace ClassicalSharp { /// Whether the player should slide after letting go of movement buttons in noclip. public bool NoclipSlide = true; - float jumpVel = 0.42f; + internal float jumpVel = 0.42f, serverJumpVel = 0.42f; /// Returns the height that the client can currently jump up to.
/// Note that when speeding is enabled the client is able to jump much further.
public float JumpHeight { @@ -72,7 +72,7 @@ namespace ClassicalSharp { SpeedMultiplier = Options.GetFloat( OptionsKey.Speed, 0.1f, 50, 7 ); PushbackPlacing = Options.GetBool( OptionsKey.PushbackPlacing, false ); - NoclipSlide = Options.GetBool( OptionsKey.NoclipSlide, true ); + NoclipSlide = Options.GetBool( OptionsKey.NoclipSlide, false ); InitRenderingData(); } @@ -249,12 +249,8 @@ namespace ClassicalSharp { if( !CanUseThirdPersonCamera || !HacksEnabled ) game.CycleCamera(); - if( !HacksEnabled || !CanAnyHacks || !CanUseThirdPersonCamera ) { - game.FieldOfView = 70; - int max = Options.GetInt( OptionsKey.FieldOfView, 1, 179, 70 ); - game.ZoomFieldOfView = max; - game.UpdateProjection(); - } + if( !HacksEnabled || !CanAnyHacks || !CanSpeed ) + jumpVel = serverJumpVel; } /// Sets the user type of this user. This is used to control permissions for grass, diff --git a/ClassicalSharp/Game/Game.cs b/ClassicalSharp/Game/Game.cs index e14b84645..16cee6436 100644 --- a/ClassicalSharp/Game/Game.cs +++ b/ClassicalSharp/Game/Game.cs @@ -98,7 +98,7 @@ namespace ClassicalSharp { thirdPersonCam = new ThirdPersonCamera( this ); forwardThirdPersonCam = new ForwardThirdPersonCamera( this ); Camera = firstPersonCam; - FieldOfView = Options.GetInt( OptionsKey.FieldOfView, 1, 179, 70 ); + FieldOfView = Options.GetInt( OptionsKey.FieldOfView, 1, 150, 70 ); ZoomFieldOfView = FieldOfView; UpdateProjection(); CommandManager = new CommandManager(); diff --git a/ClassicalSharp/Game/InputHandler.cs b/ClassicalSharp/Game/InputHandler.cs index 446930ccd..15e76e08f 100644 --- a/ClassicalSharp/Game/InputHandler.cs +++ b/ClassicalSharp/Game/InputHandler.cs @@ -388,7 +388,7 @@ namespace ClassicalSharp { if( fovIndex == -1 ) fovIndex = game.ZoomFieldOfView; fovIndex -= e.DeltaPrecise * 5; - int max = Options.GetInt( OptionsKey.FieldOfView, 1, 179, 70 ); + int max = Options.GetInt( OptionsKey.FieldOfView, 1, 150, 70 ); Utils.Clamp( ref fovIndex, 1, max ); game.FieldOfView = (int)fovIndex; diff --git a/ClassicalSharp/Network/NetworkProcessor.CPE.cs b/ClassicalSharp/Network/NetworkProcessor.CPE.cs index 510b179a2..ce03a2dbc 100644 --- a/ClassicalSharp/Network/NetworkProcessor.CPE.cs +++ b/ClassicalSharp/Network/NetworkProcessor.CPE.cs @@ -377,6 +377,7 @@ namespace ClassicalSharp { float jumpHeight = reader.ReadInt16() / 32f; if( jumpHeight < 0 ) jumpHeight = 1.4f; p.CalculateJumpVelocity( jumpHeight ); + p.serverJumpVel = p.jumpVel; game.Events.RaiseHackPermissionsChanged(); } diff --git a/ClassicalSharp/Network/NetworkProcessor.cs b/ClassicalSharp/Network/NetworkProcessor.cs index 761b50787..8d53098d1 100644 --- a/ClassicalSharp/Network/NetworkProcessor.cs +++ b/ClassicalSharp/Network/NetworkProcessor.cs @@ -132,6 +132,7 @@ namespace ClassicalSharp { if( opcode == 0xFF && lastOpcode == PacketId.CpeHackControl ) { reader.Remove( 1 ); game.LocalPlayer.CalculateJumpVelocity( 1.4f ); // assume default jump height + game.LocalPlayer.serverJumpVel = game.LocalPlayer.jumpVel; continue; }