-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_cellfixer.cs
222 lines (206 loc) · 9.12 KB
/
gen_cellfixer.cs
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
using Mutagen.Bethesda.Environments;
using Mutagen.Bethesda.Plugins;
using Mutagen.Bethesda.Starfield;
using Mutagen.Bethesda;
using Noggog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FrankyCLI
{
class gen_cellfixer
{
//V0.0.1 was creating extra Cell Blocks and Sublocks. CellFixer creates a new cell in the correct format without the other parts.
public static int Generate(string[] args)
{
Random random = new Random();
StarfieldMod myMod;
string modname = args[0];
string mode = args[1];
string prefix = args[2];
string item = args[3];
string modelpath = args[4];
string datapath = "";
using (var env = GameEnvironment.Typical.Builder<IStarfieldMod, IStarfieldModGetter>(GameRelease.Starfield).Build())
{
var immutableLoadOrderLinkCache = env.LoadOrder.ToImmutableLinkCache();
datapath = env.DataFolderPath;
//Find the modkey
ModKey newMod = new ModKey(modname, ModType.Master);
myMod = new StarfieldMod(newMod, StarfieldRelease.Starfield);
if (!env.LoadOrder.ModExists(newMod))
{
myMod = new StarfieldMod(newMod, StarfieldRelease.Starfield);
}
else
{
for (int i = 0; i < env.LoadOrder.Count; i++)
{
if (env.LoadOrder[i].FileName == modname + ".esm")
{
ModPath modPath = Path.Combine(env.DataFolderPath, env.LoadOrder[i].FileName);
myMod = StarfieldMod.CreateFromBinary(modPath, StarfieldRelease.Starfield);
}
}
}
//Cell---------------------------
/*
ElminsterAU
Block and sub-block address the last 2 digits of the object id of the record converted to decimal
You have no control over these
Then it's broken. Because the game engine depends on the records being in the correct block/sub-block to find them
*/
IFormLinkNullable<IImageSpaceGetter> DefaultImagespacePackin = new FormKey(env.LoadOrder[0].ModKey, 0x0006AD68).ToNullableLink<IImageSpaceGetter>();
Console.WriteLine("Building Record : " + prefix + "_cell_" + item);
var newCell = new Cell(myMod)
{
EditorID = prefix + "_cell_" + item,
Temporary = new ExtendedList<IPlaced>(),
Flags = Cell.Flag.IsInteriorCell,
Lighting = new CellLighting()
{
DirectionalFade = 1,
FogPower = 1,
FogMax = 1,
NearHeightRange = 10000,
Unknown1 = 1951,
Unknown2 = 3,
},
WaterHeight = 0,
XILS = 1.0f,
XCLAs = new ExtendedList<CellXCLAItem>()
{
new CellXCLAItem()
{
XCLA = 1,
XCLD = "Default Layer Name 1"
},
new CellXCLAItem()
{
XCLA = 2,
XCLD = "Default Layer Name 2"
},
new CellXCLAItem()
{
XCLA = 3,
XCLD = "Default Layer Name 3"
},
new CellXCLAItem()
{
XCLA = 4,
XCLD = "Default Layer Name 4"
},
},
ImageSpace = DefaultImagespacePackin,
};
var key = newCell.FormKey.ID;
var stringkey = key.ToString();
var cellblockNumber = int.Parse(stringkey.Substring(stringkey.Length - 1));
var subBlockNumber = int.Parse(stringkey.Substring(stringkey.Length - 2, 1));
//Try and use existing cellblocks and subblocks first.
CellBlock cellblock = null;
bool newCellBlock = false;
for( int i = 0; i < myMod.Cells.Count; i++ )
{
if (myMod.Cells[i].BlockNumber == cellblockNumber )
{
cellblock = myMod.Cells[i];
break;
}
}
if (cellblock == null )
{
cellblock = new CellBlock
{
BlockNumber = cellblockNumber,
GroupType = GroupTypeEnum.InteriorCellBlock,
SubBlocks = new ExtendedList<CellSubBlock>()
};
newCellBlock = true;
}
bool addSubblock = true;
for(int i = 0; i < cellblock.SubBlocks.Count; i++ )
{
if (cellblock.SubBlocks[i].BlockNumber == subBlockNumber)
{
addSubblock = false;
}
}
if (addSubblock)
{
cellblock.SubBlocks.Add(new CellSubBlock()
{
BlockNumber = subBlockNumber,
GroupType = GroupTypeEnum.InteriorCellSubBlock,
Cells = new ExtendedList<Cell>()
});
}
// Cell contents -------------------------------
IFormLink<IPlaceableObjectGetter> OutpostGroupPackinDummy = new FormKey(env.LoadOrder[0].ModKey, 0x00015804).ToLink<IPlaceableObjectGetter>();
IFormLink<IPlaceableObjectGetter> PrefabPackinPivotDummy = new FormKey(env.LoadOrder[0].ModKey, 0x0003F808).ToLink<IPlaceableObjectGetter>();
IFormLink<IKeywordGetter> UpdatesDynamicNavmeshKeyword = new FormKey(env.LoadOrder[0].ModKey, 0x00140158).ToLink<IKeywordGetter>();
IFormLink<IPlaceableObjectGetter> TRP_Canister_Toxic_01 = new FormKey(env.LoadOrder[0].ModKey, 0x00024358).ToLink<IPlaceableObjectGetter>();
Console.WriteLine("Building Cell Contents");
newCell.Temporary.Add(new PlacedObject(myMod)
{
Base = OutpostGroupPackinDummy,
Position = new P3Float(0, 0, 0),
Rotation = new P3Float(0, 0, 0)
});
newCell.Temporary.Add(new PlacedObject(myMod)
{
Base = PrefabPackinPivotDummy,
Position = new P3Float(0, 0, 0),
Rotation = new P3Float(0, 0, 0)
});
var cell_contents_components = new ExtendedList<AComponent>()
{
new KeywordFormComponent()
{
Keywords = new ExtendedList<IFormLinkGetter<IKeywordGetter>>()
{
UpdatesDynamicNavmeshKeyword
}
}
};
newCell.Temporary.Add(new PlacedObject(myMod)
{
Base = TRP_Canister_Toxic_01,
//Not sure we need ragdoll data, but just copying what I know works
RagdollData = new ExtendedList<RagdollData>()
{
new RagdollData()
{
BoneId = 0,
Position = new P3Float(0, 0, 0),
Rotation = new P3Float(0, 0, 0)
}
},
Components = cell_contents_components,
Position = new P3Float(0, 0, 0),
Rotation = new P3Float(0, 0, 0)
});
bool addedCell = false;
for (int i = 0; i < cellblock.SubBlocks.Count && !addedCell; i++)
{
if (cellblock.SubBlocks[i].BlockNumber == subBlockNumber)
{
cellblock.SubBlocks[i].Cells.Add(newCell);
addedCell = true;
}
}
if(newCellBlock)
{
myMod.Cells.Add(cellblock);
}
// Finish up ---------------------------------------------
Console.WriteLine("New cell at: Block " + cellblockNumber + " sub: " + subBlockNumber);
}
myMod.WriteToBinary(datapath + "\\" + modname + ".esm");
Console.WriteLine("Finished");
return 0;
}
}
}