Installing mods
An install is the moment a player's interest becomes content in your game. The SDK handles the whole path: downloading the file, checking it arrived intact, unpacking it and placing it where your game loads mods from. Your game shows progress and loads the result.
Players keep their mods up to date without leaving your game. The SDK checks for newer versions, and an update is the same one-step install.
Each player on a shared device keeps their own list of mods, which ones are switched on, and the order they load in. Mod files themselves are stored once.
The SDK also protects the mods folder. It notices when a mod's files are missing or were changed by hand, so your game can offer a repair instead of loading a broken mod.
The Library interface
Installing, updating and loading mods all go through ICFCore.Library.
| Call | What it does |
|---|---|
Install | Downloads and installs a mod file. Three overloads |
CancelInstallation | Cancels a queued or running install |
GetInstalledMods | Lists the current player's installed mods |
SyncWithServer | Checks the installed mods for newer files |
SetEnableState | Turns one mod on or off for the current player |
UpdateInstalledModsProperties | Sets enabled state and load order for several mods |
Uninstall | Removes a mod |
PerformModsValidation | Checks installed files against CurseForge |
CleanTempDir | Deletes temporary install files now |
Failure delegates receive a CFCoreError. See Error handling.
Installing a mod
How it works
- Get the
Modfrom search or lookup. See Browsing and discovery. - Call
Install. The SDK picks the file, unless you pass one. - Show progress from the progress delegate.
- When the success delegate runs, the mod is on disk and in the player's library.
using Overwolf.CFCore.Base;
using Overwolf.CFCore.Base.Api.Models;
using Overwolf.CFCore.Base.Common;
using Overwolf.CFCore.Base.Library.Models;
using UnityEngine;
public class ModInstaller : MonoBehaviour {
private InstalledMod _pending;
public async void InstallMod(ICFCore core, Mod mod) {
_pending = await core.Library.Install(
mod,
(InstalledMod installed) => {
_pending = null;
Debug.Log($"Installed {installed.Details.Name} at {installed.PathOnDisk}");
},
(LibraryProgress progress) => {
uint percent = progress.DataTransfer?.Progress ?? 0;
Debug.Log($"{progress.State}: {percent}%");
},
(CFCoreError error, InstalledMod failed) => {
_pending = null;
Debug.LogError($"Install failed: {error.Description}");
});
}
public void Cancel(ICFCore core) {
if (_pending == null) {
return;
}
core.Library.CancelInstallation(
_pending,
() => Debug.Log("Cancel requested"),
(CFCoreError error) => Debug.LogError(error.Description));
}
}
Install returns a Task<InstalledMod> holding the pending install record. Keep it to cancel the install. It is null when the install could not start, and the failure delegate runs in that case too, with a null InstalledMod.
Prebuilt UI: CFUnity.Install.InstallMod.
Which file is installed
| Overload | Installs |
|---|---|
Install(mod, ...) | The mod's main file. See below |
Install(mod, file, ...) | The file you pass, for example an older version |
Install(mod, file, additionalParams, ...) | The file you pass, with extra parameters |
The main file is the entry in Mod.LatestFiles whose id is Mod.MainFileId.
The install fails without starting when the mod id is 0, when the mod belongs to a different game than the one in your settings, or when the mod is one of the player's local drafts. When you pass no file, or a File whose Id is 0, it also fails when the mod has no main file in LatestFiles.
InstallModAdditionalParams.Origin tells CurseForge where the install started, for install analytics. Use ModPage, the default, for installs from your browser, and ServerModule for installs a game server asked for.
What happens during an install
The progress delegate receives a LibraryProgress with the InstalledMod, a State and a DataTransfer. DataTransfer.Progress is a percentage from 0 to 100 within the current state. While downloading, DataTransfer.TransferredBytes and DataTransfer.TransferRateBytesPerSecond are also set.
LibraryProgressState | What the SDK is doing |
|---|---|
Pending | The install is queued |
CleaningUp | Clearing temporary install files, before the download and again at the end |
Downloading | Downloading the file |
Validating | Checking the download against its hash |
Unzipping | Unpacking the archive |
Copying | Moving the mod into the mods directory |
CleaningUp is reported before the download starts, and again when the install ends, whether it succeeded or failed.
Progress during Unzipping can be raised on a background thread. Store the value and apply it to your interface from the main thread, for example in Update. Every other progress state, and the success and failure delegates, run on the main thread.
A download that does not match its hash fails, and nothing is installed. The failure arrives as an error with only a Description.
A new install that fails or is cancelled is removed from the library. A failed update keeps the version that was installed before.
Several installs at once
Installs run in parallel up to Settings.MaxConcurrentInstallations. Further installs wait in a queue and start in order as others finish.
Do not call Install for a mod that is already queued or installing. The second call fails, but only after it has changed the mod's shared library record. For a new mod, that can remove the record, and the first install then never calls its success delegate. Track which mods are installing in your game, and disable the install button for them.
Cancelling an installation
CancelInstallation takes the InstalledMod returned by Install.
| When you cancel | What happens |
|---|---|
| While queued | The install is dropped when its turn comes |
| Before the download ends, or while unzipping | The install stops |
| While validating, copying or doing the final clean-up | The cancel is ignored, and the install finishes |
A stopped or dropped install's failure delegate runs with a cancellation, which is described on Error handling.
The installed mod model
InstalledMod is the library's record of one mod for the current player.
| Field | Type | What it holds |
|---|---|---|
Id | Guid | The SDK's own id for this entry. Stable across sessions |
Details | Mod | The mod, as returned by CurseForge |
InstalledFile | File | The file on disk |
LatestUpdatedFile | File | The file being installed, or the main file SyncWithServer found |
Status | InstalledModStatus | See below |
PathOnDisk | string | Where the mod is. See below |
Enabled | bool | Whether the current player has the mod turned on |
LoadOrder | int | The current player's load order position |
Unmanaged | bool | Whether the mod was placed on disk outside the SDK |
DateInstalled | DateTime | When the installed file was installed |
InstalledModStatus | What it means | What to do |
|---|---|---|
Pending | Queued or installing | Wait |
Normal | Installed and up to date | Load it |
OutOfDate | Installed, and the mod's main file on CurseForge is a different file | Load it, and offer the update |
Invalid | Files are missing or were changed | Do not load it. Install it again, or uninstall it |
InstalledModStatus also declares WorkingCopy and Uploading, which the current SDK does not set on installed mods.
OutOfDate compares the installed file with the mod's current main file, not file dates. A player who deliberately installed an older file sees that mod as OutOfDate after the next update check.
Where the mod is on disk
| Directory mode | PathOnDisk |
|---|---|
CFCoreStructure | <game id>/<mod id>_<file id> |
CFCoreStructureWithoutGameId | <mod id>_<file id> |
Flat | The absolute path of the file's first module. See below |
In the two structured modes, PathOnDisk is relative to Settings.ModsDirectory. Combine a relative PathOnDisk with Settings.ModsDirectory before loading. In Flat mode, every module of the file sits directly in the mods directory, and PathOnDisk points at the first one. Flat mode moves only the modules the file lists: a file that lists none installs nothing into the mods directory, and its PathOnDisk is the mod's name. Before moving a file's modules into place, the SDK deletes anything in the mods directory with the same names, so two mods whose modules share a name replace each other. How to choose a mode is on Getting started.
Loading installed mods
GetInstalledMods returns the current player's mods, sorted by load order. Load the mods that are Enabled and whose status is Normal or OutOfDate.
using System.Collections.Generic;
using System.IO;
using Overwolf.CFCore.Base;
using Overwolf.CFCore.Base.Common;
using Overwolf.CFCore.Base.Library.Models;
using Overwolf.CFCore.Base.Library.Models.Enums;
using UnityEngine;
public class ModLoader : MonoBehaviour {
public void LoadAll(ICFCore core, string modsDirectory) {
core.Library.GetInstalledMods(
(List<InstalledMod> mods) => {
foreach (InstalledMod mod in mods) {
bool usable = mod.Status == InstalledModStatus.Normal ||
mod.Status == InstalledModStatus.OutOfDate;
if (!mod.Enabled || !usable) {
continue;
}
string path = Path.Combine(modsDirectory, mod.PathOnDisk);
Debug.Log($"Load {mod.Details.Name} from {path}");
}
},
(CFCoreError error) => Debug.LogError(error.Description));
}
}
Path.Combine returns PathOnDisk unchanged when it is already absolute, so the same code works in Flat mode.
Prebuilt UI: CFUnity.Install.GetInstalledMods, or the cached CFUnity.Install.InstalledMods.
Enabling, disabling and load order
Enabled state and load order belong to the current player. Another player on the same device has their own.
| When | Enabled | Load order |
|---|---|---|
| A player first installs a mod | true | 0, first, as soon as the install is requested. The player's other ordered mods move down one place |
| An unmanaged mod is found | true | Unassigned, sorted after every ordered mod |
SetEnableState turns one mod on or off by its mod id. UpdateInstalledModsProperties changes several mods at once. Each InstalledModProperties names a mod by Id, the InstalledMod.Id, or by ModId, and sets only the fields you give a value:
| Field | Type | What it does |
|---|---|---|
Id | Guid | The installed mod to change. Takes precedence over ModId when set |
ModId | uint | The mod id, used when Id is not set |
Enabled | bool? | The new enabled state. Null leaves it unchanged |
LoadOrder | int? | The new load order. Null leaves it unchanged |
Entries that match no installed mod are skipped. The SDK does not renumber the rest of the list, so send the full order when a player reorders mods.
Prebuilt UI: CFUnity.Install.UpdateInstalledModsProperties. Players can reorder and toggle mods in the browser when Use Installed Mods Management is on.
Updating mods
How it works
- Call
SyncWithServer. It fetches the current details of the player's installed mods. - A mod whose main file differs from its installed file gets the
OutOfDatestatus, if it wasNormal, and itsLatestUpdatedFileholds the main file. - To update, call
InstallwithDetailsandLatestUpdatedFilefrom the installed mod. - On success the old version is replaced. If the download, hash check or unpacking fails, the old version stays installed.
core.Library.SyncWithServer(
() => Debug.Log("Installed mods checked for updates"),
(CFCoreError error) => Debug.LogWarning(error.Description));
SyncWithServer also refreshes Details for every installed mod, so names, images and ratings stay current.
Prebuilt UI: CFUnity.Install.UpdateMod. CFUnity runs the server check the first time it reads the installed mods.
Uninstalling a mod
Uninstall takes a mod id. It removes the mod's files from the mods directory and removes the mod from the current player's library. Its success delegate receives the removed InstalledMod.
Uninstall deletes the files even when another local player on the same device still has the mod installed. That player's library keeps the mod, which the next startup check marks Invalid. On a device with several local players, warn before uninstalling.
Local creations cannot be installed or uninstalled through the library. See Creating UGC.
Prebuilt UI: CFUnity.Install.UninstallMod.
Validating installed mods
The SDK checks the player's installed mods each time it starts. In the two structured modes it checks that each mod's folder exists. In Flat mode it checks that each of the file's modules exists. A mod that fails the check gets the Invalid status.
PerformModsValidation runs a deeper check on the mods you pass. It fetches each installed file's details from CurseForge and compares a fingerprint of every module on disk with them. Its first delegate receives the mods that ended up Invalid.
How it works
- Pass the installed mods to check, for example before joining a multiplayer session.
- Mods whose files match are set back to
NormalorOutOfDate. - Mods whose files do not match are set to
Invalidand returned to you. - To repair a mod, install the same file again.
When you set a premium public key, PerformModsValidation verifies the signature on the file details. If the signature does not match, every mod being checked is set to Invalid and the failure delegate runs. See Monetization.
Disk space and temp cleanup
Installs work in a .tmp folder inside the mods directory. The SDK clears it at startup, keeping the files of mods whose status is Pending. CleanTempDir clears the folder at any time, for example to free disk space. It removes everything in it, including files of installs in progress.
In the two structured modes, the SDK treats the mods directory as its own. At startup, and whenever you call CleanTempDir, it deletes every folder there that is not an installed mod. If players add mods by hand, turn on unmanaged mod detection so those folders are kept, or use Flat mode, where this cleanup does not run.
Unmanaged mods
With Settings.UnmanagedMods.Enabled set, the SDK scans the mods directory at startup. Every folder that was not installed through the SDK, and whose name does not start with a dot, is added to the library as an unmanaged mod.
| Unmanaged mod field | Value |
|---|---|
Unmanaged | true |
Details.Id | 0 |
Details.Name | The folder name |
InstalledFile | Null |
Status | Normal |
PathOnDisk | The folder, relative to Settings.ModsDirectory. See below |
A folder found by ScanOneLevelUp outside Settings.ModsDirectory is stored with an absolute path.
Use unmanaged mod detection with the two structured modes. In Flat mode, the scan also registers the folders of mods installed through the SDK as unmanaged mods.
When an unmanaged mod's folder disappears, the SDK tries to remove it from the library at the next startup. Because every unmanaged mod has the mod id 0, with several unmanaged mods the removal can hit another entry, which is then added again as new and loses its enabled state and load order.
Unmanaged mods all have the mod id 0, so calls that take a mod id cannot tell them apart. Use UpdateInstalledModsProperties with InstalledMod.Id to enable, disable or reorder an unmanaged mod. SyncWithServer and PerformModsValidation skip unmanaged mods.
Settings.UnmanagedMods.ScanOneLevelUp also scans the folder above the mods directory. See Initialization and settings.
Premium mods
For a premium mod, the SDK requests a protected download address from CurseForge before it downloads the file. On a game server, where Settings.IsServer is set, it downloads the file directly. Ownership, purchases and trials are on Monetization.
Installing with CFUnity
CFUnity.Install wraps the library and keeps a cache of the player's installed mods.
| Member | What it does |
|---|---|
InstallMod | Installs a mod, optionally with an origin and a file |
UpdateMod | Installs the mod's LatestUpdatedFile |
UninstallMod | Uninstalls a mod |
CancelInstall | Cancels a mod's install |
GetInstalledMods | Reads the installed mods, checking for updates the first time |
InstalledMods | The cached list of installed mods |
IsModInstalled | Whether a mod, or a specific file of it, is in the library. See below |
IsModInstalling | Whether a mod is installing |
GetInstalledModStatus | A mod's InstalledModStatus. See below |
UpdateInstalledModsProperties | Sets enabled state and load order |
RegisterInstallListener | Reports state changes and progress |
OnInstalledModsUpdated | Fires when the installed list changes |
IsModInstalled is also true for a mod that is Pending, and InstallMod refuses such a mod as already installed. GetInstalledModStatus returns Invalid for a mod that is not in the library at all, so check IsModInstalled first.
With Use Subscriptions on, InstallMod also subscribes the player to the mod. See Subscriptions.
RegisterInstallListener takes a mod, a state delegate and an optional progress delegate. Pass null as the mod to hear about every mod. The state delegate receives the mod, an InstallService.ModInstallState and an error string, which is null on success. The progress delegate receives the mod, the progress as a fraction from 0 to 1, a speed value and the state. CFUnity delivers both on the main thread.
ModInstallState | Meaning |
|---|---|
Installing | An install started, or failed when the error is not null |
Installed | An install or an update finished |
Updating | An update started |
Uninstalling | An uninstall started |
Uninstalled | An uninstall finished |
InstallCancelled | An install ended with an error that has no description |
UpdateCancelled | An update ended with an error that has no description |
UninstallCancelled | An uninstall was cancelled |
ModInstallState also declares Updated, which CFUnity never reports. A finished update reports Installed. An install that cannot start at all, for example because the mod has no main file, reports no state. Remove a listener with UnregisterInstallListener.
Escalation
If installs fail repeatedly with the same error, send the error fields and the SDK log file to cfforstudios@overwolf.com.