Skip to content

Commit

Permalink
Hotfix for broken Simple Sidearms support
Browse files Browse the repository at this point in the history
  • Loading branch information
Dakraid committed Apr 23, 2020
1 parent 16b5521 commit 89029cd
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 27 deletions.
3 changes: 2 additions & 1 deletion About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
<li>1.1</li>
</supportedVersions>
<packageId>netrve.usemelee</packageId>
<description>Allows hunters to make use of melee weapons to do their job. (Installed version: v1.1.0)</description>
<description>Allows hunters to make use of melee weapons to do their job. (Installed version: v1.1.1)</description>
<loadAfter>
<li>brrainz.harmony</li>
<li>ludeon.rimWorld</li>
<li>ludeon.rimWorld.royalty</li>
<li>petetimessix.simplesidearms</li>
Expand Down
Binary file modified Assemblies/HuntersUseMelee.dll
Binary file not shown.

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

32 changes: 13 additions & 19 deletions Source/HuntersUseMelee/HuntersUseMelee.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
// If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/

using System;
using System.Linq;
using SimpleSidearms;
using System.Reflection;
using HarmonyLib;
using RimWorld;
using Verse;
Expand All @@ -13,19 +14,7 @@ namespace HuntersUseMelee
[StaticConstructorOnStartup]
public static class HuntersUseMeleeMain
{
public static readonly bool SimpleSidearmsLoaded;

// Constructor just used to see if Simple Sidearms is loaded
static HuntersUseMeleeMain()
{
SimpleSidearmsLoaded = IsLoaded("PeteTimesSix.SimpleSidearms");
}

// Utility function to check if a mod is loaded based on its packageId
private static bool IsLoaded(string packageId)
{
return LoadedModManager.RunningModsListForReading.Any(x => x.PackageId == packageId);
}
public static bool SimpleSidearmsLoaded => ModsConfig.ActiveModsInLoadOrder.Any(m => m.Name == "Simple sidearms" || m.PackageId == "petetimessix.simplesidearms");
}

[StaticConstructorOnStartup]
Expand Down Expand Up @@ -55,19 +44,24 @@ static void Postfix(Pawn p, ref bool __result)
__result = true;
return;
}

// Check if primary is a valid, damaging melee weapon
// Automatically assign the result
__result = p.equipment.Primary != null && p.equipment.Primary.def.IsMeleeWeapon &&
p.equipment.PrimaryEq.PrimaryVerb.HarmsHealth();


// Simple Sidearms support
// As above, we skip if result is already true, but we also skip is setting is off
// As above, we skip if result is already true, but we also skip if setting is off
// Or Simple Sidearms isn't loaded
if (__result || !(HuntersUseMeleeMain.SimpleSidearmsLoaded && HuntersUseMeleeMod.settings.enableSimpleSidearms)) return;
if (__result || !HuntersUseMeleeMod.settings.enableSimpleSidearms || !HuntersUseMeleeMain.SimpleSidearmsLoaded) return;

// If the pawn can carry sidearms and has any, they are good to go
if (p.getCarriedWeapons().Any())
var simpleExtensions = AccessTools.TypeByName("SimpleSidearms.Extensions");
var getGuns = simpleExtensions.GetMethod("getCarriedWeapons");

// p.getCarriedWeapons().Any()
if (getGuns != null && getGuns.Invoke(null, new object[] { p, true, false }) != null)
__result = true;
}

Expand Down
4 changes: 1 addition & 3 deletions Source/HuntersUseMelee/HuntersUseMelee.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,12 @@
<ItemGroup>
<Reference Include="0Harmony, Version=2.0.0.9, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\..\..\References\0Harmony.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\..\RimWorldWin64_Data\Managed\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="SimpleSidearms, Version=1.4.5.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\..\..\..\..\workshop\content\294100\927155256\v1.1\Assemblies\SimpleSidearms.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand Down
4 changes: 2 additions & 2 deletions Source/HuntersUseMelee/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
// 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.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyVersion("1.1.1.0")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: NeutralResourcesLanguage("en")]

0 comments on commit 89029cd

Please sign in to comment.