/********* ** Public methods *********/ /// <summary>Get a mod API if it's installed and valid.</summary> /// <param name="label">A human-readable name for the mod.</param> /// <param name="modId">The mod's unique ID.</param> /// <param name="minVersion">The minimum version of the mod that's supported.</param> /// <param name="modRegistry">An API for fetching metadata about loaded mods.</param> /// <param name="monitor">Encapsulates monitoring and logging.</param> /// <returns>Returns the mod's API interface if valid, else null.</returns> public static TInterface GetValidatedApi <TInterface>(string label, string modId, string minVersion, IModRegistry modRegistry, IMonitor monitor) where TInterface : class { // check mod installed IManifest mod = modRegistry.Get(modId)?.Manifest; if (mod == null) { return(null); } // check mod version if (mod.Version.IsOlderThan(minVersion)) { monitor.Log($"Detected {label} {mod.Version}, but need {minVersion} or later. Disabled integration with that mod.", LogLevel.Warn); return(null); } // get API var api = modRegistry.GetApi <TInterface>(modId); if (api == null) { monitor.Log($"Detected {label}, but couldn't fetch its API. Disabled integration with that mod.", LogLevel.Warn); return(null); } return(api); }
/// <inheritdoc cref="IModRegistry.GetApi{T}"/> /// <param name="modRegistry">The mod registry to extend.</param> /// <param name="uniqueId">The mod's unique ID.</param> /// <param name="label">A human-readable name for the mod.</param> /// <param name="minVersion">The minimum supported version of the API.</param> /// <param name="monitor">The monitor with which to log errors.</param> public static TInterface GetApi <TInterface>(this IModRegistry modRegistry, string uniqueId, string label, string minVersion, IMonitor monitor) where TInterface : class { // fetch info IManifest manifest = modRegistry.Get(uniqueId)?.Manifest; if (manifest == null) { return(null); } // check version if (manifest.Version.IsOlderThan(minVersion)) { monitor.Log($"Detected {label} {manifest.Version}, but need {minVersion} or later. Disabled integration with this mod.", LogLevel.Warn); return(null); } // fetch API TInterface api = modRegistry.GetApi <TInterface>(uniqueId); if (api == null) { monitor.Log($"Detected {label}, but couldn't fetch its API. Disabled integration with this mod.", LogLevel.Warn); return(null); } return(api); }
/// <summary> /// Set up compatibility with other external mods. /// </summary> private void AddModCompatibility() { // Setup compatibility for the mod [Rush Orders]. isPlayerUsingRushedOrders = false; // Check if the player uses the mod [Rush Orders]. bool isLoaded = modRegistry.IsLoaded(MOD_RUSH_ORDERS_MOD_ID); if (!isLoaded) { return; } // The API we consume is only available starting with Rush Orders 1.1.4. IModInfo mod = modRegistry.Get(MOD_RUSH_ORDERS_MOD_ID); if (mod.Manifest.Version.IsOlderThan("1.1.4")) { monitor.Log($"You are running an unsupported version of the mod [{mod.Manifest.Name}]! " + $"Please use at least [{mod.Manifest.Name} 1.1.4] for compatibility!", LogLevel.Info); return; } rushOrdersApi = modRegistry.GetApi <IRushOrdersApi>(MOD_RUSH_ORDERS_MOD_ID); if (rushOrdersApi == null) { monitor.Log($"Could not add compatibility for the mod [{mod.Manifest.Name}]! " + $"A newer version of the mod [ToolUpgradeDeliveryService] might be needed.", LogLevel.Error); return; } rushOrdersApi.ToolRushed += OnPlacedRushOrder; isPlayerUsingRushedOrders = true; }
/// <summary> /// Applies late patches. /// </summary> /// <param name="harmony">Harmony instance.</param> /// <param name="registry">Mod registry.</param> internal static void ApplyPatches(Harmony harmony, IModRegistry registry) { if (registry.Get("spacechase0.DynamicGameAssets") is null) { return; } try { if (AccessTools.TypeByName("DynamicGameAssets.Game.CustomFruitTree") is Type dgaTree) { ModEntry.ModMonitor.Log("Transpiling DGA to remove damage to fruit trees from hoes", LogLevel.Info); harmony.Patch( original: dgaTree.InstanceMethodNamed("performToolAction"), transpiler: new HarmonyMethod(typeof(FruitTreesAvoidHoe), nameof(FruitTreesAvoidHoe.Transpiler))); } else { ModEntry.ModMonitor.Log("Cannot find dga fruit trees; they will still be affected by hoes.", LogLevel.Info); } } catch (Exception ex) { ModEntry.ModMonitor.Log($"Ran into issue transpiling DGA fruit trees to remove damage from hoes\n\n{ex}.", LogLevel.Error); } }
public CustomKissingModProxy(IModRegistry registry, IMonitor monitor) { IModInfo modInfo = registry.Get("Digus.CustomKissingMod"); if (modInfo != null && modInfo.Manifest.Version.IsOlderThan(MINIMUM_VERSION)) { monitor.Log($"Couldn't work correctly with Custom Kissing Mod version {modInfo.Manifest.Version} (requires >= {MINIMUM_VERSION}). Don't worry, this issue doesn't affect stability, but update is recommended :)", LogLevel.Warn); } this.api = registry.GetApi <ICustomKissingModApi>("Digus.CustomKissingMod"); }
public API(IModRegistry modRegistry) { this.modRegistry = modRegistry; IModInfo gmcm = modRegistry.Get("spacechase0.GenericModConfigMenu"); if (gmcm is null) { this.fixedHeight = false; } else { this.fixedHeight = gmcm.Manifest.Version.IsOlderThan(new SemanticVersion(1, 8, 2)); } }
/********* ** Public methods *********/ /// <summary>Construct an instance.</summary> /// <param name="label">A human-readable name for the mod.</param> /// <param name="modID">The mod's unique ID.</param> /// <param name="minVersion">The minimum version of the mod that's supported.</param> /// <param name="modRegistry">An API for fetching metadata about loaded mods.</param> /// <param name="monitor">Encapsulates monitoring and logging.</param> protected BaseIntegration(string label, string modID, string minVersion, IModRegistry modRegistry, IMonitor monitor) { // init this.Label = label; this.ModID = modID; this.ModRegistry = modRegistry; this.Monitor = monitor; // validate mod IManifest manifest = modRegistry.Get(this.ModID); if (manifest == null) { return; } if (manifest.Version.IsOlderThan(minVersion)) { monitor.Log($"Detected {label} {manifest.Version}, but need {minVersion} or later. Disabled integration with this mod.", LogLevel.Warn); return; } this.IsLoaded = true; }
public static string FetchTexturePath(IModRegistry modRegistry, string modIdAndPath) { if (modIdAndPath == null || modIdAndPath.IndexOf('/') == -1) { return(null); } string packId = modIdAndPath.Substring(0, modIdAndPath.IndexOf('/')); string path = modIdAndPath.Substring(modIdAndPath.IndexOf('/') + 1); // This is really bad. Pathos don't kill me. var modInfo = modRegistry.Get(packId); if (modInfo.GetType().GetProperty("Mod").GetValue(modInfo) is IMod mod) { return(mod.Helper.Content.GetActualAssetKey(path)); } else if (modInfo.GetType().GetProperty("ContentPack").GetValue(modInfo) is IContentPack pack) { return(pack.GetActualAssetKey(path)); } return(null); }
/// <summary> /// Grabs a reference to Smart Building's CurrentlyInBuildMode. /// </summary> /// <param name="registry">ModRegistry.</param> internal static void GetSmartBuildingBuildMode(IModRegistry registry) { if (registry.Get("DecidedlyHuman.SmartBuilding") is not IModInfo info || info.Manifest.Version.IsOlderThan("1.3.2")) { ModEntry.ModMonitor.Log("SmartBuilding not installed, no need to adjust for that", LogLevel.Trace); }