diff --git a/Novetus/NovetusCore/Classes/Script.cs b/Novetus/NovetusCore/Classes/Script.cs index dccdbd6..72f7ae2 100644 --- a/Novetus/NovetusCore/Classes/Script.cs +++ b/Novetus/NovetusCore/Classes/Script.cs @@ -204,7 +204,6 @@ namespace Novetus.Core } error: - ErrorHandler(filePath + ": Failed to load script."); return null; } diff --git a/Novetus/NovetusCore/StorageAndFunctions/FileManagement.cs b/Novetus/NovetusCore/StorageAndFunctions/FileManagement.cs index 495451d..62e09af 100644 --- a/Novetus/NovetusCore/StorageAndFunctions/FileManagement.cs +++ b/Novetus/NovetusCore/StorageAndFunctions/FileManagement.cs @@ -67,6 +67,8 @@ namespace Novetus.Core private string FileName { get; set; } public string FullPath { get;} + public virtual Dictionary ValueDefaults { get; set; } + public ConfigBase(string section, string path, string fileName) { Section = section; @@ -89,18 +91,37 @@ namespace Novetus.Core public void CreateFile() { INI = new INIFile(FullPath); - DeployDefaults(); - } - - public virtual void DeployDefaults() - { GenerateDefaults(); - GenerateDefaultsEvent(); } - public virtual void GenerateDefaults() + public virtual void DefineDefaults() { - //defaults go in here. + //fill dictionary here + } + + public void GenerateDefaults() + { + DefineDefaults(); + + if (ValueDefaults.Count == 0) + { + ValueDefaults = new Dictionary() + { + {"Error", "There are no default values in your ConfigBase class!"} + }; + } + + foreach (string key in ValueDefaults.Keys) + { + var value = ValueDefaults[key]; + + if (value != null) + { + SaveSetting(key, value); + } + } + + GenerateDefaultsEvent(); } public virtual void GenerateDefaultsEvent() @@ -137,8 +158,7 @@ namespace Novetus.Core public void SaveSettingInt(string section, string name, int value) { - INI.IniWriteValue(section, name, value.ToString()); - SaveSettingEvent(); + SaveSetting(section, name, value.ToString()); } public void SaveSettingBool(string name, bool value) @@ -148,8 +168,7 @@ namespace Novetus.Core public void SaveSettingBool(string section, string name, bool value) { - INI.IniWriteValue(section, name, value.ToString()); - SaveSettingEvent(); + SaveSetting(section, name, value.ToString()); } public virtual void SaveSettingEvent() @@ -168,7 +187,19 @@ namespace Novetus.Core } else { - return ""; + string defaultval; + + try + { + defaultval = ValueDefaults[name]; + } + catch(Exception) + { + defaultval = ""; + } + + SaveSetting(section, name, defaultval); + return INI.IniReadValue(section, name); } } @@ -177,9 +208,9 @@ namespace Novetus.Core return ReadSetting(Section, name); } - public int ReadSettingInt(string name) + public int ReadSettingInt(string section, string name) { - bool result = int.TryParse(ReadSetting(name), out int value); + bool result = int.TryParse(ReadSetting(section, name), out int value); if(result) { return value; @@ -188,9 +219,14 @@ namespace Novetus.Core return 0; } - public bool ReadSettingBool(string name) + public int ReadSettingInt(string name) { - bool result = bool.TryParse(ReadSetting(name), out bool value); + return ReadSettingInt(Section, name); + } + + public bool ReadSettingBool(string section, string name) + { + bool result = bool.TryParse(ReadSetting(section, name), out bool value); if (result) { return value; @@ -199,6 +235,11 @@ namespace Novetus.Core return false; } + public bool ReadSettingBool(string name) + { + return ReadSettingBool(Section, name); + } + public virtual void ReadSettingEvent() { //read setting event. @@ -214,44 +255,45 @@ namespace Novetus.Core public Config(string filename) : base("Config", GlobalPaths.ConfigDir, filename) { } - public override void GenerateDefaults() + public override void DefineDefaults() { - SaveSetting("SelectedClient", ""); - SaveSetting("Map", ""); - SaveSettingBool("CloseOnLaunch", false); - SaveSettingInt("UserID", NovetusFuncs.GeneratePlayerID()); - SaveSetting("PlayerName", "Player"); - SaveSettingInt("RobloxPort", 53640); - SaveSettingInt("PlayerLimit", 12); - SaveSettingBool("UPnP", false); - SaveSettingBool("DisabledAssetSDKHelp", false); - SaveSettingBool("DiscordRichPresence", true); - SaveSetting("MapPath", ""); - SaveSetting("MapPathSnip", ""); - SaveSettingInt("GraphicsMode", (int)Settings.Mode.Automatic); - SaveSettingInt("QualityLevel", (int)Settings.Level.Automatic); + ValueDefaults = new Dictionary(){ + {"SelectedClient", ""}, + {"Map", ""}, + {"CloseOnLaunch", Util.BoolValue(false)}, + {"UserID", Util.IntValue(NovetusFuncs.GeneratePlayerID())}, + {"PlayerName", "Player"}, + {"RobloxPort", Util.IntValue(53640)}, + {"PlayerLimit", Util.IntValue(12)}, + {"UPnP", Util.BoolValue(false)}, + {"DisabledAssetSDKHelp", Util.BoolValue(false)}, + {"DiscordRichPresence", Util.BoolValue(true)}, + {"MapPath", ""}, + {"MapPathSnip", ""}, + {"GraphicsMode", Util.IntValue((int)Settings.Mode.Automatic)}, + {"QualityLevel", Util.IntValue((int)Settings.Level.Automatic)}, + {"LauncherStyle", Util.IntValue((int)Settings.Style.Stylish)}, + {"AssetSDKFixerSaveBackups", Util.BoolValue(true)}, + {"AlternateServerIP", ""}, + {"ShowServerNotifications", Util.BoolValue(false)}, + {"ServerBrowserServerName", "Novetus"}, + {"ServerBrowserServerAddress", ""}, + {"Priority", Util.IntValue((int)ProcessPriorityClass.RealTime)}, + {"FirstServerLaunch", Util.BoolValue(true)}, + {"NewGUI", Util.BoolValue(false)}, + {"URIQuickConfigure", Util.BoolValue(true)}, + {"BootstrapperShowUI", Util.BoolValue(true)}, + {"WebProxyInitialSetupRequired", Util.BoolValue(true)}, + {"WebProxyEnabled", Util.BoolValue(false)} + }; + } + public override void GenerateDefaultsEvent() + { if (Util.IsWineRunning()) { SaveSettingInt("LauncherStyle", (int)Settings.Style.Extended); } - else - { - SaveSettingInt("LauncherStyle", (int)Settings.Style.Stylish); - } - - SaveSettingBool("AssetSDKFixerSaveBackups", true); - SaveSetting("AlternateServerIP", ""); - SaveSettingBool("ShowServerNotifications", false); - SaveSetting("ServerBrowserServerName", "Novetus"); - SaveSetting("ServerBrowserServerAddress", ""); - SaveSettingInt("Priority", (int)ProcessPriorityClass.RealTime); - SaveSettingBool("FirstServerLaunch", true); - SaveSettingBool("NewGUI", false); - SaveSettingBool("URIQuickConfigure", true); - SaveSettingBool("BootstrapperShowUI", true); - SaveSettingBool("WebProxyInitialSetupRequired", true); - SaveSettingBool("WebProxyEnabled", false); } } #endregion @@ -262,33 +304,35 @@ namespace Novetus.Core public CustomizationConfig() : base("Customization", GlobalPaths.ConfigDir, GlobalPaths.ConfigNameCustomization) { } public CustomizationConfig(string filename) : base("Customization", GlobalPaths.ConfigDir, filename) { } - public override void GenerateDefaults() + public override void DefineDefaults() { - SaveSetting("Hat1", "NoHat.rbxm"); - SaveSetting("Hat2", "NoHat.rbxm"); - SaveSetting("Hat3", "NoHat.rbxm"); - SaveSetting("Face", "DefaultFace.rbxm"); - SaveSetting("Head", "DefaultHead.rbxm"); - SaveSetting("TShirt", "NoTShirt.rbxm"); - SaveSetting("Shirt", "NoShirt.rbxm"); - SaveSetting("Pants", "NoPants.rbxm"); - SaveSetting("Icon", "NBC"); - SaveSetting("Extra", "NoExtra.rbxm"); - SaveSettingInt("HeadColorID", 24); - SaveSettingInt("TorsoColorID", 23); - SaveSettingInt("LeftArmColorID", 24); - SaveSettingInt("RightArmColorID", 24); - SaveSettingInt("LeftLegColorID", 119); - SaveSettingInt("RightLegColorID", 119); - SaveSetting("HeadColorString", "Color [A=255, R=245, G=205, B=47]"); - SaveSetting("TorsoColorString", "Color [A=255, R=13, G=105, B=172]"); - SaveSetting("LeftArmColorString", "Color [A=255, R=245, G=205, B=47]"); - SaveSetting("RightArmColorString", "Color [A=255, R=245, G=205, B=47]"); - SaveSetting("LeftLegColorString", "Color [A=255, R=164, G=189, B=71]"); - SaveSetting("RightLegColorString", "Color [A=255, R=164, G=189, B=71]"); - SaveSettingBool("ExtraSelectionIsHat", false); - SaveSettingBool("ShowHatsInExtra", false); - SaveSetting("CharacterID", ""); + ValueDefaults = new Dictionary(){ + {"Hat1", "NoHat.rbxm"}, + {"Hat2", "NoHat.rbxm"}, + {"Hat3", "NoHat.rbxm"}, + {"Face", "DefaultFace.rbxm"}, + {"Head", "DefaultHead.rbxm"}, + {"TShirt", "NoTShirt.rbxm"}, + {"Shirt", "NoShirt.rbxm"}, + {"Pants", "NoPants.rbxm"}, + {"Icon", "NBC"}, + {"Extra", "NoExtra.rbxm"}, + {"HeadColorID", Util.IntValue(24)}, + {"TorsoColorID", Util.IntValue(23)}, + {"LeftArmColorID", Util.IntValue(24)}, + {"RightArmColorID", Util.IntValue(24)}, + {"LeftLegColorID", Util.IntValue(119)}, + {"RightLegColorID", Util.IntValue(119)}, + {"HeadColorString", "Color [A=255, R=245, G=205, B=47]"}, + {"TorsoColorString", "Color [A=255, R=13, G=105, B=172]"}, + {"LeftArmColorString", "Color [A=255, R=245, G=205, B=47]"}, + {"RightArmColorString", "Color [A=255, R=245, G=205, B=47]"}, + {"LeftLegColorString", "Color [A=255, R=164, G=189, B=71]"}, + {"RightLegColorString", "Color [A=255, R=164, G=189, B=71]"}, + {"ExtraSelectionIsHat", Util.BoolValue(false)}, + {"ShowHatsInExtra", Util.BoolValue(false)}, + {"CharacterID", ""} + }; } } #endregion diff --git a/Novetus/NovetusCore/StorageAndFunctions/Util.cs b/Novetus/NovetusCore/StorageAndFunctions/Util.cs index aa8d8ee..6957c4a 100644 --- a/Novetus/NovetusCore/StorageAndFunctions/Util.cs +++ b/Novetus/NovetusCore/StorageAndFunctions/Util.cs @@ -767,83 +767,97 @@ namespace Novetus.Core } #if LAUNCHER - //https://stackoverflow.com/questions/30687987/unable-to-decompress-bz2-file-has-orginal-file-using-dotnetzip-library - public static string Compress(string sourceFile, bool forceOverwrite) - { - var outFname = sourceFile + ".bz2"; - - if (File.Exists(outFname)) + //https://stackoverflow.com/questions/30687987/unable-to-decompress-bz2-file-has-orginal-file-using-dotnetzip-library + public static string Compress(string sourceFile, bool forceOverwrite) { - if (forceOverwrite) - File.Delete(outFname); - else - return null; - } - long rowCount = 0; - var output = File.Create(outFname); + var outFname = sourceFile + ".bz2"; - try - { - using (StreamReader reader = new StreamReader(sourceFile)) + if (File.Exists(outFname)) { - using (var compressor = new Ionic.BZip2.ParallelBZip2OutputStream(output)) - { - StreamWriter writer = new StreamWriter(compressor, Encoding.UTF8); - string line = ""; - while ((line = reader.ReadLine()) != null) - { - writer.WriteLine(line); - rowCount++; - } + if (forceOverwrite) + File.Delete(outFname); + else + return null; + } + long rowCount = 0; + var output = File.Create(outFname); - writer.Close(); - compressor.Close(); + try + { + using (StreamReader reader = new StreamReader(sourceFile)) + { + using (var compressor = new Ionic.BZip2.ParallelBZip2OutputStream(output)) + { + StreamWriter writer = new StreamWriter(compressor, Encoding.UTF8); + string line = ""; + while ((line = reader.ReadLine()) != null) + { + writer.WriteLine(line); + rowCount++; + } + + writer.Close(); + compressor.Close(); + } } } + catch (Exception) + { + + throw; + } + finally + { + if (output != null) + output = null; + } + + // Pump(fs, compressor); + + return outFname; } - catch (Exception) + + public static string Decompress(string sourceFile, bool forceOverwrite) { + var outFname = sourceFile.Replace(".bz2", ""); + if (File.Exists(outFname)) + { + if (forceOverwrite) + File.Delete(outFname); + else + return null; + } - throw; + using (Stream fs = File.OpenRead(sourceFile), + output = File.Create(outFname), + decompressor = new Ionic.BZip2.BZip2InputStream(fs)) + Pump(decompressor, output); + + return outFname; } - finally + + private static void Pump(Stream src, Stream dest) { - if (output != null) - output = null; + byte[] buffer = new byte[2048]; + int n; + while ((n = src.Read(buffer, 0, buffer.Length)) > 0) + dest.Write(buffer, 0, n); } - - // Pump(fs, compressor); - - return outFname; - } - - public static string Decompress(string sourceFile, bool forceOverwrite) - { - var outFname = sourceFile.Replace(".bz2", ""); - if (File.Exists(outFname)) - { - if (forceOverwrite) - File.Delete(outFname); - else - return null; - } - - using (Stream fs = File.OpenRead(sourceFile), - output = File.Create(outFname), - decompressor = new Ionic.BZip2.BZip2InputStream(fs)) - Pump(decompressor, output); - - return outFname; - } - - private static void Pump(Stream src, Stream dest) - { - byte[] buffer = new byte[2048]; - int n; - while ((n = src.Read(buffer, 0, buffer.Length)) > 0) - dest.Write(buffer, 0, n); - } #endif + + //these methods were made so we dont have to do shit like false.ToString() or 0.ToString(). + //will still use ToString for converting variables, but converting values didn't feel right. + + public static string BoolValue(bool value) + { + return value.ToString(); + } + + public static string IntValue(int value) + { + return value.ToString(); + } + #endregion } #endregion diff --git a/changelog.txt b/changelog.txt index ee04ba1..c4cbfc5 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,22 @@ +EDGE Snapshot v23.8544.14774.1 +Enhancements: +- The Config System now has support for default values! + - Missing values will now be replaced with default values, making the system more reliable. + +Fixes: +- The Award Badge API is now functional again. +---------------------------------------------------------------------------- +EDGE Snapshot v23.8543.15186.1 +Enhancements: +- Customization is now fixed and available. + - You may have to delete your config/config_customization.ini in order for Novetus to save the proper default settings. + +Fixes: +- Fixed a bug where Hat #2 reports as Hat #1 in the character customization menu. + +Known Issues: +- The Hair O' Snow will not work with clients below 2010L due to it being saved with version 2 instead of version 1.0. +---------------------------------------------------------------------------- EDGE Snapshot v23.8542.41029.1 Notes: - This snapshot begins the introduction of EDGE builds, snapshots with heavily unpolished, work-in-progress features coming to Novetus. The EDGE features will be listed in each EDGE snapshot. diff --git a/defaultaddons/novetusexts/webproxy/AwardBadge.cs b/defaultaddons/novetusexts/webproxy/AwardBadge.cs index e5a7e5b..0e3c41a 100644 --- a/defaultaddons/novetusexts/webproxy/AwardBadge.cs +++ b/defaultaddons/novetusexts/webproxy/AwardBadge.cs @@ -27,7 +27,7 @@ public class AwardBadge : IWebProxyExtension void AddBadgeToDB(BadgeData data, bool Awarded = false) { CreateBadgeDatabaseIfNeeded(); - string BaseMapName = GlobalVars.UserConfiguration.MapPathSnip.Replace(@"maps\\", "").Replace(".rbxl", "").Replace(".rbxlx", "").Replace(".bz2", ""); + string BaseMapName = GlobalVars.UserConfiguration.ReadSetting("MapPathSnip").Replace(@"maps\\", "").Replace(".rbxl", "").Replace(".rbxlx", "").Replace(".bz2", ""); string BadgeName = BaseMapName + "_" + data.BadgeId.ToString() + "_" + (data.BadgeName.Replace(" ", "-")) + "_" + data.BadgeCreatorName; ini.IniWriteValue(BadgeDatabaseSection, BadgeName, Awarded.ToString()); } @@ -61,7 +61,7 @@ public class AwardBadge : IWebProxyExtension result.BadgeId = BadgeID; result.BadgeName = BadgeID.ToString(); result.BadgeCreatorName = "Unknown"; - string metaFile = (GlobalVars.UserConfiguration.MapPath.Replace(".rbxl", "").Replace(".rbxlx", "").Replace(".bz2", "") + MetadataFileExtension); + string metaFile = (GlobalVars.UserConfiguration.ReadSetting("MapPath").Replace(".rbxl", "").Replace(".rbxlx", "").Replace(".bz2", "") + MetadataFileExtension); if (GlobalVars.GameOpened == ScriptType.EasterEgg) { @@ -95,7 +95,7 @@ public class AwardBadge : IWebProxyExtension return "0"; } - return GlobalVars.UserConfiguration.PlayerName + " won " + creatorName + "'s \"" + badgeName + "\" award!"; + return GlobalVars.UserConfiguration.ReadSetting("PlayerName") + " won " + creatorName + "'s \"" + badgeName + "\" award!"; } public override string Name()