Skip to main content

ModInstaller

A static class in TavernLib, TavernLib.Backend.Mods.

Installs, verifies, enables and scans the mods in Mods, keeping a record (manifest.json) in each mod folder. Downloads are checked against their SHA-256 and built in a staging folder.

Fields​

3 private and internal fields
MemberWhat it is
private const int DownloadStallSecondsHow long a download may go without data before it is given up on.
private const int ZipMaxEntriesMost entries a mod zip may hold before extraction is refused.
private const long ZipMaxTotalUncompressedMost bytes a zip may extract to, and the cap on any one download.

Methods​

MemberWhat it is
static List<LibraryDependency> CollectLibraryDependencies(string gameDir, IReadOnlyList<ModManifest> mods, string target)Every library a set of mods needs for a target. Throws when two mods, or an installed one, pin different builds of one file.
static void InstallLibraryDependency(string gameDir, NativeHttp http, LibraryDependency lib, DateTime deadlineUtc)Downloads a library into UserLibs, checks its hash, and writes a .meta.json beside it.
static void InstallMod(string gameDir, NativeHttp http, ModManifest mod, string target, DateTime deadlineUtc)Downloads, checks and installs one mod's build for a target into Mods/<id>/.<target>, then writes its record.
static bool RefreshRecordMetadata(string gameDir, ModManifest manifest)Updates an installed record's parity_required and scenes from a manifest of the same version. True if it changed.
static ValueTuple<List<InstalledModInfo>, List<UntrackedMod>> ScanMods(string gameDir)Lists the mods in Mods: ones with a record of ours, and untracked DLLs and folders, with their enabled state.
static bool SetEnabled(string gameDir, string modId, bool enabled)Enables or disables a tracked mod by renaming its record. False if it's already that way or has no record.
static bool? VerifyLibrary(string gameDir, string filename, string wantSha256 = null)Hashes a UserLibs file against its sidecar. null with nothing to check; false if the sidecar pins another build.
static bool? VerifyTarget(string gameDir, ModRecord record, string target)Hashes a mod's installed files for a target against its record. null with nothing to check. Slow: reads every file.
9 private and internal methods
MemberWhat it is
private static void CheckSameLibrary(LibraryDependency a, string aOwner, LibraryDependency b, string bOwner)Throws if two mods pin the same library file with different SHA-256 values.
private static void DisableShadowedLooseDlls(string gameDir, string modId, string targetDir)Renames a loose Mods DLL with the same name as one just installed, so MelonLoader doesn't load it twice.
private static void DisplaceForeign(string gameDir, string modId)Moves a mod folder this manager didn't install into Mods/.displaced instead of deleting it.
private static void DownloadVerifyMove(NativeHttp http, string url, string sha256, string destPath, DateTime deadlineUtc)Downloads and verifies a file, then moves it to its destination path.
private static Dictionary<string, string> HashTree(string baseDir)Returns the SHA-256 of every file under a folder, keyed by relative path.
private static void MoveAside(string modDir, string aside, ICollection<string> keep, bool legacy, string modId)Moves what an install replaces into an aside folder, and puts it back if a file is in use.
private static void SafeExtractZip(string zipPath, string destDir)Extracts a zip, refusing absolute paths, colons, symlinks, escaping paths and oversized archives.
private static string Sha256File(string path)Returns the lowercase hex SHA-256 of a file.
private static void VerifiedDownload(NativeHttp http, string url, string sha256, string workDir, DateTime deadlineUtc, Action<string> use)Downloads a URL to a temp file, checks its SHA-256, hands the file to a callback, then deletes the temp.