@rian8337/osu-droid-replay-analyzer 4.0.0-beta.102 → 4.0.0-beta.104

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.cjs ADDED
@@ -0,0 +1,1811 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let _rian8337_osu_base = require("@rian8337/osu-base");
3
+ let _rian8337_osu_droid_replay = require("@rian8337/osu-droid-replay");
4
+ // src/analysis/RebalanceSliderCheeseChecker.ts
5
+ /**
6
+ * Utility to check whether relevant sliders in a beatmap are cheesed for rebalance scores.
7
+ */
8
+ var RebalanceSliderCheeseChecker = class {
9
+ /**
10
+ * The beatmap that is being analyzed.
11
+ */
12
+ beatmap;
13
+ /**
14
+ * The data of the replay.
15
+ */
16
+ data;
17
+ /**
18
+ * The difficulty attributes of the beatmap.
19
+ */
20
+ difficultyAttributes;
21
+ /**
22
+ * The 50 osu!droid hit window of the analyzed beatmap.
23
+ */
24
+ hitWindow50;
25
+ isHardRock;
26
+ /**
27
+ * @param beatmap The beatmap to analyze.
28
+ * @param data The data of the replay.
29
+ * @param difficultyAttributes The difficulty attributes of the beatmap.
30
+ */
31
+ constructor(beatmap, data, difficultyAttributes) {
32
+ this.beatmap = beatmap;
33
+ this.data = data;
34
+ this.difficultyAttributes = difficultyAttributes;
35
+ this.hitWindow50 = _rian8337_osu_base.HitWindowFactory.createDroid(beatmap.difficulty.od, difficultyAttributes.mods.has(_rian8337_osu_base.ModPrecise)).mehWindow;
36
+ this.isHardRock = difficultyAttributes.mods.has(_rian8337_osu_base.ModHardRock);
37
+ }
38
+ /**
39
+ * Checks if relevant sliders in the given beatmap was cheesed.
40
+ */
41
+ check() {
42
+ if (this.difficultyAttributes.difficultSliders.length === 0 || this.difficultyAttributes.sliderFactor === 1) return 1;
43
+ const cheesedDifficultyRatings = this.checkSliderCheesing();
44
+ return this.calculateSliderCheesePenalty(cheesedDifficultyRatings);
45
+ }
46
+ /**
47
+ * Checks for sliders that were cheesed.
48
+ */
49
+ checkSliderCheesing() {
50
+ const { objects } = this.beatmap.hitObjects;
51
+ const cheesedDifficultyRatings = [];
52
+ const cursorLoopIndices = _rian8337_osu_base.Utils.initializeArray(this.data.cursorMovement.length, 0);
53
+ const acceptableRadius = objects[0].radius * 2;
54
+ for (const difficultSlider of this.difficultyAttributes.difficultSliders.slice().sort((a, b) => a.index - b.index)) {
55
+ if (difficultSlider.index >= this.data.hitObjectData.length) continue;
56
+ const object = objects[difficultSlider.index];
57
+ const objectData = this.data.hitObjectData[difficultSlider.index];
58
+ if (objectData.result === _rian8337_osu_base.HitResult.Miss) continue;
59
+ let lateHitThreshold = this.hitWindow50;
60
+ if (this.data.replayVersion < 8) lateHitThreshold = Math.min(lateHitThreshold, object.duration);
61
+ if (objectData.accuracy < -this.hitWindow50 || objectData.accuracy > lateHitThreshold) continue;
62
+ const objectStartPosition = object.stackedPosition;
63
+ const minTimeLimit = object.startTime - this.hitWindow50;
64
+ const maxTimeLimit = object.startTime + this.hitWindow50;
65
+ const closestDistances = [];
66
+ const closestGroupIndices = [];
67
+ for (let i = 0; i < this.data.cursorMovement.length; ++i) {
68
+ const cursorGroups = this.data.cursorMovement[i].occurrenceGroups;
69
+ let closestDistance = Number.POSITIVE_INFINITY;
70
+ let closestIndex = cursorGroups.length;
71
+ for (let j = cursorLoopIndices[i]; j < cursorGroups.length; j = ++cursorLoopIndices[i]) {
72
+ const group = cursorGroups[j];
73
+ if (group.endTime < minTimeLimit) continue;
74
+ if (group.startTime > maxTimeLimit) break;
75
+ if (group.startTime >= minTimeLimit) {
76
+ const distance = this.getCursorPosition(group.down).getDistance(objectStartPosition);
77
+ if (closestDistance > distance) {
78
+ closestDistance = distance;
79
+ closestIndex = j;
80
+ }
81
+ if (closestDistance <= acceptableRadius / 2) break;
82
+ }
83
+ const { allOccurrences } = group;
84
+ for (let k = 1; k < allOccurrences.length; ++k) {
85
+ const cursor = allOccurrences[k];
86
+ const prevCursor = allOccurrences[k - 1];
87
+ let distance = Number.POSITIVE_INFINITY;
88
+ const currentPosition = this.getCursorPosition(cursor);
89
+ const prevPosition = this.getCursorPosition(prevCursor);
90
+ switch (cursor.id) {
91
+ case _rian8337_osu_droid_replay.MovementType.Up:
92
+ distance = prevPosition.getDistance(objectStartPosition);
93
+ break;
94
+ case _rian8337_osu_droid_replay.MovementType.Move: for (let mSecPassed = Math.max(prevCursor.time, minTimeLimit); mSecPassed <= Math.min(cursor.time, maxTimeLimit); ++mSecPassed) {
95
+ const t = (mSecPassed - prevCursor.time) / (cursor.time - prevCursor.time);
96
+ distance = _rian8337_osu_base.Interpolation.lerp(prevPosition, currentPosition, t).getDistance(objectStartPosition);
97
+ if (closestDistance > distance) {
98
+ closestDistance = distance;
99
+ closestIndex = j;
100
+ }
101
+ if (closestDistance <= acceptableRadius / 2) break;
102
+ }
103
+ }
104
+ if (closestDistance > distance) {
105
+ closestDistance = distance;
106
+ closestIndex = j;
107
+ }
108
+ if (closestDistance <= acceptableRadius / 2) break;
109
+ }
110
+ }
111
+ closestDistances.push(closestDistance);
112
+ closestGroupIndices.push(closestIndex);
113
+ if (cursorLoopIndices[i] > 0) --cursorLoopIndices[i];
114
+ }
115
+ const cursorIndex = closestDistances.indexOf(Math.min(...closestDistances));
116
+ if (closestDistances[cursorIndex] > acceptableRadius / 2) {
117
+ cheesedDifficultyRatings.push(difficultSlider.difficultyRating);
118
+ continue;
119
+ }
120
+ const group = this.data.cursorMovement[cursorIndex].occurrenceGroups[closestGroupIndices[cursorIndex]];
121
+ let isCheesed = false;
122
+ let occurrenceLoopIndex = 1;
123
+ const { allOccurrences } = group;
124
+ const headHitTime = object.startTime + objectData.accuracy;
125
+ const judgesPassedNestedObjectsOnHeadHit = this.data.replayVersion >= 6;
126
+ let headHitBallPosition = null;
127
+ let headHitCursorPosition = null;
128
+ for (let i = 1; i < object.nestedHitObjects.length; ++i) {
129
+ if (isCheesed) break;
130
+ if (!objectData.tickset[i - 1]) continue;
131
+ const nestedObject = object.nestedHitObjects[i];
132
+ const nestedPosition = nestedObject.stackedPosition;
133
+ if (judgesPassedNestedObjectsOnHeadHit && nestedObject.startTime <= headHitTime) {
134
+ headHitBallPosition ??= object.stackedPosition.add(object.curvePositionAt(_rian8337_osu_base.MathUtils.clamp((headHitTime - object.startTime) / object.duration, 0, 1)));
135
+ headHitCursorPosition ??= this.getCursorPositionAt(group, headHitTime);
136
+ isCheesed = headHitCursorPosition.getDistance(headHitBallPosition) > acceptableRadius || nestedPosition.getDistance(headHitBallPosition) > acceptableRadius;
137
+ continue;
138
+ }
139
+ while (occurrenceLoopIndex < allOccurrences.length && allOccurrences[occurrenceLoopIndex].time < nestedObject.startTime) ++occurrenceLoopIndex;
140
+ if (occurrenceLoopIndex === allOccurrences.length) continue;
141
+ const cursor = allOccurrences[occurrenceLoopIndex];
142
+ const prevCursor = allOccurrences[occurrenceLoopIndex - 1];
143
+ const currentPosition = this.getCursorPosition(cursor);
144
+ const prevPosition = this.getCursorPosition(prevCursor);
145
+ switch (cursor.id) {
146
+ case _rian8337_osu_droid_replay.MovementType.Move: {
147
+ const t = (nestedObject.startTime - prevCursor.time) / (cursor.time - prevCursor.time);
148
+ isCheesed = _rian8337_osu_base.Interpolation.lerp(prevPosition, currentPosition, t).getDistance(nestedPosition) > acceptableRadius;
149
+ break;
150
+ }
151
+ case _rian8337_osu_droid_replay.MovementType.Up: isCheesed = prevPosition.getDistance(nestedPosition) > acceptableRadius;
152
+ }
153
+ }
154
+ if (isCheesed) cheesedDifficultyRatings.push(difficultSlider.difficultyRating);
155
+ }
156
+ return cheesedDifficultyRatings;
157
+ }
158
+ /**
159
+ * Calculates the slider cheese penalty.
160
+ */
161
+ calculateSliderCheesePenalty(cheesedDifficultyRatings) {
162
+ const summedDifficultyRating = Math.min(1, cheesedDifficultyRatings.reduce((a, v) => a + v, 0));
163
+ return Math.max(this.difficultyAttributes.sliderFactor, Math.pow(1 - summedDifficultyRating * this.difficultyAttributes.sliderFactor, 2));
164
+ }
165
+ /**
166
+ * Obtains the position of a cursor occurrence group at a given time.
167
+ *
168
+ * @param group The cursor occurrence group.
169
+ * @param time The time.
170
+ * @returns The position of the cursor at the given time, clamped to the group's active time.
171
+ */
172
+ getCursorPositionAt(group, time) {
173
+ const { allOccurrences } = group;
174
+ if (time <= allOccurrences[0].time) return this.getCursorPosition(allOccurrences[0]);
175
+ for (let i = 1; i < allOccurrences.length; ++i) {
176
+ const cursor = allOccurrences[i];
177
+ if (cursor.time < time) continue;
178
+ const prevCursor = allOccurrences[i - 1];
179
+ const prevPosition = this.getCursorPosition(prevCursor);
180
+ if (cursor.id === _rian8337_osu_droid_replay.MovementType.Up) return prevPosition;
181
+ return _rian8337_osu_base.Interpolation.lerp(prevPosition, this.getCursorPosition(cursor), _rian8337_osu_base.Interpolation.reverseLerp(time, prevCursor.time, cursor.time));
182
+ }
183
+ const lastCursor = allOccurrences.at(-1);
184
+ return this.getCursorPosition(lastCursor.id === _rian8337_osu_droid_replay.MovementType.Up && allOccurrences.length > 1 ? allOccurrences[allOccurrences.length - 2] : lastCursor);
185
+ }
186
+ getCursorPosition(cursor) {
187
+ if (this.isHardRock) return new _rian8337_osu_base.Vector2(cursor.position.x, _rian8337_osu_base.Playfield.baseSize.y - cursor.position.y);
188
+ return cursor.position;
189
+ }
190
+ };
191
+ // src/analysis/RebalanceThreeFingerChecker.ts
192
+ /**
193
+ * Utility to check whether or not a beatmap is three-fingered for rebalance scores.
194
+ */
195
+ var RebalanceThreeFingerChecker = class RebalanceThreeFingerChecker {
196
+ /**
197
+ * The beatmap that is being analyzed.
198
+ */
199
+ beatmap;
200
+ /**
201
+ * The data of the replay.
202
+ */
203
+ data;
204
+ /**
205
+ * The difficulty attributes of the beatmap.
206
+ */
207
+ difficultyAttributes;
208
+ /**
209
+ * Extended sections of the beatmap for drag detection.
210
+ */
211
+ beatmapSections = [];
212
+ /**
213
+ * The hit window of this beatmap. Keep in mind that speed-changing mods do not change hit window length in game logic.
214
+ */
215
+ hitWindow;
216
+ /**
217
+ * A reprocessed break points to match right on object time.
218
+ *
219
+ * This is used to increase detection accuracy since break points do not start right at the
220
+ * start of the hitobject before it and do not end right at the first hitobject after it.
221
+ */
222
+ breakPointAccurateTimes = [];
223
+ /**
224
+ * A cursor occurrence nested array that only contains `movementType.DOWN` movement ID occurrences.
225
+ *
226
+ * Each index represents the cursor index.
227
+ */
228
+ downCursorInstances = [];
229
+ /**
230
+ * Nerf factors from all sections that were three-fingered.
231
+ */
232
+ nerfFactors = [];
233
+ isHardRock;
234
+ /**
235
+ * @param beatmap The beatmap to analyze.
236
+ * @param data The data of the replay.
237
+ * @param difficultyAttributes The difficulty attributes of the beatmap.
238
+ */
239
+ constructor(beatmap, data, difficultyAttributes) {
240
+ this.beatmap = beatmap;
241
+ this.data = data;
242
+ this.difficultyAttributes = difficultyAttributes;
243
+ this.isHardRock = difficultyAttributes.mods.has(_rian8337_osu_base.ModHardRock);
244
+ this.hitWindow = _rian8337_osu_base.HitWindowFactory.createDroid(beatmap.difficulty.od, difficultyAttributes.mods.has(_rian8337_osu_base.ModPrecise));
245
+ }
246
+ /**
247
+ * Checks whether a beatmap is eligible to be detected for 3-finger.
248
+ *
249
+ * @param difficultyAttributes The difficulty attributes of the beatmap.
250
+ */
251
+ static isEligibleToDetect(difficultyAttributes) {
252
+ return difficultyAttributes.possibleThreeFingeredSections.length > 0;
253
+ }
254
+ /**
255
+ * Checks if the given beatmap is 3-fingered and also returns the final penalty.
256
+ *
257
+ * The beatmap will be separated into sections and each section will be determined
258
+ * whether or not it is dragged.
259
+ *
260
+ * After that, each section will be assigned a nerf factor based on whether or not
261
+ * the section is 3-fingered. These nerf factors will be summed up into a final
262
+ * nerf factor, taking beatmap difficulty into account.
263
+ */
264
+ check() {
265
+ if (!RebalanceThreeFingerChecker.isEligibleToDetect(this.difficultyAttributes) || this.data.cursorMovement.filter((v) => v.occurrenceGroups.length > 0).length <= 3) return {
266
+ is3Finger: false,
267
+ penalty: 1
268
+ };
269
+ this.getAccurateBreakPoints();
270
+ this.filterCursorInstances();
271
+ this.getBeatmapSections();
272
+ this.calculateNerfFactors();
273
+ const finalPenalty = this.calculateFinalPenalty();
274
+ return {
275
+ is3Finger: finalPenalty > 1,
276
+ penalty: finalPenalty
277
+ };
278
+ }
279
+ /**
280
+ * Generates a new set of "accurate break points".
281
+ *
282
+ * This is done to increase detection accuracy since break points do not start right at the
283
+ * end of the hitobject before it and do not end right at the first hitobject after it.
284
+ */
285
+ getAccurateBreakPoints() {
286
+ const objects = this.beatmap.hitObjects.objects;
287
+ const objectData = this.data.hitObjectData;
288
+ for (const breakPoint of this.beatmap.events.breaks) {
289
+ const beforeIndex = _rian8337_osu_base.MathUtils.clamp(objects.findIndex((o) => o.endTime >= breakPoint.startTime) - 1, 0, objects.length - 2);
290
+ const objectBefore = objects[beforeIndex];
291
+ const objectBeforeData = objectData[beforeIndex];
292
+ let timeBefore = objectBefore.endTime;
293
+ if (objectBefore instanceof _rian8337_osu_base.Circle) {
294
+ if (objectBeforeData.result !== _rian8337_osu_base.HitResult.Miss) timeBefore += objectBeforeData.accuracy;
295
+ else timeBefore += this.hitWindow.mehWindow;
296
+ }
297
+ const afterIndex = beforeIndex + 1;
298
+ const objectAfter = objects[afterIndex];
299
+ const objectAfterData = objectData[afterIndex];
300
+ let timeAfter = objectAfter.startTime;
301
+ if (objectAfter instanceof _rian8337_osu_base.Circle && objectAfterData.result !== _rian8337_osu_base.HitResult.Miss) timeAfter += objectAfterData.accuracy;
302
+ this.breakPointAccurateTimes.push(new _rian8337_osu_base.BreakPoint(timeBefore, timeAfter));
303
+ }
304
+ }
305
+ /**
306
+ * Filters the original cursor instances, returning only those with `movementType.DOWN` movement ID.
307
+ *
308
+ * This also filters cursors that are in break period or happen before start/after end of the beatmap.
309
+ */
310
+ filterCursorInstances() {
311
+ const objects = this.beatmap.hitObjects.objects;
312
+ const objectData = this.data.hitObjectData;
313
+ const firstObjectResult = objectData[0].result;
314
+ const lastObjectResult = objectData.at(-1).result;
315
+ const firstObject = objects[0];
316
+ const lastObject = objects.at(-1);
317
+ let firstObjectHitWindow = this.hitWindow.mehWindow;
318
+ if (firstObject instanceof _rian8337_osu_base.Circle) switch (firstObjectResult) {
319
+ case _rian8337_osu_base.HitResult.Great:
320
+ firstObjectHitWindow = this.hitWindow.greatWindow;
321
+ break;
322
+ case _rian8337_osu_base.HitResult.Good:
323
+ firstObjectHitWindow = this.hitWindow.okWindow;
324
+ break;
325
+ default: firstObjectHitWindow = this.hitWindow.mehWindow;
326
+ }
327
+ let lastObjectHitWindow = this.hitWindow.mehWindow;
328
+ if (lastObject instanceof _rian8337_osu_base.Circle) switch (lastObjectResult) {
329
+ case _rian8337_osu_base.HitResult.Great:
330
+ lastObjectHitWindow = this.hitWindow.greatWindow;
331
+ break;
332
+ case _rian8337_osu_base.HitResult.Good:
333
+ lastObjectHitWindow = this.hitWindow.okWindow;
334
+ break;
335
+ default: lastObjectHitWindow = this.hitWindow.mehWindow;
336
+ }
337
+ else if (lastObject instanceof _rian8337_osu_base.Slider) lastObjectHitWindow = Math.min(lastObject.spanDuration, lastObjectHitWindow);
338
+ const firstObjectHitTime = firstObject.startTime - firstObjectHitWindow;
339
+ const lastObjectHitTime = lastObject.startTime + lastObjectHitWindow;
340
+ for (const cursorInstance of this.data.cursorMovement) {
341
+ const validOccurrences = [];
342
+ for (const group of cursorInstance.occurrenceGroups) {
343
+ if (group.startTime < firstObjectHitTime) continue;
344
+ if (group.startTime > lastObjectHitTime) break;
345
+ if (this.breakPointAccurateTimes.some((v) => group.startTime >= v.startTime && group.endTime <= v.endTime)) continue;
346
+ validOccurrences.push(group.down);
347
+ }
348
+ this.downCursorInstances.push(validOccurrences);
349
+ }
350
+ }
351
+ /**
352
+ * Divides the beatmap into sections, which will be used to
353
+ * detect dragged sections and improve detection speed.
354
+ */
355
+ getBeatmapSections() {
356
+ const beatmapObjects = this.beatmap.hitObjects.objects;
357
+ const aimCursorGroupLookupIndices = _rian8337_osu_base.Utils.initializeArray(this.downCursorInstances.length, 0);
358
+ const aimCursorLookupIndices = _rian8337_osu_base.Utils.initializeArray(this.downCursorInstances.length, 1);
359
+ const pressCursorLookupIndices = _rian8337_osu_base.Utils.initializeArray(this.downCursorInstances.length, 0);
360
+ for (const section of this.difficultyAttributes.possibleThreeFingeredSections) {
361
+ const objects = [];
362
+ for (let i = section.firstObjectIndex; i <= section.lastObjectIndex; ++i) {
363
+ const object = beatmapObjects[i];
364
+ const objectData = this.data.hitObjectData[i];
365
+ objects.push({
366
+ object,
367
+ aimingCursorInstanceIndex: this.getObjectAimIndex(object, objectData, aimCursorGroupLookupIndices, aimCursorLookupIndices),
368
+ pressingCursorInstanceIndex: this.getObjectPressIndex(object, objectData, pressCursorLookupIndices)
369
+ });
370
+ }
371
+ this.beatmapSections.push({
372
+ ...section,
373
+ objects
374
+ });
375
+ }
376
+ }
377
+ /**
378
+ * Obtains the index of the cursor that aimed the object at the nearest time.
379
+ *
380
+ * @param object The object to obtain the index for.
381
+ * @param objectData The hit data of the object.
382
+ * @param cursorInstanceIndices The cursor indices to start looking for the cursor instance from, to save computation time.
383
+ * @param cursorGroupIndices The cursor indices to start looking for the cursor group from, to save computation time.
384
+ * @param cursorIndices The cursor indices to start looking for the cursor from, to save computation time.
385
+ * @returns The index of the cursor, -1 if the object was missed or it's a spinner.
386
+ */
387
+ getObjectAimIndex(object, objectData, cursorGroupIndices, cursorIndices) {
388
+ if (objectData.result === _rian8337_osu_base.HitResult.Miss || object instanceof _rian8337_osu_base.Spinner) return -1;
389
+ if (object instanceof _rian8337_osu_base.Slider) {
390
+ let lateHitThreshold = this.hitWindow.mehWindow;
391
+ if (this.data.replayVersion < 8) lateHitThreshold = Math.min(lateHitThreshold, object.duration);
392
+ if (objectData.accuracy < -this.hitWindow.mehWindow || objectData.accuracy > lateHitThreshold) return -1;
393
+ }
394
+ const hitTime = object.startTime + objectData.accuracy;
395
+ const objectPosition = object.stackedPosition;
396
+ let closestDistance = Number.POSITIVE_INFINITY;
397
+ let nearestCursorIndex = -1;
398
+ for (let i = 0; i < this.data.cursorMovement.length; ++i) {
399
+ const cursorData = this.data.cursorMovement[i];
400
+ for (let j = cursorGroupIndices[i]; j < cursorData.occurrenceGroups.length; cursorGroupIndices[i] = ++j) {
401
+ const cursorGroup = cursorData.occurrenceGroups[j];
402
+ if (cursorGroup.endTime < hitTime) {
403
+ cursorIndices[i] = 1;
404
+ continue;
405
+ }
406
+ if (cursorGroup.startTime > hitTime) break;
407
+ const cursors = cursorGroup.allOccurrences;
408
+ for (let k = cursorIndices[i]; k < cursors.length; cursorIndices[i] = ++k) {
409
+ const cursor = cursors[k];
410
+ const prevCursor = cursors[k - 1];
411
+ if (prevCursor.time > hitTime) break;
412
+ if (hitTime > cursor.time) continue;
413
+ let distance;
414
+ const currentPosition = this.getCursorPosition(cursor);
415
+ const prevPosition = this.getCursorPosition(prevCursor);
416
+ switch (cursor.id) {
417
+ case _rian8337_osu_droid_replay.MovementType.Up:
418
+ distance = prevPosition.getDistance(objectPosition);
419
+ break;
420
+ case _rian8337_osu_droid_replay.MovementType.Move: {
421
+ const t = (hitTime - prevCursor.time) / (cursor.time - prevCursor.time);
422
+ const cursorPosition = _rian8337_osu_base.Interpolation.lerp(prevPosition, currentPosition, t);
423
+ distance = objectPosition.getDistance(cursorPosition);
424
+ break;
425
+ }
426
+ case _rian8337_osu_droid_replay.MovementType.Down: continue;
427
+ }
428
+ if (closestDistance > distance) {
429
+ closestDistance = distance;
430
+ nearestCursorIndex = i;
431
+ }
432
+ }
433
+ if (cursorIndices[i] === cursors.length) cursorIndices[i] = 1;
434
+ break;
435
+ }
436
+ cursorGroupIndices[i] = Math.max(0, cursorGroupIndices[i] - 1);
437
+ cursorIndices[i] = Math.max(1, cursorIndices[i] - 1);
438
+ }
439
+ return nearestCursorIndex;
440
+ }
441
+ /**
442
+ * Obtains the index of the nearest cursor of which an object was pressed in terms of time.
443
+ *
444
+ * @param object The object to obtain the index for.
445
+ * @param objectData The hit data of the object.
446
+ * @param cursorLookupIndices The cursor indices to start looking for the cursor from, to save computation time.
447
+ * @param excludedIndices The cursor indices that should not be checked.
448
+ * @returns The index of the cursor, -1 if the object was missed or it's a spinner.
449
+ */
450
+ getObjectPressIndex(object, objectData, cursorLookupIndices) {
451
+ if (objectData.result === _rian8337_osu_base.HitResult.Miss || object instanceof _rian8337_osu_base.Spinner) return -1;
452
+ if (object instanceof _rian8337_osu_base.Slider) {
453
+ let lateHitThreshold = this.hitWindow.mehWindow;
454
+ if (this.data.replayVersion < 8) lateHitThreshold = Math.min(lateHitThreshold, object.duration);
455
+ if (objectData.accuracy < -this.hitWindow.mehWindow || objectData.accuracy > lateHitThreshold) return -1;
456
+ }
457
+ const hitTime = object.startTime + objectData.accuracy;
458
+ let nearestCursorInstanceIndex = -1;
459
+ let nearestTime = Number.POSITIVE_INFINITY;
460
+ for (let i = 0; i < this.downCursorInstances.length; ++i) {
461
+ const cursors = this.downCursorInstances[i];
462
+ let cursorNearestTime = Number.POSITIVE_INFINITY;
463
+ for (let j = cursorLookupIndices[i]; j < cursors.length; cursorLookupIndices[i] = ++j) {
464
+ const cursor = cursors[j];
465
+ if (cursor.time > hitTime) break;
466
+ cursorNearestTime = hitTime - cursor.time;
467
+ }
468
+ if (cursorNearestTime < nearestTime) {
469
+ nearestCursorInstanceIndex = i;
470
+ nearestTime = cursorNearestTime;
471
+ }
472
+ }
473
+ return nearestCursorInstanceIndex;
474
+ }
475
+ /**
476
+ * Creates nerf factors by scanning through objects.
477
+ */
478
+ calculateNerfFactors() {
479
+ for (const beatmapSection of this.beatmapSections) {
480
+ const threeFingerCursorCounts = _rian8337_osu_base.Utils.initializeArray(Math.max(0, this.downCursorInstances.length - 2), 0);
481
+ for (const object of beatmapSection.objects) {
482
+ if (object.pressingCursorInstanceIndex === -1) continue;
483
+ if (object.aimingCursorInstanceIndex < 3) switch (object.pressingCursorInstanceIndex) {
484
+ case 0:
485
+ case 1:
486
+ case 2: break;
487
+ default: ++threeFingerCursorCounts[object.pressingCursorInstanceIndex - 3];
488
+ }
489
+ else switch (object.pressingCursorInstanceIndex) {
490
+ case 0:
491
+ case 1: break;
492
+ default: ++threeFingerCursorCounts[object.pressingCursorInstanceIndex - 2];
493
+ }
494
+ }
495
+ const threeFingerCursorCount = threeFingerCursorCounts.reduce((a, v) => a + v, 0);
496
+ if (threeFingerCursorCount === 0) continue;
497
+ const sectionObjectCount = beatmapSection.objects.length;
498
+ const threeFingeredObjectRatio = threeFingerCursorCount / sectionObjectCount;
499
+ const strainFactor = Math.max(1, beatmapSection.sumStrain * threeFingeredObjectRatio);
500
+ const fingerFactor = threeFingerCursorCounts.reduce((acc, count, index) => acc + Math.pow((index + 1) * count / sectionObjectCount, .9), 1);
501
+ const lengthFactor = 1 + Math.pow(threeFingeredObjectRatio, .8);
502
+ this.nerfFactors.push({
503
+ strainFactor,
504
+ fingerFactor,
505
+ lengthFactor
506
+ });
507
+ }
508
+ }
509
+ /**
510
+ * Calculates the final penalty.
511
+ */
512
+ calculateFinalPenalty() {
513
+ return this.nerfFactors.reduce((a, n) => a + .015 * Math.pow(n.strainFactor * n.fingerFactor * n.lengthFactor, 1.05), 1);
514
+ }
515
+ getCursorPosition(cursor) {
516
+ if (this.isHardRock) return new _rian8337_osu_base.Vector2(cursor.position.x, _rian8337_osu_base.Playfield.baseSize.y - cursor.position.y);
517
+ return cursor.position;
518
+ }
519
+ };
520
+ // src/analysis/SliderCheeseChecker.ts
521
+ /**
522
+ * Utility to check whether relevant sliders in a beatmap are cheesed for live scores.
523
+ */
524
+ var SliderCheeseChecker = class {
525
+ /**
526
+ * The beatmap that is being analyzed.
527
+ */
528
+ beatmap;
529
+ /**
530
+ * The data of the replay.
531
+ */
532
+ data;
533
+ /**
534
+ * The difficulty attributes of the beatmap.
535
+ */
536
+ difficultyAttributes;
537
+ /**
538
+ * The 50 osu!droid hit window of the analyzed beatmap.
539
+ */
540
+ hitWindow50;
541
+ isHardRock;
542
+ /**
543
+ * @param beatmap The beatmap to analyze.
544
+ * @param data The data of the replay.
545
+ * @param difficultyAttributes The difficulty attributes of the beatmap.
546
+ */
547
+ constructor(beatmap, data, difficultyAttributes) {
548
+ this.beatmap = beatmap;
549
+ this.data = data;
550
+ this.difficultyAttributes = difficultyAttributes;
551
+ this.hitWindow50 = _rian8337_osu_base.HitWindowFactory.createDroid(beatmap.difficulty.od, difficultyAttributes.mods.has(_rian8337_osu_base.ModPrecise)).mehWindow;
552
+ this.isHardRock = difficultyAttributes.mods.has(_rian8337_osu_base.ModHardRock);
553
+ }
554
+ /**
555
+ * Checks if relevant sliders in the given beatmap was cheesed.
556
+ */
557
+ check() {
558
+ if (this.difficultyAttributes.difficultSliders.length === 0 || this.difficultyAttributes.sliderFactor === 1) return 1;
559
+ const cheesedDifficultyRatings = this.checkSliderCheesing();
560
+ return this.calculateSliderCheesePenalty(cheesedDifficultyRatings);
561
+ }
562
+ /**
563
+ * Checks for sliders that were cheesed.
564
+ */
565
+ checkSliderCheesing() {
566
+ const { objects } = this.beatmap.hitObjects;
567
+ const cheesedDifficultyRatings = [];
568
+ const cursorLoopIndices = _rian8337_osu_base.Utils.initializeArray(this.data.cursorMovement.length, 0);
569
+ const acceptableRadius = objects[0].radius * 2;
570
+ for (const difficultSlider of this.difficultyAttributes.difficultSliders.slice().sort((a, b) => a.index - b.index)) {
571
+ if (difficultSlider.index >= this.data.hitObjectData.length) continue;
572
+ const object = objects[difficultSlider.index];
573
+ const objectData = this.data.hitObjectData[difficultSlider.index];
574
+ if (objectData.result === _rian8337_osu_base.HitResult.Miss) continue;
575
+ let lateHitThreshold = this.hitWindow50;
576
+ if (this.data.replayVersion < 8) lateHitThreshold = Math.min(lateHitThreshold, object.duration);
577
+ if (objectData.accuracy < -this.hitWindow50 || objectData.accuracy > lateHitThreshold) continue;
578
+ const objectStartPosition = object.stackedPosition;
579
+ const minTimeLimit = object.startTime - this.hitWindow50;
580
+ const maxTimeLimit = object.startTime + this.hitWindow50;
581
+ const closestDistances = [];
582
+ const closestGroupIndices = [];
583
+ for (let i = 0; i < this.data.cursorMovement.length; ++i) {
584
+ const cursorGroups = this.data.cursorMovement[i].occurrenceGroups;
585
+ let closestDistance = Number.POSITIVE_INFINITY;
586
+ let closestIndex = cursorGroups.length;
587
+ for (let j = cursorLoopIndices[i]; j < cursorGroups.length; j = ++cursorLoopIndices[i]) {
588
+ const group = cursorGroups[j];
589
+ if (group.endTime < minTimeLimit) continue;
590
+ if (group.startTime > maxTimeLimit) break;
591
+ if (group.startTime >= minTimeLimit) {
592
+ const distance = this.getCursorPosition(group.down).getDistance(objectStartPosition);
593
+ if (closestDistance > distance) {
594
+ closestDistance = distance;
595
+ closestIndex = j;
596
+ }
597
+ if (closestDistance <= acceptableRadius / 2) break;
598
+ }
599
+ const { allOccurrences } = group;
600
+ for (let k = 1; k < allOccurrences.length; ++k) {
601
+ const cursor = allOccurrences[k];
602
+ const prevCursor = allOccurrences[k - 1];
603
+ let distance = Number.POSITIVE_INFINITY;
604
+ const currentPosition = this.getCursorPosition(cursor);
605
+ const prevPosition = this.getCursorPosition(prevCursor);
606
+ switch (cursor.id) {
607
+ case _rian8337_osu_droid_replay.MovementType.Up:
608
+ distance = prevPosition.getDistance(objectStartPosition);
609
+ break;
610
+ case _rian8337_osu_droid_replay.MovementType.Move: for (let mSecPassed = Math.max(prevCursor.time, minTimeLimit); mSecPassed <= Math.min(cursor.time, maxTimeLimit); ++mSecPassed) {
611
+ const t = (mSecPassed - prevCursor.time) / (cursor.time - prevCursor.time);
612
+ distance = _rian8337_osu_base.Interpolation.lerp(prevPosition, currentPosition, t).getDistance(objectStartPosition);
613
+ if (closestDistance > distance) {
614
+ closestDistance = distance;
615
+ closestIndex = j;
616
+ }
617
+ if (closestDistance <= acceptableRadius / 2) break;
618
+ }
619
+ }
620
+ if (closestDistance > distance) {
621
+ closestDistance = distance;
622
+ closestIndex = j;
623
+ }
624
+ if (closestDistance <= acceptableRadius / 2) break;
625
+ }
626
+ }
627
+ closestDistances.push(closestDistance);
628
+ closestGroupIndices.push(closestIndex);
629
+ if (cursorLoopIndices[i] > 0) --cursorLoopIndices[i];
630
+ }
631
+ const cursorIndex = closestDistances.indexOf(Math.min(...closestDistances));
632
+ if (closestDistances[cursorIndex] > acceptableRadius / 2) {
633
+ cheesedDifficultyRatings.push(difficultSlider.difficultyRating);
634
+ continue;
635
+ }
636
+ const group = this.data.cursorMovement[cursorIndex].occurrenceGroups[closestGroupIndices[cursorIndex]];
637
+ let isCheesed = false;
638
+ let occurrenceLoopIndex = 1;
639
+ const { allOccurrences } = group;
640
+ const headHitTime = object.startTime + objectData.accuracy;
641
+ const judgesPassedNestedObjectsOnHeadHit = this.data.replayVersion >= 6;
642
+ let headHitBallPosition = null;
643
+ let headHitCursorPosition = null;
644
+ for (let i = 1; i < object.nestedHitObjects.length; ++i) {
645
+ if (isCheesed) break;
646
+ if (!objectData.tickset[i - 1]) continue;
647
+ const nestedObject = object.nestedHitObjects[i];
648
+ const nestedPosition = nestedObject.stackedPosition;
649
+ if (judgesPassedNestedObjectsOnHeadHit && nestedObject.startTime <= headHitTime) {
650
+ headHitBallPosition ??= object.stackedPosition.add(object.curvePositionAt(_rian8337_osu_base.MathUtils.clamp((headHitTime - object.startTime) / object.duration, 0, 1)));
651
+ headHitCursorPosition ??= this.getCursorPositionAt(group, headHitTime);
652
+ isCheesed = headHitCursorPosition.getDistance(headHitBallPosition) > acceptableRadius || nestedPosition.getDistance(headHitBallPosition) > acceptableRadius;
653
+ continue;
654
+ }
655
+ while (occurrenceLoopIndex < allOccurrences.length && allOccurrences[occurrenceLoopIndex].time < nestedObject.startTime) ++occurrenceLoopIndex;
656
+ if (occurrenceLoopIndex === allOccurrences.length) continue;
657
+ const cursor = allOccurrences[occurrenceLoopIndex];
658
+ const prevCursor = allOccurrences[occurrenceLoopIndex - 1];
659
+ const currentPosition = this.getCursorPosition(cursor);
660
+ const prevPosition = this.getCursorPosition(prevCursor);
661
+ switch (cursor.id) {
662
+ case _rian8337_osu_droid_replay.MovementType.Move: {
663
+ const t = (nestedObject.startTime - prevCursor.time) / (cursor.time - prevCursor.time);
664
+ isCheesed = _rian8337_osu_base.Interpolation.lerp(prevPosition, currentPosition, t).getDistance(nestedPosition) > acceptableRadius;
665
+ break;
666
+ }
667
+ case _rian8337_osu_droid_replay.MovementType.Up: isCheesed = prevPosition.getDistance(nestedPosition) > acceptableRadius;
668
+ }
669
+ }
670
+ if (isCheesed) cheesedDifficultyRatings.push(difficultSlider.difficultyRating);
671
+ }
672
+ return cheesedDifficultyRatings;
673
+ }
674
+ /**
675
+ * Calculates the slider cheese penalty.
676
+ */
677
+ calculateSliderCheesePenalty(cheesedDifficultyRatings) {
678
+ const summedDifficultyRating = Math.min(1, cheesedDifficultyRatings.reduce((a, v) => a + v, 0));
679
+ return Math.max(this.difficultyAttributes.sliderFactor, Math.pow(1 - summedDifficultyRating * this.difficultyAttributes.sliderFactor, 2));
680
+ }
681
+ /**
682
+ * Obtains the position of a cursor occurrence group at a given time.
683
+ *
684
+ * @param group The cursor occurrence group.
685
+ * @param time The time.
686
+ * @returns The position of the cursor at the given time, clamped to the group's active time.
687
+ */
688
+ getCursorPositionAt(group, time) {
689
+ const { allOccurrences } = group;
690
+ if (time <= allOccurrences[0].time) return this.getCursorPosition(allOccurrences[0]);
691
+ for (let i = 1; i < allOccurrences.length; ++i) {
692
+ const cursor = allOccurrences[i];
693
+ if (cursor.time < time) continue;
694
+ const prevCursor = allOccurrences[i - 1];
695
+ const prevPosition = this.getCursorPosition(prevCursor);
696
+ if (cursor.id === _rian8337_osu_droid_replay.MovementType.Up) return prevPosition;
697
+ return _rian8337_osu_base.Interpolation.lerp(prevPosition, this.getCursorPosition(cursor), _rian8337_osu_base.Interpolation.reverseLerp(time, prevCursor.time, cursor.time));
698
+ }
699
+ const lastCursor = allOccurrences.at(-1);
700
+ return this.getCursorPosition(lastCursor.id === _rian8337_osu_droid_replay.MovementType.Up && allOccurrences.length > 1 ? allOccurrences[allOccurrences.length - 2] : lastCursor);
701
+ }
702
+ getCursorPosition(cursor) {
703
+ if (this.isHardRock) return new _rian8337_osu_base.Vector2(cursor.position.x, _rian8337_osu_base.Playfield.baseSize.y - cursor.position.y);
704
+ return cursor.position;
705
+ }
706
+ };
707
+ // src/analysis/ThreeFingerChecker.ts
708
+ /**
709
+ * Utility to check whether or not a beatmap is three-fingered for live scores.
710
+ */
711
+ var ThreeFingerChecker = class ThreeFingerChecker {
712
+ /**
713
+ * The beatmap that is being analyzed.
714
+ */
715
+ beatmap;
716
+ /**
717
+ * The data of the replay.
718
+ */
719
+ data;
720
+ /**
721
+ * The difficulty attributes of the beatmap.
722
+ */
723
+ difficultyAttributes;
724
+ /**
725
+ * Extended sections of the beatmap for drag detection.
726
+ */
727
+ beatmapSections = [];
728
+ /**
729
+ * The hit window of this beatmap. Keep in mind that speed-changing mods do not change hit window length in game logic.
730
+ */
731
+ hitWindow;
732
+ /**
733
+ * A reprocessed break points to match right on object time.
734
+ *
735
+ * This is used to increase detection accuracy since break points do not start right at the
736
+ * start of the hitobject before it and do not end right at the first hitobject after it.
737
+ */
738
+ breakPointAccurateTimes = [];
739
+ /**
740
+ * A cursor occurrence nested array that only contains `movementType.DOWN` movement ID occurrences.
741
+ *
742
+ * Each index represents the cursor index.
743
+ */
744
+ downCursorInstances = [];
745
+ /**
746
+ * Nerf factors from all sections that were three-fingered.
747
+ */
748
+ nerfFactors = [];
749
+ isHardRock;
750
+ /**
751
+ * @param beatmap The beatmap to analyze.
752
+ * @param data The data of the replay.
753
+ * @param difficultyAttributes The difficulty attributes of the beatmap.
754
+ */
755
+ constructor(beatmap, data, difficultyAttributes) {
756
+ this.beatmap = beatmap;
757
+ this.data = data;
758
+ this.difficultyAttributes = difficultyAttributes;
759
+ this.isHardRock = difficultyAttributes.mods.has(_rian8337_osu_base.ModHardRock);
760
+ this.hitWindow = _rian8337_osu_base.HitWindowFactory.createDroid(beatmap.difficulty.od, difficultyAttributes.mods.has(_rian8337_osu_base.ModPrecise));
761
+ }
762
+ /**
763
+ * Checks whether a beatmap is eligible to be detected for 3-finger.
764
+ *
765
+ * @param difficultyAttributes The difficulty attributes of the beatmap.
766
+ */
767
+ static isEligibleToDetect(difficultyAttributes) {
768
+ return difficultyAttributes.possibleThreeFingeredSections.length > 0;
769
+ }
770
+ /**
771
+ * Checks if the given beatmap is 3-fingered and also returns the final penalty.
772
+ *
773
+ * The beatmap will be separated into sections and each section will be determined
774
+ * whether or not it is dragged.
775
+ *
776
+ * After that, each section will be assigned a nerf factor based on whether or not
777
+ * the section is 3-fingered. These nerf factors will be summed up into a final
778
+ * nerf factor, taking beatmap difficulty into account.
779
+ */
780
+ check() {
781
+ if (!ThreeFingerChecker.isEligibleToDetect(this.difficultyAttributes) || this.data.cursorMovement.filter((v) => v.occurrenceGroups.length > 0).length <= 3) return {
782
+ is3Finger: false,
783
+ penalty: 1
784
+ };
785
+ this.getAccurateBreakPoints();
786
+ this.filterCursorInstances();
787
+ this.getBeatmapSections();
788
+ this.calculateNerfFactors();
789
+ const finalPenalty = this.calculateFinalPenalty();
790
+ return {
791
+ is3Finger: finalPenalty > 1,
792
+ penalty: finalPenalty
793
+ };
794
+ }
795
+ /**
796
+ * Generates a new set of "accurate break points".
797
+ *
798
+ * This is done to increase detection accuracy since break points do not start right at the
799
+ * end of the hitobject before it and do not end right at the first hitobject after it.
800
+ */
801
+ getAccurateBreakPoints() {
802
+ const objects = this.beatmap.hitObjects.objects;
803
+ const objectData = this.data.hitObjectData;
804
+ for (const breakPoint of this.beatmap.events.breaks) {
805
+ const beforeIndex = _rian8337_osu_base.MathUtils.clamp(objects.findIndex((o) => o.endTime >= breakPoint.startTime) - 1, 0, objects.length - 2);
806
+ const objectBefore = objects[beforeIndex];
807
+ const objectBeforeData = objectData[beforeIndex];
808
+ let timeBefore = objectBefore.endTime;
809
+ if (objectBefore instanceof _rian8337_osu_base.Circle) {
810
+ if (objectBeforeData.result !== _rian8337_osu_base.HitResult.Miss) timeBefore += objectBeforeData.accuracy;
811
+ else timeBefore += this.hitWindow.mehWindow;
812
+ }
813
+ const afterIndex = beforeIndex + 1;
814
+ const objectAfter = objects[afterIndex];
815
+ const objectAfterData = objectData[afterIndex];
816
+ let timeAfter = objectAfter.startTime;
817
+ if (objectAfter instanceof _rian8337_osu_base.Circle && objectAfterData.result !== _rian8337_osu_base.HitResult.Miss) timeAfter += objectAfterData.accuracy;
818
+ this.breakPointAccurateTimes.push(new _rian8337_osu_base.BreakPoint(timeBefore, timeAfter));
819
+ }
820
+ }
821
+ /**
822
+ * Filters the original cursor instances, returning only those with `movementType.DOWN` movement ID.
823
+ *
824
+ * This also filters cursors that are in break period or happen before start/after end of the beatmap.
825
+ */
826
+ filterCursorInstances() {
827
+ const objects = this.beatmap.hitObjects.objects;
828
+ const objectData = this.data.hitObjectData;
829
+ const firstObjectResult = objectData[0].result;
830
+ const lastObjectResult = objectData.at(-1).result;
831
+ const firstObject = objects[0];
832
+ const lastObject = objects.at(-1);
833
+ let firstObjectHitWindow = this.hitWindow.mehWindow;
834
+ if (firstObject instanceof _rian8337_osu_base.Circle) switch (firstObjectResult) {
835
+ case _rian8337_osu_base.HitResult.Great:
836
+ firstObjectHitWindow = this.hitWindow.greatWindow;
837
+ break;
838
+ case _rian8337_osu_base.HitResult.Good:
839
+ firstObjectHitWindow = this.hitWindow.okWindow;
840
+ break;
841
+ default: firstObjectHitWindow = this.hitWindow.mehWindow;
842
+ }
843
+ let lastObjectHitWindow = this.hitWindow.mehWindow;
844
+ if (lastObject instanceof _rian8337_osu_base.Circle) switch (lastObjectResult) {
845
+ case _rian8337_osu_base.HitResult.Great:
846
+ lastObjectHitWindow = this.hitWindow.greatWindow;
847
+ break;
848
+ case _rian8337_osu_base.HitResult.Good:
849
+ lastObjectHitWindow = this.hitWindow.okWindow;
850
+ break;
851
+ default: lastObjectHitWindow = this.hitWindow.mehWindow;
852
+ }
853
+ else if (lastObject instanceof _rian8337_osu_base.Slider) lastObjectHitWindow = Math.min(lastObject.spanDuration, lastObjectHitWindow);
854
+ const firstObjectHitTime = firstObject.startTime - firstObjectHitWindow;
855
+ const lastObjectHitTime = lastObject.startTime + lastObjectHitWindow;
856
+ for (const cursorInstance of this.data.cursorMovement) {
857
+ const validOccurrences = [];
858
+ for (const group of cursorInstance.occurrenceGroups) {
859
+ if (group.startTime < firstObjectHitTime) continue;
860
+ if (group.startTime > lastObjectHitTime) break;
861
+ if (this.breakPointAccurateTimes.some((v) => group.startTime >= v.startTime && group.endTime <= v.endTime)) continue;
862
+ validOccurrences.push(group.down);
863
+ }
864
+ this.downCursorInstances.push(validOccurrences);
865
+ }
866
+ }
867
+ /**
868
+ * Divides the beatmap into sections, which will be used to
869
+ * detect dragged sections and improve detection speed.
870
+ */
871
+ getBeatmapSections() {
872
+ const beatmapObjects = this.beatmap.hitObjects.objects;
873
+ const aimCursorGroupLookupIndices = _rian8337_osu_base.Utils.initializeArray(this.downCursorInstances.length, 0);
874
+ const aimCursorLookupIndices = _rian8337_osu_base.Utils.initializeArray(this.downCursorInstances.length, 1);
875
+ const pressCursorLookupIndices = _rian8337_osu_base.Utils.initializeArray(this.downCursorInstances.length, 0);
876
+ for (const section of this.difficultyAttributes.possibleThreeFingeredSections) {
877
+ const objects = [];
878
+ for (let i = section.firstObjectIndex; i <= section.lastObjectIndex; ++i) {
879
+ const object = beatmapObjects[i];
880
+ const objectData = this.data.hitObjectData[i];
881
+ objects.push({
882
+ object,
883
+ aimingCursorInstanceIndex: this.getObjectAimIndex(object, objectData, aimCursorGroupLookupIndices, aimCursorLookupIndices),
884
+ pressingCursorInstanceIndex: this.getObjectPressIndex(object, objectData, pressCursorLookupIndices)
885
+ });
886
+ }
887
+ this.beatmapSections.push({
888
+ ...section,
889
+ objects
890
+ });
891
+ }
892
+ }
893
+ /**
894
+ * Obtains the index of the cursor that aimed the object at the nearest time.
895
+ *
896
+ * @param object The object to obtain the index for.
897
+ * @param objectData The hit data of the object.
898
+ * @param cursorInstanceIndices The cursor indices to start looking for the cursor instance from, to save computation time.
899
+ * @param cursorGroupIndices The cursor indices to start looking for the cursor group from, to save computation time.
900
+ * @param cursorIndices The cursor indices to start looking for the cursor from, to save computation time.
901
+ * @returns The index of the cursor, -1 if the object was missed or it's a spinner.
902
+ */
903
+ getObjectAimIndex(object, objectData, cursorGroupIndices, cursorIndices) {
904
+ if (objectData.result === _rian8337_osu_base.HitResult.Miss || object instanceof _rian8337_osu_base.Spinner) return -1;
905
+ if (object instanceof _rian8337_osu_base.Slider) {
906
+ let lateHitThreshold = this.hitWindow.mehWindow;
907
+ if (this.data.replayVersion < 8) lateHitThreshold = Math.min(lateHitThreshold, object.duration);
908
+ if (objectData.accuracy < -this.hitWindow.mehWindow || objectData.accuracy > lateHitThreshold) return -1;
909
+ }
910
+ const hitTime = object.startTime + objectData.accuracy;
911
+ const objectPosition = object.stackedPosition;
912
+ let closestDistance = Number.POSITIVE_INFINITY;
913
+ let nearestCursorIndex = -1;
914
+ for (let i = 0; i < this.data.cursorMovement.length; ++i) {
915
+ const cursorData = this.data.cursorMovement[i];
916
+ for (let j = cursorGroupIndices[i]; j < cursorData.occurrenceGroups.length; cursorGroupIndices[i] = ++j) {
917
+ const cursorGroup = cursorData.occurrenceGroups[j];
918
+ if (cursorGroup.endTime < hitTime) {
919
+ cursorIndices[i] = 1;
920
+ continue;
921
+ }
922
+ if (cursorGroup.startTime > hitTime) break;
923
+ const cursors = cursorGroup.allOccurrences;
924
+ for (let k = cursorIndices[i]; k < cursors.length; cursorIndices[i] = ++k) {
925
+ const cursor = cursors[k];
926
+ const prevCursor = cursors[k - 1];
927
+ if (prevCursor.time > hitTime) break;
928
+ if (hitTime > cursor.time) continue;
929
+ let distance;
930
+ const currentPosition = this.getCursorPosition(cursor);
931
+ const prevPosition = this.getCursorPosition(prevCursor);
932
+ switch (cursor.id) {
933
+ case _rian8337_osu_droid_replay.MovementType.Up:
934
+ distance = prevPosition.getDistance(objectPosition);
935
+ break;
936
+ case _rian8337_osu_droid_replay.MovementType.Move: {
937
+ const t = (hitTime - prevCursor.time) / (cursor.time - prevCursor.time);
938
+ const cursorPosition = _rian8337_osu_base.Interpolation.lerp(prevPosition, currentPosition, t);
939
+ distance = objectPosition.getDistance(cursorPosition);
940
+ break;
941
+ }
942
+ case _rian8337_osu_droid_replay.MovementType.Down: continue;
943
+ }
944
+ if (closestDistance > distance) {
945
+ closestDistance = distance;
946
+ nearestCursorIndex = i;
947
+ }
948
+ }
949
+ if (cursorIndices[i] === cursors.length) cursorIndices[i] = 1;
950
+ break;
951
+ }
952
+ cursorGroupIndices[i] = Math.max(0, cursorGroupIndices[i] - 1);
953
+ cursorIndices[i] = Math.max(1, cursorIndices[i] - 1);
954
+ }
955
+ return nearestCursorIndex;
956
+ }
957
+ /**
958
+ * Obtains the index of the nearest cursor of which an object was pressed in terms of time.
959
+ *
960
+ * @param object The object to obtain the index for.
961
+ * @param objectData The hit data of the object.
962
+ * @param cursorLookupIndices The cursor indices to start looking for the cursor from, to save computation time.
963
+ * @param excludedIndices The cursor indices that should not be checked.
964
+ * @returns The index of the cursor, -1 if the object was missed or it's a spinner.
965
+ */
966
+ getObjectPressIndex(object, objectData, cursorLookupIndices) {
967
+ if (objectData.result === _rian8337_osu_base.HitResult.Miss || object instanceof _rian8337_osu_base.Spinner) return -1;
968
+ if (object instanceof _rian8337_osu_base.Slider) {
969
+ let lateHitThreshold = this.hitWindow.mehWindow;
970
+ if (this.data.replayVersion < 8) lateHitThreshold = Math.min(lateHitThreshold, object.duration);
971
+ if (objectData.accuracy < -this.hitWindow.mehWindow || objectData.accuracy > lateHitThreshold) return -1;
972
+ }
973
+ const hitTime = object.startTime + objectData.accuracy;
974
+ let nearestCursorInstanceIndex = -1;
975
+ let nearestTime = Number.POSITIVE_INFINITY;
976
+ for (let i = 0; i < this.downCursorInstances.length; ++i) {
977
+ const cursors = this.downCursorInstances[i];
978
+ let cursorNearestTime = Number.POSITIVE_INFINITY;
979
+ for (let j = cursorLookupIndices[i]; j < cursors.length; cursorLookupIndices[i] = ++j) {
980
+ const cursor = cursors[j];
981
+ if (cursor.time > hitTime) break;
982
+ cursorNearestTime = hitTime - cursor.time;
983
+ }
984
+ if (cursorNearestTime < nearestTime) {
985
+ nearestCursorInstanceIndex = i;
986
+ nearestTime = cursorNearestTime;
987
+ }
988
+ }
989
+ return nearestCursorInstanceIndex;
990
+ }
991
+ /**
992
+ * Creates nerf factors by scanning through objects.
993
+ */
994
+ calculateNerfFactors() {
995
+ for (const beatmapSection of this.beatmapSections) {
996
+ const threeFingerCursorCounts = _rian8337_osu_base.Utils.initializeArray(Math.max(0, this.downCursorInstances.length - 2), 0);
997
+ for (const object of beatmapSection.objects) {
998
+ if (object.pressingCursorInstanceIndex === -1) continue;
999
+ if (object.aimingCursorInstanceIndex < 3) switch (object.pressingCursorInstanceIndex) {
1000
+ case 0:
1001
+ case 1:
1002
+ case 2: break;
1003
+ default: ++threeFingerCursorCounts[object.pressingCursorInstanceIndex - 3];
1004
+ }
1005
+ else switch (object.pressingCursorInstanceIndex) {
1006
+ case 0:
1007
+ case 1: break;
1008
+ default: ++threeFingerCursorCounts[object.pressingCursorInstanceIndex - 2];
1009
+ }
1010
+ }
1011
+ const threeFingerCursorCount = threeFingerCursorCounts.reduce((a, v) => a + v, 0);
1012
+ if (threeFingerCursorCount === 0) continue;
1013
+ const sectionObjectCount = beatmapSection.objects.length;
1014
+ const threeFingeredObjectRatio = threeFingerCursorCount / sectionObjectCount;
1015
+ const strainFactor = Math.max(1, beatmapSection.sumStrain * threeFingeredObjectRatio);
1016
+ const fingerFactor = threeFingerCursorCounts.reduce((acc, count, index) => acc + Math.pow((index + 1) * count / sectionObjectCount, .9), 1);
1017
+ const lengthFactor = 1 + Math.pow(threeFingeredObjectRatio, .8);
1018
+ this.nerfFactors.push({
1019
+ strainFactor,
1020
+ fingerFactor,
1021
+ lengthFactor
1022
+ });
1023
+ }
1024
+ }
1025
+ /**
1026
+ * Calculates the final penalty.
1027
+ */
1028
+ calculateFinalPenalty() {
1029
+ return this.nerfFactors.reduce((a, n) => a + .015 * Math.pow(n.strainFactor * n.fingerFactor * n.lengthFactor, 1.05), 1);
1030
+ }
1031
+ getCursorPosition(cursor) {
1032
+ if (this.isHardRock) return new _rian8337_osu_base.Vector2(cursor.position.x, _rian8337_osu_base.Playfield.baseSize.y - cursor.position.y);
1033
+ return cursor.position;
1034
+ }
1035
+ };
1036
+ // src/analysis/objects/IndexedHitObject.ts
1037
+ /**
1038
+ * Contains information about which cursor index hits a hitobject.
1039
+ */
1040
+ var IndexedHitObject = class {
1041
+ /**
1042
+ * The cursor index that hits the hitobject.
1043
+ *
1044
+ * If -1, the detection was unable to find any cursor that attempted to hit
1045
+ * the hitobject or it did not meet the criteria for detection.
1046
+ */
1047
+ cursorIndex;
1048
+ /**
1049
+ * The group index of the cursor within the cursor index that hits the hitobject.
1050
+ *
1051
+ * If -1, the detection was unable to find any cursor that attempted to hit
1052
+ * the hitobject or it did not meet the criteria for detection.
1053
+ */
1054
+ groupIndex;
1055
+ /**
1056
+ * The occurrence index within the group of the cursor within the cursor index that hits the hitobject.
1057
+ *
1058
+ * If -1, the detection was unable to find any cursor that attempted to hit
1059
+ * the hitobject or it did not meet the criteria for detection.
1060
+ */
1061
+ occurrenceIndex;
1062
+ /**
1063
+ * The angle of the movement of the cursor towards the next hitobject.
1064
+ */
1065
+ angle;
1066
+ /**
1067
+ * If this is a slider, whether the slider was cheesed.
1068
+ */
1069
+ sliderCheesed = false;
1070
+ /**
1071
+ * The underlying difficulty hitobject.
1072
+ */
1073
+ object;
1074
+ /**
1075
+ * The position of the cursor at the end of this hitobject.
1076
+ *
1077
+ * Will be altered during detection.
1078
+ */
1079
+ endCursorPosition;
1080
+ /**
1081
+ * Whether the hitobject is likely two-handed.
1082
+ */
1083
+ is2Handed;
1084
+ /**
1085
+ * @param object The underlying hitobject.
1086
+ * @param cursorIndex The cursor index that moves towards the hitobject.
1087
+ * @param groupIndex The group index of the cursor within the cursor index that hits the hitobject.
1088
+ * @param occurrenceIndex The occurrence index within the group of the cursor within the cursor index that hits the hitobject.
1089
+ * @param angle The angle of the movement of the cursor that moves towards the hitobject.
1090
+ */
1091
+ constructor(object, cursorIndex, groupIndex, occurrenceIndex, angle, is2Handed) {
1092
+ this.object = object;
1093
+ this.cursorIndex = cursorIndex;
1094
+ this.groupIndex = groupIndex;
1095
+ this.occurrenceIndex = occurrenceIndex;
1096
+ this.angle = angle;
1097
+ this.is2Handed = is2Handed;
1098
+ this.endCursorPosition = this.object.stackedEndPosition;
1099
+ }
1100
+ };
1101
+ // src/analysis/TwoHandChecker.ts
1102
+ /**
1103
+ * Utility to check whether or not a beatmap is two-handed.
1104
+ */
1105
+ var TwoHandChecker = class {
1106
+ /**
1107
+ * The beatmap to analyze.
1108
+ */
1109
+ beatmap;
1110
+ /**
1111
+ * The difficulty attributes that is being analyzed.
1112
+ */
1113
+ attributes;
1114
+ /**
1115
+ * The data of the replay.
1116
+ */
1117
+ data;
1118
+ /**
1119
+ * The hitobjects of the beatmap that have been assigned with their respective cursor index.
1120
+ */
1121
+ indexedHitObjects = [];
1122
+ /**
1123
+ * The osu!droid hitwindow of the analyzed beatmap.
1124
+ */
1125
+ hitWindow;
1126
+ isHardRock;
1127
+ /**
1128
+ * @param beatmap The beatmap to analyze.
1129
+ * @param attributes The difficulty attributes to analyze.
1130
+ * @param data The data of the replay.
1131
+ */
1132
+ constructor(beatmap, attributes, data) {
1133
+ this.beatmap = beatmap;
1134
+ this.attributes = attributes;
1135
+ this.data = data;
1136
+ const greatWindow = new _rian8337_osu_base.OsuHitWindow(attributes.overallDifficulty).greatWindow * attributes.clockRate;
1137
+ this.hitWindow = attributes.mods.has(_rian8337_osu_base.ModPrecise) ? new _rian8337_osu_base.PreciseDroidHitWindow(_rian8337_osu_base.PreciseDroidHitWindow.greatWindowToOD(greatWindow)) : new _rian8337_osu_base.DroidHitWindow(_rian8337_osu_base.DroidHitWindow.greatWindowToOD(greatWindow));
1138
+ this.isHardRock = attributes.mods.has(_rian8337_osu_base.ModHardRock);
1139
+ }
1140
+ /**
1141
+ * Checks if a beatmap is two-handed.
1142
+ */
1143
+ check() {
1144
+ if (this.data.cursorMovement.filter((v) => v.occurrenceGroups.length > 0).length <= 1) return {
1145
+ is2Hand: false,
1146
+ twoHandedNoteCount: 0
1147
+ };
1148
+ this.indexHitObjects();
1149
+ return {
1150
+ is2Hand: false,
1151
+ twoHandedNoteCount: 0
1152
+ };
1153
+ }
1154
+ /**
1155
+ * Converts hitobjects into indexed hit objects.
1156
+ */
1157
+ indexHitObjects() {
1158
+ const indexes = [];
1159
+ for (let i = 0; i < this.data.hitObjectData.length; ++i) {
1160
+ const indexedHitObject = this.getIndexedHitObject(i);
1161
+ indexedHitObject.sliderCheesed = this.checkSliderCheesing(indexedHitObject, this.data.hitObjectData[i]);
1162
+ indexes.push(indexedHitObject.cursorIndex);
1163
+ this.indexedHitObjects.push(indexedHitObject);
1164
+ }
1165
+ }
1166
+ /**
1167
+ * Gets the cursor index that hits the given object.
1168
+ *
1169
+ * @param objectIndex The index of the object to check.
1170
+ * @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.
1171
+ */
1172
+ getIndexedHitObject(objectIndex) {
1173
+ const object = this.beatmap.hitObjects.objects[objectIndex];
1174
+ if (objectIndex === 0 || object instanceof _rian8337_osu_base.Spinner) return new IndexedHitObject(object, -1, -1, -1, null, false);
1175
+ const prevObject = this.beatmap.hitObjects.objects[objectIndex - 1];
1176
+ const prevObjectData = this.data.hitObjectData[objectIndex - 1];
1177
+ if (prevObject instanceof _rian8337_osu_base.Spinner || prevObjectData.result === _rian8337_osu_base.HitResult.Miss) return new IndexedHitObject(object, -1, -1, -1, null, false);
1178
+ const objectStartPosition = object.stackedPosition;
1179
+ let prevObjectEndPosition = prevObject.stackedEndPosition;
1180
+ if (prevObject instanceof _rian8337_osu_base.Slider) {
1181
+ if (prevObject.distance > 0) {
1182
+ const endPosition = prevObject.stackedEndPosition;
1183
+ const lazyEndMovement = objectStartPosition.subtract(endPosition);
1184
+ const actualEndMovement = objectStartPosition.subtract(prevObjectEndPosition);
1185
+ if (lazyEndMovement.length < actualEndMovement.length) prevObjectEndPosition = endPosition;
1186
+ } else prevObjectEndPosition = prevObject.stackedPosition;
1187
+ }
1188
+ if (object.stackedPosition.subtract(prevObjectEndPosition).length <= object.radius) return new IndexedHitObject(object, -1, -1, -1, null, false);
1189
+ const objectInformation = this.getCursorPositionForObjectStart(objectIndex);
1190
+ const prevObjectInformation = this.getCursorPositionForObjectEnd(objectIndex - 1);
1191
+ this.indexedHitObjects[objectIndex - 1].endCursorPosition = prevObjectInformation.position;
1192
+ if (prevObjectInformation.position.x === Number.POSITIVE_INFINITY) return new IndexedHitObject(object, -1, -1, -1, null, false);
1193
+ if (prevObjectInformation.cursorIndex === objectInformation.cursorIndex && prevObjectInformation.groupIndex === objectInformation.groupIndex) return new IndexedHitObject(object, objectInformation.cursorIndex, objectInformation.groupIndex, prevObjectInformation.occurrenceIndex, 0, false);
1194
+ const cursorData = this.data.cursorMovement[prevObjectInformation.cursorIndex];
1195
+ let finalAngle = Number.POSITIVE_INFINITY;
1196
+ const cursors = cursorData.occurrenceGroups[prevObjectInformation.groupIndex].allOccurrences;
1197
+ const prevToCurrentCursorMovement = objectInformation.position.subtract(prevObjectInformation.position);
1198
+ for (let i = prevObjectInformation.occurrenceIndex + 1; i < cursors.length; ++i) {
1199
+ const cursor = cursors[i];
1200
+ const prevCursor = cursors[i - 1];
1201
+ const currentPosition = this.getCursorPosition(cursor);
1202
+ const prevPosition = this.getCursorPosition(prevCursor);
1203
+ if (currentPosition.equals(prevPosition)) continue;
1204
+ if (cursor.id === _rian8337_osu_droid_replay.MovementType.Up) break;
1205
+ const currentMovement = currentPosition.subtract(prevPosition);
1206
+ const dot = prevToCurrentCursorMovement.dot(currentMovement);
1207
+ const det = prevToCurrentCursorMovement.x * currentMovement.y - prevToCurrentCursorMovement.y * currentMovement.x;
1208
+ finalAngle = Math.min(finalAngle, Math.abs(Math.atan2(det, dot)));
1209
+ }
1210
+ const is2Handed = finalAngle >= Math.PI / 6;
1211
+ if (!Number.isFinite(finalAngle)) return new IndexedHitObject(object, -1, -1, -1, null, false);
1212
+ return new IndexedHitObject(object, prevObjectInformation.cursorIndex, prevObjectInformation.groupIndex, prevObjectInformation.occurrenceIndex, finalAngle, is2Handed);
1213
+ }
1214
+ /**
1215
+ * Gets the position of the cursor that presses an object.
1216
+ *
1217
+ * @param objectIndex THe index of the object.
1218
+ * @returns The position of the cursor that presses the object.
1219
+ */
1220
+ getCursorPositionForObjectStart(objectIndex) {
1221
+ const object = this.beatmap.hitObjects.objects[objectIndex];
1222
+ const data = this.data.hitObjectData[objectIndex];
1223
+ const objectPosition = object.stackedPosition;
1224
+ if (object instanceof _rian8337_osu_base.Spinner) return {
1225
+ position: objectPosition,
1226
+ cursorIndex: 0,
1227
+ groupIndex: Number.POSITIVE_INFINITY,
1228
+ occurrenceIndex: Number.POSITIVE_INFINITY,
1229
+ cursorTime: object.startTime
1230
+ };
1231
+ let hitWindow = this.hitWindow.mehWindow;
1232
+ if (object instanceof _rian8337_osu_base.Circle) switch (data.result) {
1233
+ case _rian8337_osu_base.HitResult.Great:
1234
+ hitWindow = this.hitWindow.greatWindow;
1235
+ break;
1236
+ case _rian8337_osu_base.HitResult.Good: hitWindow = this.hitWindow.okWindow;
1237
+ }
1238
+ let nearestPosition = new _rian8337_osu_base.Vector2(Number.POSITIVE_INFINITY);
1239
+ let nearestCursorIndex = 0;
1240
+ let nearestGroupIndex = 0;
1241
+ let nearestCursorGroupIndex = 0;
1242
+ let nearestCursorTime = 0;
1243
+ const minimumActiveTime = object.startTime - hitWindow;
1244
+ const maximumActiveTime = object.startTime + hitWindow;
1245
+ for (let i = 0; i < this.data.cursorMovement.length; ++i) {
1246
+ if (nearestPosition.getDistance(objectPosition) <= object.radius) break;
1247
+ const cursorData = this.data.cursorMovement[i];
1248
+ for (let j = 0; j < cursorData.occurrenceGroups.length; ++j) {
1249
+ if (nearestPosition.getDistance(objectPosition) <= object.radius) break;
1250
+ const cursorGroup = cursorData.occurrenceGroups[j];
1251
+ if (cursorGroup.endTime < minimumActiveTime) continue;
1252
+ if (cursorGroup.startTime > maximumActiveTime) break;
1253
+ const { down } = cursorGroup;
1254
+ const downPosition = this.getCursorPosition(down);
1255
+ if (downPosition.getDistance(objectPosition) <= object.radius && Math.abs(down.time - object.startTime) <= hitWindow) {
1256
+ if (objectIndex > 0) {
1257
+ const prevObject = this.beatmap.hitObjects.objects[objectIndex - 1];
1258
+ if (down.time > prevObject.endTime) return {
1259
+ position: downPosition,
1260
+ cursorIndex: i,
1261
+ groupIndex: j,
1262
+ occurrenceIndex: 0,
1263
+ cursorTime: down.time
1264
+ };
1265
+ } else return {
1266
+ position: downPosition,
1267
+ cursorIndex: i,
1268
+ groupIndex: j,
1269
+ occurrenceIndex: 0,
1270
+ cursorTime: down.time
1271
+ };
1272
+ }
1273
+ const cursors = cursorGroup.allOccurrences;
1274
+ for (let k = 1; k < cursors.length; ++k) {
1275
+ const cursor = cursors[k];
1276
+ const prevCursor = cursors[k - 1];
1277
+ if (cursor.time < minimumActiveTime) continue;
1278
+ if (prevCursor.time > maximumActiveTime) break;
1279
+ let cursorPosition;
1280
+ if (cursor.id === _rian8337_osu_droid_replay.MovementType.Up) {
1281
+ cursorPosition = this.getCursorPosition(prevCursor);
1282
+ if (cursorPosition.getDistance(objectPosition) < nearestPosition.getDistance(objectPosition)) {
1283
+ nearestPosition = cursorPosition;
1284
+ nearestCursorIndex = i;
1285
+ nearestGroupIndex = j;
1286
+ nearestCursorGroupIndex = k;
1287
+ nearestCursorTime = prevCursor.time;
1288
+ }
1289
+ } else for (let k = 0; k < this.data.cursorMovement.length; ++k) {
1290
+ if (k === i) continue;
1291
+ const cursorGroup = this.data.cursorMovement[k].occurrenceGroups.find((v) => v.down.time >= prevCursor.time && v.down.time <= cursor.time);
1292
+ if (!cursorGroup) continue;
1293
+ const t = (cursorGroup.down.time - prevCursor.time) / (cursor.time - prevCursor.time);
1294
+ cursorPosition = _rian8337_osu_base.Interpolation.lerp(this.getCursorPosition(prevCursor), this.getCursorPosition(cursor), t);
1295
+ const distance = cursorPosition.getDistance(objectPosition);
1296
+ if (distance < nearestPosition.getDistance(objectPosition)) {
1297
+ nearestPosition = cursorPosition;
1298
+ nearestCursorIndex = i;
1299
+ nearestGroupIndex = j;
1300
+ nearestCursorGroupIndex = k;
1301
+ nearestCursorTime = cursorGroup.down.time;
1302
+ }
1303
+ if (distance <= object.radius) break;
1304
+ }
1305
+ if (nearestPosition.getDistance(objectPosition) <= object.radius) break;
1306
+ }
1307
+ }
1308
+ }
1309
+ if (nearestPosition.getDistance(objectPosition) === Number.POSITIVE_INFINITY) return {
1310
+ position: nearestPosition,
1311
+ cursorIndex: Number.POSITIVE_INFINITY,
1312
+ groupIndex: Number.POSITIVE_INFINITY,
1313
+ occurrenceIndex: Number.POSITIVE_INFINITY,
1314
+ cursorTime: object.startTime
1315
+ };
1316
+ return {
1317
+ position: nearestPosition,
1318
+ cursorIndex: nearestCursorIndex,
1319
+ groupIndex: nearestGroupIndex,
1320
+ occurrenceIndex: nearestCursorGroupIndex,
1321
+ cursorTime: nearestCursorTime
1322
+ };
1323
+ }
1324
+ /**
1325
+ * Gets the position of the cursor that at an object's end position.
1326
+ *
1327
+ * @param objectIndex THe index of the object.
1328
+ * @returns The position of the cursor at the object's end position.
1329
+ */
1330
+ getCursorPositionForObjectEnd(objectIndex) {
1331
+ const object = this.beatmap.hitObjects.objects[objectIndex];
1332
+ if (!(object instanceof _rian8337_osu_base.Slider)) return this.getCursorPositionForObjectStart(objectIndex);
1333
+ const nextObject = this.beatmap.hitObjects.objects[objectIndex - 1];
1334
+ let objectEndPosition = object.stackedEndPosition;
1335
+ if (object.distance > 0 && nextObject) {
1336
+ const endPosition = object.stackedEndPosition;
1337
+ const nextStartPosition = nextObject.stackedPosition;
1338
+ const lazyEndMovement = nextStartPosition.subtract(endPosition);
1339
+ const actualEndMovement = nextStartPosition.subtract(objectEndPosition);
1340
+ if (lazyEndMovement.length < actualEndMovement.length) objectEndPosition = endPosition;
1341
+ } else objectEndPosition = object.stackedPosition;
1342
+ let nearestPosition = new _rian8337_osu_base.Vector2(Number.POSITIVE_INFINITY);
1343
+ let nearestCursorIndex = 0;
1344
+ let nearestGroupIndex = 0;
1345
+ let nearestCursorGroupIndex = 0;
1346
+ let nearestCursorTime = 0;
1347
+ for (let i = 0; i < this.data.cursorMovement.length; ++i) {
1348
+ const cursorData = this.data.cursorMovement[i];
1349
+ for (let j = 0; j < cursorData.occurrenceGroups.length; ++j) {
1350
+ const cursorGroup = cursorData.occurrenceGroups[j];
1351
+ if (cursorGroup.endTime < object.startTime) continue;
1352
+ if (cursorGroup.startTime > object.endTime) break;
1353
+ const cursors = cursorGroup.allOccurrences;
1354
+ for (let k = 0; k < cursors.length; ++k) {
1355
+ const cursor = cursors[k];
1356
+ let cursorPosition;
1357
+ switch (cursor.id) {
1358
+ case _rian8337_osu_droid_replay.MovementType.Down:
1359
+ cursorPosition = this.getCursorPosition(cursor);
1360
+ break;
1361
+ case _rian8337_osu_droid_replay.MovementType.Up: {
1362
+ const prevCursor = cursors[k - 1];
1363
+ cursorPosition = this.getCursorPosition(prevCursor);
1364
+ break;
1365
+ }
1366
+ case _rian8337_osu_droid_replay.MovementType.Move: {
1367
+ const prevCursor = cursors[k - 1];
1368
+ const t = _rian8337_osu_base.MathUtils.clamp((object.endTime - prevCursor.time) / (cursor.time - prevCursor.time), 0, 1);
1369
+ cursorPosition = _rian8337_osu_base.Interpolation.lerp(this.getCursorPosition(prevCursor), this.getCursorPosition(cursor), t);
1370
+ break;
1371
+ }
1372
+ }
1373
+ if (cursorPosition.getDistance(objectEndPosition) < nearestPosition.getDistance(objectEndPosition)) {
1374
+ nearestPosition = cursorPosition;
1375
+ nearestCursorIndex = i;
1376
+ nearestGroupIndex = j;
1377
+ switch (cursor.id) {
1378
+ case _rian8337_osu_droid_replay.MovementType.Down:
1379
+ nearestCursorGroupIndex = k;
1380
+ nearestCursorTime = cursor.time;
1381
+ break;
1382
+ case _rian8337_osu_droid_replay.MovementType.Up:
1383
+ nearestCursorGroupIndex = k - 1;
1384
+ nearestCursorTime = cursors[k - 1].time;
1385
+ break;
1386
+ case _rian8337_osu_droid_replay.MovementType.Move:
1387
+ nearestCursorGroupIndex = k;
1388
+ nearestCursorTime = object.endTime;
1389
+ }
1390
+ }
1391
+ }
1392
+ }
1393
+ }
1394
+ if (nearestPosition.getDistance(objectEndPosition) === Number.POSITIVE_INFINITY) return {
1395
+ position: nearestPosition,
1396
+ cursorIndex: Number.POSITIVE_INFINITY,
1397
+ groupIndex: Number.POSITIVE_INFINITY,
1398
+ occurrenceIndex: Number.POSITIVE_INFINITY,
1399
+ cursorTime: object.endTime
1400
+ };
1401
+ return {
1402
+ position: nearestPosition,
1403
+ cursorIndex: nearestCursorIndex,
1404
+ groupIndex: nearestGroupIndex,
1405
+ occurrenceIndex: nearestCursorGroupIndex,
1406
+ cursorTime: nearestCursorTime
1407
+ };
1408
+ }
1409
+ /**
1410
+ * Checks whether a slider was cheesed.
1411
+ *
1412
+ * This is done by checking if a cursor follows a slider all the way to its end position.
1413
+ *
1414
+ * @param indexedHitObject The indexed slider.
1415
+ * @param hitData The hit data of the slider.
1416
+ * @returns Whether the slider was cheesed.
1417
+ */
1418
+ checkSliderCheesing(indexedHitObject, hitData) {
1419
+ if (!(indexedHitObject.object instanceof _rian8337_osu_base.Slider) || hitData.result === _rian8337_osu_base.HitResult.Miss || indexedHitObject.cursorIndex === -1) return false;
1420
+ return false;
1421
+ }
1422
+ getCursorPosition(cursor) {
1423
+ if (this.isHardRock) return new _rian8337_osu_base.Vector2(cursor.position.x, _rian8337_osu_base.Playfield.baseSize.y - cursor.position.y);
1424
+ return cursor.position;
1425
+ }
1426
+ };
1427
+ // src/ReplayAnalyzer.ts
1428
+ /**
1429
+ * A replay analyzer that analyzes a replay from osu!droid.
1430
+ *
1431
+ * 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}.
1432
+ *
1433
+ * Once analyzed, the result can be accessed via the `data` property.
1434
+ */
1435
+ var ReplayAnalyzer = class {
1436
+ /**
1437
+ * The score ID of the replay.
1438
+ */
1439
+ scoreID;
1440
+ /**
1441
+ * The original odr file of the replay.
1442
+ */
1443
+ originalODR = null;
1444
+ /**
1445
+ * The replay's Java object stream, the decompressed content of its odr file.
1446
+ *
1447
+ * When set, `analyze()` decodes it instead of {@link originalODR}. `analyze()` does not set it.
1448
+ */
1449
+ fixedODR = null;
1450
+ /**
1451
+ * Whether or not the play is considered using >=3 finger abuse.
1452
+ */
1453
+ is3Finger;
1454
+ /**
1455
+ * Whether or not the play is considered 2-handed.
1456
+ */
1457
+ is2Hand;
1458
+ /**
1459
+ * The beatmap that is being analyzed. `DroidDifficultyCalculator` or `RebalanceDroidDifficultyCalculator` is required for three finger or two hand analyzing.
1460
+ *
1461
+ * Replays before version 3 do not record their mods. For those, the mods of a `DroidPlayableBeatmap`, or else
1462
+ * of `difficultyAttributes`, are used. Replay version 1 cursor positions need them to undo the Hard Rock flip,
1463
+ * so set this before calling `analyze()`.
1464
+ */
1465
+ get beatmap() {
1466
+ return this._beatmap;
1467
+ }
1468
+ set beatmap(value) {
1469
+ this._beatmap = value;
1470
+ this.playableBeatmap = value instanceof _rian8337_osu_base.DroidPlayableBeatmap ? value : void 0;
1471
+ }
1472
+ _beatmap;
1473
+ /**
1474
+ * The difficulty attributes of the beatmap.
1475
+ */
1476
+ difficultyAttributes;
1477
+ /**
1478
+ * The results of the analyzer. `null` when initialized.
1479
+ */
1480
+ data = null;
1481
+ /**
1482
+ * Penalty value used to penalize dpp for 2-hand.
1483
+ */
1484
+ aimPenalty = 1;
1485
+ /**
1486
+ * Penalty value used to penalize dpp for 3 finger abuse.
1487
+ */
1488
+ tapPenalty = 1;
1489
+ /**
1490
+ * Penalty values used to penalize dpp for slider cheesing.
1491
+ */
1492
+ sliderCheesePenalty = 1;
1493
+ /**
1494
+ * Whether this replay has been checked against 3 finger usage.
1495
+ */
1496
+ hasBeenCheckedFor3Finger = false;
1497
+ /**
1498
+ * Whether this replay has been checked against 2 hand usage.
1499
+ */
1500
+ hasBeenCheckedFor2Hand = false;
1501
+ /**
1502
+ * Whether this replay has been checked against slider cheesing.
1503
+ */
1504
+ hasBeenCheckedForSliderCheesing = false;
1505
+ /**
1506
+ * The amount of two-handed objects.
1507
+ */
1508
+ twoHandedNoteCount = 0;
1509
+ playableBeatmap;
1510
+ constructor(values) {
1511
+ this.scoreID = values?.scoreID;
1512
+ this.beatmap = values?.map;
1513
+ this.difficultyAttributes = values?.difficultyAttributes;
1514
+ }
1515
+ /**
1516
+ * Analyzes a replay.
1517
+ */
1518
+ async analyze() {
1519
+ if (!this.originalODR && !this.fixedODR) this.originalODR = await this.downloadReplay();
1520
+ const file = this.fixedODR ?? this.originalODR;
1521
+ if (!file) return this;
1522
+ try {
1523
+ this.data = new _rian8337_osu_droid_replay.ReplayDecoder().decode(file, {
1524
+ beatmap: this.beatmap,
1525
+ mods: this.getUnrecordedMods()
1526
+ });
1527
+ } catch {}
1528
+ return this;
1529
+ }
1530
+ /**
1531
+ * Gets hit error information of the replay.
1532
+ *
1533
+ * `analyze()` must be called before calling this, and `beatmap` must be defined.
1534
+ */
1535
+ calculateHitError() {
1536
+ if (!this.data || !this.beatmap) return null;
1537
+ const hitObjectData = this.data.hitObjectData;
1538
+ let positiveCount = 0;
1539
+ let negativeCount = 0;
1540
+ let positiveTotal = 0;
1541
+ let negativeTotal = 0;
1542
+ const { objects } = this.getPlayableBeatmap().hitObjects;
1543
+ const { mehWindow } = this.getBeatmapHitWindow();
1544
+ const accuracies = [];
1545
+ for (let i = 0; i < hitObjectData.length; ++i) {
1546
+ const v = hitObjectData[i];
1547
+ const o = objects[i];
1548
+ if (o instanceof _rian8337_osu_base.Spinner || v.result === _rian8337_osu_base.HitResult.Miss) continue;
1549
+ const { accuracy } = v;
1550
+ if (o instanceof _rian8337_osu_base.Slider && !this.isSliderHeadHit(o, accuracy, mehWindow, this.data.replayVersion)) continue;
1551
+ accuracies.push(accuracy);
1552
+ if (accuracy >= 0) {
1553
+ positiveTotal += accuracy;
1554
+ ++positiveCount;
1555
+ } else {
1556
+ negativeTotal += accuracy;
1557
+ ++negativeCount;
1558
+ }
1559
+ }
1560
+ return {
1561
+ positiveAvg: positiveTotal / positiveCount || 0,
1562
+ negativeAvg: negativeTotal / negativeCount || 0,
1563
+ unstableRate: _rian8337_osu_base.MathUtils.calculateStandardDeviation(accuracies) * 10
1564
+ };
1565
+ }
1566
+ /**
1567
+ * Obtains the amount of slider nested objects hit in the replay.
1568
+ *
1569
+ * This requires `analyze()` to be called first and `beatmap` to be defined.
1570
+ *
1571
+ * @returns Slider hit information or `null` if the replay has not been analyzed or the beatmap is not defined.
1572
+ */
1573
+ obtainSliderHitInformation() {
1574
+ const { data } = this;
1575
+ if (!data || !this.beatmap) return null;
1576
+ const beatmap = this.getPlayableBeatmap();
1577
+ const sliderInformation = {
1578
+ head: {
1579
+ obtained: 0,
1580
+ total: beatmap.hitObjects.sliders
1581
+ },
1582
+ tick: {
1583
+ obtained: 0,
1584
+ total: 0
1585
+ },
1586
+ repeat: {
1587
+ obtained: 0,
1588
+ total: 0
1589
+ },
1590
+ end: {
1591
+ obtained: 0,
1592
+ total: 0
1593
+ }
1594
+ };
1595
+ const hitWindow = this.getBeatmapHitWindow();
1596
+ for (let i = 0; i < data.hitObjectData.length; ++i) {
1597
+ const object = beatmap.hitObjects.objects[i];
1598
+ const objectData = data.hitObjectData[i];
1599
+ if (!(object instanceof _rian8337_osu_base.Slider)) continue;
1600
+ if (this.isSliderHeadHit(object, objectData.accuracy, hitWindow.mehWindow, data.replayVersion)) ++sliderInformation.head.obtained;
1601
+ for (let j = 1; j < object.nestedHitObjects.length; ++j) {
1602
+ const nested = object.nestedHitObjects[j];
1603
+ let tickInformation;
1604
+ switch (true) {
1605
+ case nested instanceof _rian8337_osu_base.SliderTick:
1606
+ tickInformation = sliderInformation.tick;
1607
+ break;
1608
+ case nested instanceof _rian8337_osu_base.SliderRepeat:
1609
+ tickInformation = sliderInformation.repeat;
1610
+ break;
1611
+ case nested instanceof _rian8337_osu_base.SliderTail:
1612
+ tickInformation = sliderInformation.end;
1613
+ break;
1614
+ default: continue;
1615
+ }
1616
+ ++tickInformation.total;
1617
+ if (objectData.tickset[j - 1]) ++tickInformation.obtained;
1618
+ }
1619
+ }
1620
+ return sliderInformation;
1621
+ }
1622
+ /**
1623
+ * Simulates a hit window for the replay.
1624
+ *
1625
+ * This does not account for required spins in a spinner.
1626
+ *
1627
+ * Requires `analyze()` to be called first and `beatmap` to be defined.
1628
+ *
1629
+ * @param hitWindow The hit window to simulate.
1630
+ * @returns The accuracy of the replay based on the hit window, or `null` if the replay has not been analyzed or the beatmap is not defined.
1631
+ */
1632
+ simulateHitWindow(hitWindow) {
1633
+ const { data, beatmap } = this;
1634
+ if (!data || !beatmap) return null;
1635
+ const accuracy = new _rian8337_osu_base.Accuracy({
1636
+ n300: 0,
1637
+ n100: 0,
1638
+ n50: 0,
1639
+ nmiss: 0
1640
+ });
1641
+ for (let i = 0; i < data.hitObjectData.length; ++i) {
1642
+ const object = beatmap.hitObjects.objects[i];
1643
+ const objectData = data.hitObjectData[i];
1644
+ const hitAccuracy = Math.abs(objectData.accuracy);
1645
+ let { result } = objectData;
1646
+ if (object instanceof _rian8337_osu_base.Circle) {
1647
+ if (hitAccuracy <= hitWindow.greatWindow) result = _rian8337_osu_base.HitResult.Great;
1648
+ else if (hitAccuracy <= hitWindow.okWindow) result = _rian8337_osu_base.HitResult.Good;
1649
+ else if (hitAccuracy <= hitWindow.mehWindow) result = _rian8337_osu_base.HitResult.Meh;
1650
+ else result = _rian8337_osu_base.HitResult.Miss;
1651
+ } else if (object instanceof _rian8337_osu_base.Slider) {
1652
+ if (hitAccuracy <= Math.min(hitWindow.mehWindow, object.duration)) {
1653
+ let ticksObtained = 1;
1654
+ for (let j = 1; j < object.nestedHitObjects.length; ++j) if (objectData.tickset[j - 1]) ++ticksObtained;
1655
+ if (ticksObtained === object.nestedHitObjects.length) result = _rian8337_osu_base.HitResult.Great;
1656
+ else if (ticksObtained >= Math.trunc(object.nestedHitObjects.length / 2)) result = _rian8337_osu_base.HitResult.Good;
1657
+ else if (ticksObtained > 0) result = _rian8337_osu_base.HitResult.Meh;
1658
+ else result = _rian8337_osu_base.HitResult.Miss;
1659
+ } else result = _rian8337_osu_base.HitResult.Miss;
1660
+ }
1661
+ switch (result) {
1662
+ case _rian8337_osu_base.HitResult.Miss:
1663
+ ++accuracy.nmiss;
1664
+ break;
1665
+ case _rian8337_osu_base.HitResult.Meh:
1666
+ ++accuracy.n50;
1667
+ break;
1668
+ case _rian8337_osu_base.HitResult.Good:
1669
+ ++accuracy.n100;
1670
+ break;
1671
+ case _rian8337_osu_base.HitResult.Great: ++accuracy.n300;
1672
+ }
1673
+ }
1674
+ return accuracy;
1675
+ }
1676
+ /**
1677
+ * Checks if a play is using 3 fingers.
1678
+ *
1679
+ * Requires `analyze()` to be called first and `map` and `difficultyAttributes` to be defined.
1680
+ */
1681
+ checkFor3Finger() {
1682
+ if (!this.beatmap || !this.data || !this.difficultyAttributes) return;
1683
+ this.playableBeatmap ??= this.constructPlayableBeatmap();
1684
+ const result = (this.difficultyAttributes.mode === "rebalance" ? new RebalanceThreeFingerChecker(this.playableBeatmap, this.data, this.difficultyAttributes) : new ThreeFingerChecker(this.playableBeatmap, this.data, this.difficultyAttributes)).check();
1685
+ this.is3Finger = result.is3Finger;
1686
+ this.tapPenalty = result.penalty;
1687
+ this.hasBeenCheckedFor3Finger = true;
1688
+ }
1689
+ /**
1690
+ * Checks if a play is using 2 hands.
1691
+ *
1692
+ * Requires `analyze()` to be called first as well as `beatmap` and `difficultyAttributes` to be defined.
1693
+ */
1694
+ checkFor2Hand() {
1695
+ if (!this.beatmap || !this.difficultyAttributes || !this.data) return;
1696
+ this.playableBeatmap ??= this.constructPlayableBeatmap();
1697
+ const result = new TwoHandChecker(this.playableBeatmap, this.difficultyAttributes, this.data).check();
1698
+ this.is2Hand = result.is2Hand;
1699
+ this.twoHandedNoteCount = result.twoHandedNoteCount;
1700
+ this.hasBeenCheckedFor2Hand = true;
1701
+ }
1702
+ /**
1703
+ * Checks if a play has cheesed sliders.
1704
+ *
1705
+ * Requires `analyze()` to be called first and `map` and `difficultyAttributes` to be defined.
1706
+ */
1707
+ checkForSliderCheesing() {
1708
+ if (!this.beatmap || !this.data || !this.difficultyAttributes) return;
1709
+ this.playableBeatmap ??= this.constructPlayableBeatmap();
1710
+ const sliderCheeseChecker = this.difficultyAttributes.mode === "rebalance" ? new RebalanceSliderCheeseChecker(this.playableBeatmap, this.data, this.difficultyAttributes) : new SliderCheeseChecker(this.playableBeatmap, this.data, this.difficultyAttributes);
1711
+ this.sliderCheesePenalty = sliderCheeseChecker.check();
1712
+ this.hasBeenCheckedForSliderCheesing = true;
1713
+ }
1714
+ /**
1715
+ * Downloads the given score ID's replay.
1716
+ */
1717
+ async downloadReplay() {
1718
+ if (this.scoreID === void 0) return null;
1719
+ const apiRequestBuilder = new _rian8337_osu_base.DroidAPIRequestBuilder().setRequireAPIkey(false).setEndpoint("upload").addParameter("", `${this.scoreID.toString()}.odr`);
1720
+ let result;
1721
+ try {
1722
+ result = await apiRequestBuilder.sendRequest();
1723
+ } catch (e) {
1724
+ console.error(`Error retrieving replay for score ID ${this.scoreID.toString()}: ${e.message}`);
1725
+ return null;
1726
+ }
1727
+ if (result.statusCode !== 200) {
1728
+ console.error(`Error retrieving replay for score ID ${this.scoreID.toString()}: ${result.describeFailure()}`);
1729
+ return null;
1730
+ }
1731
+ return result.data;
1732
+ }
1733
+ constructPlayableBeatmap() {
1734
+ if (this.beatmap instanceof _rian8337_osu_base.DroidPlayableBeatmap) return this.beatmap;
1735
+ if (!this.beatmap || !this.data) throw new Error("Beatmap and replay data must be defined.");
1736
+ const mods = this.data.isReplayV3() ? this.data.convertedMods : this.difficultyAttributes?.mods;
1737
+ return this.beatmap.createDroidPlayableBeatmap(mods);
1738
+ }
1739
+ /**
1740
+ * Gets the mods of a replay that does not record them (replay version 1 and 2), if they are known.
1741
+ */
1742
+ getUnrecordedMods() {
1743
+ return this.beatmap instanceof _rian8337_osu_base.DroidPlayableBeatmap ? this.beatmap.mods : this.difficultyAttributes?.mods;
1744
+ }
1745
+ getPlayableBeatmap() {
1746
+ this.playableBeatmap ??= this.constructPlayableBeatmap();
1747
+ return this.playableBeatmap;
1748
+ }
1749
+ getBeatmapHitWindow() {
1750
+ if (!this.data || !this.beatmap) return null;
1751
+ const { difficulty, mods } = this.getPlayableBeatmap();
1752
+ return _rian8337_osu_base.HitWindowFactory.createDroid(difficulty.od, mods.has(_rian8337_osu_base.ModPrecise));
1753
+ }
1754
+ /**
1755
+ * Determines whether the game counts a slider's head as hit at a hit offset.
1756
+ *
1757
+ * @param slider The slider.
1758
+ * @param accuracy The hit offset of the slider's head, in milliseconds.
1759
+ * @param mehWindow The meh hit window, in milliseconds.
1760
+ * @param replayVersion The version of the replay the hit offset comes from.
1761
+ */
1762
+ isSliderHeadHit(slider, accuracy, mehWindow, replayVersion) {
1763
+ const lateHitThreshold = replayVersion < 8 ? Math.min(mehWindow, slider.duration) : mehWindow;
1764
+ if (replayVersion < 6 && mehWindow > slider.duration) return accuracy <= lateHitThreshold;
1765
+ return -mehWindow <= accuracy && accuracy <= lateHitThreshold;
1766
+ }
1767
+ };
1768
+ Object.defineProperty(exports, "CursorData", {
1769
+ enumerable: true,
1770
+ get: function() {
1771
+ return _rian8337_osu_droid_replay.CursorData;
1772
+ }
1773
+ });
1774
+ Object.defineProperty(exports, "CursorOccurrence", {
1775
+ enumerable: true,
1776
+ get: function() {
1777
+ return _rian8337_osu_droid_replay.CursorOccurrence;
1778
+ }
1779
+ });
1780
+ Object.defineProperty(exports, "CursorOccurrenceGroup", {
1781
+ enumerable: true,
1782
+ get: function() {
1783
+ return _rian8337_osu_droid_replay.CursorOccurrenceGroup;
1784
+ }
1785
+ });
1786
+ Object.defineProperty(exports, "MovementType", {
1787
+ enumerable: true,
1788
+ get: function() {
1789
+ return _rian8337_osu_droid_replay.MovementType;
1790
+ }
1791
+ });
1792
+ exports.RebalanceSliderCheeseChecker = RebalanceSliderCheeseChecker;
1793
+ exports.RebalanceThreeFingerChecker = RebalanceThreeFingerChecker;
1794
+ exports.ReplayAnalyzer = ReplayAnalyzer;
1795
+ Object.defineProperty(exports, "ReplayData", {
1796
+ enumerable: true,
1797
+ get: function() {
1798
+ return _rian8337_osu_droid_replay.ReplayData;
1799
+ }
1800
+ });
1801
+ Object.defineProperty(exports, "ReplayV3Data", {
1802
+ enumerable: true,
1803
+ get: function() {
1804
+ return _rian8337_osu_droid_replay.ReplayV3Data;
1805
+ }
1806
+ });
1807
+ exports.SliderCheeseChecker = SliderCheeseChecker;
1808
+ exports.ThreeFingerChecker = ThreeFingerChecker;
1809
+ exports.TwoHandChecker = TwoHandChecker;
1810
+
1811
+ //# sourceMappingURL=index.cjs.map