config system hotfixes

This commit is contained in:
Bitl 2023-05-24 08:19:49 -07:00
parent 9f6427a5b9
commit 7096548a62
5 changed files with 219 additions and 143 deletions

View File

@ -204,7 +204,6 @@ namespace Novetus.Core
} }
error: error:
ErrorHandler(filePath + ": Failed to load script.");
return null; return null;
} }

View File

@ -67,6 +67,8 @@ namespace Novetus.Core
private string FileName { get; set; } private string FileName { get; set; }
public string FullPath { get;} public string FullPath { get;}
public virtual Dictionary<string, string> ValueDefaults { get; set; }
public ConfigBase(string section, string path, string fileName) public ConfigBase(string section, string path, string fileName)
{ {
Section = section; Section = section;
@ -89,18 +91,37 @@ namespace Novetus.Core
public void CreateFile() public void CreateFile()
{ {
INI = new INIFile(FullPath); INI = new INIFile(FullPath);
DeployDefaults();
}
public virtual void DeployDefaults()
{
GenerateDefaults(); 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<string, string>()
{
{"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() public virtual void GenerateDefaultsEvent()
@ -137,8 +158,7 @@ namespace Novetus.Core
public void SaveSettingInt(string section, string name, int value) public void SaveSettingInt(string section, string name, int value)
{ {
INI.IniWriteValue(section, name, value.ToString()); SaveSetting(section, name, value.ToString());
SaveSettingEvent();
} }
public void SaveSettingBool(string name, bool value) public void SaveSettingBool(string name, bool value)
@ -148,8 +168,7 @@ namespace Novetus.Core
public void SaveSettingBool(string section, string name, bool value) public void SaveSettingBool(string section, string name, bool value)
{ {
INI.IniWriteValue(section, name, value.ToString()); SaveSetting(section, name, value.ToString());
SaveSettingEvent();
} }
public virtual void SaveSettingEvent() public virtual void SaveSettingEvent()
@ -168,7 +187,19 @@ namespace Novetus.Core
} }
else 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); 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) if(result)
{ {
return value; return value;
@ -188,9 +219,14 @@ namespace Novetus.Core
return 0; 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) if (result)
{ {
return value; return value;
@ -199,6 +235,11 @@ namespace Novetus.Core
return false; return false;
} }
public bool ReadSettingBool(string name)
{
return ReadSettingBool(Section, name);
}
public virtual void ReadSettingEvent() public virtual void ReadSettingEvent()
{ {
//read setting event. //read setting event.
@ -214,44 +255,45 @@ namespace Novetus.Core
public Config(string filename) : base("Config", GlobalPaths.ConfigDir, filename) { } public Config(string filename) : base("Config", GlobalPaths.ConfigDir, filename) { }
public override void GenerateDefaults() public override void DefineDefaults()
{ {
SaveSetting("SelectedClient", ""); ValueDefaults = new Dictionary<string, string>(){
SaveSetting("Map", ""); {"SelectedClient", ""},
SaveSettingBool("CloseOnLaunch", false); {"Map", ""},
SaveSettingInt("UserID", NovetusFuncs.GeneratePlayerID()); {"CloseOnLaunch", Util.BoolValue(false)},
SaveSetting("PlayerName", "Player"); {"UserID", Util.IntValue(NovetusFuncs.GeneratePlayerID())},
SaveSettingInt("RobloxPort", 53640); {"PlayerName", "Player"},
SaveSettingInt("PlayerLimit", 12); {"RobloxPort", Util.IntValue(53640)},
SaveSettingBool("UPnP", false); {"PlayerLimit", Util.IntValue(12)},
SaveSettingBool("DisabledAssetSDKHelp", false); {"UPnP", Util.BoolValue(false)},
SaveSettingBool("DiscordRichPresence", true); {"DisabledAssetSDKHelp", Util.BoolValue(false)},
SaveSetting("MapPath", ""); {"DiscordRichPresence", Util.BoolValue(true)},
SaveSetting("MapPathSnip", ""); {"MapPath", ""},
SaveSettingInt("GraphicsMode", (int)Settings.Mode.Automatic); {"MapPathSnip", ""},
SaveSettingInt("QualityLevel", (int)Settings.Level.Automatic); {"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()) if (Util.IsWineRunning())
{ {
SaveSettingInt("LauncherStyle", (int)Settings.Style.Extended); 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 #endregion
@ -262,33 +304,35 @@ namespace Novetus.Core
public CustomizationConfig() : base("Customization", GlobalPaths.ConfigDir, GlobalPaths.ConfigNameCustomization) { } public CustomizationConfig() : base("Customization", GlobalPaths.ConfigDir, GlobalPaths.ConfigNameCustomization) { }
public CustomizationConfig(string filename) : base("Customization", GlobalPaths.ConfigDir, filename) { } public CustomizationConfig(string filename) : base("Customization", GlobalPaths.ConfigDir, filename) { }
public override void GenerateDefaults() public override void DefineDefaults()
{ {
SaveSetting("Hat1", "NoHat.rbxm"); ValueDefaults = new Dictionary<string, string>(){
SaveSetting("Hat2", "NoHat.rbxm"); {"Hat1", "NoHat.rbxm"},
SaveSetting("Hat3", "NoHat.rbxm"); {"Hat2", "NoHat.rbxm"},
SaveSetting("Face", "DefaultFace.rbxm"); {"Hat3", "NoHat.rbxm"},
SaveSetting("Head", "DefaultHead.rbxm"); {"Face", "DefaultFace.rbxm"},
SaveSetting("TShirt", "NoTShirt.rbxm"); {"Head", "DefaultHead.rbxm"},
SaveSetting("Shirt", "NoShirt.rbxm"); {"TShirt", "NoTShirt.rbxm"},
SaveSetting("Pants", "NoPants.rbxm"); {"Shirt", "NoShirt.rbxm"},
SaveSetting("Icon", "NBC"); {"Pants", "NoPants.rbxm"},
SaveSetting("Extra", "NoExtra.rbxm"); {"Icon", "NBC"},
SaveSettingInt("HeadColorID", 24); {"Extra", "NoExtra.rbxm"},
SaveSettingInt("TorsoColorID", 23); {"HeadColorID", Util.IntValue(24)},
SaveSettingInt("LeftArmColorID", 24); {"TorsoColorID", Util.IntValue(23)},
SaveSettingInt("RightArmColorID", 24); {"LeftArmColorID", Util.IntValue(24)},
SaveSettingInt("LeftLegColorID", 119); {"RightArmColorID", Util.IntValue(24)},
SaveSettingInt("RightLegColorID", 119); {"LeftLegColorID", Util.IntValue(119)},
SaveSetting("HeadColorString", "Color [A=255, R=245, G=205, B=47]"); {"RightLegColorID", Util.IntValue(119)},
SaveSetting("TorsoColorString", "Color [A=255, R=13, G=105, B=172]"); {"HeadColorString", "Color [A=255, R=245, G=205, B=47]"},
SaveSetting("LeftArmColorString", "Color [A=255, R=245, G=205, B=47]"); {"TorsoColorString", "Color [A=255, R=13, G=105, B=172]"},
SaveSetting("RightArmColorString", "Color [A=255, R=245, G=205, B=47]"); {"LeftArmColorString", "Color [A=255, R=245, G=205, B=47]"},
SaveSetting("LeftLegColorString", "Color [A=255, R=164, G=189, B=71]"); {"RightArmColorString", "Color [A=255, R=245, G=205, B=47]"},
SaveSetting("RightLegColorString", "Color [A=255, R=164, G=189, B=71]"); {"LeftLegColorString", "Color [A=255, R=164, G=189, B=71]"},
SaveSettingBool("ExtraSelectionIsHat", false); {"RightLegColorString", "Color [A=255, R=164, G=189, B=71]"},
SaveSettingBool("ShowHatsInExtra", false); {"ExtraSelectionIsHat", Util.BoolValue(false)},
SaveSetting("CharacterID", ""); {"ShowHatsInExtra", Util.BoolValue(false)},
{"CharacterID", ""}
};
} }
} }
#endregion #endregion

View File

@ -767,83 +767,97 @@ namespace Novetus.Core
} }
#if LAUNCHER #if LAUNCHER
//https://stackoverflow.com/questions/30687987/unable-to-decompress-bz2-file-has-orginal-file-using-dotnetzip-library //https://stackoverflow.com/questions/30687987/unable-to-decompress-bz2-file-has-orginal-file-using-dotnetzip-library
public static string Compress(string sourceFile, bool forceOverwrite) public static string Compress(string sourceFile, bool forceOverwrite)
{
var outFname = sourceFile + ".bz2";
if (File.Exists(outFname))
{ {
if (forceOverwrite) var outFname = sourceFile + ".bz2";
File.Delete(outFname);
else
return null;
}
long rowCount = 0;
var output = File.Create(outFname);
try if (File.Exists(outFname))
{
using (StreamReader reader = new StreamReader(sourceFile))
{ {
using (var compressor = new Ionic.BZip2.ParallelBZip2OutputStream(output)) if (forceOverwrite)
{ File.Delete(outFname);
StreamWriter writer = new StreamWriter(compressor, Encoding.UTF8); else
string line = ""; return null;
while ((line = reader.ReadLine()) != null) }
{ long rowCount = 0;
writer.WriteLine(line); var output = File.Create(outFname);
rowCount++;
}
writer.Close(); try
compressor.Close(); {
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) byte[] buffer = new byte[2048];
output = null; 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 #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
} }
#endregion #endregion

View File

@ -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 EDGE Snapshot v23.8542.41029.1
Notes: 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. - 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.

View File

@ -27,7 +27,7 @@ public class AwardBadge : IWebProxyExtension
void AddBadgeToDB(BadgeData data, bool Awarded = false) void AddBadgeToDB(BadgeData data, bool Awarded = false)
{ {
CreateBadgeDatabaseIfNeeded(); 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; string BadgeName = BaseMapName + "_" + data.BadgeId.ToString() + "_" + (data.BadgeName.Replace(" ", "-")) + "_" + data.BadgeCreatorName;
ini.IniWriteValue(BadgeDatabaseSection, BadgeName, Awarded.ToString()); ini.IniWriteValue(BadgeDatabaseSection, BadgeName, Awarded.ToString());
} }
@ -61,7 +61,7 @@ public class AwardBadge : IWebProxyExtension
result.BadgeId = BadgeID; result.BadgeId = BadgeID;
result.BadgeName = BadgeID.ToString(); result.BadgeName = BadgeID.ToString();
result.BadgeCreatorName = "Unknown"; 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) if (GlobalVars.GameOpened == ScriptType.EasterEgg)
{ {
@ -95,7 +95,7 @@ public class AwardBadge : IWebProxyExtension
return "0"; 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() public override string Name()