@rian8337/osu-droid-replay-analyzer 1.4.18-alpha.0 → 2.0.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,20 +1,1866 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./data/CursorData"), exports);
14
- __exportStar(require("./constants/hitResult"), exports);
15
- __exportStar(require("./constants/movementType"), exports);
16
- __exportStar(require("./ReplayAnalyzer"), exports);
17
- __exportStar(require("./data/ReplayData"), exports);
18
- __exportStar(require("./data/ReplayObjectData"), exports);
19
- __exportStar(require("./analysis/ThreeFingerChecker"), exports);
20
- //# sourceMappingURL=index.js.map
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var osuBase = require('@rian8337/osu-base');
6
+ var osuDifficultyCalculator = require('@rian8337/osu-difficulty-calculator');
7
+ var osuRebalanceDifficultyCalculator = require('@rian8337/osu-rebalance-difficulty-calculator');
8
+ var unzipper = require('unzipper');
9
+ var javaDeserialization = require('java-deserialization');
10
+ var stream = require('stream');
11
+
12
+ function _interopNamespace(e) {
13
+ if (e && e.__esModule) return e;
14
+ var n = Object.create(null);
15
+ if (e) {
16
+ Object.keys(e).forEach(function (k) {
17
+ if (k !== 'default') {
18
+ var d = Object.getOwnPropertyDescriptor(e, k);
19
+ Object.defineProperty(n, k, d.get ? d : {
20
+ enumerable: true,
21
+ get: function () { return e[k]; }
22
+ });
23
+ }
24
+ });
25
+ }
26
+ n["default"] = e;
27
+ return Object.freeze(n);
28
+ }
29
+
30
+ var javaDeserialization__namespace = /*#__PURE__*/_interopNamespace(javaDeserialization);
31
+
32
+ /**
33
+ * Represents a cursor's occurrence.
34
+ */
35
+ class CursorOccurrence {
36
+ /**
37
+ * The time of this occurrence.
38
+ */
39
+ time;
40
+ /**
41
+ * The position of the occurrence.
42
+ */
43
+ position;
44
+ /**
45
+ * The movement ID of the occurrence.
46
+ */
47
+ id;
48
+ constructor(time, x, y, id) {
49
+ this.time = time;
50
+ this.position = new osuBase.Vector2(x, y);
51
+ this.id = id;
52
+ }
53
+ }
54
+
55
+ /**
56
+ * Represents a cursor instance in an osu!droid replay.
57
+ *
58
+ * Stores cursor movement data in the form of `CursorOccurrence`s.
59
+ *
60
+ * This is used when analyzing replays using replay analyzer.
61
+ */
62
+ class CursorData {
63
+ /**
64
+ * The occurrences of this cursor instance.
65
+ */
66
+ occurrences = [];
67
+ constructor(values) {
68
+ for (let i = 0; i < values.size; ++i) {
69
+ this.occurrences.push(new CursorOccurrence(values.time[i], values.x[i], values.y[i], values.id[i]));
70
+ }
71
+ }
72
+ }
73
+
74
+ /**
75
+ * The result of a hit in an osu!droid replay.
76
+ */
77
+ exports.hitResult = void 0;
78
+ (function (hitResult) {
79
+ /**
80
+ * Miss (0).
81
+ */
82
+ hitResult[hitResult["RESULT_0"] = 1] = "RESULT_0";
83
+ /**
84
+ * Meh (50).
85
+ */
86
+ hitResult[hitResult["RESULT_50"] = 2] = "RESULT_50";
87
+ /**
88
+ * Great (100).
89
+ */
90
+ hitResult[hitResult["RESULT_100"] = 3] = "RESULT_100";
91
+ /**
92
+ * Good (300).
93
+ */
94
+ hitResult[hitResult["RESULT_300"] = 4] = "RESULT_300";
95
+ })(exports.hitResult || (exports.hitResult = {}));
96
+
97
+ /**
98
+ * Movement type of a cursor in an osu!droid replay.
99
+ */
100
+ exports.movementType = void 0;
101
+ (function (movementType) {
102
+ movementType[movementType["DOWN"] = 0] = "DOWN";
103
+ movementType[movementType["MOVE"] = 1] = "MOVE";
104
+ movementType[movementType["UP"] = 2] = "UP";
105
+ })(exports.movementType || (exports.movementType = {}));
106
+
107
+ /**
108
+ * Represents a replay data in an osu!droid replay.
109
+ *
110
+ * Stores generic information about an osu!droid replay such as player name, MD5 hash, time set, etc.
111
+ *
112
+ * This is used when analyzing replays using replay analyzer.
113
+ */
114
+ class ReplayData {
115
+ replayVersion;
116
+ folderName;
117
+ fileName;
118
+ hash;
119
+ time;
120
+ hit300k;
121
+ hit100k;
122
+ score;
123
+ maxCombo;
124
+ accuracy;
125
+ isFullCombo;
126
+ playerName;
127
+ rawMods;
128
+ rank;
129
+ convertedMods;
130
+ cursorMovement;
131
+ hitObjectData;
132
+ speedModification;
133
+ forcedAR;
134
+ constructor(values) {
135
+ this.replayVersion = values.replayVersion;
136
+ this.folderName = values.folderName;
137
+ this.fileName = values.fileName;
138
+ this.hash = values.hash;
139
+ this.time = new Date(values.time || 0);
140
+ this.hit300k = values.hit300k || 0;
141
+ this.hit100k = values.hit100k || 0;
142
+ this.score = values.score || 0;
143
+ this.maxCombo = values.maxCombo || 0;
144
+ this.accuracy = values.accuracy || new osuBase.Accuracy({});
145
+ this.isFullCombo = values.isFullCombo || false;
146
+ this.playerName = values.playerName || "";
147
+ this.rawMods = values.rawMods || "";
148
+ this.rank = values.rank || "";
149
+ this.convertedMods = values.convertedMods || [];
150
+ this.cursorMovement = values.cursorMovement;
151
+ this.hitObjectData = values.hitObjectData;
152
+ this.speedModification = values.speedModification || 1;
153
+ this.forcedAR = values.forcedAR;
154
+ }
155
+ }
156
+
157
+ /**
158
+ * A beatmap section generator that generates beatmap section based on aim/speed strain.
159
+ */
160
+ class BeatmapSectionGenerator {
161
+ /**
162
+ * Generates `BeatmapSection`s for the specified beatmap.
163
+ *
164
+ * @param map The beatmap to generate.
165
+ * @param minSectionObjectCount The maximum delta time allowed between two beatmap sections.
166
+ * Increasing this number decreases the amount of beatmap sections in general. Note that this value does not account for the speed multiplier of
167
+ * the play, similar to the way replay object data is stored.
168
+ * @param maxSectionDeltaTime The minimum object count required to make a beatmap section. Increasing this number decreases the amount of beatmap sections.
169
+ */
170
+ static generateSections(map, minSectionObjectCount, maxSectionDeltaTime) {
171
+ const beatmapSections = [];
172
+ let firstObjectIndex = 0;
173
+ for (let i = 0; i < map.objects.length - 1; ++i) {
174
+ const current = map.objects[i];
175
+ const next = map.objects[i + 1];
176
+ const realDeltaTime = next.object.startTime - current.object.endTime;
177
+ if (realDeltaTime >= maxSectionDeltaTime) {
178
+ // Ignore sections that don't meet object count requirement.
179
+ if (i - firstObjectIndex < minSectionObjectCount) {
180
+ firstObjectIndex = i + 1;
181
+ continue;
182
+ }
183
+ beatmapSections.push({
184
+ firstObjectIndex,
185
+ lastObjectIndex: i,
186
+ });
187
+ firstObjectIndex = i + 1;
188
+ }
189
+ }
190
+ // Don't forget to manually add the last beatmap section, which would otherwise be ignored.
191
+ if (map.objects.length - firstObjectIndex > minSectionObjectCount) {
192
+ beatmapSections.push({
193
+ firstObjectIndex,
194
+ lastObjectIndex: map.objects.length - 1,
195
+ });
196
+ }
197
+ return beatmapSections;
198
+ }
199
+ }
200
+
201
+ /**
202
+ * Represents a section of a beatmap.
203
+ */
204
+ class BeatmapSection {
205
+ /**
206
+ * The index of the first `DifficultyHitObject` of this beatmap section.
207
+ */
208
+ firstObjectIndex;
209
+ /**
210
+ * The index of the last `DifficultyHitObject` of this beatmap section.
211
+ */
212
+ lastObjectIndex;
213
+ /**
214
+ * @param firstObjectIndex The index of the first `DifficultyHitObject` of this beatmap section.
215
+ * @param lastObjectIndex The index of the last `DifficultyHitObject` of this beatmap section.
216
+ */
217
+ constructor(firstObjectIndex, lastObjectIndex) {
218
+ this.firstObjectIndex = firstObjectIndex;
219
+ this.lastObjectIndex = lastObjectIndex;
220
+ }
221
+ }
222
+
223
+ /**
224
+ * A section of a beatmap with extra information used for detecting three-finger usage.
225
+ */
226
+ class ThreeFingerBeatmapSection extends BeatmapSection {
227
+ /**
228
+ * Whether or not this beatmap section is dragged.
229
+ */
230
+ isDragged;
231
+ /**
232
+ * The index of the cursor that is dragging this section.
233
+ */
234
+ dragFingerIndex;
235
+ constructor(values) {
236
+ super(values.firstObjectIndex, values.lastObjectIndex);
237
+ this.isDragged = values.isDragged;
238
+ this.dragFingerIndex = values.dragFingerIndex;
239
+ }
240
+ }
241
+
242
+ /**
243
+ * Utility to check whether or not a beatmap is three-fingered.
244
+ */
245
+ class ThreeFingerChecker {
246
+ /**
247
+ * The beatmap to analyze.
248
+ */
249
+ map;
250
+ /**
251
+ * The data of the replay.
252
+ */
253
+ data;
254
+ /**
255
+ * The strain threshold to start detecting for 3-fingered section.
256
+ *
257
+ * Increasing this number will result in less sections being flagged.
258
+ */
259
+ static strainThreshold = 175;
260
+ /**
261
+ * The distance threshold between cursors to assume that two cursors are
262
+ * actually pressed with 1 finger in osu!pixels.
263
+ *
264
+ * This is used to prevent cases where a player would lift their finger
265
+ * too fast to the point where the 4th cursor instance or beyond is recorded
266
+ * as 1st, 2nd, or 3rd cursor instance.
267
+ */
268
+ cursorDistancingDistanceThreshold = 60;
269
+ /**
270
+ * The threshold for the amount of cursors that are assumed to be pressed
271
+ * by a single finger.
272
+ */
273
+ cursorDistancingCountThreshold = 10;
274
+ /**
275
+ * The threshold for the time difference of cursors that are assumed to be pressed
276
+ * by a single finger, in milliseconds.
277
+ */
278
+ cursorDistancingTimeThreshold = 1000;
279
+ /**
280
+ * The amount of notes that has a tap strain exceeding `strainThreshold`.
281
+ */
282
+ strainNoteCount;
283
+ /**
284
+ * The ratio threshold between non-3 finger cursors and 3-finger cursors.
285
+ *
286
+ * Increasing this number will increase detection accuracy, however
287
+ * it also increases the chance of falsely flagged plays.
288
+ */
289
+ threeFingerRatioThreshold = 0.01;
290
+ /**
291
+ * The maximum delta time allowed between two beatmap sections.
292
+ *
293
+ * Increasing this number decreases the amount of beatmap sections in general.
294
+ *
295
+ * Note that this value does not account for the speed multiplier of
296
+ * the play, similar to the way replay object data is stored.
297
+ */
298
+ maxSectionDeltaTime = 2000;
299
+ /**
300
+ * The minimum object count required to make a beatmap section.
301
+ *
302
+ * Increasing this number decreases the amount of beatmap sections.
303
+ */
304
+ minSectionObjectCount = 5;
305
+ /**
306
+ * The sections of the beatmap that was cut based on `maxSectionDeltaTime` and `minSectionObjectCount`.
307
+ */
308
+ beatmapSections = [];
309
+ /**
310
+ * This threshold is used to filter out accidental taps.
311
+ *
312
+ * Increasing this number makes the filtration more sensitive, however it
313
+ * will also increase the chance of 3-fingered plays getting out from
314
+ * being flagged.
315
+ */
316
+ accidentalTapThreshold = 400;
317
+ /**
318
+ * The hit window of this beatmap. Keep in mind that speed-changing mods do not change hit window length in game logic.
319
+ */
320
+ hitWindow;
321
+ /**
322
+ * A reprocessed break points to match right on object time.
323
+ *
324
+ * This is used to increase detection accuracy since break points do not start right at the
325
+ * start of the hitobject before it and do not end right at the first hitobject after it.
326
+ */
327
+ breakPointAccurateTimes = [];
328
+ /**
329
+ * A cursor data array that only contains `movementType.DOWN` movement ID occurrences.
330
+ */
331
+ downCursorInstances = [];
332
+ /**
333
+ * Nerf factors from all sections that were three-fingered.
334
+ */
335
+ nerfFactors = [];
336
+ /**
337
+ * @param map The beatmap to analyze.
338
+ * @param data The data of the replay.
339
+ */
340
+ constructor(map, data) {
341
+ this.map = map;
342
+ this.data = data;
343
+ const stats = new osuBase.MapStats({
344
+ od: this.map.map.difficulty.od,
345
+ mods: this.map.mods.filter((m) => !osuBase.ModUtil.speedChangingMods
346
+ .map((v) => v.droidString)
347
+ .includes(m.droidString)),
348
+ }).calculate();
349
+ this.hitWindow = new osuBase.DroidHitWindow(stats.od);
350
+ const strainNotes = map.objects.filter((v) => v.originalTapStrain >= ThreeFingerChecker.strainThreshold);
351
+ this.strainNoteCount = strainNotes.length;
352
+ }
353
+ /**
354
+ * Checks whether a beatmap is eligible to be detected for 3-finger.
355
+ */
356
+ static isEligibleToDetect(map) {
357
+ return map.objects.some((v) => v.originalTapStrain >= this.strainThreshold);
358
+ }
359
+ /**
360
+ * Checks if the given beatmap is 3-fingered and also returns the final penalty.
361
+ *
362
+ * The beatmap will be separated into sections and each section will be determined
363
+ * whether or not it is dragged.
364
+ *
365
+ * After that, each section will be assigned a nerf factor based on whether or not
366
+ * the section is 3-fingered. These nerf factors will be summed up into a final
367
+ * nerf factor, taking beatmap difficulty into account.
368
+ */
369
+ check() {
370
+ if (this.strainNoteCount === 0) {
371
+ return { is3Finger: false, penalty: 1 };
372
+ }
373
+ this.getAccurateBreakPoints();
374
+ this.filterCursorInstances();
375
+ if (this.downCursorInstances.filter((v) => v.occurrences.length > 0)
376
+ .length <= 3) {
377
+ return { is3Finger: false, penalty: 1 };
378
+ }
379
+ this.getBeatmapSections();
380
+ this.detectDragPlay();
381
+ this.getDetailedBeatmapSections();
382
+ this.preventAccidentalTaps();
383
+ if (this.downCursorInstances.filter((v) => v.occurrences.length > 0)
384
+ .length <= 3) {
385
+ return { is3Finger: false, penalty: 1 };
386
+ }
387
+ this.calculateNerfFactors();
388
+ const finalPenalty = this.calculateFinalPenalty();
389
+ return { is3Finger: finalPenalty > 1, penalty: finalPenalty };
390
+ }
391
+ /**
392
+ * Generates a new set of "accurate break points".
393
+ *
394
+ * This is done to increase detection accuracy since break points do not start right at the
395
+ * start of the hitobject before it and do not end right at the first hitobject after it.
396
+ */
397
+ getAccurateBreakPoints() {
398
+ const objects = this.map.objects;
399
+ const objectData = this.data.hitObjectData;
400
+ const isPrecise = this.map.mods.some((m) => m instanceof osuBase.ModPrecise);
401
+ for (const breakPoint of this.map.map.events.breaks) {
402
+ const beforeIndex = osuBase.MathUtils.clamp(objects.findIndex((o) => o.object.endTime >= breakPoint.startTime) - 1, 0, objects.length - 2);
403
+ let timeBefore = objects[beforeIndex].object.endTime;
404
+ // For sliders and spinners, automatically set hit window length to be as lenient as possible.
405
+ let beforeIndexHitWindowLength = this.hitWindow.hitWindowFor50(isPrecise);
406
+ switch (objectData[beforeIndex].result) {
407
+ case exports.hitResult.RESULT_300:
408
+ beforeIndexHitWindowLength =
409
+ this.hitWindow.hitWindowFor300(isPrecise);
410
+ break;
411
+ case exports.hitResult.RESULT_100:
412
+ beforeIndexHitWindowLength =
413
+ this.hitWindow.hitWindowFor100(isPrecise);
414
+ break;
415
+ default:
416
+ beforeIndexHitWindowLength =
417
+ this.hitWindow.hitWindowFor50(isPrecise);
418
+ }
419
+ timeBefore += beforeIndexHitWindowLength;
420
+ const afterIndex = beforeIndex + 1;
421
+ let timeAfter = objects[afterIndex].object.startTime;
422
+ // For sliders and spinners, automatically set hit window length to be as lenient as possible.
423
+ let afterIndexHitWindowLength = this.hitWindow.hitWindowFor50(isPrecise);
424
+ switch (objectData[afterIndex].result) {
425
+ case exports.hitResult.RESULT_300:
426
+ afterIndexHitWindowLength =
427
+ this.hitWindow.hitWindowFor300(isPrecise);
428
+ break;
429
+ case exports.hitResult.RESULT_100:
430
+ afterIndexHitWindowLength =
431
+ this.hitWindow.hitWindowFor100(isPrecise);
432
+ break;
433
+ default:
434
+ afterIndexHitWindowLength =
435
+ this.hitWindow.hitWindowFor50(isPrecise);
436
+ }
437
+ timeAfter += afterIndexHitWindowLength;
438
+ this.breakPointAccurateTimes.push({
439
+ startTime: timeBefore,
440
+ endTime: timeAfter,
441
+ });
442
+ }
443
+ }
444
+ /**
445
+ * Filters the original cursor instances, returning only those with `movementType.DOWN` movement ID.
446
+ *
447
+ * This also filters cursors that are in break period or happen before start/after end of the beatmap.
448
+ */
449
+ filterCursorInstances() {
450
+ const objects = this.map.objects;
451
+ const objectData = this.data.hitObjectData;
452
+ const firstObjectResult = objectData[0].result;
453
+ const lastObjectResult = objectData.at(-1).result;
454
+ const isPrecise = this.map.mods.some((m) => m instanceof osuBase.ModPrecise);
455
+ // For sliders, automatically set hit window length to be as lenient as possible.
456
+ let firstObjectHitWindow = this.hitWindow.hitWindowFor50(isPrecise);
457
+ if (objects[0].object instanceof osuBase.Circle) {
458
+ switch (firstObjectResult) {
459
+ case exports.hitResult.RESULT_300:
460
+ firstObjectHitWindow =
461
+ this.hitWindow.hitWindowFor300(isPrecise);
462
+ break;
463
+ case exports.hitResult.RESULT_100:
464
+ firstObjectHitWindow =
465
+ this.hitWindow.hitWindowFor100(isPrecise);
466
+ break;
467
+ default:
468
+ firstObjectHitWindow =
469
+ this.hitWindow.hitWindowFor50(isPrecise);
470
+ }
471
+ }
472
+ // For sliders, automatically set hit window length to be as lenient as possible.
473
+ let lastObjectHitWindow = this.hitWindow.hitWindowFor50(isPrecise);
474
+ if (objects.at(-1).object instanceof osuBase.Circle) {
475
+ switch (lastObjectResult) {
476
+ case exports.hitResult.RESULT_300:
477
+ lastObjectHitWindow =
478
+ this.hitWindow.hitWindowFor300(isPrecise);
479
+ break;
480
+ case exports.hitResult.RESULT_100:
481
+ lastObjectHitWindow =
482
+ this.hitWindow.hitWindowFor100(isPrecise);
483
+ break;
484
+ default:
485
+ lastObjectHitWindow =
486
+ this.hitWindow.hitWindowFor50(isPrecise);
487
+ }
488
+ }
489
+ // These hit time uses hit window length as threshold.
490
+ // This is because cursors aren't recorded exactly at hit time,
491
+ // probably due to the game's behavior.
492
+ const firstObjectHitTime = objects[0].object.startTime - firstObjectHitWindow;
493
+ const lastObjectHitTime = objects.at(-1).object.startTime + lastObjectHitWindow;
494
+ for (let i = 0; i < this.data.cursorMovement.length; ++i) {
495
+ const cursorInstance = this.data.cursorMovement[i];
496
+ const newCursorData = new CursorData({
497
+ size: 0,
498
+ time: [],
499
+ x: [],
500
+ y: [],
501
+ id: [],
502
+ });
503
+ for (let j = 0; j < cursorInstance.occurrences.length; ++j) {
504
+ if (cursorInstance.occurrences[j].id !== exports.movementType.DOWN) {
505
+ continue;
506
+ }
507
+ const time = cursorInstance.occurrences[j].time;
508
+ if (time < firstObjectHitTime || time > lastObjectHitTime) {
509
+ continue;
510
+ }
511
+ if (this.breakPointAccurateTimes.some((v) => time >= v.startTime && time <= v.endTime)) {
512
+ continue;
513
+ }
514
+ newCursorData.occurrences.push(new CursorOccurrence(time, cursorInstance.occurrences[j].position.x, cursorInstance.occurrences[j].position.y, cursorInstance.occurrences[j].id));
515
+ }
516
+ this.downCursorInstances.push(newCursorData);
517
+ }
518
+ }
519
+ /**
520
+ * Divides the beatmap into sections, which will be used to
521
+ * detect dragged sections and improve detection speed.
522
+ */
523
+ getBeatmapSections() {
524
+ const beatmapSections = BeatmapSectionGenerator.generateSections(this.map, this.minSectionObjectCount, this.maxSectionDeltaTime);
525
+ for (const beatmapSection of beatmapSections) {
526
+ this.beatmapSections.push(new ThreeFingerBeatmapSection({
527
+ firstObjectIndex: beatmapSection.firstObjectIndex,
528
+ lastObjectIndex: beatmapSection.lastObjectIndex,
529
+ isDragged: false,
530
+ dragFingerIndex: -1,
531
+ }));
532
+ }
533
+ }
534
+ /**
535
+ * Checks whether or not each beatmap sections is dragged.
536
+ */
537
+ detectDragPlay() {
538
+ for (let i = 0; i < this.beatmapSections.length; ++i) {
539
+ const dragIndex = this.checkDrag(this.beatmapSections[i]);
540
+ this.beatmapSections[i].dragFingerIndex = dragIndex;
541
+ this.beatmapSections[i].isDragged = dragIndex !== -1;
542
+ }
543
+ }
544
+ /**
545
+ * Checks if a section is dragged and returns the index of the drag finger.
546
+ *
547
+ * If the section is not dragged, -1 will be returned.
548
+ *
549
+ * @param section The section to check.
550
+ */
551
+ checkDrag(section) {
552
+ const objects = this.map.objects;
553
+ const objectData = this.data.hitObjectData;
554
+ const isPrecise = this.map.mods.some((m) => m instanceof osuBase.ModPrecise);
555
+ const firstObject = objects[section.firstObjectIndex];
556
+ const lastObject = objects[section.lastObjectIndex];
557
+ let firstObjectMinHitTime = firstObject.object.startTime;
558
+ if (firstObject.object instanceof osuBase.Circle) {
559
+ switch (objectData[section.firstObjectIndex].result) {
560
+ case exports.hitResult.RESULT_300:
561
+ firstObjectMinHitTime -=
562
+ this.hitWindow.hitWindowFor300(isPrecise);
563
+ break;
564
+ case exports.hitResult.RESULT_100:
565
+ firstObjectMinHitTime -=
566
+ this.hitWindow.hitWindowFor100(isPrecise);
567
+ break;
568
+ default:
569
+ firstObjectMinHitTime -=
570
+ this.hitWindow.hitWindowFor50(isPrecise);
571
+ }
572
+ }
573
+ else {
574
+ firstObjectMinHitTime -= this.hitWindow.hitWindowFor50(isPrecise);
575
+ }
576
+ let lastObjectMaxHitTime = lastObject.object.startTime;
577
+ if (lastObject.object instanceof osuBase.Circle) {
578
+ switch (objectData[section.lastObjectIndex].result) {
579
+ case exports.hitResult.RESULT_300:
580
+ lastObjectMaxHitTime +=
581
+ this.hitWindow.hitWindowFor300(isPrecise);
582
+ break;
583
+ case exports.hitResult.RESULT_100:
584
+ lastObjectMaxHitTime +=
585
+ this.hitWindow.hitWindowFor100(isPrecise);
586
+ break;
587
+ default:
588
+ lastObjectMaxHitTime +=
589
+ this.hitWindow.hitWindowFor50(isPrecise);
590
+ }
591
+ }
592
+ else {
593
+ lastObjectMaxHitTime += this.hitWindow.hitWindowFor50(isPrecise);
594
+ }
595
+ // Since there may be more than 1 cursor instance index,
596
+ // we check which cursor instance follows hitobjects all over.
597
+ const cursorIndexes = [];
598
+ for (let i = 0; i < this.data.cursorMovement.length; ++i) {
599
+ const c = this.data.cursorMovement[i];
600
+ if (c.occurrences.length === 0) {
601
+ continue;
602
+ }
603
+ // Do not include cursors that don't have an occurence in this section
604
+ // this speeds up checking process.
605
+ if (c.occurrences.filter((v) => v.time >= firstObjectMinHitTime &&
606
+ v.time <= lastObjectMaxHitTime).length === 0) {
607
+ continue;
608
+ }
609
+ // If this cursor instance doesn't move, it's not the cursor instance we want.
610
+ if (c.occurrences.filter((v) => v.id === exports.movementType.MOVE)
611
+ .length === 0) {
612
+ continue;
613
+ }
614
+ cursorIndexes.push(i);
615
+ }
616
+ return this.findDragIndex(objects.slice(section.firstObjectIndex, section.lastObjectIndex + 1), objectData.slice(section.firstObjectIndex, section.lastObjectIndex + 1), cursorIndexes);
617
+ }
618
+ /**
619
+ * Finds the drag index of the section.
620
+ *
621
+ * @param sectionObjects The objects in the section.
622
+ * @param sectionReplayObjectData The hitobject data of all objects in the section.
623
+ * @param cursorIndexes The indexes of the cursor instance that has at least an occurrence in the section.
624
+ */
625
+ findDragIndex(sectionObjects, sectionReplayObjectData, cursorIndexes) {
626
+ let objectIndex = sectionObjects.findIndex((v, i) => !(v.object instanceof osuBase.Spinner) &&
627
+ sectionReplayObjectData[i].result !== exports.hitResult.RESULT_0);
628
+ if (objectIndex === -1) {
629
+ return -1;
630
+ }
631
+ while (cursorIndexes.length > 0) {
632
+ if (objectIndex === sectionObjects.length) {
633
+ break;
634
+ }
635
+ const o = sectionObjects[objectIndex];
636
+ const s = sectionReplayObjectData[objectIndex];
637
+ ++objectIndex;
638
+ if (s.result === exports.hitResult.RESULT_0) {
639
+ continue;
640
+ }
641
+ // Get the cursor instance that is closest to the object's hit time.
642
+ for (let j = 0; j < cursorIndexes.length; ++j) {
643
+ const c = this.data.cursorMovement[cursorIndexes[j]];
644
+ // Cursor instances aren't always recorded at all times,
645
+ // therefore the game emulates the movement between
646
+ // movementType.MOVE cursors.
647
+ const hitTime = o.object.startTime + s.accuracy;
648
+ const nextHitIndex = c.occurrences.findIndex((v) => v.time >= hitTime);
649
+ const hitIndex = nextHitIndex - 1;
650
+ if (hitIndex <= -1) {
651
+ cursorIndexes[j] = -1;
652
+ continue;
653
+ }
654
+ if (c.occurrences[hitIndex].id === exports.movementType.UP) {
655
+ cursorIndexes[j] = -1;
656
+ continue;
657
+ }
658
+ const cursorPosition = new osuBase.Vector2(c.occurrences[hitIndex].position.x, c.occurrences[hitIndex].position.y);
659
+ let isInObject = false;
660
+ if (c.occurrences[nextHitIndex].id === exports.movementType.MOVE ||
661
+ c.occurrences[hitIndex].id === exports.movementType.MOVE) {
662
+ // Try to interpolate movement between two movementType.MOVE cursor every 1ms.
663
+ // This minimizes rounding error.
664
+ for (let mSecPassed = c.occurrences[hitIndex].time; mSecPassed <= c.occurrences[nextHitIndex].time; ++mSecPassed) {
665
+ const t = (mSecPassed - c.occurrences[nextHitIndex].time) /
666
+ (c.occurrences[hitIndex].time -
667
+ c.occurrences[nextHitIndex].time);
668
+ cursorPosition.x = osuBase.Interpolation.lerp(c.occurrences[hitIndex].position.x, c.occurrences[nextHitIndex].position.x, t);
669
+ cursorPosition.y = osuBase.Interpolation.lerp(c.occurrences[hitIndex].position.y, c.occurrences[nextHitIndex].position.y, t);
670
+ if (o.object.stackedPosition.getDistance(cursorPosition) <= o.object.radius) {
671
+ isInObject = true;
672
+ break;
673
+ }
674
+ }
675
+ }
676
+ else {
677
+ isInObject =
678
+ o.object.stackedPosition.getDistance(cursorPosition) <=
679
+ o.object.radius;
680
+ }
681
+ if (!isInObject) {
682
+ cursorIndexes[j] = -1;
683
+ }
684
+ }
685
+ cursorIndexes = cursorIndexes.filter((v) => v !== -1);
686
+ }
687
+ return cursorIndexes.shift() ?? -1;
688
+ }
689
+ /**
690
+ * Redivides the beatmap into sections.
691
+ *
692
+ * The result will be used to detect for three-fingered
693
+ * sections.
694
+ */
695
+ getDetailedBeatmapSections() {
696
+ const objects = this.map.objects;
697
+ const newBeatmapSections = [];
698
+ for (const beatmapSection of this.beatmapSections) {
699
+ let inSpeedSection = false;
700
+ let newFirstObjectIndex = beatmapSection.firstObjectIndex;
701
+ for (let i = beatmapSection.firstObjectIndex; i <= beatmapSection.lastObjectIndex; ++i) {
702
+ if (!inSpeedSection &&
703
+ objects[i].originalTapStrain >=
704
+ ThreeFingerChecker.strainThreshold) {
705
+ inSpeedSection = true;
706
+ newFirstObjectIndex = i;
707
+ continue;
708
+ }
709
+ if (inSpeedSection &&
710
+ objects[i].originalTapStrain <
711
+ ThreeFingerChecker.strainThreshold) {
712
+ inSpeedSection = false;
713
+ newBeatmapSections.push({
714
+ firstObjectIndex: newFirstObjectIndex,
715
+ lastObjectIndex: i,
716
+ isDragged: beatmapSection.isDragged,
717
+ dragFingerIndex: beatmapSection.dragFingerIndex,
718
+ });
719
+ }
720
+ }
721
+ // Don't forget to manually add the last beatmap section, which would otherwise be ignored.
722
+ if (inSpeedSection) {
723
+ newBeatmapSections.push({
724
+ firstObjectIndex: newFirstObjectIndex,
725
+ lastObjectIndex: beatmapSection.lastObjectIndex,
726
+ isDragged: beatmapSection.isDragged,
727
+ dragFingerIndex: beatmapSection.dragFingerIndex,
728
+ });
729
+ }
730
+ }
731
+ this.beatmapSections.length = 0;
732
+ this.beatmapSections.push(...newBeatmapSections);
733
+ }
734
+ /**
735
+ * Attempts to prevent accidental taps from being flagged.
736
+ *
737
+ * This detection will filter cursors that don't hit
738
+ * any object in beatmap sections, thus eliminating any
739
+ * unnecessary taps.
740
+ */
741
+ preventAccidentalTaps() {
742
+ let filledCursorAmount = this.downCursorInstances.filter((v) => v.occurrences.length > 0).length;
743
+ if (filledCursorAmount <= 3) {
744
+ return;
745
+ }
746
+ const objects = this.map.objects;
747
+ const totalCursorAmount = this.downCursorInstances.reduce((acc, value) => acc + value.occurrences.length, 0);
748
+ for (let i = 0; i < this.downCursorInstances.length; ++i) {
749
+ if (filledCursorAmount <= 3) {
750
+ break;
751
+ }
752
+ const cursorInstance = this.downCursorInstances[i];
753
+ // Use an estimation for accidental tap threshold.
754
+ if (cursorInstance.occurrences.length <=
755
+ Math.ceil(objects.length / this.accidentalTapThreshold) &&
756
+ cursorInstance.occurrences.length / totalCursorAmount <
757
+ this.threeFingerRatioThreshold * 2) {
758
+ --filledCursorAmount;
759
+ cursorInstance.occurrences.length = 0;
760
+ }
761
+ this.downCursorInstances[i] = cursorInstance;
762
+ }
763
+ }
764
+ /**
765
+ * Creates nerf factors by scanning through objects.
766
+ *
767
+ * This check will ignore all objects with speed strain below `strainThreshold`.
768
+ */
769
+ calculateNerfFactors() {
770
+ const objects = this.map.objects;
771
+ const objectData = this.data.hitObjectData;
772
+ const isPrecise = this.data.convertedMods.some((m) => m instanceof osuBase.ModPrecise);
773
+ // We only filter cursor instances that are above the strain threshold.
774
+ // This minimalizes the amount of cursor instances to analyze.
775
+ for (const beatmapSection of this.beatmapSections) {
776
+ const dragIndex = beatmapSection.dragFingerIndex;
777
+ const startTime = objects[beatmapSection.firstObjectIndex].object.startTime +
778
+ (objectData[beatmapSection.firstObjectIndex].result !==
779
+ exports.hitResult.RESULT_0
780
+ ? objectData[beatmapSection.firstObjectIndex].accuracy
781
+ : -this.hitWindow.hitWindowFor50(isPrecise));
782
+ const endTime = objects[beatmapSection.lastObjectIndex].object.endTime +
783
+ (objectData[beatmapSection.lastObjectIndex].result !==
784
+ exports.hitResult.RESULT_0
785
+ ? objectData[beatmapSection.lastObjectIndex].accuracy
786
+ : this.hitWindow.hitWindowFor50(isPrecise));
787
+ // Filter cursor instances during section.
788
+ this.downCursorInstances.forEach((c) => {
789
+ const i = c.occurrences.findIndex((t) => t.time >= startTime);
790
+ if (i !== -1) {
791
+ c.occurrences = c.occurrences.slice(0, i);
792
+ }
793
+ });
794
+ const cursorAmounts = [];
795
+ const cursorVectorTimes = [];
796
+ for (let i = 0; i < this.downCursorInstances.length; ++i) {
797
+ // Do not include drag cursor instance.
798
+ if (i === dragIndex) {
799
+ continue;
800
+ }
801
+ const cursorData = this.downCursorInstances[i];
802
+ let amount = 0;
803
+ for (let j = 0; j < cursorData.occurrences.length; ++j) {
804
+ if (cursorData.occurrences[j].time >= startTime &&
805
+ cursorData.occurrences[j].time <= endTime) {
806
+ ++amount;
807
+ cursorVectorTimes.push({
808
+ vector: new osuBase.Vector2(cursorData.occurrences[j].position.x, cursorData.occurrences[j].position.y),
809
+ time: cursorData.occurrences[j].time,
810
+ });
811
+ }
812
+ }
813
+ cursorAmounts.push(amount);
814
+ }
815
+ // This index will be used to detect if a section is 3-fingered.
816
+ // If the section is dragged, the dragged instance will be ignored,
817
+ // hence why the index is 1 less than nondragged section.
818
+ const fingerSplitIndex = dragIndex !== -1 ? 2 : 3;
819
+ // Divide >=4th (3rd for drag) cursor instances with 1st + 2nd (+ 3rd for nondrag)
820
+ // to check if the section is 3-fingered.
821
+ const threeFingerRatio = cursorAmounts
822
+ .slice(fingerSplitIndex)
823
+ .reduce((acc, value) => acc + value, 0) /
824
+ cursorAmounts
825
+ .slice(0, fingerSplitIndex)
826
+ .reduce((acc, value) => acc + value, 0);
827
+ const similarPresses = [];
828
+ for (const cursorVectorTime of cursorVectorTimes) {
829
+ const pressIndex = similarPresses.findIndex((v) => v.vector.getDistance(cursorVectorTime.vector) <=
830
+ this.cursorDistancingDistanceThreshold);
831
+ if (pressIndex !== -1) {
832
+ if (cursorVectorTime.time -
833
+ similarPresses[pressIndex].lastTime >=
834
+ this.cursorDistancingTimeThreshold) {
835
+ similarPresses.splice(pressIndex, 1);
836
+ similarPresses.push({
837
+ vector: cursorVectorTime.vector,
838
+ count: 1,
839
+ lastTime: cursorVectorTime.time,
840
+ });
841
+ continue;
842
+ }
843
+ similarPresses[pressIndex].vector = cursorVectorTime.vector;
844
+ similarPresses[pressIndex].lastTime = cursorVectorTime.time;
845
+ ++similarPresses[pressIndex].count;
846
+ }
847
+ else {
848
+ similarPresses.push({
849
+ vector: cursorVectorTime.vector,
850
+ count: 1,
851
+ lastTime: cursorVectorTime.time,
852
+ });
853
+ }
854
+ }
855
+ // Sort by highest count; assume the order is 3rd, 4th, 5th, ... finger
856
+ const validPresses = similarPresses
857
+ .filter((v) => v.count >= this.cursorDistancingCountThreshold)
858
+ .sort((a, b) => {
859
+ return b.count - a.count;
860
+ })
861
+ .slice(2);
862
+ // Ignore cursor presses that are only 1 for now since they are very likely to be accidental
863
+ if ((threeFingerRatio > this.threeFingerRatioThreshold &&
864
+ cursorAmounts.filter((v) => v > 1).length > 3) ||
865
+ validPresses.length > 0) {
866
+ // Strain factor
867
+ const objectCount = beatmapSection.lastObjectIndex -
868
+ beatmapSection.firstObjectIndex +
869
+ 1;
870
+ const strainFactor = Math.pow(objects
871
+ .slice(beatmapSection.firstObjectIndex, beatmapSection.lastObjectIndex)
872
+ .reduce((acc, value) => acc +
873
+ value.originalTapStrain /
874
+ ThreeFingerChecker.strainThreshold, 0), 0.75);
875
+ // We can ignore the first 3 (2 for drag) filled cursor instances
876
+ // since they are guaranteed not 3 finger.
877
+ const threeFingerCursorAmounts = cursorAmounts
878
+ .slice(fingerSplitIndex)
879
+ .filter((amount) => amount > 0);
880
+ // Finger factor applies more penalty if more fingers were used.
881
+ const fingerFactor = threeFingerRatio > this.threeFingerRatioThreshold
882
+ ? threeFingerCursorAmounts.reduce((acc, value, index) => acc +
883
+ Math.pow(((index + 1) * value * objectCount) /
884
+ this.strainNoteCount, 0.8), 1)
885
+ : Math.pow(validPresses.reduce((acc, value, index) => acc +
886
+ Math.pow(((index + 1) *
887
+ (value.count /
888
+ (this
889
+ .cursorDistancingCountThreshold *
890
+ 2)) *
891
+ objectCount) /
892
+ this.strainNoteCount, 0.2), 1), 0.2);
893
+ // Length factor applies more penalty if there are more 3-fingered object.
894
+ const lengthFactor = 1 + Math.pow(objectCount / this.strainNoteCount, 1.2);
895
+ this.nerfFactors.push({
896
+ strainFactor: Math.max(1, strainFactor),
897
+ fingerFactor,
898
+ lengthFactor,
899
+ });
900
+ }
901
+ }
902
+ }
903
+ /**
904
+ * Calculates the final penalty.
905
+ */
906
+ calculateFinalPenalty() {
907
+ return (1 +
908
+ this.nerfFactors.reduce((a, n) => a +
909
+ 0.015 *
910
+ Math.pow(n.strainFactor * n.fingerFactor * n.lengthFactor, 1.05), 0));
911
+ }
912
+ }
913
+
914
+ /**
915
+ * Contains information about which cursor index hits a hitobject.
916
+ */
917
+ class IndexedHitObject {
918
+ /**
919
+ * The index of the cursor that hits the hitobject.
920
+ */
921
+ cursorIndex;
922
+ /**
923
+ * The underlying difficulty hitobject.
924
+ */
925
+ object;
926
+ /**
927
+ * @param object The underlying difficulty hitobject.
928
+ * @param cursorIndex The index of the cursor that hits the hitobject.
929
+ */
930
+ constructor(object, cursorIndex) {
931
+ this.object = object;
932
+ this.cursorIndex = cursorIndex;
933
+ }
934
+ }
935
+
936
+ /**
937
+ * Utility to check whether or not a beatmap is two-handed.
938
+ */
939
+ class TwoHandChecker {
940
+ /**
941
+ * The beatmap that is being analyzed.
942
+ */
943
+ map;
944
+ /**
945
+ * The data of the replay.
946
+ */
947
+ data;
948
+ /**
949
+ * The hitobjects of the beatmap that have been assigned with their respective cursor index.
950
+ */
951
+ indexedHitObjects = [];
952
+ /**
953
+ * The osu!droid hitwindow of the analyzed beatmap.
954
+ */
955
+ hitWindow;
956
+ /**
957
+ * The minimum count of a cursor index occurrence to be valid.
958
+ *
959
+ * This is used to prevent excessive penalty by splitting the beatmap into
960
+ * those that do not worth any strain.
961
+ */
962
+ minCursorIndexCount = 5;
963
+ /**
964
+ * The approximated difficulty of the current object such that the object is likely to be 2-handed by a player.
965
+ *
966
+ * This scales with an object's angle and speed relative to the previous object.
967
+ * Acute angles or fast speed will accumulate this number. Conversely, wide angles or slow speed will decay this number.
968
+ */
969
+ currentAngleDiffApproxDefault = 10;
970
+ /**
971
+ * The threshold at which objects will be started getting considered to be 2-handable.
972
+ */
973
+ currentAngleDiffApproxThreshold = 200;
974
+ /**
975
+ * @param map The beatmap to analyze.
976
+ * @param data The data of the replay.
977
+ */
978
+ constructor(map, data) {
979
+ this.map = map;
980
+ this.data = data;
981
+ const stats = new osuBase.MapStats({
982
+ od: this.map.map.difficulty.od,
983
+ mods: this.map.mods.filter((m) => !osuBase.ModUtil.speedChangingMods
984
+ .map((v) => v.droidString)
985
+ .includes(m.droidString)),
986
+ }).calculate();
987
+ this.hitWindow = new osuBase.DroidHitWindow(stats.od);
988
+ }
989
+ /**
990
+ * Checks if a beatmap is two-handed.
991
+ */
992
+ check() {
993
+ if (this.data.cursorMovement.filter((v) => v.occurrences.length > 0)
994
+ .length <= 1) {
995
+ return false;
996
+ }
997
+ this.indexHitObjects();
998
+ this.applyPenalty();
999
+ return true;
1000
+ }
1001
+ /**
1002
+ * Converts hitobjects into indexed hit objects.
1003
+ */
1004
+ indexHitObjects() {
1005
+ const hitWindowOffset = this.getHitWindowOffset();
1006
+ const indexes = [];
1007
+ let overallDiffApprox = this.currentAngleDiffApproxDefault;
1008
+ for (let i = 0; i < this.map.objects.length; ++i) {
1009
+ const diff = i > 0 ? this.getSpacingAngleDiffApprox(i) : 1;
1010
+ overallDiffApprox = osuBase.MathUtils.clamp(overallDiffApprox * diff, this.currentAngleDiffApproxDefault, this.currentAngleDiffApproxThreshold + 100);
1011
+ const index = overallDiffApprox >= this.currentAngleDiffApproxThreshold
1012
+ ? this.getCursorIndex(i, hitWindowOffset)
1013
+ : -1;
1014
+ indexes.push(index);
1015
+ this.indexedHitObjects.push(new IndexedHitObject(this.map.objects[i], index));
1016
+ }
1017
+ const indexCounts = osuBase.Utils.initializeArray(this.data.cursorMovement.length, 0);
1018
+ for (const index of indexes) {
1019
+ if (index === -1) {
1020
+ continue;
1021
+ }
1022
+ ++indexCounts[index];
1023
+ }
1024
+ const mainCursorIndex = indexCounts.indexOf(Math.max(...indexCounts));
1025
+ const ignoredCursorIndexes = [];
1026
+ for (let i = 0; i < indexCounts.length; ++i) {
1027
+ if (indexCounts[i] < this.minCursorIndexCount &&
1028
+ i !== mainCursorIndex) {
1029
+ ignoredCursorIndexes.push(i);
1030
+ }
1031
+ }
1032
+ this.indexedHitObjects.forEach((indexedHitObject) => {
1033
+ if (indexedHitObject.cursorIndex === -1 ||
1034
+ ignoredCursorIndexes.includes(indexedHitObject.cursorIndex)) {
1035
+ indexedHitObject.cursorIndex = mainCursorIndex;
1036
+ }
1037
+ });
1038
+ for (let i = 0; i < this.data.cursorMovement.length; ++i) {
1039
+ console.log("Index", i, "count:", this.indexedHitObjects.filter((v) => v.cursorIndex === i).length);
1040
+ }
1041
+ }
1042
+ /**
1043
+ * Gets the approximation of an object's difficulty such that the object is likely to be 2-handed.
1044
+ *
1045
+ * @param index The index of the object.
1046
+ */
1047
+ getSpacingAngleDiffApprox(index) {
1048
+ const object = this.map.objects[index];
1049
+ if (object.object instanceof osuBase.Spinner) {
1050
+ return 0.1;
1051
+ }
1052
+ const angleDiff = object.angle !== null
1053
+ ? 0.5 + Math.pow(Math.cos(object.angle / 2), 2)
1054
+ : 1;
1055
+ const speedDiff = object.lazyJumpDistance / Math.max(1, object.deltaTime);
1056
+ // Make decay slower.
1057
+ return Math.max(0.8, angleDiff * speedDiff);
1058
+ }
1059
+ /**
1060
+ * Gets the hit window offset to be applied to `getCursorIndex`.
1061
+ */
1062
+ getHitWindowOffset() {
1063
+ const deltaTimes = [];
1064
+ for (let i = 0; i < this.data.cursorMovement.length; ++i) {
1065
+ const c = this.data.cursorMovement[i];
1066
+ for (let j = 0; j < c.occurrences.length; ++j) {
1067
+ if (c.occurrences[j].time <
1068
+ this.map.map.hitObjects.objects[0].startTime -
1069
+ this.hitWindow.hitWindowFor50()) {
1070
+ continue;
1071
+ }
1072
+ if (c.occurrences[j].id !== exports.movementType.MOVE) {
1073
+ continue;
1074
+ }
1075
+ const deltaTime = c.occurrences[j]?.time - c.occurrences[j - 1]?.time || 0;
1076
+ if (deltaTime > 0) {
1077
+ deltaTimes.push(deltaTime);
1078
+ }
1079
+ }
1080
+ }
1081
+ return Math.min(...deltaTimes);
1082
+ }
1083
+ /**
1084
+ * Gets the cursor index that hits the given object.
1085
+ *
1086
+ * @param index The index of the object to check.
1087
+ * @param hitWindowOffset The offset for hit window to compensate for replay hit inaccuracies.
1088
+ * @returns The cursor index that hits the given object, -1 if the index is not found, the object is a spinner, or the object was missed.
1089
+ */
1090
+ getCursorIndex(index, hitWindowOffset) {
1091
+ const object = this.map.objects[index];
1092
+ const data = this.data.hitObjectData[index];
1093
+ if (object.object instanceof osuBase.Spinner ||
1094
+ data.result === exports.hitResult.RESULT_0) {
1095
+ return -1;
1096
+ }
1097
+ const isPrecise = this.data.convertedMods.some((m) => m instanceof osuBase.ModPrecise);
1098
+ // For sliders, automatically set hit window to be as lenient as possible.
1099
+ let hitWindowLength = this.hitWindow.hitWindowFor50(isPrecise);
1100
+ if (!(object.object instanceof osuBase.Slider)) {
1101
+ switch (data.result) {
1102
+ case exports.hitResult.RESULT_300:
1103
+ hitWindowLength = this.hitWindow.hitWindowFor300(isPrecise);
1104
+ break;
1105
+ case exports.hitResult.RESULT_100:
1106
+ hitWindowLength = this.hitWindow.hitWindowFor100(isPrecise);
1107
+ break;
1108
+ }
1109
+ }
1110
+ const startTime = object.object.startTime;
1111
+ const hitTime = startTime + data.accuracy;
1112
+ const minimumHitTime = startTime - hitWindowLength - hitWindowOffset;
1113
+ const maximumHitTime = startTime + hitWindowLength + hitWindowOffset;
1114
+ const cursorInformations = [];
1115
+ for (let i = 0; i < this.data.cursorMovement.length; ++i) {
1116
+ const c = this.data.cursorMovement[i];
1117
+ if (c.occurrences.length === 0) {
1118
+ continue;
1119
+ }
1120
+ let hitTimeBeforeIndex = osuBase.MathUtils.clamp(c.occurrences.findIndex((v) => v.time >= minimumHitTime), 0, c.occurrences.length - 2);
1121
+ let hitTimeAfterIndex = c.occurrences.findIndex(
1122
+ // There is a special case for sliders where the time leniency in droid is a lot bigger compared to PC.
1123
+ // To prevent slider end time from ending earlier than hit window leniency, we use the maximum value between both.
1124
+ (v) => v.time >= Math.max(object.object.endTime, maximumHitTime));
1125
+ if (hitTimeAfterIndex === -1) {
1126
+ // Maximum hit time or object end time may be out of bounds for every presses.
1127
+ // We set the index to the latest cursor occurrence if that happens.
1128
+ hitTimeAfterIndex = c.occurrences.length;
1129
+ }
1130
+ --hitTimeAfterIndex;
1131
+ // Sometimes a `movementType.UP` instance occurs at the same time as a `movementType.MOVE`
1132
+ // or a cursor is recorded twice in one time, therefore this check is required.
1133
+ while (c.occurrences[hitTimeBeforeIndex]?.time ===
1134
+ c.occurrences[hitTimeBeforeIndex - 1]?.time &&
1135
+ hitTimeBeforeIndex > 0) {
1136
+ --hitTimeBeforeIndex;
1137
+ }
1138
+ // We track the cursor movement along those indexes.
1139
+ // Current cursor position is in `hitTimeBeforeIndex`.
1140
+ let distance = Number.POSITIVE_INFINITY;
1141
+ let acceptableRadius = object.object.radius;
1142
+ // Sliders have a bigger radius tolerance due to slider ball.
1143
+ if (object.object instanceof osuBase.Slider) {
1144
+ acceptableRadius *= 2.4;
1145
+ }
1146
+ let j = hitTimeBeforeIndex;
1147
+ for (j; j <= hitTimeAfterIndex; ++j) {
1148
+ const occurrence = c.occurrences[j];
1149
+ const nextOccurrence = c.occurrences[j + 1];
1150
+ const cursorPosition = occurrence.position;
1151
+ if (occurrence.time > hitTime + hitWindowOffset) {
1152
+ // Set distance to minimum just for the last.
1153
+ if (occurrence.id !== exports.movementType.UP) {
1154
+ distance = Math.min(distance, object.object.stackedPosition.getDistance(cursorPosition));
1155
+ }
1156
+ break;
1157
+ }
1158
+ if (occurrence.id === exports.movementType.UP) {
1159
+ continue;
1160
+ }
1161
+ distance =
1162
+ object.object.stackedPosition.getDistance(cursorPosition);
1163
+ if (nextOccurrence &&
1164
+ nextOccurrence.id === exports.movementType.MOVE &&
1165
+ occurrence.time !== nextOccurrence.time &&
1166
+ !occurrence.position.equals(nextOccurrence.position)) {
1167
+ // If next cursor is a `move` instance and it doesn't go out of time
1168
+ // range, we interpolate cursor position between two occurrences.
1169
+ const nextPosition = nextOccurrence.position;
1170
+ const displacement = nextPosition.subtract(cursorPosition);
1171
+ for (let mSecPassed = Math.max(minimumHitTime, occurrence.time); mSecPassed <=
1172
+ Math.min(hitTime + hitWindowOffset, nextOccurrence.time); ++mSecPassed) {
1173
+ const progress = (mSecPassed - occurrence.time) /
1174
+ (nextOccurrence.time - occurrence.time);
1175
+ distance = object.object.stackedPosition.getDistance(cursorPosition.add(displacement.scale(progress)));
1176
+ }
1177
+ }
1178
+ }
1179
+ if (distance > acceptableRadius) {
1180
+ continue;
1181
+ }
1182
+ // The case for a one-handed object is that there will be a slight movement in the cursor towards
1183
+ // the next object in fast patterns. We should not be worried about slow patterns as they will only
1184
+ // make a minimal difference and the difficulty approximation we did earlier should filter them out.
1185
+ // In order to verify if the player does that, we check if the movement towards the next
1186
+ // object is sufficient enough to be two-handed. This is done by checking if the movement
1187
+ // from the current object to the next object and the movement from the current object
1188
+ // to the significant move cursor occurrence produces an angle that is acute enough.
1189
+ let isAngleFulfilled = false;
1190
+ // For sliders, we need to consider two cases. The first case is when the player doesn't drag
1191
+ // the slider. The second case is when the player drags the slider.
1192
+ // TODO: check for cursor occurrences in nested objects
1193
+ // Get the latest down or movement cursor occurrence.
1194
+ while (c.occurrences[j]?.id === exports.movementType.UP &&
1195
+ j > hitTimeBeforeIndex) {
1196
+ --j;
1197
+ }
1198
+ if (object.object instanceof osuBase.Circle) {
1199
+ // For circles, we only need to consider the actual press on the circle.
1200
+ // Therefore, we need to get the latest down cursor occurrence instead.
1201
+ while (c.occurrences[j]?.id !== exports.movementType.DOWN &&
1202
+ j > hitTimeBeforeIndex) {
1203
+ --j;
1204
+ }
1205
+ }
1206
+ // Theoretically there can only be 1 up occurrence, but this is a
1207
+ // consideration if the user manually adds cursor occurrences.
1208
+ if (c.occurrences[j]?.id === exports.movementType.UP) {
1209
+ ++j;
1210
+ }
1211
+ // Some move instances move in the exact same place. Not sure why, most likely
1212
+ // because the position is recorded as int in the game and the movement is too small to
1213
+ // convert into +1 or -1.
1214
+ let nextSignificantOccurrenceIndex = j + 1;
1215
+ while (c.occurrences[j] &&
1216
+ c.occurrences[nextSignificantOccurrenceIndex] &&
1217
+ c.occurrences[j].position.equals(c.occurrences[nextSignificantOccurrenceIndex].position)) {
1218
+ ++nextSignificantOccurrenceIndex;
1219
+ }
1220
+ const nextSignificantOccurrence = c.occurrences[nextSignificantOccurrenceIndex];
1221
+ const next = this.map.objects[index + 1];
1222
+ if (nextSignificantOccurrence?.id === exports.movementType.MOVE && next) {
1223
+ // Get the object's actual end position.
1224
+ let actualEndPosition = object.object.stackedEndPosition;
1225
+ if (object.object instanceof osuBase.Slider &&
1226
+ object.object.lazyEndPosition) {
1227
+ // For sliders, we take the closest distance between the lazy end position
1228
+ // and stacked end position towards the next significant cursor occurrence.
1229
+ // This assumes that the player takes the simpler movement.
1230
+ const lazyEndDistance = object.object.lazyEndPosition.getDistance(nextSignificantOccurrence.position);
1231
+ const actualEndDistance = object.object.stackedEndPosition.getDistance(nextSignificantOccurrence.position);
1232
+ if (lazyEndDistance < actualEndDistance) {
1233
+ actualEndPosition = object.object.lazyEndPosition;
1234
+ }
1235
+ }
1236
+ // Get the movement vector towards the next cursor occurrence by subtracting
1237
+ // the next cursor occurrence with the object's position.
1238
+ const movementVec = nextSignificantOccurrence.position.subtract(actualEndPosition);
1239
+ const currentToNext = next.object.stackedPosition.subtract(actualEndPosition);
1240
+ const dot = currentToNext.dot(movementVec);
1241
+ const det = currentToNext.x * movementVec.y -
1242
+ currentToNext.y * movementVec.x;
1243
+ const movementToNextAngle = Math.abs(Math.atan2(det, dot));
1244
+ isAngleFulfilled = movementToNextAngle < Math.PI / 6;
1245
+ }
1246
+ cursorInformations.push({
1247
+ // If the angle is fulfilled, we set the cursor index to the main cursor index.
1248
+ cursorIndex: isAngleFulfilled ? i : -1,
1249
+ distanceDiff: distance,
1250
+ });
1251
+ }
1252
+ // Cursors have been filtered to see which of them is inside the object.
1253
+ // Now we look at which cursor is closest to the center of the object.
1254
+ const minDistanceDiff = Math.min(...cursorInformations.map((v) => {
1255
+ return v.distanceDiff;
1256
+ }));
1257
+ return (cursorInformations.find((c) => c.distanceDiff === minDistanceDiff)
1258
+ ?.cursorIndex ?? -1);
1259
+ }
1260
+ /**
1261
+ * Applies penalty to the original star rating instance.
1262
+ */
1263
+ applyPenalty() {
1264
+ const beatmaps = new Array(this.data.cursorMovement.length);
1265
+ this.indexedHitObjects.forEach((o) => {
1266
+ if (!beatmaps[o.cursorIndex]) {
1267
+ const map = osuBase.Utils.deepCopy(this.map.map);
1268
+ map.hitObjects.clear();
1269
+ beatmaps[o.cursorIndex] = map;
1270
+ }
1271
+ beatmaps[o.cursorIndex].hitObjects.add(o.object.object);
1272
+ });
1273
+ // Keep rhythm values as we don't intend to calculate for them.
1274
+ const rhythmValues = this.map.objects.map((v) => {
1275
+ return {
1276
+ strain: v.rhythmStrain,
1277
+ multiplier: v.rhythmMultiplier,
1278
+ };
1279
+ });
1280
+ this.map.objects.length = 0;
1281
+ beatmaps.forEach((beatmap) => {
1282
+ if (!beatmap) {
1283
+ return;
1284
+ }
1285
+ const starRating = osuBase.Utils.deepCopy(this.map);
1286
+ starRating.map = beatmap;
1287
+ starRating.generateDifficultyHitObjects();
1288
+ starRating.objects[0].deltaTime =
1289
+ starRating.objects[0].startTime -
1290
+ this.indexedHitObjects[0].object.startTime;
1291
+ starRating.objects[0].strainTime = Math.max(25, starRating.objects[0].deltaTime);
1292
+ this.map.objects.push(...starRating.objects);
1293
+ });
1294
+ this.map.objects.sort((a, b) => a.startTime - b.startTime);
1295
+ // Reassign rhythm values before calculating.
1296
+ for (let i = 0; i < this.map.objects.length; ++i) {
1297
+ this.map.objects[i].rhythmStrain = rhythmValues[i].strain;
1298
+ this.map.objects[i].rhythmMultiplier = rhythmValues[i].multiplier;
1299
+ }
1300
+ // Do not include rhythm skill.
1301
+ this.map.calculateAim();
1302
+ this.map.calculateTap();
1303
+ this.map.calculateFlashlight();
1304
+ this.map.calculateVisual();
1305
+ this.map.calculateTotal();
1306
+ }
1307
+ }
1308
+
1309
+ /**
1310
+ * A replay analyzer that analyzes a replay from osu!droid.
1311
+ *
1312
+ * Created by reverse engineering the replay parser from the game itself, which can be found {@link https://github.com/osudroid/osu-droid/blob/master/src/ru/nsu/ccfit/zuev/osu/scoring/Replay.java here}.
1313
+ *
1314
+ * Once analyzed, the result can be accessed via the `data` property.
1315
+ */
1316
+ class ReplayAnalyzer {
1317
+ /**
1318
+ * The score ID of the replay.
1319
+ */
1320
+ scoreID;
1321
+ /**
1322
+ * The original odr file of the replay.
1323
+ */
1324
+ originalODR = null;
1325
+ /**
1326
+ * The fixed odr file of the replay.
1327
+ */
1328
+ fixedODR = null;
1329
+ /**
1330
+ * Whether or not the play is considered using >=3 finger abuse.
1331
+ */
1332
+ is3Finger;
1333
+ /**
1334
+ * Whether or not the play is considered 2-handed.
1335
+ */
1336
+ is2Hand;
1337
+ /**
1338
+ * The beatmap that is being analyzed. `DroidStarRating` or `RebalanceDroidStarRating` is required for three finger or two hand analyzing.
1339
+ */
1340
+ map;
1341
+ /**
1342
+ * The results of the analyzer. `null` when initialized.
1343
+ */
1344
+ data = null;
1345
+ /**
1346
+ * Penalty value used to penalize dpp for 2-hand.
1347
+ */
1348
+ aimPenalty = 1;
1349
+ /**
1350
+ * Penalty value used to penalize dpp for 3 finger abuse.
1351
+ */
1352
+ tapPenalty = 1;
1353
+ /**
1354
+ * Whether this replay has been checked against 3 finger usage.
1355
+ */
1356
+ hasBeenCheckedFor3Finger = false;
1357
+ /**
1358
+ * Whether this replay has been checked against 2 hand usage.
1359
+ */
1360
+ hasBeenCheckedFor2Hand = false;
1361
+ // Sizes of primitive data types in Java (in bytes)
1362
+ BYTE_LENGTH = 1;
1363
+ SHORT_LENGTH = 2;
1364
+ INT_LENGTH = 4;
1365
+ FLOAT_LENGTH = 4;
1366
+ LONG_LENGTH = 8;
1367
+ constructor(values) {
1368
+ this.scoreID = values.scoreID;
1369
+ this.map = values.map;
1370
+ }
1371
+ /**
1372
+ * Analyzes a replay.
1373
+ */
1374
+ async analyze() {
1375
+ if (!this.originalODR && !this.fixedODR) {
1376
+ this.originalODR = await this.downloadReplay();
1377
+ }
1378
+ if (!this.originalODR) {
1379
+ return this;
1380
+ }
1381
+ if (!this.fixedODR) {
1382
+ this.fixedODR = await this.decompress().catch(() => {
1383
+ return null;
1384
+ });
1385
+ }
1386
+ if (!this.fixedODR) {
1387
+ return this;
1388
+ }
1389
+ this.parseReplay();
1390
+ return this;
1391
+ }
1392
+ /**
1393
+ * Downloads the given score ID's replay.
1394
+ */
1395
+ async downloadReplay() {
1396
+ const apiRequestBuilder = new osuBase.DroidAPIRequestBuilder()
1397
+ .setRequireAPIkey(false)
1398
+ .setEndpoint("upload")
1399
+ .addParameter("", `${this.scoreID}.odr`);
1400
+ const result = await apiRequestBuilder.sendRequest();
1401
+ if (result.statusCode !== 200) {
1402
+ return null;
1403
+ }
1404
+ return result.data;
1405
+ }
1406
+ /**
1407
+ * Decompresses a replay.
1408
+ *
1409
+ * The decompressed replay is in a form of Java object. This will be converted to a buffer and deserialized to read data from the replay.
1410
+ */
1411
+ decompress() {
1412
+ return new Promise((resolve, reject) => {
1413
+ const stream$1 = new stream.Readable();
1414
+ stream$1.push(this.originalODR);
1415
+ stream$1.push(null);
1416
+ stream$1
1417
+ .pipe(unzipper.Parse())
1418
+ .on("entry", async (entry) => {
1419
+ const fileName = entry.path;
1420
+ if (fileName === "data") {
1421
+ return resolve(await entry.buffer());
1422
+ }
1423
+ else {
1424
+ entry.autodrain();
1425
+ }
1426
+ })
1427
+ .on("error", (e) => {
1428
+ setTimeout(() => reject(e), 2000);
1429
+ });
1430
+ });
1431
+ }
1432
+ /**
1433
+ * Parses a replay after being downloaded and converted to a buffer.
1434
+ */
1435
+ parseReplay() {
1436
+ // javaDeserialization can only somewhat parse some string field
1437
+ // the rest will be a buffer that we need to manually parse
1438
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1439
+ let rawObject;
1440
+ try {
1441
+ rawObject = javaDeserialization__namespace.parse(this.fixedODR);
1442
+ }
1443
+ catch {
1444
+ return;
1445
+ }
1446
+ const resultObject = {
1447
+ replayVersion: rawObject[0].version,
1448
+ folderName: rawObject[1],
1449
+ fileName: rawObject[2],
1450
+ hash: rawObject[3],
1451
+ cursorMovement: [],
1452
+ hitObjectData: [],
1453
+ };
1454
+ if (resultObject.replayVersion >= 3) {
1455
+ resultObject.time = new Date(Number(rawObject[4].readBigUInt64BE(0)));
1456
+ resultObject.hit300k = rawObject[4].readInt32BE(8);
1457
+ resultObject.hit100k = rawObject[4].readInt32BE(16);
1458
+ resultObject.score = rawObject[4].readInt32BE(32);
1459
+ resultObject.maxCombo = rawObject[4].readInt32BE(36);
1460
+ resultObject.accuracy = new osuBase.Accuracy({
1461
+ n300: rawObject[4].readInt32BE(12),
1462
+ n100: rawObject[4].readInt32BE(20),
1463
+ n50: rawObject[4].readInt32BE(24),
1464
+ nmiss: rawObject[4].readInt32BE(28),
1465
+ });
1466
+ resultObject.isFullCombo = !!rawObject[4][44];
1467
+ resultObject.playerName = rawObject[5];
1468
+ resultObject.rawMods = rawObject[6].elements;
1469
+ resultObject.convertedMods = this.convertMods(rawObject[6].elements);
1470
+ // Determine rank
1471
+ const totalHits = resultObject.accuracy.n300 +
1472
+ resultObject.accuracy.n100 +
1473
+ resultObject.accuracy.n50 +
1474
+ resultObject.accuracy.nmiss;
1475
+ const isHidden = resultObject.convertedMods.some((m) => m instanceof osuBase.ModHidden || m instanceof osuBase.ModFlashlight);
1476
+ const hit300Ratio = resultObject.accuracy.n300 / totalHits;
1477
+ switch (true) {
1478
+ case resultObject.accuracy.value() === 1:
1479
+ if (isHidden) {
1480
+ resultObject.rank = "XH";
1481
+ }
1482
+ else {
1483
+ resultObject.rank = "X";
1484
+ }
1485
+ break;
1486
+ case hit300Ratio > 0.9 &&
1487
+ resultObject.accuracy.n50 / totalHits < 0.01 &&
1488
+ !resultObject.accuracy.nmiss:
1489
+ if (isHidden) {
1490
+ resultObject.rank = "SH";
1491
+ }
1492
+ else {
1493
+ resultObject.rank = "S";
1494
+ }
1495
+ break;
1496
+ case (hit300Ratio > 0.8 && !resultObject.accuracy.nmiss) ||
1497
+ hit300Ratio > 0.9:
1498
+ resultObject.rank = "A";
1499
+ break;
1500
+ case (hit300Ratio > 0.7 && !resultObject.accuracy.nmiss) ||
1501
+ hit300Ratio > 0.8:
1502
+ resultObject.rank = "B";
1503
+ break;
1504
+ case hit300Ratio > 0.6:
1505
+ resultObject.rank = "C";
1506
+ break;
1507
+ default:
1508
+ resultObject.rank = "D";
1509
+ }
1510
+ }
1511
+ if (resultObject.replayVersion >= 4) {
1512
+ const s = rawObject[7].split("|");
1513
+ resultObject.speedModification =
1514
+ parseFloat(s[0].replace("x", "")) || 1;
1515
+ if (s.length > 1) {
1516
+ resultObject.forcedAR = parseFloat(s[1].replace("AR", ""));
1517
+ }
1518
+ }
1519
+ let bufferIndex;
1520
+ switch (true) {
1521
+ // replay v4 and above
1522
+ case resultObject.replayVersion >= 4:
1523
+ bufferIndex = 8;
1524
+ break;
1525
+ // replay v3
1526
+ case resultObject.replayVersion === 3:
1527
+ bufferIndex = 7;
1528
+ break;
1529
+ // replay v1 and v2
1530
+ default:
1531
+ bufferIndex = 4;
1532
+ }
1533
+ const replayDataBufferArray = [];
1534
+ for (bufferIndex; bufferIndex < rawObject.length; ++bufferIndex) {
1535
+ replayDataBufferArray.push(rawObject[bufferIndex]);
1536
+ }
1537
+ // Merge all cursor movement and hit object data section into one for better control when parsing
1538
+ const replayDataBuffer = Buffer.concat(replayDataBufferArray);
1539
+ let bufferCounter = 0;
1540
+ const size = replayDataBuffer.readInt32BE(bufferCounter);
1541
+ bufferCounter += this.INT_LENGTH;
1542
+ // Parse movement data
1543
+ for (let x = 0; x < size; x++) {
1544
+ const moveSize = replayDataBuffer.readInt32BE(bufferCounter);
1545
+ bufferCounter += this.INT_LENGTH;
1546
+ const time = [];
1547
+ const x = [];
1548
+ const y = [];
1549
+ const id = [];
1550
+ for (let i = 0; i < moveSize; i++) {
1551
+ time[i] = replayDataBuffer.readInt32BE(bufferCounter);
1552
+ bufferCounter += this.INT_LENGTH;
1553
+ id[i] = time[i] & 3;
1554
+ time[i] >>= 2;
1555
+ if (id[i] !== exports.movementType.UP) {
1556
+ if (resultObject.replayVersion >= 5) {
1557
+ x[i] = replayDataBuffer.readFloatBE(bufferCounter);
1558
+ bufferCounter += this.FLOAT_LENGTH;
1559
+ y[i] = replayDataBuffer.readFloatBE(bufferCounter);
1560
+ bufferCounter += this.FLOAT_LENGTH;
1561
+ }
1562
+ else {
1563
+ x[i] = replayDataBuffer.readInt16BE(bufferCounter);
1564
+ bufferCounter += this.SHORT_LENGTH;
1565
+ y[i] = replayDataBuffer.readInt16BE(bufferCounter);
1566
+ bufferCounter += this.SHORT_LENGTH;
1567
+ }
1568
+ }
1569
+ else {
1570
+ x[i] = -1;
1571
+ y[i] = -1;
1572
+ }
1573
+ }
1574
+ resultObject.cursorMovement.push(new CursorData({
1575
+ size: moveSize,
1576
+ time: time,
1577
+ x: x,
1578
+ y: y,
1579
+ id: id,
1580
+ }));
1581
+ }
1582
+ const replayObjectLength = replayDataBuffer.readInt32BE(bufferCounter);
1583
+ bufferCounter += this.INT_LENGTH;
1584
+ // Parse result data
1585
+ for (let i = 0; i < replayObjectLength; i++) {
1586
+ const replayObjectData = {
1587
+ accuracy: 0,
1588
+ tickset: [],
1589
+ result: 0,
1590
+ };
1591
+ replayObjectData.accuracy =
1592
+ replayDataBuffer.readInt16BE(bufferCounter);
1593
+ bufferCounter += this.SHORT_LENGTH;
1594
+ const len = replayDataBuffer.readInt8(bufferCounter);
1595
+ bufferCounter += this.BYTE_LENGTH;
1596
+ if (len > 0) {
1597
+ const bytes = [];
1598
+ for (let j = 0; j < len; j++) {
1599
+ bytes.push(replayDataBuffer.readInt8(bufferCounter));
1600
+ bufferCounter += this.BYTE_LENGTH;
1601
+ }
1602
+ // Int/int division in Java; numbers must be truncated to get actual number
1603
+ for (let j = 0; j < len * 8; j++) {
1604
+ replayObjectData.tickset[j] =
1605
+ (bytes[len - Math.trunc(j / 8) - 1] &
1606
+ (1 << Math.trunc(j % 8))) !==
1607
+ 0;
1608
+ }
1609
+ }
1610
+ if (resultObject.replayVersion >= 1) {
1611
+ replayObjectData.result =
1612
+ replayDataBuffer.readInt8(bufferCounter);
1613
+ bufferCounter += this.BYTE_LENGTH;
1614
+ }
1615
+ resultObject.hitObjectData.push(replayObjectData);
1616
+ }
1617
+ // Parse max combo, hit results, and accuracy in old replay version
1618
+ if (resultObject.replayVersion < 3 && this.map) {
1619
+ let hit300 = 0;
1620
+ let hit300k = 0;
1621
+ let hit100 = 0;
1622
+ let hit100k = 0;
1623
+ let hit50 = 0;
1624
+ let hit0 = 0;
1625
+ let grantsGekiOrKatu = true;
1626
+ const objects = (this.map instanceof osuDifficultyCalculator.DroidStarRating ||
1627
+ this.map instanceof osuRebalanceDifficultyCalculator.DroidStarRating
1628
+ ? this.map.map
1629
+ : this.map).hitObjects.objects;
1630
+ for (let i = 0; i < resultObject.hitObjectData.length; ++i) {
1631
+ // Hit result
1632
+ const hitObjectData = resultObject.hitObjectData[i];
1633
+ const isNextNewCombo = i + 1 !== objects.length ? objects[i + 1].isNewCombo : true;
1634
+ switch (hitObjectData.result) {
1635
+ case exports.hitResult.RESULT_0:
1636
+ ++hit0;
1637
+ grantsGekiOrKatu = false;
1638
+ break;
1639
+ case exports.hitResult.RESULT_50:
1640
+ ++hit50;
1641
+ grantsGekiOrKatu = false;
1642
+ break;
1643
+ case exports.hitResult.RESULT_100:
1644
+ ++hit100;
1645
+ if (grantsGekiOrKatu && isNextNewCombo) {
1646
+ ++hit100k;
1647
+ }
1648
+ break;
1649
+ case exports.hitResult.RESULT_300:
1650
+ ++hit300;
1651
+ if (grantsGekiOrKatu && isNextNewCombo) {
1652
+ ++hit300k;
1653
+ }
1654
+ break;
1655
+ }
1656
+ if (isNextNewCombo) {
1657
+ grantsGekiOrKatu = true;
1658
+ }
1659
+ }
1660
+ resultObject.hit300k = hit300k;
1661
+ resultObject.hit100k = hit100k;
1662
+ resultObject.accuracy = new osuBase.Accuracy({
1663
+ n300: hit300,
1664
+ n100: hit100,
1665
+ n50: hit50,
1666
+ nmiss: hit0,
1667
+ nobjects: hit300 + hit100 + hit50 + hit0,
1668
+ });
1669
+ // Determine rank
1670
+ const totalHits = resultObject.accuracy.n300 +
1671
+ resultObject.accuracy.n100 +
1672
+ resultObject.accuracy.n50 +
1673
+ resultObject.accuracy.nmiss;
1674
+ const isHidden = resultObject.convertedMods?.some((m) => m instanceof osuBase.ModHidden || m instanceof osuBase.ModFlashlight) ?? false;
1675
+ const hit300Ratio = resultObject.accuracy.n300 / totalHits;
1676
+ switch (true) {
1677
+ case resultObject.accuracy.value() === 1:
1678
+ if (isHidden) {
1679
+ resultObject.rank = "XH";
1680
+ }
1681
+ else {
1682
+ resultObject.rank = "X";
1683
+ }
1684
+ break;
1685
+ case hit300Ratio > 0.9 &&
1686
+ resultObject.accuracy.n50 / totalHits < 0.01 &&
1687
+ !resultObject.accuracy.nmiss:
1688
+ if (isHidden) {
1689
+ resultObject.rank = "SH";
1690
+ }
1691
+ else {
1692
+ resultObject.rank = "S";
1693
+ }
1694
+ break;
1695
+ case (hit300Ratio > 0.8 && !resultObject.accuracy.nmiss) ||
1696
+ hit300Ratio > 0.9:
1697
+ resultObject.rank = "A";
1698
+ break;
1699
+ case (hit300Ratio > 0.7 && !resultObject.accuracy.nmiss) ||
1700
+ hit300Ratio > 0.8:
1701
+ resultObject.rank = "B";
1702
+ break;
1703
+ case hit300Ratio > 0.6:
1704
+ resultObject.rank = "C";
1705
+ break;
1706
+ default:
1707
+ resultObject.rank = "D";
1708
+ }
1709
+ }
1710
+ this.data = new ReplayData(resultObject);
1711
+ }
1712
+ /**
1713
+ * Gets hit error information of the replay.
1714
+ *
1715
+ * `analyze()` must be called before calling this.
1716
+ */
1717
+ calculateHitError() {
1718
+ if (!this.data || !this.map) {
1719
+ return null;
1720
+ }
1721
+ const hitObjectData = this.data.hitObjectData;
1722
+ let positiveCount = 0;
1723
+ let negativeCount = 0;
1724
+ let positiveTotal = 0;
1725
+ let negativeTotal = 0;
1726
+ const objects = (this.map instanceof osuDifficultyCalculator.DroidStarRating ||
1727
+ this.map instanceof osuRebalanceDifficultyCalculator.DroidStarRating
1728
+ ? this.map.map
1729
+ : this.map).hitObjects.objects;
1730
+ for (let i = 0; i < hitObjectData.length; ++i) {
1731
+ const v = hitObjectData[i];
1732
+ const o = objects[i];
1733
+ if (o instanceof osuBase.Spinner || v.result === exports.hitResult.RESULT_0) {
1734
+ continue;
1735
+ }
1736
+ const accuracy = v.accuracy;
1737
+ if (accuracy >= 0) {
1738
+ positiveTotal += accuracy;
1739
+ ++positiveCount;
1740
+ }
1741
+ else {
1742
+ negativeTotal += accuracy;
1743
+ ++negativeCount;
1744
+ }
1745
+ }
1746
+ return {
1747
+ positiveAvg: positiveTotal / positiveCount || 0,
1748
+ negativeAvg: negativeTotal / negativeCount || 0,
1749
+ unstableRate: osuBase.MathUtils.calculateStandardDeviation(hitObjectData.map((v, i) => v.result !== exports.hitResult.RESULT_0 &&
1750
+ !(objects[i] instanceof osuBase.Spinner)
1751
+ ? v.accuracy
1752
+ : 0)) * 10,
1753
+ };
1754
+ }
1755
+ /**
1756
+ * Converts replay mods to droid mod string.
1757
+ */
1758
+ convertDroidMods(replayMods) {
1759
+ const replayModsConstants = {
1760
+ MOD_NOFAIL: "n",
1761
+ MOD_EASY: "e",
1762
+ MOD_HIDDEN: "h",
1763
+ MOD_HARDROCK: "r",
1764
+ MOD_DOUBLETIME: "d",
1765
+ MOD_HALFTIME: "t",
1766
+ MOD_NIGHTCORE: "c",
1767
+ MOD_PRECISE: "s",
1768
+ MOD_SMALLCIRCLE: "m",
1769
+ MOD_SPEEDUP: "b",
1770
+ MOD_REALLYEASY: "l",
1771
+ MOD_PERFECT: "f",
1772
+ MOD_SUDDENDEATH: "u",
1773
+ MOD_SCOREV2: "v",
1774
+ };
1775
+ let modString = "";
1776
+ for (const mod of replayMods) {
1777
+ for (const property in replayModsConstants) {
1778
+ if (!(property in replayModsConstants)) {
1779
+ continue;
1780
+ }
1781
+ if (!mod.includes(property)) {
1782
+ continue;
1783
+ }
1784
+ modString +=
1785
+ replayModsConstants[property];
1786
+ break;
1787
+ }
1788
+ }
1789
+ return modString;
1790
+ }
1791
+ /**
1792
+ * Converts replay mods to regular mod string.
1793
+ */
1794
+ convertMods(replayMods) {
1795
+ return osuBase.ModUtil.droidStringToMods(this.convertDroidMods(replayMods));
1796
+ }
1797
+ /**
1798
+ * Checks if a play is using 3 fingers.
1799
+ *
1800
+ * Requires `analyze()` to be called first and `map` to be defined as `DroidStarRating` or `RebalanceDroidStarRating`.
1801
+ */
1802
+ checkFor3Finger() {
1803
+ if (!(this.map instanceof osuDifficultyCalculator.DroidStarRating ||
1804
+ this.map instanceof osuRebalanceDifficultyCalculator.DroidStarRating) ||
1805
+ !this.data) {
1806
+ return;
1807
+ }
1808
+ const threeFingerChecker = new ThreeFingerChecker(this.map, this.data);
1809
+ const result = threeFingerChecker.check();
1810
+ this.is3Finger = result.is3Finger;
1811
+ this.tapPenalty = result.penalty;
1812
+ this.hasBeenCheckedFor3Finger = true;
1813
+ }
1814
+ /**
1815
+ * Checks if a play is using 2 hands.
1816
+ *
1817
+ * Requires `analyze()` to be called first and `map` to be defined as `DroidStarRating` or `RebalanceDroidStarRating`.
1818
+ */
1819
+ checkFor2Hand() {
1820
+ if (!(this.map instanceof osuDifficultyCalculator.DroidStarRating ||
1821
+ this.map instanceof osuRebalanceDifficultyCalculator.DroidStarRating) ||
1822
+ !this.data) {
1823
+ return;
1824
+ }
1825
+ const twoHandChecker = new TwoHandChecker(this.map, this.data);
1826
+ this.is2Hand = twoHandChecker.check();
1827
+ this.hasBeenCheckedFor2Hand = true;
1828
+ }
1829
+ }
1830
+
1831
+ /**
1832
+ * Represents a hitobject in an osu!droid replay.
1833
+ *
1834
+ * Stores information about hitobjects in an osu!droid replay such as hit offset, tickset, and hit result.
1835
+ *
1836
+ * This is used when analyzing replays using replay analyzer.
1837
+ */
1838
+ class ReplayObjectData {
1839
+ /**
1840
+ * The offset of which the hitobject was hit in milliseconds.
1841
+ */
1842
+ accuracy;
1843
+ /**
1844
+ * The tickset of the hitobject.
1845
+ *
1846
+ * This is used to determine whether or not a slider event (tick/repeat/end) is hit based on the order they appear.
1847
+ */
1848
+ tickset;
1849
+ /**
1850
+ * The bitwise hit result of the hitobject.
1851
+ */
1852
+ result;
1853
+ constructor(values) {
1854
+ this.accuracy = values.accuracy;
1855
+ this.tickset = values.tickset;
1856
+ this.result = values.result;
1857
+ }
1858
+ }
1859
+
1860
+ exports.CursorData = CursorData;
1861
+ exports.CursorOccurrence = CursorOccurrence;
1862
+ exports.ReplayAnalyzer = ReplayAnalyzer;
1863
+ exports.ReplayData = ReplayData;
1864
+ exports.ReplayObjectData = ReplayObjectData;
1865
+ exports.ThreeFingerChecker = ThreeFingerChecker;
1866
+ //# sourceMappingURL=index.js.map