@rian8337/osu-droid-replay-analyzer 2.0.0-alpha.1 → 2.0.0-alpha.12

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
@@ -29,25 +29,45 @@ function _interopNamespace(e) {
29
29
 
30
30
  var javaDeserialization__namespace = /*#__PURE__*/_interopNamespace(javaDeserialization);
31
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
+
32
55
  /**
33
56
  * Represents a cursor instance in an osu!droid replay.
34
57
  *
35
- * Stores cursor movement data such as x and y coordinates, movement size, etc.
58
+ * Stores cursor movement data in the form of `CursorOccurrence`s.
36
59
  *
37
60
  * This is used when analyzing replays using replay analyzer.
38
61
  */
39
62
  class CursorData {
40
- size;
41
- time;
42
- x;
43
- y;
44
- id;
63
+ /**
64
+ * The occurrences of this cursor instance.
65
+ */
66
+ occurrences = [];
45
67
  constructor(values) {
46
- this.size = values.size;
47
- this.time = values.time;
48
- this.x = values.x;
49
- this.y = values.y;
50
- this.id = values.id;
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
+ }
51
71
  }
52
72
  }
53
73
 
@@ -352,14 +372,16 @@ class ThreeFingerChecker {
352
372
  }
353
373
  this.getAccurateBreakPoints();
354
374
  this.filterCursorInstances();
355
- if (this.downCursorInstances.filter((v) => v.size > 0).length <= 3) {
375
+ if (this.downCursorInstances.filter((v) => v.occurrences.length > 0)
376
+ .length <= 3) {
356
377
  return { is3Finger: false, penalty: 1 };
357
378
  }
358
379
  this.getBeatmapSections();
359
380
  this.detectDragPlay();
360
381
  this.getDetailedBeatmapSections();
361
382
  this.preventAccidentalTaps();
362
- if (this.downCursorInstances.filter((v) => v.size > 0).length <= 3) {
383
+ if (this.downCursorInstances.filter((v) => v.occurrences.length > 0)
384
+ .length <= 3) {
363
385
  return { is3Finger: false, penalty: 1 };
364
386
  }
365
387
  this.calculateNerfFactors();
@@ -478,22 +500,18 @@ class ThreeFingerChecker {
478
500
  y: [],
479
501
  id: [],
480
502
  });
481
- for (let j = 0; j < cursorInstance.size; ++j) {
482
- if (cursorInstance.id[j] !== exports.movementType.DOWN) {
503
+ for (let j = 0; j < cursorInstance.occurrences.length; ++j) {
504
+ if (cursorInstance.occurrences[j].id !== exports.movementType.DOWN) {
483
505
  continue;
484
506
  }
485
- const time = cursorInstance.time[j];
507
+ const time = cursorInstance.occurrences[j].time;
486
508
  if (time < firstObjectHitTime || time > lastObjectHitTime) {
487
509
  continue;
488
510
  }
489
511
  if (this.breakPointAccurateTimes.some((v) => time >= v.startTime && time <= v.endTime)) {
490
512
  continue;
491
513
  }
492
- ++newCursorData.size;
493
- newCursorData.time.push(time);
494
- newCursorData.x.push(cursorInstance.x[j]);
495
- newCursorData.y.push(cursorInstance.y[j]);
496
- newCursorData.id.push(cursorInstance.id[j]);
514
+ newCursorData.occurrences.push(new CursorOccurrence(time, cursorInstance.occurrences[j].position.x, cursorInstance.occurrences[j].position.y, cursorInstance.occurrences[j].id));
497
515
  }
498
516
  this.downCursorInstances.push(newCursorData);
499
517
  }
@@ -579,16 +597,18 @@ class ThreeFingerChecker {
579
597
  const cursorIndexes = [];
580
598
  for (let i = 0; i < this.data.cursorMovement.length; ++i) {
581
599
  const c = this.data.cursorMovement[i];
582
- if (c.size === 0) {
600
+ if (c.occurrences.length === 0) {
583
601
  continue;
584
602
  }
585
603
  // Do not include cursors that don't have an occurence in this section
586
604
  // this speeds up checking process.
587
- if (c.time.filter((v) => v >= firstObjectMinHitTime && v <= lastObjectMaxHitTime).length === 0) {
605
+ if (c.occurrences.filter((v) => v.time >= firstObjectMinHitTime &&
606
+ v.time <= lastObjectMaxHitTime).length === 0) {
588
607
  continue;
589
608
  }
590
609
  // If this cursor instance doesn't move, it's not the cursor instance we want.
591
- if (c.id.filter((v) => v === exports.movementType.MOVE).length === 0) {
610
+ if (c.occurrences.filter((v) => v.id === exports.movementType.MOVE)
611
+ .length === 0) {
592
612
  continue;
593
613
  }
594
614
  cursorIndexes.push(i);
@@ -625,27 +645,28 @@ class ThreeFingerChecker {
625
645
  // therefore the game emulates the movement between
626
646
  // movementType.MOVE cursors.
627
647
  const hitTime = o.object.startTime + s.accuracy;
628
- const nextHitIndex = c.time.findIndex((v) => v >= hitTime);
648
+ const nextHitIndex = c.occurrences.findIndex((v) => v.time >= hitTime);
629
649
  const hitIndex = nextHitIndex - 1;
630
650
  if (hitIndex <= -1) {
631
651
  cursorIndexes[j] = -1;
632
652
  continue;
633
653
  }
634
- if (c.id[hitIndex] === exports.movementType.UP) {
654
+ if (c.occurrences[hitIndex].id === exports.movementType.UP) {
635
655
  cursorIndexes[j] = -1;
636
656
  continue;
637
657
  }
638
- const cursorPosition = new osuBase.Vector2(c.x[hitIndex], c.y[hitIndex]);
658
+ const cursorPosition = new osuBase.Vector2(c.occurrences[hitIndex].position.x, c.occurrences[hitIndex].position.y);
639
659
  let isInObject = false;
640
- if (c.id[nextHitIndex] === exports.movementType.MOVE ||
641
- c.id[hitIndex] === exports.movementType.MOVE) {
660
+ if (c.occurrences[nextHitIndex].id === exports.movementType.MOVE ||
661
+ c.occurrences[hitIndex].id === exports.movementType.MOVE) {
642
662
  // Try to interpolate movement between two movementType.MOVE cursor every 1ms.
643
663
  // This minimizes rounding error.
644
- for (let mSecPassed = c.time[hitIndex]; mSecPassed <= c.time[nextHitIndex]; ++mSecPassed) {
645
- const t = (mSecPassed - c.time[nextHitIndex]) /
646
- (c.time[hitIndex] - c.time[nextHitIndex]);
647
- cursorPosition.x = osuBase.Interpolation.lerp(c.x[hitIndex], c.x[nextHitIndex], t);
648
- cursorPosition.y = osuBase.Interpolation.lerp(c.y[hitIndex], c.y[nextHitIndex], t);
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);
649
670
  if (o.object.stackedPosition.getDistance(cursorPosition) <= o.object.radius) {
650
671
  isInObject = true;
651
672
  break;
@@ -718,32 +739,24 @@ class ThreeFingerChecker {
718
739
  * unnecessary taps.
719
740
  */
720
741
  preventAccidentalTaps() {
721
- let filledCursorAmount = this.downCursorInstances.filter((v) => v.size > 0).length;
742
+ let filledCursorAmount = this.downCursorInstances.filter((v) => v.occurrences.length > 0).length;
722
743
  if (filledCursorAmount <= 3) {
723
744
  return;
724
745
  }
725
746
  const objects = this.map.objects;
726
- const totalCursorAmount = this.downCursorInstances.reduce((acc, value) => acc + value.size, 0);
747
+ const totalCursorAmount = this.downCursorInstances.reduce((acc, value) => acc + value.occurrences.length, 0);
727
748
  for (let i = 0; i < this.downCursorInstances.length; ++i) {
728
749
  if (filledCursorAmount <= 3) {
729
750
  break;
730
751
  }
731
752
  const cursorInstance = this.downCursorInstances[i];
732
753
  // Use an estimation for accidental tap threshold.
733
- if (cursorInstance.size <=
754
+ if (cursorInstance.occurrences.length <=
734
755
  Math.ceil(objects.length / this.accidentalTapThreshold) &&
735
- cursorInstance.size / totalCursorAmount <
756
+ cursorInstance.occurrences.length / totalCursorAmount <
736
757
  this.threeFingerRatioThreshold * 2) {
737
758
  --filledCursorAmount;
738
- for (const property in cursorInstance) {
739
- const prop = property;
740
- if (Array.isArray(cursorInstance[prop])) {
741
- cursorInstance[prop].length = 0;
742
- }
743
- else {
744
- cursorInstance[prop] = 0;
745
- }
746
- }
759
+ cursorInstance.occurrences.length = 0;
747
760
  }
748
761
  this.downCursorInstances[i] = cursorInstance;
749
762
  }
@@ -773,13 +786,9 @@ class ThreeFingerChecker {
773
786
  : this.hitWindow.hitWindowFor50(isPrecise));
774
787
  // Filter cursor instances during section.
775
788
  this.downCursorInstances.forEach((c) => {
776
- const i = c.time.findIndex((t) => t >= startTime);
789
+ const i = c.occurrences.findIndex((t) => t.time >= startTime);
777
790
  if (i !== -1) {
778
- c.size -= i;
779
- c.time.splice(0, i);
780
- c.x.splice(0, i);
781
- c.y.splice(0, i);
782
- c.id.splice(0, i);
791
+ c.occurrences = c.occurrences.slice(0, i);
783
792
  }
784
793
  });
785
794
  const cursorAmounts = [];
@@ -791,13 +800,13 @@ class ThreeFingerChecker {
791
800
  }
792
801
  const cursorData = this.downCursorInstances[i];
793
802
  let amount = 0;
794
- for (let j = 0; j < cursorData.size; ++j) {
795
- if (cursorData.time[j] >= startTime &&
796
- cursorData.time[j] <= endTime) {
803
+ for (let j = 0; j < cursorData.occurrences.length; ++j) {
804
+ if (cursorData.occurrences[j].time >= startTime &&
805
+ cursorData.occurrences[j].time <= endTime) {
797
806
  ++amount;
798
807
  cursorVectorTimes.push({
799
- vector: new osuBase.Vector2(cursorData.x[j], cursorData.y[j]),
800
- time: cursorData.time[j],
808
+ vector: new osuBase.Vector2(cursorData.occurrences[j].position.x, cursorData.occurrences[j].position.y),
809
+ time: cursorData.occurrences[j].time,
801
810
  });
802
811
  }
803
812
  }
@@ -936,10 +945,6 @@ class TwoHandChecker {
936
945
  * The data of the replay.
937
946
  */
938
947
  data;
939
- /**
940
- * A cursor data array that only contains `movementType.DOWN` and `movementType.MOVE` movement ID occurrences.
941
- */
942
- downMoveCursorInstances = [];
943
948
  /**
944
949
  * The hitobjects of the beatmap that have been assigned with their respective cursor index.
945
950
  */
@@ -974,56 +979,28 @@ class TwoHandChecker {
974
979
  * Checks if a beatmap is two-handed.
975
980
  */
976
981
  check() {
977
- this.filterCursorInstances();
978
- if (this.downMoveCursorInstances.filter((v) => v.size > 0).length <= 1) {
982
+ if (this.data.cursorMovement.filter((v) => v.occurrences.length > 0)
983
+ .length <= 1) {
979
984
  return false;
980
985
  }
981
986
  this.indexHitObjects();
982
987
  this.applyPenalty();
983
988
  return true;
984
989
  }
985
- /**
986
- * Filters the original cursor instances, returning only those with `movementType.DOWN` and `movementType.MOVE` movement ID.
987
- */
988
- filterCursorInstances() {
989
- for (let i = 0; i < this.data.cursorMovement.length; ++i) {
990
- const cursorInstance = this.data.cursorMovement[i];
991
- const newCursorData = {
992
- size: 0,
993
- time: [],
994
- x: [],
995
- y: [],
996
- id: [],
997
- };
998
- for (let j = 0; j < cursorInstance.size; ++j) {
999
- if (cursorInstance.id[j] === exports.movementType.UP) {
1000
- continue;
1001
- }
1002
- ++newCursorData.size;
1003
- newCursorData.time.push(cursorInstance.time[j]);
1004
- newCursorData.x.push(cursorInstance.x[j]);
1005
- newCursorData.y.push(cursorInstance.y[j]);
1006
- newCursorData.id.push(cursorInstance.id[j]);
1007
- }
1008
- this.downMoveCursorInstances.push(newCursorData);
1009
- }
1010
- }
1011
990
  /**
1012
991
  * Converts hitobjects into indexed hit objects.
1013
992
  */
1014
993
  indexHitObjects() {
1015
- const objects = this.map.objects;
1016
- const objectData = this.data.hitObjectData;
994
+ const hitWindowOffset = this.getHitWindowOffset();
1017
995
  const indexes = [];
1018
996
  for (let i = 0; i < this.map.objects.length; ++i) {
1019
- const current = objects[i];
1020
- const currentData = objectData[i];
1021
- const index = this.getCursorIndex(current, currentData);
997
+ const index = this.map.objects[i].aimStrainWithSliders >= 175
998
+ ? this.getCursorIndex(i, hitWindowOffset)
999
+ : -1;
1022
1000
  indexes.push(index);
1023
- this.indexedHitObjects.push(new IndexedHitObject(current, index));
1001
+ this.indexedHitObjects.push(new IndexedHitObject(this.map.objects[i], index));
1024
1002
  }
1025
- console.log(indexes.filter((v) => v !== -1).length, "cursors found,", indexes.filter((v) => v === -1).length, "not found");
1026
- const indexCounts = osuBase.Utils.initializeArray(this.downMoveCursorInstances.length, 0);
1003
+ const indexCounts = osuBase.Utils.initializeArray(this.data.cursorMovement.length, 0);
1027
1004
  for (const index of indexes) {
1028
1005
  if (index === -1) {
1029
1006
  continue;
@@ -1033,7 +1010,8 @@ class TwoHandChecker {
1033
1010
  const mainCursorIndex = indexCounts.indexOf(Math.max(...indexCounts));
1034
1011
  const ignoredCursorIndexes = [];
1035
1012
  for (let i = 0; i < indexCounts.length; ++i) {
1036
- if (indexCounts[i] < this.minCursorIndexCount) {
1013
+ if (indexCounts[i] < this.minCursorIndexCount &&
1014
+ i !== mainCursorIndex) {
1037
1015
  ignoredCursorIndexes.push(i);
1038
1016
  }
1039
1017
  }
@@ -1043,109 +1021,233 @@ class TwoHandChecker {
1043
1021
  indexedHitObject.cursorIndex = mainCursorIndex;
1044
1022
  }
1045
1023
  });
1046
- for (let i = 0; i < this.downMoveCursorInstances.length; ++i) {
1047
- console.log("Index", i, "count:", indexes.filter((v) => v === i).length);
1024
+ for (let i = 0; i < this.data.cursorMovement.length; ++i) {
1025
+ console.log("Index", i, "count:", this.indexedHitObjects.filter((v) => v.cursorIndex === i).length);
1048
1026
  }
1049
1027
  }
1028
+ /**
1029
+ * Gets the hit window offset to be applied to `getCursorIndex`.
1030
+ */
1031
+ getHitWindowOffset() {
1032
+ const deltaTimes = [];
1033
+ for (let i = 0; i < this.data.cursorMovement.length; ++i) {
1034
+ const c = this.data.cursorMovement[i];
1035
+ for (let j = 0; j < c.occurrences.length; ++j) {
1036
+ if (c.occurrences[j].time <
1037
+ this.map.map.hitObjects.objects[0].startTime -
1038
+ this.hitWindow.hitWindowFor50()) {
1039
+ continue;
1040
+ }
1041
+ if (c.occurrences[j].id !== exports.movementType.MOVE) {
1042
+ continue;
1043
+ }
1044
+ const deltaTime = c.occurrences[j]?.time - c.occurrences[j - 1]?.time || 0;
1045
+ if (deltaTime > 0) {
1046
+ deltaTimes.push(deltaTime);
1047
+ }
1048
+ }
1049
+ }
1050
+ return Math.min(...deltaTimes);
1051
+ }
1050
1052
  /**
1051
1053
  * Gets the cursor index that hits the given object.
1052
1054
  *
1053
- * @param object The object to check.
1054
- * @param data The replay data of the object.
1055
+ * @param index The index of the object to check.
1056
+ * @param hitWindowOffset The offset for hit window to compensate for replay hit inaccuracies.
1055
1057
  * @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.
1056
1058
  */
1057
- getCursorIndex(object, data) {
1059
+ getCursorIndex(index, hitWindowOffset) {
1060
+ const object = this.map.objects[index];
1061
+ const data = this.data.hitObjectData[index];
1058
1062
  if (object.object instanceof osuBase.Spinner ||
1059
1063
  data.result === exports.hitResult.RESULT_0) {
1060
1064
  return -1;
1061
1065
  }
1066
+ if (object.object.startTime === 12514) {
1067
+ console.log("Hi");
1068
+ }
1062
1069
  const isPrecise = this.data.convertedMods.some((m) => m instanceof osuBase.ModPrecise);
1063
- let hitWindowLength;
1064
- switch (data.result) {
1065
- case exports.hitResult.RESULT_300:
1066
- hitWindowLength = this.hitWindow.hitWindowFor300(isPrecise);
1067
- break;
1068
- case exports.hitResult.RESULT_100:
1069
- hitWindowLength = this.hitWindow.hitWindowFor100(isPrecise);
1070
- break;
1071
- default:
1072
- hitWindowLength = this.hitWindow.hitWindowFor50(isPrecise);
1070
+ // For sliders, automatically set hit window to be as lenient as possible.
1071
+ let hitWindowLength = this.hitWindow.hitWindowFor50(isPrecise);
1072
+ if (!(object.object instanceof osuBase.Slider)) {
1073
+ switch (data.result) {
1074
+ case exports.hitResult.RESULT_300:
1075
+ hitWindowLength = this.hitWindow.hitWindowFor300(isPrecise);
1076
+ break;
1077
+ case exports.hitResult.RESULT_100:
1078
+ hitWindowLength = this.hitWindow.hitWindowFor100(isPrecise);
1079
+ break;
1080
+ }
1073
1081
  }
1074
- const hitTime = object.object.startTime;
1075
- const maximumHitTime = hitTime + hitWindowLength;
1076
- const minimumHitTime = hitTime - hitWindowLength;
1082
+ const startTime = object.object.startTime;
1083
+ const hitTime = startTime + data.accuracy;
1084
+ const minimumHitTime = startTime - hitWindowLength - hitWindowOffset;
1085
+ const maximumHitTime = startTime + hitWindowLength + hitWindowOffset;
1077
1086
  const cursorInformations = [];
1078
- for (let i = 0; i < this.downMoveCursorInstances.length; ++i) {
1079
- const c = this.downMoveCursorInstances[i];
1080
- let minDistance = Number.POSITIVE_INFINITY;
1081
- let minHitTime = 0;
1082
- for (let j = 0; j < c.size; ++j) {
1083
- if (c.time[j] < minimumHitTime) {
1084
- continue;
1087
+ for (let i = 0; i < this.data.cursorMovement.length; ++i) {
1088
+ const c = this.data.cursorMovement[i];
1089
+ if (c.occurrences.length === 0) {
1090
+ continue;
1091
+ }
1092
+ let hitTimeBeforeIndex = osuBase.MathUtils.clamp(c.occurrences.findIndex((v) => v.time >= minimumHitTime), 1, c.occurrences.length - 1) - 1;
1093
+ let hitTimeAfterIndex = c.occurrences.findIndex(
1094
+ // There is a special case for sliders where the time leniency in droid is a lot bigger compared to PC.
1095
+ // To prevent slider end time from ending earlier than hit window leniency, we use the maximum value between both.
1096
+ (v) => v.time >= Math.max(object.object.endTime, maximumHitTime));
1097
+ if (hitTimeAfterIndex === -1) {
1098
+ // Maximum hit time or object end time may be out of bounds for every presses.
1099
+ // We set the index to the latest cursor occurrence if that happens.
1100
+ hitTimeAfterIndex = c.occurrences.length;
1101
+ }
1102
+ --hitTimeAfterIndex;
1103
+ // Sometimes a `movementType.UP` instance occurs at the same time as a `movementType.MOVE`
1104
+ // or a cursor is recorded twice in one time, therefore this check is required.
1105
+ while (c.occurrences[hitTimeBeforeIndex]?.time ===
1106
+ c.occurrences[hitTimeBeforeIndex - 1]?.time &&
1107
+ hitTimeBeforeIndex > 0) {
1108
+ --hitTimeBeforeIndex;
1109
+ }
1110
+ // We track the cursor movement along those indexes.
1111
+ // Current cursor position is in `hitTimeBeforeIndex`.
1112
+ let distance = Number.POSITIVE_INFINITY;
1113
+ let acceptableRadius = object.object.radius;
1114
+ // Sliders have a bigger radius tolerance due to slider ball.
1115
+ if (object.object instanceof osuBase.Slider) {
1116
+ acceptableRadius *= 2.4;
1117
+ }
1118
+ let j = hitTimeBeforeIndex;
1119
+ for (j; j <= hitTimeAfterIndex; ++j) {
1120
+ const occurrence = c.occurrences[j];
1121
+ const nextOccurrence = c.occurrences[j + 1];
1122
+ const cursorPosition = occurrence.position;
1123
+ if (occurrence.time > hitTime + hitWindowOffset) {
1124
+ // Set distance to minimum just for the last.
1125
+ if (occurrence.id !== exports.movementType.UP) {
1126
+ distance = Math.min(distance, object.object.stackedPosition.getDistance(cursorPosition));
1127
+ }
1128
+ break;
1085
1129
  }
1086
- // For some reason, some cursor instances repeat itself,
1087
- // so just skip it to save time.
1088
- if (c.time[j + 1] === c.time[j]) {
1130
+ if (occurrence.id === exports.movementType.UP) {
1089
1131
  continue;
1090
1132
  }
1091
- if (c.time[j - 1] > maximumHitTime) {
1092
- break;
1133
+ distance =
1134
+ object.object.stackedPosition.getDistance(cursorPosition);
1135
+ if (nextOccurrence &&
1136
+ nextOccurrence.id === exports.movementType.MOVE &&
1137
+ occurrence.time !== nextOccurrence.time &&
1138
+ !occurrence.position.equals(nextOccurrence.position)) {
1139
+ // If next cursor is a `move` instance and it doesn't go out of time
1140
+ // range, we interpolate cursor position between two occurrences.
1141
+ const nextPosition = nextOccurrence.position;
1142
+ const displacement = nextPosition.subtract(cursorPosition);
1143
+ for (let mSecPassed = Math.max(minimumHitTime, occurrence.time); mSecPassed <=
1144
+ Math.min(hitTime + hitWindowOffset, nextOccurrence.time); ++mSecPassed) {
1145
+ const progress = (mSecPassed - occurrence.time) /
1146
+ (nextOccurrence.time - occurrence.time);
1147
+ distance = object.object.stackedPosition.getDistance(cursorPosition.add(displacement.scale(progress)));
1148
+ }
1093
1149
  }
1094
- let hitPosition = new osuBase.Vector2(c.x[j], c.y[j]);
1095
- let distanceToObject = object.object.stackedPosition.getDistance(hitPosition);
1096
- if (minDistance > distanceToObject) {
1097
- minDistance = distanceToObject;
1098
- minHitTime = c.time[j];
1150
+ }
1151
+ if (distance > acceptableRadius) {
1152
+ continue;
1153
+ }
1154
+ // The case for a one-handed object is that there will be a slight movement in the cursor towards
1155
+ // the next object in fast patterns. We should not be worried about slow patterns as they will only
1156
+ // make a minimal difference and aim strain threshold should filter them out.
1157
+ // In order to verify if the player does that, we check if the movement towards the next
1158
+ // object is sufficient enough to be two-handed. This is done by checking if the movement
1159
+ // from the current object to the next object and the movement from the current object
1160
+ // to the significant move cursor occurrence produces an angle that is acute enough.
1161
+ let isAngleFulfilled = false;
1162
+ // For sliders, we need to consider two cases. The first case is when the player doesn't drag
1163
+ // the slider. The second case is when the player drags the slider.
1164
+ // TODO: check for cursor occurrences in nested objects
1165
+ // Get the latest down or movement cursor occurrence.
1166
+ while (c.occurrences[j]?.id === exports.movementType.UP &&
1167
+ j > hitTimeBeforeIndex) {
1168
+ --j;
1169
+ }
1170
+ if (object.object instanceof osuBase.Circle) {
1171
+ // For circles, we only need to consider the actual press on the circle.
1172
+ // Therefore, we need to get the latest down cursor occurrence instead.
1173
+ while (c.occurrences[j]?.id !== exports.movementType.DOWN &&
1174
+ j > hitTimeBeforeIndex) {
1175
+ --j;
1099
1176
  }
1100
- minDistance = Math.min(minDistance, object.object.stackedPosition.getDistance(hitPosition));
1101
- if (c.id[j + 1] === exports.movementType.MOVE ||
1102
- c.id[j] === exports.movementType.MOVE) {
1103
- // Interpolate cursor position between two occurrences
1104
- const initialPosition = new osuBase.Vector2(c.x[j], c.y[j]);
1105
- const nextPosition = new osuBase.Vector2(c.x[j + 1], c.y[j + 1]);
1106
- const displacement = nextPosition.subtract(initialPosition);
1107
- for (let mSecPassed = c.time[j]; mSecPassed <= Math.min(c.time[j + 1], maximumHitTime); ++mSecPassed) {
1108
- const progress = (mSecPassed - c.time[j]) /
1109
- (c.time[j + 1] - c.time[j]);
1110
- hitPosition = initialPosition.add(displacement.scale(progress));
1111
- distanceToObject =
1112
- object.object.stackedPosition.getDistance(hitPosition);
1113
- if (minDistance > distanceToObject) {
1114
- minDistance = distanceToObject;
1115
- minHitTime = mSecPassed;
1116
- }
1177
+ }
1178
+ // Theoretically there can only be 1 up occurrence, but this is a
1179
+ // consideration if the user manually adds cursor occurrences.
1180
+ if (c.occurrences[j]?.id === exports.movementType.UP) {
1181
+ ++j;
1182
+ }
1183
+ // Some move instances move in the exact same place. Not sure why, most likely
1184
+ // because the position is recorded as int in the game and the movement is too small to
1185
+ // convert into +1 or -1.
1186
+ let nextSignificantOccurrenceIndex = j + 1;
1187
+ while (c.occurrences[j] &&
1188
+ c.occurrences[nextSignificantOccurrenceIndex] &&
1189
+ c.occurrences[j].position.equals(c.occurrences[nextSignificantOccurrenceIndex].position)) {
1190
+ ++nextSignificantOccurrenceIndex;
1191
+ }
1192
+ const nextSignificantOccurrence = c.occurrences[nextSignificantOccurrenceIndex];
1193
+ const next = this.map.objects[index + 1];
1194
+ if (nextSignificantOccurrence?.id === exports.movementType.MOVE && next) {
1195
+ // Get the object's actual end position.
1196
+ let actualEndPosition = object.object.stackedEndPosition;
1197
+ if (object.object instanceof osuBase.Slider &&
1198
+ object.object.lazyEndPosition) {
1199
+ // For sliders, we take the closest distance between the lazy end position
1200
+ // and stacked end position towards the next significant cursor occurrence.
1201
+ // This assumes that the player takes the simpler movement.
1202
+ const lazyEndDistance = object.object.lazyEndPosition.getDistance(nextSignificantOccurrence.position);
1203
+ const actualEndDistance = object.object.stackedEndPosition.getDistance(nextSignificantOccurrence.position);
1204
+ if (lazyEndDistance < actualEndDistance) {
1205
+ actualEndPosition = object.object.lazyEndPosition;
1117
1206
  }
1118
1207
  }
1208
+ // Get the movement vector towards the next cursor occurrence by subtracting
1209
+ // the next cursor occurrence with the object's position.
1210
+ const movementVec = nextSignificantOccurrence.position.subtract(actualEndPosition);
1211
+ const currentToNext = next.object.stackedPosition.subtract(actualEndPosition);
1212
+ const dot = currentToNext.dot(movementVec);
1213
+ const det = currentToNext.x * movementVec.y -
1214
+ currentToNext.y * movementVec.x;
1215
+ const movementToNextAngle = Math.abs(Math.atan2(det, dot));
1216
+ isAngleFulfilled = movementToNextAngle < Math.PI / 6;
1119
1217
  }
1120
- if (minDistance <= object.object.radius) {
1121
- cursorInformations.push({
1122
- cursorIndex: i,
1123
- hitTimeDiff: Math.abs(minHitTime - hitTime),
1124
- });
1125
- }
1126
- }
1127
- if (cursorInformations.length === 0) {
1128
- return -1;
1218
+ cursorInformations.push({
1219
+ // If the angle is fulfilled, we set the cursor index to the main cursor index.
1220
+ cursorIndex: isAngleFulfilled ? -1 : i,
1221
+ distanceDiff: distance,
1222
+ });
1129
1223
  }
1130
- // Now we look at which cursor is closest to hit time
1131
- const minHitTimeDiff = Math.min(...cursorInformations.map((v) => {
1132
- return v.hitTimeDiff;
1133
- }));
1134
- return (cursorInformations.find((c) => c.hitTimeDiff === minHitTimeDiff)
1135
- ?.cursorIndex);
1224
+ // Cursors have been filtered to see which of them is inside the object.
1225
+ // Now we look at which cursor is closest to the center of the object.
1226
+ const minDistanceDiff = Math.min(...cursorInformations.map((v) => v.distanceDiff));
1227
+ return (cursorInformations.find((c) => c.distanceDiff === minDistanceDiff)
1228
+ ?.cursorIndex ?? -1);
1136
1229
  }
1137
1230
  /**
1138
1231
  * Applies penalty to the original star rating instance.
1139
1232
  */
1140
1233
  applyPenalty() {
1141
- const beatmaps = new Array(this.downMoveCursorInstances.length);
1234
+ const beatmaps = new Array(this.data.cursorMovement.length);
1142
1235
  this.indexedHitObjects.forEach((o) => {
1143
1236
  if (!beatmaps[o.cursorIndex]) {
1144
1237
  const map = osuBase.Utils.deepCopy(this.map.map);
1238
+ map.hitObjects.clear();
1145
1239
  beatmaps[o.cursorIndex] = map;
1146
1240
  }
1147
1241
  beatmaps[o.cursorIndex].hitObjects.add(o.object.object);
1148
1242
  });
1243
+ // Preserve some values that aren't reasonable for them to be changed.
1244
+ const preservedValues = this.map.objects.map((v) => {
1245
+ return {
1246
+ noteDensity: v.noteDensity,
1247
+ rhythmStrain: v.rhythmStrain,
1248
+ rhythmMultiplier: v.rhythmMultiplier,
1249
+ };
1250
+ });
1149
1251
  this.map.objects.length = 0;
1150
1252
  beatmaps.forEach((beatmap) => {
1151
1253
  if (!beatmap) {
@@ -1155,15 +1257,25 @@ class TwoHandChecker {
1155
1257
  starRating.map = beatmap;
1156
1258
  starRating.generateDifficultyHitObjects();
1157
1259
  starRating.objects[0].deltaTime =
1158
- starRating.objects[0].object.startTime -
1159
- this.indexedHitObjects[0].object.object.startTime;
1160
- starRating.objects[0].strainTime = Math.max(50, starRating.objects[0].deltaTime);
1260
+ starRating.objects[0].startTime -
1261
+ this.indexedHitObjects[0].object.startTime;
1262
+ starRating.objects[0].strainTime = Math.max(25, starRating.objects[0].deltaTime);
1161
1263
  this.map.objects.push(...starRating.objects);
1162
1264
  });
1163
- this.map.objects.sort((a, b) => {
1164
- return a.startTime - b.startTime;
1165
- });
1166
- this.map.calculateAll();
1265
+ this.map.objects.sort((a, b) => a.startTime - b.startTime);
1266
+ // Reassign rhythm values before calculating.
1267
+ for (let i = 0; i < this.map.objects.length; ++i) {
1268
+ this.map.objects[i].noteDensity = preservedValues[i].noteDensity;
1269
+ this.map.objects[i].rhythmStrain = preservedValues[i].rhythmStrain;
1270
+ this.map.objects[i].rhythmMultiplier =
1271
+ preservedValues[i].rhythmMultiplier;
1272
+ }
1273
+ // Do not include rhythm skill.
1274
+ this.map.calculateAim();
1275
+ this.map.calculateTap();
1276
+ this.map.calculateFlashlight();
1277
+ this.map.calculateVisual();
1278
+ this.map.calculateTotal();
1167
1279
  }
1168
1280
  }
1169
1281
 
@@ -1404,42 +1516,41 @@ class ReplayAnalyzer {
1404
1516
  for (let x = 0; x < size; x++) {
1405
1517
  const moveSize = replayDataBuffer.readInt32BE(bufferCounter);
1406
1518
  bufferCounter += this.INT_LENGTH;
1407
- const moveArray = {
1408
- size: moveSize,
1409
- time: [],
1410
- x: [],
1411
- y: [],
1412
- id: [],
1413
- };
1519
+ const time = [];
1520
+ const x = [];
1521
+ const y = [];
1522
+ const id = [];
1414
1523
  for (let i = 0; i < moveSize; i++) {
1415
- moveArray.time[i] = replayDataBuffer.readInt32BE(bufferCounter);
1524
+ time[i] = replayDataBuffer.readInt32BE(bufferCounter);
1416
1525
  bufferCounter += this.INT_LENGTH;
1417
- moveArray.id[i] = moveArray.time[i] & 3;
1418
- moveArray.time[i] >>= 2;
1419
- if (moveArray.id[i] !== exports.movementType.UP) {
1526
+ id[i] = time[i] & 3;
1527
+ time[i] >>= 2;
1528
+ if (id[i] !== exports.movementType.UP) {
1420
1529
  if (resultObject.replayVersion >= 5) {
1421
- moveArray.x[i] =
1422
- replayDataBuffer.readFloatBE(bufferCounter);
1530
+ x[i] = replayDataBuffer.readFloatBE(bufferCounter);
1423
1531
  bufferCounter += this.FLOAT_LENGTH;
1424
- moveArray.y[i] =
1425
- replayDataBuffer.readFloatBE(bufferCounter);
1532
+ y[i] = replayDataBuffer.readFloatBE(bufferCounter);
1426
1533
  bufferCounter += this.FLOAT_LENGTH;
1427
1534
  }
1428
1535
  else {
1429
- moveArray.x[i] =
1430
- replayDataBuffer.readInt16BE(bufferCounter);
1536
+ x[i] = replayDataBuffer.readInt16BE(bufferCounter);
1431
1537
  bufferCounter += this.SHORT_LENGTH;
1432
- moveArray.y[i] =
1433
- replayDataBuffer.readInt16BE(bufferCounter);
1538
+ y[i] = replayDataBuffer.readInt16BE(bufferCounter);
1434
1539
  bufferCounter += this.SHORT_LENGTH;
1435
1540
  }
1436
1541
  }
1437
1542
  else {
1438
- moveArray.x[i] = -1;
1439
- moveArray.y[i] = -1;
1543
+ x[i] = -1;
1544
+ y[i] = -1;
1440
1545
  }
1441
1546
  }
1442
- resultObject.cursorMovement.push(moveArray);
1547
+ resultObject.cursorMovement.push(new CursorData({
1548
+ size: moveSize,
1549
+ time: time,
1550
+ x: x,
1551
+ y: y,
1552
+ id: id,
1553
+ }));
1443
1554
  }
1444
1555
  const replayObjectLength = replayDataBuffer.readInt32BE(bufferCounter);
1445
1556
  bufferCounter += this.INT_LENGTH;
@@ -1720,6 +1831,7 @@ class ReplayObjectData {
1720
1831
  }
1721
1832
 
1722
1833
  exports.CursorData = CursorData;
1834
+ exports.CursorOccurrence = CursorOccurrence;
1723
1835
  exports.ReplayAnalyzer = ReplayAnalyzer;
1724
1836
  exports.ReplayData = ReplayData;
1725
1837
  exports.ReplayObjectData = ReplayObjectData;