This repository has been archived by the owner on Oct 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
artifact req capture.linq
249 lines (230 loc) · 9.86 KB
/
artifact req capture.linq
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
<Query Kind="Program">
<NuGetReference>FiddlerCore2</NuGetReference>
<NuGetReference>morelinq</NuGetReference>
<NuGetReference>protobuf-net</NuGetReference>
<NuGetReference>Rx-Main</NuGetReference>
<Namespace>Fiddler</Namespace>
<Namespace>MoreLinq</Namespace>
<Namespace>ProtoBuf</Namespace>
<Namespace>System.Reactive.Disposables</Namespace>
<Namespace>System.Reactive.Linq</Namespace>
</Query>
void Main()
{
Util.Cleanup += (s,e) => FiddlerApplication.Shutdown();
var artifactsAOB = Encoding.UTF8.GetBytes("Artififacts").ToHashSet();
ObserveSession()
.Where(x => x.LocalProcess.StartsWith("astroflux"))
.Where(x => x.fullUrl.StartsWith("https://api.playerio.com/api/85"))
.Where(x => artifactsAOB.IsSubsetOf(x.RequestBody))
.SelectMany(session =>
{
try
{
return Artifact.Parse(session.ResponseBody);
}
catch (Exception e)
{
string.Join("\n", session.RequestBody.Batch(16)
.Select(line => string.Join(" ", line.Select(b => b.ToString("X2")))))
.Dump("RequestBody");
string.Join("\n", session.ResponseBody.Batch(16)
.Select(line => string.Join(" ", line.Select(b => b.ToString("X2")))))
.Dump("ResponseBody");
throw;
}
})
.Dump();
}
// Define other methods and classes here
public IObservable<Session> ObserveSession()
{
return Observable.Create<Session>(o =>
{
FiddlerApplication.AfterSessionComplete += o.OnNext;
FiddlerApplication.Startup(8889, FiddlerCoreStartupFlags.Default);
return Disposable.Create(() => FiddlerApplication.Shutdown());
});
}
public class Artifact
{
internal string ID { get; set; }
public string Name { get; set; }
internal string Bitmap { get; set; }
public int LevelPotential { get; set; }
public int Level { get; set; }
public bool Revealed { get; set; }
internal bool Upgraded { get; set; }
internal List<ArtifactAttribute> Attributes { get; set; }
public Dictionary<string, double> Stats => Attributes.GroupBy(x => x.BaseType).ToDictionary(g => g.Key, g => g.Sum(x => x.Value));
public static Artifact FromBigDbObject(BigDbObject data)
{
return new Artifact
{
ID = data.Key,
Name = data.Properties["name"].Text,
Bitmap = data.Properties["bitmap"].Text,
Level = data.Properties["level"].Integer,
LevelPotential = data.Properties["levelPotential"].Integer,
Revealed = data.Properties["revealed"].Bool,
Attributes = data.Properties["stats"].Array.Values
.Select(x => x.Object.Value)
.Select(x => ArtifactAttribute.Create(x.Text, x.Double))
.ToList()
};
}
public static Artifact[] Parse(byte[] data)
{
using (var stream = new MemoryStream(data))
using (var reader = new BinaryReader(stream))
{
var token = default(string);
if (reader.ReadByte() != 0)
{
var length = reader.ReadUInt16();
var buffer = reader.ReadBytes(length);
token = Encoding.UTF8.GetString(buffer);
}
var error = reader.Read() == 0;
if (error)
{
Serializer.Deserialize<LoadError>(stream).Dump();
throw new InvalidDataException();
}
var results = Serializer.Deserialize<LoadArrayMessage<BigDbObject>>(stream);
return results.Objects
.Select(x => Artifact.FromBigDbObject(x))
.ToArray();
}
}
}
public class ArtifactAttribute
{
public string Type { get; set; }
public string BaseType => Regex.Replace(Type, @"\d$", string.Empty);
public double RawValue { get; set; }
public double Value { get; set; } // some values like shield multi is actually weaker than stated, ninja-nerfed
public ArtifactAttribute(string type, double rawValue) : this(type, rawValue, rawValue) { }
public ArtifactAttribute(string type, double rawValue, double value)
{
this.Type = type;
this.RawValue = rawValue;
this.Value = value;
}
public static ArtifactAttribute Create(string key, double value)
{
switch (key.PadRight(15))
{
case "healthAdd ":
case "healthAdd2 ":
case "healthAdd3 ": return new ArtifactAttribute(key, value, 2 * value);
case "healthMulti ": return new ArtifactAttribute(key, value, 1.35 * value);
case "armorAdd ":
case "armorAdd2 ":
case "armorAdd3 ": return new ArtifactAttribute(key, value, 7.5 * value);
case "armorMulti ": return new ArtifactAttribute(key, value);
case "corrosiveAdd ":
case "corrosiveAdd2 ":
case "corrosiveAdd3 ": return new ArtifactAttribute(key, value, 4 * value);
case "corrosiveMulti ": return new ArtifactAttribute(key, value);
case "energyAdd ":
case "energyAdd2 ":
case "energyAdd3 ": return new ArtifactAttribute(key, value, 4 * value);
case "energyMulti ": return new ArtifactAttribute(key, value);
case "kineticAdd ":
case "kineticAdd2 ":
case "kineticAdd3 ": return new ArtifactAttribute(key, value, 4 * value);
case "kineticMulti ": return new ArtifactAttribute(key, value);
case "shieldAdd ":
case "shieldAdd2 ":
case "shieldAdd3 ": return new ArtifactAttribute(key, value, 2 * value);
case "shieldMulti ": return new ArtifactAttribute(key, value, 1.35 * value);
case "shieldRegen ": return new ArtifactAttribute(key, value);
case "corrosiveResist": return new ArtifactAttribute(key, value);
case "energyResist ": return new ArtifactAttribute(key, value);
case "kineticResist ": return new ArtifactAttribute(key, value);
case "allResist ": return new ArtifactAttribute(key, value);
case "allAdd ":
case "allAdd2 ":
case "allAdd3 ": return new ArtifactAttribute(key, value, 1.5 * value);
case "allMulti ": return new ArtifactAttribute(key, value, 1.35 * value);
case "speed ":
case "speed2 ":
case "speed3 ": return new ArtifactAttribute(key, value, 0.1 * value);
case "refire ":
case "refire2 ":
case "refire3 ": return new ArtifactAttribute(key, value, 0.3 * value);
case "convHp ": return new ArtifactAttribute(key, value, Math.Min(0.1 * value, 100));
case "convShield ": return new ArtifactAttribute(key, value, Math.Min(0.1 * value, 100));
case "powerReg ":
case "powerReg2 ":
case "powerReg3 ": return new ArtifactAttribute(key, value, 0.15 * value);
case "powerMax ": return new ArtifactAttribute(key, value);
case "cooldown ":
case "cooldown2 ":
case "cooldown3 ": return new ArtifactAttribute(key, value, 0.1 * value);
default: return new ArtifactAttribute(key, value, double.NaN);
}
}
}
#region ProtoBuf
[ProtoContract]
public class LoadArrayMessage<TMessage>
{
[ProtoMember(1)]
public TMessage[] Objects { get; set; }
}
[ProtoContract]
public class LoadError
{
[ProtoMember(1)] public int ErrorCode { get; set; }
[ProtoMember(2)] public string Message { get; set; }
}
[ProtoContract]
public class BigDbObject
{
[ProtoMember(1)]
public string Key { get; set; }
[ProtoMember(2)]
public string Version { get; set; }
[ProtoMember(3)]
public Dictionary<string, ValueObject> Properties { get; set; }
[ProtoMember(4)]
public int CreatorID { get; set; }
}
[ProtoContract]
public class ObjectProperty
{
[ProtoMember(1)] public string Name { get; set; }
[ProtoMember(2)] public ValueObject Value { get; set; }
}
[ProtoContract]
public class ValueObject
{
[ProtoMember(1)] public int Type { get; set; }
[ProtoMember(2)] public string Text { get; set; }
[ProtoMember(3)] public int Integer { get; set; }
[ProtoMember(4)] public uint UnsignedInteger { get; set; }
[ProtoMember(5)] public long Long { get; set; }
[ProtoMember(6)] public bool Bool { get; set; }
[ProtoMember(7)] public float Float { get; set; }
[ProtoMember(8)] public double Double { get; set; }
[ProtoMember(9)] public byte[] Bytes { get; set; }
[ProtoMember(10)] public DateTime DateTime { get; set; }
[ProtoMember(11)] public Dictionary<int, ValueObject> Array { get; set; }
[ProtoMember(12)] public ObjectProperty Object { get; set; }
private static Dictionary<int, Func<ValueObject, object>> ValueGetterMapping = typeof(ValueObject)
.GetProperties()
.Where(p => p.SetMethod != null)
.ToDictionary<PropertyInfo, int, Func<ValueObject, object>>(
p => p.GetCustomAttribute<ProtoMemberAttribute>().Tag,
p => v => p.GetValue(v));
public dynamic Value => ValueGetterMapping[Type + 2](this);
}
[ProtoContract]
public class ArrayProperty
{
[ProtoMember(1)] public int Index { get; set; }
[ProtoMember(2)] public ValueObject Value { get; set; }
}
#endregion