Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for 1.5.4 beta #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions MercenaryArmy/MercenaryArmy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,6 @@
<Reference Include="TaleWorlds.ObjectSystem">
<HintPath>$(MOUNT_AND_BLADE_DIR)bin\Win64_Shipping_Client\TaleWorlds.ObjectSystem.dll</HintPath>
</Reference>
<Reference Include="ModLib">
<HintPath>$(MODLIB)</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="ModLib.Definitions">
<HintPath>$(MODLIB_DEFS)</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand All @@ -80,7 +72,6 @@
<ItemGroup>
<Compile Include="MercenaryArmyMod.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Settings.cs" />
<Compile Include="SubModule.cs" />
</ItemGroup>
<ItemGroup>
Expand All @@ -91,6 +82,5 @@
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(MOD_FOLDER)\bin\Win64_Shipping_Client\" />
<Copy SourceFiles="$(ProjectDir)\SubModule.xml" DestinationFolder="$(MOD_FOLDER)" />
<Copy SourceFiles="$(HARMONY_DLL)" DestinationFolder="$(MOD_FOLDER)\bin\Win64_Shipping_Client\" />
<Copy SourceFiles="$(MODLIB_DEFS)" DestinationFolder="$(MOD_FOLDER)\bin\Win64_Shipping_Client\" />
</Target>
</Project>
123 changes: 106 additions & 17 deletions MercenaryArmy/MercenaryArmyMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using HarmonyLib;
using TaleWorlds.Core;
Expand All @@ -13,7 +11,8 @@
using TaleWorlds.CampaignSystem.ViewModelCollection;
using TaleWorlds.CampaignSystem.ViewModelCollection.ArmyManagement;
using TaleWorlds.CampaignSystem.Actions;
using TaleWorlds.ObjectSystem;
using TaleWorlds.CampaignSystem.Siege;
using TaleWorlds.CampaignSystem.GameMenus;

namespace MercenaryArmy
{
Expand All @@ -26,9 +25,10 @@ static void Postfix(ref bool __result, ref string reasonText)
{
if (!errs.Any())
{
// Only enable the army button for independents if the hack is enabled
if (Settings.Instance.CreatePlayerKingdom)
errs.Add(GameTexts.FindText("str_need_to_be_a_part_of_kingdom", (string)null).ToString());

//No need for cheat anymore
//if (Settings.Instance.CreatePlayerKingdom)
errs.Add(GameTexts.FindText("str_need_to_be_a_part_of_kingdom", (string)null).ToString());
errs.Add(GameTexts.FindText("str_mercenary_cannot_manage_army", (string)null).ToString());
}

Expand Down Expand Up @@ -59,14 +59,97 @@ static void Postfix(ArmyManagementVM __instance)
}
}


/// <summary>
/// Initialise hourly tick for armies not in kingdom from player
/// </summary>
[HarmonyPatch(typeof(Campaign), "InitializeCampaignObjectsOnAfterLoad")]
public class CampaignMod
{
static void Postfix(Campaign __instance)
{
if (__instance.MainParty.Army != null)
{
Traverse traverse = Traverse.Create((object)__instance.MainParty.Army).Method("OnAfterLoad", (object[])null);
if (traverse.MethodExists())
{
traverse.GetValue();
}
}
}
}

