forked from gardenappl/VanillaTweaks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LangTweaks.cs
111 lines (101 loc) · 4.03 KB
/
LangTweaks.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
using System;
using System.Collections.Generic;
using System.Reflection;
using Terraria;
using Terraria.ID;
using Terraria.Localization;
using Terraria.ModLoader;
using Terraria.UI;
using static Terraria.ModLoader.ModContent;
namespace VanillaTweaks
{
public static class LangTweaks
{
class ReplacedTooltipLine
{
public ItemTooltip Line;
public short ItemID;
public ReplacedTooltipLine(ItemTooltip line, short itemID)
{
this.Line = line;
this.ItemID = itemID;
}
}
static List<ReplacedTooltipLine> ReplacedTooltips = new List<ReplacedTooltipLine>();
public static void EditNames(LanguageManager _)
{
if (GetInstance<ClientConfig>().CobaltShieldRename)
{
Lang.GetItemName(ItemID.CobaltShield).Override = Language.GetText("Mods.VanillaTweaks.ItemName.CobaltShield");
}
if (GetInstance<ClientConfig>().SandstoneRename)
{
Lang.GetItemName(ItemID.SandstoneBrick).Override = Language.GetText("Mods.VanillaTweaks.ItemName.SandstoneBrick");
Lang.GetItemName(ItemID.SandstoneBrickWall).Override = Language.GetText("Mods.VanillaTweaks.ItemName.SandstoneBrickWall");
Lang.GetItemName(ItemID.SandstoneSlab).Override = Language.GetText("Mods.VanillaTweaks.ItemName.SandstoneSlab");
if (VanillaTweaks.Miscellania != null)
{
if (VanillaTweaks.Miscellania_SandstoneSlabWall != null)
Lang.GetItemName(VanillaTweaks.Miscellania_SandstoneSlabWall.Type).Override = Language.GetText("Mods.VanillaTweaks.ItemName.SandstoneSlabWall");
//textValueMethod.Invoke(Lang.GetItemName(type), new object[]{ Language.GetTextValue("Mods.GoldensMisc.ItemName.SandstoneSlabWall") });
}
}
}
static void ReplaceTooltip(ItemTooltip[] tooltipArray, string newTooltip, short itemID)
{
ReplacedTooltips.Add(new ReplacedTooltipLine(tooltipArray[itemID], itemID));
if (newTooltip == null)
tooltipArray[itemID] = ItemTooltip.None;
else
tooltipArray[itemID] = ItemTooltip.FromLanguageKey(newTooltip);
}
public static void EditTooltips()
{
var bindFlags = BindingFlags.Static | BindingFlags.NonPublic;
var tooltipsField = typeof(Lang).GetField("_itemTooltipCache", bindFlags);
var tooltips = (ItemTooltip[])tooltipsField.GetValue(null);
if (GetInstance<ServerConfig>().SwatHelmetTweak)
{
if (VanillaTweaks.Miscellania_ReinforcedVest != null)
ReplaceTooltip(tooltips, "Mods.VanillaTweaks.MiscellaniaTooltip.SwatHelmet", ItemID.SWATHelmet);
else
ReplaceTooltip(tooltips, "Mods.VanillaTweaks.ItemTooltip.SwatHelmet", ItemID.SWATHelmet);
}
if (GetInstance<ServerConfig>().MeteorArmorDamageTweak)
{
ReplaceTooltip(tooltips, null, ItemID.MeteorHelmet);
ReplaceTooltip(tooltips, null, ItemID.MeteorSuit);
ReplaceTooltip(tooltips, null, ItemID.MeteorLeggings);
}
if (GetInstance<ServerConfig>().SnowArmorTweak)
{
ReplaceTooltip(tooltips, "Mods.VanillaTweaks.ItemTooltip.Snow", ItemID.EskimoHood);
ReplaceTooltip(tooltips, "Mods.VanillaTweaks.ItemTooltip.Snow", ItemID.EskimoCoat);
ReplaceTooltip(tooltips, "Mods.VanillaTweaks.ItemTooltip.Snow", ItemID.EskimoPants);
}
if (GetInstance<ServerConfig>().PharaohSetTweak)
{
ReplaceTooltip(tooltips, "Mods.VanillaTweaks.ItemTooltip.Pharaoh", ItemID.PharaohsMask);
ReplaceTooltip(tooltips, "Mods.VanillaTweaks.ItemTooltip.Pharaoh", ItemID.PharaohsRobe);
}
if (GetInstance<ServerConfig>().CrimsonArmorTweak)
{
ReplaceTooltip(tooltips, "Mods.VanillaTweaks.ItemTooltip.Crimson", ItemID.CrimsonHelmet);
ReplaceTooltip(tooltips, "Mods.VanillaTweaks.ItemTooltip.Crimson", ItemID.CrimsonScalemail);
ReplaceTooltip(tooltips, "Mods.VanillaTweaks.ItemTooltip.Crimson", ItemID.CrimsonGreaves);
}
}
public static void ResetTooltips()
{
var bindFlags = BindingFlags.Static | BindingFlags.NonPublic;
var tooltipsField = typeof(Lang).GetField("_itemTooltipCache", bindFlags);
var tooltips = (ItemTooltip[])tooltipsField.GetValue(null);
foreach (var tooltip in ReplacedTooltips)
{
tooltips[tooltip.ItemID] = tooltip.Line;
}
ReplacedTooltips.Clear();
}
}
}