forked from forkification/OpenHacknet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFastDelayableActionSystem.cs
More file actions
165 lines (154 loc) · 4.65 KB
/
FastDelayableActionSystem.cs
File metadata and controls
165 lines (154 loc) · 4.65 KB
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
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Xml;
namespace Hacknet
{
// Token: 0x02000021 RID: 33
public class FastDelayableActionSystem : DelayableActionSystem
{
// Token: 0x060000D6 RID: 214 RVA: 0x0000D978 File Offset: 0x0000BB78
public FastDelayableActionSystem(Folder sourceFolder, object osObj)
{
FastDelayableActionSystem <>4__this = this;
this.folder = sourceFolder;
OS os = (OS)osObj;
os.UpdateSubscriptions = (Action<float>)Delegate.Combine(os.UpdateSubscriptions, new Action<float>(delegate(float t)
{
<>4__this.Update(t, (OS)osObj);
}));
}
// Token: 0x060000D7 RID: 215 RVA: 0x0000D9F0 File Offset: 0x0000BBF0
private void Update(float t, object osObj)
{
for (int i = 0; i < this.Actions.Count; i++)
{
try
{
float num = this.Actions[i].Key;
SerializableAction value = this.Actions[i].Value;
num -= t;
if (num <= 0f)
{
try
{
value.Trigger((OS)osObj);
}
catch (Exception ex)
{
((OS)osObj).write(Utils.GenerateReportFromException(ex));
Utils.AppendToErrorFile(Utils.GenerateReportFromException(ex));
}
this.Actions.RemoveAt(i);
i--;
}
else
{
this.Actions[i] = new KeyValuePair<float, SerializableAction>(num, value);
}
}
catch (Exception)
{
}
}
}
// Token: 0x060000D8 RID: 216 RVA: 0x0000DAE8 File Offset: 0x0000BCE8
public override void InstantlyResolveAllActions(object osObj)
{
for (int i = 0; i < this.Actions.Count; i++)
{
try
{
this.Actions[i].Value.Trigger(osObj);
this.Actions.RemoveAt(i);
i--;
}
catch (Exception ex)
{
((OS)osObj).write(Utils.GenerateReportFromException(ex));
Utils.AppendToErrorFile(Utils.GenerateReportFromException(ex));
}
}
}
// Token: 0x060000D9 RID: 217 RVA: 0x0000DB78 File Offset: 0x0000BD78
public override void AddAction(SerializableAction action, float delay)
{
this.Actions.Add(new KeyValuePair<float, SerializableAction>(delay, action));
}
// Token: 0x060000DA RID: 218 RVA: 0x0000DB90 File Offset: 0x0000BD90
private FileEntry EncryptAction(SerializableAction action, float delay)
{
string str = FileEncrypter.EncryptString(action.GetSaveString(), "das", "UNKNOWN", FastDelayableActionSystem.EncryptionPass, null);
string dataEntry = delay.ToString("0.0000000000", CultureInfo.InvariantCulture) + "\n" + str;
FileEntry result = new FileEntry(dataEntry, this.SeqNum.ToString("000") + ".act");
this.SeqNum++;
return result;
}
// Token: 0x060000DB RID: 219 RVA: 0x0000DC0C File Offset: 0x0000BE0C
public List<FileEntry> GetAllFilesForActions()
{
this.SeqNum = 0;
List<FileEntry> list = new List<FileEntry>();
for (int i = 0; i < this.Actions.Count; i++)
{
list.Add(this.EncryptAction(this.Actions[i].Value, this.Actions[i].Key));
}
return list;
}
// Token: 0x060000DC RID: 220 RVA: 0x0000DC80 File Offset: 0x0000BE80
public void DeserializeActions(List<FileEntry> files)
{
this.Actions.Clear();
for (int i = 0; i < files.Count; i++)
{
try
{
string data = this.folder.files[i].data;
int num = data.IndexOf('\n');
string value = data.Substring(0, num);
string data2 = data.Substring(num + 1);
float key = (float)Convert.ToDouble(value, CultureInfo.InvariantCulture);
string s = FileEncrypter.DecryptString(data2, FastDelayableActionSystem.EncryptionPass)[2];
using (Stream stream = Utils.GenerateStreamFromString(s))
{
try
{
XmlReader rdr = XmlReader.Create(stream);
SerializableAction value2 = SerializableAction.Deserialize(rdr);
this.Actions.Add(new KeyValuePair<float, SerializableAction>(key, value2));
}
catch (Exception ex)
{
if (OS.DEBUG_COMMANDS)
{
Utils.AppendToWarningsFile("Error deserializing action in fast action host :\n" + Utils.GenerateReportFromExceptionCompact(ex));
}
}
}
}
catch (Exception ex)
{
if (OS.DEBUG_COMMANDS)
{
Utils.AppendToWarningsFile(string.Concat(new object[]
{
"Error deserializing action ",
i,
" in fast action host :\n",
Utils.GenerateReportFromExceptionCompact(ex)
}));
}
}
}
}
// Token: 0x040000EA RID: 234
private static string EncryptionPass = "dasencrypt";
// Token: 0x040000EB RID: 235
private Folder folder;
// Token: 0x040000EC RID: 236
internal List<KeyValuePair<float, SerializableAction>> Actions = new List<KeyValuePair<float, SerializableAction>>();
// Token: 0x040000ED RID: 237
private int SeqNum = 0;
}
}