[HarmonyPatch(typeof(MobileParty), "ConsiderMapEventsAndSiegesInternal")]
public class MobilePartyMod
{
static bool Prefix(MobileParty __instance, IFaction factionToConsiderAgainst)
{
//we exit and go back to normal if army is not player's army
if (__instance.Army == null || __instance.Army.LeaderParty == null || !__instance.Army.LeaderParty.IsMainParty)
return true;
if (__instance.Army != null && __instance.Army.Kingdom != null && __instance.Army.Kingdom != __instance.MapFaction)
__instance.Army = (Army)null;
if (__instance.CurrentSettlement != null)
{
IFaction mapFaction = __instance.CurrentSettlement.MapFaction;
if (mapFaction != null && mapFaction.IsAtWarWith(__instance.MapFaction) && __instance.IsRaiding || __instance.IsMainParty && (PlayerEncounter.Current.ForceRaid || PlayerEncounter.Current.ForceSupplies || PlayerEncounter.Current.ForceVolunteers))
return false;
}
if (__instance.Party.MapEventSide != null)
{
IFaction mapFaction1 = __instance.Party.MapEventSide.OtherSide.MapFaction;
IFaction mapFaction2 = __instance.Party.MapEventSide.MapFaction;
BattleSideEnum side = PlayerEncounter.Battle != null ? PlayerEncounter.Battle.PlayerSide : BattleSideEnum.None;
if (mapFaction1 == null || !mapFaction1.IsAtWarWith(__instance.MapFaction) && mapFaction1 == factionToConsiderAgainst)
{
if (__instance.Party == PartyBase.MainParty && PlayerEncounter.Current != null && __instance.Party.SiegeEvent != null)
PlayerEncounter.Current.SetPlayerSiegeInterruptedByPeace();
__instance.Party.MapEventSide = (MapEventSide)null;
}
else if (mapFaction2 == null || mapFaction2.IsAtWarWith(__instance.MapFaction) && mapFaction1 == factionToConsiderAgainst)
__instance.Party.MapEventSide = (MapEventSide)null;
if (__instance.Party == PartyBase.MainParty && PlayerEncounter.Current != null && (PlayerEncounter.Battle != null && PlayerEncounter.Battle.PartiesOnSide(GetOtherSide(side)).Any<PartyBase>((Func<PartyBase, bool>)(x => x.MapFaction == factionToConsiderAgainst))) && !PlayerEncounter.EncounteredParty.MapFaction.IsAtWarWith(MobileParty.MainParty.MapFaction))
PlayerEncounter.Finish(true);
}
if (__instance.BesiegerCamp != null)
{
IFaction mapFaction1 = __instance.BesiegerCamp.SiegeEvent.BesiegedSettlement.MapFaction;
IFaction mapFaction2 = __instance.BesiegerCamp.BesiegerParty?.MapFaction;
if (mapFaction1 == null || !mapFaction1.IsAtWarWith(__instance.MapFaction) && mapFaction1 == factionToConsiderAgainst)
__instance.BesiegerCamp = (BesiegerCamp)null;
else if (mapFaction2 == null || mapFaction2.IsAtWarWith(__instance.MapFaction) && mapFaction1 == factionToConsiderAgainst)
__instance.BesiegerCamp = (BesiegerCamp)null;
}
if (__instance.CurrentSettlement == null)
return false;
IFaction mapFaction3 = __instance.CurrentSettlement.MapFaction;
if (mapFaction3 == null || mapFaction3 != factionToConsiderAgainst || !mapFaction3.IsAtWarWith(__instance.MapFaction))
return false;
if (__instance.IsMainParty && !__instance.IsRaiding)
{
if (GameStateManager.Current.ActiveState.IsMission || !__instance.CurrentSettlement.IsFortification)
return false;
GameMenu.SwitchToMenu("fortification_crime_rating");
}
else
LeaveSettlementAction.ApplyForParty(__instance);
return false;
}

private static BattleSideEnum GetOtherSide(BattleSideEnum side)
{
return side != BattleSideEnum.Attacker ? BattleSideEnum.Attacker : BattleSideEnum.Defender;
}
}

[HarmonyPatch(typeof(ArmyManagementVM), "ExecuteDone")]
public class ExecuteDoneMod
{
static bool Prefix(ArmyManagementVM __instance, MBBindingList<ArmyManagementItemVM> ____partiesToRemove, Action ____onClose)
{
// Only enable this hack if it is enabled and player is independent
// Only enable if player is independent
// THIS IS A PORT OF ArmyManagementVM.ExecuteDone!
if (!Hero.MainHero.MapFaction.IsKingdomFaction && Settings.Instance.CreatePlayerKingdom)
if (!Hero.MainHero.MapFaction.IsKingdomFaction)
{
int num = __instance.PartiesInCart.Sum<ArmyManagementItemVM>((Func<ArmyManagementItemVM, int>)(P => P.Cost));
bool flag1 = (double)num <= (double)Hero.MainHero.Clan.Influence;
Expand All @@ -85,17 +168,23 @@ static bool Prefix(ArmyManagementVM __instance, MBBindingList<ArmyManagementItem
{
if (MobileParty.MainParty.Army == null)
{
string err = "";
if (!CampaignCheats.CheckCheatUsage(ref err))
Army army = new Army((Kingdom)null, Hero.MainHero.PartyBelongedTo, Army.ArmyTypes.Patrolling, Hero.MainHero.HomeSettlement, (Hero)null)
{
AIBehavior = Army.AIBehaviorFlags.Gathering
};
army.Gather();
Traverse traverse = Traverse.Create((object)CampaignEventDispatcher.Instance).Method("OnArmyCreated", new Type[1]
{
InformationMessage im = new InformationMessage(err);
InformationManager.DisplayMessage(im);
return false;
typeof (Army)
}, (object[])null);
if (traverse.MethodExists())
{
traverse.GetValue((object)army);
}
if (army.LeaderParty.LeaderHero == Hero.MainHero && (Game.Current.GameStateManager.GameStates.Single<GameState>((Func<GameState, bool>)(S => S is MapState)) is MapState mapState))
{
mapState.OnArmyCreated(MobileParty.MainParty);
}
if ((MobileParty.MainParty.MapFaction as Kingdom) is null)
CampaignCheats.CreatePlayerKingdom(new List<string>());

((Kingdom)MobileParty.MainParty.MapFaction).CreateArmy(Hero.MainHero, (IMapPoint)Hero.MainHero.HomeSettlement, Army.ArmyTypes.Patrolling);
}
foreach (ArmyManagementItemVM managementItemVm in (Collection<ArmyManagementItemVM>)__instance.PartiesInCart)
{
Expand Down
4 changes: 2 additions & 2 deletions MercenaryArmy/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.2.1")]
[assembly: AssemblyFileVersion("1.0.2.1")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]