Skip to content

Commit

Permalink
Merge pull request #1 from Designer225/e1.3
Browse files Browse the repository at this point in the history
e1.3 recompile and repatching
  • Loading branch information
Designer225 committed May 8, 2020
2 parents f87bd73 + 766f55d commit 0ac92b3
Show file tree
Hide file tree
Showing 62 changed files with 95 additions and 13 deletions.
Binary file modified FixedBanditSpawning/.vs/FixedBanditSpawning/v16/.suo
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
7 changes: 7 additions & 0 deletions FixedBanditSpawning/FixedBanditSpawning.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\bin\Win64_Shipping_Client\TaleWorlds.DotNet.dll</HintPath>
</Reference>
<Reference Include="TaleWorlds.Engine, Version=1.0.0.0, Culture=neutral, processorArchitecture=AMD64">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\bin\Win64_Shipping_Client\TaleWorlds.Engine.dll</HintPath>
</Reference>
<Reference Include="TaleWorlds.Library">
<HintPath>..\..\..\bin\Win64_Shipping_Client\TaleWorlds.Library.dll</HintPath>
</Reference>
Expand All @@ -63,6 +67,9 @@
<Reference Include="TaleWorlds.MountAndBlade">
<HintPath>..\..\..\bin\Win64_Shipping_Client\TaleWorlds.MountAndBlade.dll</HintPath>
</Reference>
<Reference Include="TaleWorlds.ObjectSystem">
<HintPath>..\..\..\bin\Win64_Shipping_Client\TaleWorlds.ObjectSystem.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="SubModule.cs" />
Expand Down
94 changes: 83 additions & 11 deletions FixedBanditSpawning/SubModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using TaleWorlds.CampaignSystem;
using TaleWorlds.CampaignSystem.SandBox.CampaignBehaviors;
using TaleWorlds.Core;
using TaleWorlds.Engine;
using TaleWorlds.Library;
using TaleWorlds.MountAndBlade;
using Helpers;
Expand All @@ -17,11 +18,14 @@ namespace FixedBanditSpawning
{
public class SubModule : MBSubModuleBase
{
//internal static Dictionary<Agent, float> AgentAgeDict { get; set; } = new Dictionary<Agent, float>();

protected override void OnSubModuleLoad()
{
base.OnSubModuleLoad();

new Harmony("d225.fixedbanditspawning").PatchAll();
Harmony harmony = new Harmony("d225.fixedbanditspawning");
harmony.PatchAll();
}
}

Expand Down Expand Up @@ -71,27 +75,25 @@ public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructio
Label jumpLabel = default;
for (int i = 0; i < codes.Count; i++)
{
if (stage == 0 && codes[i].opcode == OpCodes.Ldarg_0)
if (stage == 0 && codes[i].opcode == OpCodes.Ldloc_3)
{
stage = 1;
replaceIndex = i;
}
else if (stage == 1)
{
if (codes[i].opcode == OpCodes.Call
&& codes[i].operand is MethodInfo && codes[i].operand as MethodInfo == AccessTools.PropertyGetter(typeof(Mission), nameof(Mission.Mode)))
if (codes[i].opcode == OpCodes.Brtrue_S && codes[i].operand is Label)
{
stage = 2;
replaceIndex = i;
}
else
{
stage = 0;
replaceIndex = -1;
}
}
else if (stage == 2)
{
if (codes[i].opcode == OpCodes.Ldc_I4_2)
if (codes[i].opcode == OpCodes.Ldarg_1)
{
stage = 3;
}
Expand All @@ -101,20 +103,90 @@ public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructio
replaceIndex = -1;
}
}
else if (stage == 3 && codes[i].opcode == OpCodes.Bne_Un_S && codes[i].operand is Label)
else if (stage == 3)
{
if (codes[i].opcode == OpCodes.Ldc_I4_S)
{
stage = 4;
}
else
{
stage = 0;
replaceIndex = -1;
}
}
else if (stage == 4)
{
if (codes[i].opcode == OpCodes.Callvirt && codes[i].operand is MethodInfo
&& codes[i].operand as MethodInfo == AccessTools.Method(typeof(AgentBuildData), nameof(AgentBuildData.Age)))
{
stage = 5;
}
else
{
stage = 0;
replaceIndex = -1;
}
}
else if (stage == 5)
{
if (codes[i].opcode == OpCodes.Pop)
{
stage = 6;
}
else
{
stage = 0;
replaceIndex = -1;
}
}
else if (stage == 6)
{
jumpLabel = (Label)(codes[i].operand);
break;
if (codes[i].opcode == OpCodes.Br_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);
codes[replaceIndex].operand = jumpLabel;
Debug.Print("[FixedBanditSpawning] Age checker in Mission.SpawnAgent() bypassed :)");
}

return codes.AsEnumerable();
}
}

