RimWorld.CompatUtils 1.1.0

There is a newer version of this package available.
See the version list below for details.
Install-Package RimWorld.CompatUtils -Version 1.1.0
dotnet add package RimWorld.CompatUtils --version 1.1.0
<PackageReference Include="RimWorld.CompatUtils" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RimWorld.CompatUtils --version 1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: RimWorld.CompatUtils, 1.1.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. 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.1.0

// Install RimWorld.CompatUtils as a Cake Tool
#tool nuget:?package=RimWorld.CompatUtils&version=1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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 });
}

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.1.1 81 9/30/2021
1.1.0 85 9/30/2021
1.0.6 117 9/24/2021
1.0.5 71 9/19/2021
1.0.4 87 9/11/2021
1.0.3 117 8/29/2021
1.0.2 116 8/29/2021
1.0.1 87 8/27/2021

Made GetConsistentMethod(string modPackageId, MethodInfo methodInfo, Type[] correctMethodTypes, bool logError) method public, Fixed rare error when ReflectedType is null