-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNoteSearch.cs
More file actions
118 lines (104 loc) · 3.46 KB
/
NoteSearch.cs
File metadata and controls
118 lines (104 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using Parser.Map;
using Parser.Utils;
using ReplayDecoder;
namespace MapPostprocessor
{
public static class NoteSearch
{
public static Dictionary<int, bool> TryFindingNotes(MapWrapper map, Replay replay, List<NoteWrapper> mapnotes) {
var foundNotes = new Dictionary<int, bool>();
var nonBombs = replay.notes.Where(n => n.eventType != NoteEventType.bomb).ToList();
for (var j = 0; j < mapnotes.Count; j++) {
var mapnote = mapnotes[j];
for (var m = 0; m < nonBombs.Count; m++) {
var replaynote = nonBombs[m];
if (!foundNotes.ContainsKey(m)) {
if (
Math.Abs(replaynote.spawnTime - mapnote.Time) < 0.0005 &&
(replaynote.noteID == mapnote.Id ||
replaynote.noteID == mapnote.IdWithScoring ||
replaynote.noteID == mapnote.IdWithAlternativeScoring ||
replaynote.noteID == mapnote.IdWithLegacyScoring)
) {
mapnote.Event = replaynote;
foundNotes[m] = true;
break;
}
}
}
}
for (var j = 0; j < mapnotes.Count; j++) {
var mapnote = mapnotes[j];
if (mapnote.Event == null) {
for (var m = 0; m < nonBombs.Count; m++) {
var replaynote = nonBombs[m];
if (!foundNotes.ContainsKey(m)) {
if (
replaynote.noteID == mapnote.Id ||
replaynote.noteID == mapnote.IdWithScoring ||
replaynote.noteID == mapnote.IdWithAlternativeScoring ||
replaynote.noteID == mapnote.IdWithLegacyScoring
) {
mapnote.Event = replaynote;
break;
}
}
}
}
}
return foundNotes;
}
public static Dictionary<int, bool> TryFindingBombs(MapWrapper map, Replay replay, List<BombWrapper> mapnotes) {
var foundNotes = new Dictionary<int, bool>();
var nonBombs = replay.notes.Where(n => n.eventType == NoteEventType.bomb).ToList();
for (var j = 0; j < mapnotes.Count; j++) {
var mapnote = mapnotes[j];
for (var m = 0; m < nonBombs.Count; m++) {
var replaynote = nonBombs[m];
if (!foundNotes.ContainsKey(m)) {
if (
Math.Abs(replaynote.spawnTime - mapnote.Time) < 0.0005 &&
(replaynote.noteID == mapnote.Id ||
replaynote.noteID == mapnote.IdWithScoring ||
replaynote.noteID == mapnote.IdWithAlternativeScoring ||
replaynote.noteID == mapnote.IdWithLegacyScoring)
) {
mapnote.Event = replaynote;
foundNotes[m] = true;
break;
}
}
}
}
return foundNotes;
}
public static MapWrapper ForReplay(this MapWrapper map, Replay replay) {
var result = map;
foreach (var item in map.Notes)
{
item.Event = null;
}
foreach (var item in map.Bombs)
{
item.Event = null;
}
foreach (var item in map.Chains)
{
item.Event = null;
}
var foundNotes = TryFindingNotes(map, replay, map.Notes);
if (foundNotes.Keys.Count < map.Notes.Count) {
var mirroredData = ChiralitySupport.Mirror_Horizontal(map.Difficulty.Data, 4, true, false, false);
var mirrored = MapWrapper.Process(new DifficultySet(map.Difficulty.Difficulty, map.Difficulty.Characteristic, mirroredData, map.Difficulty.BeatMap));
var foundMirrored = TryFindingNotes(map, replay, mirrored.Notes);
if (foundMirrored.Keys.Count > foundNotes.Keys.Count) {
result = mirrored;
} else {
Console.WriteLine($"Broken replay {replay.info.hash} {replay.info.playerName} {replay.info.difficulty} {replay.info.mode}");
}
}
TryFindingBombs(result, replay, result.Bombs);
return result;
}
}
}