Advertisement
Guest User

iActivate - Patcher

a guest
Jun 1st, 2015
403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.96 KB | None | 0 0
  1. unit UserScript;
  2.  
  3. uses mteFunctions;
  4.  
  5. var
  6.   files, masters: TStringList;
  7.   userFile: IInterface;
  8.  
  9. procedure FixRNAM(g: IInterface);
  10. var
  11.   i: integer;
  12.   r: IInterface;
  13.   s1, s2: string;
  14.  
  15. begin
  16.   for i := 0 to Pred(ElementCount(g)) do begin
  17.     r := ElementByIndex(g, i);
  18.     s1 := Copy(EditorID(r), 1, 35);
  19.     s2 := Copy(EditorID(r), 1, 9);
  20.  
  21.     if not ElementExists(r, 'RNAM') then    // Skips all records which doens't contain RNAM.
  22.       continue;  
  23.     if s1 = 'DLC2ApocryphaConstellationActivator' then      // Skips all records with the editorID s1. Needed because of unwanted edits.
  24.       continue;
  25.     if s2 = 'CWMapFlag' then        // Skips all records with the editorID s2. Needed because of unwanted edits.
  26.       continue;
  27.  
  28.     AddMessage('    Fixing '+Name(r));
  29.     try
  30.       r := wbCopyElementToFile(r, userFile, false, true);   //If record gets through all the above criteria, copies the record to the userfile.
  31.       SetElementEditValues(r, 'RNAM', '');      //Preforms the actual change by replacing the RNAMs string with nothing: '')
  32.     except
  33.       on x : Exception do AddMessage('    Failed to fix record. '+x.Message);
  34.     end;  
  35.   end;
  36. end;
  37.  
  38. function Initialize: Integer;
  39. var
  40.   i: integer;
  41. begin
  42.   i := MessageDlg('Before running this script, please be sure to read the installation section for iActivate on the Nexus.'+Chr(13)+''+Chr(13)+'Are you sure you wish to continue?', mtConfirmation, [mbYes, mbCancel], 0);
  43.   if i = mrYes then begin  
  44.   end else begin
  45.     Result := 1;
  46.     Exit;
  47.   end;
  48.   files := TStringList.Create;
  49.   masters := TStringList.Create;
  50.   ScriptProcessElements := [etFile];  // Process function will only get the files the user selected
  51. end;
  52.  
  53. function Process(e: IInterface): Integer;
  54. begin
  55.   if StrEndsWith(GetFileName(e), '.dat') then exit; // Skips hardcoded objects
  56.   files.AddObject(GetFileName(e), TObject(e));
  57.   AddMastersToList(e, masters);
  58. end;
  59.  
  60. function Finalize: Integer;
  61. var
  62.   i: integer;
  63.   f, g: IInterface;
  64. begin
  65.   if files.Count = 0 then begin
  66.     AddMessage('No files selected. Terminating script.');
  67.     files.Free;
  68.     masters.Free;
  69.     exit;
  70.   end;
  71.   userFile := AddNewFile;
  72.   if not Assigned(userFile) then begin
  73.     AddMessage('Failed to create patch.');
  74.     files.Free;
  75.     masters.Free;
  76.     exit;
  77.   end;
  78.   AddMastersToFile(userFile, masters, true);
  79.   for i := Pred(files.Count) downto 0 do begin
  80.     f := ObjectToElement(files.Objects[i]);
  81.     AddMessage('Processing file: '+files[i]);
  82.  
  83.     // Process ACTI record group (Action)
  84.     g := GroupBySignature(f, 'ACTI');
  85.     if Assigned(g) then begin
  86.       AddMessage('  Processing Group: ACTI');
  87.       FixRNAM(g);
  88.     end;
  89.     // Process FLOR record group (Flora)
  90.     g := GroupBySignature(f, 'FLOR');
  91.     if Assigned(g) then begin
  92.       AddMessage('  Processing Group: FLOR');
  93.       FixRNAM(g);
  94.     end;
  95.   end;
  96.  
  97.   // Clean masters
  98.   CleanMasters(userFile);
  99.  
  100.   // Free memory
  101.   files.Free;
  102.   masters.Free;
  103. end;
  104.  
  105. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement