-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDebugGame.cs
96 lines (88 loc) · 4.26 KB
/
DebugGame.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
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Clipboard = System.Windows.Forms.Clipboard;
using System.Net.Mail;
using System.Net;
using System.Security;
namespace Accelerated_Delivery_Win
{
public class CrashDebugGame : Game
{
private SpriteBatch spriteBatch;
private SpriteFont font;
private readonly Exception exception;
private GraphicsDeviceManager g;
KeyboardState lastFrame;
bool sentMail = false;
string add = "";
private BoxCutter Cutter;
public CrashDebugGame(Exception ex, BoxCutter cutter)
{
exception = ex;
Cutter = cutter;
try
{
Cutter.WriteExceptionToLog(ex, true);
}
catch { }
g = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void LoadContent()
{
g.PreferredBackBufferWidth = 800;
g.PreferredBackBufferHeight = 600;
font = Content.Load<SpriteFont>("Font/CrashFont");
spriteBatch = new SpriteBatch(GraphicsDevice);
g.ApplyChanges();
}
protected override void Update(GameTime gameTime)
{
KeyboardState thisFrame = Keyboard.GetState();
if((thisFrame.IsKeyDown(Keys.LeftControl) || thisFrame.IsKeyDown(Keys.RightControl)) &&
thisFrame.IsKeyDown(Keys.C) && lastFrame.IsKeyUp(Keys.C))
{
string text = "Type:" + exception.GetType() + "\nError:\n" + exception.Message + "\nStack:\n" + exception.StackTrace;
Clipboard.Clear();
System.Threading.Thread.Sleep(500);
Clipboard.SetDataObject(text, true, 5, 200);
}
if(((thisFrame.IsKeyDown(Keys.LeftControl) || thisFrame.IsKeyDown(Keys.RightControl)) &&
thisFrame.IsKeyDown(Keys.M) && lastFrame.IsKeyUp(Keys.M)) && !sentMail)
{
SecureString p = new SecureString();
p.AppendChar('d'); p.AppendChar('a'); p.AppendChar('r'); p.AppendChar('k');
p.AppendChar('4'); p.AppendChar('T'); p.AppendChar('e'); p.AppendChar('O');
p.MakeReadOnly();
SmtpClient client = new SmtpClient("smtp.gmail.com", 587)
{
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential("[email protected]", p)
};
using(MailMessage m = new MailMessage("[email protected]", "[email protected]", "Crash Report", "Error:\n" + exception.Message + "\nStack:\n" + exception.StackTrace))
client.Send(m);
sentMail = true;
add = "\n\n Mail sent!";
}
if(GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed ||
thisFrame.IsKeyDown(Keys.Escape))
Exit();
base.Update(gameTime);
lastFrame = thisFrame;
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(ClearOptions.Target, Color.Black, 0, 0);
spriteBatch.Begin(SpriteSortMode.Immediate, null, SamplerState.LinearClamp, null, null);
string text = "We sincerely apologize, but Accelerated Delivery has\nencountered a catastrophic malfunction.\nPress CTRL+C to copy the error message to the clipboard,\nand then mail it to [email protected].\nPlease include what you were doing, what\nlevel/menu you were on, and such.\nPress Back or Escape to exit, and press CTRL+M\nto send an email containing the error (you\nmust be connected to the internet). Thanks, and\n have a nice day!" + add;
spriteBatch.DrawString(font, text, new Vector2(g.GraphicsDevice.Viewport.Width * 0.5f, g.GraphicsDevice.Viewport.Height * 0.5f), Color.White,
0, font.MeasureString(text) * 0.5f, 1, SpriteEffects.None, 0);
spriteBatch.End();
base.Draw(gameTime);
}
}
}