-
Notifications
You must be signed in to change notification settings - Fork 2
/
YASSM - Safe Export.pas
100 lines (89 loc) · 3.34 KB
/
YASSM - Safe Export.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
{
Exports Safe data to JSON
Intended for Fallout 76
}
unit userscript;
var
sl,ItemList: TStringList;
procedure GetMarkers;
var
wrld, wrldgrup, block, subblock, cell, e: IInterface;
i,w,x,y,z,counter: integer;
row, Name, LockLevel: string;
begin
//Let's try to filter to the specific worldspace so we don't have to search through more stuff...
if wbGameMode = gmFNV then
wrld := RecordByFormID(FileByIndex(0), $000DA726, False)
else if wbGameMode = gmFO76 then
wrld := RecordByFormID(FileByIndex(0), 2480661, False)
else
wrld := RecordByFormID(FileByIndex(0), $0000003C, False);
wrldgrup := ChildGroup(wrld);
for i := 0 to ElementCount(wrldgrup) - 1 do begin
block := ElementByIndex(wrldgrup,i);
//AddMessage('Block '+BaseName(Block));
for x := 0 to ElementCount(block) -1 do begin
subblock := ElementByIndex(block,x);
//AddMessage('Block '+BaseName(block) +' SubBlock '+BaseName(subblock));
for y := 0 to ElementCount(subblock) -1 do begin
//We only want to look through Temp items
cell := FindChildGroup(ChildGroup(ElementByIndex(subblock,y)),9,ElementByIndex(subblock,y));
for z := 0 to ElementCount(cell) -1 do begin
e := ElementByIndex(cell,z);
Name := GetEditValue(ElementByName(e,'NAME - Base'));
If (wbStringListInString(ItemList,Name) <> -1) then begin
LockLevel := GetEditValue(ElementByName(ElementByName(e,'XLOC - Lock Data'),'Level'));
if (pos('Novice',LockLevel)>0) then LockLevel := '0'
else if (pos('Advanced',LockLevel)>0) then LockLevel := '1'
else if (pos('Expert',LockLevel)>0) then LockLevel := '2'
else if (pos('Master',LockLevel)>0) then LockLevel := '3'
else if (pos('Key',LockLevel)>0) then LockLevel := 'Key'
else exit;
Row := '{"id":"'+IntToHex(FixedFormID(e), 8)+'","name":"'+StringReplace(Name(e),'"','\"',[rfReplaceAll]) +'",';
Row := Row + '"type":"SafeMarker_Lvl_'+LockLevel+'",';
Row := Row + '"x":'+GetEditValue(ElementByName(ElementByName(ElementByName(e,'DATA - Position/Rotation'),'Position'),'X'))+',';
Row := Row + '"y":'+GetEditValue(ElementByName(ElementByName(ElementByName(e,'DATA - Position/Rotation'),'Position'),'Y'))+',';
Row := Row + '"z":'+GetEditValue(ElementByName(ElementByName(ElementByName(e,'DATA - Position/Rotation'),'Position'),'Z'))+'},';
sl.Add(row);
end;
end;
end;
end;
end;
end;
// Called before processing
// You can remove it if script doesn't require initialization code
function Initialize: integer;
begin
ItemList := TStringList.Create;
ItemList.Add('LootPriorityPrewar_Safe');
sl := TStringList.Create;
sl.Add('[');
sl.Sorted := True;
GetMarkers;
Result := 0;
end;
function Finalize: integer;
var
fname, Last: string;
rowcount: integer;
begin
try
fname := ProgramPath + 'Safe.json';
//Lets have proper JSON and remove the last record's comma
If (sl.Count > 1) then begin //Let's only do if there are rows...
rowcount := sl.count-1; //0 Index, so let's remove one
Last := sl[rowcount]; //Get the Last row
sl.Delete(rowcount); //Remove last line from the list
Delete(Last, Length(Last), Length(Last) -1); //Trim off last character the trailing ,
sl.Add(Last); //Add the last line back
end;
sl.Sorted := False;
sl.Add(']');
sl.SaveToFile(fname);
finally
sl.Free; //Make sure we free memory if this pukes..
end;
Result := 1;
end;
end.