Skip to content

Commit

Permalink
Add: Further improved unsubmited map matching using map hash derived …
Browse files Browse the repository at this point in the history
…from osu memory
  • Loading branch information
Piotrekol committed Dec 20, 2018
1 parent 211d37d commit 0c33095
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 4 deletions.
1 change: 1 addition & 0 deletions StreamCompanionTypes/DataTypes/MapSearchArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class MapSearchArgs : EventArgs
public int MapId { get; set; } = 0;
public OsuStatus Status { get; set; } = OsuStatus.Null;
public string SourceName { get; }
public string MapHash { get; set; }
//TODO: enforce explicitly setting event type via ctor
public OsuEventType EventType { get; set; } = OsuEventType.MapChange;

Expand Down
7 changes: 7 additions & 0 deletions StreamCompanionTypes/Interfaces/ISqliteControler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ public interface ISqliteControler : IDisposable, IMapDataStorer, CollectionManag
/// <returns>Beatmap object with data, or null on not found</returns>
Beatmap GetBeatmap(int mapId);

/// <summary>
///
/// </summary>
/// <param name="mapId"></param>
/// <returns>Beatmap object with data, or null on not found</returns>
Beatmap GetBeatmap(string mapHash);

/// <summary>
///
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void ConsumerTask()
//Here we prioritize Memory events over MSN/other.
if (TasksMemory.TryPop(out searchArgs))
{
if (searchArgs.MapId == 0)
if (searchArgs.MapId == 0 && string.IsNullOrEmpty(searchArgs.MapHash))
{
memorySearchFailed = true;
}
Expand Down
24 changes: 24 additions & 0 deletions osu!StreamCompanion/Code/Core/SqliteConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,30 @@ public Beatmap GetBeatmap(int mapId)
}
return beatmap;
}
public Beatmap GetBeatmap(string mapHash)
{
mapHash = mapHash.ToLower();
List<string> tableNames = new List<string>{"withID", "Temp", "withoutID" };

Beatmap beatmap = null;

foreach (var tableName in tableNames)
{
string sql = $"SELECT * FROM `{tableName}` WHERE Md5 = '{mapHash}'";
var reader = Query(sql);

if (reader.Read())
{
beatmap = new Beatmap();
beatmap.Read(reader);
reader.Dispose();
break;
}
reader.Dispose();
}

return beatmap;
}

private Beatmap GetBeatmapUsingReplacements(string table, bool useRaw, Dictionary<string, string> replacements)
{
Expand Down
9 changes: 9 additions & 0 deletions osu!StreamCompanion/Code/Core/SqliteControler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ public Beatmap GetBeatmap(int mapId)
return _sqlConnector.GetBeatmap(mapId);
}
}

public Beatmap GetBeatmap(string mapHash)
{
lock (_sqlConnector)
{
return _sqlConnector.GetBeatmap(mapHash);
}
}

/// <summary>
///
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,34 @@ public MapSearchResult FindBeatmap(MapSearchArgs searchArgs)
Beatmap beatmap = null;
if (searchArgs.MapId > 0)
beatmap = _sqliteControler.GetBeatmap(searchArgs.MapId);
if (beatmap == null || (beatmap.MapId <= 0))

if(!IsValidBeatmap(beatmap) && !string.IsNullOrEmpty(searchArgs.MapHash))
beatmap = _sqliteControler.GetBeatmap(searchArgs.MapHash);


if (!IsValidBeatmap(beatmap))
{
if (!(string.IsNullOrEmpty(searchArgs.Artist) && string.IsNullOrEmpty(searchArgs.Title)) || !string.IsNullOrEmpty(searchArgs.Raw))
{
beatmap = _sqliteControler.GetBeatmap(searchArgs.Artist, searchArgs.Title, searchArgs.Diff, searchArgs.Raw);
}
}

if (beatmap?.MapId > -1 && !(string.IsNullOrWhiteSpace(beatmap.ArtistRoman) || string.IsNullOrWhiteSpace(beatmap.TitleRoman)))
if (IsValidBeatmap(beatmap))
{
result.BeatmapsFound.Add(beatmap);
}
result.MapSearchString = searchArgs.Raw;
return result;
}

private bool IsValidBeatmap(Beatmap beatmap)
{
return beatmap != null
&& !string.IsNullOrEmpty(beatmap.Md5)
&& !(string.IsNullOrWhiteSpace(beatmap.ArtistRoman) || string.IsNullOrWhiteSpace(beatmap.TitleRoman));
}

public void GetMainWindowHandle(IMainWindowModel mainWindowHandle)
{
_mainWindowHandle = mainWindowHandle;
Expand Down
4 changes: 3 additions & 1 deletion plugins/OsuMemoryEventSource/MemoryListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ public void Tick(IOsuMemoryReader reader, bool sendEvents)
_lastMapId = _currentMapId;
_lastStatus = _currentStatus;
_lastMapString = _currentMapString;
var mapHash = reader.GetMapMd5();

NewOsuEvent?.Invoke(this, new MapSearchArgs("OsuMemory")
{
MapId = _currentMapId,
Status = status,
Raw = _currentMapString
Raw = _currentMapString,
MapHash = mapHash
});

}
Expand Down

0 comments on commit 0c33095

Please sign in to comment.