Skip to content

Commit

Permalink
Merge pull request #2 from Designer225/e1.4.1
Browse files Browse the repository at this point in the history
v1.0.0
* Merged fixes to a single mod.
* Included settings to enable and disable patches.
  • Loading branch information
Designer225 committed May 22, 2020
2 parents c464664 + db38f09 commit eb2047b
Show file tree
Hide file tree
Showing 64 changed files with 15,570 additions and 14 deletions.
Binary file modified FixedBanditSpawning/.vs/FixedBanditSpawning/v16/.suo
Binary file not shown.
Binary file not shown.
27 changes: 27 additions & 0 deletions FixedBanditSpawning/D225MiscFixesSettings.Localisation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TaleWorlds.Localization;

namespace FixedBanditSpawning
{
public partial class D225MiscFixesSettings
{
private const string ModNameText = "{=ModNameText}Designer225's Miscellaneous Fixes",

PatchBanditSpawningName = "{=PatchBanditSpawningName}Patch Bandit Spawning",
PatchBanditSpawningHint = "{=PatchBanditSpawningHint}Enable this to patch bandit spawning to allow more than 3 types of troops. Disable if another mod also does this.",
PatchAgentSpawningName = "{=PatchAgentSpawningName}Patch Agent Spawning",
PatchAgentSpawningHint = "{=PatchAgentSpawningHint}Enable this to bypass age check that makes underage agents look adult-ish. Disable if another mod also does this.",
PatchInvincibleChildrenName = "{=PatchInvincibleChildrenName}Patch Invincible Children",
PatchInvincibleChildrenHint = "{=PatchInvincibleChildrenHint}Enable this to make children less overpowered. Disable if another mod also does this.",
PatchWandererSpawningName = "{=PatchWandererSpawningName}Patch Wander Spawning",
PatchWandererSpawningHint = "{=PatchWandererSpawningHint}Enable this to get rid of the arbitrary minimum of 20 years for wanderer spawning and also to increase the age range to from adult age to adult age + 32. Disable if another mod also does this.",
WanderSpawningRngMaxName = "{=WanderSpawningRngMaxName}Wanderer Max RNG Age Increase",
WanderSpawningRngMaxHint = "{=WanderSpawningRngMaxHint}Sets the maximum age increase of wanderers during game start. Default is 32 years (originally 5 + randomized max 27). Does not require restart unlike other options.";

private static readonly TextObject ModNameTextObject = new TextObject(ModNameText);
}
}
37 changes: 37 additions & 0 deletions FixedBanditSpawning/D225MiscFixesSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MBOptionScreen.Settings;
using MBOptionScreen.Attributes;
using MBOptionScreen.Attributes.v2;

