Skip to content

Commit

Permalink
Add Support for DataPuller v2.1.0
Browse files Browse the repository at this point in the history
Closes #16
  • Loading branch information
TheXorog committed Apr 14, 2023
1 parent 7f60551 commit c6ce772
Show file tree
Hide file tree
Showing 9 changed files with 420 additions and 7 deletions.
29 changes: 29 additions & 0 deletions BeatRecorder/Entities/BeatSaber/DataPuller/DataPullerData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace BeatRecorder.Entities;

public class DataPullerData
{
public int Score { get; set; }
public int ScoreWithMultipliers { get; set; }
public int MaxScore { get; set; }
public int MaxScoreWithMultipliers { get; set; }
public string Rank { get; set; }
public bool FullCombo { get; set; }
public int NotesSpawned { get; set; }
public int Combo { get; set; }
public int Misses { get; set; }
public float Accuracy { get; set; }
public Blockhitscore BlockHitScore { get; set; }
public float PlayerHealth { get; set; }
public int ColorType { get; set; }
public int TimeElapsed { get; set; }
public int EventTrigger { get; set; }
public long UnixTimestamp { get; set; }

public class Blockhitscore
{
public int PreSwing { get; set; }
public int PostSwing { get; set; }
public int CenterSwing { get; set; }
}

}
62 changes: 62 additions & 0 deletions BeatRecorder/Entities/BeatSaber/DataPuller/DataPullerMain.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
namespace BeatRecorder.Entities;

