Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2018
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 9.24 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.   sTag: String;
  27.  
  28. // Options dialogue form prep
  29. procedure PrepareDialog(frm: TForm; caption: String; height, width: Integer);
  30. begin
  31.   frm.BorderStyle := bsDialog;
  32.   frm.Height := height;
  33.   frm.Width := width;
  34.   frm.Position := poScreenCenter;
  35.   frm.Caption := caption;
  36. end;
  37.  
  38. // Sets layout for Options dialogue form
  39. procedure ShowForm;
  40. var
  41.   frm: TForm;
  42.   lblPrompt: TLabel;
  43.   cbVIS, cbAWKCR, cbSkipPatched, cbWeightless: TCheckBox;
  44.   btnNewPatch, btnAmend, btnCancel: TButton;
  45.   i: integer;
  46. begin
  47.   frm := TForm.Create(nil);
  48.   try
  49.     // Create checkboxes
  50.     PrepareDialog(frm, 'R88 VIS-G Patcher Options', 260, 260);
  51.     lblPrompt := ConstructLabel(frm, frm, 16, 14, 40, 260 - 32, 'Please select your preferences', '');
  52.     cbVIS := ConstructCheckbox(frm, frm, lblPrompt.Top + 38, 50, 150, 'Run VIS patcher?', cbChecked, '');
  53.     cbVIS.ShowHint := true;
  54.     cbVIS.Hint := 'This enables the VIS patcher to automatically update item names in line with VIS-G and DEF_UIs icon tags';
  55.     cbAWKCR := ConstructCheckbox(frm, frm, cbVIS.Top + 20, 50, 150, 'Run AWKCR Workbench patcher?', cbChecked, '');
  56.     cbAWKCR.ShowHint := true;
  57.     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';    
  58.     cbSkipPatched := ConstructCheckbox(frm, frm, cbAWKCR.Top + 20, 50, 150, 'Skip already patched records', cbChecked, '');  
  59.     cbSkipPatched.ShowHint := true;
  60.     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.';
  61.     cbWeightless := ConstructCheckbox(frm, frm, cbSkipPatched.Top + 20, 50, 150, 'Weightless Scrap?', cbChecked, '');    
  62.     cbWeightless.ShowHint := true;
  63.     cbWeightless.Hint := 'This makes mod-added junk and scrap weightless';
  64.    
  65.    
  66.    
  67.     btnNewPatch := TButton.Create(frm);
  68.     btnNewPatch.Parent := frm;
  69.     btnNewPatch.Left := frm.Width div 2 - btnNewPatch.Width - 4;
  70.     btnNewPatch.Top := cbWeightless.Top + 35;
  71.     btnNewPatch.Caption := 'New Patch';
  72.     btnNewPatch.ModalResult := mrYes;
  73.     btnNewPatch.ShowHint := true;
  74.     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.';
  75.  
  76.     btnCancel := TButton.Create(frm);
  77.     btnCancel.Parent := frm;
  78.     btnCancel.Left := btnNewPatch.Left + btnNewPatch.Width + 8;
  79.     btnCancel.Top := btnNewPatch.Top;
  80.     btnCancel.Caption := 'Cancel';
  81.     btnCancel.ModalResult := mrCancel;
  82.  
  83.     i := frm.ShowModal;
  84.     UserCancelled := i = 2;
  85.     if not UserCancelled then begin
  86.       bVIS := cbVIS.Checked;
  87.       bAWKCR := cbAWKCR.Checked;
  88.       bSkipPatched := cbSkipPatched.Checked;
  89.       bWeightless := cbWeightless.Checked;
  90.     end;
  91.   finally
  92.     frm.Free;
  93.   end;
  94. end;
  95.  
  96.  
  97. ////////////////////////////////////////
  98. // Add any other custom functions here//
  99. ////////////////////////////////////////
  100.  
  101.  
  102. //Function to write TAG string to beginning of existing string.
  103. function AddTagString(sTag, sPath: String; rec: IInterface): IInterface;
  104. var
  105.   oldString: String;
  106. begin
  107.   oldString := geev(rec, sPath);
  108.   seev(rec, sPath, (sTag + ' ' + oldString));
  109. end;
  110.  
  111. function SetWeightless(rec: IInterface; sPath: String;):IInterface;
  112. begin
  113.   SetElementEditValues(rec, sPath, 0);
  114. end;
  115.  
  116.  
  117. ////////////////////////////
  118. // GROUP Filter Functions //
  119. ////////////////////////////
  120.  
  121. function filterAMMO(i: Integer; rec: IInterface): IInterface;
  122. begin
  123.   if (GetElementEditValues(rec, 'Record Header\Record Flags\Non-Playable') = '1') then
  124.     RemoveRecord(i);  
  125. end;
  126.  
  127. function filterARMO(i: Integer; rec: IInterface): IInterface;
  128. begin
  129.  
  130. end;
  131.  
  132. function filterMISC(i: Integer; rec: IInterface): IInterface;
  133. begin
  134.  
  135. end;
  136.  
  137. function filterWEAP(i: Integer; rec: IInterface): IInterface;
  138. begin
  139.  
  140. end;
  141.  
  142.  
  143. ///////////////////////////
  144. // GROUP Patch Functions //
  145. ///////////////////////////
  146.  
  147. function patchALCH(i: Integer; rec: IInterface):IInterface;
  148. begin
  149.   sTag := '(Alch)';
  150. end;
  151.  
  152. function patchAMMO(i: Integer; rec: IInterface):IInterface;
  153. begin
  154.   sTag := '(Ammo)';
  155. end;
  156.  
  157. function patchARMO(i: Integer; rec: IInterface):IInterface;
  158. begin
  159.   sTag := '(Armo)';
  160. end;
  161.  
  162. function patchBOOK(i: Integer; rec: IInterface):IInterface;
  163. begin
  164.   sTag := '(Book)';
  165. end;
  166.  
  167. function patchKEYM(i: Integer; rec: IInterface):IInterface;
  168. begin
  169.   sTag := '(Keym)';
  170. end;
  171.  
  172. function patchMISC(i: Integer; rec: IInterface):IInterface;
  173. begin
  174.   sTag := '(Misc)';
  175. end;
  176.  
  177. function patchNOTE(i: Integer; rec: IInterface):IInterface;
  178. begin
  179.   sTag := '(Note)';
  180. end;
  181.  
  182. function patchWEAP(i: Integer; rec: IInterface):IInterface;
  183. begin
  184.   sTag := '(Weap)';
  185. end;
  186.  
  187.  
  188. /////////////////
  189. // Main Script //
  190. /////////////////
  191.  
  192.  
  193. function Initialize: Integer;
  194.  
  195. var
  196.   i: Integer;
  197.   rec: IInterface;
  198.   sFiles: String;
  199.  
  200. begin
  201.  
  202.   // Call MXPF init functions and set MXPF prefs
  203.   InitializeMXPF;
  204.   mxLoadMasterRecords := true;
  205.   mxSkipPatchedRecords := false;
  206.   mxLoadWinningOverrides := true;
  207.   PatchFileByAuthor('R88_VIS-G_PatchFile');
  208.  
  209.   // Call form for user options.
  210.   ShowForm;
  211.   if UserCancelled then begin
  212.     AddMessage('User cancelled patching');
  213.     AddMessage('Operation cancelled. No patch generated');
  214.     exit;
  215.   end;
  216.  
  217.   ShowMessage('Script Initialising. Patching can take some time depending on the size of your mod list. Please be patient.');
  218.  
  219.   // Load valid records and remove groups from previous run patch.
  220.   LoadRecords('WEAP');
  221.   LoadRecords('NOTE');
  222.   LoadRecords('MISC');
  223.   LoadRecords('KEYM');
  224.   LoadRecords('BOOK');
  225.   LoadRecords('ARMO');
  226.   LoadRecords('AMMO');
  227.   LoadRecords('ALCH');
  228.   RemoveNode(GroupBySignature(mxPatchFile, 'ALCH'));
  229.   RemoveNode(GroupBySignature(mxPatchFile, 'AMMO'));
  230.   RemoveNode(GroupBySignature(mxPatchFile, 'ARMO'));
  231.   RemoveNode(GroupBySignature(mxPatchFile, 'BOOK'));
  232.   RemoveNode(GroupBySignature(mxPatchFile, 'KEYM'));
  233.   RemoveNode(GroupBySignature(mxPatchFile, 'MISC'));
  234.   RemoveNode(GroupBySignature(mxPatchFile, 'NOTE'));
  235.   RemoveNode(GroupBySignature(mxPatchFile, 'WEAP'));
  236.  
  237.   // Filter out unnecessary records on groups that may contain invalid records for tagging.
  238.   for i := MaxrecordIndex downto 0 do begin
  239.     rec := GetRecord(i);
  240.     if (geev(rec, 'Record Header\Signature') = 'AMMO') then
  241.       filterAMMO(i, rec)
  242.     else if (geev(rec, 'Record Header\Signature') = 'ARMO') then
  243.       filterARMO(i, rec)
  244.     else if (geev(rec, 'Record Header\Signature') = 'MISC') then
  245.       filterMISC(i, rec)
  246.     else if (geev(rec, 'Record Header\Signature') = 'WEAP') then
  247.       filterWEAP(i, rec);
  248.   end;
  249.  
  250.   // Copy remaining records to patch file.
  251.   CopyRecordsToPatch;
  252.  
  253.   // Patch Files
  254.   for i := 0 to MaxrecordIndex do begin
  255.     rec := GetPatchRecord(i);  
  256.     if (geev(rec, 'Record Header\Signature') = 'ALCH') then
  257.       begin
  258.         patchALCH(i, rec);
  259.         AddTagString(sTag, 'FULL - Name', rec);
  260.       end
  261.     else if (geev(rec, 'Record Header\Signature') = 'AMMO') then
  262.       begin
  263.         patchAMMO(i, rec);
  264.         AddTagString(sTag, 'FULL - Name', rec);
  265.       end
  266.     else if (geev(rec, 'Record Header\Signature') = 'ARMO') then
  267.       begin
  268.         patchARMO(i, rec);
  269.         AddTagString(sTag, 'FULL - Name', rec);
  270.       end
  271.     else if (geev(rec, 'Record Header\Signature') = 'BOOK') then
  272.       begin
  273.         patchBOOK(i, rec);
  274.         AddTagString(sTag, 'FULL - Name', rec);
  275.       end
  276.     else if (geev(rec, 'Record Header\Signature') = 'KEYM') then
  277.       begin
  278.         patchKEYM(i, rec);
  279.         AddTagString(sTag, 'FULL - Name', rec);
  280.       end
  281.     else if (geev(rec, 'Record Header\Signature') = 'MISC') then
  282.       begin
  283.         patchMISC(i, rec);
  284.         AddTagString(sTag, 'FULL - Name', rec);
  285.       end
  286.     else if (geev(rec, 'Record Header\Signature') = 'NOTE') then
  287.       begin
  288.         patchNOTE(i, rec);
  289.         AddTagString(sTag, 'FULL - Name', rec);
  290.       end
  291.     else if (geev(rec, 'Record Header\Signature') = 'WEAP') then
  292.       begin
  293.         patchWEAP(i, rec);
  294.         AddTagString(sTag, 'FULL - Name', rec);
  295.       end;
  296.   end;
  297.  
  298.   // Cleanup MXPF
  299.   CleanMasters(mxPatchFile);
  300.   PrintMXPFReport;
  301.   FinalizeMXPF;
  302.   ShowMessage('Patching Complete.');
  303. end;
  304. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement