RimWorld.CompatUtils
1.2.3
dotnet add package RimWorld.CompatUtils --version 1.2.3
NuGet\Install-Package RimWorld.CompatUtils -Version 1.2.3
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.2.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RimWorld.CompatUtils --version 1.2.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: RimWorld.CompatUtils, 1.2.3"
#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.2.3 // Install RimWorld.CompatUtils as a Cake Tool #tool nuget:?package=RimWorld.CompatUtils&version=1.2.3
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 });
}
Product | Versions 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.
-
.NETFramework 4.8
- Krafs.Rimworld.Ref (>= 1.0.2551)
- Lib.Harmony (>= 2.2.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Minor optimizations and method parameter type fixes