Hazuzi

WSE mod description script

Jul 30th, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.54 KB | None | 0 0
  1. unit FO4PatchOmodDescriptions;
  2.  
  3. const
  4. sPropertiesList = wbScriptsPath + 'a.txt';
  5.  
  6. var
  7. slPropertyMap: TStringList;
  8. plugin: IInterface;
  9.  
  10. function GetMappedValue(prop: IInterface): String;
  11. var
  12. valuetype, valuefunctiontype, valuePropertytype: string;
  13. f: Real;
  14. g: String;
  15. begin
  16. valuetype := GetElementEditValues(prop, 'Value Type');
  17. valuePropertytype := GetElementEditValues(prop, 'Property');
  18. valuefunctiontype := GetElementEditValues(prop, 'Function Type');
  19.  
  20. if (valuetype = 'FormID,Float') and (valuefunctiontype = 'MUL+ADD') then begin
  21. f := GetNativeValue(ElementByIndex(prop, 6));
  22. if f > 1.0 then
  23. Result := FloatToStr(f) + 'x'
  24. else if f > 0.0 then
  25. Result := '+' + IntToStr(Int(f * 100)) + '%'
  26. else
  27. Result := IntToStr(Int(f * 100)) + '%';
  28. end
  29. else if (valuetype = 'Float') and (valuefunctiontype = 'MUL+ADD') then begin
  30. f := GetNativeValue(ElementByIndex(prop, 6));
  31. if f > 1.0 then
  32. Result := FloatToStr(f) + 'x'
  33. else if f > 0.0 then
  34. Result := '+' + IntToStr(Int(f * 100)) + '%'
  35. else
  36. Result := IntToStr(Int(f * 100)) + '%';
  37. end
  38. else if (valuetype = 'Float') and (valuefunctiontype = 'MinRange') then begin
  39. f := GetNativeValue(ElementByIndex(prop, 6));
  40. Result := FloatToStr(f) + 'units';
  41. end
  42. else if valuetype = 'Float' then begin
  43. f := GetNativeValue(ElementByIndex(prop, 6));
  44. if f > 1.0 then
  45. Result := FloatToStr(f) + 'x'
  46. else if f > 0.0 then
  47. Result := '+' + IntToStr(Int(f * 100)) + '%'
  48. else
  49. Result := IntToStr(Int(f * 100)) + '%';
  50. end
  51. else if valuetype = 'FormID,Float' then begin
  52. f := GetNativeValue(ElementByIndex(prop, 7));
  53. Result := FloatToStr(f);
  54. end
  55. else if valuetype = 'Int' then begin
  56. f := GetNativeValue(ElementByIndex(prop, 6));
  57. Result := FloatToStr(f);
  58.  
  59. end
  60. else if (valuetype = 'FormID,Int') and (valuePropertytype = 'ZoomData') then begin
  61. Result := slPropertyMap.Values[GetEditValue(ElementByIndex(prop, 6))];
  62. end
  63. else if valuetype = 'FormID,Int' then begin
  64. f := GetNativeValue(ElementByIndex(prop, 6));
  65. if f > 1.0 then
  66. Result := FloatToStr(f);
  67. end
  68. else if valuetype = 'FormID,Float' then begin
  69. Result := slPropertyMap.Values[GetEditValue(ElementByIndex(prop, 7))];
  70. end
  71. end;
  72.  
  73.  
  74. function GetMappedDescription(prop: IInterface; propname: String): String;
  75. var
  76. mappedName, mappedValue, query, queryfunction: String;
  77. f: Real;
  78. begin
  79. mappedName := slPropertyMap.Values[propname];
  80. mappedValue := GetMappedValue(prop);
  81. query := slPropertyMap.Values[GetEditValue(ElementByIndex(prop, 6))];
  82. queryfunction := GetElementEditValues(prop, 'Function Type');
  83.  
  84. if mappedValue = '' then exit;
  85. if mappedName = 'Potato' then exit;
  86. if query = 'Potato' then exit;
  87. if mappedValue = '\\' then
  88. Result := Format('%s%s', [mappedName, mappedValue])+ ''
  89. else if mappedName = 'Damage_Type' then
  90. Result := 'Additional ' + Format('%s' + ' Damage: ' + '%s', [query, mappedValue])
  91. else if mappedName = 'Damage_Resistance' then
  92. Result := Format('%s' + ' Damage Reduced by: ' + '%s', [query, mappedValue])
  93. else if mappedName = 'Actor_Values_Type' then
  94. Result := Format('%s' + '+' + '%s', [query, mappedValue])
  95. else if (mappedName = 'Keywords_Values_Type') or (mappedName = 'MaterialSwaps_Values_Type') or (mappedName = 'Enchantments_Value') or (mappedName = 'MaterialSwaps_Values_Type') or (mappedName = 'Ammo_Type') then
  96. Result := Format('%s', [query])
  97. else
  98. Result := Format('%s%s', [mappedName, mappedValue]); //output layout
  99. end;
  100.  
  101. function GetOmodDescription(rec: IInterface): String;
  102. var
  103. i, j: Integer;
  104. prop, properties: IInterface;
  105. propname: string;
  106. sl: TStringList;
  107. begin
  108. sl := TStringList.Create;
  109.  
  110. properties := ElementByPath(rec, 'DATA\\Properties');
  111. for i := 0 to Pred(ElementCount(properties)) do begin
  112. prop := ElementByIndex(properties, i);
  113. propname := GetElementEditValues(prop, 'Property');
  114. j := slPropertyMap.IndexOfName(propname);
  115. if j = -1 then Continue;
  116. // add property index as prefix for sorting
  117. sl.Add( Format('%.3d', [j]) + GetMappedDescription(prop, propname) );
  118. end;
  119.  
  120.  
  121. // sort, concatenate and remove prefixes
  122. sl.Sort;
  123. for i := 0 to sl.Count - 1 do begin
  124. if Result <> '' then Result := Result + ' | ';
  125. Result := Result + Copy(sl[i], 4, Length(sl[i]));
  126. end;
  127.  
  128. sl.Free;
  129. end;
  130.  
  131. function Initialize: Integer;
  132. begin
  133. slPropertyMap := TStringList.Create;
  134. slPropertyMap.LoadFromFile(sPropertiesList);
  135. end;
  136.  
  137. function Process(e: IInterface): Integer;
  138. var
  139. desc: string;
  140. r: IInterface;
  141. begin
  142. if Signature(e) <> 'OMOD' then
  143. Exit;
  144.  
  145. // patch the winning override record
  146. e := WinningOverride(e);
  147.  
  148. desc := GetOmodDescription(e);
  149.  
  150. if desc = '' then
  151. Exit;
  152.  
  153. // create new plugin
  154. if not Assigned(plugin) then begin
  155. if MessageDlg('Create new patch plugin [YES] or append to the last loaded one [NO]?', mtConfirmation, [mbYes, mbNo], 0) = mrYes then
  156. plugin := AddNewFile
  157. else
  158. plugin := FileByIndex(Pred(FileCount));
  159. if not Assigned(plugin) then begin
  160. Result := 1;
  161. Exit;
  162. end;
  163. end;
  164.  
  165. // skip already copied
  166. if GetFileName(e) = GetFileName(plugin) then
  167. Exit;
  168.  
  169. // add masters
  170. AddRequiredElementMasters(e, plugin, False);
  171.  
  172. try
  173. // copy as override
  174. r := wbCopyElementToFile(e, plugin, False, True);
  175. // setting new description
  176. SetElementEditValues(r, 'DESC', desc);
  177. except
  178. on Ex: Exception do begin
  179. AddMessage('Failed to copy: ' + FullPath(e));
  180. AddMessage(' reason: ' + Ex.Message);
  181. end
  182. end;
  183.  
  184. end;
  185.  
  186. function Finalize: Integer;
  187. begin
  188. slPropertyMap.Free;
  189. if Assigned(plugin) then
  190. SortMasters(plugin);
  191. end;
  192.  
  193. end.
Advertisement
Add Comment
Please, Sign In to add comment