From be094c31bb9cf2588050e23ff8f8bd2d535d15cc Mon Sep 17 00:00:00 2001 From: Benny Zlotnik Date: Tue, 4 Oct 2022 13:22:26 +0300 Subject: [PATCH 1/5] update dependencies --- build/common.props | 1 - 1 file changed, 1 deletion(-) diff --git a/build/common.props b/build/common.props index c4b0b282..6b8b4181 100644 --- a/build/common.props +++ b/build/common.props @@ -26,7 +26,6 @@ 3.1.0.61 - net472 x64 From 5a68f85108e82519bfd53aee5cf1c576c1e33086 Mon Sep 17 00:00:00 2001 From: Benny Zlotnik Date: Tue, 4 Oct 2022 13:22:52 +0300 Subject: [PATCH 2/5] fix teleportation Fix issue where sending a messenger to settlement results in teleporting the player. This is done by essentially by removing the code that enters the settlement and instead just initiates the dialog as if there's no settlement involved --- .../Messengers/MessengerManager.cs | 32 ++++++------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/src/Bannerlord.Diplomacy/Messengers/MessengerManager.cs b/src/Bannerlord.Diplomacy/Messengers/MessengerManager.cs index 02447ebf..a6d67241 100644 --- a/src/Bannerlord.Diplomacy/Messengers/MessengerManager.cs +++ b/src/Bannerlord.Diplomacy/Messengers/MessengerManager.cs @@ -11,6 +11,7 @@ using TaleWorlds.CampaignSystem.Encounters; using TaleWorlds.CampaignSystem.GameState; using TaleWorlds.CampaignSystem.Party; +using TaleWorlds.CampaignSystem.Settlements; using TaleWorlds.CampaignSystem.Settlements.Locations; using TaleWorlds.Core; using TaleWorlds.Library; @@ -31,7 +32,7 @@ internal sealed class MessengerManager : IMissionListener private Messenger? _activeMessenger; private Mission? _currentMission; - [SaveableField(1)] [UsedImplicitly] private List _messengers; + [SaveableField(1)][UsedImplicitly] private List _messengers; public MBReadOnlyList Messengers { get; private set; } @@ -184,31 +185,18 @@ public void StartDialogue(Hero targetHero, Messenger messenger) else targetParty = targetHero.PartyBelongedTo?.Party ?? targetHero.BornSettlement?.Party; - var settlement = targetHero.CurrentSettlement; - PlayerEncounter.Start(); PlayerEncounter.Current.SetupFields(heroParty, targetParty ?? heroParty); Campaign.Current.CurrentConversationContext = ConversationContext.Default; - if (settlement != null) - { - PlayerEncounter.EnterSettlement(); - Location locationOfCharacter = LocationComplex.Current.GetLocationOfCharacter(targetHero); - CampaignEventDispatcher.Instance.OnPlayerStartTalkFromMenu(targetHero); - _currentMission = - (Mission) PlayerEncounter.LocationEncounter.CreateAndOpenMissionController(locationOfCharacter, null, targetHero.CharacterObject); - } - else - { - var specialScene = ""; - var sceneLevels = ""; - - _currentMission = (Mission) Campaign.Current.CampaignMissionManager.OpenConversationMission( - new ConversationCharacterData(Hero.MainHero.CharacterObject, heroParty, true), - new ConversationCharacterData(targetHero.CharacterObject, targetParty, true), - specialScene, sceneLevels); - } - + var specialScene = ""; + var sceneLevels = ""; + + // TODO: hack the scene to show the scene of the target instead of the player's + _currentMission = (Mission) Campaign.Current.CampaignMissionManager.OpenConversationMission( + new ConversationCharacterData(Hero.MainHero.CharacterObject, Hero.MainHero.PartyBelongedTo.Party, true), + new ConversationCharacterData(targetHero.CharacterObject, targetHero.PartyBelongedTo?.Party, true), + specialScene, sceneLevels); _currentMission.AddListener(this); } From cdef9a7310e94efc8ebd1a6692ac50f0073ced94 Mon Sep 17 00:00:00 2001 From: Benny Zlotnik Date: Tue, 4 Oct 2022 13:33:32 +0300 Subject: [PATCH 3/5] fix faction selection issue in the Kingdom->Diplomacy view Fix alliances/wars/pacts listings, as well as infomation in the tooltips --- .../DiplomaticAction/AbstractScoringModel.cs | 2 +- .../PatchTools/PatchManager.cs | 3 +- .../Patches/ViewModelPatch.cs | 44 +++++++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 src/Bannerlord.Diplomacy/Patches/ViewModelPatch.cs diff --git a/src/Bannerlord.Diplomacy/DiplomaticAction/AbstractScoringModel.cs b/src/Bannerlord.Diplomacy/DiplomaticAction/AbstractScoringModel.cs index 3fb76499..19c19d99 100644 --- a/src/Bannerlord.Diplomacy/DiplomaticAction/AbstractScoringModel.cs +++ b/src/Bannerlord.Diplomacy/DiplomaticAction/AbstractScoringModel.cs @@ -19,7 +19,7 @@ namespace Diplomacy.DiplomaticAction protected AbstractScoringModel(IDiplomacyScores scores) => Scores = scores; - public virtual ExplainedNumber GetScore(Kingdom ourKingdom, Kingdom otherKingdom, bool includeDesc = false) + public virtual ExplainedNumber GetScore(Kingdom otherKingdom, Kingdom ourKingdom, bool includeDesc = false) { var explainedNum = new ExplainedNumber(Scores.Base, includeDesc); diff --git a/src/Bannerlord.Diplomacy/PatchTools/PatchManager.cs b/src/Bannerlord.Diplomacy/PatchTools/PatchManager.cs index 669db544..5beca6bb 100644 --- a/src/Bannerlord.Diplomacy/PatchTools/PatchManager.cs +++ b/src/Bannerlord.Diplomacy/PatchTools/PatchManager.cs @@ -69,7 +69,8 @@ private PatchManager(string harmonyId) new DefaultEncyclopediaFactionPagePatch(), new RebelKingdomPatches(), new KingdomManagementVMPatch(), - new MBBannerEditorGauntletScreenPatch() + new MBBannerEditorGauntletScreenPatch(), + new ViewModelPatch() // ... Only 1 class left to convert to declarative patching. }; } diff --git a/src/Bannerlord.Diplomacy/Patches/ViewModelPatch.cs b/src/Bannerlord.Diplomacy/Patches/ViewModelPatch.cs new file mode 100644 index 00000000..32e0bfa2 --- /dev/null +++ b/src/Bannerlord.Diplomacy/Patches/ViewModelPatch.cs @@ -0,0 +1,44 @@ +using TaleWorlds.Library; +using Diplomacy.PatchTools; + +using System.Collections.Generic; +using System.Reflection; +using System; +using TaleWorlds.CampaignSystem.ViewModelCollection.KingdomManagement.Diplomacy; + +namespace Diplomacy.Patches +{ + internal class ViewModelPatch : PatchClass + { + protected override IEnumerable Prepare() + { + return new Patch[] + { + new Prefix(nameof(FixInvoke), new Reflect.Method(typeof(Common), "InvokeWithLog", new Type[]{typeof(MethodInfo), typeof(object), typeof(object[])})), + }; + } + + // TODO: this is a terrible hack, hopefully I will get assitance with https://github.com/BUTR/Bannerlord.UIExtenderEx/discussions/159 + // and fix it properly + private static void FixInvoke(MethodInfo methodInfo, object obj, object[] args) + { + var instance = methodInfo.GetType().GetField("_instance", BindingFlags.NonPublic | BindingFlags.Instance); + if (instance != null && instance.GetValue(methodInfo) is ViewModelMixin.KingdomTruceItemVmMixin) + { + if (!Environment.StackTrace.Contains("OnRefresh")) + { + var MixinInstance = (ViewModelMixin.KingdomTruceItemVmMixin) instance.GetValue(methodInfo); + var BadVm = MixinInstance.GetType().BaseType.GetField("_vm", BindingFlags.Instance | BindingFlags.NonPublic); + // Replace VM with obj + BadVm.SetValue(MixinInstance, new WeakReference((KingdomTruceItemVM) obj)); + + // Replace private _factionn reference + var vm = MixinInstance.GetType().GetField("_faction2", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.IgnoreCase); + vm.SetValue(MixinInstance, ((KingdomTruceItemVM) obj).Faction2); + MixinInstance.GetType().GetProperty("DiplomacyProperties").SetValue(MixinInstance, new ViewModel.DiplomacyPropertiesVM(((KingdomTruceItemVM) obj).Faction1, ((KingdomTruceItemVM) obj).Faction2)); + MixinInstance.OnRefresh(); + } + } + } + } +} From 6459c0b43b670294c338249fef7024bc6244d615 Mon Sep 17 00:00:00 2001 From: Benny Zlotnik Date: Tue, 4 Oct 2022 14:22:50 +0300 Subject: [PATCH 4/5] fix war selection issue --- .../Patches/ViewModelPatch.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Bannerlord.Diplomacy/Patches/ViewModelPatch.cs b/src/Bannerlord.Diplomacy/Patches/ViewModelPatch.cs index 32e0bfa2..d2705f87 100644 --- a/src/Bannerlord.Diplomacy/Patches/ViewModelPatch.cs +++ b/src/Bannerlord.Diplomacy/Patches/ViewModelPatch.cs @@ -39,6 +39,22 @@ private static void FixInvoke(MethodInfo methodInfo, object obj, object[] args) MixinInstance.OnRefresh(); } } + else if (instance != null && instance.GetValue(methodInfo) is ViewModelMixin.KingdomWarItemVMMixin) + { + if (!Environment.StackTrace.Contains("OnRefresh")) + { + var MixinInstance = (ViewModelMixin.KingdomWarItemVMMixin) instance.GetValue(methodInfo); + var BadVm = MixinInstance.GetType().BaseType.GetField("_vm", BindingFlags.Instance | BindingFlags.NonPublic); + // Replace VM with obj + BadVm.SetValue(MixinInstance, new WeakReference((KingdomWarItemVM) obj)); + + // Replace private _factionn reference + var vm = MixinInstance.GetType().GetField("_faction2", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.IgnoreCase); + vm.SetValue(MixinInstance, ((KingdomWarItemVM) obj).Faction2); + MixinInstance.GetType().GetProperty("DiplomacyProperties").SetValue(MixinInstance, new ViewModel.DiplomacyPropertiesVM(((KingdomWarItemVM) obj).Faction1, ((KingdomWarItemVM) obj).Faction2)); + MixinInstance.OnRefresh(); + } + } } } } From 6b8e38ebc50e876e4b526a56f216232152bf030b Mon Sep 17 00:00:00 2001 From: Benny Zlotnik Date: Wed, 5 Oct 2022 18:39:16 +0300 Subject: [PATCH 5/5] update changelog --- changelog.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/changelog.txt b/changelog.txt index 3021574c..303fb3b2 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,10 @@ --------------------------------------------------------------------------------------------------- +Version: 1.1.12 +Game Versions: e1.8.1,e1.8.0 +* Update dependencies to fix 1.8.0 hotfix crash +* Fix faction selection issue in the kingdom diplomacy view +* Fix messenger teleportation issue +--------------------------------------------------------------------------------------------------- Version: 1.1.11 Game Versions: e1.8.0 * Compatibility with e1.8.0