-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_shipstruct.cs
381 lines (357 loc) · 17.6 KB
/
gen_shipstruct.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
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
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_shipstruct
{
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);
//Check if this mod already contains this entry
foreach ( var ms in myMod.MoveableStatics)
{
if (ms.EditorID == prefix + "_ms_" + item)
{
Console.WriteLine("Error, mod already contains : " + prefix + "_ms_" + item);
return 1;
}
}
}
}
}
// Moveable Static ------------------------------------------
Console.WriteLine("Building Record : " + prefix + "_ms_" + item);
IFormLinkNullable<ISnapTemplateGetter> snaplink = new FormKey(env.LoadOrder[0].ModKey, 0x00059B01).ToNullableLink<ISnapTemplateGetter>();
IFormLinkNullable<ILayeredMaterialSwapGetter> paint1 = new FormKey(env.LoadOrder[0].ModKey, 0x00099196).ToNullableLink<ILayeredMaterialSwapGetter>();
IFormLinkNullable<ILayeredMaterialSwapGetter> paint2 = new FormKey(env.LoadOrder[0].ModKey, 0x000B6B1F).ToNullableLink<ILayeredMaterialSwapGetter>();
IFormLinkNullable<ILayeredMaterialSwapGetter> paint3 = new FormKey(env.LoadOrder[0].ModKey, 0x002AF78A).ToNullableLink<ILayeredMaterialSwapGetter>();
IFormLinkNullable<IKeywordGetter> spaceshipformshipmodule = new FormKey(env.LoadOrder[0].ModKey, 0x001BB401).ToNullableLink<IKeywordGetter>();
IFormLinkNullable<IKeywordGetter> NavmeshUseDefaultCollisionForGeneration = new FormKey(env.LoadOrder[0].ModKey, 0x00207960).ToNullableLink<IKeywordGetter>();
byte[] flldarry = new byte[4] { 1, 0, 0, 0 };
byte[] xflgarry = new byte[1] { 2 };
MoveableStatic moveableStatic = new MoveableStatic(myMod);
moveableStatic.EditorID = prefix + "_ms_" + item;
moveableStatic.ObjectBounds = new ObjectBounds()
{
First = new P3Float(-4, -4, -1.767578f),
Second = new P3Float(4, 4, 1.767578f)
};
moveableStatic.ODTY = 0;
moveableStatic.SnapTemplate = snaplink;
moveableStatic.Model = new Model()
{
File = new Mutagen.Bethesda.Plugins.Assets.AssetLink<Mutagen.Bethesda.Starfield.Assets.StarfieldModelAssetType>(modelpath),
MaterialSwaps = new ExtendedList<IFormLinkGetter<ILayeredMaterialSwapGetter>>()
{
paint1,
paint2,
paint3,
},
FLLD = new MemorySlice<byte>(flldarry),
XFLG = new MemorySlice<byte>(xflgarry),
};
moveableStatic.DATA = 4;
moveableStatic.Keywords = new ExtendedList<IFormLinkGetter<IKeywordGetter>>()
{
spaceshipformshipmodule,
NavmeshUseDefaultCollisionForGeneration
};
myMod.MoveableStatics.Add(moveableStatic);
//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];
}
}
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>();
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 = moveableStatic.ToLink<IPlaceableObjectGetter>(),
//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);
}
// Packin --------------------------------------
Console.WriteLine("Building Record : " + prefix + "_pkn_" + item);
IFormLink<ITransformGetter> link = new FormKey(env.LoadOrder[0].ModKey, 0x00050FAC).ToLink<ITransformGetter>();
byte[] barray = new byte[4] { 14, 00, 00, 00 };
var packin = new PackIn(myMod)
{
EditorID = prefix + "_pkn_" + item,
ObjectBounds = new ObjectBounds()
{
First = new P3Float(-4, -4, -1.767578f),
Second = new P3Float(4, 4, 1.767578f)
},
ODTY = 0,
Transforms = new Transforms
{
Ship = link
},
Filter = "\\Ships\\Modules\\Exterior\\Struct\\Deimos\\",
Cell = newCell.ToNullableLink<ICellGetter>(),
Version = 0,
FNAM = new MemorySlice<byte>(barray),
MaterialSwaps = new ExtendedList<IFormLinkGetter<ILayeredMaterialSwapGetter>>()
};
myMod.PackIns.Add(packin);
//Generic Base Form -------------------------------------------
IFormLinkNullable<IGenericBaseFormTemplateGetter> FormSpaceshipModule = new FormKey(env.LoadOrder[0].ModKey, 0x0003058E).ToNullableLink<IGenericBaseFormTemplateGetter>();
IFormLinkNullable<IActorValueInformationGetter> SpaceshipPartMass = new FormKey(env.LoadOrder[0].ModKey, 0x0000ACDB).ToNullableLink<IActorValueInformationGetter>();
IFormLinkNullable<IActorValueInformationGetter> ShipModuleVariant = new FormKey(env.LoadOrder[0].ModKey, 0x0027BACE).ToNullableLink<IActorValueInformationGetter>();
IFormLinkNullable<IKeywordGetter> SpaceshipLinkedExterior = new FormKey(env.LoadOrder[0].ModKey, 0x0000662F).ToNullableLink<IKeywordGetter>();
IFormLinkNullable<IKeywordGetter> ShipModuleManufacturerDeimos = new FormKey(env.LoadOrder[0].ModKey, 0x001462C0).ToNullableLink<IKeywordGetter>();
Console.WriteLine("Building Record : " + prefix + "_gbfm_" + item);
var gbfm_components = new ExtendedList<AComponent>()
{
new PropertySheetComponent()
{
Properties = new ExtendedList<ObjectProperty>()
{
new ObjectProperty()
{
ActorValue = SpaceshipPartMass,
Value = 5,
},
new ObjectProperty()
{
ActorValue = ShipModuleVariant,
Value = 1,
}
}
},
new FormLinkDataComponent()
{
Links= new ExtendedList<FormLinkComponentLink>
{
new FormLinkComponentLink()
{
LinkedForm = packin.ToNullableLink<IStarfieldMajorRecordGetter>(),
Keyword = SpaceshipLinkedExterior,
}
}
},
new KeywordFormComponent()
{
Keywords = new ExtendedList<IFormLinkGetter<IKeywordGetter>>()
{
ShipModuleManufacturerDeimos
}
},
new FullNameComponent()
{
Name = item
}
};
var gbfm = new GenericBaseForm(myMod)
{
EditorID = prefix + "_gbfm_" + item,
ObjectBounds = new ObjectBounds() { First = new P3Float(0, 0, 0), Second = new P3Float(0, 0, 0) },
ODTY = 0,
Template = FormSpaceshipModule,
Components = gbfm_components,
STRVs = new ExtendedList<string>()
{
"BGSMod_Template_Component"
}
};
myMod.GenericBaseForms.Add(gbfm);
//Constructable object -------------------------
Console.WriteLine("Building Record : " + prefix + "_co_" + item);
byte tnamearry = 00;
IFormLinkNullable<IKeywordGetter> WorkbenchShipBuildingKeyword = new FormKey(env.LoadOrder[0].ModKey, 0x0029C480).ToNullableLink<IKeywordGetter>();
IFormLinkNullable<IKeywordGetter> Category_ShipMod_Structure = new FormKey(env.LoadOrder[0].ModKey, 0x0029C473).ToNullableLink<IKeywordGetter>();
var co = new ConstructibleObject(myMod)
{
EditorID = prefix + "_co_" + item,
Description = item,
CreatedObject = gbfm.ToNullableLink<IConstructibleObjectTargetGetter>(),
AmountProduced = 1,
MenuSortOrder = 1,
TNAM = tnamearry,
LearnMethod = ConstructibleObject.LearnMethodEnum.DefaultOrConditions,
Value = 1000,
WorkbenchKeyword = WorkbenchShipBuildingKeyword,
Categories = new ExtendedList<IFormLinkGetter<IKeywordGetter>>()
{
Category_ShipMod_Structure
},
RECF = 0,
};
myMod.ConstructibleObjects.Add(co);
// Finish up ---------------------------------------------
}
myMod.WriteToBinary(datapath + "\\" + modname + ".esm");
Console.WriteLine("Finished");
return 0;
}
}
}