forked from MarkusMaal/BlueScreenSimulatorPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
win.cs
404 lines (387 loc) · 15.8 KB
/
win.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Media;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using SimulatorDatabase;
namespace UltimateBlueScreenSimulator
{
public partial class Win : Form
{
public bool window = false;
internal BlueScreen me = Program.bluescreens[0];
readonly List<WindowScreen> wss = new List<WindowScreen>();
readonly List<Bitmap> freezescreens = new List<Bitmap>();
ThreadStart t;
Thread secondThread;
readonly List<Bitmap> image = new List<Bitmap>();
bool locked = true;
bool displaying = false;
readonly Random r = new Random();
readonly SoundPlayer sp = new SoundPlayer();
Bitmap splash = Properties.Resources.win1_splash;
public Win()
{
InitializeComponent();
}
private void WriteWord()
{
while (true)
{
while (displaying)
{
Thread.Sleep(2);
}
Color bg = me.GetTheme(true); Color fg = me.GetTheme(false);
if (this.BackColor == this.ForeColor)
{
bg = Color.FromArgb(r.Next(0, 255), r.Next(0, 255), r.Next(0, 255));
fg = Color.FromArgb(r.Next(0, 255), r.Next(0, 255), r.Next(0, 255));
}
Bitmap bmpres = GetSymbol(bg, fg);
for (int i = 0; i < new Random().Next(20, 77); i++)
{
Bitmap two = GetSymbol(bg, fg);
bmpres = Merge(bmpres, two);
}
image.Add(bmpres);
//bmpres.Dispose();
locked = false;
displaying = true;
}
}
private Bitmap GetSymbol(Color bg, Color fg)
{
int index = r.Next(0, 255);
Rectangle cropRect = new Rectangle(index * 8, 0, 8, 12);
try
{
Bitmap src = Properties.Resources.doscii as Bitmap;
Bitmap target = new Bitmap(cropRect.Width, cropRect.Height);
using (Graphics g = Graphics.FromImage(target))
{
g.DrawImage(src, new Rectangle(0, 0, target.Width, target.Height),
cropRect,
GraphicsUnit.Pixel);
}
Bitmap tc = Changecolor(bg, target, Color.FromArgb(0, 0, 0));
Bitmap t = Changecolor(fg, tc, Color.FromArgb(255, 255, 255));
target = t;
return target;
}
catch
{
return new Bitmap(1, 1);
}
}
private Bitmap Merge(Bitmap bmp, Bitmap bmp2)
{
Bitmap ne = new Bitmap(bmp.Width + 8, bmp.Height);
using (Graphics grfx = Graphics.FromImage(ne))
{
grfx.DrawImage(bmp, 0, 0);
grfx.DrawImage(bmp2, ne.Width - 8, 0);
}
return ne;
}
private Bitmap Changecolor(Color gc, Bitmap bmp, Color incol)
{
Color black = incol;
Color white = gc;
Bitmap img = bmp;
for (int i = 0; i < img.Width; i++)
{
for (int j = 0; j < img.Height; j++)
{
Color pixelColor = img.GetPixel(i, j);
if (pixelColor == black)
img.SetPixel(i, j, white);
}
}
return img;
}
public Bitmap CreateNonIndexedImage(Image src)
{
Bitmap newBmp = new Bitmap(src.Width, src.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
using (Graphics gfx = Graphics.FromImage(newBmp))
{
gfx.DrawImage(src, 0, 0);
}
src.Dispose();
return newBmp;
}
private void Win_Load(object sender, EventArgs e)
{
try
{
this.Icon = me.GetIcon();
this.Text = me.GetString("friendlyname");
Program.load_progress = 101;
watermark.Visible = me.GetBool("watermark");
if (me.GetString("qr_file") != "local:null")
{
switch (me.GetString("qr_file"))
{
case "local:0":
splash = Properties.Resources.win1_splash;
break;
case "local:1":
splash = Properties.Resources.win2_splash;
break;
default:
splash = (Bitmap)Image.FromFile(me.GetString("qr_file"));
break;
}
if (this.BackColor == this.ForeColor)
{
Color bg = Color.FromArgb(r.Next(0, 255), r.Next(0, 255), r.Next(0, 255));
Color fg = Color.FromArgb(r.Next(0, 255), r.Next(0, 255), r.Next(0, 255));
splash = Changecolor(fg, Changecolor(bg, CreateNonIndexedImage(splash), Color.FromArgb(19, 19, 19)), Color.FromArgb(255, 255, 255));
} else
{
splash = Changecolor(me.GetTheme(false), Changecolor(me.GetTheme(true), CreateNonIndexedImage(splash), Color.FromArgb(19, 19, 19)), Color.FromArgb(255, 255, 255));
}
int z = 1;
for (int y = 0; y < 224; y += 12)
{
Bitmap bmp = new Bitmap(pictureBox1.Width, 12);
Rectangle cropRect = new Rectangle(0, y, pictureBox1.Width, 12);
using (Graphics g = Graphics.FromImage(bmp))
{
g.DrawImage(splash, new Rectangle(0, 0, bmp.Width, bmp.Height), cropRect, GraphicsUnit.Pixel);
}
((PictureBox)tableLayoutPanel1.Controls["pictureBox" + z.ToString()]).Image = bmp;
z++;
}
}
if (me.GetBool("playsound"))
{
sp.Stream = Properties.Resources.beep;
sp.PlayLooping();
}
int[] colors = { this.BackColor.R + 50, this.BackColor.G + 50, this.BackColor.B + 50 };
if (colors[0] > 255) { colors[0] -= 255; }
if (colors[1] > 255) { colors[1] -= 255; }
if (colors[2] > 255) { colors[2] -= 255; }
watermark.ForeColor = Color.FromArgb(colors[0], colors[1], colors[2]);
Program.loadfinished = true;
if (!me.GetBool("windowed"))
{
this.FormBorderStyle = FormBorderStyle.None;
this.TopMost = false;
if (Screen.AllScreens.Length > 1)
{
foreach (Screen s in Screen.AllScreens)
{
WindowScreen ws = new WindowScreen();
if (!s.Primary)
{
if (Program.multidisplaymode != "none")
{
ws.StartPosition = FormStartPosition.Manual;
ws.Location = s.WorkingArea.Location;
ws.Size = new Size(s.WorkingArea.Width, s.WorkingArea.Height);
ws.primary = false;
if (Program.multidisplaymode == "freeze")
{
Bitmap screenshot = new Bitmap(s.Bounds.Width,
s.Bounds.Height,
System.Drawing.Imaging.PixelFormat.Format32bppArgb);
Graphics gfxScreenshot = Graphics.FromImage(screenshot);
gfxScreenshot.CopyFromScreen(
s.Bounds.X,
s.Bounds.Y,
0,
0,
s.Bounds.Size,
CopyPixelOperation.SourceCopy
);
freezescreens.Add(screenshot);
}
}
}
wss.Add(ws);
}
}
else
{
wss.Add(new WindowScreen());
}
for (int i = 0; i < wss.Count; i++)
{
WindowScreen ws = wss[i];
ws.Show();
if (!ws.primary)
{
if (Program.multidisplaymode == "freeze")
{
ws.screenDisplay.Image = freezescreens[i - 1];
}
}
}
}
else
{
//this.Size = new Size(640, 320);
}
t = new ThreadStart(WriteWord);
secondThread = new Thread(t);
secondThread.Start();
} catch (Exception ex)
{
Program.loadfinished = true;
screenUpdater.Enabled = false;
this.Hide();
if (Program.f1.enableeggs) { me.Crash(ex.Message, ex.StackTrace, "OrangeScreen"); }
else { MessageBox.Show("The blue screen cannot be displayed due to an error.\n\n" + ex.Message + "\n\n" + ex.StackTrace, "E R R O R", MessageBoxButtons.OK, MessageBoxIcon.Error); }
this.Close();
}
Program.load_progress = 100;
}
private void Timer1_Tick(object sender, EventArgs e)
{
if (screenUpdater.Interval != me.GetInt("blink_speed")) { screenUpdater.Interval = me.GetInt("blink_speed"); }
if (!window)
{
foreach (WindowScreen ws in wss)
{
if (ws.Visible == false)
{
this.Close();
}
try
{
if (!ws.primary && Program.multidisplaymode == "blank")
{
continue;
}
Program.dr.Draw(ws);
}
catch
{
this.Close();
}
}
this.BringToFront();
this.Activate();
}
if (!locked)
{
foreach (Image img in image)
{
if ((img != null) || (pictureBox19 != null))
{
if (pictureBox19.Image.Width + img.Width > pictureBox19.Width)
{
try
{
Bitmap partone = new Bitmap(pictureBox19.Width - img.Width, img.Height);
Graphics g;
g = Graphics.FromImage(partone);
g.DrawImage(img, 0, 0);
Bitmap bmp = new Bitmap(pictureBox19.Width, pictureBox19.Image.Height);
g = Graphics.FromImage(bmp);
g.DrawImage(pictureBox19.Image, 0, 0);
g.DrawImage(partone, new Point(pictureBox19.Image.Width + 1, 0));
pictureBox19.Image = bmp;
if (pictureBox1.Image != null)
{
pictureBox1.Image.Dispose();
}
for (int i = 1; i < 19; i++)
{
try
{
((PictureBox)tableLayoutPanel1.Controls["pictureBox" + i.ToString()]).Image = ((PictureBox)tableLayoutPanel1.Controls["pictureBox" + (i + 1).ToString()]).Image;
}
catch
{
}
}
pictureBox19.Image = Properties.Resources.dummy;
partone.Dispose();
}
catch
{
}
img.Dispose();
}
else
{
Bitmap bmp = new Bitmap(pictureBox19.Image.Width + img.Width, pictureBox19.Image.Height);
Graphics g = Graphics.FromImage(bmp);
g.DrawImage(pictureBox19.Image, 0, 0);
g.DrawImage(img, new Point(pictureBox19.Image.Width + 1, 0));
pictureBox19.Image = bmp;
img.Dispose();
}
}
}
image.Clear();
displaying = false;
locked = true;
}
}
private void Win_FormClosed(object sender, FormClosedEventArgs e)
{
try
{
foreach (Control c in tableLayoutPanel1.Controls)
{
c.Dispose();
}
this.Dispose();
}
catch
{
Console.WriteLine("Warning: \"Win\" forcibly closed from external source!!!");
}
}
private void Win_FormClosing(object sender, FormClosingEventArgs e)
{
try
{
screenUpdater.Enabled = false;
if (Program.f1 != null)
{
if (secondThread != null)
{
secondThread.Abort();
}
foreach (WindowScreen ws in wss)
{
ws.Close();
}
foreach (Image img in freezescreens)
{
img.Dispose();
}
foreach (Image img in image)
{
img.Dispose();
}
splash.Dispose();
if (me.GetBool("playsound"))
{
sp.Stop();
sp.Dispose();
}
try
{
this.Dispose();
} catch { }
}
} catch (Exception ex)
{
Program.loadfinished = true;
MessageBox.Show("An error has occoured.\n\n" + ex.Message + "\n\n" + ex.StackTrace, "Critical error", MessageBoxButtons.OK, MessageBoxIcon.Error);
this.Dispose();
}
}
}
}