Advertisement
Gernash

BMD-Renamer

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