[HarmonyPatch(typeof(Mission), "BuildAgent")]
public static class Mission_BuildAgent_Patch
{
public static void Postfix(ref Agent agent)
{
if (agent.IsHuman && agent.Age < 18f)
{
float age = agent.Age;
float scale = agent.AgentScale;
//Debug.Print(string.Format("[FixedBanditSpawning] original agent {0} scale: {1}", agent.Name, agent.AgentScale));
AccessTools.PropertySetter(typeof(Agent), nameof(Agent.Age)).Invoke(agent, new object[] { 18f });
SkinGenerationParams skinParams = new SkinGenerationParams((int)(SkinMask.NoneVisible), agent.SpawnEquipment.GetUnderwearType(agent.IsFemale),
(int)agent.SpawnEquipment.BodyMeshType, (int)agent.SpawnEquipment.HairCoverType, (int)agent.SpawnEquipment.BeardCoverType,
(int)agent.SpawnEquipment.BodyDeformType, agent == Agent.Main, agent.Character.FaceDirtAmount, agent.IsFemale ? 1 : 0, false, false);
agent.AgentVisuals.AddSkinMeshes(skinParams, agent.BodyPropertiesValue);
//Debug.Print(string.Format("[FixedBanditSpawning] original agent {0} scale: {1}", agent.Name, agent.AgentScale));
AccessTools.Method(typeof(Agent), "SetInitialAgentScale").Invoke(agent, new object[] { scale });
//Debug.Print(string.Format("[FixedBanditSpawning] original agent {0} scale: {1}", agent.Name, agent.AgentScale));
agent.AgentVisuals.BatchLastLodMeshes();
agent.PreloadForRendering();
AccessTools.PropertySetter(typeof(Agent), nameof(Agent.Age)).Invoke(agent, new object[] { age });
}
}
}
}
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 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 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 @@ -27,3 +27,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.dll
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
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 FixedCompanionAgeSpawning/SubModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected override void OnSubModuleLoad()
{
base.OnSubModuleLoad();

new Harmony("d225.fixedbanditspawning").PatchAll();
new Harmony("d225.fixedcompanionagespawning").PatchAll();
}
}

Expand Down Expand Up @@ -116,6 +116,7 @@ public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructio
{
codes[i + 1] = new CodeInstruction(OpCodes.Nop);
codes[i + 2] = new CodeInstruction(OpCodes.Nop);
codes[i + 3].operand = 32;
Debug.Print("[FixedBanditSpawning] Artificial age adder in UrbanCharactersCampaignBehavior.CreateCompanion() bypassed :)");
break;
}
Expand Down
Binary file not shown.
Binary file not shown.
Binary file modified FixedCompanionAgeSpawning/bin/Debug/Newtonsoft.Json.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified FixedCompanionAgeSpawning/bin/Debug/TaleWorlds.Core.dll
Binary file not shown.
Binary file not shown.
Binary file modified FixedCompanionAgeSpawning/bin/Debug/TaleWorlds.Diamond.dll
Binary file not shown.
Binary file modified FixedCompanionAgeSpawning/bin/Debug/TaleWorlds.DotNet.dll
Binary file not shown.
Binary file modified FixedCompanionAgeSpawning/bin/Debug/TaleWorlds.Engine.dll
Binary file not shown.
Binary file modified FixedCompanionAgeSpawning/bin/Debug/TaleWorlds.InputSystem.dll
Binary file not shown.
Binary file modified FixedCompanionAgeSpawning/bin/Debug/TaleWorlds.Library.dll
Binary file not shown.
Binary file modified FixedCompanionAgeSpawning/bin/Debug/TaleWorlds.Localization.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified FixedCompanionAgeSpawning/bin/Debug/TaleWorlds.Network.dll
Binary file not shown.
Binary file not shown.
Binary file modified FixedCompanionAgeSpawning/bin/Debug/TaleWorlds.PSAI.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ D:\SteamLibrary\steamapps\common\Mount & Blade II Bannerlord\Modules\FixedBandit
D:\SteamLibrary\steamapps\common\Mount & Blade II Bannerlord\Modules\FixedBanditSpawning\FixedCompanionAgeSpawning\obj\Debug\FixedCompanionAgeSpawning.csproj.CopyComplete
D:\SteamLibrary\steamapps\common\Mount & Blade II Bannerlord\Modules\FixedBanditSpawning\FixedCompanionAgeSpawning\obj\Debug\FixedCompanionAgeSpawning.dll
D:\SteamLibrary\steamapps\common\Mount & Blade II Bannerlord\Modules\FixedBanditSpawning\FixedCompanionAgeSpawning\obj\Debug\FixedCompanionAgeSpawning.pdb
D:\SteamLibrary\steamapps\common\Mount & Blade II Bannerlord\Modules\FixedBanditSpawning\FixedCompanionAgeSpawning\bin\Debug\TaleWorlds.ObjectSystem.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion SubModule.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Module>
<Name value="Fixed Bandit Spawning"/>
<Id value="FixedBanditSpawning"/>
<Version value="v1.0.0"/>
<Version value="v1.1.0"/>
<SingleplayerModule value="true"/>
<MultiplayerModule value="false"/>
<Official value="false"/>
Expand Down
Binary file modified bin/Win64_Shipping_Client/FixedBanditSpawning.dll
Binary file not shown.

0 comments on commit 0ac92b3

Please sign in to comment.