From 86a7b49c08683a1825ab4ee5ef506e70ba8d5b45 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Fri, 11 Dec 2015 13:00:22 +1100 Subject: [PATCH] Add option to disable all hacks, move hacks settings to their own screen. --- .../2D/Screens/Menu/HacksSettingsScreen.cs | 70 +++++++++++++++++++ .../2D/Screens/Menu/OptionsScreen.cs | 38 +++------- ClassicalSharp/2D/Screens/Menu/PauseScreen.cs | 14 ++-- ClassicalSharp/ClassicalSharp.csproj | 1 + ClassicalSharp/Entities/LocalPlayer.cs | 22 +++--- ClassicalSharp/Utils/Options.cs | 1 + 6 files changed, 100 insertions(+), 46 deletions(-) create mode 100644 ClassicalSharp/2D/Screens/Menu/HacksSettingsScreen.cs diff --git a/ClassicalSharp/2D/Screens/Menu/HacksSettingsScreen.cs b/ClassicalSharp/2D/Screens/Menu/HacksSettingsScreen.cs new file mode 100644 index 000000000..893403a22 --- /dev/null +++ b/ClassicalSharp/2D/Screens/Menu/HacksSettingsScreen.cs @@ -0,0 +1,70 @@ +using System; +using System.Drawing; +using ClassicalSharp.Singleplayer; + +namespace ClassicalSharp { + + public class HacksSettingsScreen : MenuInputScreen { + + public HacksSettingsScreen( Game game ) : base( game ) { + } + + public override void Init() { + base.Init(); + INetworkProcessor network = game.Network; + + buttons = new ButtonWidget[] { + // Column 1 + Make( -140, -100, "Hacks enabled", Anchor.Centre, OnWidgetClick, + g => g.LocalPlayer.HacksEnabled ? "yes" : "no", + (g, v) => { g.LocalPlayer.HacksEnabled = v == "yes"; + Options.Set( OptionsKey.HacksEnabled, v == "yes" ); + g.LocalPlayer.CheckHacksConsistency(); + } ), + + Make( -140, -50, "Speed multiplier", Anchor.Centre, OnWidgetClick, + g => g.LocalPlayer.SpeedMultiplier.ToString(), + (g, v) => { g.LocalPlayer.SpeedMultiplier = Single.Parse( v ); + Options.Set( OptionsKey.Speed, v ); } ), + + // Column 2 + Make( 140, -100, "Liquids breakable", Anchor.Centre, OnWidgetClick, + g => g.LiquidsBreakable ? "yes" : "no", + (g, v) => { g.LiquidsBreakable = v == "yes"; + Options.Set( OptionsKey.LiquidsBreakable, v == "yes" ); } ), + + Make( 140, -50, "Pushback placing", Anchor.Centre, 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" ); + } + }), + + MakeBack( false, titleFont, + (g, w) => g.SetNewScreen( new PauseScreen( g ) ) ), + null, + }; + + validators = new MenuInputValidator[] { + new BooleanValidator(), + new RealValidator( 0.1f, 50 ), + + new BooleanValidator(), + new BooleanValidator(), + }; + okayIndex = buttons.Length - 1; + } + + ButtonWidget Make( int x, int y, string text, Anchor vDocking, Action onClick, + Func getter, Action setter ) { + ButtonWidget widget = ButtonWidget.Create( game, x, y, 240, 35, text, + Anchor.Centre, vDocking, titleFont, onClick ); + widget.GetValue = getter; + widget.SetValue = setter; + return widget; + } + } +} \ No newline at end of file diff --git a/ClassicalSharp/2D/Screens/Menu/OptionsScreen.cs b/ClassicalSharp/2D/Screens/Menu/OptionsScreen.cs index 0e42a5e48..4039dccc9 100644 --- a/ClassicalSharp/2D/Screens/Menu/OptionsScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/OptionsScreen.cs @@ -15,27 +15,18 @@ namespace ClassicalSharp { buttons = new ButtonWidget[] { // Column 1 - Make( -140, -200, "Liquids breakable", Anchor.Centre, OnWidgetClick, - g => g.LiquidsBreakable ? "yes" : "no", - (g, v) => { g.LiquidsBreakable = v == "yes"; - Options.Set( OptionsKey.LiquidsBreakable, v == "yes" ); } ), - Make( -140, -150, "Use sound (WIP)", Anchor.Centre, OnWidgetClick, + Make( -140, -100, "Use sound (WIP)", Anchor.Centre, OnWidgetClick, g => g.UseSound ? "yes" : "no", (g, v) => { g.UseSound = v == "yes"; g.AudioPlayer.SetSound( g.UseSound ); Options.Set( OptionsKey.UseSound, v == "yes" ); }), - Make( -140, -100, "Show hover names", Anchor.Centre, OnWidgetClick, + Make( -140, -50, "Show hover names", Anchor.Centre, OnWidgetClick, g => g.Players.ShowHoveredNames ? "yes" : "no", (g, v) => { g.Players.ShowHoveredNames = v == "yes"; Options.Set( OptionsKey.ShowHoveredNames, v == "yes" ); }), - Make( -140, -50, "Speed multiplier", Anchor.Centre, OnWidgetClick, - g => g.LocalPlayer.SpeedMultiplier.ToString(), - (g, v) => { g.LocalPlayer.SpeedMultiplier = Single.Parse( v ); - Options.Set( OptionsKey.Speed, v ); } ), - Make( -140, 0, "FPS limit", Anchor.Centre, OnWidgetClick, g => g.FpsLimit.ToString(), (g, v) => { object raw = Enum.Parse( typeof(FpsLimitMethod), v ); @@ -48,38 +39,28 @@ namespace ClassicalSharp { // Column 2 !network.IsSinglePlayer ? null : - Make( 140, -200, "Block physics", Anchor.Centre, OnWidgetClick, + Make( 140, -150, "Block physics", Anchor.Centre, OnWidgetClick, g => ((SinglePlayerServer)network).physics.Enabled ? "yes" : "no", (g, v) => { ((SinglePlayerServer)network).physics.Enabled = v == "yes"; Options.Set( OptionsKey.SingleplayerPhysics, v == "yes" ); }), - Make( 140, -150, "Use music", Anchor.Centre, OnWidgetClick, + Make( 140, -100, "Use music", Anchor.Centre, OnWidgetClick, g => g.UseMusic ? "yes" : "no", (g, v) => { g.UseMusic = v == "yes"; g.AudioPlayer.SetMusic( g.UseMusic ); Options.Set( OptionsKey.UseMusic, v == "yes" ); }), - Make( 140, -100, "View bobbing", Anchor.Centre, OnWidgetClick, + Make( 140, -50, "View bobbing", Anchor.Centre, OnWidgetClick, g => g.ViewBobbing ? "yes" : "no", (g, v) => { g.ViewBobbing = v == "yes"; Options.Set( OptionsKey.ViewBobbing, v == "yes" ); }), - Make( 140, -50, "Auto close launcher", Anchor.Centre, OnWidgetClick, + Make( 140, 0, "Auto close launcher", Anchor.Centre, OnWidgetClick, g => Options.GetBool( OptionsKey.AutoCloseLauncher, false ) ? "yes" : "no", (g, v) => Options.Set( OptionsKey.AutoCloseLauncher, v == "yes" ) ), - Make( 140, 0, "Pushback placing", Anchor.Centre, 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" ); - } - }), - Make( 140, 50, "Mouse sensitivity", Anchor.Centre, OnWidgetClick, g => g.MouseSensitivity.ToString(), (g, v) => { g.MouseSensitivity = Int32.Parse( v ); @@ -89,13 +70,11 @@ namespace ClassicalSharp { (g, w) => g.SetNewScreen( new PauseScreen( g ) ) ), null, }; - buttons[4].Metadata = typeof(FpsLimitMethod); + buttons[2].Metadata = typeof(FpsLimitMethod); validators = new MenuInputValidator[] { new BooleanValidator(), - new BooleanValidator(), - new BooleanValidator(), - new RealValidator( 0.1f, 50 ), + new BooleanValidator(), new EnumValidator(), new IntegerValidator( 16, 4096 ), @@ -103,7 +82,6 @@ namespace ClassicalSharp { new BooleanValidator(), new BooleanValidator(), new BooleanValidator(), - new BooleanValidator(), new IntegerValidator( 1, 100 ), }; okayIndex = buttons.Length - 1; diff --git a/ClassicalSharp/2D/Screens/Menu/PauseScreen.cs b/ClassicalSharp/2D/Screens/Menu/PauseScreen.cs index 55a2b21e3..ccba96729 100644 --- a/ClassicalSharp/2D/Screens/Menu/PauseScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/PauseScreen.cs @@ -24,12 +24,12 @@ namespace ClassicalSharp { (g, w) => g.SetNewScreen( new OptionsScreen( g ) ) ), Make( -140, -100, "Gui options", Anchor.Centre, (g, w) => g.SetNewScreen( new GuiOptionsScreen( g ) ) ), - Make( -140, -50, "Env settings", Anchor.Centre, + Make( -140, -50, "Hacks settings", Anchor.Centre, + (g, w) => g.SetNewScreen( new HacksSettingsScreen( g ) ) ), + Make( -140, 0, "Env settings", Anchor.Centre, (g, w) => g.SetNewScreen( new EnvSettingsScreen( g ) ) ), - Make( -140, 0, "Key bindings", Anchor.Centre, - (g, w) => g.SetNewScreen( new NormalKeyBindingsScreen( g ) ) ), - Make( -140, 50, "Hotkeys", Anchor.Centre, - (g, w) => g.SetNewScreen( new HotkeyScreen( g ) ) ), + Make( -140, 50, "Key bindings", Anchor.Centre, + (g, w) => g.SetNewScreen( new NormalKeyBindingsScreen( g ) ) ), // Column 2 Make( 140, -150, "Save level", Anchor.Centre, @@ -40,8 +40,10 @@ namespace ClassicalSharp { !game.Network.IsSinglePlayer ? null : Make( 140, -50, "Generate level", Anchor.Centre, (g, w) => g.SetNewScreen( new GenLevelScreen( g ) ) ), - Make( 140, 50, "Select texture pack", Anchor.Centre, + Make( 140, 0, "Select texture pack", Anchor.Centre, (g, w) => g.SetNewScreen( new TexturePackScreen( g ) ) ), + Make( 140, 50, "Hotkeys", Anchor.Centre, + (g, w) => g.SetNewScreen( new HotkeyScreen( g ) ) ), // Other MakeOther( 10, 5, 120, "Quit game", Anchor.BottomOrRight, diff --git a/ClassicalSharp/ClassicalSharp.csproj b/ClassicalSharp/ClassicalSharp.csproj index d97d71115..c148467f6 100644 --- a/ClassicalSharp/ClassicalSharp.csproj +++ b/ClassicalSharp/ClassicalSharp.csproj @@ -100,6 +100,7 @@ + diff --git a/ClassicalSharp/Entities/LocalPlayer.cs b/ClassicalSharp/Entities/LocalPlayer.cs index 34e31a13e..5ade71caa 100644 --- a/ClassicalSharp/Entities/LocalPlayer.cs +++ b/ClassicalSharp/Entities/LocalPlayer.cs @@ -16,6 +16,8 @@ namespace ClassicalSharp { public byte UserType; public bool PushbackPlacing; + public bool HacksEnabled = true; + /// Whether the player is allowed to use the types of cameras that use third person. public bool CanUseThirdPersonCamera = true; @@ -125,7 +127,7 @@ namespace ClassicalSharp { if( game.IsKeyDown( KeyBinding.Right ) ) zMoving += 0.98f; jumping = game.IsKeyDown( KeyBinding.Jump ); - speeding = CanSpeed && game.IsKeyDown( KeyBinding.Speed ); + speeding = CanSpeed && HacksEnabled && game.IsKeyDown( KeyBinding.Speed ); flyingUp = game.IsKeyDown( KeyBinding.FlyUp ); flyingDown = game.IsKeyDown( KeyBinding.FlyDown ); } @@ -264,12 +266,12 @@ namespace ClassicalSharp { /// Disables any hacks if their respective CanHackX value is set to false. public void CheckHacksConsistency() { - if( !CanFly ) { flying = false; flyingDown = false; flyingUp = false; } - if( !CanNoclip ) noClip = false; - if( !CanSpeed) speeding = false; - if( !CanPushbackBlocks ) PushbackPlacing = false; + if( !CanFly || !HacksEnabled ) { flying = false; flyingDown = false; flyingUp = false; } + if( !CanNoclip || !HacksEnabled ) noClip = false; + if( !CanSpeed || !HacksEnabled ) speeding = false; + if( !CanPushbackBlocks || !HacksEnabled ) PushbackPlacing = false; - if( !CanUseThirdPersonCamera ) + if( !CanUseThirdPersonCamera || !HacksEnabled ) game.SetCamera( false ); } @@ -299,7 +301,7 @@ namespace ClassicalSharp { internal bool HandleKeyDown( Key key ) { KeyMap keys = game.InputHandler.Keys; - if( key == keys[KeyBinding.Respawn] && CanRespawn ) { + if( key == keys[KeyBinding.Respawn] && CanRespawn && HacksEnabled ) { Vector3I p = Vector3I.Floor( SpawnPoint ); if( game.Map.IsValidPos( p ) ) { // Spawn player at highest valid position. @@ -316,11 +318,11 @@ namespace ClassicalSharp { Vector3 spawn = (Vector3)p + new Vector3( 0.5f, 0.01f, 0.5f ); LocationUpdate update = LocationUpdate.MakePos( spawn, false ); SetLocation( update, false ); - } else if( key == keys[KeyBinding.SetSpawn] && CanRespawn ) { + } else if( key == keys[KeyBinding.SetSpawn] && CanRespawn && HacksEnabled ) { SpawnPoint = Position; - } else if( key == keys[KeyBinding.Fly] && CanFly ) { + } else if( key == keys[KeyBinding.Fly] && CanFly && HacksEnabled ) { flying = !flying; - } else if( key == keys[KeyBinding.NoClip] && CanNoclip ) { + } else if( key == keys[KeyBinding.NoClip] && CanNoclip && HacksEnabled ) { noClip = !noClip; } else { return false; diff --git a/ClassicalSharp/Utils/Options.cs b/ClassicalSharp/Utils/Options.cs index f6cab37ea..30e657e1f 100644 --- a/ClassicalSharp/Utils/Options.cs +++ b/ClassicalSharp/Utils/Options.cs @@ -21,6 +21,7 @@ namespace ClassicalSharp { public const string ShowBlockInHand = "blockinhand"; public const string UseMusic = "usemusic"; public const string UseSound = "usesound"; + public const string HacksEnabled = "hacksenabled"; public const string MouseLeft = "mouseleft"; public const string MouseMiddle = "mousemiddle";