aboutsummaryrefslogtreecommitdiff
path: root/source/WindowsFormsApplication1/API.cs
blob: 419922335e65e8aba64a5ecffe000fb148d7e392 (plain) (blame)
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
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Media;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Compression;
using System.Drawing;
using Newtonsoft.Json;
using System.Security.Cryptography;
using System.Diagnostics;
using System.Net;
using System.ComponentModel;
using System.Net.NetworkInformation;

namespace ShiftOS
{
    public static class Consts
    {
        public const string Version = "0.1.2";
    }

    public class Settings
    {
        public int MusicVolume { get; set; }
    }

    public class PanelButton
    {
        /// <summary>
        /// Initializes a new instance of a Panel Button model.
        /// </summary>
        /// <param name="name">The text displayed on the button.</param>
        /// <param name="icon">The icon displayed on the button.</param>
        /// <param name="formToManage">The form that is managed by the button.</param>
        public PanelButton(string name, Image icon, ref Form formToManage)
        {
            Name = name;
            Icon = icon;
            FormToManage = formToManage;
        }

        public string Name { get; set; }
        public Image Icon { get; set; }
        public Form FormToManage { get; set; }
    }

    public class ApplauncherItem
    {
        public ApplauncherItem(string name, Image icn, string lua, bool disp) 
        {
            Name = name;
            Icon = icn;
            Lua = lua;
            Display = disp;
        }
        public string Name { get; set; }
        public Image Icon { get; set; }
        public string Lua { get; set; } //ShiftCode that decides what ShiftOS will do when the item is clicked.
        public bool Display { get; set; }
    }

    public class ModApplauncherItem
    {
        public string Name { get; set; }
        public string Icon { get; set; }

        /// <summary>
        /// Legacy mod AL entries for compatibilty
        /// </summary>
        public string ShiftCode { get; set; } //ShiftCode that decides what ShiftOS will do when the item is clicked.
        
        public string Lua { get; set; }

        public Form FormToOpen { get; set; } //If ShiftCode == "openForm", ShiftOS will open this form.
        public bool Display { get; set; }
        public string AppDirectory { get; set; }
    }


    public class API
    {
        public static Dictionary<Form, string> OpenGUIDs = new Dictionary<Form, string>();
        public static Dictionary<string, Control> DEF_PanelGUIDs = new Dictionary<string, Control>();


        /// <summary>
        /// Settings file.
        /// </summary>
        public static Settings LoadedSettings = null;

        /// <summary>
        /// Whether or not dev commands like '05tray' are available.
        /// Typically, this is set to true if the release is classified as
        /// an alpha, beta, or release candidate.
        /// 
        /// Turn it off if the release is the final RC, or the stable release!
        /// 
        /// Enabling developer mode will cause the save engine to not encrypt the save file
        /// or Shiftorium Registry on save, enabling you to easily modify your save
        /// to test new features or to bring in lots of codepoints. This is why
        /// Developer mode should ALWAYS be off in non-dev releases, to prevent cheating.
        /// </summary>
        public static bool DeveloperMode = true;

        /// <summary>
        /// If this is true, only certain applications will open and only
        /// certain features will work.
        /// 
        /// This is useful for story plots like the End Game where you don't
        /// want the user being distracted by novelty features when they should
        /// be focusing on what's happening.
        /// 
        /// Think of it like the opposite of what Developer Mode would do.
        /// </summary>
        public static bool LimitedMode = false;

        public static bool InfoboxesPlaySounds = true;

        public static void SkinControl(Control c)
        {
            if(c is Button)
            {
                var b = c as Button;
                b.FlatStyle = FlatStyle.Flat;
            }
            if(c is Panel || c is FlowLayoutPanel)
            {
                foreach(Control child in c.Controls)
                {
                    SkinControl(child);
                }
            }
        }

        public static List<Process> RunningModProcesses = new List<Process>();
        public static Dictionary<string, string> CommandAliases = new Dictionary<string, string>();
        public static Terminal LoggerTerminal = null;
        
        /// <summary>
        /// Logs an exception to the log.
        /// </summary>
        /// <param name="Message">The text to log.</param>
        /// <param name="fatal">Is it a fatal crash?</param>
        public static void LogException(string Message, bool fatal)
        {
            if(!File.Exists(Paths.SystemDir + "_Log.txt"))
            {
                if (fatal == true)
                {
                    File.WriteAllText(Paths.SystemDir + "_Log.txt", GetLogTime() + " [ExWatch/WARNING] ShiftOS has encountered an UNHANDLED exception with message \"" + Message + "\". Report this to Michael as well as what you were doing when it happened ASAP.");
                }
                else
                {
                    File.WriteAllText(Paths.SystemDir + "_Log.txt", GetLogTime() + " ShiftOS encountered a handled exception with message \"" + Message + "\" and was able to keep going. Ignore this.");
                }
            }
            else
            {
                List<string> Entries = new List<string>();
                foreach(string entry in File.ReadAllLines(Paths.SystemDir + "_Log.txt")) {
                    Entries.Add(entry);
                }
                if (fatal == true)
                {
                    Entries.Add(GetLogTime() + " [ExWatch/WARNING] ShiftOS has encountered an UNHANDLED exception with message \"" + Message + "\". Report this to Michael as well as what you were doing when it happened ASAP.");
                }
                else
                {
                    Entries.Add(GetLogTime() + " ShiftOS encountered a handled exception with message \"" + Message + "\" and was able to keep going. Ignore this.");
                }
                File.WriteAllLines(Paths.SystemDir + "_Log.txt", Entries.ToArray());
            }
        }

        /// <summary>
        /// Logs text to the log file.
        /// </summary>
        /// <param name="Message">The text to log.</param>
        public static void Log(string Message)
        {
            if (!File.Exists(Paths.SystemDir + "_Log.txt"))
            {
                File.WriteAllText(Paths.SystemDir + "_Log.txt", GetLogTime() + " " + Message);
            }
            else
            {
                List<string> Entries = new List<string>();
                foreach (string entry in File.ReadAllLines(Paths.SystemDir + "_Log.txt"))
                {
                    Entries.Add(entry);
                }
                Entries.Add(GetLogTime() + " " + Message);
                File.WriteAllLines(Paths.SystemDir + "_Log.txt", Entries.ToArray());
            }
        }

        /// <summary>
        /// Gets a proper-formatted date/time string for the log.
        /// </summary>
        /// <returns></returns>
        public static string GetLogTime()
        {
            return "[" + DateTime.Now.ToLongDateString() + "\\" + DateTime.Now.ToLongTimeString() + "]";
        }
        
        /// <summary>
        /// Property representing the currently loaded name pack.
        /// </summary>
        public static Skinning.NamePack LoadedNames
        {
            get
            {
                if (Skinning.Utilities.LoadedNames != null)
                {
                    return Skinning.Utilities.LoadedNames;
                }
                else
                {
                    Skinning.Utilities.LoadedNames = new Skinning.NamePack();
                    Skinning.Utilities.loadedSkin.EmbeddedNamePackPath = "names.npk";
                    Skinning.Utilities.SaveEmbeddedNamePack();
                    Log("[Name Changer] Couldn't locate loaded name pack, using default name pack.");
                    return Skinning.Utilities.LoadedNames;
                }
            }
        }

