Mutagen-Modding / Mutagen

A .NET library for analyzing, creating, and manipulating Bethesda mods
GNU General Public License v3.0
121 stars 32 forks source link

ESL Light Master detection and writing #463

Closed Noggog closed 5 months ago

Noggog commented 1 year ago

Related to https://github.com/Mutagen-Modding/Synthesis/issues/110

Potential related code:

uint uintMin = 0x800;
uint uintMax = 0xFFF;
bool isESPFE = true;
ModKey patchModKey = state.PatchMod.ModKey;

foreach (var rec in state.PatchMod.EnumerateMajorRecords())
{
    if (!rec.FormKey.ModKey.Equals(patchModKey)) continue;
    if (rec.FormKey.ID < uintMin) isESPFE = false;
    if (rec.FormKey.ID > uintMax) isESPFE = false;
}
if (isESPFE) state.PatchMod.ModHeader.Flags |= SkyrimModHeader.HeaderFlag.LightMaster;

Since the decision to turn it into an ESL will change the ModKey, we need to not just plop this logic into the ModHeaderWriteLogic only, as users will probably want to detect ESL-ability before calling the write function, so they can adjust their ModKey appropriately.

We will then also want to add it to ModHeaderWriteLogic with some options in BinaryWriteParameters to do the detection and perhaps throw an exception if it's deemed not esl-able, but set to be an esl.

Michael-wigontherun commented 1 year ago

Please refer back to the post on synthesis https://github.com/Mutagen-Modding/Synthesis/issues/110#issuecomment-1685249560

It should not change the ModKey and plugin file name. It only needs to add the flag so it can be loaded in esl space.