-
Notifications
You must be signed in to change notification settings - Fork 0
/
Armory.cs
327 lines (304 loc) · 16.5 KB
/
Armory.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
using Ionic.Zlib;
using Mutagen.Bethesda;
using Mutagen.Bethesda.Plugins;
using Mutagen.Bethesda.Starfield;
using Noggog;
using System.IO.Abstractions;
using System.Linq;
using static System.Windows.Forms.LinkLabel;
namespace StarArmory
{
class Armory
{
public static List<IArmorGetter> clothes { get; set; } = new List<IArmorGetter>();
public static List<IArmorGetter> hats { get; set; } = new List<IArmorGetter>();
public static List<IArmorGetter> spacesuits { get; set; } = new List<IArmorGetter>();
public static List<IArmorGetter> spacehelmets { get; set; } = new List<IArmorGetter>();
public static List<IArmorGetter> boostpacks { get; set; } = new List<IArmorGetter>();
public static List<IIngestibleGetter> ingestibles { get; set; } = new List<IIngestibleGetter>();
public static List<IWeaponGetter> ranged_weapons { get; set; } = new List<IWeaponGetter>();
public static List<IWeaponGetter> melee_weapons { get; set; } = new List<IWeaponGetter>();
public static List<IWeaponGetter> grenades { get; set; } = new List<IWeaponGetter>();
public static List<FactionPlan> plans;
public static Dictionary<string, Faction> factions;
public static List<string> UpgradedItems;//This is to prevent adding multiple keywords.
public static void Clear()
{
clothes.Clear();
hats.Clear();
spacesuits.Clear();
spacehelmets.Clear();
boostpacks.Clear();
}
public static bool hasflag(FirstPersonFlag value, FirstPersonFlag flag)
{
return ((value & flag) != 0);
}
public static void LoadClothes(List<string> mods)
{
StarArmory.log.Info("Starting to Load Mod Content");
using (var env = StarArmory.GetGameEnvironment())
{
var immutableLoadOrderLinkCache = env.LoadOrder.ToImmutableLinkCache();
FormKey Apparel = new FormKey(env.LoadOrder[0].ModKey, 918668);//ArmorTypeApparelOrNakedBody[KYWD: 000E048C]
FormKey Head = new FormKey(env.LoadOrder[0].ModKey, 918667);//ArmorTypeApparelHead [KYWD:000E048B]
FormKey spacesuit = new FormKey(env.LoadOrder[0].ModKey, 2344896);//ArmorTypeSpacesuitBody [KYWD:0023C7C0]
FormKey spacehelmet = new FormKey(env.LoadOrder[0].ModKey, 2344897);//ArmorTypeSpacesuitBackpack [KYWD:0023C7BF]
FormKey boostpack = new FormKey(env.LoadOrder[0].ModKey, 2344895);//ArmorTypeSpacesuitHelmet[KYWD: 0023C7C1]
Dictionary<FirstPersonFlag, string> ClothesFPF = new Dictionary<FirstPersonFlag, string>();
List<IArmorGetter> Leftovers = new List<IArmorGetter>();
int itemsAdded = 0;
foreach (var mod in env.LoadOrder)
{
if (!mods.Contains(mod.Value.FileName))
{
continue;
}
if (mod.Value.Mod != null)
{
try
{
//-------------------------------------------
// Armor
//-------------------------------------------
var armours = mod.Value.Mod.Armors.ToList();
StarArmory.log.Info("Loading Mod: " + mod.Value.FileName);
foreach (var armor in armours)
{
bool added = false;
bool Keyword = false;
var link = immutableLoadOrderLinkCache.Resolve<IArmorGetter>(armor.FormKey);
//-------------------------------------------
// Clothing
//-------------------------------------------
if (armor.HasKeyword(Apparel))
{
StarArmory.log.Info("Processing Armor: " + armor.EditorID + " flags " + armor.FirstPersonFlags.Value);
if (hasflag(armor.FirstPersonFlags.Value, FirstPersonFlag.BODY) )
{
clothes.Add(link);
added = true;
itemsAdded++;
StarArmory.log.Info("Added to clothes: " + armor.EditorID);
foreach (FirstPersonFlag item in Enum.GetValues(typeof(FirstPersonFlag))) {
if (hasflag(armor.FirstPersonFlags.Value, item))
{
//StarArmory.logr.WriteLine("Has Flag: " + item);
if (!ClothesFPF.ContainsKey(item))
{
ClothesFPF.Add(item, armor.EditorID);
}
}
}
}
else {
Leftovers.Add(armor);
}
Keyword = true;
}
//-------------------------------------------
// Spacesuits
//-------------------------------------------
if (armor.HasKeyword(spacesuit))
{
//Check that it actually is a spacesuit.
if (armor.FirstPersonFlags.Value == FirstPersonFlag.SSBODY)
{
spacesuits.Add(link);
added = true;
itemsAdded++;
}
Keyword = true;
}
//-------------------------------------------
// Space Helmets
//-------------------------------------------
if (armor.HasKeyword(spacehelmet))
{
//Check that it actually is a helmet
if (armor.FirstPersonFlags.Value == FirstPersonFlag.SSHelmet ||
armor.FirstPersonFlags.Value == FirstPersonFlag.Eyepatch
)
{
spacehelmets.Add(link);
added = true;
itemsAdded++;
}
Keyword = true;
}
//-------------------------------------------
// Boostpacks
//-------------------------------------------
if (armor.HasKeyword(boostpack))
{
boostpacks.Add(link);
added = true;
Keyword = true;
itemsAdded++;
}
if (!added)
{
StarArmory.log.Info("Didn't load armor " + armor.EditorID + " from mod " + mod.Value.FileName + " Keyword found: " + Keyword.ToString() + " | FirstPersonFlags checks : " + added.ToString());
}
}
}
catch (Exception ex)
{
StarArmory.log.Info("Exception in Armor Processing in Mod: " + mod.Value.FileName);
StarArmory.log.Info("Exception: " + ex);
}
//-------------------------------------------
// Weapons
//-------------------------------------------
try
{
FormKey weapon_ranged = new FormKey(env.LoadOrder[0].ModKey, 177940);//WeaponTypeRanged [KYWD:0002B714]
FormKey weapon_melee = new FormKey(env.LoadOrder[0].ModKey, 303268);//WeaponTypeMelee1H [KYWD:0004A0A4]
FormKey grenade = new FormKey(env.LoadOrder[0].ModKey, 303270);//WeaponTypeThrown [KYWD:0004A0A6]
var weapons = mod.Value.Mod.Weapons.ToList();
foreach (var weapon in weapons)
{
bool added = false;
var link = immutableLoadOrderLinkCache.Resolve<IWeaponGetter>(weapon.FormKey);
//-------------------------------------------
// Ranged Weapons
//-------------------------------------------
if (weapon.HasKeyword(weapon_ranged))
{
ranged_weapons.Add(link);
added = true;
itemsAdded++;
}
//-------------------------------------------
// Melee Weapons
//-------------------------------------------
if (weapon.HasKeyword(weapon_melee))
{
melee_weapons.Add(link);
added = true;
itemsAdded++;
}
//-------------------------------------------
// Grenades
//-------------------------------------------
if (weapon.HasKeyword(grenade))
{
grenades.Add(link);
added = true;
itemsAdded++;
}
if (!added)
{
StarArmory.log.Info("Didn't load weapon " + weapon.EditorID + " from mod " + mod.Value.FileName + " Keyword found: " + added.ToString());
}
}
}
catch (Exception ex)
{
StarArmory.log.Info("Exception in Weapon Processing in Mod: " + mod.Value.FileName);
StarArmory.log.Info("Exception: " + ex);
}
//-------------------------------------------
// Aid/Food
//-------------------------------------------
//todo
//ingestibles
try
{
var Ingestibles = mod.Value.Mod.Ingestibles.ToList();
foreach (var item in Ingestibles)
{
var link = immutableLoadOrderLinkCache.Resolve<IIngestibleGetter>(item.FormKey);
ingestibles.Add(link);
}
}
catch (Exception ex)
{
StarArmory.log.Info("Exception in Aid/Food Processing in Mod: " + mod.Value.FileName);
StarArmory.log.Info("Exception: " + ex);
}
//-------------------------------------------
// Misc
//-------------------------------------------
//todo
//-------------------------------------------
// Resources
//-------------------------------------------
//todo
StarArmory.log.Info("Finished procressing Mod: " + mod.Value.FileName);
StarArmory.log.Info(mod.Value.FileName + " contained " + itemsAdded + " valid items");
}
}
//-------------------------------------------
// Hats
//-------------------------------------------
//We don't want to add hats that clash with the clothes, so we process clothes first then hats.
foreach (var mod in env.LoadOrder)
{
if (!mods.Contains(mod.Value.FileName))
{
continue;
}
if (mod.Value.Mod != null)
{
try
{
var armours = mod.Value.Mod.Armors.ToList();
StarArmory.log.Info("Loading Mod: " + mod.Value.FileName);
foreach (var armor in armours)
{
var link = immutableLoadOrderLinkCache.Resolve<IArmorGetter>(armor.FormKey);
if (armor.HasKeyword(Head))
{
bool clashing = false;
foreach (var flag in ClothesFPF)
{
if (hasflag(armor.FirstPersonFlags.Value, flag.Key))
{
clashing = true;
StarArmory.log.Info("Clashing FPF: " + armor.EditorID + " flag " + flag.Key.ToString() + " was used in " + flag.Value);
}
}
if (!clashing)
{
hats.Add(link);
itemsAdded++;
}
}
}
}
catch (Exception ex)
{
StarArmory.log.Info("Exception in Armor Processing in Mod: " + mod.Value.FileName);
StarArmory.log.Info("Exception: " + ex);
}
}
}
//-------------------------------------------
// Accessories
//-------------------------------------------
//Some clothes didn't pass the first run. Here we try and add what we can to hats
foreach (var clothing in Leftovers)
{
bool clashing = false;
foreach (var flag in ClothesFPF)
{
if (hasflag(clothing.FirstPersonFlags.Value, flag.Key))
{
clashing = true;
StarArmory.log.Info("Clashing FPF: " + clothing.EditorID + " flag " + flag.Key.ToString() + " was used in " + flag.Value);
}
}
if (!clashing)
{
//Things that aren't outfits are probably accessories.
hats.Add(clothing);
itemsAdded++;
StarArmory.log.Info("Added to hats: " + clothing.EditorID);
}
}
StarArmory.log.Info("Finished procressing mods.");
}
}
}
}