Skip to main content

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.

CallWhat it does
InstallDownloads and installs a mod file. Three overloads
CancelInstallationCancels a queued or running install
GetInstalledModsLists the current player's installed mods
SyncWithServerChecks the installed mods for newer files
SetEnableStateTurns one mod on or off for the current player
UpdateInstalledModsPropertiesSets enabled state and load order for several mods
UninstallRemoves a mod
PerformModsValidationChecks installed files against CurseForge
CleanTempDirDeletes temporary install files now

Failure delegates receive a CFCoreError. See Error handling.

Installing a mod​

How it works

  1. Get the Mod from search or lookup. See Browsing and discovery.
  2. Call Install. The SDK picks the file, unless you pass one.
  3. Show progress from the progress delegate.
  4. 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​

OverloadInstalls
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.

LibraryProgressStateWhat the SDK is doing
PendingThe install is queued
CleaningUpClearing temporary install files, before the download and again at the end
DownloadingDownloading the file
ValidatingChecking the download against its hash
UnzippingUnpacking the archive
CopyingMoving the mod into the mods directory

CleaningUp is reported before the download starts, and again when the install ends, whether it succeeded or failed.

warning

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.

warning

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 cancelWhat happens
While queuedThe install is dropped when its turn comes
Before the download ends, or while unzippingThe install stops
While validating, copying or doing the final clean-upThe 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.

FieldTypeWhat it holds
IdGuidThe SDK's own id for this entry. Stable across sessions
DetailsModThe mod, as returned by CurseForge
InstalledFileFileThe file on disk
LatestUpdatedFileFileThe file being installed, or the main file SyncWithServer found
StatusInstalledModStatusSee below
PathOnDiskstringWhere the mod is. See below
EnabledboolWhether the current player has the mod turned on
LoadOrderintThe current player's load order position
UnmanagedboolWhether the mod was placed on disk outside the SDK
DateInstalledDateTimeWhen the installed file was installed
InstalledModStatusWhat it meansWhat to do
PendingQueued or installingWait
NormalInstalled and up to dateLoad it
OutOfDateInstalled, and the mod's main file on CurseForge is a different fileLoad it, and offer the update
InvalidFiles are missing or were changedDo 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 modePathOnDisk
CFCoreStructure<game id>/<mod id>_<file id>
CFCoreStructureWithoutGameId<mod id>_<file id>
FlatThe 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.

WhenEnabledLoad order
A player first installs a modtrue0, first, as soon as the install is requested. The player's other ordered mods move down one place
An unmanaged mod is foundtrueUnassigned, 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:

FieldTypeWhat it does
IdGuidThe installed mod to change. Takes precedence over ModId when set
ModIduintThe mod id, used when Id is not set
Enabledbool?The new enabled state. Null leaves it unchanged
LoadOrderint?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

  1. Call SyncWithServer. It fetches the current details of the player's installed mods.
  2. A mod whose main file differs from its installed file gets the OutOfDate status, if it was Normal, and its LatestUpdatedFile holds the main file.
  3. To update, call Install with Details and LatestUpdatedFile from the installed mod.
  4. 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.

warning

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

  1. Pass the installed mods to check, for example before joining a multiplayer session.
  2. Mods whose files match are set back to Normal or OutOfDate.
  3. Mods whose files do not match are set to Invalid and returned to you.
  4. To repair a mod, install the same file again.
note

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.

warning

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 fieldValue
Unmanagedtrue
Details.Id0
Details.NameThe folder name
InstalledFileNull
StatusNormal
PathOnDiskThe folder, relative to Settings.ModsDirectory. See below

A folder found by ScanOneLevelUp outside Settings.ModsDirectory is stored with an absolute path.

warning

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.

MemberWhat it does
InstallModInstalls a mod, optionally with an origin and a file
UpdateModInstalls the mod's LatestUpdatedFile
UninstallModUninstalls a mod
CancelInstallCancels a mod's install
GetInstalledModsReads the installed mods, checking for updates the first time
InstalledModsThe cached list of installed mods
IsModInstalledWhether a mod, or a specific file of it, is in the library. See below
IsModInstallingWhether a mod is installing
GetInstalledModStatusA mod's InstalledModStatus. See below
UpdateInstalledModsPropertiesSets enabled state and load order
RegisterInstallListenerReports state changes and progress
OnInstalledModsUpdatedFires 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.

ModInstallStateMeaning
InstallingAn install started, or failed when the error is not null
InstalledAn install or an update finished
UpdatingAn update started
UninstallingAn uninstall started
UninstalledAn uninstall finished
InstallCancelledAn install ended with an error that has no description
UpdateCancelledAn update ended with an error that has no description
UninstallCancelledAn 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.