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