From 07378d495717de2e9ce85908ad98efb2895766f6 Mon Sep 17 00:00:00 2001
From: JavidPack <javidpack@gmail.com>
Date: Tue, 19 Sep 2017 14:46:12 -0600
Subject: [PATCH] 0.2.7.4, exception web reporting.

---
 CheatSheet.cs      | 51 ++++++++++++++++++++++++++++++++++++++++++++++
 CheatSheetWorld.cs | 10 ++++++++-
 build.txt          |  2 +-
 3 files changed, 61 insertions(+), 2 deletions(-)

diff --git a/CheatSheet.cs b/CheatSheet.cs
index 36a53e3..7634838 100644
--- a/CheatSheet.cs
+++ b/CheatSheet.cs
@@ -2,9 +2,12 @@
 using Microsoft.Xna.Framework;
 using Microsoft.Xna.Framework.Graphics;
 using Microsoft.Xna.Framework.Input;
+using Newtonsoft.Json;
 using System;
 using System.Collections.Generic;
+using System.Collections.Specialized;
 using System.IO;
+using System.Net;
 using Terraria;
 using Terraria.ID;
 using Terraria.Localization;
@@ -472,4 +475,52 @@ internal enum CheatSheetMessageType : byte
 		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)
+		{
+			ErrorLogger.Log("CheatSheet: " + e.Message + e.StackTrace);
+			try
+			{
+				ReportData data = new ReportData(e);
+				data.additionaldata = "Loaded Mods: " + string.Join(", ", ModLoader.GetLoadedMods());
+				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 = ModLoader.version.ToString();
+				modversion = CheatSheet.instance.Version.ToString();
+				mod = "CheatSheet";
+				platform = ModLoader.compressedPlatformRepresentation;
+			}
+
+			public ReportData(Exception e) : this()
+			{
+				errormessage = e.Message + e.StackTrace;
+			}
+		}
+	}
 }
\ No newline at end of file
diff --git a/CheatSheetWorld.cs b/CheatSheetWorld.cs
index 0404c23..1495283 100644
--- a/CheatSheetWorld.cs
+++ b/CheatSheetWorld.cs
@@ -1,4 +1,5 @@
 using CheatSheet.Menus;
+using System;
 using System.IO;
 using Terraria;
 using Terraria.ModLoader;
@@ -11,7 +12,14 @@ public override void Initialize()
 		{
 			if (!Main.dedServ && Main.LocalPlayer.name != "")
 			{
-				(mod as CheatSheet).hotbar.bCycleExtraAccessorySlots.Tooltip = "Extra Accessory Slots: " + Main.LocalPlayer.GetModPlayer<CheatSheetPlayer>(mod).numberExtraAccessoriesEnabled;
+				try
+				{
+					(mod as CheatSheet).hotbar.bCycleExtraAccessorySlots.Tooltip = "Extra Accessory Slots: " + Main.LocalPlayer.GetModPlayer<CheatSheetPlayer>(mod).numberExtraAccessoriesEnabled;
+				}
+				catch (Exception e)
+				{
+					CheatSheetUtilities.ReportException(e);
+				}
 			}
 
 			//    ((CheatSheet)mod).hotbar.ChangedBossDowner();
diff --git a/build.txt b/build.txt
index 9478d62..a955db3 100644
--- a/build.txt
+++ b/build.txt
@@ -1,5 +1,5 @@
 author = jopojelly, jofairden
-version = 0.2.7.3
+version = 0.2.7.4
 displayName = Cheat Sheet
 homepage = http://forums.terraria.org/index.php?threads/cheat-sheet.41407/
 buildIgnore = .vs\*, Properties\*, *.csproj, *.user, obj\*, bin\*, *.config, .git\*