DieFeM

OverridesToNewRecords.pas

May 17th, 2020
1,631
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {
  2.   Convert overrides into new records, all references are updated with reindexed FormIDs
  3.   too so they must already exist in a plugin.
  4.   For example if you have an override of worldspace record [WRLD:00001234]
  5.   which references water [WATR:00005678], after applying script it would become
  6.   [WRLD:01001234] referencing [WATR:01005678] (assuming plugin is loaded at index 01).
  7. }
  8. unit OverridesToNewRecords;
  9.  
  10. procedure UpdateReferences(e: IInterface; ModLoadOrder: integer);
  11. var
  12.   ref: IInterface;
  13.   i: integer;
  14. begin
  15.   ref := LinksTo(e);
  16.   if Assigned(ref) then
  17.     if (GetLoadOrder(GetFile(ref)) <> ModLoadOrder) and (GetLoadOrder(GetFile(ref)) <> 0) then begin
  18.       i := GetLoadOrderFormID(ref);
  19.       i := (i and $FFFFFF) or (ModLoadOrder shl 24);
  20.       //AddMessage('Updating ref: ' + Path(e) + ' \ ' + GetEditValue(e));
  21.       try
  22.         SetEditValue(e, IntToHex(i, 8));
  23.       except
  24.         on E: Exception do begin
  25.           AddMessage('Error');
  26.         end
  27.       end;
  28.     end;
  29.  
  30.   if CanContainFormIDs(e) then begin
  31.     //AddMessage('Can Contain FormIDs: ' + Name(e));
  32.     for i := ElementCount(e) downto 0 do
  33.       UpdateReferences(ElementByIndex(e, i), ModLoadOrder);
  34.   end;
  35. end;
  36.  
  37. function Process(e: IInterface): integer;
  38. var
  39.   i, fid: integer;
  40. begin
  41.   // not an override
  42.   //if IsMaster(e) then
  43.     //Exit;
  44.    
  45.   //AddMessage('Override to new record: ' + Name(e));
  46.   i := GetLoadOrder(GetFile(e));
  47.   UpdateReferences(e, i);
  48.   fid := GetLoadOrderFormID(e);
  49.   fid := (fid and $FFFFFF) or (i shl 24);
  50.   SetLoadOrderFormID(e, fid);
  51.   //AddMessage(IntToStr(fid));
  52. end;
  53.  
  54. end.
RAW Paste Data