unit userscript; uses 'lib\mxpf'; function Initialize: integer; var badlist_A, badlist_W, goodlist_A, goodlist_W: IInterface; badrec, goodrec, badforms_A, badforms_W, newbadform, goodforms_A, goodforms_W, newgoodform: IInterface; KWDA, VMAD: IInterface; index, P0, P1, P2, object_index, N: integer; item_edid, item_name: string; ArmorScriptExceptions, WeaponScriptExceptions: TStringList; badobject, goodobject: TObject; badobject_list, goodobject_list: TList; ArmorIsPlayable, ArmorHasEnch, ArmorHasKeyword, ArmorIsInList: boolean; WeaponIsPlayable, WeaponHasEnch, WeaponHasKeyword, WeaponIsInList: boolean; NewObject: boolean; begin InitializeMXPF; DefaultOptionsMXPF; PatchFileByName('EnchantCleaner.esp'); //----------------------------------------------------------------// SCRIPT EXCEPTIONS. DON'T EDIT ANYTHING ABOVE. ArmorScriptExceptions := TStringList.Create; // ArmorScriptExceptions.Add('???'); // ArmorScriptExceptions.Add('???'); // ArmorScriptExceptions.Add('???'); // ArmorScriptExceptions.Add('???'); WeaponScriptExceptions := TStringList.Create; WeaponScriptExceptions.Add('SilverSwordScript'); WeaponScriptExceptions.Add('DLC1EnhancedCrossBowAddPerkScript'); // WeaponScriptExceptions.Add('???'); // WeaponScriptExceptions.Add('???'); //----------------------------------------------------------------// SCRIPT EXCEPTIONS. DON'T EDIT ANYTHING BELOW. badlist_A := MainRecordByEditorID(GroupBySignature(mxPatchFile, 'FLST'), 'EC_ArmorList'); badforms_A := Add(badlist_A, 'FormIDs', true); Remove(ElementByIP(badlist_A, 'FormIDs\[0]')); goodlist_A := MainRecordByEditorID(GroupBySignature(mxPatchFile, 'FLST'), 'EC_ArmorList_NoEnch'); goodforms_A := Add(goodlist_A, 'FormIDs', true); Remove(ElementByIP(goodlist_A, 'FormIDs\[0]')); badlist_W := MainRecordByEditorID(GroupBySignature(mxPatchFile, 'FLST'), 'EC_WeaponList'); badforms_W := Add(badlist_W, 'FormIDs', true); Remove(ElementByIP(badlist_W, 'FormIDs\[0]')); goodlist_W := MainRecordByEditorID(GroupBySignature(mxPatchFile, 'FLST'), 'EC_WeaponList_NoEnch'); goodforms_W := Add(goodlist_W, 'FormIDs', true); Remove(ElementByIP(goodlist_W, 'FormIDs\[0]')); badobject_list := TList.Create; goodobject_list := TList.Create; LoadRecords('ARMO'); for index := 0 to MaxRecordIndex do begin badrec := GetRecord(index); ArmorIsPlayable := false; ArmorHasEnch := false; ArmorHasKeyword := false; P0 := StrToInt('0' + GetElementEditValues(badrec, 'Record Header\Record Flags\Non-Playable')); P1 := StrToInt('0' + GetElementEditValues(badrec, 'BODT\General Flags\(ARMO)Non-Playable')); P2 := StrToInt('0' + GetElementEditValues(badrec, 'BOD2\General Flags\(ARMO)Non-Playable')); if (P0 + P1 + P2 = 0) then ArmorIsPlayable := true; if (GetElementEditValues(badrec, 'EITM') <> '') then ArmorHasEnch := true; if (HasKeyword(badrec, 'MagicDisallowEnchanting') = true) then ArmorHasKeyword := true; ArmorIsInList := false; if (ArmorIsPlayable = true) and ((ArmorHasEnch = true) or (ArmorHasKeyword = true)) then ArmorIsInList := true; if (ArmorIsInList = true) then begin item_edid := GetElementEditValues(badrec, 'EDID'); item_name := Name(badrec); AddRequiredMasters(badrec, mxPatchFile); newbadform := ElementAssign(badforms_A, HighInteger, nil, false); SetEditValue(newbadform, item_name); while (GetElementEditValues(badrec, 'TNAM') <> '') do begin badrec := LinksTo(ElementByPath(badrec, 'TNAM')); badrec := HighestOverrideOrSelf(badrec, 4096); AddRequiredMasters(badrec, mxPatchFile); end; if (HasKeyword(badrec, 'MagicDisallowEnchanting') = false) and (GetElementEditValues(badrec, 'EITM') = '') then goodrec := badrec else begin badobject := TObject(badrec); object_index := badobject_list.IndexOf(badobject); if (object_index = -1) then begin goodrec := wbCopyElementToFile(badrec, mxPatchFile, true, true); goodobject := TObject(goodrec); badobject_list.Add(badobject); goodobject_list.Add(goodobject); NewObject := true; end else begin goodobject := goodobject_list[object_index]; goodrec := ObjectToElement(goodobject); NewObject := false; end; if (NewObject = true) then begin SetElementEditValues(goodrec, 'DESC', ''); Remove(ElementByIP(goodrec, 'EITM')); KWDA := ElementByPath(goodrec, 'KWDA'); for N := Pred(ElementCount(KWDA)) downto 0 do if (GetElementEditValues(LinksTo(ElementByIndex(KWDA, N)), 'EDID') = 'MagicDisallowEnchanting') then Remove(ElementByIndex(KWDA, N)); if (ElementCount(KWDA) = 0) then Remove(ElementByPath(goodrec, 'KWDA')); VMAD := ElementByPath(goodrec, 'VMAD\Scripts'); for N := Pred(ElementCount(VMAD)) downto 0 do if (ArmorScriptExceptions.IndexOf(GetElementEditValues(goodrec, 'VMAD\Scripts\[' + IntToStr(N) + ']\ScriptName')) = -1) then Remove(ElementByPath(goodrec, 'VMAD\Scripts\[' + IntToStr(N) + ']')); if (ElementCount(VMAD) = 0) then Remove(ElementByPath(goodrec, 'VMAD')); SetElementEditValues(goodrec, 'EDID', GetElementEditValues(goodrec, 'EDID') + '_ECDup'); end; end; newgoodform := ElementAssign(goodforms_A, HighInteger, nil, false); SetEditValue(newgoodform, Name(goodrec)); AddMessage(item_edid + ' -->-- ' + GetElementEditValues(goodrec, 'EDID')); end; end; for index := MaxRecordIndex downto 0 do RemoveRecord(index); badobject_list.Clear; goodobject_list.Clear; LoadRecords('WEAP'); for index := 0 to MaxRecordIndex do begin badrec := GetRecord(index); WeaponIsPlayable := false; WeaponHasEnch := false; WeaponHasKeyword := false; P0 := StrToInt('0' + GetElementEditValues(badrec, 'Record Header\Record Flags\Non-Playable')); P1 := StrToInt('0' + GetElementEditValues(badrec, 'DNAM\Flags\Non-playable')); if (P0 + P1 = 0) then WeaponIsPlayable := true; if (GetElementEditValues(badrec, 'EITM') <> '') then WeaponHasEnch := true; if (HasKeyword(badrec, 'MagicDisallowEnchanting') = true) then WeaponHasKeyword := true; WeaponIsInList := false; if (WeaponIsPlayable = true) and ((WeaponHasEnch = true) or (WeaponHasKeyword = true)) then WeaponIsInList := true; if (WeaponIsInList = true) then begin item_edid := GetElementEditValues(badrec, 'EDID'); item_name := Name(badrec); AddRequiredMasters(badrec, mxPatchFile); newbadform := ElementAssign(badforms_W, HighInteger, nil, false); SetEditValue(newbadform, item_name); while (GetElementEditValues(badrec, 'CNAM') <> '') do begin badrec := LinksTo(ElementByPath(badrec, 'CNAM')); badrec := HighestOverrideOrSelf(badrec, 4096); AddRequiredMasters(badrec, mxPatchFile); end; if (HasKeyword(badrec, 'MagicDisallowEnchanting') = false) and (GetElementEditValues(badrec, 'EITM') = '') then goodrec := badrec else begin badobject := TObject(badrec); object_index := badobject_list.IndexOf(badobject); if (object_index = -1) then begin goodrec := wbCopyElementToFile(badrec, mxPatchFile, true, true); goodobject := TObject(goodrec); badobject_list.Add(badobject); goodobject_list.Add(goodobject); NewObject := true; end else begin goodobject := goodobject_list[object_index]; goodrec := ObjectToElement(goodobject); NewObject := false; end; if (NewObject = true) then begin SetElementEditValues(goodrec, 'DESC', ''); Remove(ElementByIP(goodrec, 'EITM')); KWDA := ElementByPath(goodrec, 'KWDA'); for N := Pred(ElementCount(KWDA)) downto 0 do if (GetElementEditValues(LinksTo(ElementByIndex(KWDA, N)), 'EDID') = 'MagicDisallowEnchanting') then Remove(ElementByIndex(KWDA, N)); if (ElementCount(KWDA) = 0) then Remove(ElementByPath(goodrec, 'KWDA')); VMAD := ElementByPath(goodrec, 'VMAD\Scripts'); for N := Pred(ElementCount(VMAD)) downto 0 do if (WeaponScriptExceptions.IndexOf(GetElementEditValues(goodrec, 'VMAD\Scripts\[' + IntToStr(N) + ']\ScriptName')) = -1) then Remove(ElementByPath(goodrec, 'VMAD\Scripts\[' + IntToStr(N) + ']')); if (ElementCount(VMAD) = 0) then Remove(ElementByPath(goodrec, 'VMAD')); SetElementEditValues(goodrec, 'EDID', GetElementEditValues(goodrec, 'EDID') + '_ECDup'); end; end; newgoodform := ElementAssign(goodforms_W, HighInteger, nil, false); SetEditValue(newgoodform, Name(goodrec)); AddMessage(item_edid + ' -->-- ' + GetElementEditValues(goodrec, 'EDID')); end; end; for index := MaxRecordIndex downto 0 do RemoveRecord(index); badobject_list.Clear; goodobject_list.Clear; FinalizeMXPF; end; procedure AddRequiredMasters(rec: IInterface; target: IwbFile); var masters: TStringList; begin masters := TStringList.Create; AddMastersToList(GetFile(rec), masters); AddMastersToFile(target, masters, true); SortMasters(target); masters.Clear; end; end.