# Mod Loading System

This document covers `TODOS.phase-72.72.14.1.2`: discovering `.mayamod`
packages, validating manifests, and producing a deterministic dependency-order
load plan.

## Runtime Surface

- module: `V2Modding`
- subsystem: `UV2ModLoadingSubsystem`
- helper library: `UV2ModLoadingBlueprintLibrary`
- automation: `V2/ue/Source/V2Tests/Private/Modding/ModLoadingSystem.spec.cpp`
- contract: `V2/ue/Content/V2/Modding/ModLoadingSystem_V2_Contract.json`
- format contract: `V2/ue/Content/V2/Modding/ModFileFormat_V2_Contract.json`
- manifest schema: `V2/ue/Content/V2/Modding/MayamodManifest_v1.schema.json`

## Discovery

`FV2ModDirectoryPolicy` defines the search roots, `.mayamod` extension,
`manifest.json` file name, package size limit, loose development directory
support, and ranked-disable policy. The default roots are project saved mods,
project user mods, and project content mods.

`DiscoverModPackages` scans those roots for `.mayamod` files and loose
`.mayamod` development directories, records the manifest path, and sorts results
by package path for stable downstream behavior.

## Manifest Validation

`ParseMayamodManifestJson` parses manifest JSON into `FV2ModPackageManifest`.
`ValidateMayamodManifest` rejects unsupported format versions, missing identity
fields, missing game/engine/mod-API/package version ranges, invalid asset
entries, invalid script entries, missing SHA-256 integrity hashes, and manifests
that do not keep network access denied by default.

## Dependency Ordering

`BuildDependencyOrderedLoadPlan` validates all manifests, rejects duplicate mod
ids, rejects missing required dependencies, rejects cyclic dependency graphs,
and uses a lexically sorted ready queue so equal-priority load plans remain
deterministic. The result exposes ordered mod ids, ordered manifests, validation
issues, validity, and ranked eligibility.

`LoadMayamodPackages` currently loads into the V2 mod registry abstraction by
accepting only a valid dependency-ordered plan and returning the ordered mod
ids. Asset mounting, sandbox execution, dependency-version solving, and hot
reload remain owned by later Phase 72 modding tasks.

## Verification

```bash
python3 V2/ue/Tools/check-v2-mod-loading-system.py
python3 V2/ue/Tools/check-v2-mod-file-format.py
python3 V2/ue/Tools/check-v2-ci-workflow.py
python3 V2/tools/validate-v2-docs.py
python3 -m py_compile V2/ue/Tools/check-v2-mod-loading-system.py V2/ue/Tools/check-v2-mod-file-format.py V2/ue/Tools/check-v2-ci-workflow.py
python3 -m json.tool V2/ue/Content/V2/Modding/ModLoadingSystem_V2_Contract.json
```
