-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathparser.js
3344 lines (2936 loc) · 111 KB
/
parser.js
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
const PARSER_VERSION = 7;
const log = require('./pino.js');
const fs = require('fs');
const path = require('path');
const ReplayTypes = require(path.join(__dirname, 'constants.js'));
const heroprotocol = require('heroprotocol');
const XRegExp = require('xregexp');
const attrs = require('./attr.js');
// uncomment for debug
// log.level = 'trace';
// 2.55.2.87306
const MAX_SUPPORTED_BUILD = 87774;
const BSTEP_FRAME_THRESHOLD = 8;
const ReplayDataType = {
game: 'gameevents',
message: 'messageevents',
tracker: 'trackerevents',
attribute: 'attributeevents',
header: 'header',
details: 'details',
init: 'initdata',
stats: 'stats',
lobby: 'battlelobby',
};
// lil bit of duplication here but for fallback reasons, this exists
const ReplayToProtocolType = {
gameevents: heroprotocol.GAME_EVENTS,
messageevents: heroprotocol.MESSAGE_EVENTS,
trackerevents: heroprotocol.TRACKER_EVENTS,
attributeevents: heroprotocol.ATTRIBUTES_EVENTS,
header: heroprotocol.HEADER,
details: heroprotocol.DETAILS,
initdata: heroprotocol.INITDATA,
battlelobby: 'replay.server.battlelobby',
};
const ReplayStatus = {
OK: 1,
Unsupported: 0,
Duplicate: -1,
Failure: -2,
UnsupportedMap: -3,
ComputerPlayerFound: -4,
Incomplete: -5,
TooOld: -6,
Unverified: -7,
};
const StatusString = {
1: 'OK',
0: 'Unsupported',
'-1': 'Duplicate',
'-2': 'Internal Exception',
'-3': 'Unsupported Map',
'-4': 'Computer Player Found',
'-5': 'Incomplete',
'-6': 'Too Old',
'-7': 'Unverified',
};
// it's everything except gameevents which is just a massive amount of data
const CommonReplayData = [
ReplayDataType.message,
ReplayDataType.tracker,
ReplayDataType.attribute,
ReplayDataType.header,
ReplayDataType.details,
ReplayDataType.init,
ReplayDataType.lobby,
];
const AllReplayData = [
ReplayDataType.game,
ReplayDataType.message,
ReplayDataType.tracker,
ReplayDataType.attribute,
ReplayDataType.header,
ReplayDataType.details,
ReplayDataType.init,
ReplayDataType.lobby,
];
function parse(file, requestedData, opts) {
var replay = {};
// execute sync
for (var i in requestedData) {
log.debug('Retrieving ' + requestedData[i]);
replay[requestedData[i]] = heroprotocol.get(
ReplayToProtocolType[requestedData[i]],
file
);
}
if (opts) {
if ('saveToFile' in opts) {
fs.writeFile(opts.saveToFile, JSON.stringify(replay, null, 2), function (
err
) {
if (err) throw err;
log.info('Wrote replay data to ' + opts.saveToFile);
});
}
}
// battletags
replay.tags = {};
if (replay[ReplayDataType.lobby]) {
replay.tags = getBattletags(replay[ReplayDataType.lobby]);
}
return replay;
}
// returns a summary of header data (player ID, date, type, map)
// for checking duplicates
// header does not do anything that's unsupported by the max build number, so it's fine to run all the time.
function getHeader(file) {
try {
let data = parse(file, [
ReplayDataType.header,
ReplayDataType.details,
ReplayDataType.init,
ReplayDataType.tracker,
ReplayDataType.lobby,
]);
var details = data.details;
var match = {};
// header data
match.version = data.header.m_version;
match.type = data.header.m_type;
// game mode
match.mode =
data.initdata.m_syncLobbyState.m_gameDescription.m_gameOptions.m_ammId;
if (match.mode === null) match.mode = -1;
// map details
// for localization reasons we need the internal map name from the EndOfGameTalentChoices event
var tracker = data.trackerevents;
for (let i in tracker) {
let event = tracker[i];
// case on event type
if (event._eventid === ReplayTypes.TrackerEvent.Stat) {
if (
event.m_eventName === ReplayTypes.StatEventType.EndOfGameTalentChoices
) {
let internalMap = event.m_stringData[2].m_value;
if (internalMap in ReplayTypes.MapType) {
match.map = ReplayTypes.MapType[event.m_stringData[2].m_value];
break;
} else {
log.error('Unrecognized internal map name: ' + internalMap);
return { err: 'map' };
}
}
}
}
match.date = winFileTimeToDate(details.m_timeUTC);
match.rawDate = details.m_timeUTC;
// players
match.playerIDs = [];
var playerDetails = details.m_playerList;
for (var i = 0; i < playerDetails.length; i++) {
var pdata = playerDetails[i];
let ToonHandle =
pdata.m_toon.m_region +
'-' +
pdata.m_toon.m_programId +
'-' +
pdata.m_toon.m_realm +
'-' +
pdata.m_toon.m_id;
match.playerIDs.push(ToonHandle);
}
match.tags = data.tags;
return match;
} catch (err) {
log.error({ error: err });
return { err: err };
}
}
function getBattletags(buffer) {
if (buffer) {
let btagRegExp = XRegExp('(\\p{L}|\\d){3,24}#\\d{4,10}[zØ]?', 'g');
let matches = buffer.toString().match(btagRegExp);
// process
let tagMap = [];
for (let match of matches) {
// split into name + tag
let name = match.substr(0, match.indexOf('#'));
let tag = match.substr(match.indexOf('#') + 1);
tagMap.push({ tag, name, full: match });
log.trace('Found BattleTag: ' + match);
}
return tagMap;
}
}
// processes a replay file and adds it to the database
// the parser no longer requires a heroes talents instance to function.
function processReplay(file, opts = {}) {
// options
if (!('getBMData' in opts)) opts.getBMData = true;
if (!('useAttributeName' in opts)) opts.useAttributeName = false;
if (!('legacyTalentKeys' in opts)) opts.legacyTalentKeys = false;
try {
log.info('Parsing ' + file);
// parse it
var data;
if (opts.getBMData) {
data = parse(file, AllReplayData);
} else {
data = parse(file, CommonReplayData);
}
var details = data.details;
// start with the match, since a lot of things are keyed off of it
// the match id is not generated until insertion (key off unique id generated by database)
// TODO: de-duplication
var match = {};
// header data
match.version = data.header.m_version;
// version check
if (
match.version.m_build > MAX_SUPPORTED_BUILD &&
!opts.overrideVerifiedBuild
) {
log.warn(
`Unverified build number ${match.version.m_build}, aborting. Override this behavior with the 'overrideVerifiedBuild' option.`
);
return { status: ReplayStatus.Unverified };
} else if (
match.version.m_build > MAX_SUPPORTED_BUILD &&
opts.overrideVerifiedBuild === true
) {
log.warn(
`Proceeding with processing unverified build number ${match.version.m_build}. Some values may be missing and unexpected behavior may occur.`
);
}
match.type = data.header.m_type;
match.loopLength = data.header.m_elapsedGameLoops;
match.filename = file;
// game mode
match.mode =
data.initdata.m_syncLobbyState.m_gameDescription.m_gameOptions.m_ammId;
if (match.mode === null) match.mode = -1;
// check for supported mode
if (match.mode === ReplayTypes.GameMode.Brawl) {
log.warn('Brawls are not supported!');
return { status: ReplayStatus.Unsupported };
}
// map details
// for localization reasons we need the internal map name from the EndOfGameTalentChoices event
var tracker = data.trackerevents;
for (let i in tracker) {
let event = tracker[i];
// case on event type
if (event._eventid === ReplayTypes.TrackerEvent.Stat) {
if (
event.m_eventName === ReplayTypes.StatEventType.EndOfGameTalentChoices
) {
let internalMap = event.m_stringData[2].m_value;
if (internalMap in ReplayTypes.MapType) {
match.map = ReplayTypes.MapType[event.m_stringData[2].m_value];
break;
} else {
log.warn('Unrecognized internal map name: ' + internalMap);
return { status: ReplayStats.UnsupportedMap };
}
}
}
}
// match.map = details.m_title;
match.date = winFileTimeToDate(details.m_timeUTC);
log.debug(
'Processing ' +
ReplayTypes.GameModeStrings[match.mode] +
' game on ' +
match.map +
' at ' +
match.date
);
match.rawDate = details.m_timeUTC;
// check for duplicate matches somewhere else, this function executes without async calls
// until insertion. Should have a processReplays function that does the de-duplication.
//this._db.matches.find({ 'map' : match.map, 'date' : match.date, 'loopLength' : match.loopLength }, function(err, docs) {
// players
// the match will just store the players involed. The details will be stored
// in a document in the heroData db
// players are 1-indexed, look at details first
var players = {};
match.playerIDs = [];
match.heroes = [];
match.levelTimes = { 0: {}, 1: {} };
var playerDetails = details.m_playerList;
log.debug('Gathering Preliminary Player Data...');
for (var i = 0; i < playerDetails.length; i++) {
var pdata = playerDetails[i];
var pdoc = {};
// collect data
pdoc.hero = pdata.m_hero;
// some uh, unicode issues here
// we're gonna use the NA hero name and remove his ú
if (pdoc.hero === 'Lúcio') pdoc.hero = 'Lucio';
pdoc.name = pdata.m_name;
pdoc.uuid = pdata.m_toon.m_id;
pdoc.region = pdata.m_toon.m_region;
pdoc.realm = pdata.m_toon.m_realm;
// ok so actually search forward here and look for a name match
for (let j = i; j < data.tags.length; j++) {
if (data.tags[j].name === pdoc.name) {
pdoc.tag = parseInt(data.tags[j].tag);
}
}
// match region should be logged too, since all players should be
// in the same region, overwrite constantly
match.region = pdata.m_toon.m_region;
pdoc.team = pdata.m_teamId; /// the team id doesn't neatly match up with the tracker events, may adjust later
pdoc.ToonHandle =
pdata.m_toon.m_region +
'-' +
pdata.m_toon.m_programId +
'-' +
pdata.m_toon.m_realm +
'-' +
pdata.m_toon.m_id;
// DEBUG
//if (pdata.m_toon.m_realm === 0) {
// pdoc.ToonHandle = pdata.m_name + ' [CPU]';
//}
pdoc.gameStats = {};
pdoc.talents = {};
pdoc.takedowns = [];
pdoc.deaths = [];
pdoc.gameStats.awards = [];
pdoc.bsteps = [];
pdoc.voiceLines = [];
pdoc.sprays = [];
pdoc.taunts = [];
pdoc.dances = [];
pdoc.units = {};
pdoc.votes = 0;
pdoc.rawDate = match.rawDate;
pdoc.map = match.map;
pdoc.date = match.date;
pdoc.build = match.version.m_build;
pdoc.mode = match.mode;
pdoc.version = match.version;
pdoc.globes = { count: 0, events: [] };
players[pdoc.ToonHandle] = pdoc;
match.playerIDs.push(pdoc.ToonHandle);
log.trace('Found player ' + pdoc.ToonHandle + ' (' + pdoc.name + ')');
}
log.debug('Preliminary Player Processing Complete');
log.debug('Matching Tracker Player ID to handles...');
// construct identfier map for player handle to internal player object id
// maps player id in the Tracker data to the proper player object
var playerIDMap = {};
match.loopGameStart = 0; // fairly sure this is always 610 but just in case look for the "GatesOpen" event
// the match length is actually incorrect. need to track core death events for actual match time.
var cores = {};
for (let i = 0; i < tracker.length; i++) {
let event = tracker[i];
// case on event type
if (event._eventid === ReplayTypes.TrackerEvent.Stat) {
if (event.m_eventName === ReplayTypes.StatEventType.PlayerInit) {
if (event.m_stringData[0].m_value === 'Computer') {
log.warn('Games with computer players are not supported');
// DEBUG
//event.m_stringData.push({ m_value: `Player ${event.m_intData[0].m_value} [CPU]`});
return { status: ReplayStatus.ComputerPlayerFound };
}
playerIDMap[event.m_intData[0].m_value] =
event.m_stringData[1].m_value;
const attrName =
data.attributeevents.scopes[event.m_intData[0].m_value]['4002'][0]
.value;
players[event.m_stringData[1].m_value].heroLevel = parseInt(
data.attributeevents.scopes[event.m_intData[0].m_value]['4008'][0]
.value
);
players[event.m_stringData[1].m_value].hero = opts.useAttributeName
? attrName
: attrs.heroAttribute[attrName];
// right hero names should be tracked here...
match.heroes.push(players[event.m_stringData[1].m_value].hero);
log.trace(
'Player ' +
event.m_stringData[1].m_value +
' has tracker ID ' +
event.m_intData[0].m_value
);
} else if (event.m_eventName === ReplayTypes.StatEventType.GatesOpen) {
match.loopGameStart = event._gameloop;
}
} else if (event._eventid === ReplayTypes.TrackerEvent.UnitBorn) {
if (
event.m_unitTypeName === ReplayTypes.UnitType.KingsCore ||
event.m_unitTypeName === ReplayTypes.UnitType.VanndarStormpike ||
event.m_unitTypeName === ReplayTypes.UnitType.DrekThar
) {
let tag = event.m_unitTagIndex + '-' + event.m_unitTagRecycle;
cores[tag] = event;
log.trace(
'Team ' + (event.m_upkeepPlayerId - 11) + ' core ' + tag + ' found'
);
}
}
}
match.length = loopsToSeconds(match.loopLength - match.loopGameStart);
log.debug('Player ID Mapping Complete');
log.debug('Gathering player cosmetic info...');
let lobbyState = data.initdata.m_syncLobbyState.m_lobbyState.m_slots;
var playerLobbyID = {};
for (let i = 0; i < lobbyState.length; i++) {
let p = lobbyState[i];
let id = p.m_toonHandle;
if (id === '') continue;
if (!(id in players)) continue;
players[id].skin = p.m_skin;
players[id].announcer = p.m_announcerPack;
players[id].mount = p.m_mount;
players[id].silenced = p.m_hasSilencePenalty;
if ('m_hasVoiceSilencePenalty' in p)
players[id].voiceSilenced = p.m_hasVoiceSilencePenalty;
playerLobbyID[p.m_userId] = id;
players[id].length = match.length;
}
let playerList = data.details.m_playerList;
var playerWorkingSlotID = {};
for (let i = 0; i < playerList.length; i++) {
let pl = playerList[i];
let toon =
pl.m_toon.m_region +
'-Hero-' +
pl.m_toon.m_realm +
'-' +
pl.m_toon.m_id;
playerWorkingSlotID[pl.m_workingSetSlotId] = toon;
}
// fallback plan
// the initdata.m_lobbyState.m_slots should have it instead
if (null in playerWorkingSlotID) {
log.warn('playerWorkingSlotIDs are null. Proceeding to fallback...');
playerWorkingSlotID = {};
for (let slot of data.initdata.m_syncLobbyState.m_lobbyState.m_slots) {
let toon = playerLobbyID[slot.m_userId];
if (toon) {
playerWorkingSlotID[slot.m_workingSetSlotId] = toon;
}
}
}
log.debug('Cosmetic use data collection complete');
// draft bans check
if (
match.mode === ReplayTypes.GameMode.UnrankedDraft ||
match.mode === ReplayTypes.GameMode.HeroLeague ||
match.mode === ReplayTypes.GameMode.TeamLeague ||
match.mode === ReplayTypes.GameMode.StormLeague ||
match.mode === ReplayTypes.GameMode.Custom
) {
log.debug('Gathering draft data...');
match.bans = { 0: [], 1: [] };
match.picks = { 0: [], 1: [] };
let attr = data.attributeevents.scopes['16'];
for (let a in attr) {
let obj = attr[a][0];
// first round bans
if (obj.attrid === 4023) {
// team 0 ban 1
match.bans[0].push({ hero: obj.value, order: 1, absolute: 1 });
} else if (obj.attrid === 4028) {
// team 1 ban 1
match.bans[1].push({ hero: obj.value, order: 1, absolute: 1 });
}
if (match.version.m_build < 66292) {
// prior to build 66292, there were only two bans. in this case, the second ban
// came in the middle. After this patch, the second ban is actually a first round
// ban (technically). It will be marked as such.
if (obj.attrid === 4025) {
// team 0 ban 2
match.bans[0].push({ hero: obj.value, order: 2, absolute: 2 });
} else if (obj.attrid === 4030) {
// team 1 ban 2
match.bans[1].push({ hero: obj.value, order: 2, absolute: 2 });
}
} else if (match.version.m_build >= 66292) {
if (obj.attrid === 4025) {
// team 0 ban 2
match.bans[0].push({ hero: obj.value, order: 1, absolute: 2 });
} else if (obj.attrid === 4030) {
// team 1 ban 2
match.bans[1].push({ hero: obj.value, order: 1, absolute: 2 });
}
}
// third round bans
if (obj.attrid === 4043) {
// team 0 ban 3
match.bans[0].push({ hero: obj.value, order: 2, absolute: 3 });
} else if (obj.attrid === 4045) {
// team 1 ban 3
match.bans[1].push({ hero: obj.value, order: 2, absolute: 3 });
}
}
// picks
const pickOrder = { 0: [], 1: [] };
try {
for (let e in data.trackerevents) {
let msg = data.trackerevents[e];
if (msg._event === 'NNet.Replay.Tracker.SHeroPickedEvent') {
let player = players[playerWorkingSlotID[msg.m_controllingPlayer]];
if (!('first' in match.picks)) match.picks.first = player.team;
// due to swaps, player pick order isn't necessarily correct.
// also due to this implementation not allowing use of internal hero identifier,
// we have to do a little extra processing here...
// record actual player pick order
pickOrder[player.team].push({
hero: msg.m_hero,
id: msg.m_controllingPlayer,
});
} else if (msg._event === 'NNet.Replay.Tracker.SHeroSwappedEvent') {
// find the hero id and assign a new player id
const player =
players[playerWorkingSlotID[msg.m_newControllingPlayer]];
const idx = pickOrder[player.team].findIndex(
(p) => p.hero === msg.m_hero
);
pickOrder[player.team][idx].id = msg.m_newControllingPlayer;
}
}
} catch (e) {
log.debug('Invalid draft data found, proceeding without draft data...');
pickOrder[0] = [];
pickOrder[1] = [];
}
// map to hero names
try {
match.picks[0] = pickOrder[0].map(
(p) => players[playerWorkingSlotID[p.id]].hero
);
match.picks[1] = pickOrder[1].map(
(p) => players[playerWorkingSlotID[p.id]].hero
);
} catch (e) {
console.log(`Error processing draft data: ${e}`);
}
let a = 1;
let b = 0;
// check if Blue Team has first pick
if (match.picks && match.picks.first === 0) {
[a, b] = [b, a];
}
// create a list of bans and picks in draft order
let selections = [];
selections.push(match.bans[a][0]);
selections.push(match.bans[b][0]);
// check if the game is from before the second early ban was added
if (match.version.m_build < 66292) {
selections.push("N/A");
selections.push("N/A");
} else {
selections.push(match.bans[a][1]);
selections.push(match.bans[b][1]);
}
selections.push(match.picks[a][0]);
selections.push(match.picks[b][0]);
selections.push(match.picks[b][1]);
selections.push(match.picks[a][1]);
selections.push(match.picks[a][2]);
// check if the game is from before the second early ban was added
if (match.version.m_build < 66292) {
selections.push(match.bans[b][1]);
selections.push(match.bans[a][1]);
} else {
selections.push(match.bans[b][2]);
selections.push(match.bans[a][2]);
}
selections.push(match.picks[b][2]);
selections.push(match.picks[b][3]);
selections.push(match.picks[a][3]);
selections.push(match.picks[a][4]);
selections.push(match.picks[b][4]);
// get the slot number for each hero
for (const [id, player] of Object.entries(players)) {
player.turn = selections.indexOf(player.hero);
}
log.debug('Draft data complete');
}
// the tracker events have most of the useful data
// track a few different kinds of things here, this is probably where most of the interesting stuff will come from
match.XPBreakdown = [];
match.takedowns = [];
match.mercs = { captures: [], units: {} };
match.team0Takedowns = 0;
match.team1Takedowns = 0;
match.structures = {};
match.objective = { type: match.map };
// objective object initialization (per-map)
if (match.map === ReplayTypes.MapType.ControlPoints) {
match.objective[0] = { count: 0, damage: 0, events: [] };
match.objective[1] = { count: 0, damage: 0, events: [] };
} else if (match.map === ReplayTypes.MapType.TowersOfDoom) {
match.objective.sixTowerEvents = [];
// this is a special case for towers, other matches will have a general 'structures' object in the root
match.objective.structures = [];
match.objective[0] = { count: 0, damage: 0, events: [] };
match.objective[1] = { count: 0, damage: 0, events: [] };
} else if (match.map === ReplayTypes.MapType.CursedHollow) {
match.objective.tributes = [];
match.objective[0] = { count: 0, events: [] };
match.objective[1] = { count: 0, events: [] };
} else if (match.map === ReplayTypes.MapType.DragonShire) {
// it appears that we can track the status of the shrines based on owner changed events
var moon = {};
var sun = {};
var dragon = null;
match.objective.shrines = { moon: [], sun: [] };
match.objective[0] = { count: 0, events: [] };
match.objective[1] = { count: 0, events: [] };
} else if (match.map === ReplayTypes.MapType.HauntedWoods) {
var currentTerror = { 0: {}, 1: {} };
match.objective[0] = { count: 0, events: [], units: [] };
match.objective[1] = { count: 0, events: [], units: [] };
} else if (match.map === ReplayTypes.MapType.HauntedMines) {
// unfortunately the mines map seems to be missing some older events that had the info about the golem spawns
// the data would be... tricky to reconstruct due to ambiguity over who picks up the skull
// we can track when these are summoned though and maybe how long they last
var golems = [null, null];
match.objective[0] = [];
match.objective[1] = [];
} else if (match.map === ReplayTypes.MapType.BattlefieldOfEternity) {
var immortal = {};
match.objective.results = [];
} else if (match.map === ReplayTypes.MapType.Shrines) {
// track shrine outcome, and each team's punishers.
match.objective.shrines = [];
match.objective[0] = { count: 0, events: [] };
match.objective[1] = { count: 0, events: [] };
} else if (match.map === ReplayTypes.MapType.Crypts) {
var currentSpiders = { units: {}, active: false };
match.objective[0] = { count: 0, events: [] };
match.objective[1] = { count: 0, events: [] };
} else if (match.map === ReplayTypes.MapType.Volskaya) {
var currentProtector = { active: false };
match.objective[0] = { count: 0, events: [] };
match.objective[1] = { count: 0, events: [] };
} else if (match.map === ReplayTypes.MapType['Warhead Junction']) {
var nukes = {};
match.objective[0] = { count: 0, success: 0, events: [] };
match.objective[1] = { count: 0, success: 0, events: [] };
match.objective.warheads = [];
} else if (match.map === ReplayTypes.MapType.AlteracPass) {
match.objective[0] = { events: [] };
match.objective[1] = { events: [] };
} else if (match.map === ReplayTypes.MapType.BraxisHoldout) {
var waveUnits = { 0: {}, 1: {} };
var waveID = -1;
var beacons = {};
match.objective.beacons = [];
match.objective.waves = [];
} else if (match.map === ReplayTypes.MapType.BlackheartsBay) {
// hopefully something goes here eventually
match.objective[0] = { count: 0, events: [] };
match.objective[1] = { count: 0, events: [] };
} else if (match.map === ReplayTypes.MapType.Hanamura) {
// can't wait till i have to detect which version of the map this is
// i mean i guess it doesn't really matter if the old one fails?
// As of 2.37 this refers to new Hanamura Temple
// lists payload sequences in order (each object in the array is one payload spawn and completion)
match.objective = { events: [] };
} else if (match.map === undefined) {
log.error('Map name not found. Replay too old?');
return { status: ReplayStatus.TooOld };
} else {
// unsupported map
log.error('Map ' + match.map + ' is not supported');
return { status: ReplayStatus.UnsupportedMap };
}
var team0XPEnd;
var team1XPEnd;
// player 11 = blue (0) team ai?, player 12 = red (0) team ai?
var possibleMinionXP = { 0: 0, 1: 0 };
log.debug('[TRACKER] Starting Event Analysis...');
for (let i = 0; i < tracker.length; i++) {
let event = tracker[i];
// case on event type
if (event._eventid === ReplayTypes.TrackerEvent.Score) {
// score is real long, separate function
processScoreArray(event.m_instanceList, match, players, playerIDMap);
} else if (event._eventid === ReplayTypes.TrackerEvent.Stat) {
if (
event.m_eventName === ReplayTypes.StatEventType.EndOfGameTalentChoices
) {
let trackerPlayerID = event.m_intData[0].m_value;
let playerID = playerIDMap[trackerPlayerID];
log.trace('[TRACKER] Processing Talent Choices for ' + playerID);
// this actually contains more than talent choices
if (event.m_stringData[1].m_value === 'Win') {
players[playerID].win = true;
} else {
players[playerID].win = false;
}
players[playerID].internalHeroName = event.m_stringData[0].m_value;
// talents
for (let j = 0; j < event.m_stringData.length; j++) {
if (event.m_stringData[j].m_key.startsWith('Tier')) {
let key = event.m_stringData[j].m_key;
if (opts.legacyTalentKeys === true) {
players[playerID].talents[key] = event.m_stringData[j].m_value;
} else {
key = key.replace(/\s+/g, '');
players[playerID].talents[key] = event.m_stringData[j].m_value;
}
}
}
} else if (
event.m_eventName === ReplayTypes.StatEventType.PeriodicXPBreakdown
) {
// periodic xp breakdown
let xpb = {};
xpb.loop = event._gameloop;
xpb.time = loopsToSeconds(xpb.loop - match.loopGameStart);
xpb.team = event.m_intData[0].m_value - 1; // team is 1-indexed in this event?
xpb.teamLevel = event.m_intData[1].m_value;
xpb.breakdown = {};
xpb.theoreticalMinionXP = possibleMinionXP[xpb.team];
log.trace(
'[TRACKER] Processing XP Breakdown for team ' +
xpb.team +
' at loop ' +
xpb.loop
);
for (let j in event.m_fixedData) {
xpb.breakdown[event.m_fixedData[j].m_key] =
event.m_fixedData[j].m_value / 4096;
}
match.XPBreakdown.push(xpb);
} else if (
event.m_eventName === ReplayTypes.StatEventType.EndOfGameXPBreakdown
) {
// end of game xp breakdown
let xpb = {};
xpb.loop = event._gameloop;
xpb.time = loopsToSeconds(xpb.loop - match.loopGameStart);
xpb.team = players[playerIDMap[event.m_intData[0].m_value]].team;
xpb.theoreticalMinionXP = possibleMinionXP[xpb.team];
xpb.breakdown = {};
log.trace(
'[TRACKER] Caching Final XP Breakdown for team ' +
xpb.team +
' at loop ' +
xpb.loop
);
for (let j in event.m_fixedData) {
xpb.breakdown[event.m_fixedData[j].m_key] =
event.m_fixedData[j].m_value / 4096;
}
if (xpb.team === ReplayTypes.TeamType.Blue) {
team0XPEnd = xpb;
} else if (xpb.team === ReplayTypes.TeamType.Red) {
team1XPEnd = xpb;
}
} else if (
event.m_eventName === ReplayTypes.StatEventType.PlayerDeath
) {
// add data to the match and the individual players
let tData = {};
tData.loop = event._gameloop;
tData.time = loopsToSeconds(tData.loop - match.loopGameStart);
tData.x = event.m_fixedData[0].m_value;
tData.y = event.m_fixedData[1].m_value;
tData.killers = [];
// player ids
let victim;
let killers = [];
for (let j = 0; j < event.m_intData.length; j++) {
let entry = event.m_intData[j];
if (entry.m_key === 'PlayerID') {
tData.victim = {
player: playerIDMap[entry.m_value],
hero: players[playerIDMap[entry.m_value]].hero,
};
victim = playerIDMap[entry.m_value];
} else if (entry.m_key === 'KillingPlayer') {
let tdo = {};
if (!(entry.m_value in playerIDMap)) {
// this poor person died to a creep
tdo.player = '0';
tdo.hero = 'Nexus Forces';
} else {
tdo = {
player: playerIDMap[entry.m_value],
hero: players[playerIDMap[entry.m_value]].hero,
};
}
killers.push(playerIDMap[entry.m_value]);
tData.killers.push(tdo);
}
}
if (players[victim].team === ReplayTypes.TeamType.Blue)
match.team1Takedowns += 1;
else if (players[victim].team === ReplayTypes.TeamType.Red)
match.team0Takedowns += 1;
match.takedowns.push(tData);
players[victim].deaths.push(tData);
for (let j = 0; j < killers.length; j++) {
if (killers[j] === undefined) continue;
players[killers[j]].takedowns.push(tData);
}
log.trace(
'[TRACKER] Processed Player ' + victim + ' death at ' + tData.loop
);
} else if (
event.m_eventName === ReplayTypes.StatEventType.LootSprayUsed
) {
let spray = {};
let id = event.m_stringData[1].m_value;
spray.kind = event.m_stringData[2].m_value;
spray.x = event.m_fixedData[0].m_value;
spray.y = event.m_fixedData[1].m_value;
spray.loop = event._gameloop;
spray.time = loopsToSeconds(spray.loop - match.loopGameStart);
spray.kills = 0;
spray.deaths = 0;
players[id].sprays.push(spray);
log.trace('[TRACKER] Spray from player ' + id + ' found');
} else if (
event.m_eventName === ReplayTypes.StatEventType.LootVoiceLineUsed
) {
let line = {};
let id = event.m_stringData[1].m_value;
line.kind = event.m_stringData[2].m_value;
line.x = event.m_fixedData[0].m_value;
line.y = event.m_fixedData[1].m_value;
line.loop = event._gameloop;
line.time = loopsToSeconds(line.loop - match.loopGameStart);
line.kills = 0;
line.deaths = 0;
players[id].voiceLines.push(line);
log.trace('[TRACKER] Voice Line from player ' + id + ' found');
} else if (
event.m_eventName === ReplayTypes.StatEventType.SkyTempleShotsFired
) {
let objEvent = {
team: event.m_intData[2].m_value - 1,
loop: event._gameloop,
damage: event.m_fixedData[0].m_value / 4096,
};
objEvent.time = loopsToSeconds(objEvent.loop - match.loopGameStart);
if (objEvent.team === 0 || objEvent.team === 1) {
match.objective[objEvent.team].events.push(objEvent);
match.objective[objEvent.team].damage += objEvent.damage;
match.objective[objEvent.team].count += 1;
}
log.trace(
'[TRACKER] Sky Temple: Shot fired for team ' + objEvent.team
);
} else if (
event.m_eventName === ReplayTypes.StatEventType.AltarCaptured
) {
let objEvent = {
team: event.m_intData[0].m_value - 1,
loop: event._gameloop,
owned: event.m_intData[1].m_value,
};
objEvent.damage = objEvent.owned + 1;
objEvent.time = loopsToSeconds(objEvent.loop - match.loopGameStart);
match.objective[objEvent.team].events.push(objEvent);
match.objective[objEvent.team].damage += objEvent.damage;
match.objective[objEvent.team].count += 1;
log.trace(
'[TRACKER] Towers of Doom: Altar Capture for team ' + objEvent.team
);
} else if (
event.m_eventName === ReplayTypes.StatEventType.ImmortalDefeated
) {
let objEvent = {