From 43b04c80557c72b63ef251cd2a6101ccd6a83b6b Mon Sep 17 00:00:00 2001 From: Alexey Chernyshov Date: Sun, 11 Dec 2022 12:48:47 +0300 Subject: [PATCH 1/4] Crashfixes --- build/common.props | 6 +++--- changelog.txt | 7 ++++++- src/Bannerlord.Diplomacy/Messengers/MessengerManager.cs | 4 ++-- .../ViewModelMixin/KingdomDiplomacyVMMixin.cs | 4 +++- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/build/common.props b/build/common.props index f8b0805d..92f19e4e 100644 --- a/build/common.props +++ b/build/common.props @@ -2,8 +2,8 @@ - 1.1.17 - 1.0.1 + 1.1.18 + 1.0.0 @@ -78,7 +78,7 @@ $(SecondLine) $(LastLine) - e1.1.0 + v1.0.0 $(GameMinimalVersion) $(GameStableVersion) $(GameBetaVersion) diff --git a/changelog.txt b/changelog.txt index df1375c8..5ca0f29f 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,9 @@ --------------------------------------------------------------------------------------------------- +Version: 1.1.18 +Game Versions: v1.0.0,v1.0.1,v1.0.2 +* Fixed a crash that occurred when sending a Messenger to a hero in the field. +* Hopefully fixed a rare crash, which sometimes occurred in Kingdom Management. +--------------------------------------------------------------------------------------------------- Version: 1.1.17 Game Versions: v1.0.0,v1.0.1,v1.0.2 * Recompiled for v1.0.2. @@ -6,7 +11,7 @@ Game Versions: v1.0.0,v1.0.1,v1.0.2 * Fixed several issues with peace and war restrictions not applying properly. * Fixed a crash that occurred when sending a Messenger to a factionless hero. * Fixed a crash that occurred when trying to create a caravan using a Messenger. -* Messengers now use correct the scene for the conversation. +* Messengers now use correct scene for the conversation. * Messengers can no longer freely access highborn locations unless you can. * The speed of Messengers now depends on the maximum arrival time. * Added an explanation for why some characters may not be available to send Messengers to. diff --git a/src/Bannerlord.Diplomacy/Messengers/MessengerManager.cs b/src/Bannerlord.Diplomacy/Messengers/MessengerManager.cs index a3636019..bcf035c0 100644 --- a/src/Bannerlord.Diplomacy/Messengers/MessengerManager.cs +++ b/src/Bannerlord.Diplomacy/Messengers/MessengerManager.cs @@ -204,8 +204,8 @@ public void StartDialogue(Hero targetHero, Messenger messenger) PlayerEncounter.Start(); PlayerEncounter.Current.SetupFields(heroParty, targetParty ?? heroParty); - Campaign.Current.CurrentConversationContext = ConversationContext.Default; + if (targetSettlement != null) { _position2D = new(Hero.MainHero.GetMapPoint().Position2D); @@ -374,7 +374,7 @@ private void CleanUpSettlementEncounter(float obj) { PlayerEncounter.Finish(); - if (_position2D != Vec2.Invalid) + if (_position2D.IsValid) { MobileParty.MainParty.Position2D = _position2D; } diff --git a/src/Bannerlord.Diplomacy/ViewModelMixin/KingdomDiplomacyVMMixin.cs b/src/Bannerlord.Diplomacy/ViewModelMixin/KingdomDiplomacyVMMixin.cs index 96813d1d..2dec4056 100644 --- a/src/Bannerlord.Diplomacy/ViewModelMixin/KingdomDiplomacyVMMixin.cs +++ b/src/Bannerlord.Diplomacy/ViewModelMixin/KingdomDiplomacyVMMixin.cs @@ -43,7 +43,6 @@ private static void OnDiplomacyItemSelectionPostfix(KingdomDiplomacyVM __instanc } } - private static readonly TextObject _TAlliances = new("{=zpNalMeA}Alliances"); private static readonly TextObject _TStats = new("{=1occw3EF}Stats"); private static readonly TextObject _TOverview = new("{=OvbY5qxL}Overview"); @@ -128,6 +127,9 @@ public void ExecuteShowOverview() public void ExecuteShowStatComparison() { + if (ViewModel is null) + return; + ViewModel!.IsDisplayingStatComparisons = true; ViewModel!.IsDisplayingWarLogs = false; } From aa5d11c16a0602636ce8241623cb9a0bfcd49051 Mon Sep 17 00:00:00 2001 From: Alexey Chernyshov Date: Sun, 11 Dec 2022 13:17:32 +0300 Subject: [PATCH 2/4] Removed unnecessary switching --- .../ViewModelMixin/KingdomDiplomacyVMMixin.cs | 38 ------------------- 1 file changed, 38 deletions(-) diff --git a/src/Bannerlord.Diplomacy/ViewModelMixin/KingdomDiplomacyVMMixin.cs b/src/Bannerlord.Diplomacy/ViewModelMixin/KingdomDiplomacyVMMixin.cs index 2dec4056..e9aa8c5c 100644 --- a/src/Bannerlord.Diplomacy/ViewModelMixin/KingdomDiplomacyVMMixin.cs +++ b/src/Bannerlord.Diplomacy/ViewModelMixin/KingdomDiplomacyVMMixin.cs @@ -5,12 +5,8 @@ using Diplomacy.Event; using Diplomacy.Extensions; -using HarmonyLib; -using HarmonyLib.BUTR.Extensions; - using JetBrains.Annotations; -using System; using System.Collections.Generic; using System.Linq; @@ -26,23 +22,6 @@ namespace Diplomacy.ViewModelMixin [UsedImplicitly] internal sealed class KingdomDiplomacyVMMixin : BaseViewModelMixin { - static KingdomDiplomacyVMMixin() - { - var harmony = new Harmony("Diplomacy.ViewModelMixin.KingdomDiplomacyVMMixin"); - - harmony.Patch( - AccessTools2.Method(typeof(KingdomDiplomacyVM), "OnDiplomacyItemSelection"), - postfix: new HarmonyMethod(typeof(KingdomDiplomacyVMMixin), nameof(OnDiplomacyItemSelectionPostfix))); - } - - private static void OnDiplomacyItemSelectionPostfix(KingdomDiplomacyVM __instance, KingdomDiplomacyItemVM item) - { - if (__instance.GetPropertyValue(nameof(Mixin)) is WeakReference weakReference && weakReference.TryGetTarget(out var mixin)) - { - mixin.OnDiplomacyItemSelection(item); - } - } - private static readonly TextObject _TAlliances = new("{=zpNalMeA}Alliances"); private static readonly TextObject _TStats = new("{=1occw3EF}Stats"); private static readonly TextObject _TOverview = new("{=OvbY5qxL}Overview"); @@ -56,9 +35,6 @@ private static void OnDiplomacyItemSelectionPostfix(KingdomDiplomacyVM __instanc private bool _showOverview; private bool _showStats; - [DataSourceProperty] - public WeakReference Mixin => new(this); - [DataSourceProperty] public bool ShowOverview { get => _showOverview; set => SetField(ref _showOverview, value, nameof(ShowOverview)); } @@ -125,20 +101,6 @@ public void ExecuteShowOverview() ShowStats = false; } - public void ExecuteShowStatComparison() - { - if (ViewModel is null) - return; - - ViewModel!.IsDisplayingStatComparisons = true; - ViewModel!.IsDisplayingWarLogs = false; - } - - private void OnDiplomacyItemSelection(KingdomDiplomacyItemVM item) - { - ExecuteShowStatComparison(); - } - public override void OnRefresh() { ExecuteShowOverview(); From 97d2a1a68b1987d54b70abe847935cd621638c49 Mon Sep 17 00:00:00 2001 From: Alexey Chernyshov Date: Sun, 11 Dec 2022 13:44:41 +0300 Subject: [PATCH 3/4] Fixed Encyclopedia hero page crash --- changelog.txt | 3 ++- src/Bannerlord.Diplomacy/Messengers/MessengerManager.cs | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/changelog.txt b/changelog.txt index 5ca0f29f..57b6e735 100644 --- a/changelog.txt +++ b/changelog.txt @@ -2,7 +2,8 @@ Version: 1.1.18 Game Versions: v1.0.0,v1.0.1,v1.0.2 * Fixed a crash that occurred when sending a Messenger to a hero in the field. -* Hopefully fixed a rare crash, which sometimes occurred in Kingdom Management. +* Fixed a rare crash that sometimes occurred in Kingdom Management. +* Fixed a rare crash that occurred on Encyclopedia Hero page when the hero was imprisoned by leaderless party. --------------------------------------------------------------------------------------------------- Version: 1.1.17 Game Versions: v1.0.0,v1.0.1,v1.0.2 diff --git a/src/Bannerlord.Diplomacy/Messengers/MessengerManager.cs b/src/Bannerlord.Diplomacy/Messengers/MessengerManager.cs index bcf035c0..aa4f3b19 100644 --- a/src/Bannerlord.Diplomacy/Messengers/MessengerManager.cs +++ b/src/Bannerlord.Diplomacy/Messengers/MessengerManager.cs @@ -315,12 +315,12 @@ public static bool IsTargetHeroAvailable(Hero targetHero, out TextObject excepti TextObject reason; if (targetHero.IsDead) reason = new("{=vhsHDMil}{HERO_NAME} is dead. ", new() { ["HERO_NAME"] = targetHero.Name }); - else if (targetHero.IsPrisoner) + else if (targetHero.IsPrisoner && targetHero.PartyBelongedToAsPrisoner != null) reason = new("{=CusN2JMb}{HERO_NAME} is imprisoned {?IS_MOBILE}by{?}in{\\?} {DETENTION_PLACE}. ", new() { ["HERO_NAME"] = targetHero.Name, ["IS_MOBILE"] = targetHero.PartyBelongedToAsPrisoner.IsSettlement ? 0 : 1, - ["DETENTION_PLACE"] = targetHero.PartyBelongedToAsPrisoner.IsSettlement ? targetHero.PartyBelongedToAsPrisoner.Settlement.Name : targetHero.PartyBelongedToAsPrisoner.LeaderHero.Name + ["DETENTION_PLACE"] = targetHero.PartyBelongedToAsPrisoner.IsSettlement ? targetHero.PartyBelongedToAsPrisoner.Settlement.Name : ((targetHero.PartyBelongedToAsPrisoner.LeaderHero?.Name ?? targetHero.PartyBelongedToAsPrisoner.Name) ?? TextObject.Empty) }); else if (targetHero.IsFugitive) reason = new("{=1BISlFYx}{HERO_NAME} is fugitive and doesn't want to be found. ", new() { ["HERO_NAME"] = targetHero.Name }); From d0456dc6f6fa353491374b1d998d0906df60d19b Mon Sep 17 00:00:00 2001 From: Alexey Chernyshov Date: Sun, 11 Dec 2022 13:59:55 +0300 Subject: [PATCH 4/4] Refactoring --- .../Messengers/MessengerManager.cs | 48 ++++++++++--------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/src/Bannerlord.Diplomacy/Messengers/MessengerManager.cs b/src/Bannerlord.Diplomacy/Messengers/MessengerManager.cs index aa4f3b19..08b6d2f1 100644 --- a/src/Bannerlord.Diplomacy/Messengers/MessengerManager.cs +++ b/src/Bannerlord.Diplomacy/Messengers/MessengerManager.cs @@ -311,28 +311,7 @@ public static bool IsTargetHeroAvailable(Hero targetHero, out TextObject excepti if (!available) { exception = new("{=bLR91Eob}{REASON}The messenger won't be able to reach the addressee."); - - TextObject reason; - if (targetHero.IsDead) - reason = new("{=vhsHDMil}{HERO_NAME} is dead. ", new() { ["HERO_NAME"] = targetHero.Name }); - else if (targetHero.IsPrisoner && targetHero.PartyBelongedToAsPrisoner != null) - reason = new("{=CusN2JMb}{HERO_NAME} is imprisoned {?IS_MOBILE}by{?}in{\\?} {DETENTION_PLACE}. ", new() - { - ["HERO_NAME"] = targetHero.Name, - ["IS_MOBILE"] = targetHero.PartyBelongedToAsPrisoner.IsSettlement ? 0 : 1, - ["DETENTION_PLACE"] = targetHero.PartyBelongedToAsPrisoner.IsSettlement ? targetHero.PartyBelongedToAsPrisoner.Settlement.Name : ((targetHero.PartyBelongedToAsPrisoner.LeaderHero?.Name ?? targetHero.PartyBelongedToAsPrisoner.Name) ?? TextObject.Empty) - }); - else if (targetHero.IsFugitive) - reason = new("{=1BISlFYx}{HERO_NAME} is fugitive and doesn't want to be found. ", new() { ["HERO_NAME"] = targetHero.Name }); - else if (targetHero.IsReleased) - reason = new("{=ze8KJ1oL}{HERO_NAME} has just been released from custody and is not yet ready to make appointments. ", new() { ["HERO_NAME"] = targetHero.Name }); - else if (targetHero.IsTraveling) - reason = new("{=N5T6IXWJ}{HERO_NAME} is traveling incognito. ", new() { ["HERO_NAME"] = targetHero.Name }); - else if (targetHero.IsChild) - reason = new("{=3lknR86H}{HERO_NAME} is too inexperienced to participate in formal meetings. ", new() { ["HERO_NAME"] = targetHero.Name }); - else - reason = TextObject.Empty; - + var reason = GetUnavailabilityReason(targetHero); exception.SetTextVariable("REASON", reason); return false; } @@ -347,6 +326,31 @@ public static bool IsTargetHeroAvailable(Hero targetHero, out TextObject excepti return true; } + private static TextObject GetUnavailabilityReason(Hero targetHero) + { + TextObject reason; + if (targetHero.IsDead) + reason = new("{=vhsHDMil}{HERO_NAME} is dead. ", new() { ["HERO_NAME"] = targetHero.Name }); + else if (targetHero.IsPrisoner && targetHero.PartyBelongedToAsPrisoner != null) + reason = new("{=CusN2JMb}{HERO_NAME} is imprisoned {?IS_MOBILE}by{?}in{\\?} {DETENTION_PLACE}. ", new() + { + ["HERO_NAME"] = targetHero.Name, + ["IS_MOBILE"] = targetHero.PartyBelongedToAsPrisoner.IsSettlement ? 0 : 1, + ["DETENTION_PLACE"] = targetHero.PartyBelongedToAsPrisoner.IsSettlement ? targetHero.PartyBelongedToAsPrisoner.Settlement.Name : ((targetHero.PartyBelongedToAsPrisoner.LeaderHero?.Name ?? targetHero.PartyBelongedToAsPrisoner.Name) ?? TextObject.Empty) + }); + else if (targetHero.IsFugitive) + reason = new("{=1BISlFYx}{HERO_NAME} is fugitive and doesn't want to be found. ", new() { ["HERO_NAME"] = targetHero.Name }); + else if (targetHero.IsReleased) + reason = new("{=ze8KJ1oL}{HERO_NAME} has just been released from custody and is not yet ready to make appointments. ", new() { ["HERO_NAME"] = targetHero.Name }); + else if (targetHero.IsTraveling) + reason = new("{=N5T6IXWJ}{HERO_NAME} is traveling incognito. ", new() { ["HERO_NAME"] = targetHero.Name }); + else if (targetHero.IsChild) + reason = new("{=3lknR86H}{HERO_NAME} is too inexperienced to participate in formal meetings. ", new() { ["HERO_NAME"] = targetHero.Name }); + else + reason = TextObject.Empty; + return reason; + } + public static bool IsTargetHeroAvailableNow(Hero targetHero) { return IsTargetHeroAvailable(targetHero) && targetHero.PartyBelongedTo?.MapEvent == null;