From b713bf476fad042ed02f6363cfaad94a8fc9ad55 Mon Sep 17 00:00:00 2001 From: patel-nikhil Date: Mon, 6 Dec 2021 20:23:55 -0500 Subject: [PATCH 1/7] Add view for balance change type --- .../Balance/BalanceChange.cs | 244 ++++++++++++++++++ .../Balance/BalanceView.cs | 72 ++++++ UnofficialCrusaderPatch/Configuration.cs | 12 + .../Localization/Arabic.txt | 5 + .../Localization/Chinese.txt | 5 + .../Localization/English.txt | 5 + .../Localization/German.txt | 5 + .../Localization/Hungarian.txt | 5 + .../Localization/Polish.txt | 5 + .../Localization/Russian.txt | 5 + .../Patching/Changes/ChangeType.cs | 1 + .../UnofficialCrusaderPatch.csproj | 2 + UnofficialCrusaderPatchGUI/MainWindow.xaml.cs | 7 + 13 files changed, 373 insertions(+) create mode 100644 UnofficialCrusaderPatch/Balance/BalanceChange.cs create mode 100644 UnofficialCrusaderPatch/Balance/BalanceView.cs diff --git a/UnofficialCrusaderPatch/Balance/BalanceChange.cs b/UnofficialCrusaderPatch/Balance/BalanceChange.cs new file mode 100644 index 00000000..d2c4d166 --- /dev/null +++ b/UnofficialCrusaderPatch/Balance/BalanceChange.cs @@ -0,0 +1,244 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Web.Script.Serialization; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Media; +using UCP.Patching; + +namespace UCP.Balance +{ + public class BalanceChange : Change + { + string description; + bool IsValid = true; + + public static BalanceChange activeChange = null; + + public static List changes = new List(); + public static TreeView View; + + private static string selectedChange = String.Empty; + + public BalanceChange(string title, bool enabledDefault = false, bool isIntern = false) + : base("bal_" + title, ChangeType.Balance, enabledDefault, false) + { + this.NoLocalization = true; + } + + public override void InitUI() + { + Localization.Add(this.TitleIdent + "_descr", this.description); + base.InitUI(); + if (this.IsChecked) + { + activeChange = this; + } + ((TextBlock)this.titleBox.Content).Text = this.TitleIdent.Substring(4); + + if (this.IsValid == false) + { + ((TextBlock)this.titleBox.Content).TextDecorations = TextDecorations.Strikethrough; + this.titleBox.IsEnabled = false; + this.titleBox.ToolTip = this.description; + ((TextBlock)this.titleBox.Content).Foreground = new SolidColorBrush(Color.FromRgb(255, 0, 0)); + } + else + { + this.titleBox.IsChecked = selectedChange.Equals(this.TitleIdent); + } + this.titleBox.Background = new SolidColorBrush(Colors.White); + } + + protected override void TitleBox_Checked(object sender, RoutedEventArgs e) + { + base.TitleBox_Checked(sender, e); + + if (activeChange != null) + activeChange.IsChecked = false; + + selectedChange = this.TitleIdent; + activeChange = this; + } + + protected override void TitleBox_Unchecked(object sender, RoutedEventArgs e) + { + base.TitleBox_Unchecked(sender, e); + + if (activeChange == this) + { + activeChange = null; + selectedChange = String.Empty; + } + } + + static BalanceChange() {} + + public static void LoadConfiguration(List configuration = null) + { + if (configuration == null) + { + return; + } + + foreach (string change in configuration) + { + string[] changeLine = change.Split(new char[] { '=' }, 2, StringSplitOptions.RemoveEmptyEntries).Select(str => str.Trim()).ToArray(); + if (changeLine.Length < 2) + { + continue; + } + + string changeKey = changeLine[0]; + string changeSetting = changeLine[1]; + + bool selected = Regex.Replace(@"\s+", "", changeSetting.Split('=')[1]).Contains("True"); + if (selected == true) + { + selectedChange = changeKey; + } + } + } + + /// + /// Load built-in vanilla starting balance file and user-provided JSON balance files located in resources\balances subfolder + /// + public static void Load() + { + JavaScriptSerializer serializer = new JavaScriptSerializer(); + if (!Directory.Exists(Path.Combine(Environment.CurrentDirectory, "resources", "balances"))) + { + return; + } + + foreach (string file in Directory.EnumerateFiles(Path.Combine(Environment.CurrentDirectory, "resources", "balances"), "*.json", SearchOption.TopDirectoryOnly)) + { + StreamReader reader = new StreamReader(new FileStream(file, FileMode.Open), Encoding.UTF8); + string balanceText = reader.ReadToEnd(); + reader.Close(); + + Dictionary> balanceConfig; + try + { + balanceConfig = serializer.Deserialize>>(balanceText); + } + catch (Exception) + { + CreateNullChange(Path.GetFileNameWithoutExtension(file), "Invalid JSON detected"); + continue; + } + + try + { + string description = GetLocalizedDescription(file, balanceConfig); + BalanceChange change = new BalanceChange(Path.GetFileNameWithoutExtension(file), false) + { + CreateBalanceHeader("bal_" + Path.GetFileNameWithoutExtension(file), balanceConfig), + }; + change.description = description; + changes.Add(change); + } + catch (Exception e) + { + CreateNullChange(Path.GetFileNameWithoutExtension(file), e.Message); + } + } + } + + public static void Refresh(object sender, RoutedEventArgs args) + { + changes.Clear(); + Load(); + + Version.RemoveChanges(ChangeType.Balance); + Version.Changes.AddRange(changes); + } + + static String GetLocalizedDescription(String file, Dictionary> balanceConfig) + { + String description = file; + string currentLang = Localization.Translations.ToArray()[Configuration.Language].Ident; + try + { + description = balanceConfig["description"][currentLang].ToString(); + } + catch (Exception) + { + foreach (var lang in Localization.Translations) + { + try + { + description = balanceConfig["description"][lang.Ident].ToString(); + break; + } + catch (Exception) + { + continue; + } + } + } + if (!description.Equals(file)) + { + description = description.Substring(0, Math.Min(description.Length, 1000)); + } + return description; + } + + + static void CreateNullChange(string file, string message) + { + BalanceChange change = new BalanceChange(Path.GetFileNameWithoutExtension(file).Replace(" ", ""), false) + { + }; + change.description = message; + change.IsValid = false; + changes.Add(change); + } + + + #region Binary Edit + + internal static void DoChange(ChangeArgs args) + { + Change change = activeChange; + if (!selectedChange.Equals(String.Empty)) + { + if (activeChange == null) + { + change = changes.Where(x => x.TitleIdent.Equals(selectedChange)).First(); + foreach (var header in change) + { + header.Activate(args); + } + return; + } + foreach (var header in change) + { + header.Activate(args); + } + return; + } + } + + static DefaultHeader CreateBalanceHeader(String file, Dictionary> balanceConfig) + { + try + { + return new DefaultHeader(file, true) + { + }; + } + catch (Exception e) + { + throw new Exception("Errors found in " + file + ":\n" + e.Message); + } + } + + #endregion + + } +} diff --git a/UnofficialCrusaderPatch/Balance/BalanceView.cs b/UnofficialCrusaderPatch/Balance/BalanceView.cs new file mode 100644 index 00000000..dae68d79 --- /dev/null +++ b/UnofficialCrusaderPatch/Balance/BalanceView.cs @@ -0,0 +1,72 @@ +using System; +using System.Linq; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Media.Imaging; + +namespace UCP.Balance +{ + public class BalanceView + { + public void InitUI(Grid grid, RoutedPropertyChangedEventHandler SelectionDisabler) + { + TreeView view = new TreeView() + { + Background = null, + BorderThickness = new Thickness(0, 0, 0, 0), + Focusable = false, + Name = "BalanceView" + }; + view.SelectedItemChanged += SelectionDisabler; + + foreach (BalanceChange change in BalanceChange.changes) + { + change.InitUI(); + view.Items.Add(change.UIElement); + } + grid.Children.Add(view); + Button button = new Button + { + ToolTip = "Reload configs", + Width = 20, + Height = 20, + HorizontalAlignment = HorizontalAlignment.Right, + VerticalAlignment = VerticalAlignment.Bottom, + Margin = new Thickness(0, 0, 20, 5), + Content = new Image() + { + Source = new BitmapImage(new Uri("pack://application:,,,/UnofficialCrusaderPatchGUI;component/Graphics/refresh.png")), + } + }; + grid.Children.Add(button); + button.Click += (s, e) => Refresh(s, e, view); + } + + private void Refresh(object s, RoutedEventArgs e, TreeView view) + { + String activeChange = BalanceChange.activeChange == null ? String.Empty : BalanceChange.activeChange.TitleIdent; + for (int i = 0; i < BalanceChange.changes.Count; i++) + { + view.Items.Remove(BalanceChange.changes.ElementAt(i).UIElement); + Localization.Remove(BalanceChange.changes.ElementAt(i) + "_descr"); + } + BalanceChange.Refresh(s, e); + foreach (BalanceChange change in BalanceChange.changes) + { + change.InitUI(); + view.Items.Add(change.UIElement); + } + + if (BalanceChange.changes.Select(x => x.TitleIdent).Contains(activeChange)) + { + foreach (BalanceChange change in BalanceChange.changes) + { + if (change.TitleIdent == activeChange) + { + change.IsChecked = true; + } + } + } + } + } +} diff --git a/UnofficialCrusaderPatch/Configuration.cs b/UnofficialCrusaderPatch/Configuration.cs index 091c6298..d0317cc9 100644 --- a/UnofficialCrusaderPatch/Configuration.cs +++ b/UnofficialCrusaderPatch/Configuration.cs @@ -5,6 +5,7 @@ using System.Text.RegularExpressions; using UCP.AIC; using UCP.AIV; +using UCP.Balance; using UCP.Patching; using UCP.Startup; @@ -89,6 +90,7 @@ public static void Load(bool changesOnly = false) { List aicConfigurationList = null; List aivConfigurationList = null; + List balanceConfigurationList = null; List resourceConfigurationList = null; List startTroopConfigurationList = null; if (File.Exists(ConfigFile)) @@ -119,6 +121,15 @@ proceed to load generic change configurations */ aivConfigurationList.Add(line); continue; } + else if (Regex.Replace(@"\s+", "", line).StartsWith("bal_")) + { + if (balanceConfigurationList == null) + { + balanceConfigurationList = new List(); + } + balanceConfigurationList.Add(line); + continue; + } else if (Regex.Replace(@"\s+", "", line).StartsWith("res_")) { if (resourceConfigurationList == null) @@ -182,6 +193,7 @@ proceed to load generic change configurations */ // Calls change modules to set their selections based on the provided configuration list AICChange.LoadConfiguration(aicConfigurationList); AIVChange.LoadConfiguration(aivConfigurationList); + BalanceChange.LoadConfiguration(balanceConfigurationList); ResourceChange.LoadConfiguration(resourceConfigurationList); StartTroopChange.LoadConfiguration(startTroopConfigurationList); } diff --git a/UnofficialCrusaderPatch/Localization/Arabic.txt b/UnofficialCrusaderPatch/Localization/Arabic.txt index 53331f23..1fbf60e2 100644 --- a/UnofficialCrusaderPatch/Localization/Arabic.txt +++ b/UnofficialCrusaderPatch/Localization/Arabic.txt @@ -2,6 +2,11 @@ // DEV // ====================== +ui_Balance +{ +"Balance" +} + ai_resources_rebuy { "Improve AI restocking of needed goods" diff --git a/UnofficialCrusaderPatch/Localization/Chinese.txt b/UnofficialCrusaderPatch/Localization/Chinese.txt index 3e8a80d0..f69786bf 100644 --- a/UnofficialCrusaderPatch/Localization/Chinese.txt +++ b/UnofficialCrusaderPatch/Localization/Chinese.txt @@ -2,6 +2,11 @@ // DEV // ====================== +ui_Balance +{ +"Balance" +} + ai_resources_rebuy { "Improve AI restocking of needed goods" diff --git a/UnofficialCrusaderPatch/Localization/English.txt b/UnofficialCrusaderPatch/Localization/English.txt index 64f8881e..d0c01d8b 100644 --- a/UnofficialCrusaderPatch/Localization/English.txt +++ b/UnofficialCrusaderPatch/Localization/English.txt @@ -2,6 +2,11 @@ // DEV // ====================== +ui_Balance +{ +"Balance" +} + ai_resources_rebuy { "Improve AI restocking of needed goods" diff --git a/UnofficialCrusaderPatch/Localization/German.txt b/UnofficialCrusaderPatch/Localization/German.txt index dbabab2c..f060b192 100644 --- a/UnofficialCrusaderPatch/Localization/German.txt +++ b/UnofficialCrusaderPatch/Localization/German.txt @@ -2,6 +2,11 @@ // DEV // ====================== +ui_Balance +{ +"Balance" +} + ai_resources_rebuy { "Improve AI restocking of needed goods" diff --git a/UnofficialCrusaderPatch/Localization/Hungarian.txt b/UnofficialCrusaderPatch/Localization/Hungarian.txt index 5f23e177..aedae619 100644 --- a/UnofficialCrusaderPatch/Localization/Hungarian.txt +++ b/UnofficialCrusaderPatch/Localization/Hungarian.txt @@ -2,6 +2,11 @@ // DEV // ====================== +ui_Balance +{ +"Balance" +} + ai_resources_rebuy { "Improve AI restocking of needed goods" diff --git a/UnofficialCrusaderPatch/Localization/Polish.txt b/UnofficialCrusaderPatch/Localization/Polish.txt index fed4dc6f..a8b3514f 100644 --- a/UnofficialCrusaderPatch/Localization/Polish.txt +++ b/UnofficialCrusaderPatch/Localization/Polish.txt @@ -2,6 +2,11 @@ // DEV // ====================== +ui_Balance +{ +"Balance" +} + ai_resources_rebuy { "Improve AI restocking of needed goods" diff --git a/UnofficialCrusaderPatch/Localization/Russian.txt b/UnofficialCrusaderPatch/Localization/Russian.txt index 91e7ed92..16e424b1 100644 --- a/UnofficialCrusaderPatch/Localization/Russian.txt +++ b/UnofficialCrusaderPatch/Localization/Russian.txt @@ -2,6 +2,11 @@ // DEV // ====================== +ui_Balance +{ +"Balance" +} + ai_resources_rebuy { "Improve AI restocking of needed goods" diff --git a/UnofficialCrusaderPatch/Patching/Changes/ChangeType.cs b/UnofficialCrusaderPatch/Patching/Changes/ChangeType.cs index 6dc09226..b93e97bc 100644 --- a/UnofficialCrusaderPatch/Patching/Changes/ChangeType.cs +++ b/UnofficialCrusaderPatch/Patching/Changes/ChangeType.cs @@ -6,6 +6,7 @@ public enum ChangeType AILords, Troops, Other, + Balance, AIV, AIC, Resource, diff --git a/UnofficialCrusaderPatch/UnofficialCrusaderPatch.csproj b/UnofficialCrusaderPatch/UnofficialCrusaderPatch.csproj index 231d90ca..c8ab799f 100644 --- a/UnofficialCrusaderPatch/UnofficialCrusaderPatch.csproj +++ b/UnofficialCrusaderPatch/UnofficialCrusaderPatch.csproj @@ -95,6 +95,8 @@ + + diff --git a/UnofficialCrusaderPatchGUI/MainWindow.xaml.cs b/UnofficialCrusaderPatchGUI/MainWindow.xaml.cs index a4db87c3..e24eb5d2 100644 --- a/UnofficialCrusaderPatchGUI/MainWindow.xaml.cs +++ b/UnofficialCrusaderPatchGUI/MainWindow.xaml.cs @@ -13,6 +13,7 @@ using System.Windows.Media.Imaging; using UCP; using UCP.AIV; +using UCP.Balance; using UCP.Patching; using UCP.Startup; using UCP.AIC; @@ -73,6 +74,7 @@ public MainWindow() } StartTroopChange.Load(); ResourceChange.Load(); + BalanceChange.Load(); Version.AddExternalChanges(); // init main window @@ -299,6 +301,11 @@ void FillTreeView(IEnumerable changes) new StartTroopView().InitUI(grid, View_SelectedItemChanged); continue; } + else if (type == ChangeType.Balance) + { + new BalanceView().InitUI(grid, View_SelectedItemChanged); + continue; + } TreeView view = new TreeView() { From ffb6e65df559f958a67ef27d046daac8619c8ba0 Mon Sep 17 00:00:00 2001 From: patel-nikhil Date: Tue, 7 Dec 2021 02:04:52 -0500 Subject: [PATCH 2/7] Add stub code --- .../Balance/BalanceChange.cs | 7 +- .../Balance/BalanceConfig.cs | 16 ++ .../Balance/BalanceEnums.cs | 229 ++++++++++++++++++ .../Balance/BalanceHelper.cs | 96 ++++++++ 4 files changed, 346 insertions(+), 2 deletions(-) create mode 100644 UnofficialCrusaderPatch/Balance/BalanceConfig.cs create mode 100644 UnofficialCrusaderPatch/Balance/BalanceEnums.cs create mode 100644 UnofficialCrusaderPatch/Balance/BalanceHelper.cs diff --git a/UnofficialCrusaderPatch/Balance/BalanceChange.cs b/UnofficialCrusaderPatch/Balance/BalanceChange.cs index d2c4d166..735ffc11 100644 --- a/UnofficialCrusaderPatch/Balance/BalanceChange.cs +++ b/UnofficialCrusaderPatch/Balance/BalanceChange.cs @@ -228,9 +228,12 @@ static DefaultHeader CreateBalanceHeader(String file, Dictionary description; + Dictionary buildings; + Dictionary units; + Dictionary resources; + Dictionary siege; + } +} diff --git a/UnofficialCrusaderPatch/Balance/BalanceEnums.cs b/UnofficialCrusaderPatch/Balance/BalanceEnums.cs new file mode 100644 index 00000000..db36480b --- /dev/null +++ b/UnofficialCrusaderPatch/Balance/BalanceEnums.cs @@ -0,0 +1,229 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace UCP.Balance +{ + public class BalanceEnums + { + public List buildingNames = new List() + { + "Hovel", + "House", + "Woodcutter hut", + "Ox tether", + "Iron mine", + "Pitch rig", + "Hunters hut", + "Mercenary post", + "Barracks", + "Stockpile", + "Armory", + "Fletcher", + "Blacksmith", + "Poleturner", + "Armourer", + "Tanner", + "Bakery", + "Brewery", + "Granary", + "Quarry", + "Quarrypile", + "Inn", + "Apothecary", + "Engineers guild", + "Tunnelers guild", + "Marketplace", + "Well", + "Oil smelter", + "Siege tent", + "Wheat farm", + "Hop farm", + "Apple farm", + "Dairy farm", + "Mill", + "Stables", + "Chapel", + "Church", + "Cathedral", + "Ruins", + "Keep one", + "Keep two", + "Keep three", + "Keep four", + "Keep five", + "Large gatehouse", + "Small gatehouse", + "Main wood", + "Postern gate", + "Drawbridge", + "Tunnel", + "Campfire", + "Signpost", + "Parade ground", + "Fire ballista", + "Campground", + "Parade ground", + "Parade ground", + "Parade ground", + "Parade ground", + "Gatehouse", + "Tower", + "Gallows", + "Stocks", + "Witch hoist", + "Maypole", + "Garden", + "Killing pit", + "Pitch ditch", + "unused", + "Water pot", + "Keepdoor left", + "Keepdoor right", + "Keepdoor", + "Tower one", + "Tower two", + "Tower three", + "Tower four", + "Tower five", + "unused2", + "Catapult", + "Trebuchet", + "Siege tower", + "Battering ram", + "Portable shield", + "unused3", + "Mangonel", + "Tower Ballista", + "unused4", + "unused5", + "unused6", + "Cesspit", + "Burning stake", + "Gibbet", + "Dungeon", + "Stretching rack", + "Flogging rack", + "Chopping block", + "Dunking stool", + "Dog cage", + "Statue", + "Shrine", + "Bee hive", + "Dancing bear", + "Pond", + "Bear cave", + "European Outpost", + "Mercenary Outpost" + }; + + public List unitNames = new List() + { + "Peasant", + "Burning man", + "Woodcutter", + "Fletcher", + "Tunneler", + "Hunter", + "Quarry mason", + "Quarry grunt", + "Quarry ox", + "Pitch worker", + "Wheat farmer", + "Hops farmer", + "Apple farmer", + "Dairy farmer", + "Miller", + "Baker", + "Brewer", + "Poleturner", + "Blacksmith", + "Armourer", + "Tanner", + "European archer", + "European crossbowman", + "European spearman", + "European pikeman", + "European maceman", + "European swordsman", + "European knight", + "Ladderman", + "Engineer", + "Iron miner1", + "Iron miner2", + "Priest", + "Healer", + "Drunkard", + "Innkeeper", + "Monk", + "unknown1", + "Catapult", + "Trebuchet", + "Mangonel", + "Trader", + "Trader horse", + "Deer", + "Lion", + "Rabbit", + "Camel", + "Crow", + "Seagull", + "Siege tent", + "Cow", + "Hunter dog", + "Fireman", + "Ghost", + "Lord", + "Lady", + "Jester", + "Siege tower", + "Battering ram", + "Portable shield", + "Tower ballista", + "Chicken", + "Mother", + "Child", + "Juggler", + "Fireeater", + "Dog", + "unknown2", + "unknown3", + "Arabian archer", + "Arabian slave", + "Arabian slinger", + "Arabian assassin", + "Arabian horse archer", + "Arabian swordsman", + "Arabian firethrower", + "Fire ballista" + }; + + public List resourceNames = new List() + { + "Wood", + "Hop", + "Stone", + "Blank1", + "Iron", + "Pitch", + "Blank2", + "Wheat", + "Bread", + "Cheese", + "Meat", + "Fruit", + "Beer", + "Blank3", + "Flour", + "Bow", + "Xbow", + "Spear", + "Pike", + "Mace", + "Sword", + "Leather", + "Armor" + }; + } +} diff --git a/UnofficialCrusaderPatch/Balance/BalanceHelper.cs b/UnofficialCrusaderPatch/Balance/BalanceHelper.cs new file mode 100644 index 00000000..22566f86 --- /dev/null +++ b/UnofficialCrusaderPatch/Balance/BalanceHelper.cs @@ -0,0 +1,96 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using UCP.Patching; + +namespace UCP.Balance +{ + class BalanceHelper + { + public static ChangeEdit[] GetBinaryEdits(Dictionary> balanceConfig) + { + List editList = new List(); + + ChangeEdit buildingCostEdit = GetBuildingCostEdit(); + ChangeEdit buildingHealthEdit = GetBuildingHealthEdit(); + ChangeEdit unitHealthEdit = GetUnitHealthEdit(); + ChangeEdit unitArrowDmgEdit = GetUnitArrowDmgEdit(); + ChangeEdit unitXbowDmgEdit = GetUnitXbowDmgEdit(); + ChangeEdit unitStoneDmgEdit = GetUnitStoneDmgEdit(); + ChangeEdit unitMeleeDmgEdit = GetUnitMeleeDmgEdit(); + + if (buildingCostEdit != null) + { + editList.Add(buildingCostEdit); + } + + if (buildingHealthEdit != null) + { + editList.Add(buildingHealthEdit); + } + + if (unitHealthEdit != null) + { + editList.Add(unitHealthEdit); + } + + if (unitArrowDmgEdit != null) + { + editList.Add(unitArrowDmgEdit); + } + + if (unitMeleeDmgEdit != null) + { + editList.Add(unitMeleeDmgEdit); + } + + if (unitStoneDmgEdit != null) + { + editList.Add(unitStoneDmgEdit); + } + + if (unitXbowDmgEdit != null) + { + editList.Add(unitXbowDmgEdit); + } + + return editList.ToArray(); + } + + private static ChangeEdit GetUnitMeleeDmgEdit() + { + throw new NotImplementedException(); + } + + private static ChangeEdit GetUnitStoneDmgEdit() + { + throw new NotImplementedException(); + } + + private static ChangeEdit GetUnitXbowDmgEdit() + { + throw new NotImplementedException(); + } + + private static ChangeEdit GetUnitArrowDmgEdit() + { + throw new NotImplementedException(); + } + + private static ChangeEdit GetUnitHealthEdit() + { + throw new NotImplementedException(); + } + + private static ChangeEdit GetBuildingHealthEdit() + { + throw new NotImplementedException(); + } + + private static ChangeEdit GetBuildingCostEdit() + { + throw new NotImplementedException(); + } + } +} From 5628491eb7a00df9e78b6a0f6c9dcc744b13f594 Mon Sep 17 00:00:00 2001 From: patel-nikhil Date: Tue, 7 Dec 2021 23:11:15 -0500 Subject: [PATCH 3/7] Add AOBs for base stats and define BalanceConfig structure --- .../Balance/BalanceChange.cs | 14 ++++---- .../Balance/BalanceConfig.cs | 33 ++++++++++++++++--- .../Balance/BalanceHelper.cs | 2 +- .../CodeBlocks/bal_building_health.block | 1 + .../CodeBlocks/bal_resource_buy.block | 1 + .../CodeBlocks/bal_resource_sell.block | 1 + .../CodeBlocks/bal_unit_arrowdmg.block | 1 + .../CodeBlocks/bal_unit_health.block | 1 + .../CodeBlocks/bal_unit_meleedmg.block | 1 + .../CodeBlocks/bal_unit_stonedmg.block | 1 + .../CodeBlocks/bal_unit_xbowdmg.block | 1 + .../UnofficialCrusaderPatch.csproj | 3 ++ 12 files changed, 47 insertions(+), 13 deletions(-) create mode 100644 UnofficialCrusaderPatch/CodeBlocks/bal_building_health.block create mode 100644 UnofficialCrusaderPatch/CodeBlocks/bal_resource_buy.block create mode 100644 UnofficialCrusaderPatch/CodeBlocks/bal_resource_sell.block create mode 100644 UnofficialCrusaderPatch/CodeBlocks/bal_unit_arrowdmg.block create mode 100644 UnofficialCrusaderPatch/CodeBlocks/bal_unit_health.block create mode 100644 UnofficialCrusaderPatch/CodeBlocks/bal_unit_meleedmg.block create mode 100644 UnofficialCrusaderPatch/CodeBlocks/bal_unit_stonedmg.block create mode 100644 UnofficialCrusaderPatch/CodeBlocks/bal_unit_xbowdmg.block diff --git a/UnofficialCrusaderPatch/Balance/BalanceChange.cs b/UnofficialCrusaderPatch/Balance/BalanceChange.cs index 735ffc11..754f71cf 100644 --- a/UnofficialCrusaderPatch/Balance/BalanceChange.cs +++ b/UnofficialCrusaderPatch/Balance/BalanceChange.cs @@ -121,12 +121,12 @@ public static void Load() string balanceText = reader.ReadToEnd(); reader.Close(); - Dictionary> balanceConfig; + BalanceConfig balanceConfig; try { - balanceConfig = serializer.Deserialize>>(balanceText); + balanceConfig = serializer.Deserialize(balanceText); } - catch (Exception) + catch (Exception e) { CreateNullChange(Path.GetFileNameWithoutExtension(file), "Invalid JSON detected"); continue; @@ -158,13 +158,13 @@ public static void Refresh(object sender, RoutedEventArgs args) Version.Changes.AddRange(changes); } - static String GetLocalizedDescription(String file, Dictionary> balanceConfig) + static String GetLocalizedDescription(String file, BalanceConfig balanceConfig) { String description = file; string currentLang = Localization.Translations.ToArray()[Configuration.Language].Ident; try { - description = balanceConfig["description"][currentLang].ToString(); + description = balanceConfig.description[currentLang].ToString(); } catch (Exception) { @@ -172,7 +172,7 @@ static String GetLocalizedDescription(String file, Dictionary> balanceConfig) + static DefaultHeader CreateBalanceHeader(String file, BalanceConfig balanceConfig) { try { diff --git a/UnofficialCrusaderPatch/Balance/BalanceConfig.cs b/UnofficialCrusaderPatch/Balance/BalanceConfig.cs index 22ef5504..0087ef87 100644 --- a/UnofficialCrusaderPatch/Balance/BalanceConfig.cs +++ b/UnofficialCrusaderPatch/Balance/BalanceConfig.cs @@ -7,10 +7,33 @@ namespace UCP.Balance { public class BalanceConfig { - Dictionary description; - Dictionary buildings; - Dictionary units; - Dictionary resources; - Dictionary siege; + public class BuildingConfig + { + public int[] cost; + public int health; + } + + public class UnitConfig + { + public int health; + public int arrowDamage; + public int xbowDamage; + public int stoneDamage; + public Dictionary meleeDamageVs; + } + + public class ResourceConfig + { + public int buy; + public int sell; + } + + public Dictionary description; + public Dictionary buildings; + public Dictionary units; + public Dictionary resources; + public Dictionary siege; + + public BalanceConfig() { } } } diff --git a/UnofficialCrusaderPatch/Balance/BalanceHelper.cs b/UnofficialCrusaderPatch/Balance/BalanceHelper.cs index 22566f86..03ebba59 100644 --- a/UnofficialCrusaderPatch/Balance/BalanceHelper.cs +++ b/UnofficialCrusaderPatch/Balance/BalanceHelper.cs @@ -8,7 +8,7 @@ namespace UCP.Balance { class BalanceHelper { - public static ChangeEdit[] GetBinaryEdits(Dictionary> balanceConfig) + public static ChangeEdit[] GetBinaryEdits(BalanceConfig balanceConfig) { List editList = new List(); diff --git a/UnofficialCrusaderPatch/CodeBlocks/bal_building_health.block b/UnofficialCrusaderPatch/CodeBlocks/bal_building_health.block new file mode 100644 index 00000000..4900b4f1 --- /dev/null +++ b/UnofficialCrusaderPatch/CodeBlocks/bal_building_health.block @@ -0,0 +1 @@ +64 00 00 00 64 00 00 00 64 00 00 00 64 00 00 00 64 00 00 00 64 00 00 00 64 00 00 00 2C 01 00 00 F4 01 00 00 F4 01 00 00 F4 01 00 00 2C 01 00 00 2C 01 00 00 2C 01 00 00 2C 01 00 00 2C 01 00 00 2C 01 00 00 2C 01 00 00 2C 01 00 00 2C 01 00 00 00 00 00 00 2C 01 00 00 2C 01 00 00 F4 01 00 00 F4 01 00 00 2C 01 00 00 2C 01 00 00 2C 01 00 00 00 00 00 00 64 00 00 00 64 00 00 00 64 00 00 00 64 00 00 00 2C 01 00 00 2C 01 00 00 90 01 00 00 20 03 00 00 B0 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 D0 07 00 00 E8 03 00 00 C8 00 00 00 00 00 00 00 00 00 00 00 64 00 00 00 F4 01 00 00 00 00 00 00 F4 01 00 00 64 00 00 00 F4 01 00 00 F4 01 00 00 F4 01 00 00 F4 01 00 00 F4 01 00 00 00 00 00 00 00 00 00 00 64 00 00 00 64 00 00 00 64 00 00 00 64 00 00 00 64 00 00 00 00 00 00 00 00 00 00 00 E8 03 00 00 C8 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FA 00 00 00 E8 03 00 00 B0 04 00 00 40 06 00 00 D0 07 00 00 64 00 00 00 64 00 00 00 64 00 00 00 64 00 00 00 64 00 00 00 64 00 00 00 00 00 00 00 64 00 00 00 64 00 00 00 64 00 00 00 64 00 00 00 64 00 00 00 64 00 00 00 64 00 00 00 64 00 00 00 64 00 00 00 64 00 00 00 64 00 00 00 64 00 00 00 64 00 00 00 64 00 00 00 64 00 00 00 64 00 00 00 64 00 00 00 64 00 00 00 64 00 00 00 64 00 00 00 DC 05 00 00 DC 05 00 00 64 00 00 00 64 00 00 00 \ No newline at end of file diff --git a/UnofficialCrusaderPatch/CodeBlocks/bal_resource_buy.block b/UnofficialCrusaderPatch/CodeBlocks/bal_resource_buy.block new file mode 100644 index 00000000..edba12c2 --- /dev/null +++ b/UnofficialCrusaderPatch/CodeBlocks/bal_resource_buy.block @@ -0,0 +1 @@ +14 00 00 00 4B 00 00 00 46 00 00 00 00 00 00 00 E1 00 00 00 64 00 00 00 64 00 00 00 73 00 00 00 28 00 00 00 28 00 00 00 28 00 00 00 28 00 00 00 64 00 00 00 00 00 00 00 A0 00 00 00 9B 00 00 00 22 01 00 00 64 00 00 00 B4 00 00 00 22 01 00 00 22 01 00 00 7D 00 00 00 22 01 00 00 \ No newline at end of file diff --git a/UnofficialCrusaderPatch/CodeBlocks/bal_resource_sell.block b/UnofficialCrusaderPatch/CodeBlocks/bal_resource_sell.block new file mode 100644 index 00000000..bdca434c --- /dev/null +++ b/UnofficialCrusaderPatch/CodeBlocks/bal_resource_sell.block @@ -0,0 +1 @@ +05 00 00 00 28 00 00 00 23 00 00 00 00 00 00 00 73 00 00 00 32 00 00 00 32 00 00 00 28 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 32 00 00 00 00 00 00 00 32 00 00 00 4B 00 00 00 96 00 00 00 32 00 00 00 5A 00 00 00 96 00 00 00 96 00 00 00 3C 00 00 00 96 00 00 00 \ No newline at end of file diff --git a/UnofficialCrusaderPatch/CodeBlocks/bal_unit_arrowdmg.block b/UnofficialCrusaderPatch/CodeBlocks/bal_unit_arrowdmg.block new file mode 100644 index 00000000..ca4e7cd5 --- /dev/null +++ b/UnofficialCrusaderPatch/CodeBlocks/bal_unit_arrowdmg.block @@ -0,0 +1 @@ +98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 88 13 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 D0 07 00 00 DC 05 00 00 AC 0D 00 00 E8 03 00 00 E8 03 00 00 96 00 00 00 96 00 00 00 E8 03 00 00 D0 07 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 A0 0F 00 00 98 3A 00 00 2C 01 00 00 C8 00 00 00 B0 04 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 A0 0F 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 32 00 00 00 64 00 00 00 98 3A 00 00 98 3A 00 00 B8 0B 00 00 B8 0B 00 00 32 00 00 00 D0 07 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 F0 49 02 00 A0 0F 00 00 00 00 00 00 00 00 00 00 D0 07 00 00 58 1B 00 00 A0 0F 00 00 DC 05 00 00 E2 04 00 00 2C 01 00 00 E2 04 00 00 F4 01 00 00 \ No newline at end of file diff --git a/UnofficialCrusaderPatch/CodeBlocks/bal_unit_health.block b/UnofficialCrusaderPatch/CodeBlocks/bal_unit_health.block new file mode 100644 index 00000000..cf05d9c5 --- /dev/null +++ b/UnofficialCrusaderPatch/CodeBlocks/bal_unit_health.block @@ -0,0 +1 @@ +C4 09 00 00 C4 09 00 00 10 27 00 00 C4 09 00 00 10 27 00 00 88 13 00 00 10 27 00 00 10 27 00 00 C4 09 00 00 C4 09 00 00 C4 09 00 00 C4 09 00 00 C4 09 00 00 C4 09 00 00 C4 09 00 00 C4 09 00 00 C4 09 00 00 C4 09 00 00 10 27 00 00 88 13 00 00 C4 09 00 00 10 27 00 00 98 3A 00 00 10 27 00 00 50 C3 00 00 98 3A 00 00 A8 61 00 00 20 4E 00 00 88 13 00 00 88 13 00 00 C4 09 00 00 C4 09 00 00 C4 09 00 00 C4 09 00 00 C4 09 00 00 C4 09 00 00 98 3A 00 00 C4 09 00 00 10 27 00 00 E0 2E 00 00 10 27 00 00 C4 09 00 00 C4 09 00 00 C4 09 00 00 E0 2E 00 00 E8 03 00 00 20 4E 00 00 C4 09 00 00 C4 09 00 00 C4 09 00 00 C4 09 00 00 B8 0B 00 00 C4 09 00 00 20 A1 07 00 F0 49 02 00 C4 09 00 00 C4 09 00 00 80 A9 03 00 F0 49 02 00 10 27 00 00 10 27 00 00 C4 09 00 00 60 EA 00 00 60 EA 00 00 C4 09 00 00 C4 09 00 00 70 17 00 00 C4 09 00 00 C4 09 00 00 E0 2E 00 00 70 17 00 00 28 23 00 00 98 3A 00 00 10 27 00 00 20 4E 00 00 58 1B 00 00 10 27 00 00 \ No newline at end of file diff --git a/UnofficialCrusaderPatch/CodeBlocks/bal_unit_meleedmg.block b/UnofficialCrusaderPatch/CodeBlocks/bal_unit_meleedmg.block new file mode 100644 index 00000000..396e634c --- /dev/null +++ b/UnofficialCrusaderPatch/CodeBlocks/bal_unit_meleedmg.block @@ -0,0 +1 @@ +02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 00 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 00 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 02 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 00 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 02 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 02 00 00 00 02 00 00 00 14 00 00 00 28 00 00 00 1E 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 14 00 00 00 02 00 00 00 02 00 00 00 \ No newline at end of file diff --git a/UnofficialCrusaderPatch/CodeBlocks/bal_unit_stonedmg.block b/UnofficialCrusaderPatch/CodeBlocks/bal_unit_stonedmg.block new file mode 100644 index 00000000..98e0b4ef --- /dev/null +++ b/UnofficialCrusaderPatch/CodeBlocks/bal_unit_stonedmg.block @@ -0,0 +1 @@ +88 13 00 00 88 13 00 00 88 13 00 00 88 13 00 00 88 13 00 00 88 13 00 00 88 13 00 00 88 13 00 00 88 13 00 00 88 13 00 00 88 13 00 00 88 13 00 00 88 13 00 00 88 13 00 00 88 13 00 00 88 13 00 00 88 13 00 00 88 13 00 00 88 13 00 00 88 13 00 00 88 13 00 00 E8 03 00 00 EE 02 00 00 08 07 00 00 F4 01 00 00 F4 01 00 00 96 00 00 00 96 00 00 00 C4 09 00 00 D0 07 00 00 88 13 00 00 88 13 00 00 88 13 00 00 88 13 00 00 88 13 00 00 88 13 00 00 F4 01 00 00 88 13 00 00 C8 00 00 00 96 00 00 00 E8 03 00 00 88 13 00 00 88 13 00 00 88 13 00 00 B8 0B 00 00 88 13 00 00 88 13 00 00 88 13 00 00 88 13 00 00 88 13 00 00 88 13 00 00 88 13 00 00 88 13 00 00 32 00 00 00 64 00 00 00 88 13 00 00 88 13 00 00 D0 07 00 00 D0 07 00 00 0A 00 00 00 E8 03 00 00 88 13 00 00 88 13 00 00 88 13 00 00 88 13 00 00 50 C3 00 00 D0 07 00 00 00 00 00 00 00 00 00 00 F4 01 00 00 A0 0F 00 00 B8 0B 00 00 F4 01 00 00 F4 01 00 00 C8 00 00 00 90 01 00 00 64 00 00 00 \ No newline at end of file diff --git a/UnofficialCrusaderPatch/CodeBlocks/bal_unit_xbowdmg.block b/UnofficialCrusaderPatch/CodeBlocks/bal_unit_xbowdmg.block new file mode 100644 index 00000000..7e0b9002 --- /dev/null +++ b/UnofficialCrusaderPatch/CodeBlocks/bal_unit_xbowdmg.block @@ -0,0 +1 @@ +98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 88 13 00 00 98 3A 00 00 B8 0B 00 00 88 13 00 00 98 08 00 00 C4 09 00 00 C4 09 00 00 10 27 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 58 1B 00 00 98 3A 00 00 DC 05 00 00 E8 03 00 00 DC 05 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 10 27 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 32 00 00 00 96 00 00 00 98 3A 00 00 98 3A 00 00 40 1F 00 00 40 1F 00 00 96 00 00 00 B8 0B 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 98 3A 00 00 10 27 00 00 00 00 00 00 00 00 00 00 10 27 00 00 70 17 00 00 40 1F 00 00 40 1F 00 00 40 1F 00 00 40 1F 00 00 40 1F 00 00 F4 01 00 00 \ No newline at end of file diff --git a/UnofficialCrusaderPatch/UnofficialCrusaderPatch.csproj b/UnofficialCrusaderPatch/UnofficialCrusaderPatch.csproj index c8ab799f..b3ea1142 100644 --- a/UnofficialCrusaderPatch/UnofficialCrusaderPatch.csproj +++ b/UnofficialCrusaderPatch/UnofficialCrusaderPatch.csproj @@ -96,6 +96,9 @@ + + + From 967f2250856265e91489c4b04f011b2fbf992db9 Mon Sep 17 00:00:00 2001 From: patel-nikhil Date: Tue, 7 Dec 2021 23:17:21 -0500 Subject: [PATCH 4/7] Add building cost AOB --- UnofficialCrusaderPatch/CodeBlocks/bal_building_cost.block | 1 + 1 file changed, 1 insertion(+) create mode 100644 UnofficialCrusaderPatch/CodeBlocks/bal_building_cost.block diff --git a/UnofficialCrusaderPatch/CodeBlocks/bal_building_cost.block b/UnofficialCrusaderPatch/CodeBlocks/bal_building_cost.block new file mode 100644 index 00000000..e2a7a0d4 --- /dev/null +++ b/UnofficialCrusaderPatch/CodeBlocks/bal_building_cost.block @@ -0,0 +1 @@ +06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 14 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 14 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0F 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 14 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 64 00 00 00 14 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 C8 00 00 00 0A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 64 00 00 00 14 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 64 00 00 00 0A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 64 00 00 00 0A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 14 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 14 00 00 00 00 00 00 00 \ No newline at end of file From becad99a9fe6e4de1fdb97ab50191e6880325255 Mon Sep 17 00:00:00 2001 From: patel-nikhil Date: Tue, 7 Dec 2021 23:44:21 -0500 Subject: [PATCH 5/7] Add balance resource config stubs and implement building cost edit --- .../Balance/BalanceEnums.cs | 4 +- .../Balance/BalanceHelper.cs | 110 ++++++++++++------ 2 files changed, 76 insertions(+), 38 deletions(-) diff --git a/UnofficialCrusaderPatch/Balance/BalanceEnums.cs b/UnofficialCrusaderPatch/Balance/BalanceEnums.cs index db36480b..06cae8b6 100644 --- a/UnofficialCrusaderPatch/Balance/BalanceEnums.cs +++ b/UnofficialCrusaderPatch/Balance/BalanceEnums.cs @@ -7,7 +7,7 @@ namespace UCP.Balance { public class BalanceEnums { - public List buildingNames = new List() + public static List buildingNames = new List() { "Hovel", "House", @@ -118,7 +118,7 @@ public class BalanceEnums "Mercenary Outpost" }; - public List unitNames = new List() + public static List unitNames = new List() { "Peasant", "Burning man", diff --git a/UnofficialCrusaderPatch/Balance/BalanceHelper.cs b/UnofficialCrusaderPatch/Balance/BalanceHelper.cs index 03ebba59..0aac0ce8 100644 --- a/UnofficialCrusaderPatch/Balance/BalanceHelper.cs +++ b/UnofficialCrusaderPatch/Balance/BalanceHelper.cs @@ -12,85 +12,123 @@ public static ChangeEdit[] GetBinaryEdits(BalanceConfig balanceConfig) { List editList = new List(); - ChangeEdit buildingCostEdit = GetBuildingCostEdit(); - ChangeEdit buildingHealthEdit = GetBuildingHealthEdit(); - ChangeEdit unitHealthEdit = GetUnitHealthEdit(); - ChangeEdit unitArrowDmgEdit = GetUnitArrowDmgEdit(); - ChangeEdit unitXbowDmgEdit = GetUnitXbowDmgEdit(); - ChangeEdit unitStoneDmgEdit = GetUnitStoneDmgEdit(); - ChangeEdit unitMeleeDmgEdit = GetUnitMeleeDmgEdit(); - - if (buildingCostEdit != null) + if (balanceConfig.buildings != null) { - editList.Add(buildingCostEdit); - } + ChangeEdit buildingCostEdit = GetBuildingCostEdit(balanceConfig.buildings); + ChangeEdit buildingHealthEdit = GetBuildingHealthEdit(balanceConfig.buildings); - if (buildingHealthEdit != null) - { + editList.Add(buildingCostEdit); editList.Add(buildingHealthEdit); } - if (unitHealthEdit != null) + if (balanceConfig.resources != null) { - editList.Add(unitHealthEdit); - } + ChangeEdit resourceBuyEdit = GetResourceBuyEdit(balanceConfig.resources); + ChangeEdit resourceSellEdit = GetResourceSellEdit(balanceConfig.resources); - if (unitArrowDmgEdit != null) - { - editList.Add(unitArrowDmgEdit); + editList.Add(resourceBuyEdit); + editList.Add(resourceSellEdit); } - if (unitMeleeDmgEdit != null) - { - editList.Add(unitMeleeDmgEdit); - } - if (unitStoneDmgEdit != null) + if (balanceConfig.units != null) { - editList.Add(unitStoneDmgEdit); - } + ChangeEdit unitHealthEdit = GetUnitHealthEdit(balanceConfig.units); + ChangeEdit unitArrowDmgEdit = GetUnitArrowDmgEdit(balanceConfig.units); + ChangeEdit unitXbowDmgEdit = GetUnitXbowDmgEdit(balanceConfig.units); + ChangeEdit unitStoneDmgEdit = GetUnitStoneDmgEdit(balanceConfig.units); + ChangeEdit unitMeleeDmgEdit = GetUnitMeleeDmgEdit(balanceConfig.units); - if (unitXbowDmgEdit != null) - { + editList.Add(unitHealthEdit); + editList.Add(unitArrowDmgEdit); + editList.Add(unitMeleeDmgEdit); + editList.Add(unitStoneDmgEdit); editList.Add(unitXbowDmgEdit); } - return editList.ToArray(); } - private static ChangeEdit GetUnitMeleeDmgEdit() + private static ChangeEdit GetResourceSellEdit(Dictionary resources) + { + throw new NotImplementedException(); + } + + private static ChangeEdit GetResourceBuyEdit(Dictionary resources) { throw new NotImplementedException(); } - private static ChangeEdit GetUnitStoneDmgEdit() + private static ChangeEdit GetUnitMeleeDmgEdit(Dictionary units) { throw new NotImplementedException(); } - private static ChangeEdit GetUnitXbowDmgEdit() + private static ChangeEdit GetUnitStoneDmgEdit(Dictionary units) { throw new NotImplementedException(); } - private static ChangeEdit GetUnitArrowDmgEdit() + private static ChangeEdit GetUnitXbowDmgEdit(Dictionary units) { throw new NotImplementedException(); } - private static ChangeEdit GetUnitHealthEdit() + private static ChangeEdit GetUnitArrowDmgEdit(Dictionary units) { throw new NotImplementedException(); } - private static ChangeEdit GetBuildingHealthEdit() + private static ChangeEdit GetUnitHealthEdit(Dictionary units) { throw new NotImplementedException(); } - private static ChangeEdit GetBuildingCostEdit() + private static ChangeEdit GetBuildingHealthEdit(Dictionary buildings) { throw new NotImplementedException(); } + + private static ChangeEdit GetBuildingCostEdit(Dictionary buildings) + { + const int buildingCostLength = 5; + BinaryEdit buildingCostEdit = new BinaryEdit("bal_building_cost"); + for (int i = 0; i < BalanceEnums.buildingNames.Count; i++) + { + List currentBuildingEdit = new List(); + BalanceConfig.BuildingConfig buildingConfig; + if (buildings.TryGetValue(BalanceEnums.buildingNames[i], out buildingConfig)){ + if (buildingConfig.cost != null) + { + if (buildingConfig.cost.Length == buildingCostLength) + { + foreach (int resourceCost in buildingConfig.cost) + { + currentBuildingEdit.Add(new BinInt32(resourceCost)); + } + } + else + { + throw new Exception("Invalid building cost for " + BalanceEnums.buildingNames[i]); + } + } + } + + // if current building or current building cost entry is not specified then skip + if (currentBuildingEdit.Count == 0) + { + for (int j = 0; j < buildingCostLength; j++) + { + currentBuildingEdit.Add(new BinSkip(4)); + } + } + + // Add elements of currentBuildingEdit to the combined list of edits for building health binaryEdit + foreach (BinElement element in currentBuildingEdit) + { + buildingCostEdit.Add(element); + } + } + return buildingCostEdit; + } } } From 7fd351660729b0ae6371ee6a786615f685f693bc Mon Sep 17 00:00:00 2001 From: patel-nikhil Date: Tue, 7 Dec 2021 23:52:53 -0500 Subject: [PATCH 6/7] Make int values in balance config nullable and building health edit --- .../Balance/BalanceConfig.cs | 14 +++---- .../Balance/BalanceHelper.cs | 37 ++++++++++++++++++- 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/UnofficialCrusaderPatch/Balance/BalanceConfig.cs b/UnofficialCrusaderPatch/Balance/BalanceConfig.cs index 0087ef87..3b063b3c 100644 --- a/UnofficialCrusaderPatch/Balance/BalanceConfig.cs +++ b/UnofficialCrusaderPatch/Balance/BalanceConfig.cs @@ -10,22 +10,22 @@ public class BalanceConfig public class BuildingConfig { public int[] cost; - public int health; + public int? health; } public class UnitConfig { - public int health; - public int arrowDamage; - public int xbowDamage; - public int stoneDamage; + public int? health; + public int? arrowDamage; + public int? xbowDamage; + public int? stoneDamage; public Dictionary meleeDamageVs; } public class ResourceConfig { - public int buy; - public int sell; + public int? buy; + public int? sell; } public Dictionary description; diff --git a/UnofficialCrusaderPatch/Balance/BalanceHelper.cs b/UnofficialCrusaderPatch/Balance/BalanceHelper.cs index 0aac0ce8..1ae5815e 100644 --- a/UnofficialCrusaderPatch/Balance/BalanceHelper.cs +++ b/UnofficialCrusaderPatch/Balance/BalanceHelper.cs @@ -85,7 +85,36 @@ private static ChangeEdit GetUnitHealthEdit(Dictionary buildings) { - throw new NotImplementedException(); + BinaryEdit buildingHealthEdit = new BinaryEdit("bal_building_health"); + for (int i = 0; i < BalanceEnums.buildingNames.Count; i++) + { + List currentBuildingEdit = new List(); + BalanceConfig.BuildingConfig buildingConfig; + if (buildings.TryGetValue(BalanceEnums.buildingNames[i], out buildingConfig)) + { + if (buildingConfig.health.HasValue) + { + if (buildingConfig.health < 0 || buildingConfig.health > Int16.MaxValue) + { + throw new Exception("Invalid health of " + buildingConfig.health.ToString() + " for building " + BalanceEnums.buildingNames[i]); + } + currentBuildingEdit.Add(new BinInt32(buildingConfig.health.Value)); + } + } + + // if current building or current building health entry is not specified then add skip + if (currentBuildingEdit.Count == 0) + { + buildingHealthEdit.Add(new BinSkip(4)); + } + + // Add elements of currentBuildingEdit to the combined list of edits for building health binaryEdit + foreach (BinElement element in currentBuildingEdit) + { + buildingHealthEdit.Add(element); + } + } + return buildingHealthEdit; } private static ChangeEdit GetBuildingCostEdit(Dictionary buildings) @@ -103,6 +132,10 @@ private static ChangeEdit GetBuildingCostEdit(Dictionary Int16.MaxValue) + { + throw new Exception("Invalid resource cost of " + resourceCost.ToString() + " for building " + BalanceEnums.buildingNames[i]); + } currentBuildingEdit.Add(new BinInt32(resourceCost)); } } @@ -113,7 +146,7 @@ private static ChangeEdit GetBuildingCostEdit(Dictionary Date: Fri, 13 May 2022 21:50:45 -0400 Subject: [PATCH 7/7] Implement rest of the functions --- .../Balance/BalanceConfig.cs | 5 +- .../Balance/BalanceEnums.cs | 2 +- .../Balance/BalanceHelper.cs | 272 ++++++++++++++++-- .../UnofficialCrusaderPatch.csproj | 9 + 4 files changed, 262 insertions(+), 26 deletions(-) diff --git a/UnofficialCrusaderPatch/Balance/BalanceConfig.cs b/UnofficialCrusaderPatch/Balance/BalanceConfig.cs index 3b063b3c..b2563e6e 100644 --- a/UnofficialCrusaderPatch/Balance/BalanceConfig.cs +++ b/UnofficialCrusaderPatch/Balance/BalanceConfig.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Collections.Generic; namespace UCP.Balance { diff --git a/UnofficialCrusaderPatch/Balance/BalanceEnums.cs b/UnofficialCrusaderPatch/Balance/BalanceEnums.cs index 06cae8b6..3905fe7a 100644 --- a/UnofficialCrusaderPatch/Balance/BalanceEnums.cs +++ b/UnofficialCrusaderPatch/Balance/BalanceEnums.cs @@ -199,7 +199,7 @@ public class BalanceEnums "Fire ballista" }; - public List resourceNames = new List() + public static List resourceNames = new List() { "Wood", "Hop", diff --git a/UnofficialCrusaderPatch/Balance/BalanceHelper.cs b/UnofficialCrusaderPatch/Balance/BalanceHelper.cs index 1ae5815e..84346f65 100644 --- a/UnofficialCrusaderPatch/Balance/BalanceHelper.cs +++ b/UnofficialCrusaderPatch/Balance/BalanceHelper.cs @@ -1,7 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; using UCP.Patching; namespace UCP.Balance @@ -50,37 +48,233 @@ public static ChangeEdit[] GetBinaryEdits(BalanceConfig balanceConfig) private static ChangeEdit GetResourceSellEdit(Dictionary resources) { - throw new NotImplementedException(); + BinaryEdit resourceSellEdit = new BinaryEdit("bal_resource_sell"); + for (int i = 0; i < BalanceEnums.resourceNames.Count; i++) + { + List currentResourceEdit = new List(); + BalanceConfig.ResourceConfig resourceConfig; + if (resources.TryGetValue(BalanceEnums.unitNames[i], out resourceConfig)) + { + if (resourceConfig.sell.HasValue) + { + ValidateResourceValue("sell cost", resourceConfig.sell.Value, i, Int16.MaxValue); + currentResourceEdit.Add(new BinInt32(resourceConfig.sell.Value)); + } + } + + // if current entry is not specified then add skip + if (currentResourceEdit.Count == 0) + { + resourceSellEdit.Add(new BinSkip(4)); + } + + // Add to the combined list of edits + foreach (BinElement element in currentResourceEdit) + { + currentResourceEdit.Add(element); + } + } + return resourceSellEdit; } private static ChangeEdit GetResourceBuyEdit(Dictionary resources) { - throw new NotImplementedException(); + BinaryEdit resourceBuyEdit = new BinaryEdit("bal_resource_buy"); + for (int i = 0; i < BalanceEnums.resourceNames.Count; i++) + { + List currentResourceEdit = new List(); + BalanceConfig.ResourceConfig resourceConfig; + if (resources.TryGetValue(BalanceEnums.unitNames[i], out resourceConfig)) + { + if (resourceConfig.sell.HasValue) + { + ValidateResourceValue("buy cost", resourceConfig.sell.Value, i, Int16.MaxValue); + currentResourceEdit.Add(new BinInt32(resourceConfig.sell.Value)); + } + } + + // if current entry is not specified then add skip + if (currentResourceEdit.Count == 0) + { + resourceBuyEdit.Add(new BinSkip(4)); + } + + // Add to the combined list of edits + foreach (BinElement element in currentResourceEdit) + { + currentResourceEdit.Add(element); + } + } + return resourceBuyEdit; } private static ChangeEdit GetUnitMeleeDmgEdit(Dictionary units) { - throw new NotImplementedException(); + BinaryEdit unitMeleeDmgEdit = new BinaryEdit("bal_unit_meleedmg"); + for (int i = 0; i < BalanceEnums.unitNames.Count; i++) + { + List currentAttackerEdit = new List(); + BalanceConfig.UnitConfig unitConfig; + if (units.TryGetValue(BalanceEnums.unitNames[i], out unitConfig)) + { + if (unitConfig.meleeDamageVs != null) + { + for (int j = 0; j < BalanceEnums.unitNames.Count; j++) + { + List currentDefenderUnitEdit = new List(); + int dmgValue; + if (unitConfig.meleeDamageVs.TryGetValue(BalanceEnums.unitNames[j], out dmgValue)) + { + ValidateUnitValue("melee damage vs " + BalanceEnums.unitNames[j], dmgValue, i, Int32.MaxValue); + currentDefenderUnitEdit.Add(new BinInt32(dmgValue)); + } + + // if current entry is not specified then add skip + if (currentDefenderUnitEdit.Count == 0) + { + currentAttackerEdit.Add(new BinSkip(4 * BalanceEnums.unitNames.Count)); + } + + // Add to the combined list of edits + foreach (BinElement element in currentDefenderUnitEdit) + { + currentAttackerEdit.Add(element); + } + } + } + } + + // Add to the combined list of edits + foreach (BinElement element in currentAttackerEdit) + { + unitMeleeDmgEdit.Add(element); + } + } + return unitMeleeDmgEdit; } private static ChangeEdit GetUnitStoneDmgEdit(Dictionary units) { - throw new NotImplementedException(); + BinaryEdit unitStoneDmgEdit = new BinaryEdit("bal_unit_stonedmg"); + for (int i = 0; i < BalanceEnums.unitNames.Count; i++) + { + List currentUnitEdit = new List(); + BalanceConfig.UnitConfig unitConfig; + if (units.TryGetValue(BalanceEnums.unitNames[i], out unitConfig)) + { + if (unitConfig.stoneDamage.HasValue) + { + ValidateUnitValue("xbow damage", unitConfig.stoneDamage.Value, i, Int32.MaxValue); + currentUnitEdit.Add(new BinInt32(unitConfig.stoneDamage.Value)); + } + } + + // if current entry is not specified then add skip + if (currentUnitEdit.Count == 0) + { + unitStoneDmgEdit.Add(new BinSkip(4)); + } + + // Add to the combined list of edits + foreach (BinElement element in currentUnitEdit) + { + unitStoneDmgEdit.Add(element); + } + } + return unitStoneDmgEdit; } private static ChangeEdit GetUnitXbowDmgEdit(Dictionary units) { - throw new NotImplementedException(); + BinaryEdit unitXbowDmgEdit = new BinaryEdit("bal_unit_xbowdmg"); + for (int i = 0; i < BalanceEnums.unitNames.Count; i++) + { + List currentUnitEdit = new List(); + BalanceConfig.UnitConfig unitConfig; + if (units.TryGetValue(BalanceEnums.unitNames[i], out unitConfig)) + { + if (unitConfig.xbowDamage.HasValue) + { + ValidateUnitValue("xbow damage", unitConfig.xbowDamage.Value, i, Int32.MaxValue); + currentUnitEdit.Add(new BinInt32(unitConfig.xbowDamage.Value)); + } + } + + // if current entry is not specified then add skip + if (currentUnitEdit.Count == 0) + { + unitXbowDmgEdit.Add(new BinSkip(4)); + } + + // Add to the combined list of edits + foreach (BinElement element in currentUnitEdit) + { + unitXbowDmgEdit.Add(element); + } + } + return unitXbowDmgEdit; } private static ChangeEdit GetUnitArrowDmgEdit(Dictionary units) { - throw new NotImplementedException(); + BinaryEdit unitArrowDmgEdit = new BinaryEdit("bal_unit_arrowdmg"); + for (int i = 0; i < BalanceEnums.unitNames.Count; i++) + { + List currentUnitEdit = new List(); + BalanceConfig.UnitConfig unitConfig; + if (units.TryGetValue(BalanceEnums.unitNames[i], out unitConfig)) + { + if (unitConfig.arrowDamage.HasValue) + { + ValidateUnitValue("arrow damage", unitConfig.arrowDamage.Value, i, Int32.MaxValue); + currentUnitEdit.Add(new BinInt32(unitConfig.arrowDamage.Value)); + } + } + + // if current entry is not specified then add skip + if (currentUnitEdit.Count == 0) + { + unitArrowDmgEdit.Add(new BinSkip(4)); + } + + // Add to the combined list of edits + foreach (BinElement element in currentUnitEdit) + { + unitArrowDmgEdit.Add(element); + } + } + return unitArrowDmgEdit; } private static ChangeEdit GetUnitHealthEdit(Dictionary units) { - throw new NotImplementedException(); + BinaryEdit unitHealthEdit = new BinaryEdit("bal_unit_health"); + for (int i = 0; i < BalanceEnums.unitNames.Count; i++) + { + List currentUnitEdit = new List(); + BalanceConfig.UnitConfig unitConfig; + if (units.TryGetValue(BalanceEnums.unitNames[i], out unitConfig)) + { + if (unitConfig.health.HasValue) + { + ValidateUnitValue("health", unitConfig.health.Value, i, Int32.MaxValue); + currentUnitEdit.Add(new BinInt32(unitConfig.health.Value)); + } + } + + // if current entry is not specified then add skip + if (currentUnitEdit.Count == 0) + { + unitHealthEdit.Add(new BinSkip(4)); + } + + // Add to the combined list of edits + foreach (BinElement element in currentUnitEdit) + { + unitHealthEdit.Add(element); + } + } + return unitHealthEdit; } private static ChangeEdit GetBuildingHealthEdit(Dictionary buildings) @@ -94,21 +288,18 @@ private static ChangeEdit GetBuildingHealthEdit(Dictionary Int16.MaxValue) - { - throw new Exception("Invalid health of " + buildingConfig.health.ToString() + " for building " + BalanceEnums.buildingNames[i]); - } + ValidateBuildingValue("health", buildingConfig.health.Value, i, Int32.MaxValue); currentBuildingEdit.Add(new BinInt32(buildingConfig.health.Value)); } } - // if current building or current building health entry is not specified then add skip + // if current entry is not specified then add skip if (currentBuildingEdit.Count == 0) { buildingHealthEdit.Add(new BinSkip(4)); } - // Add elements of currentBuildingEdit to the combined list of edits for building health binaryEdit + // Add to the combined list of edits foreach (BinElement element in currentBuildingEdit) { buildingHealthEdit.Add(element); @@ -132,10 +323,7 @@ private static ChangeEdit GetBuildingCostEdit(Dictionary Int16.MaxValue) - { - throw new Exception("Invalid resource cost of " + resourceCost.ToString() + " for building " + BalanceEnums.buildingNames[i]); - } + ValidateBuildingValue("resource", resourceCost, i, Int16.MaxValue); currentBuildingEdit.Add(new BinInt32(resourceCost)); } } @@ -146,7 +334,7 @@ private static ChangeEdit GetBuildingCostEdit(Dictionary maxValue) + { + string errorMessage = GetBuildingErrorMessage(valueType, value, itemIndex); + throw new Exception(errorMessage); + } + } + + private static void ValidateResourceValue(string valueType, int value, int itemIndex, int maxValue) + { + if (value < 0 || value > maxValue) + { + string errorMessage = GetResourceErrorMessage(valueType, value, itemIndex); + throw new Exception(errorMessage); + } + } + + private static void ValidateUnitValue(string valueType, int value, int itemIndex, int maxValue) + { + if (value < 0 || value > maxValue) + { + string errorMessage = GetUnitErrorMessage(valueType, value, itemIndex); + throw new Exception(errorMessage); + } + } + + private static string GetBuildingErrorMessage(string valueType, int invalidValue, int buildingIndex) + { + return "Invalid " + valueType + " of " + invalidValue.ToString() + " for building " + BalanceEnums.buildingNames[buildingIndex]; + } + + private static string GetResourceErrorMessage(string valueType, int invalidValue, int buildingIndex) + { + return "Invalid " + valueType + " of " + invalidValue.ToString() + " for resource " + BalanceEnums.resourceNames[buildingIndex]; + } + + private static string GetUnitErrorMessage(string valueType, int invalidValue, int buildingIndex) + { + return "Invalid " + valueType + " of " + invalidValue.ToString() + " for unit " + BalanceEnums.unitNames[buildingIndex]; + } } } diff --git a/UnofficialCrusaderPatch/UnofficialCrusaderPatch.csproj b/UnofficialCrusaderPatch/UnofficialCrusaderPatch.csproj index b3ea1142..91b663af 100644 --- a/UnofficialCrusaderPatch/UnofficialCrusaderPatch.csproj +++ b/UnofficialCrusaderPatch/UnofficialCrusaderPatch.csproj @@ -336,6 +336,14 @@ + + + + + + + + @@ -360,6 +368,7 @@ + SettingsSingleFileGenerator Settings.Designer.cs