-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathITD.cs
286 lines (246 loc) · 10.9 KB
/
ITD.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
global using Microsoft.Xna.Framework;
global using Terraria;
global using Terraria.ID;
global using Terraria.ModLoader;
global using ReLogic.Content;
global using Microsoft.Xna.Framework.Graphics;
using ITD.Networking;
using System.IO;
using ITD.Systems;
using Terraria.Graphics.Effects;
using ITD.Skies;
using Terraria.Graphics.Shaders;
using System.Collections.Generic;
using ITD.Systems.Recruitment;
using ITD.Config;
using Terraria.UI.Chat;
using ITD.Common.ChatTags;
using System.Text;
using ITD.Particles;
namespace ITD
{
public class ITD : Mod
{
public static ITD Instance;
public ITD() => Instance = this;
public const string BlankTexture = "ITD/Content/BlankTexture";
public const string MiscShadersFolderPath = "Shaders/MiscShaders/";
public const string ArmorShadersFolderPath = "Shaders/ArmorShaders/";
public const string ScreenShadersFolderPath = "Shaders/ScreenShaders/";
public const string MetaballsShadersFolderPath = "Shaders/MetaballsShaders/";
public static readonly Dictionary<string, ArmorShaderData> ITDArmorShaders = [];
public static readonly Dictionary<string, MetaballShaderData> ITDMetaBallsShaders = [];
internal Mod itdMusic = null;
internal Mod wikithis = null;
internal Mod bossChecklist = null;
internal Mod munchies = null;
internal Mod achievements = null;
internal Mod dialogueTweak = null; // this is necessary so the recruitment button doesn't screw up when this mod is on
public static ITDServerConfig ServerConfig => ModContent.GetInstance<ITDServerConfig>();
public static ITDClientConfig ClientConfig => ModContent.GetInstance<ITDClientConfig>();
public int? GetMusic(string trackName)
{
return itdMusic != null ? MusicLoader.GetMusicSlot(itdMusic, "Music/" + trackName) : null;
}
public override void PostSetupContent()
{
if (ModLoader.TryGetMod("DialogueTweak", out Mod dialogueTweak))
{
dialogueTweak.Call("OnPostPortraitDraw", DrawSomething);
}
ExternalModSupport.Init();
if (!Main.dedServ)
LoadRecruitmentTextures();
}
public override object Call(params object[] args) => ModCalls.Call(args);
public override void HandlePacket(BinaryReader reader, int whoAmI) => NetSystem.HandlePacket(reader, whoAmI);
public static void LoadShader(string name, string path)
{
Asset<Effect> screen = ModContent.Request<Effect>(path, AssetRequestMode.ImmediateLoad);
Filters.Scene[name] = new Filter(new ScreenShaderData(screen, name + "Pass"), EffectPriority.High);
Filters.Scene[name].Load();
}
//public static ArmorShaderData LoadArmorShader(string name, string path, string? uImage = null)
//{
// Asset<Texture2D> overlay = null;
// if (uImage != null)
// overlay = ModContent.Request<Texture2D>(uImage, AssetRequestMode.ImmediateLoad);
// ArmorShaderData data = new(ModContent.Request<Effect>(path, AssetRequestMode.ImmediateLoad), name + "Pass");
// if (overlay != null)
// data = data.UseImage(overlay);
// ITDArmorShaders[name] = data;
// return data;
//}
public void LoadMiscShaders()
{
if (Main.netMode != NetmodeID.Server)
{
foreach (string path in GetFileNames())
{
if (!path.StartsWith(MiscShadersFolderPath) || !path.EndsWith(".xnb"))
continue;
StringBuilder sb = new StringBuilder();
sb.Append(path);
sb.Remove(0, MiscShadersFolderPath.Length);
sb.Replace(".xnb", "");
string shaderName = sb.ToString();
GameShaders.Misc[shaderName] = new MiscShaderData(ModContent.Request<Effect>(this.Name + "/" + MiscShadersFolderPath + shaderName), shaderName + "Pass");
}
}
}
public void LoadArmorShadersOverlays()
{
foreach(string shaderName in ITDArmorShaders.Keys)
{
Asset<Texture2D> overlay = null;
foreach (string overlayPath in GetFileNames())
{
if (!overlayPath.StartsWith(ArmorShadersFolderPath) || !overlayPath.EndsWith(".rawimg") || !overlayPath.Contains(shaderName))
continue;
StringBuilder sb2 = new StringBuilder();
sb2.Append(overlayPath);
sb2.Remove(0, ArmorShadersFolderPath.Length);
sb2.Replace(".rawimg","");
string overlayName = sb2.ToString();
overlay = ModContent.Request<Texture2D>(this.Name + "/" + ArmorShadersFolderPath + overlayName, AssetRequestMode.ImmediateLoad);
}
if (overlay != null)
ITDArmorShaders[shaderName].UseImage(overlay);
}
}
public void LoadArmorShaders()
{
if (Main.netMode != NetmodeID.Server)
{
foreach (string path in GetFileNames())
{
if (!path.StartsWith(ArmorShadersFolderPath) || !path.EndsWith(".xnb"))
continue;
StringBuilder sb = new StringBuilder();
sb.Append(path);
sb.Remove(0, ArmorShadersFolderPath.Length);
sb.Replace(".xnb", "");
string shaderName = sb.ToString();
ITDArmorShaders[shaderName] = new ArmorShaderData(ModContent.Request<Effect>(this.Name + "/" + ArmorShadersFolderPath + shaderName), shaderName + "Pass");
}
}
}
public void LoadScreenShaders()
{
if (Main.netMode != NetmodeID.Server)
{
foreach (string path in GetFileNames())
{
if (!path.StartsWith(ScreenShadersFolderPath) || !path.EndsWith(".xnb"))
continue;
StringBuilder sb = new StringBuilder();
sb.Append(path);
sb.Remove(0, ScreenShadersFolderPath.Length);
sb.Replace(".xnb", "");
string shaderName = sb.ToString();
Asset<Effect> screen = ModContent.Request<Effect>(this.Name + "/" + ScreenShadersFolderPath + shaderName, AssetRequestMode.ImmediateLoad);
Filters.Scene[shaderName] = new Filter(new ScreenShaderData(screen, shaderName + "Pass"), EffectPriority.High);
Filters.Scene[shaderName].Load();
}
}
}
public void LoadMetaballsShaders()
{
if (Main.netMode != NetmodeID.Server)
{
foreach (string path in GetFileNames())
{
if (!path.StartsWith(MetaballsShadersFolderPath) || !path.EndsWith(".xnb"))
continue;
StringBuilder sb = new StringBuilder();
sb.Append(path);
sb.Remove(0, MetaballsShadersFolderPath.Length);
sb.Replace(".xnb", "");
string shaderName = sb.ToString();
ITDMetaBallsShaders[shaderName] = new MetaballShaderData(ModContent.Request<Effect>(this.Name + "/" + MetaballsShadersFolderPath + shaderName));
}
}
}
public void PreAssignShadersProperties()
{
}
public override void Load()
{
SkyManager.Instance["ITD:CosjelOkuuSky"] = new CosjelOkuuSky();
//LoadShader("BlackMold", "ITD/Shaders/MelomycosisScreen");
LoadMiscShaders();
LoadScreenShaders();
LoadArmorShaders();
LoadArmorShadersOverlays();
LoadMetaballsShaders();
PreAssignShadersProperties();
itdMusic = null;
wikithis = null;
bossChecklist = null;
munchies = null;
achievements = null;
dialogueTweak = null;
ModLoader.TryGetMod("ITDMusic", out itdMusic);
ModLoader.TryGetMod("Wikithis", out wikithis);
ModLoader.TryGetMod("BossChecklist", out bossChecklist);
ModLoader.TryGetMod("Munchies", out munchies);
ModLoader.TryGetMod("TMLAchievements", out achievements);
ModLoader.TryGetMod("DialogueTweak", out dialogueTweak);
if (!Main.dedServ)
{
wikithis?.Call("AddModURL", this, "https://itdmod.fandom.com/wiki/{}");
}
ChatManager.Register<WavyHandler>(
[
"mvsin",
"mvsine",
"mvwave"
]);
ChatManager.Register<ShakyHandler>(
[
"mvshake"
]);
}
/// <summary>
/// I DON'T LIKE THE FLICKER THEY DO WHEN THEY'RE FIRST RECRUITED
/// </summary>
private void LoadRecruitmentTextures()
{
int[] canBeRecruited = TownNPCRecruitmentLoader.NPCsThatCanBeRecruited;
foreach (int i in canBeRecruited)
{
string path = $"ITD/Systems/Recruitment/{nameof(RecruitedNPC)}_{i}";
LoadRecruitmentTexture(path, i);
}
// "so what about modded NPCs?"
// this logic is handled in the Mod.Call to register a new NPC
}
public static void LoadRecruitmentTexture(string path, int i)
{
// load regular texture
ModContent.Request<Texture2D>(path);
// load shimmer texture if it exists (note: some mods might choose not to add a shimmer texture. in this case, use ModContent.RequestIfExists
// if an NPC is shimmered but there's no shimmer texture, it'll be automatically handled in the drawcode, so we don't have to worry about that
if (NPCID.Sets.ShimmerTownTransform[i])
ModContent.RequestIfExists<Texture2D>(path + "_Shimmer", out _);
}
private void DrawSomething(SpriteBatch sb, Color textColor, Rectangle panel)
{
var tex = ModContent.Request<Texture2D>("ITD/Effects/ClassicLifeOverlay");
sb.Draw(tex.Value, panel.Location.ToVector2(), Main.DiscoColor);
}
public override void Unload()
{
foreach (MetaballShaderData s in ITDMetaBallsShaders.Values)
s.Dispose();
ITDArmorShaders?.Clear();
itdMusic = null;
wikithis = null;
bossChecklist = null;
munchies = null;
achievements = null;
dialogueTweak = null;
Instance = null;
}
}
}