-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoLRecord.cs
225 lines (212 loc) · 9.59 KB
/
LoLRecord.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using ReplayDll;
using System.Text;
using FluorineFx.IO;
using FluorineFx;
namespace Recorder
{
public class LoLRecord
{
public const int LPRLatestVersion = 4;
public bool IsBroken;
public int ThisLPRVersion = 4;
public string relatedFileName;
public char[] spectatorClientVersion;
public ulong gameId;
public int gameChunkTimeInterval;
public int gameKeyFrameTimeInterval;
public int gameStartChunkId;
public int gameEndKeyFrameId;
public int gameEndChunkId;
public int gameEndStartupChunkId;
public int gameLength;
public int gameClientAddLag;
//public int gameELOLevel;
public char[] gamePlatform;
public char[] observerEncryptionKey;
//public char[] gameCreateTime;
//public char[] gameStartTime;
//public char[] gameEndTime;
public int gameDelayTime;
public int gameLastChunkTime;
public int gameLastChunkDuration;
public char[] lolVersion;
public bool hasResult;
public EndOfGameStats gameStats;
public System.Collections.Generic.Dictionary<int, byte[]> gameChunks;
public System.Collections.Generic.Dictionary<int, byte[]> gameKeyFrames;
private byte[] endOfGameStatsBytes;
public PlayerInfo[] players;
public void gameMetaAnalyze(JObject metaJson)
{
JObject jObject = JsonConvert.DeserializeObject<JObject>(metaJson["gameKey"].ToString());
this.gameId = ulong.Parse(jObject["gameId"].ToString());
this.gamePlatform = jObject["platformId"].ToString().ToCharArray();
this.gameChunkTimeInterval = int.Parse(metaJson["chunkTimeInterval"].ToString());
//this.gameStartTime = metaJson["startTime"].ToString().ToCharArray();
//this.gameEndTime = metaJson["endTime"].ToString().ToCharArray();
this.gameEndChunkId = int.Parse(metaJson["lastChunkId"].ToString());
this.gameEndKeyFrameId = int.Parse(metaJson["lastKeyFrameId"].ToString());
this.gameEndStartupChunkId = int.Parse(metaJson["endStartupChunkId"].ToString());
this.gameDelayTime = int.Parse(metaJson["delayTime"].ToString());
this.gameKeyFrameTimeInterval = int.Parse(metaJson["keyFrameTimeInterval"].ToString());
this.gameStartChunkId = int.Parse(metaJson["startGameChunkId"].ToString());
this.gameLength = int.Parse(metaJson["gameLength"].ToString());
this.gameClientAddLag = int.Parse(metaJson["clientAddedLag"].ToString());
//this.gameELOLevel = int.Parse(metaJson["interestScore"].ToString());
//this.gameCreateTime = metaJson["createTime"].ToString().ToCharArray();
this.allocateChunkAndKeyFrameSpaces();
}
private void allocateChunkAndKeyFrameSpaces()
{
this.gameKeyFrames = new System.Collections.Generic.Dictionary<int, byte[]>();
this.gameChunks = new System.Collections.Generic.Dictionary<int, byte[]>();
}
public void setAllChunksContent(System.Collections.Generic.Dictionary<int, byte[]> chunks)
{
this.gameChunks = chunks;
}
public void setAllKeyFrameContent(System.Collections.Generic.Dictionary<int, byte[]> keyFrames)
{
this.gameKeyFrames = keyFrames;
}
public void lastChunkInfoAnalyze(JObject lastChunkJson)
{
this.gameLastChunkTime = int.Parse(lastChunkJson["availableSince"].ToString());
this.gameLastChunkDuration = int.Parse(lastChunkJson["duration"].ToString());
this.gameEndChunkId = int.Parse(lastChunkJson["chunkId"].ToString());
this.gameEndKeyFrameId = int.Parse(lastChunkJson["keyFrameId"].ToString());
}
public void setEndOfGameStats(byte[] content)
{
if (content == null)
{
this.hasResult = false;
return;
}
this.endOfGameStatsBytes = content;
this.gameStats = new EndOfGameStats(this.endOfGameStatsBytes);
if (!this.gameStats.DecodeData())
{
this.hasResult = false;
return;
}
if (this.gameStats.Players != null && this.gameStats.Players.Count > 0)
{
this.players = new PlayerInfo[this.gameStats.Players.Count];
for (int i = 0; i < this.gameStats.Players.Count; i++)
{
this.players[i] = new PlayerInfo();
this.players[i].championName = this.gameStats.Players[i].SkinName;
this.players[i].playerName = this.gameStats.Players[i].SummonerName;
this.players[i].team = this.gameStats.Players[i].TeamId;
this.players[i].clientID = i;
}
}
this.hasResult = true;
}
public void writeToFile(string path)
{
System.IO.FileStream fileStream = new System.IO.FileStream(path, System.IO.FileMode.Create, System.IO.FileAccess.Write);
System.IO.BinaryWriter binaryWriter = new System.IO.BinaryWriter(fileStream);
binaryWriter.Write(4);
binaryWriter.Write(this.spectatorClientVersion.Length);
binaryWriter.Write(this.spectatorClientVersion);
binaryWriter.Write(this.gameId);
binaryWriter.Write(this.gameEndStartupChunkId);
binaryWriter.Write(this.gameStartChunkId);
binaryWriter.Write(this.gameEndChunkId);
binaryWriter.Write(this.gameEndKeyFrameId);
binaryWriter.Write(this.gameLength);
binaryWriter.Write(this.gameDelayTime);
binaryWriter.Write(this.gameClientAddLag);
binaryWriter.Write(this.gameChunkTimeInterval);
binaryWriter.Write(this.gameKeyFrameTimeInterval);
//binaryWriter.Write(this.gameELOLevel);
binaryWriter.Write(this.gameLastChunkTime);
binaryWriter.Write(this.gameLastChunkDuration);
binaryWriter.Write(this.gamePlatform.Length);
binaryWriter.Write(this.gamePlatform);
binaryWriter.Write(this.observerEncryptionKey.Length);
binaryWriter.Write(this.observerEncryptionKey);
//binaryWriter.Write(this.gameCreateTime.Length);
//binaryWriter.Write(this.gameCreateTime);
//binaryWriter.Write(this.gameStartTime.Length);
//binaryWriter.Write(this.gameStartTime);
//binaryWriter.Write(this.gameEndTime.Length);
//binaryWriter.Write(this.gameEndTime);
binaryWriter.Write(this.lolVersion.Length);
binaryWriter.Write(this.lolVersion);
binaryWriter.Write(this.hasResult);
if (this.hasResult)
{
binaryWriter.Write(this.endOfGameStatsBytes.Length);
binaryWriter.Write(this.endOfGameStatsBytes);
}
if (this.players != null)
{
binaryWriter.Write(true);
binaryWriter.Write(this.players.Length);
PlayerInfo[] array = this.players;
for (int i = 0; i < array.Length; i++)
{
PlayerInfo playerInfo = array[i];
char[] array2 = playerInfo.playerName.ToCharArray();
binaryWriter.Write(array2.Length);
binaryWriter.Write(array2);
char[] array3 = playerInfo.championName.ToCharArray();
binaryWriter.Write(array3.Length);
binaryWriter.Write(array3);
binaryWriter.Write(playerInfo.team);
binaryWriter.Write(playerInfo.clientID);
}
}
else
{
binaryWriter.Write(false);
}
binaryWriter.Write(this.gameKeyFrames.Count);
foreach (System.Collections.Generic.KeyValuePair<int, byte[]> current in this.gameKeyFrames)
{
binaryWriter.Write(current.Key);
binaryWriter.Write(current.Value.Length);
binaryWriter.Write(current.Value);
}
binaryWriter.Write(this.gameChunks.Count);
foreach (System.Collections.Generic.KeyValuePair<int, byte[]> current2 in this.gameChunks)
{
binaryWriter.Write(current2.Key);
binaryWriter.Write(current2.Value.Length);
binaryWriter.Write(current2.Value);
}
binaryWriter.Close();
fileStream.Close();
this.relatedFileName = path;
}
public void writeResultToFile(string path)
{
try
{
System.IO.FileStream fileStream = new System.IO.FileStream(path, System.IO.FileMode.Create, System.IO.FileAccess.Write);
StreamWriter sw = new StreamWriter(fileStream);
System.IO.Stream stream = new System.IO.MemoryStream(this.endOfGameStatsBytes);
using (AMFReader aMFReader = new AMFReader(stream))
{
try
{
ASObject aSObject = (ASObject)aMFReader.ReadAMF3Data();
sw.Write(JsonConvert.SerializeObject(aSObject));
}
catch { }
}
sw.Close();
fileStream.Close();
}
catch { }
}
}
}