-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCheck Missing Mandatory Properties.pas
1323 lines (1163 loc) · 44.4 KB
/
Check Missing Mandatory Properties.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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
Run on any amount of forms. A config UI will be shown before processing.
Missing mandatory properties will be output to Messages.
There is limited support for auto-filling. This will still generate output.
It should be able to auto-fill properties, if the property type corresponds to a native form type, but won't work for scripts which extend such a type yet.
For example, it should be able to autofill
`MiscObject property BobbyPin auto const mandatory`
because there is a misc item with the editor ID 'BobbyPin', but it will fail for
`MyScript property MyExtendedMisc auto const mandatory`
even if MyScript extends MiscObject, and there is a misc item with the editor ID 'MyExtendedMisc' with the script 'MyScript'.
Explanation of the settings in the config UI:
- Progress Message After:
After this number of forms have been checked, a message will be generated.
- Auto-Fill Mandatory:
Whenever auto-fill should be attempted, if a missing Mandatory property is found.
- Auto-Fill Optional:
Whenever auto-fill should be attempted, if a missing Optional property is found.
- Auto-Fill Basic Types:
If enabled, auto-fill will be attempted for properties of type ScriptObject and Form, too.
In this case, no type checking is done. If the Editor ID matches, it will be filled.
This option is irrelevant if both Auto-Fill Mandatory and Auto-Fill Optional are disabled.
- Skip some SS2 forms:
SS2 contains some templates where mandatory properties aren't filled on purpose, as well
as "recycled MISCs", which have a script, but no properties.
If they aren't skipped and the script is used on SS2, it will generate lots of false positives.
However, `shouldProcess` might be a bit too loose, since it will skip everything with "template" in the EditorID.
}
unit CheckMissingMandatoryProps;
uses PexToJson;
uses praUtil;
const
SCRIPT_TYPE_INVALID = -1; // not anything known
SCRIPT_TYPE_INTERNAL = 0; // stuff which shouldn't be extended or such
SCRIPT_TYPE_BASE = 1; // Form and ScriptObject
SCRIPT_TYPE_RECORD = 2; // base forms, like Actor or Keyword or Static
SCRIPT_TYPE_REF = 3; // any ObjectReference, REFR, ACHR, PGRE
SCRIPT_TYPE_ALIAS = 4; // any alias from a quest
configFile = ScriptsPath + 'Check Missing Mandatory Properties.cfg';
var
scriptCache, decompilerCache: TJsonObject;
processedForms, decompiledScripts, foundErrors: cardinal;
edidCache: TStringList;
progressMessageAfter: integer;
skipSomeSS2Forms: boolean; // skips some templates, recycled miscs, etc
autoFillMandatory: boolean; // attempt to auto-fill mandatory properties
autoFillOptional: boolean; // attempt to auto-fill optional properties
autoFillBasicTypes: boolean; // whenever to try to auto-fill properties of type Form or ScriptObject. No typechecking happens here, any form is fair game.
procedure loadConfig();
var
i, j, breakPos: integer;
curLine, curKey, curVal: string;
lines : TStringList;
begin
// defaults
progressMessageAfter := 1000;
skipSomeSS2Forms := true; // skips some templates, recycled miscs, etc
autoFillMandatory := true; // attempt to auto-fill mandatory properties
autoFillOptional := true; // attempt to auto-fill optional properties
autoFillBasicTypes := false; // whenever to try to auto-fill properties of type Form or ScriptObject. No typechecking happens here, any form is fair game.
if(not FileExists(configFile)) then begin
exit;
end;
lines := TStringList.create;
lines.LoadFromFile(configFile);
//
for i:=0 to lines.count-1 do begin
curLine := lines[i];
breakPos := -1;
for j:=1 to length(curLine) do begin
if(curLine[j] = '=') then begin
breakPos := j;
break;
end;
end;
if breakPos <> -1 then begin
curKey := trim(copy(curLine, 0, breakPos-1));
curVal := trim(copy(curLine, breakPos+1, length(curLine)));
if(curKey = 'progressMessageAfter') then begin
progressMessageAfter := StrToInt(curVal);
end else if(curKey = 'skipSomeSS2Forms') then begin
skipSomeSS2Forms := StrToBool(curVal);
end else if(curKey = 'autoFillMandatory') then begin
autoFillMandatory := StrToBool(curVal);
end else if(curKey = 'autoFillOptional') then begin
autoFillOptional := StrToBool(curVal);
end else if(curKey = 'autoFillBasicTypes') then begin
autoFillBasicTypes := StrToBool(curVal);
end;
end;
end;
lines.free();
end;
procedure saveConfig();
var
lines : TStringList;
begin
lines := TStringList.create;
lines.add('progressMessageAfter='+IntToStr(progressMessageAfter));
lines.add('skipSomeSS2Forms='+BoolToStr(skipSomeSS2Forms));
lines.add('autoFillMandatory='+BoolToStr(autoFillMandatory));
lines.add('autoFillOptional='+BoolToStr(autoFillOptional));
lines.add('autoFillBasicTypes='+BoolToStr(autoFillBasicTypes));
lines.saveToFile(configFile);
lines.free();
end;
function showGui(): boolean;
var
frm: TForm;
eProgressAfter: TEdit;
resultCode: cardinal;
yOffset: integer;
cbSkipForms, cbAutoFillMandatory, cbAutoFillOptional, cbAutoFillBasic: TCheckBox;
btnOkay, btnCancel: TButton;
begin
frm := CreateDialog('Check Missing Mandatory Properties', 400, 200);
eProgressAfter := CreateLabelledInput(frm, 20, 24, 100, 24, 'Progress Message After:', IntToStr(progressMessageAfter));
//eProgressAfter.LabelPosition := lpLeft;
// CreateLabel(frm, 10, 34, 'A progress message will be generated after this many forms were processed.');
yOffset := 54;
cbAutoFillMandatory := CreateCheckbox(frm, 20, yOffset, 'Auto-Fill Mandatory');
cbAutoFillOptional := CreateCheckbox(frm, 210, yOffset, 'Auto-Fill Optional');
yOffset := yOffset + 24;
cbAutoFillBasic := CreateCheckbox(frm, 20, yOffset, 'Auto-Fill Basic Types');
cbSkipForms := CreateCheckbox(frm, 210, yOffset, 'Skip some SS2 forms');
cbSkipForms.checked := skipSomeSS2Forms;
cbAutoFillMandatory.checked := autoFillMandatory;
cbAutoFillOptional.checked := autoFillOptional;
cbAutoFillBasic.checked := autoFillBasicTypes;
yOffset := yOffset + 34;
btnOkay := CreateButton(frm, 100, yOffset, 'OK');
btnOkay.ModalResult := mrYes;
btnOkay.width := 75;
btnCancel := CreateButton(frm, 200, yOffset, 'Cancel');
btnCancel.ModalResult := mrCancel;
btnCancel.width := 75;
resultCode := frm.ShowModal;
if(resultCode <> mrYes) then begin
Result := false;
frm.free();
exit;
end;
progressMessageAfter := StrToInt(trim(eProgressAfter.text));
skipSomeSS2Forms := cbSkipForms.checked;
autoFillMandatory := cbAutoFillMandatory.checked;
autoFillOptional := cbAutoFillOptional.checked;
autoFillBasicTypes := cbAutoFillBasic.checked;
saveConfig();
Result := true;
frm.free();
end;
// Called before processing
// You can remove it if script doesn't require initialization code
function Initialize: integer;
begin
Result := 0;
loadConfig();
if(not showGui()) then begin
Result := 1;
exit;
end;
decompilerCache := TJsonObject.create();
scriptCache := TJsonObject.create();
AddMessage('Script begins.');
processedForms := 0;
edidCache := TStringList.create;
edidCache.Duplicates := dupIgnore;
edidCache.CaseSensitive := false;
edidCache.Sorted := true;
decompiledScripts := 0;
foundErrors := 0;
end;
procedure addToJsonArray(newEntry: string; arr: TJsonArray);
var
i: integer;
begin
for i:=0 to arr.count-1 do begin
if(LowerCase(arr.S[i]) = LowerCase(newEntry)) then exit;
end;
arr.add(newEntry);
end;
function GetFormByEdidCached(edid: string): IInterface;
var
i: integer;
begin
i := edidCache.indexOf(edid);
if(i >= 0) then begin
Result := ObjectToElement(edidCache.Objects[i]);
exit;
end;
Result := GetFormByEdid(edid);
edidCache.AddObject(edid, result);
end;
procedure fillScriptValue(propType: string; prop, rawPropVal: IInterface; propObj: TJsonObject);
var
curObj: IInterface;
begin
if (assigned(rawPropVal)) then begin
// propObj.B['hasValue'] := true;
if(propType = 'String') then begin
propObj.S['value'] := geevt(prop, propType);
exit;
end;
if(propType = 'Int32') then begin
propObj.I['value'] := StrToInt(geevt(prop, propType));
exit;
end;
if(propType = 'Float') then begin
propObj.F['value'] := StrToFloat(geevt(prop, propType));
exit;
end;
if(propType = 'Bool') then begin
propObj.B['value'] := StrToBool(geevt(prop, propType));
exit;
end;
// Object
if(propType = 'Object') then begin
curObj := pathLinksTo(prop, 'Value\Object Union\Object v2\FormID');
if(assigned(curObj)) then begin
propObj.S['value'] := FormToAbsStr(curObj);
end else begin
propObj.S['value'] := '';
end;
exit;
end;
// not doing the rest yet
end;
end;
procedure fillScriptProperties(curScript: IInterface; outList: TJsonObject);
var
scripts, propRoot, prop, rawPropVal, propObj: IInterface;
i, j: integer;
scriptName, scriptNameLc, propName, propType: string;
scriptObj: TJsonObject;
propArray: TJsonArray;
begin
scriptName := geevt(curScript, 'scriptName');
scriptNameLc := LowerCase(scriptName);
propRoot := ElementByPath(curScript, 'Properties');
scriptObj := outList.O[scriptNameLc];
scriptObj.S['name'] := scriptName;
if(assigned(propRoot)) then begin
for j := 0 to ElementCount(propRoot)-1 do begin
prop := ElementByIndex(propRoot, j);
propName := geevt(prop, 'propertyName');
propType := geevt(prop, 'Type');
propObj := scriptObj.O['properties'].O[LowerCase(propName)]; //outList.O['properties'].O[LowerCase(propName)];
propObj.S['name'] := propName;
propObj.S['type'] := propType;
rawPropVal := getRawScriptProp(curScript, propName);
fillScriptValue(propType, prop, rawPropVal, propObj);
end;
end;
end;
procedure getScriptProperties(e: IInterface; outList: TJsonObject);
var
curScript, scripts, propRoot, prop, rawPropVal, propObj: IInterface;
i, j: integer;
scriptName, scriptNameLc, propName, propType: string;
scriptObj: TJsonObject;
propArray: TJsonArray;
begin
scripts := ElementByPath(e, 'VMAD - Virtual Machine Adapter\Scripts');
if(assigned(scripts)) then begin
// processing code goes here
for i := 0 to ElementCount(scripts)-1 do begin
curScript := ElementByIndex(scripts, i);
fillScriptProperties(curScript, outList);
end;
end;
curScript := getFragmentScript(e);
if(assigned(curScript)) then begin
fillScriptProperties(curScript, outList);
end;
end;
procedure getFilledProperties(e: IInterface; outList: TJsonObject);
var
curScript, scripts, propRoot, prop: IInterface;
i, j: integer;
scriptName, scriptNameLc, propName: string;
scriptObj: TJsonObject;
propArray: TJsonArray;
begin
scripts := ElementByPath(e, 'VMAD - Virtual Machine Adapter\Scripts');
if(not assigned(scripts)) then exit;
// processing code goes here
for i := 0 to ElementCount(scripts)-1 do begin
curScript := ElementByIndex(scripts, i);
scriptName := geevt(curScript, 'scriptName');
scriptNameLc := LowerCase(scriptName);
propRoot := ElementByPath(curScript, 'Properties');
scriptObj := outList.O[scriptNameLc];
scriptObj.S['name'] := scriptName;
if(assigned(propRoot)) then begin
propArray := scriptObj.A['properties'];
for i := 0 to ElementCount(propRoot)-1 do begin
prop := ElementByIndex(propRoot, i);
propName := geevt(prop, 'propertyName');
addToJsonArray(propName, propArray);
end;
end;
end;
end;
function readPexScriptCached(scriptName: string): TJsonObject;
var
curPexData: IInterface;
scriptKey, curScriptName: string;
done: boolean;
begin
scriptKey := LowerCase(scriptName);
if(decompilerCache.Types[scriptKey] = JSON_TYPE_OBJECT) then begin
Result := decompilerCache.O[scriptKey];
exit;
end;
if(decompilerCache.Types[scriptKey] = JSON_TYPE_BOOL) then begin
Result := nil;
exit;
end;
//JSON_TYPE_BOOL
// AddMessage('Decompiling '+scriptName);
Result := readPexScriptName(scriptName);
if(Result = nil) then begin
AddMessage('Failed to decompile '+scriptName);
decompilerCache.B[scriptKey] := false;
end else begin
decompilerCache.O[scriptKey] := Result;
end;
end;
{
Returns types:
SCRIPT_TYPE_INVALID = -1 // not anything known
SCRIPT_TYPE_INTERNAL = 0 // stuff which shouldn't be extended or unused stuff
SCRIPT_TYPE_BASE = 1 // Form and ScriptObject
SCRIPT_TYPE_RECORD = 2 // base forms, like Actor or Keyword or Static
SCRIPT_TYPE_REF = 3 // any ObjectReference, REFR, ACHR, PGRE(?)
SCRIPT_TYPE_ALIAS = 4 // any alias from a quest
}
function getFormScriptType(scriptName: string): integer;
var
scriptNameLC: string;
begin
Result := SCRIPT_TYPE_INVALID;
scriptNameLC := LowerCase(scriptName);
// lets put the unused ones here, too
if
(scriptNameLC = 'debug') or
(scriptNameLC = 'f4se') or
(scriptNameLC = 'game') or
(scriptNameLC = 'input') or
(scriptNameLC = 'inputenablelayer') or
(scriptNameLC = 'instancedata') or
(scriptNameLC = 'math') or
(scriptNameLC = 'ui') or
(scriptNameLC = 'utility') or
(scriptNameLC = 'shout') or
(scriptNameLC = 'wordofpower') or
(scriptNameLC = 'leveledspell') or
(scriptNameLC = 'scroll') or
(scriptNameLC = 'soulgem')
then begin
Result := SCRIPT_TYPE_INTERNAL;
exit;
end;
if
(scriptNameLC = 'scriptobject') or
(scriptNameLC = 'form')
then begin
Result := SCRIPT_TYPE_BASE;
exit;
end;
if
(scriptNameLC = 'objectreference') or
(scriptNameLC = 'actor')
then begin
Result := SCRIPT_TYPE_REF;
exit;
end;
if
(scriptNameLC = 'alias') or
(scriptNameLC = 'referencealias') or
(scriptNameLC = 'locationalias') or
(scriptNameLC = 'refcollectionalias')
then begin
Result := SCRIPT_TYPE_REF;
exit;
end;
if
(scriptNameLC = 'activemagiceffect') or
(scriptNameLC = 'action') or
(scriptNameLC = 'activator') or
(scriptNameLC = 'flora') or
(scriptNameLC = 'furniture') or
(scriptNameLC = 'talkingactivator') or
(scriptNameLC = 'actorbase') or
(scriptNameLC = 'actorvalue') or
(scriptNameLC = 'ammo') or
(scriptNameLC = 'armor') or
(scriptNameLC = 'associationtype') or
(scriptNameLC = 'book') or
(scriptNameLC = 'camerashot') or
(scriptNameLC = 'cell') or
(scriptNameLC = 'class') or
(scriptNameLC = 'combatstyle') or
(scriptNameLC = 'component') or
(scriptNameLC = 'container') or
(scriptNameLC = 'door') or
(scriptNameLC = 'defaultobject') or
(scriptNameLC = 'effectshader') or
(scriptNameLC = 'enchantment') or
(scriptNameLC = 'encounterzone') or
(scriptNameLC = 'equipslot') or
(scriptNameLC = 'explosion') or
(scriptNameLC = 'faction') or
(scriptNameLC = 'formlist') or
(scriptNameLC = 'globalvariable') or
(scriptNameLC = 'hazard') or
(scriptNameLC = 'headpart') or
(scriptNameLC = 'holotape') or
(scriptNameLC = 'idle') or
(scriptNameLC = 'idlemarker') or
(scriptNameLC = 'imagespacemodifier') or
(scriptNameLC = 'impactdataset') or
(scriptNameLC = 'ingredient') or
(scriptNameLC = 'instancenamingrules') or
(scriptNameLC = 'keyword') or
(scriptNameLC = 'locationreftype') or
(scriptNameLC = 'leveledactor') or
(scriptNameLC = 'leveleditem') or
(scriptNameLC = 'leveledspell') or
(scriptNameLC = 'light') or
(scriptNameLC = 'location') or
(scriptNameLC = 'magiceffect') or
(scriptNameLC = 'message') or
(scriptNameLC = 'miscobject') or
(scriptNameLC = 'constructibleobject') or
(scriptNameLC = 'key') or
(scriptNameLC = 'soulgem') or
(scriptNameLC = 'musictype') or
(scriptNameLC = 'objectmod') or
(scriptNameLC = 'outfit') or
(scriptNameLC = 'outputmodel') or
(scriptNameLC = 'package') or
(scriptNameLC = 'perk') or
(scriptNameLC = 'potion') or
(scriptNameLC = 'projectile') or
(scriptNameLC = 'quest') or
(scriptNameLC = 'race') or
(scriptNameLC = 'scene') or
(scriptNameLC = 'scroll') or
(scriptNameLC = 'shaderparticlegeometry') or
(scriptNameLC = 'shout') or
(scriptNameLC = 'sound') or
(scriptNameLC = 'soundcategory') or
(scriptNameLC = 'soundcategorysnapshot') or
(scriptNameLC = 'spell') or
(scriptNameLC = 'static') or
(scriptNameLC = 'movablestatic') or
(scriptNameLC = 'terminal') or
(scriptNameLC = 'textureset') or
(scriptNameLC = 'topic') or
(scriptNameLC = 'topicinfo') or
(scriptNameLC = 'visualeffect') or
(scriptNameLC = 'voicetype') or
(scriptNameLC = 'watertype') or
(scriptNameLC = 'weapon') or
(scriptNameLC = 'weather') or
(scriptNameLC = 'wordofpower') or
(scriptNameLC = 'worldspace') then
begin
Result := SCRIPT_TYPE_RECORD;
exit;
end;
end;
function scriptNameToSignature(scriptName: string): string;
var
scriptNameLC: string;
begin
Result := '';
scriptNameLC := LowerCase(scriptName);
if(scriptNameLC = 'objectreference') then begin
Result := 'REFR';
exit;
end;
if(scriptNameLC = 'actor') then begin
Result := 'ACHR';
exit;
end;
if(scriptNameLC = 'action') then begin
Result := 'AACT';
exit;
end;
if(scriptNameLC = 'activator') then begin
Result := 'ACTI';
exit;
end;
if(scriptNameLC = 'flora') then begin
Result := 'FLOR';
exit;
end;
if(scriptNameLC = 'furniture') then begin
Result := 'FURN';
exit;
end;
if(scriptNameLC = 'talkingactivator') then begin
Result := 'TACT';
exit;
end;
if(scriptNameLC = 'actorbase') then begin
Result := 'NPC_';
exit;
end;
if(scriptNameLC = 'actorvalue') then begin
Result := 'AVIF';
exit;
end;
if(scriptNameLC = 'ammo') then begin
Result := 'AMMO';
exit;
end;
if(scriptNameLC = 'armor') then begin
Result := 'ARMO';
exit;
end;
if(scriptNameLC = 'associationtype') then begin
Result := 'ASTP';
exit;
end;
if(scriptNameLC = 'book') then begin
Result := 'BOOK';
exit;
end;
if(scriptNameLC = 'camerashot') then begin
Result := 'CAMS';
exit;
end;
if(scriptNameLC = 'cell') then begin
Result := 'CELL';
exit;
end;
if(scriptNameLC = 'class') then begin
Result := 'CLAS';
exit;
end;
if(scriptNameLC = 'combatstyle') then begin
Result := 'CSTY';
exit;
end;
if(scriptNameLC = 'component') then begin
Result := 'CMPO';
exit;
end;
if(scriptNameLC = 'container') then begin
Result := 'CONT';
exit;
end;
if(scriptNameLC = 'door') then begin
Result := 'DOOR';
exit;
end;
if(scriptNameLC = 'defaultobject') then begin
Result := 'DFOB';
exit;
end;
if(scriptNameLC = 'effectshader') then begin
Result := 'EFSH';
exit;
end;
if(scriptNameLC = 'enchantment') then begin
Result := 'ENCH';
exit;
end;
if(scriptNameLC = 'encounterzone') then begin
Result := 'ECZN';
exit;
end;
if(scriptNameLC = 'equipslot') then begin
Result := 'EQUP';
exit;
end;
if(scriptNameLC = 'explosion') then begin
Result := 'EXPL';
exit;
end;
if(scriptNameLC = 'faction') then begin
Result := 'FACT';
exit;
end;
if(scriptNameLC = 'formlist') then begin
Result := 'FLST';
exit;
end;
if(scriptNameLC = 'globalvariable') then begin
Result := 'GLOB';
exit;
end;
if(scriptNameLC = 'hazard') then begin
Result := 'HAZD';
exit;
end;
if(scriptNameLC = 'headpart') then begin
Result := 'HDPT';
exit;
end;
if(scriptNameLC = 'holotape') then begin
Result := 'NOTE';
exit;
end;
if(scriptNameLC = 'idle') then begin
Result := 'IDLE';
exit;
end;
if(scriptNameLC = 'idlemarker') then begin
Result := 'IDLM';
exit;
end;
if(scriptNameLC = 'imagespacemodifier') then begin
Result := 'IMAD';
exit;
end;
if(scriptNameLC = 'impactdataset') then begin
Result := 'IPDS';
exit;
end;
if(scriptNameLC = 'ingredient') then begin
Result := 'INGR';
exit;
end;
if(scriptNameLC = 'instancenamingrules') then begin
Result := 'INNR';
exit;
end;
if(scriptNameLC = 'keyword') then begin
Result := 'KYWD';
exit;
end;
if(scriptNameLC = 'locationreftype') then begin
Result := 'LCRT';
exit;
end;
if(scriptNameLC = 'leveledactor') then begin
Result := 'LVLN';
exit;
end;
if(scriptNameLC = 'leveleditem') then begin
Result := 'LVLI';
exit;
end;
if(scriptNameLC = 'light') then begin
Result := 'LIGH';
exit;
end;
if(scriptNameLC = 'location') then begin
Result := 'LCTN';
exit;
end;
if(scriptNameLC = 'magiceffect') then begin
Result := 'MGEF';
exit;
end;
if(scriptNameLC = 'message') then begin
Result := 'MESG';
exit;
end;
if(scriptNameLC = 'miscobject') then begin
Result := 'MISC';
exit;
end;
if(scriptNameLC = 'constructibleobject') then begin
Result := 'COBJ';
exit;
end;
if(scriptNameLC = 'key') then begin
Result := 'KEYM';
exit;
end;
if(scriptNameLC = 'musictype') then begin
Result := 'MUSC';
exit;
end;
if(scriptNameLC = 'objectmod') then begin
Result := 'OMOD';
exit;
end;
if(scriptNameLC = 'outfit') then begin
Result := 'OTFT';
exit;
end;
if(scriptNameLC = 'outputmodel') then begin
Result := 'SOPM';
exit;
end;
if(scriptNameLC = 'package') then begin
Result := 'PACK';
exit;
end;
if(scriptNameLC = 'perk') then begin
Result := 'PERK';
exit;
end;
if(scriptNameLC = 'potion') then begin
Result := 'ALCH';
exit;
end;
if(scriptNameLC = 'projectile') then begin
Result := 'PROJ';
exit;
end;
if(scriptNameLC = 'quest') then begin
Result := 'QUST';
exit;
end;
if(scriptNameLC = 'race') then begin
Result := 'RACE';
exit;
end;
if(scriptNameLC = 'shaderparticlegeometry') then begin
Result := 'SPGD';
exit;
end;
if(scriptNameLC = 'sound') then begin
Result := 'SNDR';
exit;
end;
if(scriptNameLC = 'soundcategory') then begin
Result := 'SNCT';
exit;
end;
if(scriptNameLC = 'soundcategorysnapshot') then begin
Result := 'SCSN';
exit;
end;
if(scriptNameLC = 'spell') then begin
Result := 'SPEL';
exit;
end;
if(scriptNameLC = 'movablestatic') then begin
Result := 'MSTT';
exit;
end;
if(scriptNameLC = 'terminal') then begin
Result := 'TERM';
exit;
end;
if(scriptNameLC = 'textureset') then begin
Result := 'TXST';
exit;
end;
if(scriptNameLC = 'visualeffect') then begin
Result := 'RFCT';
exit;
end;
if(scriptNameLC = 'voicetype') then begin
Result := 'VTYP';
exit;
end;
if(scriptNameLC = 'watertype') then begin
Result := 'WATR';
exit;
end;
if(scriptNameLC = 'weapon') then begin
Result := 'WEAP';
exit;
end;
if(scriptNameLC = 'weather') then begin
Result := 'WTHR';
exit;
end;
if(scriptNameLC = 'worldspace') then begin
Result := 'WLRD';
exit;
end;
// for statics, just return STAT, do the SCOL handling outside
if(scriptNameLC = 'static') then begin
Result := 'STAT';
exit;
end;
// within quest
if(scriptNameLC = 'topic') then begin
Result := 'DIAL';
exit;
end;
if(scriptNameLC = 'topicinfo') then begin
Result := 'INFO';
exit;
end;
if(scriptNameLC = 'scene') then begin
Result := 'SCEN';
exit;
end;
// these aren't used and don't have signatures, it seems
{
shout
wordofpower
leveledspell
scroll
soulgem
}
end;
function readPexScriptFull(scriptName: string; mergeWith: TJsonObject): TJsonObject;
var
curPexData, curObject: IInterface;
curScriptName: string;
done: boolean;
i, j: integer;
curObjectsArray: TJsonArray;
begin
if(scriptName = '') then exit;
// TODO potentially blacklist all vanilla scripts
if(getFormScriptType(scriptName) <> SCRIPT_TYPE_INVALID) then begin
// "invalid" means: nothing known
exit;
end;
if(mergeWith = nil) then begin
Result := TJsonObject.create();
end else begin
Result := mergeWith;
end;
//AddMessage('Reading '+scriptName);
//decompilerCache
// Result := TJsonObject.create();
curScriptName := scriptName;
done := false;
//while(not done) do begin
curPexData := readPexScriptCached(scriptName);
if(curPexData = nil) then begin
done := true;
exit;
end;
// Result.O['header'] := curPexData.O['header'];
// Result.O['userFlags'] := curPexData.O['userFlags'];
// merge "objects"
for i:=0 to curPexData.A['objects'].count - 1 do begin
curObject := curPexData.A['objects'].O[i];
curObjectsArray := Result.A['objects'];
//AddMessage('');
appendObjectToArray(curObjectsArray, curObject);
// Result.A['objects'].Add(curPexData.A['objects'].O[i]);
readPexScriptFull(curObject.S['extends'], Result);
end;
// exit; // DEBUG
//end;
end;
function getMandatoryProperties(scriptName: string): TJsonObject;
var
pexData, curObj, curProp, propList, newPropEntry: TJsonObject;
propRoot, objRoot: TJsonArray;
i, j: integer;
curPropName: string;
userFlags: cardinal;
begin
if(scriptName = '') then exit;
if(scriptCache.Types[scriptName] = JSON_TYPE_OBJECT) then begin
Result := scriptCache.O[scriptName];
exit;
end;
Result := scriptCache.O[scriptName];
propList := Result.O['properties'];
pexData := readPexScriptFull(scriptName, nil);
decompiledScripts := decompiledScripts + 1;
if(pexData = nil) then begin
AddMessage('WARNING: Failed to decompile '+scriptName);
exit;
end;
objRoot := pexData.A['objects'];
for i:=0 to objRoot.count-1 do begin
curObj := objRoot.O[i];
if(LowerCase(curObj.S['name']) = LowerCase(scriptName)) then begin
propRoot := curObj.A['properties'];
// iterate props
for j:=0 to propRoot.count-1 do begin
curProp := propRoot.O[j];
//AddMessage('checking prop '+curProp.toString());
curPropName := curProp.S['name'];
newPropEntry := propList.O[LowerCase(curPropName)];
userFlags := curProp.U['userFlags'];
newPropEntry.S['name'] := curPropName;
newPropEntry.B['hidden'] := ((userFlags and PEX_FLAG_HIDDEN) <> 0);
newPropEntry.B['mandatory'] := ((userFlags and PEX_FLAG_MANDATORY) <> 0);
newPropEntry.S['type'] := curProp.S['type'];
end;
break;
end;
end;
//pexData.free();
end;
function shouldProcess(baseObj: IInterface): boolean;
var
edid, edidLowerCase: string;
begin
Result := false;
if(not skipSomeSS2Forms) then begin
Result := true;
exit;
end;
edid := EditorID(baseObj);
if(strStartsWith(edid, 'RECYCLED_MISC_')) then exit;
edidLowerCase := LowerCase(edid);