DieFeM

CopyReferencedAsOverrides_CustomRecursive

May 17th, 2020
1,552
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. unit CopyReferencedAsOverrides_CustomRecursive;
  2.  
  3. procedure UpdateReferences(e: IInterface; ModLoadOrder: integer);
  4. var
  5.   ref,rref : IInterface;
  6.   i : integer;
  7. begin
  8.   ref := LinksTo(e);
  9.   if Assigned(ref) then begin
  10.     if (GetLoadOrder(GetFile(ref)) <> ModLoadOrder) and (GetLoadOrder(GetFile(ref)) <> 0) then begin
  11.       i := GetLoadOrderFormID(ref);
  12.       i := (i and $FFFFFF) or (ModLoadOrder shl 24);
  13.       try
  14.         //AddMessage('Updating ref: ' + Path(e) + ' \ ' + GetEditValue(e));
  15.         SetEditValue(e, IntToHex(i, 8));
  16.       except
  17.         on E: Exception do begin
  18.           try
  19.             //AddMessage('Copying ref as override: ' + GetEditValue(ref));
  20.             rref := wbCopyElementToFile(ref, FileByLoadOrder(ModLoadOrder), False, True); // copy as override
  21.             if CanContainFormIDs(rref) then
  22.               for i := ElementCount(rref) downto 0 do
  23.                 UpdateReferences(ElementByIndex(rref, i), ModLoadOrder);
  24.           except
  25.             on E: Exception do begin
  26.               AddMessage('Failed to copy: ' + FullPath(ref));
  27.             end
  28.           end;
  29.          
  30.         end
  31.       end;
  32.     end;
  33.   end;
  34.   if CanContainFormIDs(e) then
  35.     for i := ElementCount(e) downto 0 do
  36.       UpdateReferences(ElementByIndex(e, i), ModLoadOrder);
  37. end;
  38.  
  39. function Process(e: IInterface): integer;
  40. var
  41.   i, fid: integer;
  42. begin
  43.   i := GetLoadOrder(GetFile(e));
  44.   UpdateReferences(e, i);
  45.   // not an override
  46.   //if IsMaster(e) then
  47.     //Exit;
  48.   //AddMessage('Override to new record: ' + Name(e));
  49.   //fid := GetLoadOrderFormID(e);
  50.   //fid := (fid and $FFFFFF) or (i shl 24);
  51.   //SetLoadOrderFormID(e, fid);
  52. end;
  53.  
  54. end.
RAW Paste Data