private static Skill ReadSkill(string key, System.IO.FileInfo info) { var cv = new NetScriptFramework.Tools.ConfigFile("CustomSkill." + key); cv.AddSetting("Name", new NetScriptFramework.Tools.Value("Vampire Lord")); cv.AddSetting("Description", new NetScriptFramework.Tools.Value("Kill enemies with the Drain Life or bite power attack to earn perks. Each new perk requires a few more feedings.")); cv.AddSetting("Skydome", new NetScriptFramework.Tools.Value("DLC01/Interface/INTVampirePerkSkydome.nif")); cv.AddSetting("SkydomeNormalNif", new NetScriptFramework.Tools.Value(false)); cv.AddSetting("LevelFile", new NetScriptFramework.Tools.Value("Skyrim.esm")); cv.AddSetting("LevelId", new NetScriptFramework.Tools.Value((uint)0x646)); cv.AddSetting("RatioFile", new NetScriptFramework.Tools.Value("")); cv.AddSetting("RatioId", new NetScriptFramework.Tools.Value((uint)0x0)); cv.AddSetting("ShowLevelupFile", new NetScriptFramework.Tools.Value("")); cv.AddSetting("ShowLevelupId", new NetScriptFramework.Tools.Value((uint)0x0)); cv.AddSetting("ShowMenuFile", new NetScriptFramework.Tools.Value("")); cv.AddSetting("ShowMenuId", new NetScriptFramework.Tools.Value((uint)0x0)); cv.AddSetting("PerkPointsFile", new NetScriptFramework.Tools.Value("")); cv.AddSetting("PerkPointsId", new NetScriptFramework.Tools.Value((uint)0x0)); cv.AddSetting("LegendaryFile", new NetScriptFramework.Tools.Value("")); cv.AddSetting("LegendaryId", new NetScriptFramework.Tools.Value((uint)0x0)); cv.AddSetting("ColorFile", new NetScriptFramework.Tools.Value("")); cv.AddSetting("ColorId", new NetScriptFramework.Tools.Value((uint)0x0)); cv.AddSetting("DebugReloadFile", new NetScriptFramework.Tools.Value("")); cv.AddSetting("DebugReloadId", new NetScriptFramework.Tools.Value((uint)0x0)); for (int i = 0; i <= MaxNodes; i++) { string nk = "Node" + i + "."; cv.AddSetting(nk + "Enable", new NetScriptFramework.Tools.Value(false)); cv.AddSetting(nk + "PerkFile", new NetScriptFramework.Tools.Value("")); cv.AddSetting(nk + "PerkId", new NetScriptFramework.Tools.Value((uint)0x0)); cv.AddSetting(nk + "X", new NetScriptFramework.Tools.Value((float)0)); cv.AddSetting(nk + "Y", new NetScriptFramework.Tools.Value((float)0)); cv.AddSetting(nk + "GridX", new NetScriptFramework.Tools.Value((int)0)); cv.AddSetting(nk + "GridY", new NetScriptFramework.Tools.Value((int)0)); cv.AddSetting(nk + "Links", new NetScriptFramework.Tools.Value("")); } cv.Load(); var sk = new Skill(); var v = cv.GetValue("Name"); if (v != null) { sk.Name.Value = v.ToString(); } v = cv.GetValue("Description"); if (v != null) { sk.Description.Value = v.ToString(); } v = cv.GetValue("Skydome"); if (v != null) { sk.Skydome.Value = v.ToString(); } v = cv.GetValue("SkydomeNormalNif"); bool ub; if (v != null && v.TryToBoolean(out ub) && ub) { sk.NormalNif = true; } sk.Level = LoadGValueShort("Level", cv); sk.Ratio = LoadGValueFloat("Ratio", cv); sk.ShowLevelup = LoadGValueShort("ShowLevelup", cv); sk.OpenMenu = LoadGValueShort("ShowMenu", cv); sk.PerkPoints = LoadGValueShort("PerkPoints", cv); sk.Legendary = LoadGValueShort("Legendary", cv); sk.Color = LoadGValueInt("Color", cv); sk.DebugReload = LoadGValueShort("DebugReload", cv); if (sk.Level == null) { Error(info, "Failed to load form for Level global variable!"); return(null); } if (sk.Ratio == null) { Error(info, "Failed to load form for Level ratio global variable!"); return(null); } if (sk.ShowLevelup == null) { Error(info, "Failed to load form for showing Level up global variable!"); return(null); } if (sk.OpenMenu == null) { Error(info, "Failed to load form for showing skill menu global variable!"); return(null); } var nodes = new List <TreeNode>(); for (int i = 0; i <= MaxNodes; i++) { string nk = "Node" + i + "."; v = cv.GetValue(nk + "Enable"); bool r; if (v == null || !v.TryToBoolean(out r) || !r) { continue; } var tn = new TreeNode(); tn.Index = i; int ri; uint ru; float rf; v = cv.GetValue(nk + "PerkFile"); if (v != null) { tn.PerkFile = v.ToString(); } v = cv.GetValue(nk + "PerkId"); if (v != null && v.TryToUInt32(out ru) && ru != 0) { tn.PerkId = ru; } v = cv.GetValue(nk + "X"); if (v != null && v.TryToSingle(out rf)) { tn.X = rf; } v = cv.GetValue(nk + "Y"); if (v != null && v.TryToSingle(out rf)) { tn.Y = rf; } v = cv.GetValue(nk + "GridX"); if (v != null && v.TryToInt32(out ri)) { tn.GridX = ri; } v = cv.GetValue(nk + "GridY"); if (v != null && v.TryToInt32(out ri)) { tn.GridY = ri; } v = cv.GetValue(nk + "Links"); if (v != null) { string lns = v.ToString(); var spl = lns.Split(new[] { ' ', '\t', ',' }, StringSplitOptions.RemoveEmptyEntries); List <int> lnks = new List <int>(); foreach (var x in spl) { if (int.TryParse(x, System.Globalization.NumberStyles.None, null, out ri)) { lnks.Add(ri); } else { Error(info, "Format error in " + nk + "Links! Unable to parse integer from " + x + "!"); return(null); } } if (lnks.Count != 0) { tn.Links = lnks; } } nodes.Add(tn); } try { sk.SkillTree = TreeNode.Create(nodes); } catch { Error(info, "Something went wrong when creating skill perk tree! Make sure node 0 exists and no missing nodes are referenced in links."); return(null); } return(sk); }
/// <summary> /// Initializes the fixes and applies them. /// </summary> /// <param name="parent">The parent plugin.</param> /// <param name="configKeyword">The configuration file keyword.</param> /// <exception cref="System.ArgumentException">Warning: parent.Name fix t.Name does not have valid parameterless constructor!</exception> internal static void init(NetScriptFramework.Plugin parent, string configKeyword) { if (System.Threading.Interlocked.Exchange(ref is_init, 1) != 0) { throw new InvalidOperationException(); } var asm = System.Reflection.Assembly.GetExecutingAssembly(); var types = asm.GetTypes(); foreach (var t in types) { if (t.IsAbstract || !t.IsSubclassOf(typeof(Fix))) { continue; } var cis = t.GetConstructors().Where(q => q.GetParameters().Length == 0).ToList(); if (cis.Count != 1) { throw new ArgumentException("Warning: " + parent.Name + " fix " + t.Name + " does not have valid parameterless constructor!"); } Fix f = (Fix)cis[0].Invoke(new object[0]); fixes.Add(f); } var config = new NetScriptFramework.Tools.ConfigFile(configKeyword); foreach (var f in fixes) { config.AddSetting(f.Key + ".Enabled", new NetScriptFramework.Tools.Value(f.Enabled), null, f.Description); foreach (var pair in f.IntParameters) { config.AddSetting(f.Key + "." + pair.Key, new NetScriptFramework.Tools.Value(pair.Value)); } foreach (var pair in f.FloatParameters) { config.AddSetting(f.Key + "." + pair.Key, new NetScriptFramework.Tools.Value(pair.Value)); } foreach (var pair in f.StringParameters) { config.AddSetting(f.Key + "." + pair.Key, new NetScriptFramework.Tools.Value(pair.Value)); } foreach (var pair in f.BoolParameters) { config.AddSetting(f.Key + "." + pair.Key, new NetScriptFramework.Tools.Value(pair.Value)); } } if (!config.Load()) { config.Save(); } foreach (var f in fixes) { var v = config.GetValue(f.Key + ".Enabled"); bool ub; if (v != null && v.TryToBoolean(out ub)) { f.Enabled = ub; } { var map = f.IntParameters; var ls = map.ToList(); foreach (var pair in ls) { string k = f.Key + "." + pair.Key; v = config.GetValue(k); long uv; if (v != null && v.TryToInt64(out uv)) { map[pair.Key] = uv; } } } { var map = f.FloatParameters; var ls = map.ToList(); foreach (var pair in ls) { string k = f.Key + "." + pair.Key; v = config.GetValue(k); double uv; if (v != null && v.TryToDouble(out uv)) { map[pair.Key] = uv; } } } { var map = f.BoolParameters; var ls = map.ToList(); foreach (var pair in ls) { string k = f.Key + "." + pair.Key; v = config.GetValue(k); bool uv; if (v != null && v.TryToBoolean(out uv)) { map[pair.Key] = uv; } } } { var map = f.StringParameters; var ls = map.ToList(); foreach (var pair in ls) { string k = f.Key + "." + pair.Key; v = config.GetValue(k); if (v != null) { map[pair.Key] = v.ToString(); } } } } fixes.Sort((u, v) => u.SortValue.CompareTo(v.SortValue)); foreach (var f in fixes) { if (f.Enabled) { f.Apply(); } } }
/// <summary> /// Initializes the fixes and applies them. /// </summary> /// <param name="parent">The parent plugin.</param> /// <param name="configKeyword">The configuration file keyword.</param> /// <exception cref="System.ArgumentException">Warning: parent.Name fix t.Name does not have valid parameterless constructor!</exception> internal static void init(NetScriptFramework.Plugin parent, string configKeyword) { if (System.Threading.Interlocked.Exchange(ref is_init, 1) != 0) { throw new InvalidOperationException(); } var asm = System.Reflection.Assembly.GetExecutingAssembly(); var types = asm.GetTypes(); foreach (var t in types) { if (t.IsAbstract || !t.IsSubclassOf(typeof(Mod))) { continue; } var cis = t.GetConstructors().Where(q => q.GetParameters().Length == 0).ToList(); if (cis.Count != 1) { throw new ArgumentException("Warning: " + parent.Name + " mod " + t.Name + " does not have valid parameterless constructor!"); } Mod f = (Mod)cis[0].Invoke(new object[0]); mods.Add(f); } var config = new NetScriptFramework.Tools.ConfigFile(configKeyword); foreach (var f in mods) { config.AddSetting(f.Key + ".Enabled", new NetScriptFramework.Tools.Value(f.Enabled), null, f.Description); foreach (var okey in f.OrderOfParams) { long val_i; double val_f; string val_s; bool val_b; if (f.IntParameters.TryGetValue(okey, out val_i)) { string cmt = null; f.ParameterComments.TryGetValue(okey, out cmt); NetScriptFramework.Tools.ConfigEntryFlags fl = !string.IsNullOrEmpty(cmt) ? NetScriptFramework.Tools.ConfigEntryFlags.VeryShortComment : NetScriptFramework.Tools.ConfigEntryFlags.NoNewLineBefore; config.AddSetting(f.Key + "." + okey, new NetScriptFramework.Tools.Value(val_i), null, cmt, fl); } if (f.FloatParameters.TryGetValue(okey, out val_f)) { string cmt = null; f.ParameterComments.TryGetValue(okey, out cmt); NetScriptFramework.Tools.ConfigEntryFlags fl = !string.IsNullOrEmpty(cmt) ? NetScriptFramework.Tools.ConfigEntryFlags.VeryShortComment : NetScriptFramework.Tools.ConfigEntryFlags.NoNewLineBefore; config.AddSetting(f.Key + "." + okey, new NetScriptFramework.Tools.Value(val_f), null, cmt, fl); } if (f.StringParameters.TryGetValue(okey, out val_s)) { string cmt = null; f.ParameterComments.TryGetValue(okey, out cmt); NetScriptFramework.Tools.ConfigEntryFlags fl = !string.IsNullOrEmpty(cmt) ? NetScriptFramework.Tools.ConfigEntryFlags.VeryShortComment : NetScriptFramework.Tools.ConfigEntryFlags.NoNewLineBefore; config.AddSetting(f.Key + "." + okey, new NetScriptFramework.Tools.Value(val_s), null, cmt, fl); } if (f.BoolParameters.TryGetValue(okey, out val_b)) { string cmt = null; f.ParameterComments.TryGetValue(okey, out cmt); NetScriptFramework.Tools.ConfigEntryFlags fl = !string.IsNullOrEmpty(cmt) ? NetScriptFramework.Tools.ConfigEntryFlags.VeryShortComment : NetScriptFramework.Tools.ConfigEntryFlags.NoNewLineBefore; config.AddSetting(f.Key + "." + okey, new NetScriptFramework.Tools.Value(val_b), null, cmt, fl); } } foreach (var pair in f.IntParameters) { if (f.OrderOfParams.Contains(pair.Key)) { continue; } string cmt = null; f.ParameterComments.TryGetValue(pair.Key, out cmt); NetScriptFramework.Tools.ConfigEntryFlags fl = !string.IsNullOrEmpty(cmt) ? NetScriptFramework.Tools.ConfigEntryFlags.VeryShortComment : NetScriptFramework.Tools.ConfigEntryFlags.NoNewLineBefore; config.AddSetting(f.Key + "." + pair.Key, new NetScriptFramework.Tools.Value(pair.Value), null, cmt, fl); } foreach (var pair in f.FloatParameters) { if (f.OrderOfParams.Contains(pair.Key)) { continue; } string cmt = null; f.ParameterComments.TryGetValue(pair.Key, out cmt); NetScriptFramework.Tools.ConfigEntryFlags fl = !string.IsNullOrEmpty(cmt) ? NetScriptFramework.Tools.ConfigEntryFlags.VeryShortComment : NetScriptFramework.Tools.ConfigEntryFlags.NoNewLineBefore; config.AddSetting(f.Key + "." + pair.Key, new NetScriptFramework.Tools.Value(pair.Value), null, cmt, fl); } foreach (var pair in f.StringParameters) { if (f.OrderOfParams.Contains(pair.Key)) { continue; } string cmt = null; f.ParameterComments.TryGetValue(pair.Key, out cmt); NetScriptFramework.Tools.ConfigEntryFlags fl = !string.IsNullOrEmpty(cmt) ? NetScriptFramework.Tools.ConfigEntryFlags.VeryShortComment : NetScriptFramework.Tools.ConfigEntryFlags.NoNewLineBefore; config.AddSetting(f.Key + "." + pair.Key, new NetScriptFramework.Tools.Value(pair.Value), null, cmt, fl); } foreach (var pair in f.BoolParameters) { if (f.OrderOfParams.Contains(pair.Key)) { continue; } string cmt = null; f.ParameterComments.TryGetValue(pair.Key, out cmt); NetScriptFramework.Tools.ConfigEntryFlags fl = !string.IsNullOrEmpty(cmt) ? NetScriptFramework.Tools.ConfigEntryFlags.VeryShortComment : NetScriptFramework.Tools.ConfigEntryFlags.NoNewLineBefore; config.AddSetting(f.Key + "." + pair.Key, new NetScriptFramework.Tools.Value(pair.Value), null, cmt, fl); } } if (!config.Load()) { config.Save(); } foreach (var f in mods) { var v = config.GetValue(f.Key + ".Enabled"); bool ub; if (v != null && v.TryToBoolean(out ub)) { f.Enabled = ub; } { var map = f.IntParameters; var ls = map.ToList(); foreach (var pair in ls) { string k = f.Key + "." + pair.Key; v = config.GetValue(k); long uv; if (v != null && v.TryToInt64(out uv)) { map[pair.Key] = uv; } } } { var map = f.FloatParameters; var ls = map.ToList(); foreach (var pair in ls) { string k = f.Key + "." + pair.Key; v = config.GetValue(k); double uv; if (v != null && v.TryToDouble(out uv)) { map[pair.Key] = uv; } } } { var map = f.BoolParameters; var ls = map.ToList(); foreach (var pair in ls) { string k = f.Key + "." + pair.Key; v = config.GetValue(k); bool uv; if (v != null && v.TryToBoolean(out uv)) { map[pair.Key] = uv; } } } { var map = f.StringParameters; var ls = map.ToList(); foreach (var pair in ls) { string k = f.Key + "." + pair.Key; v = config.GetValue(k); if (v != null) { map[pair.Key] = v.ToString(); } } } } mods.Sort((u, v) => u.SortValue.CompareTo(v.SortValue)); foreach (var f in mods) { if (f.Enabled) { f.Apply(); } } }