RimWorld.CompatUtils 1.0.6

There is a newer version of this package available.
See the version list below for details.
dotnet add package RimWorld.CompatUtils --version 1.0.6                
NuGet\Install-Package RimWorld.CompatUtils -Version 1.0.6                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RimWorld.CompatUtils" Version="1.0.6" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RimWorld.CompatUtils --version 1.0.6                
#r "nuget: RimWorld.CompatUtils, 1.0.6"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install RimWorld.CompatUtils as a Cake Addin
#addin nuget:?package=RimWorld.CompatUtils&version=1.0.6

// Install RimWorld.CompatUtils as a Cake Tool
#tool nuget:?package=RimWorld.CompatUtils&version=1.0.6                

Usage

All methods can be accessed via the CompatUtils.Compatibility class:

using CompatUtils;
bool combatExtendedActive = Compatibility.IsModActive("ceteam.combatextended");

Methods

bool IsModActive(string modPackageId)

Summary:
    Goes through all installed mods checking for a mod with the specified PackageID and returns whether the mod is active.

Returns:
    A bool representing whether or not a mod with the specified PackageID is active.
string GetModName(string modPackageId)

Summary:
    Goes through all installed mods checking for a mod with the specified PackageID and returns that mod's name if found.

Returns:
    A string representing the name of the mod with the specified PackageID, or null if no mod with the specified PackageID is active.
MethodInfo GetMethod(string className, string methodName, Type[] parameters = null, Type[] generics = null)

Summary:
    Uses Harmony's AccessTools to get the reflection information for the specified method.

Returns:
    The MethodInfo of the specified method if found, otherwise null.
MethodInfo GetMethod(string typeColonMethodName, Type[] parameters = null, Type[] generics = null)

Summary:
    Uses Harmony's AccessTools to get the reflection information for the specified method.

Returns:
    The MethodInfo of the specified method if found, otherwise null.
bool IsMethodConsistent(MethodInfo methodInfo, Type[] correctMethodTypes, bool logError = false, string modPackageIdForLog = null)

Summary:
    Checks all of the specified method's types in order to make sure the method hasn't been changed from your current implementation of it.
    May print a detailed error message to RimWorld's console if logError is set to true.
    The detailed error message will also give the name of the mod at fault if modPackageIdForLog is specified.

Returns:
    A bool representing whether or not the specified method's types are all the same.
MethodInfo GetConsistentMethod(string modPackageId, string className, string methodName, Type[] correctMethodTypes, bool logError = false)

Summary:
    Checks whether a mod is active, and if so gets the specified method and runs IsMethodConsistent on it.
    May print a detailed error message to RimWorld's console if logError is set to true.

Returns:
    If the specified mod and method both exist and the specified method is consistent, returns the MethodInfo of the specified method; otherwise returns null.
MethodInfo GetConsistentMethod(string modPackageId, string typeColonMethodName, Type[] correctMethodTypes, bool logError = false)

Summary:
    Checks whether a mod is active, and if so gets the specified method and runs IsMethodConsistent on it.
    May print a detailed error message to RimWorld's console if logError is set to true.

Returns:
    If the specified mod and method both exist and the specified method is consistent, returns the MethodInfo of the specified method; otherwise returns null.

Examples

public static bool combatExtendedActive = Compatibility.IsModActive("ceteam.combatextended");
public static MethodInfo combatExtendedHasAmmoMethod = Compatibility.GetMethod("CombatExtended.CE_Utility", "HasAmmo");

public static bool isMethodConsistent = Compatibility.IsMethodConsistent(combatExtendedHasAmmoMethod, new Type[] {
    typeof(ThingWithComps)
}, logError: true, modPackageIdForLog: "ceteam.combatextended");
public static MethodInfo combatExtendedHasAmmoMethod = Compatibility.GetConsistentMethod("ceteam.combatextended", "CombatExtended.CE_Utility", "HasAmmo", new Type[] {
    typeof(ThingWithComps)
}, logError: true);
public static bool HasAmmo(ThingWithComps thingWithComps)
{
    return combatExtendedHasAmmoMethod is null || (bool)combatExtendedHasAmmoMethod.Invoke(null, new object[] { thingWithComps });
}
Product Compatible and additional computed target framework versions.
.NET Framework net48 is compatible.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.3 846 1/9/2023
1.1.1 800 9/30/2021
1.1.0 740 9/30/2021
1.0.6 759 9/24/2021
1.0.5 712 9/19/2021
1.0.4 807 9/11/2021
1.0.3 749 8/29/2021
1.0.2 754 8/29/2021
1.0.1 768 8/27/2021

Attempted fix of BetterLoading null error