        /// <summary>
        /// Adds a command line alias.
        /// </summary>
        /// <param name="key">Alias name</param>
        /// <param name="value">Command to run.</param>
        /// <returns></returns>
        public static bool AddAlias(string key, string value)
        {
            if(!AliasExists(key))
            {
                CommandAliases.Add(key, value);
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// Saves alias list to save game.
        /// </summary>
        public static void SaveAliases()
        {
            string json = JsonConvert.SerializeObject(CommandAliases);
            File.WriteAllText(Paths.SystemDir + "_aliases.json", json);
        }

        /// <summary>
        /// Loads alias list from the save game.
        /// </summary>
        public static void LoadAliases()
        {
            if (File.Exists(Paths.SystemDir + "_aliases.json")) {
                string json = File.ReadAllText(Paths.SystemDir + "_aliases.json");
                CommandAliases = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
            }
            else
            {
                CommandAliases = new Dictionary<string, string>();
            }

        }

        /// <summary>
        /// Removes an alias from the list.
        /// </summary>
        /// <param name="key">Alias to remove.</param>
        /// <returns>Whether the alias could be removed.</returns>
        public static bool RemoveAlias(string key)
        {
            if(AliasExists(key))
            {
                CommandAliases.Remove(key);
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// Checks if the provided alias exists.
        /// </summary>
        /// <param name="key">The alias to check.</param>
        /// <returns>Whether the alias exists.</returns>
        public static bool AliasExists(string key)
        {
            bool no = false;
            foreach(KeyValuePair<string, string> kv in CommandAliases)
            {
                if(kv.Key == key)
                {
                    no = true;
                }
            }
            return no;
        }

        /// <summary>
        /// I have no idea what this does - Michael
        /// </summary>
        /// <param name="AppName"></param>
        public static void CreateNewLoggerTerminal(string AppName)
        {
            CreateForm(new Terminal(true), AppName, Properties.Resources.iconTerminal);
        }

        public const string HiddenAPMCommand = "0Ifm0DcBBy10VZo/p4r1Jg==";
        public const string HiddenBTNConvertCommand = "js2qrls5kvZnutMbfH46sUKzKVrBtjzPlWn/wIIe/3g=";
        public const string HiddenDodgeCommand = "mpL4WPUoDcZrsXnNUJ5RWQ==";
        public const string HiddenLabyrinthCommand = "NbNzpplGKaS5D/RdwrQMXw==";
        public const string HiddenQuickChatCommand = "iQm+/qDqgkHT/zgPiYRlZQ==";
        public const string HiddenShiftnetCommand = "NCM++hbZox7B+m9tXRXGnw==";
        public const string HiddenBWalletCommand = "1nLiZELFcaxkXDufrLuyfw==";
        public const string HiddenBDiggerCommand = "g/efSjsaglt//dr3XHnPOw==";
        public const string HiddenDecryptorCommand = "CYPXaweggfWAuS7ONt/OPQ==";

        /// <summary>
        /// Launches an saa file, hooks it up to the Lua API, and runs it.
        /// </summary>
        /// <param name="modSAA">File to run.</param>
        public static void LaunchMod(string modSAA)
        {
            if (!LimitedMode)
            {
                if (Upgrades["shiftnet"] == true)
                {
                    if (File.Exists(modSAA))
                    {
                        if (File.ReadAllText(modSAA) == HiddenAPMCommand)
                        {
                            CreateForm(new Appscape(), "Appscape Package Manager", Properties.Resources.iconAppscape);
                        }
                        else if (File.ReadAllText(modSAA) == HiddenDecryptorCommand)
                        {
                            CreateForm(new ShiftnetDecryptor(), "Shiftnet Decryptor", Properties.Resources.iconShiftnet);
                        }
                        else if (File.ReadAllText(modSAA) == HiddenBDiggerCommand)
                        {
                            CreateForm(new BitnoteDigger(), "Bitnote Digger", Properties.Resources.iconBitnoteDigger);
                        }
                        else if (File.ReadAllText(modSAA) == HiddenBWalletCommand)
                        {
                            CreateForm(new BitnoteWallet(), "Bitnote Wallet", Properties.Resources.iconBitnoteWallet);
                        }
                        else if (File.ReadAllText(modSAA) == HiddenShiftnetCommand)
                        {
                            CreateForm(new Shiftnet(), "Shiftnet", Properties.Resources.iconShiftnet);
                        }
                        else if (File.ReadAllText(modSAA) == HiddenBTNConvertCommand)
                        {
                            CreateForm(new BitnoteConverter(), "Bitnote Converter", Properties.Resources.iconBitnoteWallet);
                        }
                        else if (File.ReadAllText(modSAA) == HiddenDodgeCommand)
                        {
                            CreateForm(new Dodge(), "Dodge", Properties.Resources.iconDodge);
                        }
                        else if (File.ReadAllText(modSAA) == HiddenLabyrinthCommand)
                        {
                            CreateForm(new Labyrinth(), "Labyrinth", null);
                        }
                        else
                        {
                            try
                            {
                                ExtractFile(modSAA, Paths.Mod_Temp, true);
                                var l = new LuaInterpreter(Paths.Mod_Temp + "main.lua");
                            }
                            catch (Exception ex)
                            {
                                LogException("Error launching mod file (.saa): " + ex.Message, false);
                                CreateInfoboxSession("Error", "Could not launch the .saa file you specified. It is unsupported by this version of ShiftOS.", infobox.InfoboxMode.Info);
                            }
                        }
                        var story_rnd = new Random();
                        int story_chance = story_rnd.Next(0, 3);
                        switch (story_chance) {
                            case 2:
                                if(API.Upgrades["holochat"] == false)
                                {
                                    var t = new Terminal();
                                    API.CreateForm(t, API.LoadedNames.TerminalName, API.GetIcon("Terminal"));
                                    t.StartDevXFuriousStory();
                                    t.BringToFront();
                                }
                                break;
                        }

                    }
                    else
                    {
                        throw new ModNotFoundException();
                    }
                }
            }
            else
            {
                CreateInfoboxSession("Limited mode", "ShiftOS is in limited mode and cannot perform this action. Please complete the current Mission first.", infobox.InfoboxMode.Info);
            }
        }
        

        /// <summary>
        /// Source: http://stackoverflow.com/questions/10168240/encrypting-decrypting-a-string-in-c-sharp
        /// 
        /// String cryptography wrapper for ShiftOS.
        /// </summary>
        public static class Encryption
        {
            private static readonly string passPhrase = "h8gf9dh790df87h9";

            private static string GetMacAddress()
            {
                string macAddresses = string.Empty;

                foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
                {
                    if (nic.OperationalStatus == OperationalStatus.Up)
                    {
                        macAddresses += nic.GetPhysicalAddress().ToString();
                        break;
                    }
                }

                return macAddresses;
            }


            // This constant string is used as a "salt" value for the PasswordDeriveBytes function calls.
            // This size of the IV (in bytes) must = (keysize / 8).  Default keysize is 256, so the IV must be
            // 32 bytes long.  Using a 16 character string here gives us 32 bytes when converted to a byte array.
            private static readonly byte[] initVectorBytes = Encoding.ASCII.GetBytes("tu89geji340t89u2");

            // This constant is used to determine the keysize of the encryption algorithm.
            private const int keysize = 256;

            /// <summary>
            /// Encrypt a string.
            /// </summary>
            /// <param name="plainText">Raw string to encrypt.</param>
            /// <returns>The encrypted string.</returns>
            public static string Encrypt(string plainText)
            {
                byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);
                using (PasswordDeriveBytes password = new PasswordDeriveBytes(GetMacAddress(), null))
                {
                    byte[] keyBytes = password.GetBytes(keysize / 8);
                    using (RijndaelManaged symmetricKey = new RijndaelManaged())
                    {
                        symmetricKey.Mode = CipherMode.CBC;
                        using (ICryptoTransform encryptor = symmetricKey.CreateEncryptor(keyBytes, initVectorBytes))
                        {
                            using (MemoryStream memoryStream = new MemoryStream())
                            {
                                using (CryptoStream cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write))
                                {
                                    cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length);
                                    cryptoStream.FlushFinalBlock();
                                    byte[] cipherTextBytes = memoryStream.ToArray();
                                    return Convert.ToBase64String(cipherTextBytes);
                                }
                            }
                        }
                    }
                }
            }

            public static string Encrypt_old(string plainText)
            {
                byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);
                using (PasswordDeriveBytes password = new PasswordDeriveBytes(passPhrase, null))
                {
                    byte[] keyBytes = password.GetBytes(keysize / 8);
                    using (RijndaelManaged symmetricKey = new RijndaelManaged())
                    {
                        symmetricKey.Mode = CipherMode.CBC;
                        using (ICryptoTransform encryptor = symmetricKey.CreateEncryptor(keyBytes, initVectorBytes))
                        {
                            using (MemoryStream memoryStream = new MemoryStream())
                            {
                                using (CryptoStream cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write))
                                {
                                    cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length);
                                    cryptoStream.FlushFinalBlock();
                                    byte[] cipherTextBytes = memoryStream.ToArray();
                                    return Convert.ToBase64String(cipherTextBytes);
                                }
                            }
                        }
                    }
                }
            }


