From bbc5a738b1b3d86d2a71c1188fad89b533f251ce Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 5 May 2017 11:52:43 -0400 Subject: shiftfs permissions --- ShiftOS.Objects/ShiftFS.cs | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) (limited to 'ShiftOS.Objects') diff --git a/ShiftOS.Objects/ShiftFS.cs b/ShiftOS.Objects/ShiftFS.cs index c2121f0..45cdb14 100644 --- a/ShiftOS.Objects/ShiftFS.cs +++ b/ShiftOS.Objects/ShiftFS.cs @@ -32,23 +32,16 @@ using System.Threading; namespace ShiftOS.Objects.ShiftFS { - public enum Permissions - { - User, - Administrator, - Superuser, - All - } public class File { public string Name; public byte[] Data; public byte[] HeaderData; public bool ReadAccessToLowUsers; - public Permissions permissions; + public UserPermissions permissions; public System.IO.Stream GetStream() { - if ((int)CurrentUser >= (int)permissions || permissions == Permissions.All) + if ((int)CurrentUser <= (int)permissions) { return new System.IO.MemoryStream(Data); } @@ -59,7 +52,7 @@ namespace ShiftOS.Objects.ShiftFS return null; } - public File(string name, byte[] data, bool ReadAccess_to_low_users, Permissions perm) + public File(string name, byte[] data, bool ReadAccess_to_low_users, UserPermissions perm) { Name = name; Data = data; @@ -73,31 +66,31 @@ namespace ShiftOS.Objects.ShiftFS public List Files = new List(); public List Subdirectories = new List(); public bool ReadAccessToLowUsers; - public Permissions permissions; + public UserPermissions permissions; public void AddFile(File file) { - if ((int)CurrentUser >= (int)permissions || permissions == Permissions.All) + if ((int)CurrentUser <= (int)permissions) { Files.Add(file); } } public void RemoveFile(string name) { - if ((int)CurrentUser >= (int)permissions || permissions == Permissions.All) + if ((int)CurrentUser <= (int)permissions) { Files.Remove(Files.Find(x => x.Name == name)); } } public void RemoveFile(File file) { - if ((int)CurrentUser >= (int)permissions || permissions == Permissions.All) + if ((int)CurrentUser <= (int)permissions) { Files.Remove(file); } } public File FindFileByName(string name) { - if ((int)CurrentUser >= (int)permissions || permissions == Permissions.All) + if ((int)CurrentUser <= (int)permissions) { return Files.Find(x => x.Name == name); } @@ -105,28 +98,28 @@ namespace ShiftOS.Objects.ShiftFS } public void AddDirectory(Directory dir) { - if ((int)CurrentUser >= (int)permissions || permissions == Permissions.All) + if ((int)CurrentUser <= (int)permissions) { Subdirectories.Add(dir); } } public void RemoveDirectory(string name) { - if ((int)CurrentUser >= (int)permissions || permissions == Permissions.All) + if ((int)CurrentUser <= (int)permissions) { Subdirectories.Remove(Subdirectories.Find(x => x.Name == name)); } } public void RemoveDirectory(Directory dir) { - if ((int)CurrentUser >= (int)permissions || permissions == Permissions.All) + if ((int)CurrentUser <= (int)permissions) { Subdirectories.Remove(dir); } } public Directory FindDirectoryByName(string name) { - if ((int)CurrentUser >= (int)permissions || permissions == Permissions.All) + if ((int)CurrentUser <= (int)permissions) { return Subdirectories.Find(x => x.Name == name); } @@ -136,7 +129,7 @@ namespace ShiftOS.Objects.ShiftFS public static class Utils { - public static Permissions CurrentUser { get; set; } + public static UserPermissions CurrentUser { get; set; } public static List Mounts { get; set; } @@ -232,7 +225,7 @@ namespace ShiftOS.Objects.ShiftFS { try { - dir.AddFile(new File(pathlist[pathlist.Length - 1], Encoding.UTF8.GetBytes(contents), false, Permissions.All)); + dir.AddFile(new File(pathlist[pathlist.Length - 1], Encoding.UTF8.GetBytes(contents), false, CurrentUser)); } catch { } } @@ -281,7 +274,7 @@ namespace ShiftOS.Objects.ShiftFS if (!FileExists(path)) { - dir.AddFile(new File(pathlist[pathlist.Length - 1], contents, false, Permissions.All)); + dir.AddFile(new File(pathlist[pathlist.Length - 1], contents, false, CurrentUser)); } else { -- cgit v1.2.3 From 75ed7e9215ba88358d9b838dd82fa3841f78ae5a Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 8 May 2017 11:31:20 -0400 Subject: Fix softlocks on pre-user OOBE. --- .vs/config/applicationhost.config | 1030 ++++++++++++++++++++++++++++++++ ShiftOS.Objects/ShiftOS.Objects.csproj | 1 + ShiftOS.Objects/UserConfig.cs | 37 ++ ShiftOS.Server/Program.cs | 1 + ShiftOS.Server/SaveManager.cs | 2 +- ShiftOS.WinForms/OobeStory.cs | 10 +- ShiftOS.WinForms/UniteLoginDialog.cs | 3 +- ShiftOS.WinForms/UniteSignupDialog.cs | 3 +- ShiftOS_TheReturn/SaveSystem.cs | 2 +- ShiftOS_TheReturn/UniteClient.cs | 12 +- 10 files changed, 1091 insertions(+), 10 deletions(-) create mode 100644 .vs/config/applicationhost.config create mode 100644 ShiftOS.Objects/UserConfig.cs (limited to 'ShiftOS.Objects') diff --git a/.vs/config/applicationhost.config b/.vs/config/applicationhost.config new file mode 100644 index 0000000..b42cd34 --- /dev/null +++ b/.vs/config/applicationhost.config @@ -0,0 +1,1030 @@ + + + + + + + + +
+
+
+
+
+
+
+
+ + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+ + +
+
+
+
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ShiftOS.Objects/ShiftOS.Objects.csproj b/ShiftOS.Objects/ShiftOS.Objects.csproj index 7a19aeb..c2ef5ed 100644 --- a/ShiftOS.Objects/ShiftOS.Objects.csproj +++ b/ShiftOS.Objects/ShiftOS.Objects.csproj @@ -58,6 +58,7 @@ + diff --git a/ShiftOS.Objects/UserConfig.cs b/ShiftOS.Objects/UserConfig.cs new file mode 100644 index 0000000..61d11b8 --- /dev/null +++ b/ShiftOS.Objects/UserConfig.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; + +namespace ShiftOS.Objects +{ + public class UserConfig + { + public string UniteUrl { get; set; } + public string DigitalSocietyAddress { get; set; } + public int DigitalSocietyPort { get; set; } + + public static UserConfig Get() + { + var conf = new UserConfig + { + UniteUrl = "http://getshiftos.ml", + DigitalSocietyAddress = "michaeltheshifter.me", + DigitalSocietyPort = 13370 + }; + + if (!File.Exists("servers.json")) + { + File.WriteAllText("servers.json", JsonConvert.SerializeObject(conf, Formatting.Indented)); + } + else + { + conf = JsonConvert.DeserializeObject(File.ReadAllText("servers.json")); + } + return conf; + } + } +} diff --git a/ShiftOS.Server/Program.cs b/ShiftOS.Server/Program.cs index 97c8a66..75af56f 100644 --- a/ShiftOS.Server/Program.cs +++ b/ShiftOS.Server/Program.cs @@ -86,6 +86,7 @@ namespace ShiftOS.Server /// The command-line arguments. public static void Main(string[] args) { + UserConfig.Get(); System.Timers.Timer tmr = new System.Timers.Timer(5000); tmr.Elapsed += (o, a) => { diff --git a/ShiftOS.Server/SaveManager.cs b/ShiftOS.Server/SaveManager.cs index 63aa2bf..d81a1a7 100644 --- a/ShiftOS.Server/SaveManager.cs +++ b/ShiftOS.Server/SaveManager.cs @@ -189,7 +189,7 @@ namespace ShiftOS.Server //Update the shiftos website with the user's codepoints. if (!string.IsNullOrWhiteSpace(sav.UniteAuthToken)) { - var wreq = WebRequest.Create("http://getshiftos.ml/API/SetCodepoints/" + sav.Codepoints.ToString()); + var wreq = WebRequest.Create(UserConfig.Get().UniteUrl + "/API/SetCodepoints/" + sav.Codepoints.ToString()); wreq.Headers.Add("Authentication: Token " + sav.UniteAuthToken); wreq.GetResponse(); } diff --git a/ShiftOS.WinForms/OobeStory.cs b/ShiftOS.WinForms/OobeStory.cs index bab4889..39ca5b5 100644 --- a/ShiftOS.WinForms/OobeStory.cs +++ b/ShiftOS.WinForms/OobeStory.cs @@ -120,7 +120,7 @@ namespace ShiftOS.WinForms Console.Write(" "); ConsoleEx.BackgroundColor = ConsoleColor.Black; } - Engine.AudioManager.PlayStream(Properties.Resources.typesound); + Desktop.InvokeOnWorkerThread(() => Engine.AudioManager.PlayStream(Properties.Resources.typesound)); formatProgress++; Thread.Sleep(175); } @@ -135,14 +135,16 @@ namespace ShiftOS.WinForms { Console.WriteLine("Creating: " + dir); Thread.Sleep(125); - Engine.AudioManager.PlayStream(Properties.Resources.writesound); + Desktop.InvokeOnWorkerThread(() => Engine.AudioManager.PlayStream(Properties.Resources.writesound)); } } Console.WriteLine(); Console.WriteLine("Next, let's get user information."); Console.WriteLine(); - ShiftOS.Engine.OutOfBoxExperience.PromptForLogin(); - + Desktop.InvokeOnWorkerThread(() => + { + ShiftOS.Engine.OutOfBoxExperience.PromptForLogin(); + }); } private static bool isValid(string text, string chars) { diff --git a/ShiftOS.WinForms/UniteLoginDialog.cs b/ShiftOS.WinForms/UniteLoginDialog.cs index 4c85005..c78e987 100644 --- a/ShiftOS.WinForms/UniteLoginDialog.cs +++ b/ShiftOS.WinForms/UniteLoginDialog.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using System.Windows.Forms; using ShiftOS.Engine; using System.Net; +using ShiftOS.Objects; namespace ShiftOS.WinForms { @@ -59,7 +60,7 @@ namespace ShiftOS.WinForms try { - var webrequest = HttpWebRequest.Create("http://getshiftos.ml/Auth/Login?appname=ShiftOS&appdesc=ShiftOS+client&version=1_0_beta_2_4"); + var webrequest = HttpWebRequest.Create(UserConfig.Get().UniteUrl + "/Auth/Login?appname=ShiftOS&appdesc=ShiftOS+client&version=1_0_beta_2_4"); string base64 = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{u}:{p}")); webrequest.Headers.Add("Authentication: Basic " + base64); var response = webrequest.GetResponse(); diff --git a/ShiftOS.WinForms/UniteSignupDialog.cs b/ShiftOS.WinForms/UniteSignupDialog.cs index a46a9b0..7d0fd33 100644 --- a/ShiftOS.WinForms/UniteSignupDialog.cs +++ b/ShiftOS.WinForms/UniteSignupDialog.cs @@ -10,6 +10,7 @@ using System.Windows.Forms; using ShiftOS.Engine; using Newtonsoft.Json; using System.Net; +using ShiftOS.Objects; namespace ShiftOS.WinForms { @@ -99,7 +100,7 @@ namespace ShiftOS.WinForms try { - var webrequest = HttpWebRequest.Create("http://getshiftos.ml/Auth/Register?appname=ShiftOS&appdesc=ShiftOS+client&version=1_0_beta_2_4&displayname=" + txtdisplay.Text + "&sysname=" + txtsysname.Text); + var webrequest = HttpWebRequest.Create(UserConfig.Get().UniteUrl + "/Auth/Register?appname=ShiftOS&appdesc=ShiftOS+client&version=1_0_beta_2_4&displayname=" + txtdisplay.Text + "&sysname=" + txtsysname.Text); string base64 = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{u}:{p}")); webrequest.Headers.Add("Authentication: Basic " + base64); var response = webrequest.GetResponse(); diff --git a/ShiftOS_TheReturn/SaveSystem.cs b/ShiftOS_TheReturn/SaveSystem.cs index e635a7a..31db58a 100644 --- a/ShiftOS_TheReturn/SaveSystem.cs +++ b/ShiftOS_TheReturn/SaveSystem.cs @@ -131,7 +131,7 @@ namespace ShiftOS.Engine try { - ServerManager.Initiate("secondary4162.cloudapp.net", 13370); + ServerManager.Initiate(UserConfig.Get().DigitalSocietyAddress, UserConfig.Get().DigitalSocietyPort); //This haults the client until the connection is successful. while (ServerManager.thisGuid == new Guid()) { diff --git a/ShiftOS_TheReturn/UniteClient.cs b/ShiftOS_TheReturn/UniteClient.cs index 1136b5c..8d6a58d 100644 --- a/ShiftOS_TheReturn/UniteClient.cs +++ b/ShiftOS_TheReturn/UniteClient.cs @@ -5,13 +5,20 @@ using System.Net; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; +using ShiftOS.Objects; namespace ShiftOS.Unite { public class UniteClient { public string Token { get; private set; } - public string BaseURL { get; private set; } + public string BaseURL + { + get + { + return UserConfig.Get().UniteUrl; + } + } public string GetDisplayNameId(string id) { @@ -25,7 +32,8 @@ namespace ShiftOS.Unite public UniteClient(string baseurl, string usertoken) { - BaseURL = baseurl; + //Handled by the servers.json file + //BaseURL = baseurl; Token = usertoken; } -- cgit v1.2.3 From c0f0e99f9d2a092209e710107c1f061fc8a2eaca Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 13 May 2017 10:22:51 -0400 Subject: Dithering, audio volume, and fix shutdown bug --- ShiftOS.Objects/Save.cs | 3 + ShiftOS.WinForms/Applications/Terminal.cs | 8 +- ShiftOS.WinForms/AudioManager.cs | 27 +++-- ShiftOS.WinForms/Program.cs | 6 +- ShiftOS.WinForms/Tools/DitheringEngine.cs | 160 ++++++++++++++++++++---------- ShiftOS_TheReturn/AppearanceManager.cs | 1 + ShiftOS_TheReturn/AudioManager.cs | 8 +- ShiftOS_TheReturn/Commands.cs | 34 +++++++ 8 files changed, 175 insertions(+), 72 deletions(-) (limited to 'ShiftOS.Objects') diff --git a/ShiftOS.Objects/Save.cs b/ShiftOS.Objects/Save.cs index 2a02bbc..cc19c79 100644 --- a/ShiftOS.Objects/Save.cs +++ b/ShiftOS.Objects/Save.cs @@ -35,6 +35,9 @@ namespace ShiftOS.Objects public class Save { + public int MusicVolume { get; set; } + public int SfxVolume { get; set; } + [Obsolete("This save variable is no longer used in Beta 2.4 and above of ShiftOS. Please use ShiftOS.Engine.SaveSystem.CurrentUser.Username to access the current user's username.")] public string Username { get; set; } diff --git a/ShiftOS.WinForms/Applications/Terminal.cs b/ShiftOS.WinForms/Applications/Terminal.cs index a14cc58..02c4cc0 100644 --- a/ShiftOS.WinForms/Applications/Terminal.cs +++ b/ShiftOS.WinForms/Applications/Terminal.cs @@ -491,9 +491,9 @@ namespace ShiftOS.WinForms.Applications TerminalBackend.InStory = false; TerminalBackend.PrintPrompt(); bool help_entered = false; - TerminalBackend.TextSent += (text) => + TerminalBackend.CommandProcessed += (text, args) => { - if (text == "sos.help" && help_entered == false) + if (text.EndsWith("sos.help") && help_entered == false) help_entered = true; }; while (help_entered == false) @@ -523,10 +523,10 @@ namespace ShiftOS.WinForms.Applications TerminalBackend.InStory = false; bool winopenEntered = false; TerminalBackend.PrintPrompt(); - TerminalBackend.TextSent += (text) => + TerminalBackend.CommandProcessed += (text, args) => { if (help_entered == true) - if (text == "win.open" && winopenEntered == false) + if (text.EndsWith("win.open") && winopenEntered == false) winopenEntered = true; }; while (winopenEntered == false) diff --git a/ShiftOS.WinForms/AudioManager.cs b/ShiftOS.WinForms/AudioManager.cs index eb0e798..ec12614 100644 --- a/ShiftOS.WinForms/AudioManager.cs +++ b/ShiftOS.WinForms/AudioManager.cs @@ -74,7 +74,19 @@ namespace ShiftOS.WinForms MemoryStream str = null; NAudio.Wave.Mp3FileReader mp3 = null; NAudio.Wave.WaveOut o = null; - while (!Engine.SaveSystem.ShuttingDown) + bool shuttingDown = false; + + Engine.AppearanceManager.OnExit += () => + { + shuttingDown = true; + o?.Stop(); + o?.Dispose(); + mp3?.Close(); + mp3?.Dispose(); + str?.Close(); + str?.Dispose(); + }; + while (shuttingDown == false) { str = new MemoryStream(GetRandomSong()); mp3 = new NAudio.Wave.Mp3FileReader(str); @@ -87,14 +99,15 @@ namespace ShiftOS.WinForms c = true; }; while (!c) + { + try + { + o.Volume = (float)Engine.SaveSystem.CurrentSave.MusicVolume / 100; + } + catch { } Thread.Sleep(10); - str.Dispose(); - o.Dispose(); - mp3.Dispose(); + } } - str?.Dispose(); - o?.Dispose(); - mp3?.Dispose(); }); athread.IsBackground = true; athread.Start(); diff --git a/ShiftOS.WinForms/Program.cs b/ShiftOS.WinForms/Program.cs index 73215d4..8f65265 100644 --- a/ShiftOS.WinForms/Program.cs +++ b/ShiftOS.WinForms/Program.cs @@ -68,11 +68,7 @@ namespace ShiftOS.WinForms SkinEngine.SetIconProber(new ShiftOSIconProvider()); ShiftOS.Engine.AudioManager.Init(new ShiftOSAudioProvider()); Localization.RegisterProvider(new WFLanguageProvider()); - AppearanceManager.OnExit += () => - { - Environment.Exit(0); - }; - + TutorialManager.RegisterTutorial(new Oobe()); TerminalBackend.TerminalRequested += () => diff --git a/ShiftOS.WinForms/Tools/DitheringEngine.cs b/ShiftOS.WinForms/Tools/DitheringEngine.cs index f96a45a..d042a40 100644 --- a/ShiftOS.WinForms/Tools/DitheringEngine.cs +++ b/ShiftOS.WinForms/Tools/DitheringEngine.cs @@ -226,6 +226,53 @@ namespace ShiftOS.WinForms.Tools } #endif + public static int GetClosestColor(int gray, bool eightBits, bool sixBits, bool fourBits, bool twoBits) + { + int newgray = gray; + if (!eightBits) + { + if (sixBits) + { + newgray = gray >> 2; + } + else + { + if (fourBits) + { + newgray = (int)linear(gray, 0, 255, 0, 15) * 4; + } + else + { + if (twoBits) + { + if (gray > 127 + 63) + { + newgray = 255; + } + else if (gray > 127) + newgray = 127 + 63; + else if (gray > 63) + { + newgray = 127; + } + else if (gray > 0) + newgray = 63; + else + newgray = 0; + } + else + { + if (gray > 127) + newgray = 255; + else + newgray = 0; + } + } + } + } + return newgray; + } + #if FLOYDSTEINBERG public static Image DitherImage(Image source) { @@ -260,75 +307,78 @@ namespace ShiftOS.WinForms.Tools bool eightBits = Shiftorium.UpgradeInstalled("color_depth_8_bits"); bool color_depth_floydsteinberg = Shiftorium.UpgradeInstalled("color_depth_floyd-steinberg_dithering"); bool dithering = Shiftorium.UpgradeInstalled("color_depth_dithering"); - - if (!sixteenBits) + bool twentyfourbits = Shiftorium.UpgradeInstalled("color_depth_24_bits"); + if (twentyfourbits) + { + sourceArr.CopyTo(destArr, 0); + } + else { - if (dithering == true) + + if (!sixteenBits) { - if (false == true) + if (dithering == true) { + if (false == true) + { + + } + else + { + int error = 0; + for (int i = 0; i < destArr.Length; i += 3) + { + byte r = sourceArr[i]; + byte g = sourceArr[i + 1]; + byte b = sourceArr[i + 2]; + + if (SkinEngine.LoadedSkin.SystemKey == Color.FromArgb(r, g, b)) + { + destArr[i] = r; + destArr[i + 1] = g; + destArr[i + 2] = b; + continue; + } + + int gray = (((r + g + b) / 3) + error); + int newgray = gray; + newgray = GetClosestColor(gray, eightBits, sixBits, fourBits, twoBits); + if (newgray > 255) + newgray = 255; + if (newgray < 0) + newgray = 0; + error = gray - newgray; + destArr[i] = (byte)newgray; + destArr[i + 1] = (byte)newgray; + destArr[i + 2] = (byte)newgray; + + } + } } + else { - int error = 0; - for (int i = 0; i < destArr.Length; i += 3) + for (int i = 0; i < sourceArr.Length; i += 3) { byte r = sourceArr[i]; byte g = sourceArr[i + 1]; byte b = sourceArr[i + 2]; - - int gray = (((r + g + b) / 3) + error); - int newgray = gray; - if (!eightBits) + if (SkinEngine.LoadedSkin.SystemKey == Color.FromArgb(r, g, b)) { - if (sixBits) - { - newgray = gray >> 2; - } - else - { - if (fourBits) - { - newgray = (int)linear(gray, 0, 255, 0, 63) * 4; - } - else - { - if (twoBits) - { - if (gray > 127 + 63) - { - newgray = 255; - } - else if (gray > 127) - newgray = 127 + 63; - else if (gray > 63) - { - newgray = 127; - } - else if (gray > 0) - newgray = 63; - else - newgray = 0; - } - else - { - if (gray > 127) - newgray = 255; - else - newgray = 0; - } - } - } + destArr[i] = r; + destArr[i + 1] = g; + destArr[i + 2] = b; + continue; } - if (newgray > 255) - newgray = 255; - if (newgray < 0) - newgray = 0; - error = gray - newgray; + + int gray = (r + g + b) / 3; + int newgray = GetClosestColor(gray, eightBits, sixBits, fourBits, twoBits); destArr[i] = (byte)newgray; - destArr[i+1] = (byte)newgray; - destArr[i+2] = (byte)newgray; + destArr[i + 1] = (byte)newgray; + destArr[i + 2] = (byte)newgray; + + } } diff --git a/ShiftOS_TheReturn/AppearanceManager.cs b/ShiftOS_TheReturn/AppearanceManager.cs index 42642f8..d8004bc 100644 --- a/ShiftOS_TheReturn/AppearanceManager.cs +++ b/ShiftOS_TheReturn/AppearanceManager.cs @@ -223,6 +223,7 @@ namespace ShiftOS.Engine /// internal static void Exit() { + OnExit?.Invoke(); //disconnect from MUD ServerManager.Disconnect(); Environment.Exit(0); diff --git a/ShiftOS_TheReturn/AudioManager.cs b/ShiftOS_TheReturn/AudioManager.cs index c50bd24..fff3369 100644 --- a/ShiftOS_TheReturn/AudioManager.cs +++ b/ShiftOS_TheReturn/AudioManager.cs @@ -88,7 +88,13 @@ namespace ShiftOS.Engine _reader = new AudioFileReader(file); _out = new WaveOut(); _out.Init(_reader); - _out.Volume = _provider.Volume; + try + { + _out.Volume = (float)SaveSystem.CurrentSave.SfxVolume / 100; + } + catch + { + } _out.Play(); _out.PlaybackStopped += (o, a) => { PlayCompleted?.Invoke(); }; } diff --git a/ShiftOS_TheReturn/Commands.cs b/ShiftOS_TheReturn/Commands.cs index 5b7674a..6e59311 100644 --- a/ShiftOS_TheReturn/Commands.cs +++ b/ShiftOS_TheReturn/Commands.cs @@ -378,6 +378,40 @@ namespace ShiftOS.Engine [Namespace("sos")] public static class ShiftOSCommands { + [Command("setsfxvolume", description = "Set the volume of various sound effects to a value between 1 and 100.")] + [RequiresArgument("value")] + public static bool SetSfxVolume(Dictionary args) + { + int value = int.Parse(args["value"].ToString()); + if (value >= 0 && value <= 100) + { + SaveSystem.CurrentSave.SfxVolume = value; + SaveSystem.SaveGame(); + } + else + { + Console.WriteLine("Volume must be between 0 and 100!"); + } + return true; + } + + [Command("setmusicvolume", description ="Set the music volume to a value between 1 and 100.")] + [RequiresArgument("value")] + public static bool SetMusicVolume(Dictionary args) + { + int value = int.Parse(args["value"].ToString()); + if(value >= 0 && value <= 100) + { + SaveSystem.CurrentSave.MusicVolume = value; + SaveSystem.SaveGame(); + } + else + { + Console.WriteLine("Volume must be between 0 and 100!"); + } + return true; + } + [RemoteLock] [Command("shutdown")] public static bool Shutdown() -- cgit v1.2.3