-
Notifications
You must be signed in to change notification settings - Fork 1
/
Main.cs
365 lines (321 loc) · 18.8 KB
/
Main.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
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using UnityEngine;
using ServerSync;
using BepInEx.Configuration;
using JudesEquipment.Configuration;
using YamlDotNet.Serialization;
namespace JudesEquipment
{
[BepInDependency("Jotunn", BepInDependency.DependencyFlags.SoftDependency)]
[BepInDependency("BlacksmithTools", BepInDependency.DependencyFlags.SoftDependency)]
[BepInPlugin(GUID, MODNAME, VERSION)]
public class Main : BaseUnityPlugin
{
public const string
MODNAME = "JudesEquipment",
AUTHOR = "GoldenJude",
GUID = AUTHOR + "_" + MODNAME,
VERSION = "2.2.4";
public static ManualLogSource log;
internal readonly Harmony harmony;
public static Assembly assembly;
public const string bundleName = "judeequipment";
public const string itemConfigName = GUID + "_ItemConfig.yml";
public const string localizationconfigName = GUID + "_Localization.yml";
public const string colorConfigName = GUID + "_Colors.yml";
//public const string setEffectLocalizationToken = "SetEffect";
public static CustomSyncedValue<string> syncedModConfig = new CustomSyncedValue<string>(Sync.configSync, Path.GetFileNameWithoutExtension(itemConfigName));
public static CustomSyncedValue<string> syncedLocalization = new CustomSyncedValue<string>(Sync.configSync, Path.GetFileNameWithoutExtension(localizationconfigName));
public static SyncedConfigEntry<int> lockingConfig;
public static ConfigEntry<bool> neutralMetals;
public static ConfigEntry<bool> smoothTextures;
public static Shader creatureShader;
public static bool bsmithAvailable = false;
public static bool hugosCollidersAvaiable = false;
public static ItemConfig modConfig = new ItemConfig();
public static Dictionary<string, Dictionary<string, string>> localization = new Dictionary<string, Dictionary<string, string>>()
{
{ "English", new Dictionary<string, string>() }
};
public static FileSystemWatcher fsw = new FileSystemWatcher()
{
Path = Paths.ConfigPath,
IncludeSubdirectories = true,
EnableRaisingEvents = true
};
public Main()
{
log = Logger;
harmony = new Harmony(GUID);
assembly = Assembly.GetExecutingAssembly();
}
public void Start()
{
harmony.PatchAll(assembly);
bsmithAvailable = Util.IsModAvailable("BlacksmithTools", "2.0.0");
hugosCollidersAvaiable = Util.IsModAvailable("More Player Cloth Colliders", "3.0.0");
/*if (bsmithAvailable)
{
CreateBlacksmithsTooslConfigs();
ItemManager.InsertBsmithToolsCfgs();
}*/
lockingConfig = Sync.configSync.AddLockingConfigEntry(Config.Bind("Sync", "Sync configs", 1, "1 = enabled, 0 = disabled"));
neutralMetals = Config.Bind("Appearance", "Neutral metals", false, "Makes all metals a neutral grey");
smoothTextures = Config.Bind("Appearance", "Smooth textures", false, "Removes pixelization filter on all textures, overrides color config");
CreateDefaultLocalization();
LocalizationManager.LoadLocalization();
LoadColorConfig();
syncedModConfig.ValueChanged += () =>
{
modConfig = new DeserializerBuilder().Build().Deserialize<ItemConfig>(syncedModConfig.Value);
modConfig.ApplyArmorConfigs();
modConfig.ApplyRecipeConfigs();
modConfig.ApplySetEffects();
};
syncedLocalization.ValueChanged += () =>
{
localization = new DeserializerBuilder().Build().Deserialize<Dictionary<string, Dictionary<string, string>>>(syncedLocalization.Value);
LocalizationManager.InsertLocalization();
};
fsw.Changed += (object sender, FileSystemEventArgs e) =>
{
if (!Sync.configSync.IsSourceOfTruth) return;
if (Path.GetFileName(e.FullPath) == itemConfigName)
{
LoadModConfig();
}
if(Path.GetFileName(e.FullPath) == localizationconfigName)
{
LocalizationManager.LoadLocalization();
}
};
}
public static void LoadColorConfig()
{
List<string> list = Directory.GetFiles(Paths.ConfigPath, colorConfigName, SearchOption.AllDirectories).ToList<string>();
bool flag = list.Count == 0;
if (flag)
{
File.WriteAllText(Path.Combine(Paths.ConfigPath, colorConfigName), new SerializerBuilder().Build().Serialize(ItemManager.colorConfig));
}
else
{
var loadedColorConfig = new Dictionary<string, Dictionary<string, string>>();
try
{
loadedColorConfig = new DeserializerBuilder().Build().Deserialize<Dictionary<string, Dictionary<string, string>>>(File.ReadAllText(list[0]));
ItemManager.colorConfig = loadedColorConfig;
}
catch (Exception ex)
{
Main.log.LogWarning("An error occured when loading " + colorConfigName + ", will use default values");
Main.log.LogWarning(ex.Message);
Main.log.LogWarning(ex.StackTrace);
}
}
}
public static void LoadModConfig()
{
List<string> files = Directory.GetFiles(Paths.ConfigPath, itemConfigName, SearchOption.AllDirectories).ToList();
if (files.Count == 0)
{
File.WriteAllText(Path.Combine(Paths.ConfigPath, itemConfigName), new SerializerBuilder().Build().Serialize(modConfig));
return;
}
ItemConfig loadedItemconfig = new ItemConfig();
try
{
loadedItemconfig = new DeserializerBuilder().Build().Deserialize<ItemConfig>(File.ReadAllText(files[0]));
}
catch (Exception e)
{
Main.log.LogWarning("An error occured when loading " + Main.itemConfigName + ", will use default values");
Main.log.LogWarning(e.Message);
Main.log.LogWarning(e.StackTrace);
}
syncedModConfig.Value = new SerializerBuilder().Build().Serialize(loadedItemconfig);
try
{
if (!ConfigHasAllArmors(File.ReadAllText(files[0])))
{
File.WriteAllText(Path.Combine(Paths.ConfigPath, itemConfigName), new SerializerBuilder().Build().Serialize(modConfig));
}
}
catch(Exception e)
{
Main.log.LogWarning("failed to validate if item config fil contains all sets, error: " + Environment.NewLine + e.Message);
}
}
static bool ConfigHasAllArmors(string configJson)
{
List<FieldInfo> fields = typeof(ItemConfig).GetFields().ToList();
List<FieldInfo> itemFields = fields.Where(field => field.CustomAttributes.First(att => att.AttributeType == typeof(YamlMemberAttribute)) != null).ToList();
foreach(FieldInfo field in itemFields)
{
CustomAttributeData yamlAttribute = field.CustomAttributes.First(att => att.AttributeType == typeof(YamlMemberAttribute));
string alias = (string)yamlAttribute.NamedArguments.First(na => na.MemberName == nameof(YamlMemberAttribute.Alias)).TypedValue.Value;
if (!configJson.Contains(alias)) return false;
}
return true;
}
void CreateDefaultLocalization()
{
//localization["English"].Add(setEffectLocalizationToken, "Set effect");
localization["English"].Add("ArmorNobleHelmet", "Fur hat");
localization["English"].Add("ArmorNobleHelmet_description", "Fashionable hat with fur lining");
localization["English"].Add("ArmorNobleChest", "Noble's banner garb");
localization["English"].Add("ArmorNobleChest_description", "A garb stitched together from banners torn from your burial chamber, a good alternative to roaming Valheim bare");
localization["English"].Add("ArmorNobleLegs", "Noble's pants");
localization["English"].Add("ArmorNobleLegs_description", "Worn, loose pants from a past life where one could afford to feast more often");
localization["English"].Add("ArmorNobleCape", "Vegvisir cape");
localization["English"].Add("ArmorNobleCape_description", "Cape fashioned from a vegvisir banner");
localization["English"].Add("ArmorBarbarianBronzeHelmetJD", "Barbarian's helmet");
localization["English"].Add("ArmorBarbarianBronzeHelmetJD_description", "Helmet made from a bronze alloy");
localization["English"].Add("ArmorBarbarianBronzeChestJD", "Barbarian's armor");
localization["English"].Add("ArmorBarbarianBronzeChestJD_description", "A bronze disc attached to leather straps, a true barbarian hurls himself into battle despite the lack of protection");
localization["English"].Add("ArmorBarbarianBronzeLegsJD", "Barbarian's boots");
localization["English"].Add("ArmorBarbarianBronzeLegsJD_description", "Thick hide wrapped around one's waist, fastened with a fashionable bronze belt");
localization["English"].Add("ArmorBarbarianCapeJD", "Barbarian's fur cape");
localization["English"].Add("ArmorBarbarianCapeJD_description", "Thick, short cape made from fur. Covers ones back when his drunk raidmates can't.");
localization["English"].Add("ArmorWarriorHelmet", "Warrior's helmet");
localization["English"].Add("ArmorWarriorHelmet_description", "Chainmail wrapping around the neck provides good protection");
localization["English"].Add("ArmorWarriorChest", "Warrior's hauberk");
localization["English"].Add("ArmorWarriorChest_description", "Long vest made from linked chains");
localization["English"].Add("ArmorWarriorLegs", "Warrior's boots");
localization["English"].Add("ArmorWarriorLegs_description", "Multi-layered pants keep it's wearer warm and protected");
localization["English"].Add("ArmorPlateIronHelmetJD", "Sturdy helmet");
localization["English"].Add("ArmorPlateIronHelmetJD_description", "A sturdy helmet with a leather neckguard");
localization["English"].Add("ArmorPlateIronChestJD", "Plate mail");
localization["English"].Add("ArmorPlateIronChestJD_description", "Thick plates of metal riveted to a leather harness");
localization["English"].Add("ArmorPlateIronLegsJD", "Plate greaves");
localization["English"].Add("ArmorPlateIronLegsJD_description", "Reliable greaves and kneeguards");
localization["English"].Add("ArmorPlateCape", "Boar cape");
localization["English"].Add("ArmorPlateCape_description", "Reinforced boar hide worn around one's shoulders like a trophy");
localization["English"].Add("ArmorDragonslayerHelmet", "Horned helm");
localization["English"].Add("ArmorDragonslayerHelmet_description", "Dragon's tremble in fear when they see the blackened helmet adorned with the horns of their kin");
localization["English"].Add("ArmorDragonslayerChest", "Dragonslayer's armor");
localization["English"].Add("ArmorDragonslayerChest_description", "Obsidian layer over silver plates makes for reliable protection");
localization["English"].Add("ArmorDragonslayerLegs", "Spiked greaves");
localization["English"].Add("ArmorDragonslayerLegs_description", "Unlucky is he who finds himself in the way of these");
localization["English"].Add("ArmorWandererHelmet", "Straw hat");
localization["English"].Add("ArmorWandererHelmet_description", "A reinforced straw hat");
localization["English"].Add("ArmorWandererChest", "Coat of plates");
localization["English"].Add("ArmorWandererChest_description", "Small metal plates attached to a leather jerkin, easy to maintain during travels");
localization["English"].Add("ArmorWandererLegs", "Wanderer's pants");
localization["English"].Add("ArmorWandererLegs_description", "Durable pants with makeshift protection around the shins");
localization["English"].Add("ArmorWandererCape", "Straw cape");
localization["English"].Add("ArmorWandererCape_description", "Cheap to make cape made from straw collected in the plains, protects against the elements but is quick to catch fire");
localization["English"].Add("ArmorBlackmetalgarbHelmet", "Nomadic helmet");
localization["English"].Add("ArmorBlackmetalgarbHelmet_description", "Blackmetal helmet with colorful padding fit for a nomad");
localization["English"].Add("ArmorBlackmetalgarbChest", "Nomadic garb");
localization["English"].Add("ArmorBlackmetalgarbChest_description", "A nomadic garb adorned with protective elements made from blackmetal, found commonly in the nomad's homeland, the plains");
localization["English"].Add("ArmorBlackmetalgarbLegs", "Nomadic boots");
localization["English"].Add("ArmorBlackmetalgarbLegs_description", "Thick leather boots with blackmetal toe guard, helpful when one happens to get stomped on by a Lox");
localization["English"].Add("ArmorSerpentHelmet", "Finned helm");
localization["English"].Add("ArmorSerpentHelmet_description", "A thick blackmetal casque adorned by the fins of a mighty serpent. The style is popular with raiding knights of the South.");
localization["English"].Add("ArmorSerpentChest", "Serpent armor");
localization["English"].Add("ArmorSerpentChest_description", "Plates of blackmetal overtop a surcoat of sea serpent scales. The perfect garb for spreading Odin's good word.");
localization["English"].Add("ArmorSerpentLegs", "Serpent Cuisses");
localization["English"].Add("ArmorSerpentLegs_description", "Blackmetal cuisses, greaves and sabatons. Excellent protection with a slightly fishy smell.");
localization["English"].Add("ArmorSerpentCape", "Serpent knight's cape");
localization["English"].Add("ArmorSerpentCape_description", "Heavy dark cape of the Serpent order.");
localization["English"].Add("ArmorMistlandsHelmet", "Scorched sallet");
localization["English"].Add("ArmorMistlandsHelmet_description", "Helmet made from a rare material only found within the ashlands");
localization["English"].Add("ArmorMistlandsChest", "Scorched armor");
localization["English"].Add("ArmorMistlandsChest_description", "Thick, multi layered gambeson provides protection from the searing heat of flametal, which in turn protects from blows");
localization["English"].Add("ArmorMistlandsLegs", "Scorched greaves");
localization["English"].Add("ArmorMistlandsLegs_description", "One need not fear the cold while wearing these");
localization["English"].Add("BackpackSimple", "Simple backpack");
localization["English"].Add("BackpackSimple_description", "Leather container attached to a wooden frame");
localization["English"].Add("BackpackHeavy", "Heavy backpack");
localization["English"].Add("BackpackHeavy_description", "Large chest hauled on ones shoulders with a canvas bag for additional storage");
}
public static void CreateBlacksmithsTooslConfigs()
{
if (!bsmithAvailable) return;
//nobruh armor
ItemManager.bsmithCfgs.Add(new BlacksmithsToolsConfig()
{
itemName = "ArmorNobleChest",
bonesToHide = Util.TorsoUpperLowerArms
});
ItemManager.bsmithCfgs.Add(new BlacksmithsToolsConfig()
{
itemName = "ArmorNobleLegs",
bonesToHide = Util.CompleteLegs
});
//blackmetalgarb
ItemManager.bsmithCfgs.Add(new BlacksmithsToolsConfig()
{
itemName = "ArmorBlackmetalgarbChest",
bonesToHide = Util.TorsoUpperArms
});
ItemManager.bsmithCfgs.Add(new BlacksmithsToolsConfig()
{
itemName = "ArmorBlackmetalgarbLegs",
bonesToHide = Util.CompleteLegs
});
//barbarian legs
ItemManager.bsmithCfgs.Add(new BlacksmithsToolsConfig()
{
itemName = "ArmorBarbarianBronzeLegsJD",
bonesToHide = Util.CompleteLegs
});
ItemManager.bsmithCfgs.Add(new BlacksmithsToolsConfig()
{
itemName = "ArmorWarriorLegs",
bonesToHide = Util.CompleteLegs
});
//ronin armor
ItemManager.bsmithCfgs.Add(new BlacksmithsToolsConfig()
{
itemName = "ArmorWandererChest",
bonesToHide = Util.TorsoUpperArms
});
ItemManager.bsmithCfgs.Add(new BlacksmithsToolsConfig()
{
itemName = "ArmorWandererLegs",
bonesToHide = Util.CompleteLegs
});
//dragonslayer armor
ItemManager.bsmithCfgs.Add(new BlacksmithsToolsConfig()
{
itemName = "ArmorDragonslayerChest",
bonesToHide = Util.TorsoUpperArms
});
ItemManager.bsmithCfgs.Add(new BlacksmithsToolsConfig()
{
itemName = "ArmorDragonslayerLegs",
bonesToHide = Util.CompleteLegs
});
//ashlands armor
ItemManager.bsmithCfgs.Add(new BlacksmithsToolsConfig()
{
itemName = "ArmorMistlandsChest",
bonesToHide = Util.TorsoUpperLowerArms
});
ItemManager.bsmithCfgs.Add(new BlacksmithsToolsConfig()
{
itemName = "ArmorMistlandsLegs",
bonesToHide = Util.CompleteLegs
});
ItemManager.bsmithCfgs.Add(new BlacksmithsToolsConfig()
{
itemName = "ArmorSerpentChest",
bonesToHide = Util.TorsoUpperLowerArms
});
ItemManager.bsmithCfgs.Add(new BlacksmithsToolsConfig()
{
itemName = "ArmorSerpentLegs",
bonesToHide = Util.CompleteLegs
});
}
}
}