Skip to content

Instantly share code, notes, and snippets.

@aers
Created January 15, 2019 04:40
Show Gist options
  • Save aers/953a50c61b3028bce7e5376e8590abed to your computer and use it in GitHub Desktop.
Save aers/953a50c61b3028bce7e5376e8590abed to your computer and use it in GitHub Desktop.
xedit count loaded refrs in load order
Unit CountLoadedRefs;
Var
giTemporaryCount: Integer;
giPersistentCount: Integer;
giPluginTemporaryCount: Integer;
giPluginPersistentCount: Integer;
Const
gtPersistent = 8;
gtTemporary = 9;
Procedure IncCount(iTemporaryCount: Integer; iPersistentCount: Integer;);
Begin
giPluginTemporaryCount := giPluginTemporaryCount + iTemporaryCount;
giPluginPersistentCount := giPluginPersistentCount + iPersistentCount;
giTemporaryCount := giTemporaryCount + iTemporaryCount;
giPersistentCount := giPersistentCount + iPersistentCount;
End;
// Always count NEW Persistent Refs, never overridden ones
// Only count NEW Temporary Refs if new in esp, or previous overload was a master.
Function GetRefCount(eCell: IInterface; eCellChildren: IInterface; AGrupType: Integer; bESM: Boolean): Integer;
Var
eCellGroup: IInterface;
iChildIndex: Integer;
eChildElement: IInterface;
Begin
eCellGroup := FindChildGroup(eCellChildren, AGrupType, eCell);
Result := 0;
for iChildIndex := 0 To ElementCount(eCellGroup) - 1 Do Begin
eChildElement := ElementByIndex(eCellGroup, iChildIndex);
if (Signature(eChildElement) = 'REFR') or (Signature(eChildElement) = 'ACHR') or (Signature(eChildElement) = 'PHZD') then Begin
if AGrupType = gtTemporary Then Begin
if not bESM and IsWinningOverride(eChildElement) Then
Result := Result + 1;
End Else if AGrupType = gtPersistent Then Begin
if IsMaster(eChildElement) Then
Result := Result + 1;
End;
End;
End;
End;
Procedure CountRefsInCell(eCell: IInterface; bESM: Boolean);
Var
eCellChildren: IInterface;
iPersistentCount: Integer;
iTemporaryCount: Integer;
Begin
eCellChildren := ChildGroup(eCell);
iPersistentCount := GetRefCount(eCell, eCellChildren, gtPersistent, bESM);
iTemporaryCount := GetRefCount(eCell, eCellChildren, gtTemporary, bESM);
IncCount(iTemporaryCount, iPersistentCount);
End;
Procedure CountCellSpace(eBlockParent: IInterface; bESM: Boolean);
Var
eBlock: IInterface;
eSubBlock: IInterface;
eCell: IInterface;
iBlockIndex: Integer;
iSubBlockIndex: Integer;
iCellIndex: Integer;
Begin
For iBlockIndex := 0 To ElementCount(eBlockParent) - 1 Do Begin
eBlock := ElementByIndex(eBlockParent, iBlockIndex);
For iSubBlockIndex := 0 To ElementCount(eBlock) - 1 Do Begin
eSubBlock := ElementByIndex(eBlock, iSubBlockIndex);
for iCellIndex := 0 To ElementCount(eSubBlock) - 1 Do Begin
eCell := ElementByIndex(eSubBlock, iCellIndex);
CountRefsInCell(eCell, bESM);
End;
End;
End;
End;
Function Initialize: Integer;
Var
eFile: IInterface;
eWorlds: IInterface;
eWorld: IInterface;
eTemporary: IInterface;
eCell: IInterface;
eCells: IInterface;
iFileIndex: Integer;
iWorldIndex: Integer;
bESM: Boolean;
iTotalPluginCount: Integer;
Begin
giTemporaryCount := 0;
giPersistentCount := 0;
//
For iFileIndex := 0 To FileCount - 1 Do Begin
giPluginTemporaryCount := 0;
giPluginPersistentCount := 0;
eFile := FileByIndex(iFileIndex);
bESM := GetIsESM(eFile);
CountCellSpace(GroupBySignature(eFile, 'CELL'), bESM);
eWorlds := GroupBySignature(eFile, 'WRLD');
For iWorldIndex := 0 To ElementCount(eWorlds) - 1 Do Begin
eWorld := ElementByIndex(eWorlds, iWorldIndex);
eTemporary := ChildGroup(eWorld);
eCell := ElementByName(eTemporary, '<Persistent Worldspace Cell>');
CountRefsInCell(eCell, bESM);
CountCellSpace(eWorld, bESM);
End;
iTotalPluginCount := giPluginPersistentCount + giPluginTemporaryCount;
if iTotalPluginCount > 100 then
AddMessage(Format(
'Found %d temporary and %d persistent (%d total) loaded references in %s.', [giPluginTemporaryCount, giPluginPersistentCount, iTotalPluginCount, Name(eFile)]));
End;
AddMessage(Format(
'Found %d temporary and %d persistent loaded references, for a grand total of %d loaded references.', [giTemporaryCount, giPersistentCount, giTemporaryCount + giPersistentCount]
));
End;
End.
@Glanzer-modder
Copy link

When it's done how do I see what mods have the most refs?

It should spit out a separate line for every mod that has refs in it. Here are the last few lines when I ran it:

Found 1227 temporary and 4 persistent (1231 total) loaded references in [FE 385] PCE - ELFX PATCH.esp.
Found 184 temporary and 0 persistent (184 total) loaded references in [FE 387] JKs Understone Keep - PCE patch.esp.
Found 163 temporary and 0 persistent (163 total) loaded references in [FE 388] JKs Understone Keep - PCE - ELFX patch.esp.
Found 8597 temporary and 329 persistent (8926 total) loaded references in [E5] DungeonsRevisited.esp.
Found 0 temporary and 106 persistent (106 total) loaded references in [FE 3B7] GLZ-Blacksmith Forge Water patch.esp.
Found 3 temporary and 935 persistent (938 total) loaded references in [EA] Atlas Map Markers.esp.
Found 333 temporary and 11949 persistent (12282 total) loaded references in [EB] DynDOLOD.esp.
Found 8753 temporary and 0 persistent (8753 total) loaded references in [FE 3C5] Synthesis.esp.
Found 505178 temporary and 130505 persistent loaded references, for a grand total of 635683 loaded references.
[03:17] Done: Applying script "count_loaded_refs_in_load_order", Elapsed Time: 03:17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment