Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 7.74 KB | None | 0 0
  1. {
  2.   Ruddy88's VIS-G Auto Patcher
  3.   FALLOUT 4
  4.  
  5.   Aim: This script utility will automatically add all valid items for DEF_UI's tag system to a single patch ESP.
  6.   The items will attempt to auto categorise themself in line with Gambit's VIS-G categorisation.
  7.  
  8.   Items that can not be accurately categorised will still be assigned a generic category as close to accurate as it can.
  9.   No valid items will be ignored, so users are free to manually tweak the patch afterward with all valid items in one
  10.   convenient location.
  11.  
  12.   Requires: FO4Edit, MXPF (for Skyrim, Works in Fallout4).
  13.  
  14.   Credits:
  15.   MatorTheEternal (For MXPF and helping me throughout my entire modding life so far)
  16.   Valdacil (for VIS)
  17.   Gambit (For his contributions and for VIS-G)
  18.   Many others from many discords, too many to name.
  19.  }
  20.  
  21. unit UserScript;
  22. // Import MXPF functions
  23. uses 'lib\mxpf';
  24. var
  25.   UserCancelled, ResetPatch, bVIS, bAWKCR, bSkipPatched, bWeightless: Boolean;
  26.  
  27. // Options dialogue form prep
  28. procedure PrepareDialog(frm: TForm; caption: String; height, width: Integer);
  29. begin
  30.   frm.BorderStyle := bsDialog;
  31.   frm.Height := height;
  32.   frm.Width := width;
  33.   frm.Position := poScreenCenter;
  34.   frm.Caption := caption;
  35. end;
  36.  
  37. // Sets layout for Options dialogue form
  38. procedure ShowForm;
  39. var
  40.   frm: TForm;
  41.   lblPrompt: TLabel;
  42.   cbVIS, cbAWKCR, cbSkipPatched, cbWeightless: TCheckBox;
  43.   btnNewPatch, btnAmend, btnCancel: TButton;
  44.   i: integer;
  45. begin
  46.   frm := TForm.Create(nil);
  47.   try
  48.     // Create checkboxes
  49.     PrepareDialog(frm, 'R88 VIS-G Patcher Options', 260, 260);
  50.     lblPrompt := ConstructLabel(frm, frm, 16, 14, 40, 260 - 32, 'Please select your preferences', '');
  51.     cbVIS := ConstructCheckbox(frm, frm, lblPrompt.Top + 38, 50, 150, 'Run VIS patcher?', cbChecked, '');
  52.     cbVIS.ShowHint := true;
  53.     cbVIS.Hint := 'This enables the VIS patcher to automatically update item names in line with VIS-G and DEF_UIs icon tags';
  54.     cbAWKCR := ConstructCheckbox(frm, frm, cbVIS.Top + 20, 50, 150, 'Run AWKCR Workbench patcher?', cbChecked, '');
  55.     cbAWKCR.ShowHint := true;
  56.     cbAWKCR.Hint := 'This enables the AWKCR patcher to automatically add item recipes to the AWKCR workbenches where appropriate. Will use existing category or will assign to "Other" category';    
  57.     cbSkipPatched := ConstructCheckbox(frm, frm, cbAWKCR.Top + 20, 50, 150, 'Skip already patched records', cbChecked, '');  
  58.     cbSkipPatched.ShowHint := true;
  59.     cbSkipPatched.Hint := 'NOT IMPLEMENTED: This gives you the option to skip records that have already been patched or to override all valid records with the scripts categorisation.';
  60.     cbWeightless := ConstructCheckbox(frm, frm, cbSkipPatched.Top + 20, 50, 150, 'Weightless Scrap?', cbChecked, '');    
  61.     cbWeightless.ShowHint := true;
  62.     cbWeightless.Hint := 'This makes mod-added junk and scrap weightless';
  63.    
  64.    
  65.    
  66.     btnNewPatch := TButton.Create(frm);
  67.     btnNewPatch.Parent := frm;
  68.     btnNewPatch.Left := frm.Width div 2 - btnNewPatch.Width - 4;
  69.     btnNewPatch.Top := cbWeightless.Top + 35;
  70.     btnNewPatch.Caption := 'New Patch';
  71.     btnNewPatch.ModalResult := mrYes;
  72.     btnNewPatch.ShowHint := true;
  73.     btnNewPatch.Hint := 'Choose this if you are generating a patch for the first time or if you would like to RESET and clear all items in an existing patch.';
  74.  
  75.     btnCancel := TButton.Create(frm);
  76.     btnCancel.Parent := frm;
  77.     btnCancel.Left := btnNewPatch.Left + btnNewPatch.Width + 8;
  78.     btnCancel.Top := btnNewPatch.Top;
  79.     btnCancel.Caption := 'Cancel';
  80.     btnCancel.ModalResult := mrCancel;
  81.  
  82.     i := frm.ShowModal;
  83.     UserCancelled := i = 2;
  84.     if not UserCancelled then begin
  85.       bVIS := cbVIS.Checked;
  86.       bAWKCR := cbAWKCR.Checked;
  87.       bSkipPatched := cbSkipPatched.Checked;
  88.       bWeightless := cbWeightless.Checked;
  89.     end;
  90.   finally
  91.     frm.Free;
  92.   end;
  93. end;
  94.  
  95.  
  96. ////////////////////////////////////////
  97. // Add any other custom functions here//
  98. ////////////////////////////////////////
  99.  
  100.  
  101. //Function to write TAG string to beginning of existing string.
  102. function AddTagString(sTag, sPath: String; newRec: IInterface): IInterface;
  103. var
  104.   oldString: String;
  105. begin
  106.   oldString := geev(newRec, sPath);
  107.   seev(newRec, sPath, (sTag + ' ' + oldString));
  108. end;
  109.  
  110.  
  111. /////////////////
  112. // Main Script //
  113. /////////////////
  114.  
  115.  
  116. function Initialize: Integer;
  117.  
  118. var
  119.   i: Integer;
  120.   rec, newRec: IInterface;
  121.   sFiles, sTag: String;
  122.  
  123. begin
  124.  
  125.   InitializeMXPF;
  126.   mxLoadMasterRecords := true;
  127.   mxSkipPatchedRecords := true;
  128.   mxLoadWinningOverrides := true;
  129.   PatchFileByAuthor('R88_VIS-G_PatchFile');
  130.  
  131.   ShowForm;
  132.   if UserCancelled then begin
  133.     AddMessage('User cancelled patching');
  134.     AddMessage('Operation cancelled. No patch generated');
  135.     exit;
  136.   end;
  137.   ShowMessage('Script Initialising. Patching can take some time depending on the size of your mod list. Please be patient.');
  138.  
  139.   //ALCH Sorting
  140.   LoadRecords('ALCH');
  141.   RemoveNode(GroupBySignature(mxPatchFile, 'ALCH'));
  142.   for i := MaxRecordIndex downto 0 do begin
  143.     rec := GetRecord(i);
  144.     newRec := CopyRecordToPatch(i);
  145.     sTag := '(Tag)';
  146.     AddTagString(sTag, 'FULL - Name', newRec);
  147.  
  148.   end;
  149.   AddMastersToPatch;
  150.   AddMessage('ALCH records Patched.');
  151.  
  152.   //AMMO Sorting
  153.   LoadRecords('AMMO');
  154.   RemoveNode(GroupBySignature(mxPatchFile, 'AMMO'));
  155.   for i := MaxRecordIndex downto 0 do begin
  156.     rec := GetRecord(i);
  157.     newRec := CopyRecordToPatch(i);
  158.     sTag := '(Tag)';
  159.     AddTagString(sTag, 'FULL - Name', newRec);
  160.  
  161.   end;
  162.   AddMastersToPatch;
  163.   AddMessage('AMMO records Patched.');
  164.  
  165.   //ARMO Sorting
  166.   LoadRecords('ARMO');
  167.   RemoveNode(GroupBySignature(mxPatchFile, 'ARMO'));
  168.   for i := MaxRecordIndex downto 0 do begin
  169.     rec := GetRecord(i);
  170.     newRec := CopyRecordToPatch(i);
  171.     sTag := '(Tag)';
  172.     AddTagString(sTag, 'FULL - Name', newRec);
  173.  
  174.   end;
  175.   AddMastersToPatch;
  176.   AddMessage('ARMO records Patched.');
  177.  
  178.   //BOOK Sorting
  179.   LoadRecords('BOOK');
  180.   RemoveNode(GroupBySignature(mxPatchFile, 'BOOK'));
  181.   for i := MaxRecordIndex downto 0 do begin
  182.     rec := GetRecord(i);
  183.     newRec := CopyRecordToPatch(i);
  184.     sTag := '(Tag)';
  185.     AddTagString(sTag, 'FULL - Name', newRec);
  186.  
  187.   end;
  188.   AddMastersToPatch;
  189.   AddMessage('BOOK records Patched.');
  190.  
  191.   //KEYM Sorting
  192.   LoadRecords('KEYM');
  193.   RemoveNode(GroupBySignature(mxPatchFile, 'KEYM'));
  194.   for i := MaxRecordIndex downto 0 do begin
  195.     rec := GetRecord(i);
  196.     newRec := CopyRecordToPatch(i);
  197.     sTag := '(Tag)';
  198.     AddTagString(sTag, 'FULL - Name', newRec);
  199.  
  200.   end;
  201.   AddMastersToPatch;
  202.   AddMessage('KEYM records Patched.');
  203.  
  204.   //MISC Sorting
  205.   LoadRecords('MISC');
  206.   RemoveNode(GroupBySignature(mxPatchFile, 'MISC'));
  207.   for i := MaxRecordIndex downto 0 do begin
  208.     rec := GetRecord(i);
  209.     newRec := CopyRecordToPatch(i);
  210.     sTag := '(Tag)';
  211.     AddTagString(sTag, 'FULL - Name', newRec);
  212.  
  213.   end;
  214.   AddMastersToPatch;
  215.   AddMessage('MISC records Patched.');
  216.  
  217.   //NOTE Sorting
  218.   LoadRecords('NOTE');
  219.   RemoveNode(GroupBySignature(mxPatchFile, 'NOTE'));
  220.   for i := MaxRecordIndex downto 0 do begin
  221.     rec := GetRecord(i);
  222.     newRec := CopyRecordToPatch(i);
  223.     sTag := '(Tag)';
  224.     AddTagString(sTag, 'FULL - Name', newRec);
  225.  
  226.   end;
  227.   AddMastersToPatch;
  228.   AddMessage('NOTE records Patched.');
  229.  
  230.   //WEAP Sorting
  231.   LoadRecords('WEAP');
  232.   RemoveNode(GroupBySignature(mxPatchFile, 'WEAP'));
  233.   for i := MaxRecordIndex downto 0 do begin
  234.     rec := GetRecord(i);
  235.     newRec := CopyRecordToPatch(i);
  236.     sTag := '(Tag)';
  237.     AddTagString(sTag, 'FULL - Name', newRec);
  238.  
  239.   end;
  240.   AddMastersToPatch;
  241.   AddMessage('WEAP records Patched.');
  242.  
  243.  
  244.   // Cleanup MXPF
  245.   CleanMasters(mxPatchFile);
  246.   PrintMXPFReport;
  247.   FinalizeMXPF;
  248.   ShowMessage('Patching Complete.');
  249. end;
  250. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement