-
Notifications
You must be signed in to change notification settings - Fork 0
/
NoxiumMod.cs
384 lines (318 loc) · 11.8 KB
/
NoxiumMod.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
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using NoxiumMod.UI;
using NoxiumMod.UI.Dimensions;
using NoxiumMod.Dimensions;
using System;
using System.Collections;
using System.Collections.Generic;
using SubworldLibrary;
using System.Linq;
using System.Reflection;
using Terraria;
using Terraria.Graphics;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.UI;
using static Terraria.ModLoader.ModContent;
using NoxiumMod.UI.Subworld;
using NoxiumMod.Dimensions.Bubbles;
using NoxiumMod.UI.Computer;
using System.Runtime.Remoting.Messaging;
namespace NoxiumMod
{
public class NoxiumMod : Mod
{
public static NoxiumMod noxiumInstance;
public static ModHotKey SeedHotkey;
private AhmBar AhmUI;
internal UserInterface AHMUiInterface;
private DimensionalUI dimensionalUI;
internal UserInterface dimensionalInterface;
internal ComputerUIState computerUI; // gotta access this in games
internal UserInterface computerInterface;
public static float shakeAmount = 0;
public static int ShakeTimer;
public bool doingBarrelRoll;
private float barrelRollRotation;
private FieldInfo vanillaScreenMatrix;
private FieldInfo vanillaUIMatrix;
public override void Load()
{
noxiumInstance = GetInstance<NoxiumMod>();
vanillaScreenMatrix = typeof(SpriteViewMatrix).GetField("_transformationMatrix", BindingFlags.NonPublic | BindingFlags.Instance);
vanillaUIMatrix = typeof(Main).GetField("_uiScaleMatrix", BindingFlags.NonPublic | BindingFlags.Static);
On.Terraria.Graphics.SpriteViewMatrix.ShouldRebuild += (On.Terraria.Graphics.SpriteViewMatrix.orig_ShouldRebuild orig, SpriteViewMatrix self) =>
{
if (doingBarrelRoll)
{
return false;
}
return orig(self);
};
ComputerUI.PleaseForTheLoveOfGodDontOpenChatWhenIPressEnter();
HitboxesGlobalItem.meleeHitbox = new Rectangle?[256];
SeedHotkey = RegisterHotKey("Seed Fruit", "C");
if (!Main.dedServ)
{
AhmUI = new AhmBar();
AHMUiInterface = new UserInterface();
AHMUiInterface.SetState(AhmUI);
dimensionalUI = new DimensionalUI();
dimensionalUI.LoadUI();
dimensionalUI.Activate();
computerInterface = new UserInterface();
computerUI = new ComputerUIState();
computerUI.Activate();
JoiningUI.LoadLoadingSymbol();
PlasmaDesert.LoadBubbleTextures();
/* Examples:
dimensionalUI.RegisterDimension("The Cum Zone", ModContent.GetTexture("Terraria/Item_2"), () => Main.dayTime, () => Main.NewText("Welcome to the cum zone"));
// Appears as 'The Cum Zone', shows a dirt block texture, only appears in the day, when clicked will say 'Welcome to the cum zone'.
dimensionalUI.RegisterDimension("Hell", ModContent.GetTexture("Terraria/Item_1"), () => !Main.dayTime, () => Main.NewText("Welcome to hell"));
// Appears as 'Hell', shows an iron pickaxe texture, only appears at night, when clicked will say 'Welcome to hell'.
Call("AddDimension", "The Cum Zone", ModContent.GetTexture("Terraria/Item_2"), (Func<bool>)(() => Main.dayTime), (Action)(() => Main.NewText("Welcome to the cum zone")));
// Example of a mod.Call to add a dimension.
*/
// Gaming
dimensionalUI.RegisterDimension("Plasma Desert", ModContent.GetTexture("NoxiumMod/PlasmaDesert"), () => true, () => Subworld.Enter<PlasmaDesert>());
dimensionalUI.RegisterDimension("The Cum Zone", ModContent.GetTexture("Terraria/Item_2"), () => true, () => Main.NewText("Welcome to the cum zone"));
dimensionalInterface = new UserInterface();
}
Mod yabhb = ModLoader.GetMod("FKBossHealthBar");
if (yabhb != null)
{
yabhb.Call("hbStart");
yabhb.Call("hbSetTexture", GetTexture("UI/AhmHealthStart"), GetTexture("UI/AhmHealthMid"), GetTexture("UI/AhmHealthEnd"), GetTexture("UI/AhmHealthFill"));
yabhb.Call("hbFinishSingle", NPCType("AncientHealingMachine"));
}
}
public override void Unload()
{
Type[] types = noxiumInstance.Code.GetTypes(); // Automatically sets all static fields to null, so you don't have to worry about it, ever.
foreach (Type type in types)
{
foreach (FieldInfo item in from field in type.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)
where !field.FieldType.IsValueType && !field.IsLiteral
select field)
{
if (item.FieldType.IsGenericType)
{
if (item.FieldType.GetGenericTypeDefinition() == typeof(List<>))
{
((IList)item.GetValue(null))?.Clear();
}
else if (item.FieldType.GetGenericTypeDefinition() == typeof(Dictionary<,>))
{
((IDictionary)item.GetValue(null))?.Clear();
}
}
else if (!item.FieldType.ContainsGenericParameters)
{
item.SetValue(null, null);
}
}
}
}
public override object Call(params object[] args)
{
Array.Resize(ref args, 5);
if (args[0] is string callType)
{
if (callType == "AddDimension" && args[1] is string name && args[2] is Texture2D texture && args[3] is Func<bool> func && args[4] is Action action && !Main.dedServ)
{
dimensionalUI.RegisterDimension(name, texture, func, action);
}
}
return base.Call(args);
}
public override void UpdateUI(GameTime gameTime)
{
AHMUiInterface?.Update(gameTime);
dimensionalInterface?.Update(gameTime);
computerInterface?.Update(gameTime);
}
public override void ModifyInterfaceLayers(List<GameInterfaceLayer> layers)
{
int mouseTextIndex = layers.FindIndex(layer => layer.Name.Equals("Vanilla: Mouse Text"));
if (mouseTextIndex != -1)
{
layers.Insert(mouseTextIndex, new LegacyGameInterfaceLayer("NoxiumMod: Vanilla Stack Reproduction", delegate
{
Main.LocalPlayer.GetModPlayer<NoxiumPlayer>().SetSeedStackDelays();
return true;
}, InterfaceScaleType.UI));
layers.Insert(mouseTextIndex, new LegacyGameInterfaceLayer("NoxiumMod: Turtle UI", delegate
{
computerInterface.Draw(Main.spriteBatch, new GameTime());
return true;
}, InterfaceScaleType.UI));
}
int resourceBarIndex = layers.FindIndex(layer => layer.Name.Equals("Vanilla: Resource Bars"));
if (resourceBarIndex != -1)
{
layers.Insert(resourceBarIndex, new LegacyGameInterfaceLayer("NoxiumMod: AHM Bar", delegate
{
AHMUiInterface.Draw(Main.spriteBatch, new GameTime());
return true;
}, InterfaceScaleType.UI));
layers.Insert(resourceBarIndex, new LegacyGameInterfaceLayer("NoxiumMod: Dimension Selector", delegate
{
dimensionalInterface.Draw(Main.spriteBatch, new GameTime());
return true;
}, InterfaceScaleType.UI));
}
}
public static void ShakeScreen(float AmountOfShake, int Time)
{
ShakeTimer = Time;
shakeAmount = AmountOfShake;
}
public override void ModifyTransformMatrix(ref SpriteViewMatrix Transform)
{
Player player = Main.LocalPlayer;
//Cant shake main menu, :widepeeposad:
//We'll see about that - goodpro
//We certainly will - Oli
if (!Main.gameMenu)
{
if (shakeAmount != 0 && ShakeTimer != 0)
{
ShakeTimer--;
Vector2 Shakey = new Vector2(player.Center.X + Main.rand.NextFloat(shakeAmount), player.Center.Y + Main.rand.NextFloat(shakeAmount)) - new Vector2(Main.screenWidth / 2, Main.screenHeight / 2);
Main.screenPosition = Shakey;
}
}
if (doingBarrelRoll)
{
barrelRollRotation += 1.75f;
if (barrelRollRotation >= 360)
{
barrelRollRotation = 0;
vanillaScreenMatrix.SetValue(Transform, Matrix.CreateRotationZ(0));
vanillaUIMatrix.SetValue(Main.instance, Matrix.CreateRotationZ(0));
doingBarrelRoll = false;
return;
}
Matrix rotation = Matrix.CreateRotationZ(MathHelper.ToRadians(barrelRollRotation));
Matrix translation = Matrix.CreateTranslation(new Vector3(Main.screenWidth / 2, Main.screenHeight / 2, 0));
Matrix translation2 = Matrix.CreateTranslation(new Vector3(Main.screenWidth / -2, Main.screenHeight / -2, 0));
vanillaScreenMatrix.SetValue(Transform, translation2 * rotation * translation);
vanillaUIMatrix.SetValue(Main.instance, translation2 * rotation * translation);
}
}
public override void AddRecipes()
{
// ew
// :( -Daim
ModRecipe recipe = new ModRecipe(this);
recipe.AddIngredient(ItemID.StrangePlant3, 1);
recipe.AddIngredient(ItemID.BottledWater, 1);
recipe.AddTile(TileID.DyeVat);
recipe.SetResult(ItemID.AcidDye, 1);
recipe.AddRecipe();
recipe = new ModRecipe(this);
recipe.AddIngredient(ItemID.StrangePlant3, 1);
recipe.AddIngredient(ItemID.BottledWater, 1);
recipe.AddTile(TileID.DyeVat);
recipe.SetResult(ItemID.BlueAcidDye, 1);
recipe.AddRecipe();
recipe = new ModRecipe(this);
recipe.AddIngredient(ItemID.StrangePlant4, 1);
recipe.AddIngredient(ItemID.BottledWater, 1);
recipe.AddTile(TileID.DyeVat);
recipe.SetResult(ItemID.RedAcidDye, 1);
recipe.AddRecipe();
recipe = new ModRecipe(this);
recipe.AddIngredient(ItemID.StrangePlant1, 1);
recipe.AddIngredient(ItemID.BottledWater, 1);
recipe.AddTile(TileID.DyeVat);
recipe.SetResult(ItemID.MushroomDye, 1);
recipe.AddRecipe();
recipe = new ModRecipe(this);
recipe.AddIngredient(ItemID.StrangePlant2, 1);
recipe.AddIngredient(ItemID.BottledWater, 1);
recipe.AddTile(TileID.DyeVat);
recipe.SetResult(ItemID.MirageDye, 1);
recipe.AddRecipe();
recipe = new ModRecipe(this);
recipe.AddIngredient(ItemID.StrangePlant1, 1);
recipe.AddIngredient(ItemID.BottledWater, 1);
recipe.AddTile(TileID.DyeVat);
recipe.SetResult(ItemID.NegativeDye, 1);
recipe.AddRecipe();
recipe = new ModRecipe(this);
recipe.AddIngredient(ItemID.StrangePlant1, 1);
recipe.AddIngredient(ItemID.BottledWater, 1);
recipe.AddTile(TileID.DyeVat);
recipe.SetResult(ItemID.PurpleOozeDye, 1);
recipe.AddRecipe();
recipe = new ModRecipe(this);
recipe.AddIngredient(ItemID.StrangePlant2, 1);
recipe.AddIngredient(ItemID.BottledWater, 1);
recipe.AddTile(TileID.DyeVat);
recipe.SetResult(ItemID.ReflectiveDye, 1);
recipe.AddRecipe();
recipe = new ModRecipe(this);
recipe.AddIngredient(ItemID.StrangePlant2, 1);
recipe.AddIngredient(ItemID.BottledWater, 1);
recipe.AddTile(TileID.DyeVat);
recipe.SetResult(ItemID.ReflectiveCopperDye, 1);
recipe.AddRecipe();
recipe = new ModRecipe(this);
recipe.AddIngredient(ItemID.StrangePlant2, 1);
recipe.AddIngredient(ItemID.BottledWater, 1);
recipe.AddTile(TileID.DyeVat);
recipe.SetResult(ItemID.ReflectiveGoldDye, 1);
recipe.AddRecipe();
recipe = new ModRecipe(this);
recipe.AddIngredient(ItemID.StrangePlant1, 1);
recipe.AddIngredient(ItemID.BottledWater, 1);
recipe.AddTile(TileID.DyeVat);
recipe.SetResult(ItemID.ReflectiveObsidianDye, 1);
recipe.AddRecipe();
recipe = new ModRecipe(this);
recipe.AddIngredient(ItemID.StrangePlant2, 1);
recipe.AddIngredient(ItemID.BottledWater, 1);
recipe.AddTile(TileID.DyeVat);
recipe.SetResult(ItemID.ReflectiveMetalDye, 1);
recipe.AddRecipe();
recipe = new ModRecipe(this);
recipe.AddIngredient(ItemID.StrangePlant2, 1);
recipe.AddIngredient(ItemID.BottledWater, 1);
recipe.AddTile(TileID.DyeVat);
recipe.SetResult(ItemID.ReflectiveSilverDye, 1);
recipe.AddRecipe();
recipe = new ModRecipe(this);
recipe.AddIngredient(ItemID.StrangePlant1, 1);
recipe.AddIngredient(ItemID.BottledWater, 1);
recipe.AddTile(TileID.DyeVat);
recipe.SetResult(ItemID.ShadowDye, 1);
recipe.AddRecipe();
}
public void ToggleDimensionalUI()
{
if (dimensionalInterface.CurrentState == null)
{
dimensionalUI.Enable();
}
else
{
dimensionalUI.Disable();
}
}
public void ToggleComputerUI()
{
if (computerInterface.CurrentState == null)
{
Main.PlaySound(SoundID.MenuOpen);
computerInterface.SetState(computerUI);
}
else
{
Main.PlaySound(SoundID.MenuClose);
computerInterface.SetState(null);
}
}
}
}