public class DataPullerMain
{
public string GameVersion { get; set; }
public string PluginVersion { get; set; }
public bool InLevel { get; set; }
public bool LevelPaused { get; set; }
public bool LevelFinished { get; set; }
public bool LevelFailed { get; set; }
public bool LevelQuit { get; set; }
public string Hash { get; set; }
public string SongName { get; set; }
public string SongSubName { get; set; }
public string SongAuthor { get; set; }
public string Mapper { get; set; }
public string BSRKey { get; set; }
public string CoverImage { get; set; }
public int Duration { get; set; }
public string MapType { get; set; }
public string Difficulty { get; set; }
public string CustomDifficultyLabel { get; set; }
public int BPM { get; set; }
public float NJS { get; set; }
public ModifierObject Modifiers { get; set; }
public float ModifiersMultiplier { get; set; }
public bool PracticeMode { get; set; }
public Practicemodemodifiers PracticeModeModifiers { get; set; }
public float PP { get; set; }
public float Star { get; set; }
public bool IsMultiplayer { get; set; }
public int PreviousRecord { get; set; }
public string PreviousBSR { get; set; }
public long UnixTimestamp { get; set; }

public class ModifierObject
{
public bool NoFailOn0Energy { get; set; }
public bool OneLife { get; set; }
public bool FourLives { get; set; }
public bool NoBombs { get; set; }
public bool NoWalls { get; set; }
public bool NoArrows { get; set; }
public bool GhostNotes { get; set; }
public bool DisappearingArrows { get; set; }
public bool SmallNotes { get; set; }
public bool ProMode { get; set; }
public bool StrictAngles { get; set; }
public bool ZenMode { get; set; }
public bool SlowerSong { get; set; }
public bool FasterSong { get; set; }
public bool SuperFastSong { get; set; }
}

public class Practicemodemodifiers
{
public float SongSpeedMul { get; set; }
public bool StartInAdvanceAndClearNotes { get; set; }
public float SongStartTime { get; set; }
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BeatRecorder.Entities;
namespace BeatRecorder.Entities.Legacy;

public class DataPullerData
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BeatRecorder.Entities;
namespace BeatRecorder.Entities.Legacy;

public class DataPullerMain
{
Expand Down
45 changes: 44 additions & 1 deletion BeatRecorder/Entities/BeatSaber/SharedStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,54 @@ public SharedStatus(DataPullerMain main, DataPullerData data, int MaxCombo, Base
GameVersion = main?.GameVersion,
};

if (!baseBeatSaberHandler.ImageCache.ContainsKey(main?.CoverImage ?? "https://raw.githubusercontent.com/TheXorog/BeatRecorder/main/BeatRecorder/Assets/BeatSaberIcon.jpg"))
baseBeatSaberHandler.ImageCache.TryAdd(main?.CoverImage ?? "https://raw.githubusercontent.com/TheXorog/BeatRecorder/main/BeatRecorder/Assets/BeatSaberIcon.jpg", Bitmap.FromStream(new HttpClient().GetStreamAsync(main?.CoverImage ?? "https://raw.githubusercontent.com/TheXorog/BeatRecorder/main/BeatRecorder/Assets/BeatSaberIcon.jpg").Result));

Bitmap image = (Bitmap)baseBeatSaberHandler.ImageCache[main?.CoverImage ?? "https://raw.githubusercontent.com/TheXorog/BeatRecorder/main/BeatRecorder/Assets/BeatSaberIcon.jpg"];

BeatmapInfo = new()
{
Name = main?.SongName,
SubName = main?.SongSubName,
Author = main?.SongAuthor,
Creator = main?.Mapper,
Cover = (Bitmap)image,
IdOrHash = main?.Hash,
Bpm = main?.BPM,
NoteJumpSpeed = main?.NJS,
Difficulty = main?.Difficulty,
CustomDifficulty = main?.CustomDifficultyLabel
};

PerformanceInfo = new()
{
RawScore = data?.Score,
Score = data?.ScoreWithMultipliers,
Accuracy = (double)Math.Round(data?.Accuracy ?? 0, 2),
Rank = data?.Rank,
MissedNoteCount = data?.Misses,
Failed = main?.LevelFailed,
Finished = main?.LevelFinished,
MaxCombo = MaxCombo,
Combo = data?.Combo,
SoftFailed = ((main?.LevelFailed ?? false) || (data?.PlayerHealth ?? 0) <= 0) && (main?.Modifiers.NoFailOn0Energy ?? false)
};
}

public SharedStatus(Entities.Legacy.DataPullerMain main, Entities.Legacy.DataPullerData data, int MaxCombo, BaseBeatSaberHandler baseBeatSaberHandler)
{
GameInfo = new()
{
ModUsed = Mod.Datapuller,
ModVersion = main?.PluginVersion,
GameVersion = main?.GameVersion,
};

if (!baseBeatSaberHandler.ImageCache.ContainsKey(main?.coverImage ?? "https://raw.githubusercontent.com/TheXorog/BeatRecorder/main/BeatRecorder/Assets/BeatSaberIcon.jpg"))
baseBeatSaberHandler.ImageCache.TryAdd(main?.coverImage ?? "https://raw.githubusercontent.com/TheXorog/BeatRecorder/main/BeatRecorder/Assets/BeatSaberIcon.jpg", Bitmap.FromStream(new HttpClient().GetStreamAsync(main?.coverImage ?? "https://raw.githubusercontent.com/TheXorog/BeatRecorder/main/BeatRecorder/Assets/BeatSaberIcon.jpg").Result));

Bitmap image = (Bitmap)baseBeatSaberHandler.ImageCache[main?.coverImage ?? "https://raw.githubusercontent.com/TheXorog/BeatRecorder/main/BeatRecorder/Assets/BeatSaberIcon.jpg"];

BeatmapInfo = new()
{
Name = main?.SongName,
Expand Down
7 changes: 6 additions & 1 deletion BeatRecorder/Entities/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ internal class Config
/// </summary>
public string BeatSaberPort { get; set; } = "6557";

/// <summary>
/// Whether to use the legacy handler of the selected mod, if supported.
/// Currently supports: DataPuller.
/// </summary>
public bool BeatSaberUseLegacyIfAvailable { get; set; } = false;

/// <summary>
/// The websocket server to connect to for obs
/// </summary>
Expand Down Expand Up @@ -139,7 +145,6 @@ internal class Config
/// </summary>
public string OBSPauseScene { get; set; } = "";



/// <summary>
/// Migration value for deserializering
Expand Down
7 changes: 5 additions & 2 deletions BeatRecorder/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace BeatRecorder;

public class Program
{
public static string Version = "2.0.1";
public static string Version = "2.1.0";

public bool RunningPrerelease = false;

Expand Down Expand Up @@ -208,7 +208,10 @@ async Task<bool> UseModernSocket()
}
case "datapuller":
{
BeatSaberClient = new DataPullerHandler().Initialize(this); // 2946
if (LoadedConfig.BeatSaberUseLegacyIfAvailable)
BeatSaberClient = new DataPullerLegacyHandler().Initialize(this); // 2946
else
BeatSaberClient = new DataPullerHandler().Initialize(this);
break;
}
case "beatsaberplus":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private void DataMessageRecieved(string text)
return;
}

if (InLevel && (CurrentData?.unixTimestamp ?? 0) < _status.unixTimestamp)
if (InLevel && (CurrentData?.UnixTimestamp ?? 0) < _status.UnixTimestamp)
CurrentData = _status;

if (CurrentMaxCombo < _status.Combo)
Expand Down
Loading

0 comments on commit c6ce772

Please sign in to comment.