Skip to content
This repository has been archived by the owner on Mar 29, 2022. It is now read-only.

Commit

Permalink
Hotfix for 0.0.2
Browse files Browse the repository at this point in the history
Fixed possible null pointers
and bug with reapplication on reloads
  • Loading branch information
tynakuh committed Apr 9, 2020
1 parent b256e42 commit 11ff286
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion SubModule.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Module>
<Name value="Community Patch"/>
<Id value="CommunityPatch"/>
<Version value="v0.0.3"/>
<Version value="v0.0.2"/>
<SingleplayerModule value="true"/>
<MultiplayerModule value="true"/>
<Official value="false"/>
Expand Down
2 changes: 1 addition & 1 deletion src/CommunityPatch/CommunityPatch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Configurations>Release;Debug</Configurations>
<Platforms>x64</Platforms>
<RootNamespace />
<Version>0.0.3</Version>
<Version>0.0.2</Version>
<Title>Community Patch</Title>
<Authors>Tyler Young</Authors>
<Company>The Mount &amp; Blade II: Bannerlord Community</Company>
Expand Down
2 changes: 1 addition & 1 deletion src/CommunityPatch/Patches/DisciplinarianPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ private readonly PerkObject _perk
= PerkObject.FindFirst(x => x.Name.GetID() == "ER3ieXOb");

public bool IsApplicable(Game game)
=> _perk.PrimaryRole == SkillEffect.PerkRole.Personal;
=> _perk?.PrimaryRole == SkillEffect.PerkRole.Personal;

public void Apply(Game game) {
// Dear TaleWorlds; Value should probably be publicly exposed, maybe by a method
Expand Down
2 changes: 2 additions & 0 deletions src/CommunityPatch/Patches/PeakFormPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public override void Reset()
public override bool IsApplicable(Game game)
// ReSharper disable once CompareOfFloatsByEqualityOperator
{
if (_perk == null)
return false;
if (_perk.PrimaryBonus != 0f)
return false;

Expand Down
1 change: 1 addition & 0 deletions src/CommunityPatch/Patches/PrisonerRecruitmentPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public override bool IsApplicable(Game game) {
}

public override void Apply(Game game) {
if (Applied) return;
CommunityPatchSubModule.Harmony.Patch(TargetMethodInfo,
postfix: new HarmonyMethod(PatchMethodInfo));

Expand Down
2 changes: 2 additions & 0 deletions src/CommunityPatch/Patches/StewardAgrarianPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public override void Reset()
public override bool IsApplicable(Game game)
// ReSharper disable once CompareOfFloatsByEqualityOperator
{
if (_perk == null)
return false;
if (_perk.PrimaryBonus != 0f)
return false;

Expand Down
2 changes: 2 additions & 0 deletions src/CommunityPatch/Patches/StewardProminencePatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public override bool IsApplicable(Game game) {
}

public override void Apply(Game game) {
if (Applied) return;

CommunityPatchSubModule.Harmony.Patch(TargetMethodInfo,
postfix: new HarmonyMethod(PatchMethodInfo));

Expand Down
1 change: 1 addition & 0 deletions src/CommunityPatch/Patches/StewardSupremeAuthorityPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public override bool IsApplicable(Game game) {
}

public override void Apply(Game game) {
if (Applied) return;
CommunityPatchSubModule.Harmony.Patch(TargetMethodInfo,
postfix: new HarmonyMethod(PatchMethodInfo));

Expand Down
4 changes: 3 additions & 1 deletion src/CommunityPatch/Patches/WarRationsPerkPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public override bool IsApplicable(Game game) {
var patchInfo = Harmony.GetPatchInfo(TargetMethodInfo);
if (AlreadyPatchedByOthers(patchInfo))
return false;
if (Applied)

This comment has been minimized.

Copy link
@tynakuh

tynakuh Apr 9, 2020

Author Collaborator

Un-needed. Actually exists in Apply already.

return false;

var bytes = TargetMethodInfo.GetCilBytes();
if (bytes == null) return false;
Expand All @@ -56,7 +58,7 @@ public override bool IsApplicable(Game game) {

// ReSharper disable once InconsistentNaming
private static void Postfix(ref float __result, MobileParty party, StatExplainer explainer) {
var qm = party.LeaderHero.Clan.GetEffectiveQuartermaster();
var qm = party?.LeaderHero?.Clan?.GetEffectiveQuartermaster();

if (qm == null)
return;
Expand Down

0 comments on commit 11ff286

Please sign in to comment.