Skip to content

Commit

Permalink
Merge pull request #88 from DiplomacyTeam/dev
Browse files Browse the repository at this point in the history
1.1.12 Fixes
  • Loading branch information
artifixer authored Oct 8, 2022
2 parents 329a919 + c421018 commit 621322a
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 32 deletions.
11 changes: 5 additions & 6 deletions build/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,20 @@
<!--Harmony Version-->
<HarmonyVersion>2.2.1</HarmonyVersion>
<!--ButterLib Version-->
<ButterLibVersion>2.1.5</ButterLibVersion>
<ButterLibVersion>2.1.13</ButterLibVersion>
<!--MCM Version-->
<MCMVersion>4.7.3</MCMVersion>
<MCMVersion>4.7.7</MCMVersion>
<!--UIExtenderEx Version-->
<UIExtenderExVersion>2.2.1</UIExtenderExVersion>
<UIExtenderExVersion>2.2.5</UIExtenderExVersion>
<!--BUTRShared Version-->
<BUTRSharedVersion>2.0.0.82</BUTRSharedVersion>
<BUTRSharedVersion>2.0.0.86</BUTRSharedVersion>
<!--BUTRModuleManager Version-->
<BUTRModuleManagerVersion>3.0.97</BUTRModuleManagerVersion>
<BUTRModuleManagerVersion>4.0.121</BUTRModuleManagerVersion>
<!--ModuleLoader Version-->
<BUTRModuleLoaderVersion>1.0.1.36</BUTRModuleLoaderVersion>
<!--Harmony Extensions Version-->
<HarmonyExtensionsVersion>3.1.0.61</HarmonyExtensionsVersion>
</PropertyGroup>

<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<Platforms>x64</Platforms>
Expand Down
6 changes: 6 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Bannerlord.Diplomacy/Bannerlord.Diplomacy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
and we need to reference that old version instead of the latest. -->
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" IncludeAssets="compile" />
<!-- Enable NET5 Features on NET472 -->
<PackageReference Include="IsExternalInit" Version="1.0.2">
<PackageReference Include="IsExternalInit" Version="1.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Nullable" Version="1.3.0">
<PackageReference Include="Nullable" Version="1.3.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
32 changes: 10 additions & 22 deletions src/Bannerlord.Diplomacy/Messengers/MessengerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,7 +32,7 @@ internal sealed class MessengerManager : IMissionListener
private Messenger? _activeMessenger;
private Mission? _currentMission;

[SaveableField(1)] [UsedImplicitly] private List<Messenger> _messengers;
[SaveableField(1)][UsedImplicitly] private List<Messenger> _messengers;

public MBReadOnlyList<Messenger> Messengers { get; private set; }

Expand Down Expand Up @@ -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);
}

Expand Down
3 changes: 2 additions & 1 deletion src/Bannerlord.Diplomacy/PatchTools/PatchManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
};
}
Expand Down
60 changes: 60 additions & 0 deletions src/Bannerlord.Diplomacy/Patches/ViewModelPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
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<ViewModelPatch>
{
protected override IEnumerable<Patch> 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>((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();
}
}
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>((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();
}
}
}
}
}

0 comments on commit 621322a

Please sign in to comment.