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
|
/*
* MIT License
*
* Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#define DEVEL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using ShiftOS.Engine.Properties;
using System.IO;
using Newtonsoft.Json;
using System.IO.Compression;
using ShiftOS.Objects;
using Discoursistency.Base.Models.Authentication;
using ShiftOS.Engine.Scripting;
using ShiftOS.Objects.ShiftFS;
namespace ShiftOS.Engine
{
[RequiresUpgrade("desktop;wm_free_placement")]
public static class InfoboxDebugCommands
{
[RequiresArgument("title")]
[RequiresArgument("msg")]
[Command("show")]
public static bool ShowInfo(Dictionary<string, object> args)
{
Desktop.InvokeOnWorkerThread(new Action(() =>
{
Infobox.Show(args["title"].ToString(), args["msg"].ToString());
}));
return true;
}
[RequiresArgument("title")]
[RequiresArgument("msg")]
[Command("yesno")]
public static bool ShowYesNo(Dictionary<string, object> args)
{
bool forwarding = TerminalBackend.IsForwardingConsoleWrites;
var fGuid = TerminalBackend.ForwardGUID;
Action<bool> callback = (result) =>
{
TerminalBackend.IsForwardingConsoleWrites = forwarding;
TerminalBackend.ForwardGUID = (forwarding == true) ? fGuid : null;
string resultFriendly = (result == true) ? "yes" : "no";
Console.WriteLine($"{SaveSystem.CurrentUser.Username} says {resultFriendly}.");
TerminalBackend.IsForwardingConsoleWrites = false;
};
Desktop.InvokeOnWorkerThread(new Action(() =>
{
Infobox.PromptYesNo(args["title"].ToString(), args["msg"].ToString(), callback);
}));
return true;
}
[RequiresArgument("title")]
[RequiresArgument("msg")]
[Command("text")]
public static bool ShowText(Dictionary<string, object> args)
{
bool forwarding = TerminalBackend.IsForwardingConsoleWrites;
var fGuid = TerminalBackend.ForwardGUID;
Action<string> callback = (result) =>
{
TerminalBackend.IsForwardingConsoleWrites = forwarding;
TerminalBackend.ForwardGUID = (forwarding == true) ? fGuid : null;
Console.WriteLine($"{SaveSystem.CurrentUser.Username} says \"{result}\".");
TerminalBackend.IsForwardingConsoleWrites = false;
};
Desktop.InvokeOnWorkerThread(new Action(() =>
{
Infobox.PromptText(args["title"].ToString(), args["msg"].ToString(), callback);
}));
return true;
}
}
public static class AudioCommands
{
[Command("setvol", description = "Set the volume of the system audio to anywhere between 0 and 100.")]
[RequiresArgument("value")]
[RequiresUpgrade("audio_volume")]
public static bool SetVolume(Dictionary<string,object> args)
{
int val = Convert.ToInt32(args["value"].ToString());
float volume = (val / 100F);
AudioManager.SetVolume(volume);
return true;
}
[RequiresUpgrade("audio_volume")]
[Command("mute", description = "Sets the volume of the system audio to 0")]
public static bool MuteAudio()
{
AudioManager.SetVolume(0);
return true;
}
}
[TutorialLock]
public static class TerminalCommands
{
[Command("clear")]
public static bool Clear()
{
AppearanceManager.ConsoleOut.Clear();
return true;
}
[Command("echo")]
[RequiresArgument("text")]
public static bool Echo(Dictionary<string, object> args)
{
Console.WriteLine(args["text"]);
return true;
}
}
public static class ShiftOSCommands
{
[Command("setsfxenabled", description = "Set whether or not sound effects are enabled in the system.")]
[RequiresArgument("value")]
public static bool SetSfxEnabled(Dictionary<string, object> args)
{
try
{
bool value = Convert.ToBoolean(args["value"].ToString());
SaveSystem.CurrentSave.SoundEnabled = value;
SaveSystem.SaveGame();
}
catch
{
Console.WriteLine("Error: Value must be either true or false.");
}
return true;
}
[Command("setmusicenabled", description = "Set whether or not music is enabled in the system.")]
[RequiresArgument("value")]
public static bool SetMusicEnabled(Dictionary<string, object> args)
{
try
{
bool value = Convert.ToBoolean(args["value"].ToString());
SaveSystem.CurrentSave.MusicEnabled = value;
SaveSystem.SaveGame();
}
catch
{
Console.WriteLine("Error: Value must be either true or false.");
}
return true;
}
[Command("setsfxvolume", description ="Set the system sound volume to a value between 1 and 100.")]
[RequiresArgument("value")]
public static bool SetSfxVolume(Dictionary<string, object> args)
{
int value = int.Parse(args["value"].ToString());
if(value >= 0 && value <= 100)
{
SaveSystem.CurrentSave.MusicVolume = value;
SaveSystem.SaveGame();
}
else
{
Console.WriteLine("Volume must be between 0 and 100!");
}
return true;
}
[RemoteLock]
[Command("shutdown")]
public static bool Shutdown()
{
TerminalBackend.InvokeCommand("sos.save");
AppearanceManager.Exit();
return true;
}
[Command("lang", "{COMMAND_SOS_LANG_USAGE}", "{COMMAND_SOS_LANG_DESCRIPTION}")]
[RequiresArgument("language")]
public static bool SetLanguage(Dictionary<string, object> userArgs)
{
try
{
string lang = "";
if (userArgs.ContainsKey("language"))
lang = (string)userArgs["language"];
else
throw new Exception("You must specify a valid 'language' value.");
if (Localization.GetAllLanguages().Contains(lang))
{
SaveSystem.CurrentSave.Language = lang;
SaveSystem.SaveGame();
Console.WriteLine("{LANGUAGE_CHANGED}");
return true;
}
throw new Exception($"Couldn't find language with ID: {lang}");
}
catch
{
return false;
}
}
[Command("commands", "", "{COMMAND_COMMANDS_DESCRIPTION}")]
public static bool Commands()
{
var sb = new StringBuilder();
sb.AppendLine("Commands");
sb.AppendLine("=================");
sb.AppendLine();
//print all unique namespaces.
foreach (var n in TerminalBackend.Commands.Where(x => !(x is TerminalBackend.WinOpenCommand) && Shiftorium.UpgradeInstalled(x.Dependencies) && x.CommandInfo.hide == false).OrderBy(x => x.CommandInfo.name))
{
sb.Append(n.CommandInfo.name);
if (!string.IsNullOrWhiteSpace(n.CommandInfo.description))
if (Shiftorium.UpgradeInstalled("help_descriptions"))
sb.Append(" - " + n.CommandInfo.description);
sb.AppendLine();
}
Console.WriteLine(sb.ToString());
return true;
}
[Command("help", description = "Type this command to list all the things you can do in ShiftOS.")]
public static bool Help()
{
Commands();
WindowCommands.Programs();
return true;
}
[MultiplayerOnly]
[Command("save")]
public static bool Save()
{
SaveSystem.SaveGame();
return true;
}
[MultiplayerOnly]
[Command("status")]
public static bool Status()
{
string status = $@"ShiftOS version {Assembly.GetExecutingAssembly().GetName().Version.ToString()}
Codepoints: {SaveSystem.CurrentSave.Codepoints}
Upgrades: {SaveSystem.CurrentSave.CountUpgrades()} installed,
{Shiftorium.GetAvailable().Length} available
";
Console.WriteLine(status);
Console.WriteLine("Objectives:");
try
{
if (Story.CurrentObjectives.Count > 0)
{
foreach (var obj in Story.CurrentObjectives)
{
Console.WriteLine(obj.Name);
Console.WriteLine("-------------------------------");
Console.WriteLine();
Console.WriteLine(obj.Description);
}
}
else
{
Console.WriteLine(" - No objectives are running. Check back later!");
}
}
catch
{
Console.WriteLine(" - No objectives are running. Check back later!");
}
return true;
}
}
[MultiplayerOnly]
public static class ShiftoriumCommands
{
[Command("buy")]
[RequiresArgument("upgrade")]
public static bool BuyUpgrade(Dictionary<string, object> userArgs)
{
try
{
string upgrade = "";
if (userArgs.ContainsKey("upgrade"))
upgrade = (string)userArgs["upgrade"];
else
throw new Exception("You must specify a valid 'upgrade' value.");
foreach (var upg in Shiftorium.GetAvailable())
{
if (upg.ID == upgrade)
{
Shiftorium.Buy(upgrade, upg.Cost);
return true;
}
}
throw new Exception($"Couldn't find upgrade with ID: {upgrade}");
}
catch
{
return false;
}
}
[RequiresUpgrade("shiftorium_bulk_buy")]
[Command("bulkbuy")]
[RequiresArgument("upgrades")]
public static bool BuyBulk(Dictionary<string, object> args)
{
if (args.ContainsKey("upgrades"))
{
string[] upgrade_list = (args["upgrades"] as string).Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
foreach (var upg in upgrade_list)
{
var dict = new Dictionary<string, object>();
dict.Add("upgrade", upg);
BuyUpgrade(dict);
}
}
else
{
throw new Exception("Please specify a list of upgrades in the 'upgrades' argument. Each upgrade is separated by a comma.");
}
return true;
}
[Command("upgradeinfo", description ="Shows information about a specific upgrade.")]
[RequiresArgument("upgrade")]
public static bool ViewInfo(Dictionary<string, object> userArgs)
{
try
{
string upgrade = "";
if (userArgs.ContainsKey("upgrade"))
upgrade = (string)userArgs["upgrade"];
else
throw new Exception("You must specify a valid 'upgrade' value.");
foreach (var upg in Shiftorium.GetDefaults())
{
if (upg.ID == upgrade)
{
Console.WriteLine($@"Information for {upgrade}:
{upg.Category}: {upg.Name} - {upg.Cost} Codepoints
------------------------------------------------------
{upg.Description}
To buy this upgrade, run:
shiftorium.buy{{upgrade:""{upg.ID}""}}");
return true;
}
}
throw new Exception($"Couldn't find upgrade with ID: {upgrade}");
}
catch
{
return false;
}
}
[Command("upgradecategories", description = "Shows all available Shiftorium upgrade categories, and how many upgrades are available in them.")]
public static bool ListCategories()
{
foreach(var cat in Shiftorium.GetCategories())
{
Console.WriteLine($"{cat} - {Shiftorium.GetAvailable().Where(x=>x.Category==cat).Count()} upgrades");
}
return true;
}
[Command("upgrades", description ="Lists all available Shiftorium upgrades.")]
public static bool ListAll(Dictionary<string, object> args)
{
try
{
bool showOnlyInCategory = false;
string cat = "Other";
if (args.ContainsKey("cat"))
{
showOnlyInCategory = true;
cat = args["cat"].ToString();
}
Dictionary<string, ulong> upgrades = new Dictionary<string, ulong>();
int maxLength = 5;
IEnumerable<ShiftoriumUpgrade> upglist = Shiftorium.GetAvailable();
if (showOnlyInCategory)
{
if (Shiftorium.IsCategoryEmptied(cat))
{
ConsoleEx.Bold = true;
ConsoleEx.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Shiftorium Query Error");
Console.WriteLine();
ConsoleEx.Bold = false;
ConsoleEx.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine("Either there are no upgrades in the category \"" + cat + "\" or the category was not found.");
return true;
}
upglist = Shiftorium.GetAvailable().Where(x => x.Category == cat);
}
if(upglist.Count() == 0)
{
ConsoleEx.Bold = true;
ConsoleEx.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("No upgrades available!");
Console.WriteLine();
ConsoleEx.Bold = false;
ConsoleEx.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine("You have installed all available upgrades for your system. Please check back later for more.");
return true;
}
foreach (var upg in upglist)
{
if (upg.ID.Length > maxLength)
{
maxLength = upg.ID.Length;
}
upgrades.Add(upg.ID, upg.Cost);
}
Console.WriteLine("ID".PadRight((maxLength + 5) - 2) + "Cost (Codepoints)");
foreach (var upg in upgrades)
{
Console.WriteLine(upg.Key.PadRight((maxLength + 5) - upg.Key.Length) + " " + upg.Value.ToString());
}
return true;
}
catch (Exception e)
{
CrashHandler.Start(e);
return false;
}
}
}
public static class WindowCommands
{
[RemoteLock]
[Command("processes", description = "Shows all running applications.")]
public static bool List()
{
Console.WriteLine("Window ID\tName");
foreach (var app in AppearanceManager.OpenForms)
{
//Windows are displayed the order in which they were opened.
Console.WriteLine($"{AppearanceManager.OpenForms.IndexOf(app)}\t{app.Text}");
}
return true;
}
[Command("programs", description = "Lists all the programs installed in ShiftOS.")]
public static bool Programs()
{
Console.WriteLine("Programs:");
Console.WriteLine("===============");
Console.WriteLine();
foreach(var cmd in TerminalBackend.Commands.Where(x=>x is TerminalBackend.WinOpenCommand && Shiftorium.UpgradeInstalled(x.Dependencies)).OrderBy(x => x.CommandInfo.name))
{
Console.Write(" - " + cmd.CommandInfo.name);
if (!string.IsNullOrWhiteSpace(cmd.CommandInfo.description))
if (Shiftorium.UpgradeInstalled("help_descriptions"))
Console.Write(": " + cmd.CommandInfo.description);
Console.WriteLine();
}
return true;
}
[RemoteLock]
[Command("close", usage = "{win:integer32}", description ="Closes the specified window.")]
[RequiresArgument("win")]
[RequiresUpgrade("close_command")]
public static bool CloseWindow(Dictionary<string, object> args)
{
int winNum = -1;
if (args.ContainsKey("win"))
winNum = Convert.ToInt32(args["win"].ToString());
string err = null;
if (winNum < 0 || winNum >= AppearanceManager.OpenForms.Count)
err = "The window number must be between 0 and " + (AppearanceManager.OpenForms.Count - 1).ToString() + ".";
if (string.IsNullOrEmpty(err))
{
Console.WriteLine($"Closing {AppearanceManager.OpenForms[winNum].Text}...");
AppearanceManager.Close(AppearanceManager.OpenForms[winNum].ParentWindow);
}
else
{
Console.WriteLine(err);
}
return true;
}
}
}
|