forked from gardenappl/BossExpertise
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BossExpertise.cs
155 lines (145 loc) · 4.22 KB
/
BossExpertise.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
using System.IO;
using System.Reflection;
using Terraria;
using Terraria.ID;
using Terraria.Localization;
using Terraria.ModLoader;
namespace BossExpertise
{
public class BossExpertise : Mod
{
public static int ActualDifficulty = 0;
public static int CurrentDifficulty = 0;
public override void Load()
{
LegacyConfigV1.Load();
LegacyConfigV2.Load();
AddConfig("Config", new Config());
if (ModContent.GetInstance<Config>().CurrentFakedDifficulty == "Expert")
{
CurrentDifficulty = 1;
}
else if (ModContent.GetInstance<Config>().CurrentFakedDifficulty == "Master")
{
CurrentDifficulty = 2;
}
else
{
CurrentDifficulty = 0;
}
}
/*public override void PostSetupContent()
{
if(ModContent.GetInstance<Config>().AddCheatSheetButton)
CheatSheetIntegration.Load();
}*/
public override void Unload()
{
LegacyConfigV1.Unload();
LegacyConfigV2.Unload();
}
public override void HandlePacket(BinaryReader reader, int whoAmI)
{
var msgType = (ExpertMessageType)reader.ReadByte();
// Log("Received message! Type: {0}, Net mode: {1}", msgType, Main.netMode);
switch(msgType)
{
case ExpertMessageType.SyncDifficulty:
int difficulty = reader.ReadInt32();
HookDifficultyMode(difficulty);
if (Main.netMode == NetmodeID.Server)
{
SyncDifficultyMode(difficulty, whoAmI);
}
return;
case ExpertMessageType.SyncDemonHeart:
var player = Main.player[reader.ReadInt32()];
player.extraAccessory = reader.ReadBoolean();
return;
}
}
void SyncDifficultyMode(int difficulty, int ignoreClient = -1)
{
HookDifficultyMode(difficulty);
if (Main.netMode != NetmodeID.SinglePlayer)
{
var msg = GetPacket();
msg.Write((byte)ExpertMessageType.SyncDifficulty);
msg.Write(difficulty);
msg.Send(ignoreClient: ignoreClient);
}
}
public static void HookDifficultyMode(int difficulty)
{
if (difficulty == 0 || difficulty > 2)
{
FieldInfo expert = typeof(Main)
.GetField("_overrideForExpertMode", BindingFlags.Static | BindingFlags.NonPublic);
expert.SetValue(null, false);
FieldInfo master = typeof(Main)
.GetField("_overrideForMasterMode", BindingFlags.Static | BindingFlags.NonPublic);
master.SetValue(null, false);
}
else if (difficulty == 1)
{
FieldInfo expert = typeof(Main)
.GetField("_overrideForExpertMode", BindingFlags.Static | BindingFlags.NonPublic);
expert.SetValue(null, true);
FieldInfo master = typeof(Main)
.GetField("_overrideForMasterMode", BindingFlags.Static | BindingFlags.NonPublic);
master.SetValue(null, false);
}
else if (difficulty == 2)
{
FieldInfo expert = typeof(Main)
.GetField("_overrideForExpertMode", BindingFlags.Static | BindingFlags.NonPublic);
expert.SetValue(null, true);
FieldInfo master = typeof(Main)
.GetField("_overrideForMasterMode", BindingFlags.Static | BindingFlags.NonPublic);
master.SetValue(null, true);
}
}
public void SetDifficultyMode(int difficulty)
{
if (difficulty > 2)
{
difficulty = 0;
}
if (Main.expertMode && difficulty == 0)
{
Main.NewText(Language.GetTextValue("Mods.BossExpertise.NowNormalMode"));
}
else if (!Main.expertMode && difficulty == 1)
{
Main.NewText(Language.GetTextValue("Mods.BossExpertise.NowExpertMode"), 255, 50, 50);
}
else if (!Main.masterMode && difficulty == 2)
{
Main.NewText(Language.GetTextValue("Mods.BossExpertise.NowMasterMode"), 255, 50, 50);
}
else if (!Main.expertMode && difficulty == 0)
{
Main.NewText(Language.GetTextValue("Mods.BossExpertise.AlreadyNormalMode"));
}
else if (Main.expertMode && difficulty == 1)
{
Main.NewText(Language.GetTextValue("Mods.BossExpertise.AlreadyExpertMode"), 255, 50, 50);
}
else if (!Main.masterMode && difficulty == 2)
{
Main.NewText(Language.GetTextValue("Mods.BossExpertise.AlreadyMasterMode"), 255, 50, 50);
}
else
{
Log("Something went wrong in BossExpertise: " + CurrentDifficulty);
return;
}
SyncDifficultyMode(difficulty);
ActualDifficulty = difficulty;
}
public static void Log(object message)
{
ModContent.GetInstance<BossExpertise>().Logger.Info(message);
}
}
}