-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathOriginConfig.cs
746 lines (715 loc) · 26.2 KB
/
OriginConfig.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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
using Microsoft.Xna.Framework.Graphics;
using Newtonsoft.Json;
using Origins.Dev;
using Origins.Items.Accessories;
using Origins.Items.Other.Fish;
using Origins.Items.Weapons.Melee;
using Origins.Layers;
using Origins.LootConditions;
using Origins.Reflection;
using Origins.UI;
using Origins.UI.Event;
using PegasusLib;
using ReLogic.OS;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using Terraria;
using Terraria.Audio;
using Terraria.GameContent.ItemDropRules;
using Terraria.GameContent.UI.Elements;
using Terraria.ID;
using Terraria.Localization;
using Terraria.ModLoader;
using Terraria.ModLoader.Config;
using Terraria.ModLoader.Config.UI;
using Terraria.ModLoader.IO;
namespace Origins {
public class OriginConfig : ModConfig {
public static OriginConfig Instance;
public override ConfigScope Mode => ConfigScope.ServerSide;
[Header("VanillaBuffs")]
[DefaultValue(true)]
public bool WoodBuffs = true;
[DefaultValue(true)]
public bool RainSetBuff = true;
[DefaultValue(true), ReloadRequired]
public bool RoyalGel = true;
[DefaultValue(true), ReloadRequired]
public bool VolatileGelatin = true;
[Header("Other")]
[DefaultValue(true)]
public bool Assimilation = true;
[Header("Balance")]
[JsonDefaultDictionaryKeyValue("{\"Mod\": \"Terraria\", \"Name\": \"GenericDamageClass\"}")]
[JsonIgnore, ShowDespiteJsonIgnore]
public Dictionary<DamageClassDefinition, float> StatShareRatio { get; set; } = new() {
[new("Terraria/SummonDamageClass")] = 0.5f
};
[JsonIgnore]
public static bool GraveshieldZombiesShouldDropAsItem => ServerSideAccessibility.Instance.GraveshieldZombiesDropAsItem && !Main.getGoodWorld;
[ReloadRequired]
[DefaultValue(true)]
public bool GrassMerge = true;
internal void Save() {
Directory.CreateDirectory(ConfigManager.ModConfigPath);
string filename = Mod.Name + "_" + Name + ".json";
string path = Path.Combine(ConfigManager.ModConfigPath, filename);
string json = JsonConvert.SerializeObject(this, ConfigManager.serializerSettings);
WikiPageExporter.WriteFileNoUnneededRewrites(path, json);
}
static string BalanceSaveBath => Path.Combine(ConfigManager.ModConfigPath, "OriginsBalanceConfig" + ".nbt");
public override void OnLoaded() {
LoadFromFile();
}
internal void LoadFromFile() {
if (File.Exists(BalanceSaveBath)) Load(TagIO.FromFile(BalanceSaveBath));
}
internal void SaveToFile() {
TagCompound balanceData = [];
Save(balanceData);
TagIO.ToFile(balanceData, BalanceSaveBath);
}
internal void Save(TagCompound tag) {
TagCompound statShareData = [];
foreach (KeyValuePair<DamageClassDefinition, float> item in StatShareRatio) {
statShareData[item.Key.ToString()] = item.Value;
}
tag[nameof(StatShareRatio)] = statShareData;
}
internal void Load(TagCompound tag) {
StatShareRatio = [];
foreach (KeyValuePair<string, object> item in tag.SafeGet<TagCompound>(nameof(StatShareRatio), [])) {
StatShareRatio[DamageClassDefinition.FromString(item.Key)] = item.Value is float value ? value : 1;
}
}
internal void CloneTo(OriginConfig clone) {
TagCompound balanceData = [];
Save(balanceData);
clone.Load(balanceData);
}
}
public class OriginClientConfig : ModConfig {
public static OriginClientConfig Instance;
public override ConfigScope Mode => ConfigScope.ClientSide;
[DefaultValue(false)]
public bool SetBonusDoubleTap = false;
[DefaultValue(true)]
public bool AnimatedRavel = true;
[DefaultValue(0.2f), Range(0, 1), Increment(0.05f)]
public float DefiledShaderJitter = 0.2f;
[DefaultValue(0.1f), Range(0, 1), Increment(0.05f)]
public float DefiledShaderNoise = 0.1f;
[DefaultValue(1f), Range(0, 2), Increment(0.1f)]
public float ScreenShakeMultiplier = 1f;
[DefaultValue(true)]
public bool ExtraGooeyRivenGores = true;
[DefaultValue(false)]
public bool TwentyFourHourTime = false;
[DefaultValue(false)]
public bool OldSoundtrack = false;
public LaserTagConfig laserTagConfig = new();
[Header("Journal")]
[DefaultValue(true)]
public bool OpenJournalOnUnlock = true;
[DefaultValue(Journal_Default_UI_Mode.Quest_List)]
public Journal_Default_UI_Mode DefaultJournalMode = Journal_Default_UI_Mode.Quest_List;
internal void Save() {
Directory.CreateDirectory(ConfigManager.ModConfigPath);
string filename = Mod.Name + "_" + Name + ".json";
string path = Path.Combine(ConfigManager.ModConfigPath, filename);
string json = JsonConvert.SerializeObject(this, ConfigManager.serializerSettings);
WikiPageExporter.WriteFileNoUnneededRewrites(path, json);
}
[CustomModConfigItem(typeof(InconspicuousVersionElement))]
public DebugConfig DebugMenuButton { get; set; } = new();
internal static bool forceReloadLanguage = false;
public override void OnChanged() {
if (forceReloadLanguage) {
GameCulture culture = LanguageManager.Instance.ActiveCulture;
GameCulture french = GameCulture.FromCultureName(GameCulture.CultureName.French);
LanguageManager.Instance.SetLanguage(culture == french ? GameCulture.FromCultureName(GameCulture.CultureName.Italian) : french);
LanguageManager.Instance.SetLanguage(culture);
}
}
}
public class LaserTagConfig : ModConfig {
public static LaserTagConfig Instance => OriginClientConfig.Instance.laserTagConfig;
public override ConfigScope Mode => ConfigScope.ClientSide;
public override bool Autoload(ref string name) => false;
[DefaultValue(Laser_Tag_Health_Pip_Placement.Back), DrawTicks]
public Laser_Tag_Health_Pip_Placement HealthPipPlacement { get; set; } = Laser_Tag_Health_Pip_Placement.Back;
[DefaultValue(6), Slider, Range(0, 32), DrawTicks, Increment(2)]
public int HealthPipOffset { get; set; } = 6;
[DefaultValue(false)]
public bool HealthPipDirectionInverted { get; set; } = false;
}
internal class InconspicuousVersionElement : ConfigElement<ModConfig> {
private UIPanel separatePagePanel;
public override void OnBind() {
base.OnBind();
this.OnLeftClick += (evt, el) => {
if (Terraria.UI.ItemSlot.ShiftInUse) {
UIModConfig.SwitchToSubConfig(separatePagePanel);
} else {
Platform.Get<IClipboard>().Value = Origins.instance.Version.ToString();
Main.NewText("Copied version to clipboard");
}
};
TextDisplayFunction = () => $"{Label}: {Origins.instance.Version}";
if (Value is null) {
ModConfig data = Activator.CreateInstance(MemberInfo.Type, nonPublic: true) as ModConfig;
JsonConvert.PopulateObject(JsonDefaultValueAttribute?.Json ?? "{}", data, ConfigManager.serializerSettings);
Value = data;
}
SetupList();
Recalculate();
}
private void SetupList() {
separatePagePanel = UIModConfig.MakeSeparateListPanel(Item, Value, MemberInfo, List, Index, Language.GetOrRegister("Mods.Origins.Configs.OriginClientConfig.DebugMenuButton.SecretLabel").ToString);
}
public override void Recalculate() {
base.Recalculate();
Height.Set(30, 0f);
}
}
public class DebugConfig : ModConfig {
public static DebugConfig Instance => OriginClientConfig.Instance.DebugMenuButton;
public override ConfigScope Mode => ConfigScope.ClientSide;
public override bool Autoload(ref string name) => false;
[DefaultValue(false)]
public bool DebugMode = false;
[DefaultValue(false)]
public bool ForceAprilFools = false;
#region exporting
public string StatJSONPath { get; set; }
public bool ExportAllItemStatsJSON {
get => false;
set {
if (value) {
if (string.IsNullOrWhiteSpace(StatJSONPath)) {
Origins.LogError($"StatJSONPath is null or whitespace");
return;
}
if (Terraria.UI.ItemSlot.ShiftInUse) {
Directory.CreateDirectory(StatJSONPath);
int i;
for (i = 0; i < ItemLoader.ItemCount; i++) if (ContentSamples.ItemsByType[i].ModItem?.Mod is Origins) break;
for (; i < ItemLoader.ItemCount; i++) {
Item item = ContentSamples.ItemsByType[i];
if (item.ModItem is not null) {
if (item.ModItem?.Mod is not Origins) break;
WikiPageExporter.ExportItemStats(item);
}
}
} else {
const string text = "Shift must be held to export all stats, for safety reasons";
Origins.LogError(text);
Main.NewText(text);
}
}
}
}
public ItemDefinition ExportItemStatsJSON {
get => default;
set {
if ((value?.Type ?? 0) > ItemID.None) {
if (string.IsNullOrWhiteSpace(StatJSONPath)) {
Origins.LogError($"StatJSONPath is null or whitespace");
return;
}
Directory.CreateDirectory(StatJSONPath);
WikiPageExporter.ExportItemStats(ContentSamples.ItemsByType[value.Type]);
}
}
}
public bool ExportAllNPCStatsJSON {
get => false;
set {
if (value) {
if (string.IsNullOrWhiteSpace(StatJSONPath)) {
Origins.LogError($"StatJSONPath is null or whitespace");
return;
}
if (Terraria.UI.ItemSlot.ShiftInUse) {
Directory.CreateDirectory(StatJSONPath);
int i;
for (i = 0; i < NPCLoader.NPCCount; i++) if (ContentSamples.NpcsByNetId[i].ModNPC?.Mod is Origins) break;
for (; i < NPCLoader.NPCCount; i++) {
NPC npc = ContentSamples.NpcsByNetId[i];
if (npc.ModNPC is not null) {
if (npc.ModNPC?.Mod is not Origins) break;
WikiPageExporter.ExportNPCStats(npc);
}
}
} else {
const string text = "Shift must be held to export all stats, for safety reasons";
Origins.LogError(text);
Main.NewText(text);
}
}
}
}
public bool ExportAllBuffStatsJSON {
get => false;
set {
if (value) {
if (string.IsNullOrWhiteSpace(StatJSONPath)) {
Origins.LogError($"StatJSONPath is null or whitespace");
return;
}
Directory.CreateDirectory(StatJSONPath);
for (int i = BuffID.Count; i < BuffLoader.BuffCount; i++) {
ModBuff buff = BuffLoader.GetBuff(i);
if (buff?.Mod is Origins) WikiPageExporter.ExportBuffStats(buff);
}
}
}
}
public NPCDefinition ExportNPCStatsJSON {
get => default;
set {
if ((value?.Type ?? 0) > NPCID.None) {
if (string.IsNullOrWhiteSpace(StatJSONPath)) {
Origins.LogError($"StatJSONPath is null or whitespace");
return;
}
Directory.CreateDirectory(StatJSONPath);
WikiPageExporter.ExportNPCStats(ContentSamples.NpcsByNetId[value.Type]);
}
}
}
public bool ExportAllNPCPages {
get => false;
set {
if (value) {
if (string.IsNullOrWhiteSpace(WikiTemplatePath)) {
Origins.LogError($"WikiTemplatePath is null or whitespace");
return;
}
if (string.IsNullOrWhiteSpace(WikiPagePath)) {
Origins.LogError($"WikiPagePath is null or whitespace");
return;
}
if (Terraria.UI.ItemSlot.ShiftInUse) {
Directory.CreateDirectory(WikiPagePath);
int i;
for (i = 0; i < ItemLoader.ItemCount; i++) if (ContentSamples.NpcsByNetId[i].ModNPC?.Mod is Origins) break;
for (; i < ItemLoader.ItemCount; i++) {
NPC npc = ContentSamples.NpcsByNetId[i];
if (npc.ModNPC is not null) {
if (npc.ModNPC?.Mod is not Origins) break;
if (npc.ModNPC is ICustomWikiStat { ShouldHavePage: false }) continue;
if (npc.ModNPC is ICustomWikiStat { FullyGeneratable: true } || !File.Exists(WikiPageExporter.GetWikiPagePath(WikiPageExporter.GetWikiName(npc.ModNPC))))
WikiPageExporter.ExportNPCPage(npc);
}
}
} else {
Main.NewText("Shift must be held to export all stats, for safety reasons");
}
}
}
}
public NPCDefinition ExportNPCPage {
get => default;
set {
if ((value?.Type ?? 0) != NPCID.None) {
if (string.IsNullOrWhiteSpace(WikiTemplatePath)) {
Origins.LogError($"WikiTemplatePath is null or whitespace");
return;
}
if (string.IsNullOrWhiteSpace(WikiPagePath)) {
Origins.LogError($"WikiPagePath is null or whitespace");
return;
}
Directory.CreateDirectory(WikiPagePath);
WikiPageExporter.ExportNPCPage(ContentSamples.NpcsByNetId[value.Type]);
}
}
}
public bool ExportAllItemPages {
get => false;
set {
if (value) {
if (string.IsNullOrWhiteSpace(WikiTemplatePath)) {
Origins.LogError($"WikiTemplatePath is null or whitespace");
return;
}
if (string.IsNullOrWhiteSpace(WikiPagePath)) {
Origins.LogError($"WikiPagePath is null or whitespace");
return;
}
if (Terraria.UI.ItemSlot.ShiftInUse) {
Directory.CreateDirectory(WikiPagePath);
int i;
for (i = 0; i < ItemLoader.ItemCount; i++) if (ContentSamples.ItemsByType[i].ModItem?.Mod is Origins) break;
for (; i < ItemLoader.ItemCount; i++) {
Item item = ContentSamples.ItemsByType[i];
if (item.ModItem is not null) {
if (item.ModItem?.Mod is not Origins) break;
if ((item.ModItem as ICustomWikiStat)?.ShouldHavePage == false) continue;
WikiPageExporter.ExportItemPage(item);
}
}
} else {
Main.NewText("Shift must be held to export all stats, for safety reasons");
}
}
}
}
public ItemDefinition ExportItemPage {
get => default;
set {
if ((value?.Type ?? 0) > ItemID.None) {
if (string.IsNullOrWhiteSpace(WikiTemplatePath)) {
Origins.LogError($"WikiTemplatePath is null or whitespace");
return;
}
if (string.IsNullOrWhiteSpace(WikiPagePath)) {
Origins.LogError($"WikiPagePath is null or whitespace");
return;
}
Directory.CreateDirectory(WikiPagePath);
WikiPageExporter.ExportItemPage(ContentSamples.ItemsByType[value.Type]);
}
}
}
public bool ExportAllItemImages {
get => default;
set {
if (value) {
if (string.IsNullOrWhiteSpace(WikiSpritesPath)) {
Origins.LogError($"WikiSpritesPath is null or whitespace");
return;
}
Directory.CreateDirectory(WikiSpritesPath);
int i;
for (i = 0; i < ItemLoader.ItemCount; i++) if (ContentSamples.ItemsByType[i].ModItem?.Mod is Origins) break;
for (; i < ItemLoader.ItemCount; i++) {
Item item = ContentSamples.ItemsByType[i];
if (item.ModItem is not null) {
if (item.ModItem?.Mod is not Origins) break;
if (item.ModItem is ICustomWikiStat { ShouldHavePage: false }) continue;
WikiPageExporter.ExportContentSprites(item.ModItem);
}
}
}
}
}
public ItemDefinition ExportItemImages {
get => default;
set {
if ((value?.Type ?? 0) > ItemID.None) {
if (string.IsNullOrWhiteSpace(WikiSpritesPath)) {
Origins.LogError($"WikiSpritesPath is null or whitespace");
return;
}
Directory.CreateDirectory(WikiSpritesPath);
WikiPageExporter.ExportContentSprites(ContentSamples.ItemsByType[value.Type].ModItem);
}
}
}
public bool ExportAllNPCImages {
get => default;
set {
if (value) {
if (string.IsNullOrWhiteSpace(WikiSpritesPath)) {
Origins.LogError($"WikiSpritesPath is null or whitespace");
return;
}
Directory.CreateDirectory(WikiSpritesPath);
int i;
for (i = 0; i < NPCLoader.NPCCount; i++) if (ContentSamples.NpcsByNetId[i].ModNPC?.Mod is Origins) break;
for (; i < NPCLoader.NPCCount; i++) {
NPC npc = ContentSamples.NpcsByNetId[i];
if (npc.ModNPC is not null) {
if (npc.ModNPC?.Mod is not Origins) break;
if (npc.ModNPC is ICustomWikiStat { ShouldHavePage: false }) continue;
WikiPageExporter.ExportContentSprites(npc.ModNPC);
}
}
}
}
}
public NPCDefinition ExportNPCImages {
get => default;
set {
if ((value?.Type ?? 0) > NPCID.None) {
if (string.IsNullOrWhiteSpace(WikiSpritesPath)) {
Origins.LogError($"WikiSpritesPath is null or whitespace");
return;
}
Directory.CreateDirectory(WikiSpritesPath);
WikiPageExporter.ExportContentSprites(ContentSamples.NpcsByNetId[value.Type].ModNPC);
}
}
}
public bool ExportSpecialPages {
get => false;
set {
if (value) {
if (string.IsNullOrWhiteSpace(WikiPagePath)) {
Origins.LogError($"WikiPagePath is null or whitespace");
return;
}
Directory.CreateDirectory(WikiPagePath);
foreach (var item in WikiSpecialPage.SpecialPages) {
if (item.GeneratePage() is string page) WikiPageExporter.WriteFileNoUnneededRewrites(WikiPageExporter.GetWikiPagePath(item.Name), page);
}
}
}
}
public bool ExportSpecialImages {
get => false;
set {
if (value) {
if (string.IsNullOrWhiteSpace(WikiSpritesPath)) {
Origins.LogError($"WikiSpritesPath is null or whitespace");
return;
}
Directory.CreateDirectory(WikiSpritesPath);
foreach (var item in WikiSpecialPage.SpecialPages) {
foreach ((string name, Texture2D texture) in item.GetSprites() ?? Array.Empty<(string, Texture2D)>()) {
WikiImageExporter.ExportImage(name, texture);
}
foreach ((string name, (Texture2D texture, int frames)[] textures) in item.GetAnimatedSprites() ?? Array.Empty<(string, (Texture2D texture, int frames)[])>()) {
WikiImageExporter.ExportAnimatedImage(name, textures);
}
}
}
}
}
public string WikiTemplatePath { get; set; }
public string WikiArmorTemplatePath { get; set; }
public string WikiSpecialTemplatePath { get; set; }
public string WikiSpritesPath { get; set; }
public string WikiPagePath { get; set; }
#endregion
public bool CheckTextureUsage {
get => default;
set {
if (value) {
foreach (ILoadable content in Origins.instance.GetContent()) {
if (content is ModItem item) {
Main.instance.LoadItem(item.Type);
} else if (content is ModProjectile proj) {
Main.instance.LoadProjectile(proj.Type);
} else if (content is ModNPC npc) {
Main.instance.LoadNPC(npc.Type);
} else if (content is ModTile tile) {
Main.instance.LoadTiles(tile.Type);
} else if (content is ModWall wall) {
Main.instance.LoadWall(wall.Type);
}
if (content is ILoadExtraTextures extras) {
extras.LoadTextures();
}
}
foreach (Accessory_Glow_Layer glowLayer in Origins.instance.GetContent<Accessory_Glow_Layer>()) {
glowLayer.LoadAllTextures();
}
List<string> unused = [];
var loadedAssets = AssetRepositoryMethods._assets.GetValue(Origins.instance.Assets).Keys.Select(k => k.Replace(Path.DirectorySeparatorChar, '/')).ToHashSet();
loadedAssets.Add("icon");
loadedAssets.Add("Buffs/BuffTemplate");
loadedAssets.Add("Buffs/DebuffTemplate");
loadedAssets.Add("Items/Armor/Armor_Conversion");
loadedAssets.Add("Items/Armor/ArmorTemplate_v1");
loadedAssets.Add("NPCs/BossBarTemplate");
loadedAssets.Add("Tiles/BossDrops/Boss_Trophy_Empty");
loadedAssets.Add("Tiles/BossDrops/Boss_Trophy_Item_Empty");
loadedAssets.Add("Tiles/BossDrops/Relic_Examples");
loadedAssets.Add("Tiles/interesting_tile");
loadedAssets.Add("Tiles/Tile_Template");
foreach (string asset in Origins.instance.RootContentSource.EnumerateAssets()) {
string _asset = Path.ChangeExtension(asset, null);
if ((_asset.EndsWith('_') || _asset.EndsWith("__Glow")) && (_asset.StartsWith("Items/Armor/") || _asset.StartsWith("Items/Accessories/AccUseCatalogs"))) {
continue;
}
if (!loadedAssets.Contains(_asset)) {
unused.Add(_asset);
}
}
unused.Sort(new AssetPathComparer());
for (int i = 0; i < unused.Count - 1; i++) {
string[] a = unused[i].Split('/');
string[] b = unused[i + 1].Split('/');
int minLength = a.Length < b.Length ? a.Length : b.Length;
for (int j = 0; j < minLength - 1; j++) {
if (a[j] != b[j]) {
unused.Insert(i + 1, "");
break;
}
}
}
Directory.CreateDirectory(ConfigManager.ModConfigPath);
string filename = nameof(Origins) + "_Unused_Assets.txt";
string path = Path.Combine(ConfigManager.ModConfigPath, filename);
WikiPageExporter.WriteFileNoUnneededRewrites(path, string.Join('\n', unused));
}
}
}
static void SearchLootForObtainability(List<DropRateInfo> dropInfoList, IEnumerable<IItemDropRule> rules) {
DropRateInfoChainFeed ratesInfo = new(1f);
foreach (IItemDropRule rule in rules) {
rule.ReportDroprates(dropInfoList, ratesInfo);
/*foreach (DropAsSetRule dropAsSetRule in rule.ChainedRules.Select(a => a.RuleToChain).FindDropRules<DropAsSetRule>()) {
SearchLootForObtainability(dropInfoList, dropAsSetRule.ChainedRules.Select(a => a.RuleToChain));
}*/
}
}
public bool CheckItemObtainability {
get => default;
set {
if (value) {
List<string> unobtainable = [];
HashSet<int> obtainableItems = [];
List<(int, List<int>)> recipeResultItems = [];
for (int i = 0; i < Main.recipe.Length; i++) {
Recipe recipe = Main.recipe[i];
List<int> requiredItems = recipe.requiredItem.Where(item => item.ModItem?.Mod is Origins).Select(item => item.type).ToList();
if (requiredItems.Count <= 0) {
obtainableItems.Add(recipe.createItem.type);
} else {
recipeResultItems.Add((recipe.createItem.type, requiredItems));
}
}
List<DropRateInfo> dropInfoList = [];
SearchLootForObtainability(dropInfoList, ItemDropDatabaseMethods._entriesByNpcNetId.GetValue(Main.ItemDropsDB).Values
.Concat(ItemDropDatabaseMethods._entriesByItemId.GetValue(Main.ItemDropsDB).Values)
.SelectMany(l => l)
.Concat(ItemDropDatabaseMethods._globalEntries.GetValue(Main.ItemDropsDB))
);
for (int i = 0; i < dropInfoList.Count; i++) {
obtainableItems.Add(dropInfoList[i].itemId);
}
foreach (var item in TileLoaderMethods.tileTypeAndTileStyleToItemType.GetValue()) {
obtainableItems.Add(item.Value);
}
foreach (var item in TileLoaderMethods.tiles.GetValue().SelectMany(l => l.GetItemDrops(0, 0))) {
obtainableItems.Add(item.type);
}
foreach (var item in TileLoaderMethods.wallTypeToItemType.GetValue()) {
obtainableItems.Add(item.Value);
}
foreach (var wall in TileLoaderMethods.walls.GetValue()) {
int drop = -1;
wall.Drop(0, 0, ref drop);
if (drop != -1) {
obtainableItems.Add(drop);
}
}
foreach (int itemType in Origins.instance.GetContent().SelectMany(c => c is IItemObtainabilityProvider provider ? provider.ProvideItemObtainability() : [])) {
obtainableItems.Add(itemType);
}
foreach (NPCShop.Entry entry in NPCShopDatabase.AllShops.SelectMany(s => s is NPCShop shop ? shop.Entries : [])) {
obtainableItems.Add(entry.Item.type);
}
for (int i = 0; i < ItemID.Sets.ShimmerTransformToItem.Length; i++) {
if (i != -1 && (i < ItemID.Count || obtainableItems.Contains(i))) {
obtainableItems.Add(ItemID.Sets.ShimmerTransformToItem[i]);
}
}
int tries = 0;
while (recipeResultItems.Count > 0 && ++tries < 1000) {
for (int i = 0; i < ItemID.Sets.ShimmerTransformToItem.Length; i++) {
if (i != -1 && obtainableItems.Contains(i)) {
obtainableItems.Add(ItemID.Sets.ShimmerTransformToItem[i]);
}
}
for (int i = recipeResultItems.Count; i --> 0;) {
(int result, List<int> ingredients) = recipeResultItems[i];
if (obtainableItems.Contains(result)) {
recipeResultItems.RemoveAt(i);
continue;
}
for (int j = ingredients.Count; j --> 0;) {
if (obtainableItems.Contains(ingredients[j])) {
ingredients.RemoveAt(j);
}
}
if (ingredients.Count <= 0) {
obtainableItems.Add(result);
}
if (obtainableItems.Contains(result)) {
recipeResultItems.RemoveAt(i);
}
}
}
Dictionary<int, HashSet<int>> missingIngredients = [];
for (int i = recipeResultItems.Count; i-- > 0;) {
(int result, List<int> ingredients) = recipeResultItems[i];
if (!missingIngredients.TryGetValue(result, out HashSet<int> missing)) {
missingIngredients.Add(result, ingredients.ToHashSet());
} else {
foreach (var item in ingredients) {
missing.Add(item);
}
}
}
foreach (ILoadable content in Origins.instance.GetContent()) {
if (content is ModItem item && !obtainableItems.Contains(item.Type)) {
if (missingIngredients.TryGetValue(item.Type, out HashSet<int> missing)) {
unobtainable.Add($"{item.Name}: [{string.Join(", ", missing.Select(Lang.GetItemName))}]");
} else {
unobtainable.Add(item.Name);
}
}
}
unobtainable.Sort(new AssetPathComparer());
for (int i = 0; i < unobtainable.Count - 1; i++) {
string[] a = unobtainable[i].Split('/');
string[] b = unobtainable[i + 1].Split('/');
int minLength = a.Length < b.Length ? a.Length : b.Length;
for (int j = 0; j < minLength - 1; j++) {
if (a[j] != b[j]) {
unobtainable.Insert(i + 1, "");
break;
}
}
}
Directory.CreateDirectory(ConfigManager.ModConfigPath);
string filename = nameof(Origins) + "_Unobtainable_Items.txt";
string path = Path.Combine(ConfigManager.ModConfigPath, filename);
WikiPageExporter.WriteFileNoUnneededRewrites(path, string.Join('\n', unobtainable));
}
}
}
public HashSet<string> IgnoredCompatibilitySuggestions { get; set; } = [];
}
public class AssetPathComparer : IComparer<string> {
public int Compare(string x, string y) {
string[] a = x.Split('/');
string[] b = y.Split('/');
Comparer<string> comparer = Comparer<string>.Default;
if (a.Length == b.Length) return comparer.Compare(x, y);
int maxLength = a.Length > b.Length ? a.Length : b.Length;
for (int i = 0; i < maxLength; i++) {
if (i + 1 == a.Length) return 1;
if (i + 1 == b.Length) return -1;
int comp = comparer.Compare(a[i], b[i]);
if (comp != 0) return comp;
}
return comparer.Compare(x, y);
}
}
public class OriginAccessibilityConfig : ModConfig {
public static OriginAccessibilityConfig Instance;
public override ConfigScope Mode => ConfigScope.ClientSide;
[DefaultValue(false)]
public bool DisableDefiledWastelandsShader { get; set; }
}
public class ServerSideAccessibility : ModConfig {
public static ServerSideAccessibility Instance;
public override ConfigScope Mode => ConfigScope.ServerSide;
[DefaultValue(false)]
public bool GraveshieldZombiesDropAsItem = false;
[DefaultValue(1f), Range(0, 1)]
public float RivenAsimilationMultiplier = 1f;
}
}