From 621c6fb48f823e6f002cb65815a5332385174ac1 Mon Sep 17 00:00:00 2001 From: Sean Petrie Date: Tue, 24 Dec 2024 12:30:34 -0600 Subject: [PATCH] Added Rule Creators to fix logging issues --- CHANGELOG.md | 3 ++ Repository.json | 2 +- TabletopTweaks-Core/Info.json | 2 +- .../NewRules/RuleAttackWithWeaponPrecision.cs | 14 ++++++++++ .../NewRules/RuleCalculateArmorAC.cs | 28 +++++++++++++++---- .../NewRules/RuleFortificationCheck.cs | 14 ++++++++++ 6 files changed, 56 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 87377a4b..4cd3c508 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# Version 0.7.12 +* Fixed issue with missing log creators creating stutters and bloated logs. + # Version 0.7.11 * Fix for broken type issue in some game versions. diff --git a/Repository.json b/Repository.json index c657d770..e1f541a9 100644 --- a/Repository.json +++ b/Repository.json @@ -2,7 +2,7 @@ "Releases": [ { "Id": "TabletopTweaks-Core", - "Version": "0.7.11" + "Version": "0.7.12" } ] } diff --git a/TabletopTweaks-Core/Info.json b/TabletopTweaks-Core/Info.json index 766e9d4f..1f990038 100644 --- a/TabletopTweaks-Core/Info.json +++ b/TabletopTweaks-Core/Info.json @@ -10,5 +10,5 @@ "Repository": "https://raw.githubusercontent.com/Vek17/TabletopTweaks-Core/master/Repository.json", "Requirements": [], "LoadAfter": [ "MewsiferConsole.Mod" ], - "Version": "0.7.11" + "Version": "0.7.12" } \ No newline at end of file diff --git a/TabletopTweaks-Core/NewRules/RuleAttackWithWeaponPrecision.cs b/TabletopTweaks-Core/NewRules/RuleAttackWithWeaponPrecision.cs index 9552a91e..8508c35a 100644 --- a/TabletopTweaks-Core/NewRules/RuleAttackWithWeaponPrecision.cs +++ b/TabletopTweaks-Core/NewRules/RuleAttackWithWeaponPrecision.cs @@ -14,6 +14,20 @@ namespace TabletopTweaks.Core.NewRules { class RuleAttackWithWeaponPrecision : RuleAttackWithWeapon { + [PostPatchInitialize] + static void AddGameLogEventCreator() { + if (!GameLogEventsFactory.Creators.ContainsKey(typeof(RuleAttackWithWeaponPrecision))) { + Type gameLogEventType = typeof(GameLogRuleEvent<>).MakeGenericType(new Type[] + { + typeof(RuleAttackWithWeaponPrecision) + }); + GameLogEventsFactory.Creators.Add(typeof(RuleAttackWithWeaponPrecision), (RulebookEvent rule) => (GameLogEvent)Activator.CreateInstance(gameLogEventType, new object[] + { + rule + })); + } + } + public bool ForceSneakAttack { get; set; } public RuleAttackWithWeaponPrecision([NotNull] UnitEntityData attacker, [NotNull] UnitEntityData target, [NotNull] ItemEntityWeapon weapon, int attackBonusPenalty) : base(attacker, target, weapon, attackBonusPenalty) { } diff --git a/TabletopTweaks-Core/NewRules/RuleCalculateArmorAC.cs b/TabletopTweaks-Core/NewRules/RuleCalculateArmorAC.cs index a65713c6..d36ca778 100644 --- a/TabletopTweaks-Core/NewRules/RuleCalculateArmorAC.cs +++ b/TabletopTweaks-Core/NewRules/RuleCalculateArmorAC.cs @@ -10,6 +10,8 @@ using Kingmaker.Items; using Kingmaker.RuleSystem; using Kingmaker.UI.Common; +using Kingmaker.UI.Models.Log; +using Kingmaker.UI.Models.Log.Events; using Kingmaker.UI.MVVM._VM.Tooltip.Bricks; using Kingmaker.UI.MVVM._VM.Tooltip.Templates; using Kingmaker.UI.Tooltip; @@ -21,11 +23,26 @@ using System.Linq; using System.Reflection; using System.Reflection.Emit; +using TabletopTweaks.Core.Utilities; using UnityEngine; namespace TabletopTweaks.Core.NewRules { public class RuleCalculateArmorAC : RulebookEvent { + [PostPatchInitialize] + static void AddGameLogEventCreator() { + if (!GameLogEventsFactory.Creators.ContainsKey(typeof(RuleCalculateArmorAC))) { + Type gameLogEventType = typeof(GameLogRuleEvent<>).MakeGenericType(new Type[] + { + typeof(RuleCalculateArmorAC) + }); + GameLogEventsFactory.Creators.Add(typeof(RuleCalculateArmorAC), (RulebookEvent rule) => (GameLogEvent)Activator.CreateInstance(gameLogEventType, new object[] + { + rule + })); + } + } + public int ArmorBonus => ArmorBaseBonus + ArmorEnhancementBonus + ArmorModifier + MythicMediumArmorEnduranceBonus + ArmoredMightBonus; public int ArmoredMightBonus { get { @@ -79,7 +96,7 @@ static class ItemEntityArmor_RecalculateStats_RuleCalculateArmorAC_Patch { static readonly MethodInfo ItemEntityArmor_AddModifier = AccessTools.Method( typeof(ItemEntityArmor), nameof(ItemEntityArmor.AddModifier), - new Type[] { + new Type[] { typeof(ModifiableValue), typeof(int), typeof(ModifierDescriptor), @@ -117,9 +134,10 @@ private static TargetInfo FindInsertionTarget(List codes) { var firstModifier = false; for (int i = info.Index; i < codes.Count; i++) { if (codes[i].opcode == OpCodes.Call && codes[i].Calls(ItemEntityArmor_AddModifier)) { - if (!firstModifier) { - firstModifier = true; - continue; } + if (!firstModifier) { + firstModifier = true; + continue; + } info.End = i; break; } @@ -207,6 +225,6 @@ static private void AddModifiers(TooltipTemplateItem __instance, RuleCalculateAr } } } - } + } } } diff --git a/TabletopTweaks-Core/NewRules/RuleFortificationCheck.cs b/TabletopTweaks-Core/NewRules/RuleFortificationCheck.cs index 51f81f73..4a35a5db 100644 --- a/TabletopTweaks-Core/NewRules/RuleFortificationCheck.cs +++ b/TabletopTweaks-Core/NewRules/RuleFortificationCheck.cs @@ -15,6 +15,20 @@ namespace TabletopTweaks.Core.NewRules { public class RuleFortificationCheck : RulebookTargetEvent { + [PostPatchInitialize] + static void AddGameLogEventCreator() { + if (!GameLogEventsFactory.Creators.ContainsKey(typeof(RuleFortificationCheck))) { + Type gameLogEventType = typeof(GameLogRuleEvent<>).MakeGenericType(new Type[] + { + typeof(RuleFortificationCheck) + }); + GameLogEventsFactory.Creators.Add(typeof(RuleFortificationCheck), (RulebookEvent rule) => (GameLogEvent)Activator.CreateInstance(gameLogEventType, new object[] + { + rule + })); + } + } + public RuleFortificationCheck([NotNull] RuleAttackRoll evt) : base(evt.Initiator, evt.Target) { this.Roll = new RuleRollD100(Initiator); this.ForCritical = evt.IsCriticalConfirmed;