-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
CheatSheet.cs
634 lines (558 loc) · 22.8 KB
/
CheatSheet.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
using CheatSheet.Menus;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Newtonsoft.Json;
using ReLogic.Content;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Net;
using Terraria;
using Terraria.Chat;
using Terraria.ID;
using Terraria.Localization;
using Terraria.ModLoader;
// TODO: move windows below inventory
// TODO: Filter recipes with unobtainables.
// TODO: debugmode, stat menu (from CMM)
// netMode 0 single player, netMode 1 multiplayer, netMode 2 Server
// netMode type 21 sync Main.item
namespace CheatSheet
{
internal class CheatSheet : Mod
{
internal static ModKeybind ToggleCheatSheetHotbarHotKey;
internal static CheatSheet instance;
//internal static Dictionary<string, ModTranslation> translations; // reference to private field.
internal Hotbar hotbar;
internal ItemBrowser itemBrowser;
internal NPCBrowser npcBrowser;
internal RecipeBrowserWindow recipeBrowser;
internal ExtendedCheatMenu extendedCheatMenu;
internal PaintToolsHotbar paintToolsHotbar;
internal PaintToolsUI paintToolsUI;
internal QuickTeleportHotbar quickTeleportHotbar;
internal QuickClearHotbar quickClearHotbar;
internal NPCButchererHotbar npcButchererHotbar;
internal EventManagerHotbar eventManagerHotbar;
internal Dictionary<string, bool> herosPermissions = new Dictionary<string, bool>();
internal const string ModifySpawnRateMultiplier_Permission = "ModifySpawnRateMultiplier";
internal const string ModifySpawnRateMultiplier_Display = "Modify Spawn Rate Multiplier";
internal const string PaintTools_Permission = "PaintTools";
internal const string PaintTools_Display = "Paint Tools";
internal const string RecipeBrowser_Permission = "RecipeBrowser";
internal const string RecipeBrowser_Display = "Recipe Browser";
internal const string MinionBooster_Permission = "MinionBooster";
internal const string MinionBooster_Display = "Minion Booster";
internal const string ClearItemNPCProjectile_Permission = "ClearItemNPCProjectile";
internal const string ClearItemNPCProjectile_Display = "Clear Item NPC Projectile";
internal const string ExtraAccessories_Permission = "ExtraAccessories";
internal const string ExtraAccessories_Display = "Extra Accessories";
internal const string Vacuum_Permission = "Vacuum";
internal const string Vacuum_Display = "Vacuum";
internal const string NPCButcher_Permission = "NPCButcher";
internal const string NPCButcher_Display = "NPC Butcher";
internal const string CheatSheetExtensions_Permission = "CheatSheetExtensions";
internal const string CheatSheetExtensions_Display = "Cheat Sheet Extensions";
internal const string QuickTeleport_Permission = "QuickTeleport";
internal const string QuickTeleport_Display = "Quick Teleport";
internal const int DefaultNumberOnlineToLoad = 30;
public int numberOnlineToLoad = 0;
public CheatSheet() {
}
// to do: debugmode, stat
public override void Load() {
// Since we are using hooks not in older versions, and since ItemID.Count changed, we need to do this.
if (BuildInfo.tMLVersion < new Version(0, 11, 5)) {
throw new Exception("\nThis mod uses functionality only present in the latest tModLoader. Please update tModLoader to use this mod\n\n");
}
instance = this;
ButtonClicked.Clear();
ButtonTexture.Clear();
ButtonTooltip.Clear();
ToggleCheatSheetHotbarHotKey = KeybindLoader.RegisterKeybind(this, "ToggleCheatSheetHotbar", "K");
if (Main.rand == null) {
Main.rand = new Terraria.Utilities.UnifiedRandom();
}
//FieldInfo translationsField = typeof(LocalizationLoader).GetField("translations", BindingFlags.Static | BindingFlags.NonPublic);
//translations = (Dictionary<string, ModTranslation>)translationsField.GetValue(this);
//LoadTranslations();
// set all to true on load
herosPermissions[PaintTools_Permission] = true;
herosPermissions[ModifySpawnRateMultiplier_Permission] = true;
herosPermissions[RecipeBrowser_Permission] = true;
herosPermissions[MinionBooster_Permission] = true;
herosPermissions[ClearItemNPCProjectile_Permission] = true;
herosPermissions[ExtraAccessories_Permission] = true;
herosPermissions[Vacuum_Permission] = true;
herosPermissions[NPCButcher_Permission] = true;
herosPermissions[CheatSheetExtensions_Permission] = true;
herosPermissions[QuickTeleport_Permission] = true;
}
public override void Unload() {
ButtonClicked.Clear();
ButtonTexture.Clear();
ButtonTooltip.Clear();
PaintToolsSlot.CurrentSelect = null;
AllItemsMenu.singleSlotArray = null;
UI.UICheckbox.checkboxTexture = null;
UI.UICheckbox.checkmarkTexture = null;
UI.UIScrollBar.ScrollbarTexture = null;
UI.UIScrollView.ScrollbgTexture = null;
UI.UITextbox.textboxBackground = null;
//UI.UIView.closeTexture = null;
ItemBrowser.UnloadStatic();
NPCBrowser.UnloadStatic();
RecipeBrowserWindow.UnloadStatic();
if (itemBrowser != null)
itemBrowser.itemView = null;
itemBrowser = null;
npcBrowser = null;
recipeBrowser = null;
if (hotbar != null) {
hotbar.buttonView?.RemoveAllChildren();
hotbar.buttonView = null;
hotbar = null;
}
instance = null;
ToggleCheatSheetHotbarHotKey = null;
RecipeBrowserWindow.recipeView = null;
RecipeBrowserWindow.lookupItemSlot = null;
ConfigurationTool.cheatSheet = null;
ConfigurationTool.configurationWindow = null;
Hotbar.loginTexture = null;
Hotbar.logoutTexture = null;
ConfigurationTool.button = null;
SpawnRateMultiplier.button = null;
MinionSlotBooster.button = null;
LightHack.UnloadStatic();
GodMode.UnloadStatic();
}
internal static string CSText(string category, string key) {
return Language.GetTextValue($"Mods.CheatSheet.{category}.{key}");
//return translations[$"Mods.CheatSheet.{category}.{key}"].GetTranslation(Language.ActiveCulture);
// This isn't good until after load....can revert after fixing static initializers for string[]
// return Language.GetTextValue($"Mods.CheatSheet.{category}.{key}");
}
/*
private void LoadTranslations()
{
var modTranslationDictionary = new Dictionary<string, ModTranslation>();
var translationFiles = new List<string>();
foreach (var item in File)
{
if (item.Key.StartsWith("Localization"))
translationFiles.Add(item.Key);
}
foreach (var translationFile in translationFiles)
{
string translationFileContents = System.Text.Encoding.UTF8.GetString(GetFileBytes(translationFile));
GameCulture culture = GameCulture.FromName(Path.GetFileNameWithoutExtension(translationFile));
Dictionary<string, Dictionary<string, string>> dictionary = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, string>>>(translationFileContents);
foreach (KeyValuePair<string, Dictionary<string, string>> category in dictionary)
foreach (KeyValuePair<string, string> kvp in category.Value)
{
ModTranslation mt;
string key = category.Key + "." + kvp.Key;
if (!modTranslationDictionary.TryGetValue(key, out mt))
modTranslationDictionary[key] = mt = CreateTranslation(key);
mt.AddTranslation(culture, kvp.Value);
}
}
foreach (var value in modTranslationDictionary.Values)
{
AddTranslation(value);
}
}
*/
//public override void PreSaveAndQuit()
//{
// SpawnRateMultiplier.HasPermission = true;
// CheatSheet.instance.hotbar.ChangedConfiguration();
//}
public override void PostSetupContent() {
ConfigurationLoader.Initialized();
try {
if (ModLoader.TryGetMod("HEROsMod", out Mod herosMod)) {
SetupHEROsModIntegration(herosMod);
}
}
catch (Exception e) {
Logger.Error("CheatSheet->HEROsMod PostSetupContent Error: " + e.StackTrace + e.Message);
}
}
private void SetupHEROsModIntegration(Mod herosMod) {
// Add Permissions always.
herosMod.Call(
// Special string
"AddPermission",
// Permission Name
ModifySpawnRateMultiplier_Permission,
// Permission Display Name
ModifySpawnRateMultiplier_Display
);
// Add Buttons only to non-servers (otherwise the server will crash, since textures aren't loaded on servers)
if (!Main.dedServ) {
herosMod.Call(
// Special string
"AddSimpleButton",
// Name of Permission governing the availability of the button/tool
ModifySpawnRateMultiplier_Permission,
// Texture of the button. 38x38 is recommended for HERO's Mod. Also, a white outline on the icon similar to the other icons will look good.
ModUtils.GetItemTexture(ItemID.WaterCandle),
// A method that will be called when the button is clicked
(Action)SpawnRateMultiplier.HEROsButtonPressed,
// A method that will be called when the player's permissions have changed
(Action<bool>)SpawnRateMultiplier.HEROsPermissionChanged,
// A method that will be called when the button is hovered, returning the Tooltip
(Func<string>)SpawnRateMultiplier.HEROsTooltip
);
}
// Other non-tutorial permissions.
// For simplicity, not doing buttons in Heros, just permissions for most tools.
// Could implement most without sub-menus as buttons if I have time. Right and left click support in Heros desireable.
var permissions = new List<ValueTuple<string, string>>() {
(PaintTools_Permission, PaintTools_Display),
(RecipeBrowser_Permission, RecipeBrowser_Display),
(MinionBooster_Permission,MinionBooster_Display),
(ClearItemNPCProjectile_Permission,ClearItemNPCProjectile_Display),
(ExtraAccessories_Permission,ExtraAccessories_Display),
(Vacuum_Permission,Vacuum_Display),
(NPCButcher_Permission,NPCButcher_Display),
(CheatSheetExtensions_Permission,CheatSheetExtensions_Display),
(QuickTeleport_Permission,QuickTeleport_Display),
};
foreach (var permission in permissions) {
herosMod.Call("AddPermission", permission.Item1, permission.Item2, (Action<bool>)((hasPermission) => HEROsPermissionChanged(permission.Item1, hasPermission)));
}
}
public void HEROsPermissionChanged(string permission, bool hasPermission) {
herosPermissions[permission] = hasPermission;
// This is called a bunch at once, a little wasteful.
CheatSheet.instance.hotbar.ChangedConfiguration();
}
public void SetupUI() {
//System.Collections.Concurrent.ConcurrentQueue<Action> glQueue = (System.Collections.Concurrent.ConcurrentQueue<Action>)typeof(Terraria.ModLoader.Engine.GLCallLocker).GetField("actionQueue", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null);
//glQueue.Enqueue(() =>
//{
if (!Main.dedServ) {
//for (int i = 0; i < ItemLoader.ItemCount; i++)
//{
// Main.instance.LoadItem(i);
//}
try {
ItemBrowser.LoadStatic();
itemBrowser = new ItemBrowser(this);
itemBrowser.SetDefaultPosition(new Vector2(80, 300));
itemBrowser.Visible = false;
NPCBrowser.LoadStatic();
npcBrowser = new NPCBrowser(this);
npcBrowser.SetDefaultPosition(new Vector2(30, 180));
npcBrowser.Visible = false;
RecipeBrowserWindow.LoadStatic();
recipeBrowser = new RecipeBrowserWindow(this);
recipeBrowser.SetDefaultPosition(new Vector2(30, 180));
recipeBrowser.Visible = false;
extendedCheatMenu = new ExtendedCheatMenu(this);
extendedCheatMenu.SetDefaultPosition(new Vector2(120, 180));
extendedCheatMenu.Visible = false;
paintToolsHotbar = new PaintToolsHotbar(this);
// paintToolsHotbar.SetDefaultPosition(new Microsoft.Xna.Framework.Vector2(120, 180));
paintToolsHotbar.Visible = false;
paintToolsHotbar.Hide();
paintToolsUI = new PaintToolsUI(this);
paintToolsUI.SetDefaultPosition(new Vector2(30, 180));
paintToolsUI.Visible = false;
quickTeleportHotbar = new QuickTeleportHotbar(this);
quickTeleportHotbar.Visible = false;
quickTeleportHotbar.Hide();
quickClearHotbar = new QuickClearHotbar(this);
quickClearHotbar.Visible = false;
quickClearHotbar.Hide();
npcButchererHotbar = new NPCButchererHotbar(this);
npcButchererHotbar.Visible = false;
npcButchererHotbar.Hide();
//eventManagerHotbar = new EventManagerHotbar(this);
//eventManagerHotbar.Visible = false;
//eventManagerHotbar.Hide();
LightHack.LoadStatic(); //Has to be before new Hotbar()
GodMode.LoadStatic(); //Has to be before new Hotbar()
hotbar = new Hotbar(this);
//hotbar.Position = new Microsoft.Xna.Framework.Vector2(120, 180);
hotbar.Visible = true;
if (!ModContent.GetInstance<CheatSheetClientConfig>().HotbarShownByDefault)
hotbar.Hide();
else
hotbar.Show();
}
catch (Exception e) {
Logger.Error(e.ToString());
}
}
//});
}
public static bool IsPlayerLocalServerOwner(Player player) {
if (Main.netMode == 1) {
return Netplay.Connection.Socket.GetRemoteAddress().IsLocalHost();
}
for (int plr = 0; plr < Main.maxPlayers; plr++)
if (Netplay.Clients[plr].State == 10 && Main.player[plr] == player && Netplay.Clients[plr].Socket.GetRemoteAddress().IsLocalHost())
return true;
return false;
}
//public override void PostDrawInterface(SpriteBatch spriteBatch)
//{
// //Main.spriteBatch.DrawString(FontAssets.MouseText.Value, "Drawn Always", new Vector2(Main.screenWidth/2, Main.screenHeight/2 + 20), Color.Aquamarine, 0.0f, new Vector2(), 0.8f, SpriteEffects.None, 0.0f);
// AllItemsMenu menu = (AllItemsMenu)this.GetGlobalItem("AllItemsMenu");
// menu.DrawUpdateAll(spriteBatch);
//}
//public override void PostUpdateInput()
//{
// if (!Main.gameMenu)
// {
// //UIView.UpdateUpdateInput();
// AllItemsMenu menu = (AllItemsMenu)this.GetGlobalItem("AllItemsMenu");
// menu.UpdateInput();
// }
//}
//public override void UpdateMusic(ref int music)
//{
// PreviousKeyState = Main.keyState;
//}
private KeyboardState PreviousKeyState;
public void RegisterButton(Asset<Texture2D> texture, Action buttonClickedAction, Func<string> tooltip) {
ButtonClicked.Add(buttonClickedAction);
ButtonTexture.Add(texture);
ButtonTooltip.Add(tooltip);
//ErrorLogger.Log("1 "+ButtonClicked.Count);
//ErrorLogger.Log("2 "+ ButtonTexture.Count);
//ErrorLogger.Log("3 "+ ButtonTooltip.Count);
}
internal static List<Action> ButtonClicked = new List<Action>();
internal static List<Asset<Texture2D>> ButtonTexture = new List<Asset<Texture2D>>();
internal static List<Func<string>> ButtonTooltip = new List<Func<string>>();
public override object Call(params object[] args) {
try {
string message = args[0] as string;
if (message == "AddButton_Test") {
Logger.Info("Button Adding...");
RegisterButton(args[1] as Asset<Texture2D>, args[2] as Action, args[3] as Func<string>);
Logger.Info("...Button Added");
}
else if (message == "HideHotbar") {
hotbar.Hide();
}
else {
Logger.Error("Call Error: Unknown Message: " + message);
}
}
catch (Exception e) {
Logger.Error("Call Error: " + e.StackTrace + e.Message);
}
return null;
}
public override void HandlePacket(BinaryReader reader, int whoAmI) {
CheatSheetMessageType msgType = (CheatSheetMessageType)reader.ReadByte();
string key;
switch (msgType) {
case CheatSheetMessageType.SpawnNPC:
int npcType = reader.ReadInt32();
int netID = reader.ReadInt32();
NPCSlot.HandleNPC(npcType, netID, true, whoAmI);
key = "Mods.CheatSheet.MobBrowser.SpawnNPCNotification";
ChatHelper.BroadcastChatMessage(NetworkText.FromKey(key, netID, Netplay.Clients[whoAmI].Name), Color.Azure);
//message = "Spawned " + netID + " by " + Netplay.Clients[whoAmI].Name;
//NetMessage.SendData(25, -1, -1, message, 255, Color.Azure.R, Color.Azure.G, Color.Azure.B, 0);
break;
case CheatSheetMessageType.QuickClear:
int clearType = reader.ReadInt32();
switch (clearType) {
case 0:
key = "Mods.CheatSheet.QuickClear.ItemClearNotification";
//message = "Items were cleared by ";
break;
case 1:
key = "Mods.CheatSheet.QuickClear.ProjectileClearNotification";
//message = "Projectiles were cleared by ";
break;
default:
key = "";
break;
}
//message += Netplay.Clients[whoAmI].Name;
QuickClearHotbar.HandleQuickClear(clearType, true, whoAmI);
ChatHelper.BroadcastChatMessage(NetworkText.FromKey(key, Netplay.Clients[whoAmI].Name), Color.Azure);
//NetMessage.SendData(25, -1, -1, message, 255, Color.Azure.R, Color.Azure.G, Color.Azure.B, 0);
break;
case CheatSheetMessageType.VacuumItems:
Hotbar.HandleVacuum(true, whoAmI);
key = "Mods.CheatSheet.Vacuum.VacuumNotification";
ChatHelper.BroadcastChatMessage(NetworkText.FromKey(key, Netplay.Clients[whoAmI].Name), Color.Azure);
//message = "Items on the ground were vacuumed by " + Netplay.Clients[whoAmI].Name;
//NetMessage.SendData(25, -1, -1, message, 255, Color.Azure.R, Color.Azure.G, Color.Azure.B, 0);
break;
case CheatSheetMessageType.ButcherNPCs:
NPCButchererHotbar.HandleButcher(reader.ReadInt32(), true);
key = "Mods.CheatSheet.Butcherer.ButcherNotification";
ChatHelper.BroadcastChatMessage(NetworkText.FromKey(key, Netplay.Clients[whoAmI].Name), Color.Azure);
//message = "NPCs were butchered by " + Netplay.Clients[whoAmI].Name;
//NetMessage.SendData(25, -1, -1, message, 255, Color.Azure.R, Color.Azure.G, Color.Azure.B, 0);
break;
case CheatSheetMessageType.TeleportPlayer:
QuickTeleportHotbar.HandleTeleport(reader.ReadInt32(), true, whoAmI);
break;
case CheatSheetMessageType.SetSpawnRate:
SpawnRateMultiplier.HandleSetSpawnRate(reader, whoAmI);
break;
case CheatSheetMessageType.SpawnRateSet:
SpawnRateMultiplier.HandleSpawnRateSet(reader, whoAmI);
break;
case CheatSheetMessageType.RequestFilterNPC:
int netID2 = reader.ReadInt32();
bool desired = reader.ReadBoolean();
NPCBrowser.FilterNPC(netID2, desired);
ConfigurationLoader.SaveSetting();
var packet = GetPacket();
packet.Write((byte)CheatSheetMessageType.InformFilterNPC);
packet.Write(netID2);
packet.Write(desired);
packet.Send();
break;
case CheatSheetMessageType.InformFilterNPC:
int netID3 = reader.ReadInt32();
bool desired2 = reader.ReadBoolean();
NPCBrowser.FilterNPC(netID3, desired2);
NPCBrowser.needsUpdate = true;
break;
//case CheatSheetMessageType.RequestToggleNPCSpawn:
// NPCSlot.HandleFilterRequest(reader.ReadInt32(), reader.ReadInt32(), true);
// break;
default:
Logger.Warn("Unknown Message type: " + msgType);
break;
}
}
public static Rectangle GetClippingRectangle(SpriteBatch spriteBatch, Rectangle r) {
//Vector2 vector = new Vector2(this._innerDimensions.X, this._innerDimensions.Y);
//Vector2 position = new Vector2(this._innerDimensions.Width, this._innerDimensions.Height) + vector;
Vector2 vector = new Vector2(r.X, r.Y);
Vector2 position = new Vector2(r.Width, r.Height) + vector;
vector = Vector2.Transform(vector, Main.UIScaleMatrix);
position = Vector2.Transform(position, Main.UIScaleMatrix);
Rectangle result = new Rectangle((int)vector.X, (int)vector.Y, (int)(position.X - vector.X), (int)(position.Y - vector.Y));
int width = spriteBatch.GraphicsDevice.Viewport.Width;
int height = spriteBatch.GraphicsDevice.Viewport.Height;
result.X = Utils.Clamp<int>(result.X, 0, width);
result.Y = Utils.Clamp<int>(result.Y, 0, height);
result.Width = Utils.Clamp<int>(result.Width, 0, width - result.X);
result.Height = Utils.Clamp<int>(result.Height, 0, height - result.Y);
return result;
}
}
public static class CheatSheetInterface
{
public static void RegisterButton(Asset<Texture2D> texture, Action buttonClickedAction, Func<string> tooltip) {
if (!Main.dedServ) {
ModContent.GetInstance<CheatSheet>().RegisterButton(texture, buttonClickedAction, tooltip);
}
}
public static void RegisterButton(CheatSheetButton csb) {
if (!Main.dedServ) {
ModContent.GetInstance<CheatSheet>().RegisterButton(csb.texture, csb.buttonClickedAction, csb.tooltip);
}
}
/// <summary>
/// Returns all extra accessories for the given player
/// </summary>
public static IEnumerable<Item> GetExtraAccessories(Player player) {
return player.GetModPlayer<CheatSheetPlayer>().ExtraAccessories;
}
/// <summary>
/// Returns all extra enabled accessories for the given player
/// </summary>
public static IEnumerable<Item> GetEnabledExtraAccessories(Player player) {
var cheatSheetPlayer = player.GetModPlayer<CheatSheetPlayer>();
return cheatSheetPlayer.ExtraAccessories.Take(cheatSheetPlayer.numberExtraAccessoriesEnabled);
}
/// <summary>
/// Returns the extra accessory item at the given index
/// Returns null if the index is out of bounds
/// </summary>
public static Item GetExtraAccessory(Player player, int index) {
if (index < 0 || index >= CheatSheetPlayer.MaxExtraAccessories)
return null;
return player.GetModPlayer<CheatSheetPlayer>().ExtraAccessories[index];
}
}
public class CheatSheetButton
{
internal Asset<Texture2D> texture;
//internal Action buttonClickedAction;
//internal Func<string> tooltip;
public CheatSheetButton(Asset<Texture2D> texture/*, Action buttonClickedAction, Func<string> tooltip*/) {
this.texture = texture;
// this.buttonClickedAction = buttonClickedAction;
// this.tooltip = tooltip;
}
public virtual void buttonClickedAction() {
}
public virtual string tooltip() {
return "";
}
}
internal enum CheatSheetMessageType : byte
{
SpawnNPC,
QuickClear,
VacuumItems,
ButcherNPCs,
TeleportPlayer,
SetSpawnRate,
SpawnRateSet,
FilterNPC,
RequestToggleNPCSpawn,
RequestFilterNPC,
InformFilterNPC,
}
static class CheatSheetUtilities
{
private static Uri reporturl = new Uri("http://javid.ddns.net/tModLoader/jopojellymods/report.php");
internal static void ReportException(Exception e) {
CheatSheet.instance.Logger.Error("CheatSheet: " + e.Message + e.StackTrace);
try {
ReportData data = new ReportData(e);
data.additionaldata = "Loaded Mods: " + string.Join(", ", ModLoader.Mods.Select(m => m.Name).ToArray());
string jsonpayload = JsonConvert.SerializeObject(data);
using (WebClient client = new WebClient()) {
var values = new NameValueCollection
{
{ "jsonpayload", jsonpayload },
};
client.UploadValuesAsync(reporturl, "POST", values);
}
}
catch { }
}
class ReportData
{
public string mod;
public string modversion;
public string tmodversion;
public string platform;
public string errormessage;
public string additionaldata;
public ReportData() {
tmodversion = BuildInfo.tMLVersion.ToString();
modversion = CheatSheet.instance.Version.ToString();
mod = "CheatSheet";
platform = ModLoader.CompressedPlatformRepresentation;
}
public ReportData(Exception e) : this() {
errormessage = e.Message + e.StackTrace;
}
}
}
}