            /// <summary>
            /// Decrypts an encrypted string.
            /// </summary>
            /// <param name="cipherText">The encrypted string.</param>
            /// <returns>The decrypted string.</returns>
            public static string Decrypt(string cipherText)
            {
                try
                {
                    byte[] cipherTextBytes = Convert.FromBase64String(cipherText);
                    using (PasswordDeriveBytes password = new PasswordDeriveBytes(GetMacAddress(), null))
                    {
                        byte[] keyBytes = password.GetBytes(keysize / 8);
                        using (RijndaelManaged symmetricKey = new RijndaelManaged())
                        {
                            symmetricKey.Mode = CipherMode.CBC;
                            using (ICryptoTransform decryptor = symmetricKey.CreateDecryptor(keyBytes, initVectorBytes))
                            {
                                using (MemoryStream memoryStream = new MemoryStream(cipherTextBytes))
                                {
                                    using (CryptoStream cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read))
                                    {
                                        byte[] plainTextBytes = new byte[cipherTextBytes.Length];
                                        int decryptedByteCount = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length);
                                        return Encoding.UTF8.GetString(plainTextBytes, 0, decryptedByteCount);
                                    }
                                }
                            }
                        }
                    }
                }
                catch
                {
                    return Decrypt_old(cipherText);
                }
            }

            public static string Decrypt_old(string cipherText)
            {
                byte[] cipherTextBytes = Convert.FromBase64String(cipherText);
                using (PasswordDeriveBytes password = new PasswordDeriveBytes(passPhrase, null))
                {
                    byte[] keyBytes = password.GetBytes(keysize / 8);
                    using (RijndaelManaged symmetricKey = new RijndaelManaged())
                    {
                        symmetricKey.Mode = CipherMode.CBC;
                        using (ICryptoTransform decryptor = symmetricKey.CreateDecryptor(keyBytes, initVectorBytes))
                        {
                            using (MemoryStream memoryStream = new MemoryStream(cipherTextBytes))
                            {
                                using (CryptoStream cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read))
                                {
                                    byte[] plainTextBytes = new byte[cipherTextBytes.Length];
                                    int decryptedByteCount = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length);
                                    return Encoding.UTF8.GetString(plainTextBytes, 0, decryptedByteCount);
                                }
                            }
                        }
                    }
                }
            }
        }

        /// <summary>
        /// Property representing the current client Bitnote address.
        /// </summary>
        public static SaveSystem.PrivateBitnoteAddress BitnoteAddress
        {
            get
            {
                return SaveSystem.Utilities.BitnoteAddress;
            }
        }

        public static class BitnoteEncryption
        {
            private static readonly string passPhrase = "jonathan_ladouceur_sucks_and_bitnotes_rock";

            // This constant string is used as a "salt" value for the PasswordDeriveBytes function calls.
            // This size of the IV (in bytes) must = (keysize / 8).  Default keysize is 256, so the IV must be
            // 32 bytes long.  Using a 16 character string here gives us 32 bytes when converted to a byte array.
            private static readonly byte[] initVectorBytes = Encoding.ASCII.GetBytes("tu89geji340t89u2");

            // This constant is used to determine the keysize of the encryption algorithm.
            private const int keysize = 256;

            /// <summary>
            /// Encrypts text using the bitnote passphrase.
            /// </summary>
            /// <param name="plainText">The raw string.</param>
            /// <returns>The encrypted string.</returns>
            public static string Encrypt(string plainText)
            {
                byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);
                using (PasswordDeriveBytes password = new PasswordDeriveBytes(passPhrase, null))
                {
                    byte[] keyBytes = password.GetBytes(keysize / 8);
                    using (RijndaelManaged symmetricKey = new RijndaelManaged())
                    {
                        symmetricKey.Mode = CipherMode.CBC;
                        using (ICryptoTransform encryptor = symmetricKey.CreateEncryptor(keyBytes, initVectorBytes))
                        {
                            using (MemoryStream memoryStream = new MemoryStream())
                            {
                                using (CryptoStream cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write))
                                {
                                    cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length);
                                    cryptoStream.FlushFinalBlock();
                                    byte[] cipherTextBytes = memoryStream.ToArray();
                                    return Convert.ToBase64String(cipherTextBytes);
                                }
                            }
                        }
                    }
                }
            }

            /// <summary>
            /// Decrypts an encrypted string using the Bitnote passphrase.
            /// </summary>
            /// <param name="cipherText">The encrypted text.</param>
            /// <returns>The decrypted text.</returns>
            public static string Decrypt(string cipherText)
            {
                byte[] cipherTextBytes = Convert.FromBase64String(cipherText);
                using (PasswordDeriveBytes password = new PasswordDeriveBytes(passPhrase, null))
                {
                    byte[] keyBytes = password.GetBytes(keysize / 8);
                    using (RijndaelManaged symmetricKey = new RijndaelManaged())
                    {
                        symmetricKey.Mode = CipherMode.CBC;
                        using (ICryptoTransform decryptor = symmetricKey.CreateDecryptor(keyBytes, initVectorBytes))
                        {
                            using (MemoryStream memoryStream = new MemoryStream(cipherTextBytes))
                            {
                                using (CryptoStream cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read))
                                {
                                    byte[] plainTextBytes = new byte[cipherTextBytes.Length];
                                    int decryptedByteCount = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length);
                                    return Encoding.UTF8.GetString(plainTextBytes, 0, decryptedByteCount);
                                }
                            }
                        }
                    }
                }
            }
        }


        /// <summary>
        /// Creates a new File Skimmer session.
        /// </summary>
        /// <param name="Filters">What file types can be shown when the mode is set to Open, or what file types can be saved to when mode is set to Save.</param>
        /// <param name="mode">The display mode of the File Skimmer.</param>
        public static void CreateFileSkimmerSession(string Filters, File_Skimmer.FileSkimmerMode mode)
        {
            FileSkimmerSession = new File_Skimmer(mode, Filters);
            CreateForm(FileSkimmerSession, "File Skimmer", Properties.Resources.iconFileSkimmer);
        }

        /// <summary>
        /// Call this during a closing event on a File Skimmer session to get the user's input.
        /// </summary>
        /// <returns>The user's input.</returns>
        public static string GetFSResult()
        {
            string result = "";
            if (FileSkimmerSession != null)
            {
                if (FileSkimmerSession.FileName != "")
                {
                    result = FileSkimmerSession.FileName;
                }
                else
                {
                    result = "fail";
                }
            }
            else
            {
                result = "fail";
                throw new InvalidSessionException("The File Skimmer session was not started. Try running API.CreateFileSkimmerSession().");
            }
            return result;
        }

        public static File_Skimmer FileSkimmerSession = null;


        public static List<PanelButton> PanelButtons = new List<PanelButton>();
        public static string LastRanCommand = "";

        public static List<ApplauncherItem> AppLauncherItems = new List<ApplauncherItem>();

        /// <summary>
        /// A dictionary of every single icon entry in the Icon Manager.
        /// </summary>
        public static Dictionary<string, Image> IconRegistry
        {
            get
            {
                return Skinning.Utilities.IconRegistry;
            }
        }

        /// <summary>
        /// Gets an icon from the Icon Registry.
        /// </summary>
        /// <param name="id">The ID of the icon.</param>
        /// <returns>The icon, if it exists, null if it doesn't.</returns>
        public static Image GetIcon(string id)
        {
            if(IconRegistry != null)
            {
                if(IconRegistry.ContainsKey(id))
                {
                    return IconRegistry[id];
                }
                else
                {
                    return Properties.Resources.NoIconFound;
                }
            }
            else
            {
                return Properties.Resources.NoIconFound;
            }
        }

        /// <summary>
        /// Creates a list of App Launcher Items based on what you've bought in the Shiftorium.
        /// </summary>
        public static void GetAppLauncherItems()
        {
            Skinning.Utilities.LoadEmbeddedNamePack();
            //System Applications
            AppLauncherItems.Clear();
            if (!LimitedMode)
                AppLauncherItems.Add(new ApplauncherItem(LoadedNames.ArtpadName, GetIcon("Artpad"), "open_program('artpad')", Upgrades["alartpad"]));
            AppLauncherItems.Add(new ApplauncherItem(LoadedNames.FileSkimmerName, GetIcon("FileSkimmer"), "open_program('file_skimmer')", Upgrades["alfileskimmer"]));
            if (!LimitedMode)
            {
                AppLauncherItems.Add(new ApplauncherItem("Network Browser", GetIcon("NetworkBrowser"), "open_program('netbrowse')", Upgrades["networkbrowser"]));
                AppLauncherItems.Add(new ApplauncherItem(LoadedNames.SkinLoaderName, GetIcon("SkinLoader"), "open_program('skinloader')", Upgrades["skinning"]));
                AppLauncherItems.Add(new ApplauncherItem(LoadedNames.ShiftoriumName, GetIcon("Shiftorium"), "open_program('shiftorium')", Upgrades["alshiftorium"]));
            }
            AppLauncherItems.Add(new ApplauncherItem("HoloChat", GetIcon("HoloChat"), "open_program('holochat')", API.Upgrades["holochat"]));
            if (!LimitedMode)
            {
                AppLauncherItems.Add(new ApplauncherItem("Icon Manager", GetIcon("IconManager"), "open_program('iconmanager')", Upgrades["iconmanager"]));
                AppLauncherItems.Add(new ApplauncherItem(LoadedNames.ShifterName, GetIcon("Shifter"), "open_program('shifter')", Upgrades["alshifter"]));
                AppLauncherItems.Add(new ApplauncherItem(LoadedNames.NameChangerName, GetIcon("NameChanger"), "open_program('name_changer')", Upgrades["namechanger"]));
                AppLauncherItems.Add(new ApplauncherItem(LoadedNames.PongName, GetIcon("Pong"), "open_program('pong')", Upgrades["alpong"]));
            }
            if(LimitedMode)
            {
                AppLauncherItems.Add(new ApplauncherItem("Quest Viewer", GetIcon("QuestViewer"), "open_program('quests')", true));
            }
            AppLauncherItems.Add(new ApplauncherItem(LoadedNames.TextpadName, GetIcon("TextPad"), "open_program('textpad')", Upgrades["altextpad"]));
            AppLauncherItems.Add(new ApplauncherItem(LoadedNames.TerminalName, GetIcon("Terminal"), "open_terminal()", true));
            if (!LimitedMode)
            {
                AppLauncherItems.Add(new ApplauncherItem(LoadedNames.KnowledgeInputName, GetIcon("KI"), "open_program('ki')", true));


                //System Features
                AppLauncherItems.Add(new ApplauncherItem(LoadedNames.UnityName, GetIcon("Unity"), "toggle_unity()", Upgrades["alunity"]));
                AppLauncherItems.Add(new ApplauncherItem(LoadedNames.ShutdownName, GetIcon("Shutdown"), "shutdown()", Upgrades["applaunchershutdown"]));
            }
        }

        /// <summary>
        /// The current Skin.
        /// </summary>
        public static Skinning.Skin CurrentSkin
        {
            get
            {
                return Skinning.Utilities.loadedSkin;
            }
        }

        public static ShiftOSDesktop CurrentSession = null; //The current ShiftOS desktop session.

        /// <summary>
        /// All the graphical elements of the current Skin.
        /// </summary>
        public static Skinning.Images CurrentSkinImages
        {
            get
            {
                return Skinning.Utilities.loadedskin_images;
            }
        }

        /// <summary>
        /// Plays a sound inside the Properties.Resources class.
        /// </summary>
        /// <param name="file">The unmanaged memory stream to play.</param>
        public static void PlaySound(UnmanagedMemoryStream file)
        {
            Stream str = file;
            SoundPlayer player = new SoundPlayer(str);
            player.Play();
        }

        /// <summary>
        /// Plays a sound from a byte[] array. Useful for MP3s and other formats.
        /// </summary>
        /// <param name="file">The byte[] aray</param>
        public static void PlaySound(byte[] file)
        {
            Stream mstr = new MemoryStream(file);
            SoundPlayer player = new SoundPlayer(mstr);
            player.Play();
        }

        /// <summary>
        /// Shiftorium upgrades.
        /// </summary>
        public static Dictionary<string, bool> Upgrades
        {
            get
            {
                return SaveSystem.ShiftoriumRegistry.ShiftoriumUpgrades;
            }
        }

        /// <summary>
        /// Creates a graphic picker session.
        /// </summary>
        /// <param name="GraphicName">The title of the graphic.</param>
        /// <param name="ShowMouseImages">Should the user be able to pick mouse-over/mouse-down images?</param>
        public static void CreateGraphicPickerSession(string GraphicName, bool ShowMouseImages)
        {
            GraphicPickerSession = new Graphic_Picker(GraphicName, ShowMouseImages);
            CreateForm(GraphicPickerSession, GraphicName, Properties.Resources.icongraphicpicker);
        }

        public static Graphic_Picker GraphicPickerSession = null;

        /// <summary>
        /// Call this in a closing event of a Graphic Picker session to get whether the user actually chose images.
        /// </summary>
        /// <returns>"OK" if the user chose an image, "fail" if not and "fail" if the session wasn't created.</returns>
        public static string GetGraphicPickerResult()
        {
            if(GraphicPickerSession != null)
            {
                string result = null;
                if (GraphicPickerSession.Result == "OK")
                {
                    result = "OK";
                }
                else
                {
                    result = "fail";
                }
                return result;
            }
            else {
                return "fail";
                throw new InvalidSessionException();
            }
        }

        /// <summary>
        /// The name of the OS defined by the user.
        /// </summary>
        public static string OSName
        {
            get
            {
                return SaveSystem.Utilities.LoadedSave.osname;
            }
            set
            {
                SaveSystem.Utilities.LoadedSave.osname = value;
            }
        }

        /// <summary>
        /// The username defined by the user.
        /// </summary>
        public static string Username
        {
            get
            {
                return SaveSystem.Utilities.LoadedSave.username;
            }
            set
            {
                SaveSystem.Utilities.LoadedSave.username = value;
            }
        }

        /// <summary>
        /// Current ammount of codepoints.
        /// </summary>
        public static int Codepoints
        {
            get
            {
                return SaveSystem.Utilities.LoadedSave.codepoints;
            }
        }

        /// <summary>
        /// Adds the specified amount of Codepoints.
        /// </summary>
        /// <param name="cp">Amount to add.</param>
        public static void AddCodepoints(int cp)
        {
            SaveSystem.Utilities.LoadedSave.codepoints += cp * CurrentSave.CodepointMultiplier;
        }

        /// <summary>
        /// Removes the specified amount of Codepoints if you have enough.
        /// </summary>
        /// <param name="cp">Amount to remove.</param>
        public static void RemoveCodepoints(int cp)
        {
            if (Codepoints >= cp)
            {
                SaveSystem.Utilities.LoadedSave.codepoints -= cp;
            }
        }


        /// <summary>
        /// The proper way to shut down ShiftOS.
        /// </summary>
        public static void ShutDownShiftOS()
        {
            File.WriteAllText(Paths.SystemDir + "settings.json", JsonConvert.SerializeObject(LoadedSettings));
            Audio.running = false;
            if (!LimitedMode)
            {
                //Disconnect from server.
                try
                {
                    foreach (var ip in Package_Grabber.clients)
                    {
                        if (ip.Value.IsConnected)
                            ip.Value.Disconnect();
                    }
                }
                catch
                {

                }
                //Close all mods.
                WindowComposition.ShuttingDown = true;
                if (RunningModProcesses.Count > 0)
                {
                    foreach (Process mod in RunningModProcesses)
                    {
                        try
                        {
                            mod.Kill();
                        }
                        catch (Exception ex)
                        {
                            LogException(ex.Message, false);
                        }
                    }
                    SaveSystem.Utilities.saveGame();
                    Application.Exit();

                }
                SaveSystem.Utilities.saveGame();
                //Right before the game closes...
                try
                {
                    if (Directory.Exists(Paths.Mod_Temp))
                        Directory.Delete(Paths.Mod_Temp, true);
                }
                catch (Exception ex)
                {
                    API.LogException(ex.Message, false);
                }
                finally
                {
                    //Alright, ShiftOS! HAVE AT IT!
                    Application.Exit();
                }
            }
            else
            {
                CreateInfoboxSession("Limited mode", "ShiftOS is in limited mode and cannot be shut down. Please complete the current mission before shutting down.", infobox.InfoboxMode.Info);
            }
        }

        /// <summary>
        /// Special zip file extractor method.
        /// </summary>
        /// <param name="zipFile">File to extract.</param>
        /// <param name="dir">Target directory.</param>
        /// <param name="deleteDir">Delete the target first?</param>
        public static void ExtractFile(string zipFile, string dir, bool deleteDir)
        {
            if (Directory.Exists(dir) && deleteDir == true)
            {
                Directory.Delete(dir, true);
                Directory.CreateDirectory(dir);
            }
            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            ZipFile.ExtractToDirectory(zipFile, dir);
        }

        /// <summary>
        /// Close all open applications (besides Desktop, and HijackScreen.)
        /// </summary>
        public static void CloseEverything()
        {
            PanelButtons.Clear();
            OpenPrograms.Clear();
            List<Form> formsToClose = new List<Form>();
            foreach (Form frm in Application.OpenForms)
            {
                switch (frm.Name)
                {
                    case "ShiftOSDesktop":
                    case "HijackScreen":
                        //Do nothing.
                        break;
                    default:
                        formsToClose.Add(frm);
                        break;
                }
            }
            foreach (Form frm in formsToClose)
            {
                frm.Close();
            }
        }

        /// <summary>
        /// Current save.
        /// </summary>
        public static SaveSystem.Save CurrentSave
        {
            get
            {
                return SaveSystem.Utilities.LoadedSave;
            }
        }

        public static List<Form> OpenPrograms = new List<Form>();
        public static List<WindowBorder> BordersToUpdate = new List<WindowBorder>();

        /// <summary>
        /// Transforms a standard Windows Form into a ShiftOS form.
        /// </summary>
        /// <param name="formToCreate">The Windows Form object to create.</param>
        /// <param name="AppName">Title to display</param>
        /// <param name="AppIcon">Icon to display on the titlebar.</param>
        public static void CreateForm(Form formToCreate, string AppName, Image AppIcon)
        {
            if(API.CurrentSession == null)
            {
                API.CurrentSession = new ShiftOSDesktop();
            }
            try
            {
                if (Upgrades["multitasking"] == false && formToCreate.Name != "infobox")
                {
                    CloseEverything();
                }
                var bw = new BackgroundWorker();
                bw.DoWork += (object sen, DoWorkEventArgs eva) =>
                {
                    WindowComposition.SafeToAddControls = false;
                //bugfix: Close any terminal if WindowedTerminal isn't installed.
                if (Upgrades["windowedterminal"] == false)
                    {
                        API.CurrentSession.Invoke(new Action(() =>
                        {
                            foreach (Form frm in OpenPrograms)
                            {
                                if (frm.Name.ToLower() == "terminal")
                                {
                                    API.CurrentSession.Invoke(new Action(() =>
                                    {
                                        frm.Close();
                                    }));
                                }
                            }
                        }));
                    }
                    WindowBorder brdr = new WindowBorder(AppName, AppIcon);
                    brdr.Name = "api_brdr";
                    formToCreate.Controls.Add(brdr);
                    formToCreate.ShowInTaskbar = false;
                    brdr.Show();
                    formToCreate.FormBorderStyle = FormBorderStyle.None;
                    brdr.Dock = DockStyle.Fill;
                    BordersToUpdate.Add(brdr);
                    List<Control> duplicates = new List<Control>();
                    foreach (Control ctrl in formToCreate.Controls)
                    {
                        if (ctrl.Name != "api_brdr")
                        {
                            ctrl.Hide();
                            brdr.pgcontents.Controls.Add(ctrl);
                            duplicates.Add(ctrl);
                        }
                    }
                    foreach (Control ctrl in duplicates)
                    {
                        try
                        {
                            formToCreate.Controls.Remove(ctrl);
                            ctrl.Show();
                            SkinControl(ctrl);
                        }
                        catch
                        {
                            API.CurrentSession.Invoke(new Action(() =>
                            {
                                ctrl.Show();
                                SkinControl(ctrl);
                            }));
                        }
                    }
                    WindowComposition.ShowForm(formToCreate, CurrentSkin.WindowOpenAnimation);
                    API.CurrentSession.Invoke(new Action(() =>
                    {
                        brdr.justopened = true;
                        formToCreate.TopMost = true;

                    //Open terminal on CTRL+T press on any form.
                    formToCreate.KeyDown += (object sender, KeyEventArgs e) =>
                        {
                            if (e.KeyCode == Keys.T && e.Control && formToCreate.Name != "Terminal")
                            {
                                CurrentSession.InvokeCTRLT();
                            }
                            if (formToCreate.Name != "Terminal" || Upgrades["windowedterminal"] == true)
                            {
                            //Movable Windows
                            if (API.Upgrades["movablewindows"] == true)
                                {
                                    if (e.KeyCode == Keys.A && e.Control)
                                    {
                                        e.Handled = true;
                                        formToCreate.Location = new Point(formToCreate.Location.X - 30, formToCreate.Location.Y);
                                    }
                                    if (e.KeyCode == Keys.D && e.Control)
                                    {
                                        e.Handled = true;
                                        formToCreate.Location = new Point(formToCreate.Location.X + 30, formToCreate.Location.Y);
                                    }
                                    if (e.KeyCode == Keys.W && e.Control)
                                    {
                                        e.Handled = true;
                                        formToCreate.Location = new Point(formToCreate.Location.X, formToCreate.Location.Y - 30);
                                    }
                                    if (e.KeyCode == Keys.S && e.Control)
                                    {
                                        e.Handled = true;
                                        formToCreate.Location = new Point(formToCreate.Location.X, formToCreate.Location.Y + 30);
                                    }
                                }
                            }
                        };
                        formToCreate.TransparencyKey = Skinning.Utilities.globaltransparencycolour;
                        OpenPrograms.Add(formToCreate);
                        if (AppName == "Enemy Hacker")
                        {
                            API.CurrentSession.Invoke(new Action(() =>
                            {
                                formToCreate.Left = Screen.PrimaryScreen.Bounds.Width - formToCreate.Width;
                            }));
                        }
                        else if (AppName == "You")
                        {
                            API.CurrentSession.Invoke(new Action(() =>
                            {
                                formToCreate.Left = 0;
                            }));
                        }
                    }));
                    WindowComposition.SafeToAddControls = true;
                    API.OpenGUIDs.Add(formToCreate, Guid.NewGuid().ToString());
                    API.CurrentSession.Invoke(new Action(() => { CurrentSession.InvokeWindowOp("open", formToCreate); }));
                };
                bw.RunWorkerAsync();
            }
            catch
            {

            }
        }

        /// <summary>
        /// Semi-working way to implement form rolling.
        /// </summary>
        /// <param name="formToRoll">The form to roll.</param>
        public static void RollForm(Form formToRoll)
        {
            if (formToRoll.Height == CurrentSkin.titlebarheight)
            {
                string xyraw = (string)formToRoll.Tag;
                string[] data = xyraw.Split(' ');
                string[] xy = data[0].Split(',');
                int x = Convert.ToInt16(xy[0]);
                int y = Convert.ToInt16(xy[1]);
                int mx = Convert.ToInt16(xy[2]);
                int my = Convert.ToInt16(xy[3]);
                formToRoll.Size = new Size(x, y);
                formToRoll.MinimumSize = new Size(mx, my);
            }
            else {
                formToRoll.Tag = formToRoll.Width.ToString() + "," + formToRoll.Height.ToString() + "," + formToRoll.MinimumSize.Width.ToString() + "," + formToRoll.MinimumSize.Height.ToString() + " " + formToRoll.Location.X.ToString() + "," + formToRoll.Location.Y.ToString();
                formToRoll.MinimumSize = new Size(0, 0);
                formToRoll.Height = API.CurrentSkin.titlebarheight;
            }

        }

        /// <summary>
        /// Makes all open applications load their skin data.
        /// </summary>
        public static void UpdateWindows()
        {
            try
            {
                foreach (WindowBorder brdr in BordersToUpdate)
                {
                    brdr.setupall();
                }
            }
            catch
            {

            }
        }

        /// <summary>
        /// Gets time based on what Shiftorium Upgrades you've got.
        /// </summary>
        /// <returns>The time.</returns>
        public static string GetTime()
        {
            string time = "nothing";

            if (Upgrades["splitsecondtime"] == true)
            {
                time = DateTime.Now.ToLongTimeString();
            }
            else {
                if (Upgrades["minuteaccuracytime"] == true)
                {
                    if (System.DateTime.Now.Hour < 12)
                    {
                        time = (DateTime.Now.Hour + ":" + String.Format(DateTime.Now.Minute.ToString(), "00")).ToString() + " AM";
                    }
                    else {
                        time = (DateTime.Now.Hour + ":" + String.Format(DateTime.Now.Minute.ToString(), "00")).ToString() + " PM";
                    }
                }
                else {
                    if (Upgrades["pmandam"] == true)
                    {
                        if (System.DateTime.Now.Hour < 12)
                        {
                            time = DateTime.Now.Hour + " AM";
                        }
                        else {
                            time = DateTime.Now.Hour - 12 + " PM";
                        }
                    }
                    else {
                        if (Upgrades["hourssincemidnight"] == true)
                        {
                            time = Math.Floor(System.DateTime.Now.Subtract(System.DateTime.Today).TotalSeconds / 60 / 60).ToString();
                        }
                        else {
                            if (Upgrades["minutessincemidnight"] == true)
                            {
                                time = Math.Floor(System.DateTime.Now.Subtract(System.DateTime.Today).TotalSeconds / 60).ToString();
                            }
                            else {
                                if (Upgrades["secondssincemidnight"] == true)
                                {
                                    time = Math.Floor(System.DateTime.Now.Subtract(System.DateTime.Today).TotalSeconds).ToString();
                                }
                            }
                        }
                    }
                }
            }
            return time;
        }

        /// <summary>
        /// Broken terminal command...
        /// </summary>
        /// <param name="command">Who even knows what this is?</param>
        /// <returns>I don't know.</returns>
        public static bool CloseProgram(string command)
        {
            try
            {
                List<PanelButton> PanelButtonsToKill = new List<PanelButton>();
                bool closed = false;
                foreach (Form app in OpenPrograms)
                {
                    if (app.Name.ToLower() == command)
                    {
                        foreach (PanelButton pbtn in PanelButtons)
                        {
                            if (app.Name.ToLower() == pbtn.FormToManage.Name.ToLower())
                            {
                                PanelButtonsToKill.Add(pbtn);
                            }
                        }
                        app.Close();
                        closed = true;
                    }
                    else
                    {
                        //Because the Shiftorium is referred to as 'Frontend', we must close any 'Frontend' forms if the command is equal to the Shiftorium name.
                        if (app.Name.ToLower() == "frontend" && command == CurrentSave.ShiftoriumName.ToLower())
                        {
                            foreach (PanelButton pbtn in PanelButtons)
                            {
                                if (app.Name.ToLower() == pbtn.FormToManage.Name.ToLower())
                                {
                                    PanelButtonsToKill.Add(pbtn);
                                }
                            }
                            app.Close();
                            closed = true;
                        }
                    }
                }
                foreach (PanelButton pbtn in PanelButtonsToKill)
                {
                    PanelButtons.Remove(pbtn);
                }
                return closed;
            }
            catch
            {
                return false;
            }
        }

        public static void ToggleMinimized(Form frm)
        {
            if ((Point)frm.Tag == frm.Location)
            {
                MinimizeForm(frm);
            }
            else
            {
                UnminimizeForm(frm);
            }
        }

        public static void MinimizeForm(Form frm)
        {
            frm.Tag = frm.Location;
            frm.Location = new Point(99999, 99999);
        }

        public static void UnminimizeForm(Form frm)
        {
            frm.Location = (Point)frm.Tag;
        }

        /// <summary>
        /// Shows an infobox.
        /// </summary>
        /// <param name="Title">Title of Infobox.</param>
        /// <param name="Message">The text to display.</param>
        /// <param name="Mode">User interface mode.</param>
        public static void CreateInfoboxSession(string Title, string Message, infobox.InfoboxMode Mode)
        {
            if (InfoboxSession != null)
            {
                InfoboxSession.Result = "Killed";
                InfoboxSession.Close();
                InfoboxSession = null;
            }
            InfoboxSession = new infobox(Message, Mode);
            CreateForm(InfoboxSession, Title, Properties.Resources.iconInfoBox_fw);
        }

        /// <summary>
        /// Call this on the close event of an Infobox to get the user result.
        /// </summary>
        /// <returns>If mode is "YesNo" then you'll get the button the user clicked. If "TextEntry" then the text the user entered.</returns>
        public static string GetInfoboxResult()
        {
            string Value = "";
            if (InfoboxSession == null)
            {
                throw new InvalidSessionException("An attempt to get the result of an Infobox failed because the Infobox session was null.");
            }
            else
            {
                switch (InfoboxSession.Result)
                {
                    case "OK":
                        if (InfoboxSession.displayMode == infobox.InfoboxMode.TextEntry)
                        {
                            Value = InfoboxSession.TextEntry;
                        }
                        else
                        {
                            Value = "OK";
                        }
                        break;
                    case "Yes":
                        Value = "Yes";
                        break;
                    case "No":
                        Value = "No";
                        break;
                    default:
                        Value = "Cancelled";
                        break;
                }
            }
            return Value;
        }

        public static infobox InfoboxSession = null;

        public class KnowledgeInputData
        {
            public static Dictionary<string, bool> Animals = new Dictionary<string, bool>();
            public static Dictionary<string, bool> Countries = new Dictionary<string, bool>();
            public static Dictionary<string, bool> Fruits = new Dictionary<string, bool>();

            #region "A load of Knowledge Input additions."
            public static void RegisterDictionaries()
            {
                Animals.Add("aardvark", false);
                Animals.Add("albatross", false);
                Animals.Add("alligator", false);
                Animals.Add("alpaca", false);
                Animals.Add("ant", false);
                Animals.Add("anteater", false);
                Animals.Add("antelope", false);
                Animals.Add("ape", false);
                Animals.Add("armadillo", false);
                Animals.Add("ass", false);
                Animals.Add("baboon", false);
                Animals.Add("badger", false);
                Animals.Add("barracuda", false);
                Animals.Add("bat", false);
                Animals.Add("bear", false);
                Animals.Add("beaver", false);
                Animals.Add("bee", false);
                Animals.Add("bison", false);
                Animals.Add("boar", false);
                Animals.Add("buffalo", false);
                Animals.Add("butterfly", false);
                Animals.Add("camel", false);
                Animals.Add("caribou", false);
                Animals.Add("cat", false);
                Animals.Add("caterpillar", false);
                Animals.Add("cow", false);
                Animals.Add("chamois", false);
                Animals.Add("cheetah", false);
                Animals.Add("chicken", false);
                Animals.Add("chimpanzee", false);
                Animals.Add("chinchilla", false);
                Animals.Add("chough", false);
                Animals.Add("clam", false);
                Animals.Add("cobra", false);
                Animals.Add("cockroach", false);
                Animals.Add("cod", false);
                Animals.Add("cormorant", false);
                Animals.Add("coyote", false);
                Animals.Add("crab", false);
                Animals.Add("crane", false);
                Animals.Add("crocodile", false);
                Animals.Add("crow", false);
                Animals.Add("curlew", false);
                Animals.Add("deer", false);
                Animals.Add("dinosaur", false);
                Animals.Add("dog", false);
                Animals.Add("dogfish", false);
                Animals.Add("dolphin", false);
                Animals.Add("donkey", false);
                Animals.Add("dotterel", false);
                Animals.Add("dove", false);
                Animals.Add("dragonfly", false);
                Animals.Add("duck", false);
                Animals.Add("dugong", false);
                Animals.Add("dunlin", false);
                Animals.Add("eagle", false);
                Animals.Add("echidna", false);
                Animals.Add("eel", false);
                Animals.Add("eland", false);
                Animals.Add("elephant", false);
                Animals.Add("elephant seal", false);
                Animals.Add("elk", false);
                Animals.Add("emu", false);
                Animals.Add("falcon", false);
                Animals.Add("ferret", false);
                Animals.Add("finch", false);
                Animals.Add("fish", false);
                Animals.Add("flamingo", false);
                Animals.Add("fly", false);
                Animals.Add("fox", false);
                Animals.Add("frog", false);
                Animals.Add("galago", false);
                Animals.Add("gaur", false);
                Animals.Add("gazelle", false);
                Animals.Add("gerbil", false);
                Animals.Add("giant panda", false);
                Animals.Add("giraffe", false);
                Animals.Add("gnat", false);
                Animals.Add("gnu", false);
                Animals.Add("goat", false);
                Animals.Add("goldfinch", false);
                Animals.Add("goldfish", false);
                Animals.Add("goose", false);
                Animals.Add("gorilla", false);
                Animals.Add("goshawk", false);
                Animals.Add("grasshopper", false);
                Animals.Add("grouse", false);
                Animals.Add("guanaco", false);
                Animals.Add("guineafowl", false);
                Animals.Add("guinea pig", false);
                Animals.Add("gull", false);
                Animals.Add("hamster", false);
                Animals.Add("hare", false);
                Animals.Add("hawk", false);
                Animals.Add("hedgehog", false);
                Animals.Add("heron", false);
                Animals.Add("herring", false);
                Animals.Add("hippopotamus", false);
                Animals.Add("hornet", false);
                Animals.Add("horse", false);
                Animals.Add("human", false);
                Animals.Add("humming bird", false);
                Animals.Add("hyena", false);
                Animals.Add("jackal", false);
                Animals.Add("jaguar", false);
                Animals.Add("jay", false);
                Animals.Add("jellyfish", false);
                Animals.Add("kangaroo", false);
                Animals.Add("koala", false);
                Animals.Add("komodo dragon", false);
                Animals.Add("kouprey", false);
                Animals.Add("kudu", false);
                Animals.Add("lizard", false);
                Animals.Add("lark", false);
                Animals.Add("lemur", false);
                Animals.Add("leopard", false);
                Animals.Add("lion", false);
                Animals.Add("llama", false);
                Animals.Add("lobster", false);
                Animals.Add("locust", false);
                Animals.Add("loris", false);
                Animals.Add("louse", false);
                Animals.Add("lyrebird", false);
                Animals.Add("magpie", false);
                Animals.Add("mallard", false);
                Animals.Add("manatee", false);
                Animals.Add("marten", false);
                Animals.Add("meerkat", false);
                Animals.Add("mink", false);
                Animals.Add("mole", false);
                Animals.Add("monkey", false);
                Animals.Add("moose", false);
                Animals.Add("mosquito", false);
                Animals.Add("mouse", false);
                Animals.Add("mule", false);
                Animals.Add("narwhal", false);
                Animals.Add("newt", false);
                Animals.Add("nightingale", false);
                Animals.Add("octopus", false);
                Animals.Add("okapi", false);
                Animals.Add("opossum", false);
                Animals.Add("oryx", false);
                Animals.Add("ostrich", false);
                Animals.Add("otter", false);
                Animals.Add("owl", false);
                Animals.Add("ox", false);
                Animals.Add("oyster", false);
                Animals.Add("panther", false);
                Animals.Add("parrot", false);
                Animals.Add("partridge", false);
                Animals.Add("peafowl", false);
                Animals.Add("pelican", false);
                Animals.Add("penguin", false);
                Animals.Add("pheasant", false);
                Animals.Add("pig", false);
                Animals.Add("pigeon", false);
                Animals.Add("pony", false);
                Animals.Add("porcupine", false);
                Animals.Add("porpoise", false);
                Animals.Add("prairie dog", false);
                Animals.Add("quail", false);
                Animals.Add("quelea", false);
                Animals.Add("rabbit", false);
                Animals.Add("raccoon", false);
                Animals.Add("rail", false);
                Animals.Add("ram", false);
                Animals.Add("rat", false);
                Animals.Add("raven", false);
                Animals.Add("red deer", false);
                Animals.Add("red panda", false);
                Animals.Add("reindeer", false);
                Animals.Add("rhinoceros", false);
                Animals.Add("rook", false);
                Animals.Add("ruff", false);
                Animals.Add("salamander", false);
                Animals.Add("salmon", false);
                Animals.Add("sand dollar", false);
                Animals.Add("sandpiper", false);
                Animals.Add("sardine", false);
                Animals.Add("scorpion", false);
                Animals.Add("sea lion", false);
                Animals.Add("sea urchin", false);
                Animals.Add("seahorse", false);
                Animals.Add("seal", false);
                Animals.Add("shark", false);
                Animals.Add("sheep", false);
                Animals.Add("shrew", false);
                Animals.Add("shrimp", false);
                Animals.Add("skunk", false);
                Animals.Add("snail", false);
                Animals.Add("snake", false);
                Animals.Add("spider", false);
                Animals.Add("squid", false);
                Animals.Add("squirrel", false);
                Animals.Add("starling", false);
                Animals.Add("stingray", false);
                Animals.Add("stink bug", false);
                Animals.Add("stork", false);
                Animals.Add("swallow", false);
                Animals.Add("swan", false);
                Animals.Add("tapir", false);
                Animals.Add("tarsier", false);
                Animals.Add("termite", false);
                Animals.Add("tiger", false);
                Animals.Add("toad", false);
                Animals.Add("trout", false);
                Animals.Add("turkey", false);
                Animals.Add("turtle", false);
                Animals.Add("vicuña", false);
                Animals.Add("viper", false);
                Animals.Add("vulture", false);
                Animals.Add("wallaby", false);
                Animals.Add("walrus", false);
                Animals.Add("wasp", false);
                Animals.Add("water buffalo", false);
                Animals.Add("weasel", false);
                Animals.Add("whale", false);
                Animals.Add("wolf", false);
                Animals.Add("wolverine", false);
                Animals.Add("wombat", false);
                Animals.Add("woodcock", false);
                Animals.Add("woodpecker", false);
                Animals.Add("worm", false);
                Animals.Add("wren", false);
                Animals.Add("yak", false);
                Animals.Add("zebra", false);
                Animals.Add("bird", false);

                LoadGuesses("Animals");
            }

            #endregion

            public static string Category = null;

            public static void LoadGuesses(string dictionaryToLoad)
            {
                if (!Directory.Exists(Paths.KnowledgeInput))
                {
                    Directory.CreateDirectory(Paths.KnowledgeInput);
                }
                switch (dictionaryToLoad)
                {
                    case "Animals":
                        if (!File.Exists(Paths.KnowledgeInput + "/animals.json"))
                        {
                            string json = JsonConvert.SerializeObject(Animals);
                            File.WriteAllText(Paths.KnowledgeInput + "/animals.json", json);
                        }
                        else
                        {
                            string json = File.ReadAllText(Paths.KnowledgeInput + "/animals.json");
                            Animals = JsonConvert.DeserializeObject<Dictionary<string, bool>>(json);
                        }
                        break;
                }
            }

            public static string Guess(string guess)
            {
                switch (Category)
                {
                    case "Animals":
                        try
                        {
                            if (Animals[guess.ToLower()] == true)
                            {
                                return "already_guessed";
                            }
                            else
                            {
                                Animals[guess.ToLower()] = true;
                                return "success";
                            }
                        }
                        catch
                        {
                            API.LogException("User didn't guess a valid knowledge input guess.", false);
                            return "not_valid";
                        }
                    default:
                        return "not_valid";
                }
            }
            public static void SaveGuesses()
            {
                string json = JsonConvert.SerializeObject(Animals);
                File.WriteAllText(Paths.KnowledgeInput + "/animals.json", json);
            }

            public static int GetRightGuesses()
            {
                int guesses = 0;
                switch (Category)
                {
                    case "Animals":
                        foreach (KeyValuePair<string, bool> kv in Animals)
                        {
                            if (Animals[kv.Key] == true)
                            {
                                guesses += 1;
                            }
                        }
                        break;
                }


                return guesses;
            }

            public static int GetLengthOfPossible()
            {
                int len = 0;
                switch (Category)
                {
                    case "Animals":
                        len = Animals.Count;
                        break;
                    default:
                        len = 0;
                        break;
                }


                return len;
            }
        }


        /// <summary>
        /// Opens a program. Used by the Terminal, and Lua.
        /// </summary>
        /// <param name="cmd">Program to open.</param>
        /// <returns>Whether the program could be opened.</returns>
        public static bool OpenProgram(string cmd)
        {
            bool succeeded = true;
            switch (cmd)
            {

                case "settings":
                    API.CreateForm(new GameSettings(), "Settings", API.GetIcon("Settings"));
                    break;
                case "credits":
                    var c = new CreditScroller();
                    c.FormBorderStyle = FormBorderStyle.None;
                    c.Show();
                    c.WindowState = FormWindowState.Maximized;
                    c.TopMost = true;
                    break;
                case "netbrowse":
                    if(Upgrades["networkbrowser"])
                    {
                        CreateForm(new NetworkBrowser(), "Network Browser", GetIcon("NetworkBrowser"));
                    }
                    else
                    {
                        succeeded = false;
                    }
                    break;
                case "quests":
                    if(LimitedMode)
                    {
                        CreateForm(new FinalMission.QuestViewer(), "Quest Viewer", GetIcon("QuestViewer"));
                    }
                    else
                    {
                        succeeded = false;
                    }
                    break;
                case "iconmanager":
                    if (!LimitedMode)
                    {
                        if (API.Upgrades["iconmanager"])
                        {
                            CreateForm(new IconManager(), "Icon Manager", GetIcon("IconManager"));
                            
                        }
                        else
                        {
                            succeeded = false;
                        }
                    }
                    else
                    {
                        succeeded = false;
                    }
                    break;
                case "knowledge_input":
                case "ki":
                    if (!LimitedMode)
                    {
                        API.CreateForm(new KnowledgeInput(), API.LoadedNames.KnowledgeInputName, GetIcon("KI"));
                    }
                    else
                    {
                        succeeded = false;
                    }
                    break;
                case "holochat":
                    if(API.Upgrades["holochat"] == true)
                    {
                        API.CreateForm(new HoloChat(), "HoloChat", GetIcon("HoloChat"));
                    }
                    else
                    {
                        succeeded = false;
                    }
                    break;
                case "namechanger":
                case "name_changer":
                    if (!LimitedMode)
                    {
                        if (API.Upgrades["namechanger"] == true)
                        {
                            CreateForm(new NameChanger(), LoadedNames.NameChangerName, GetIcon("NameChanger"));
                        }
                        else
                        {
                            succeeded = false;
                        }
                    }
                    else
                    {
                        succeeded = false;
                    }
                    break;
                case "artpad":
                    if (!LimitedMode)
                    {
                        if (API.Upgrades["artpad"] == true)
                        {
                            CreateForm(new Artpad(), LoadedNames.ArtpadName, GetIcon("Artpad"));
                        }
                        else
                        {
                            succeeded = false;
                        }
                    }
                    else
                    {
                        succeeded = false;
                    }
                    break;
                case "textpad":
                    if(Upgrades["textpad"] == true)
                    {
                        CreateForm(new TextPad(), "TextPad", GetIcon("TextPad"));
                    } else
                    {
                        succeeded = false;
                    }
                    break;
                case "skinloader":
                case "skin_loader":
                    if (!LimitedMode)
                    {
                        if (Upgrades["skinning"] == true)
                        {
                            CreateForm(new SkinLoader(), "Skin Loader", GetIcon("SkinLoader"));
                        }
                        else
                        {
                            succeeded = false;
                        }
                    }
                    else
                    {
                        succeeded = false;
                    }
                    break;
                case "shifter":
                    if (!LimitedMode)
                    {
                        if (Upgrades["shifter"] == true)
                        {
                            CreateForm(new Shifter(), "Shifter", GetIcon("Shifter"));
                        }
                        else
                        {
                            succeeded = false;
                        }
                    }
                    else
                    {
                        succeeded = false;
                    }
                    break;
                case "pong":
                    if (!LimitedMode)
                    {
                        if (Upgrades["pong"] == true)
                        {
                            CreateForm(new Pong(), "Pong", GetIcon("Pong"));
                        }
                        else
                        {
                            succeeded = false;
                        }
                    }
                    else
                    {
                        succeeded = false;
                    }
                    break;
                case "file_skimmer":
                    if (Upgrades["fileskimmer"] == true)
                    {
                        CreateForm(new File_Skimmer(), CurrentSave.FileSkimmerName, GetIcon("FileSkimmer"));
                    }
                    else
                    {
                        succeeded = false;
                    }
                    break;
                case "shiftorium":
                    if (!LimitedMode)
                    {
                        CreateForm(new Shiftorium.Frontend(), LoadedNames.ShiftoriumName, GetIcon("Shiftorium"));
                    }
                    else
                    {
                        succeeded = false;
                    }
                    break;
                default:
                    succeeded = false;
                    break;

            }
            return succeeded;

        }

        /// <summary>
        /// Creates a new color picker session.
        /// </summary>
        /// <param name="colorToChange">The name displayed on the top.</param>
        /// <param name="oldColor">The old color displayed on the Cancel button.</param>
        public static void CreateColorPickerSession(string colorToChange, Color oldColor)
        {
            Color_Picker cp = new Color_Picker(colorToChange, oldColor);
            CreateForm(cp, CurrentSave.ColorPickerName, Properties.Resources.iconColourPicker_fw);
            ColorPickerSession = cp;
        }

        /// <summary>
        /// Gets the color picked by the user. Call this during the close event of a Color Picker.
        /// </summary>
        /// <returns>The user's choice.</returns>
        public static Color GetLastColorFromSession()
        {
            Color lastcol = Color.Black;
            if (ColorPickerSession != null)
            {
                switch (ColorPickerSession.Result)
                {
                    case "OK":
                        lastcol = ColorPickerSession.NewColor;
                        break;
                    default:
                        lastcol = ColorPickerSession.oldcolour;
                        break;
                }
            }
            else
            {
                throw new InvalidSessionException("A valid Color Picker session wasn't found.");
            }
            return lastcol;
        }

        public static Color_Picker ColorPickerSession = null;

        #region "I don't want to be seen."
        public static Color lastcolourpick = Color.White;

        public static Color[] anymemory = new Color[16];
        public static Color[] redmemory = new Color[16];
        public static Color[] greenmemory = new Color[16];
        public static Color[] bluememory = new Color[16];
        public static Color[] orangememory = new Color[16];
        public static Color[] brownmemory = new Color[16];
        public static Color[] purplememory = new Color[16];
        public static Color[] graymemory = new Color[16];
        public static Color[] yellowmemory = new Color[16];
        public static Color[] pinkmemory = new Color[16];
        internal static Dictionary<string, Dictionary<string, object>> LuaShifterRegistry = null;

        #endregion
    }

    public class InvalidSessionException : Exception
    {
        public InvalidSessionException() : base("ShiftOS could not perform actions on an application session, because the session is invalid. Try checking if the session is not 'null' before performing actions on it through the API.")
        {

        }

        public InvalidSessionException(string inner) : base("ShiftOS could not perform actions on an application session, because the session is invalid. Try checking if the session is not 'null' before performing actions on it through the API.", new Exception(inner))
        {

        }
    }

    public class ModNotFoundException : Exception
    {
        public ModNotFoundException() : base("Could not find the mod file specified.")
        {

        }
    }
}