-
Notifications
You must be signed in to change notification settings - Fork 1
/
DM_WAED_GetIDs.pas
248 lines (214 loc) · 5.34 KB
/
DM_WAED_GetIDs.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
unit DM_EC_GetIDs;
{
Hotkey: Ctrl+Shift+F5
}
uses xEditApi, SysUtils, StrUtils;
var
output, output2: TStringList;
const
enchFmt =
' "%s": {'#13#10
' "enchantName": "%s",'#13#10
' "enchantId": "%s"'#13#10
' },';
fullFmt =
' {'#13#10
' "newItemName": "%s",'#13#10
' "itemName": "%s",'#13#10
' "itemId": "%s",'#13#10 +
' "enchantName": "%s",'#13#10
' "enchantId": "%s"'#13#10
' },';
function IsESL(f: IInterface): Boolean;
begin
Result := GetElementEditValues(ElementByIndex(f, 0), 'Record Header\Record Flags\ESL') = 1;
end;
function ActualFixedFormId(e: IInterface): string;
var
fID, ffID: Cardinal;
begin
fID := FormID(e);
if(IsESL(GetFile(e))) then ffID := fID and $FFF
else ffID := fID and $FFFFFF;
Result := Lowercase(IntToHex(ffID, 1));
end;
function RecordToStr(e: IInterface): string;
begin
Result := Format('%s|0x%s', [
GetFileName(GetFile(e)),
ActualFixedFormId(e)
]);
end;
// TODO: DELETE
function GetId(e: IInterface): string;
begin
Result := '';
if Assigned(e) then
Result := RecordToStr(MasterOrSelf(e));
end;
function GetUniqueId(e: IInterface): string;
begin
Result := '';
if Assigned(e) then
Result := RecordToStr(MasterOrSelf(e));
end;
function GetName(e: IInterface): string;
begin
Result := '';
if Assigned(e) then
Result := GetElementEditValues(e, 'FULL');
end;
// TODO: DELETE
function GetWeaponArmor(e: IInterface): string;
var
rName: string;
ench: Variant;
begin
ench := LinksTo(ElementByPath(e, 'EITM'));
rName := GetName(e);
Result := Format(fullFmt, [rName, rName, GetId(e), GetName(ench), GetId(ench)]);
if Assigned(ench) then
output2.Add(GetEnchant(ench));
end;
// TODO: DELETE
function GetEnchantMagnitude(e: IInterface): string;
var
i, n: Integer;
fxs, fx, ench: IInterface;
mag: Real;
mags: TStringList;
eName: string;
const
fmt = '%s (%g)';
begin
mags := TStringList.Create;
try
fxs := ElementByPath(e, 'Effects');
n := ElementCount(fxs);
for i := 0 to n - 1 do begin
fx := ElementByIndex(fxs, i);
ench := LinksTo(ElementByPath(fx, 'EFID'));
eName := GetElementEditValues(ench, 'FULL');
mag := GetElementNativeValues(fx, 'EFIT\Magnitude');
mags.Add(Format(fmt, [eName, mag]));
end;
Result := StringReplace(mags.CommaText, ',', ', ', [rfReplaceAll]);
Result := StringReplace(Result, '"', '', [rfReplaceAll]);
finally
mags.Free;
end;
end;
// TODO: DELETE
function GetEnchantName(e: IInterface): string;
var
r, edid: string;
begin
r := GetName(e);
edid := EditorID(e);
if ContainsText(edid, '01') then r := r + ' I'
else if ContainsText(edid, '02') then r := r + ' II'
else if ContainsText(edid, '03') then r := r + ' III'
else if ContainsText(edid, '04') then r := r + ' IV'
else if ContainsText(edid, '05') then r := r + ' V'
else if ContainsText(edid, '06') then r := r + ' VI';
Result := r;
end;
// TODO: DELETE
function GetEnchant(e: IInterface): string;
const
nameFmt = '%s (%s)';
var
nm: string;
begin
nm := GetEnchantMagnitude(e);
// nm := Format(nameFmt, [GetName(e), GetEnchantMagnitude(e)]);
Result := Format(enchFmt, [GetEnchantName(e), nm, GetId(e)]);
end;
function GetObjectFxData(e: IInterface): string;
var
i, n: Integer;
fxs, fx, ench: IInterface;
uid, eName, edid, a, d ,m: string;
const
fmt = '%s;;%s;;%s;;%s;;%s;;%s;;;';
begin
Result := '';
fxs := ElementByPath(e, 'Effects');
n := ElementCount(fxs);
for i := 0 to n - 1 do begin
fx := ElementByIndex(fxs, i);
ench := LinksTo(ElementByPath(fx, 'EFID'));
uid := GetUniqueId(ench);
edid := EditorID(ench);
eName := GetElementEditValues(ench, 'FULL');
a := GetElementEditValues(fx, 'EFIT\Area');
d := GetElementEditValues(fx, 'EFIT\Duration');
m := GetElementEditValues(fx, 'EFIT\Magnitude');
Result := Result + Format(fmt, [uid, edid, eName, a, d, m]);
end;
Result := DeleteByRegex(Result, ';;;$');
end;
// Gets enchantment data used by the Skyrim Item Manager
function GetEnchantSIM(e: IInterface): string;
const
fmt = '%s;;;%s;;;%s;;;%s';
var
nm: string;
begin
Result := Format(fmt, [GetId(e), EditorID(e), GetName(e), GetObjectFxData(e)]);
end;
function Process(e: IInterface): Integer;
var
s: string;
begin
s := '';
if Signature(e) = 'ARMO' then s := GetWeaponArmor(e)
else if Signature(e) = 'ENCH' then s := GetEnchant(e) + #13#10#13#10 + GetEnchantSIM(e);
if s <> '' then output.Add(s)
end;
function DeleteLastComma(s: string): string;
var
l: Integer;
begin
Result := s;
l := Length(s) - 1;
if RightStr(s, 1) = ',' then Result := LeftStr(s, l);
end;
procedure PrintOutput(l: TStringList);
var
s: string;
begin
s := DeleteLastComma(TrimRight(l.Text));
AddMessage(s);
end;
function Initialize: Integer;
begin
output := TStringList.Create;
output2 := TStringList.Create;
end;
function Finalize: Integer;
begin
PrintOutput(output);
if output2.Text <> '' then begin
AddMessage(#13#10#13#10);
PrintOutput(output2);
end;
output.Free;
output2.Free;
end;
function DeleteByRegex(subject, regex: string): string;
var
r: TPerlRegex;
begin
r := TPerlRegex.Create;
try
r.Subject := subject;
r.RegEx := regex;
r.Replacement := '\1';
r.ReplaceAll;
Result := r.Subject;
finally
r.Free;
end;
end;
end.