namespace FixedBanditSpawning
{
public partial class D225MiscFixesSettings : AttributeSettings<D225MiscFixesSettings>
{
public override string Id { get; set; } = "D225.MiscFixes";

public override string ModuleFolderName => "D225.MiscFixes";

public override string ModName => ModNameTextObject.ToString();

[SettingPropertyBool(PatchBanditSpawningName, HintText = PatchBanditSpawningHint, Order = 0, RequireRestart = true)]
public bool PatchBanditSpawning { get; set; } = true;

[SettingPropertyBool(PatchAgentSpawningName, HintText = PatchAgentSpawningHint, Order = 1, RequireRestart = true)]
public bool PatchAgentSpawning { get; set; } = true;

[SettingPropertyBool(PatchInvincibleChildrenName, HintText = PatchInvincibleChildrenHint, Order = 2, RequireRestart = true)]
public bool PatchInvincibleChildren { get; set; } = true;

[SettingPropertyBool(PatchWandererSpawningName, HintText = PatchWandererSpawningHint, Order = 3, RequireRestart = true)]
public bool PatchWandererSpawning { get; set; } = true;

[SettingPropertyInteger(WanderSpawningRngMaxName, 0, 50, HintText = WanderSpawningRngMaxHint, Order = 4, RequireRestart = false)]
public int WanderSpawningRngMax { get; set; } = 32;

public static int WandererRngMaxAge => Instance != null ? Instance.WanderSpawningRngMax : 32;
}
}
12 changes: 9 additions & 3 deletions FixedBanditSpawning/FixedBanditSpawning.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony, Version=2.0.0.10, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\Lib.Harmony.2.0.0.10\lib\net472\0Harmony.dll</HintPath>
<Reference Include="0Harmony, Version=2.0.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\Lib.Harmony.2.0.1\lib\net472\0Harmony.dll</HintPath>
</Reference>
<Reference Include="MBOptionScreen.v2.0.10, Version=2.0.10.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\Bannerlord.MBOptionScreen.2.0.10\lib\net472\MBOptionScreen.v2.0.10.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down Expand Up @@ -72,6 +75,8 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="D225MiscFixesSettings.cs" />
<Compile Include="D225MiscFixesSettings.Localisation.cs" />
<Compile Include="SubModule.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand All @@ -83,6 +88,7 @@
<PostBuildEvent>cd "$(TargetDir)"
xcopy $(TargetFileName) ..\..\..\bin\Win64_Shipping_Client /y
xcopy $(TargetName).pdb ..\..\..\bin\Win64_Shipping_Client /y
xcopy 0Harmony.dll ..\..\..\bin\Win64_Shipping_Client /y</PostBuildEvent>
xcopy 0Harmony.dll ..\..\..\bin\Win64_Shipping_Client /y
xcopy MBOptionScreen.v2.0.10.dll ..\..\..\bin\Win64_Shipping_Client /y</PostBuildEvent>
</PropertyGroup>
</Project>
1 change: 0 additions & 1 deletion FixedBanditSpawning/FixedBanditSpawning.sln
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Global
{04689F95-E972-42D4-ABB6-FDAA38EE554F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{04689F95-E972-42D4-ABB6-FDAA38EE554F}.Release|Any CPU.Build.0 = Release|Any CPU
{7EB1399A-ABA1-45AA-BACA-882BF02B57E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7EB1399A-ABA1-45AA-BACA-882BF02B57E3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7EB1399A-ABA1-45AA-BACA-882BF02B57E3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7EB1399A-ABA1-45AA-BACA-882BF02B57E3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
Expand Down
150 changes: 149 additions & 1 deletion FixedBanditSpawning/SubModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,23 @@ protected override void OnSubModuleLoad()
[HarmonyPatch(typeof(MobileParty), "FillPartyStacks")]
public static class MobileParty_FillPartyStacks_Patch
{
public static bool Prepare()
{
if (D225MiscFixesSettings.Instance != null && D225MiscFixesSettings.Instance.PatchBanditSpawning)
{
Debug.Print("[FixedBanditSpawning] Will patch bandit spawning in MobileParty.FillPartyStack()");
return true;
}
Debug.Print("[FixedBanditSpawning] Will NOT patch bandit spawning in MobileParty.FillPartyStack()");
return false;
}

public static bool Prefix(MobileParty __instance, PartyTemplateObject pt, MobileParty.PartyTypeEnum partyType, int troopNumberLimit)
{
switch (partyType)
{
case MobileParty.PartyTypeEnum.Bandit: // TaleWorlds hardcoding strikes again
double num1 = 0.33 + 0.67 * MiscHelper.GetGameProcess();
double num1 = 0.4 + 0.6 * MiscHelper.GetGameProcess();
int num2 = MBRandom.RandomInt(2);
double num3 = num2 == 0 ? MBRandom.RandomFloat : (MBRandom.RandomFloat * MBRandom.RandomFloat * MBRandom.RandomFloat * 4.0);
double num4 = num2 == 0 ? (num3 * 0.8 + 0.2) : 1 + num3;
Expand Down Expand Up @@ -65,6 +76,14 @@ public static bool Prefix(MobileParty __instance, PartyTemplateObject pt, Mobile
[HarmonyPatch(typeof(Mission), nameof(Mission.SpawnAgent))]
public static class Mission_SpawnAgent_Patch
{
public static bool Prepare()
{
if (D225MiscFixesSettings.Instance != null && D225MiscFixesSettings.Instance.PatchAgentSpawning)
return true;
Debug.Print("[FixedBanditSpawning] Will NOT attempt tp bypass age checker in Mission.SpawnAgent()");
return false;
}

public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
Debug.Print("[FixedBanditSpawning] Attempting to bypass age checker in Mission.SpawnAgent()");
Expand Down Expand Up @@ -168,6 +187,17 @@ public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructio
[HarmonyPatch(typeof(Mission), "BuildAgent")]
public static class Mission_BuildAgent_Patch
{
public static bool Prepare()
{
if (D225MiscFixesSettings.Instance != null && D225MiscFixesSettings.Instance.PatchInvincibleChildren)
{
Debug.Print("[FixedBanditSpawning] Will patch invincible children");
return true;
}
Debug.Print("[FixedBanditSpawning] Will NOT patch invincible children");
return false;
}

public static void Postfix(ref Agent agent)
{
if (agent.IsHuman && agent.Age < 18f)
Expand All @@ -189,4 +219,122 @@ public static void Postfix(ref Agent agent)
}
}
}

[HarmonyPatch(typeof(HeroCreator), "CreateNewHero")]
public static class HeroCreator_CreateNewHero_Patch
{
public static bool Prepare()
{
if (D225MiscFixesSettings.Instance != null && D225MiscFixesSettings.Instance.PatchWandererSpawning)
return true;
Debug.Print("[FixedBanditSpawning] Will NOT attempt to patch age checkers in HeroCreator.CreateNewHero()");
return false;
}

public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
Debug.Print("[FixedBanditSpawning] Attempting to bypass 2 age checkers in HeroCreator.CreateNewHero()");
var codes = instructions.ToList();

int stage0 = 0;
for (int j = 0; j < codes.Count; j++)
{
if (codes[j].opcode == OpCodes.Ldarg_0)
{
if (stage0 == 0)
{
stage0 = 1;
}
else if (stage0 == 1)
{
codes[j] = new CodeInstruction(OpCodes.Nop);
codes[j + 1] = new CodeInstruction(OpCodes.Nop);
codes[j + 2] = new CodeInstruction(OpCodes.Nop);
codes[j + 3] = new CodeInstruction(OpCodes.Nop);
Debug.Print("[FixedBanditSpawning] Age checker 1 in HeroCreator.CreateNewHero() bypassed :)");
break;
}
}
}

int stage = 0;
int replaceIndex = -1;
Label jumpLabel = default;
for (int i = 0; i < codes.Count; i++)
{
if (stage == 0 && codes[i].opcode == OpCodes.Ldarg_1)
{
stage = 1;
replaceIndex = i;
}
else if (stage == 1)
{
if (codes[i].opcode == OpCodes.Ldc_I4_S)
{
stage = 2;
}
else
{
stage = 0;
replaceIndex = -1;
}
}
else if (stage == 2)
{
if (codes[i].opcode == OpCodes.Bge_S && codes[i].operand is Label)
{
jumpLabel = (Label)(codes[i].operand);
break;
}
else
{
stage = 0;
replaceIndex = -1;
}
}
}

if (replaceIndex != -1 && jumpLabel != default)
{
codes[replaceIndex] = new CodeInstruction(OpCodes.Br, jumpLabel);
Debug.Print("[FixedBanditSpawning] Age checker 2 in HeroCreator.CreateNewHero() bypassed :)");
}

return codes.AsEnumerable();
}
}

[HarmonyPatch(typeof(UrbanCharactersCampaignBehavior), "CreateCompanion")]
public static class UrbanCharactersCampaignBehavior_CreateCompanion_Patch
{
public static bool Prepare()
{
if (D225MiscFixesSettings.Instance != null && D225MiscFixesSettings.Instance.PatchWandererSpawning)
return true;
Debug.Print("[FixedBanditSpawning] Will NOT attempt to bypass artificial age adder in UrbanCharactersCampaignBehavior.CreateCompanion()");
return false;
}

public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
Debug.Print("[FixedBanditSpawning] Attempting to bypass artificial age adder in UrbanCharactersCampaignBehavior.CreateCompanion()");
var codes = instructions.ToList();

for (int i = 0; i < codes.Count; i++)
{
if (codes[i].opcode == OpCodes.Callvirt
&& codes[i].operand is MethodInfo && codes[i].operand as MethodInfo == AccessTools.PropertyGetter(typeof(AgeModel), nameof(AgeModel.HeroComesOfAge)))
{
codes[i + 1] = new CodeInstruction(OpCodes.Nop);
codes[i + 2] = new CodeInstruction(OpCodes.Nop);
codes[i + 3] = new CodeInstruction(OpCodes.Call,
AccessTools.PropertyGetter(typeof(D225MiscFixesSettings), nameof(D225MiscFixesSettings.WandererRngMaxAge)));
Debug.Print("[FixedBanditSpawning] Artificial age adder in UrbanCharactersCampaignBehavior.CreateCompanion() bypassed :)");
break;
}
}

return codes.AsEnumerable();
}
}
}
Binary file modified FixedBanditSpawning/bin/Debug/0Harmony.dll
Binary file not shown.
35 changes: 29 additions & 6 deletions FixedBanditSpawning/bin/Debug/0Harmony.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified FixedBanditSpawning/bin/Debug/FixedBanditSpawning.dll
Binary file not shown.
Binary file modified FixedBanditSpawning/bin/Debug/FixedBanditSpawning.pdb
Binary file not shown.
Binary file not shown.
Binary file modified FixedBanditSpawning/bin/Debug/Newtonsoft.Json.dll
Binary file not shown.
Binary file modified FixedBanditSpawning/bin/Debug/TaleWorlds.BattlEye.Client.dll
Binary file not shown.
Binary file modified FixedBanditSpawning/bin/Debug/TaleWorlds.CampaignSystem.dll
Binary file not shown.
Binary file modified FixedBanditSpawning/bin/Debug/TaleWorlds.Core.dll
Binary file not shown.
Binary file not shown.
Binary file modified FixedBanditSpawning/bin/Debug/TaleWorlds.Diamond.dll
Binary file not shown.
Binary file modified FixedBanditSpawning/bin/Debug/TaleWorlds.DotNet.dll
Binary file not shown.
Binary file modified FixedBanditSpawning/bin/Debug/TaleWorlds.Engine.dll
Binary file not shown.
Binary file modified FixedBanditSpawning/bin/Debug/TaleWorlds.InputSystem.dll
Binary file not shown.
Binary file modified FixedBanditSpawning/bin/Debug/TaleWorlds.Library.dll
Binary file not shown.
Binary file modified FixedBanditSpawning/bin/Debug/TaleWorlds.Localization.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified FixedBanditSpawning/bin/Debug/TaleWorlds.MountAndBlade.dll
Binary file not shown.
Binary file modified FixedBanditSpawning/bin/Debug/TaleWorlds.Network.dll
Binary file not shown.
Binary file modified FixedBanditSpawning/bin/Debug/TaleWorlds.ObjectSystem.dll
Binary file not shown.
Binary file modified FixedBanditSpawning/bin/Debug/TaleWorlds.PSAI.dll
Binary file not shown.
Binary file modified FixedBanditSpawning/bin/Debug/TaleWorlds.PlatformService.dll
Binary file not shown.
Binary file modified FixedBanditSpawning/bin/Debug/TaleWorlds.PlayerServices.dll
Binary file not shown.
Binary file modified FixedBanditSpawning/bin/Debug/TaleWorlds.SaveSystem.dll
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ D:\SteamLibrary\steamapps\common\Mount & Blade II Bannerlord\Modules\FixedBandit
D:\SteamLibrary\steamapps\common\Mount & Blade II Bannerlord\Modules\FixedBanditSpawning\FixedBanditSpawning\obj\Debug\FixedBanditSpawning.pdb
D:\SteamLibrary\steamapps\common\Mount & Blade II Bannerlord\Modules\FixedBanditSpawning\FixedBanditSpawning\obj\Debug\FixedBanditSpawning.csprojAssemblyReference.cache
D:\SteamLibrary\steamapps\common\Mount & Blade II Bannerlord\Modules\FixedBanditSpawning\FixedBanditSpawning\bin\Debug\TaleWorlds.ObjectSystem.dll
D:\SteamLibrary\steamapps\common\Mount & Blade II Bannerlord\Modules\FixedBanditSpawning\FixedBanditSpawning\bin\Debug\MBOptionScreen.v2.0.10.dll
Binary file not shown.
Binary file modified FixedBanditSpawning/obj/Debug/FixedBanditSpawning.dll
Binary file not shown.
Binary file modified FixedBanditSpawning/obj/Debug/FixedBanditSpawning.pdb
Binary file not shown.
3 changes: 2 additions & 1 deletion FixedBanditSpawning/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Lib.Harmony" version="2.0.0.10" targetFramework="net472" />
<package id="Bannerlord.MBOptionScreen" version="2.0.10" targetFramework="net472" />
<package id="Lib.Harmony" version="2.0.1" targetFramework="net472" />
</packages>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit eb2047b

Please sign in to comment.