From a0ee79dbcd26a8f07d493a7e993cbaf0d02e44db Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 17 Jul 2017 14:34:59 -0400 Subject: [PATCH] Hacking, barebones fskimmer, double clicking --- ShiftOS.Frontend/Apps/FileSkimmer.cs | 151 ++++++++++++++++++ ShiftOS.Frontend/Apps/Terminal.cs | 12 +- ShiftOS.Frontend/Desktop/WindowManager.cs | 2 +- ShiftOS.Frontend/GUI/Control.cs | 7 +- ShiftOS.Frontend/GUI/ListBox.cs | 27 +++- .../GraphicsSubsystem/UIManager.cs | 5 +- ShiftOS.Frontend/HackableProvider.cs | 29 ++++ ShiftOS.Frontend/HackerTestCommands.cs | 59 +++++++ .../Properties/Resources.Designer.cs | 60 ++++--- ShiftOS.Frontend/Properties/Resources.resx | 6 + ShiftOS.Frontend/Resources/Hackables.txt | 21 +++ ShiftOS.Frontend/Resources/LootInfo.txt | 3 + ShiftOS.Frontend/ShiftOS.Frontend.csproj | 9 ++ ShiftOS.Frontend/ShiftOS.cs | 93 ++++++++++- ShiftOS.Objects/Hackable.cs | 21 ++- ShiftOS_TheReturn/FileSkimmerBackend.cs | 12 +- ShiftOS_TheReturn/Hacking.cs | 98 +++++++++++- ShiftOS_TheReturn/Paths.cs | 9 +- 18 files changed, 577 insertions(+), 47 deletions(-) create mode 100644 ShiftOS.Frontend/Apps/FileSkimmer.cs create mode 100644 ShiftOS.Frontend/HackableProvider.cs create mode 100644 ShiftOS.Frontend/HackerTestCommands.cs create mode 100644 ShiftOS.Frontend/Resources/Hackables.txt create mode 100644 ShiftOS.Frontend/Resources/LootInfo.txt diff --git a/ShiftOS.Frontend/Apps/FileSkimmer.cs b/ShiftOS.Frontend/Apps/FileSkimmer.cs new file mode 100644 index 0000000..29c5802 --- /dev/null +++ b/ShiftOS.Frontend/Apps/FileSkimmer.cs @@ -0,0 +1,151 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ShiftOS.Engine; +using static ShiftOS.Objects.ShiftFS.Utils; + +namespace ShiftOS.Frontend.Apps +{ + [WinOpen("fileskimmer")] + [Launcher("File Skimmer", false, null, "System")] + [DefaultTitle("File Skimmer")] + public class FileSkimmer : GUI.Control, IShiftOSWindow + { + private string _currentdirectory = "0:"; + private const string SD_SYSTEM = "__system"; + private GUI.ListBox _fList = null; + private GUI.TextControl _currentdirtext = null; + + public void OnLoad() + { + Width = 720; + Height = 480; + _fList = new GUI.ListBox(); + _fList.KeyEvent += (e) => + { + if(e.Key == Microsoft.Xna.Framework.Input.Keys.Enter) + { + Navigate(_fList.SelectedItem.ToString()); + } + }; + _fList.DoubleClick += () => + { + try + { + Navigate(_fList.SelectedItem.ToString()); + } + catch { } + }; + AddControl(_fList); + _currentdirtext = new GUI.TextControl(); + _currentdirtext.AutoSize = true; + AddControl(_currentdirtext); + ResetList(); + } + + public void Navigate(string relativepath) + { + if (relativepath == "Up one...") + { + if (_currentdirectory.Contains('/')) + { + int _index = _currentdirectory.LastIndexOf('/'); + int _len = _currentdirectory.Length - _index; + _currentdirectory = _currentdirectory.Remove(_index, _len); + ResetList(); + } + else + { + _currentdirectory = SD_SYSTEM; + ResetList(); + } + return; + } + + string path = ""; + if (_currentdirectory == SD_SYSTEM) + path = relativepath; + else + path = _currentdirectory + "/" + relativepath; + if (DirectoryExists(path)) + { + _currentdirectory = path; + ResetList(); + } + else if (FileExists(path)) + { + if (!FileSkimmerBackend.OpenFile(path)) + { + Engine.Infobox.Show("File Skimmer can't open this file!", "A program that can open files of this type was not found on your computer."); + } + } + } + + public void OnSkinLoad() + { + _currentdirtext.Font = SkinEngine.LoadedSkin.Header3Font; + } + + public bool OnUnload() + { + return true; + } + + public void OnUpgrade() + { + } + + public void ResetList() + { + if (_currentdirectory == SD_SYSTEM) + _currentdirtext.Text = "My storage drives"; + else + _currentdirtext.Text = _currentdirectory; + + _fList.ClearItems(); + if (_currentdirectory != SD_SYSTEM) + _fList.AddItem("Up one..."); + + if(_currentdirectory == SD_SYSTEM) + { + foreach(var mount in Mounts) + { + _fList.AddItem(Mounts.IndexOf(mount) + ":"); + } + } + else + { + foreach(var dir in GetDirectories(_currentdirectory)) + { + var dinf = GetDirectoryInfo(dir); + _fList.AddItem(dinf.Name); + } + foreach (var dir in GetFiles(_currentdirectory)) + { + var dinf = GetFileInfo(dir); + _fList.AddItem(dinf.Name); + } + + } + InvalidateTopLevel(); + } + + + protected override void OnLayout() + { + try + { + _currentdirtext.Layout(); + _fList.X = 0; + _fList.Y = 0; + _fList.Width = Width; + _fList.Height = Height - _currentdirtext.Height; + _currentdirtext.X = (Width - _currentdirtext.Width) / 2; + _currentdirtext.Y = _fList.Height; + } + catch { } + } + } +} diff --git a/ShiftOS.Frontend/Apps/Terminal.cs b/ShiftOS.Frontend/Apps/Terminal.cs index ea75f3a..6d03a0e 100644 --- a/ShiftOS.Frontend/Apps/Terminal.cs +++ b/ShiftOS.Frontend/Apps/Terminal.cs @@ -262,6 +262,16 @@ namespace ShiftOS.Frontend.Apps Debug.WriteLine("Drunky alert in terminal."); } } + else if(a.Key == Keys.Right) + { + if(Index < Text.Length) + { + Index++; + AppearanceManager.CurrentPosition++; + RecalculateLayout(); + InvalidateTopLevel(); + } + } else if (a.Key == Keys.Left) { if (SaveSystem.CurrentSave != null) @@ -274,7 +284,7 @@ namespace ShiftOS.Frontend.Apps var remstrlen = Text.Length - stringlen; var finalnum = selstart - remstrlen; - if (finalnum != headerlen) + if (finalnum > headerlen) { AppearanceManager.CurrentPosition--; base.OnKeyEvent(a); diff --git a/ShiftOS.Frontend/Desktop/WindowManager.cs b/ShiftOS.Frontend/Desktop/WindowManager.cs index 18f6728..cdbae90 100644 --- a/ShiftOS.Frontend/Desktop/WindowManager.cs +++ b/ShiftOS.Frontend/Desktop/WindowManager.cs @@ -127,10 +127,10 @@ namespace ShiftOS.Frontend.Desktop UIManager.AddTopLevel(wb); AppearanceManager.OpenForms.Add(wb); RunningBorders.Add(wb); + TileWindows(); win.OnLoad(); win.OnUpgrade(); win.OnSkinLoad(); - TileWindows(); } public void TileWindows() diff --git a/ShiftOS.Frontend/GUI/Control.cs b/ShiftOS.Frontend/GUI/Control.cs index f253903..d34a97a 100644 --- a/ShiftOS.Frontend/GUI/Control.cs +++ b/ShiftOS.Frontend/GUI/Control.cs @@ -509,7 +509,7 @@ namespace ShiftOS.Frontend.GUI } } - public virtual bool ProcessMouseState(MouseState state) + public virtual bool ProcessMouseState(MouseState state, double lastLeftClickMS) { //If we aren't rendering the control, we aren't accepting input. if (_visible == false) @@ -548,7 +548,7 @@ namespace ShiftOS.Frontend.GUI var nstate = new MouseState(coords.X, coords.Y, state.ScrollWheelValue, state.LeftButton, state.MiddleButton, state.RightButton, state.XButton1, state.XButton2); //pass that state to the process method, and set the _requiresMoreWork value to the opposite of the return value - _requiresMoreWork = !control.ProcessMouseState(nstate); + _requiresMoreWork = !control.ProcessMouseState(nstate, lastLeftClickMS); //If it's false, break the loop. if (_requiresMoreWork == false) break; @@ -575,6 +575,8 @@ namespace ShiftOS.Frontend.GUI } if (_leftState == false && ld == true) { + if (lastLeftClickMS <= 500 & lastLeftClickMS > 0) + DoubleClick?.Invoke(); var focused = UIManager.FocusedControl; UIManager.FocusedControl = this; focused?.InvalidateTopLevel(); @@ -642,6 +644,7 @@ namespace ShiftOS.Frontend.GUI KeyEvent?.Invoke(e); } + public event Action DoubleClick; public event Action MouseMove; public event Action MouseEnter; public event Action MouseLeave; diff --git a/ShiftOS.Frontend/GUI/ListBox.cs b/ShiftOS.Frontend/GUI/ListBox.cs index 29d3712..2fe5fc4 100644 --- a/ShiftOS.Frontend/GUI/ListBox.cs +++ b/ShiftOS.Frontend/GUI/ListBox.cs @@ -17,6 +17,27 @@ namespace ShiftOS.Frontend.GUI private int itemOffset = 0; private int itemsPerPage = 1; + public ListBox() + { + Click += () => + { + //loop through the list of items on the screen + for(int i = itemOffset; i < itemOffset + itemsPerPage && i < items.Count; i++) + { + int screeni = i - itemOffset; + int loc = 1+screeni * fontheight; + int height = 1+(screeni + 1) * fontheight; + if(MouseY >= loc && MouseY <= height) + { + SelectedIndex = i; + RecalculateItemsPerPage(); + return; + } + } + }; + } + + public int SelectedIndex { get @@ -73,7 +94,7 @@ namespace ShiftOS.Frontend.GUI public void RecalculateItemsPerPage() { itemsPerPage = 0; - while(itemsPerPage * fontheight < Height && itemsPerPage < items.Count - 1) + while(itemsPerPage * fontheight < Height && itemsPerPage < items.Count) { itemsPerPage++; } @@ -102,7 +123,7 @@ namespace ShiftOS.Frontend.GUI { if(e.Key== Microsoft.Xna.Framework.Input.Keys.Down) { - if(selectedIndex < items.Count - 2) + if(selectedIndex < items.Count - 1) { selectedIndex++; RecalculateItemsPerPage(); @@ -126,7 +147,7 @@ namespace ShiftOS.Frontend.GUI { gfx.Clear(LoadedSkin.ControlTextColor.ToMonoColor()); gfx.DrawRectangle(1, 1, Width - 2, Height - 2, UIManager.SkinTextures["ControlColor"]); - for(int i = itemOffset; i < items.Count - 1 && i < itemsPerPage; i++) + for(int i = itemOffset; i < items.Count && i < itemsPerPage; i++) { int x = 1; int y = fontheight * (i - itemOffset); diff --git a/ShiftOS.Frontend/GraphicsSubsystem/UIManager.cs b/ShiftOS.Frontend/GraphicsSubsystem/UIManager.cs index 165944e..a88f28e 100644 --- a/ShiftOS.Frontend/GraphicsSubsystem/UIManager.cs +++ b/ShiftOS.Frontend/GraphicsSubsystem/UIManager.cs @@ -146,11 +146,12 @@ namespace ShiftOS.Frontend.GraphicsSubsystem } } - public static void ProcessMouseState(MouseState state) + public static void ProcessMouseState(MouseState state, double lastLeftClickMS) { foreach(var ctrl in topLevels.ToArray()) { - ctrl.ProcessMouseState(state); + ctrl.ProcessMouseState(state, lastLeftClickMS); + } } diff --git a/ShiftOS.Frontend/HackableProvider.cs b/ShiftOS.Frontend/HackableProvider.cs new file mode 100644 index 0000000..1c57f37 --- /dev/null +++ b/ShiftOS.Frontend/HackableProvider.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ShiftOS.Objects; +using ShiftOS.Engine; +using Newtonsoft.Json; + +namespace ShiftOS.Frontend +{ + public class HackableProvider : IHackableProvider + { + public Hackable[] GetHackables() + { + return JsonConvert.DeserializeObject(Properties.Resources.Hackables); + } + + public byte[] GetLootFromResource(string resId) + { + return new byte[] { 0xDE, 0xAD, 0xBE, 0xEF }; //nyi + } + + public LootInfo[] GetLootInfo() + { + return JsonConvert.DeserializeObject(Properties.Resources.LootInfo); + } + } +} diff --git a/ShiftOS.Frontend/HackerTestCommands.cs b/ShiftOS.Frontend/HackerTestCommands.cs new file mode 100644 index 0000000..675356a --- /dev/null +++ b/ShiftOS.Frontend/HackerTestCommands.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ShiftOS.Engine; + +#if DEBUG +namespace ShiftOS.Frontend +{ + public static class HackerTestCommands + { + [Command("lshackables")] + public static void ListAllHackables() + { + foreach(var hackable in Hacking.AvailableToHack) + { + Console.WriteLine(hackable.ID + ": " + hackable.FriendlyName); + } + } + + [Command("describebackable")] + [RequiresArgument("id")] + public static void DescribeHackable(Dictionary args) + { + string id = args["id"].ToString(); + var hackable = Hacking.AvailableToHack.FirstOrDefault(x => x.ID == id); + if(hackable == null) + { + Console.WriteLine("Hackable not found."); + return; + } + Console.WriteLine(hackable.FriendlyName); + Console.WriteLine("------------------------"); + Console.WriteLine(); + Console.WriteLine("System name: " + hackable.SystemName); + Console.WriteLine("Loot rarity: " + hackable.LootRarity); + Console.WriteLine("Loot amount: " + hackable.LootAmount); + Console.WriteLine("Connection timeout level: " + hackable.ConnectionTimeoutLevel); + Console.WriteLine(); + Console.WriteLine(hackable.WelcomeMessage); + } + + [Command("inithack")] + [RequiresArgument("id")] + public static void InitHack(Dictionary args) + { + string id = args["id"].ToString(); + var hackable = Hacking.AvailableToHack.FirstOrDefault(x => x.ID == id); + if (hackable == null) + { + Console.WriteLine("Hackable not found."); + return; + } + Hacking.InitHack(hackable); + } + } +} +#endif \ No newline at end of file diff --git a/ShiftOS.Frontend/Properties/Resources.Designer.cs b/ShiftOS.Frontend/Properties/Resources.Designer.cs index aaca596..3d40c29 100644 --- a/ShiftOS.Frontend/Properties/Resources.Designer.cs +++ b/ShiftOS.Frontend/Properties/Resources.Designer.cs @@ -70,6 +70,35 @@ namespace ShiftOS.Frontend.Properties { } } + /// + /// Looks up a localized string similar to /* ShiftOS hackables data file + /// * + /// * This file contains information about all hackable systems in the game's campaign. + /// * + /// */ + /// + ///[ + /// { + /// SystemName: "shiftsyndicate_main", + /// FriendlyName: "ShiftSyndicate file server", + /// Password: "h0ldy0urc0l0ur", + /// PasswordHint: "Prepare to hold your colour...", + /// WelcomeMessage: "Don't make fun of SpamSyndicate web design.", + /// FirewallStrength: 1, + /// LootRarity: 1, + /// LootAmount: 4, + /// ConnectionTimeoutLevel: 4, + /// SystemType: "FileServer, SSHServer", + /// + /// } + ///]. + /// + internal static string Hackables { + get { + return ResourceManager.GetString("Hackables", resourceCulture); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// @@ -81,25 +110,18 @@ namespace ShiftOS.Frontend.Properties { } /// - /// Looks up a localized string similar to [ - /////Virus Scanner Grades - /// { - /// Name: "Virus Scanner Grade 2", - /// Description: "Update the Virus Scanner database to include threatlevel 2 viruses.", - /// Dependencies: "virus_scanner", - /// Category: "Virus Scanner", - /// Cost: 75 - /// }, - /// { - /// Name: "Virus Scanner Grade 3", - /// Description: "Update the Virus Scanner database to include threatlevel 3 viruses.", - /// Dependencies: "virus_scanner_grade_2", - /// Category: "Virus Scanner", - /// Cost: 150 - /// }, - /// { - /// Name: "Virus Scanner Grade 4", - /// Description: "Update the [rest of string was truncated]";. + /// Looks up a localized string similar to //Loot information table + /// + ///[]. + /// + internal static string LootInfo { + get { + return ResourceManager.GetString("LootInfo", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to []. /// internal static string Shiftorium { get { diff --git a/ShiftOS.Frontend/Properties/Resources.resx b/ShiftOS.Frontend/Properties/Resources.resx index 1a04f46..c0a2cff 100644 --- a/ShiftOS.Frontend/Properties/Resources.resx +++ b/ShiftOS.Frontend/Properties/Resources.resx @@ -136,4 +136,10 @@ ..\Resources\strings_fr.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 + + ..\Resources\Hackables.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 + + + ..\Resources\LootInfo.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 + \ No newline at end of file diff --git a/ShiftOS.Frontend/Resources/Hackables.txt b/ShiftOS.Frontend/Resources/Hackables.txt new file mode 100644 index 0000000..1c82394 --- /dev/null +++ b/ShiftOS.Frontend/Resources/Hackables.txt @@ -0,0 +1,21 @@ +/* ShiftOS hackables data file + * + * This file contains information about all hackable systems in the game's campaign. + * + */ + +[ + { + SystemName: "shiftsyndicate_main", + FriendlyName: "ShiftSyndicate file server", + Password: "h0ldy0urc0l0ur", + PasswordHint: "Prepare to hold your colour...", + WelcomeMessage: "Don't make fun of SpamSyndicate web design.", + FirewallStrength: 1, + LootRarity: 1, + LootAmount: 4, + ConnectionTimeoutLevel: 4, + SystemType: "FileServer, SSHServer", + + } +] \ No newline at end of file diff --git a/ShiftOS.Frontend/Resources/LootInfo.txt b/ShiftOS.Frontend/Resources/LootInfo.txt new file mode 100644 index 0000000..361bab9 --- /dev/null +++ b/ShiftOS.Frontend/Resources/LootInfo.txt @@ -0,0 +1,3 @@ +//Loot information table + +[] \ No newline at end of file diff --git a/ShiftOS.Frontend/ShiftOS.Frontend.csproj b/ShiftOS.Frontend/ShiftOS.Frontend.csproj index cdba714..c401a3c 100644 --- a/ShiftOS.Frontend/ShiftOS.Frontend.csproj +++ b/ShiftOS.Frontend/ShiftOS.Frontend.csproj @@ -43,6 +43,7 @@ + @@ -59,6 +60,8 @@ + + @@ -174,6 +177,12 @@ + + + + + +