Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get BlockHitScore, Score, MaxScore #16

Merged
merged 1 commit into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/Client/MapEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Reflection;
using System.Threading.Tasks;
using UnityEngine;
using System.Timers;
using System.IO;
using SongDetailsCache;
using SongDetailsCache.Structs;
Expand All @@ -14,6 +13,8 @@
using TMPro;
using IPA.Utilities;
using DataPuller.Controllers;
using System.Threading;
using System.Timers;

namespace DataPuller.Client
{
Expand All @@ -23,7 +24,7 @@ class MapEvents : IInitializable, IDisposable
private static BeatSaver beatSaver = new BeatSaver("BSDataPuller", Assembly.GetExecutingAssembly().GetName().Version);
private static SongDetails songDetailsCache = null;
internal static MapData.JsonData previousStaticData = new MapData.JsonData();
private Timer timer = new Timer { Interval = 250 };
private System.Timers.Timer timer = new System.Timers.Timer { Interval = 250 };
private int NoteCount = 0;

//Required objects - Made [InjectOptional] and checked at Initialize()
Expand Down Expand Up @@ -60,7 +61,7 @@ public void Initialize()

multiplayerController.stateChangedEvent += MultiplayerController_stateChangedEvent;
scoreController.scoreDidChangeEvent += ScoreDidChangeEvent;
scoreController.immediateMaxPossibleScoreDidChangeEvent += ImmediateMaxPossibleScoreDidChangeEvent;
//scoreController.immediateMaxPossibleScoreDidChangeEvent += ImmediateMaxPossibleScoreDidChangeEvent;

MapData.IsMultiplayer = true;
}
Expand All @@ -80,7 +81,7 @@ public void Initialize()

//In replay mode the scorecontroller does not work so 'RelativeScoreOrImmediateRankDidChangeEvent' will read from the UI
scoreController.scoreDidChangeEvent += ScoreDidChangeEvent;
scoreController.immediateMaxPossibleScoreDidChangeEvent += ImmediateMaxPossibleScoreDidChangeEvent;
//scoreController.immediateMaxPossibleScoreDidChangeEvent += ImmediateMaxPossibleScoreDidChangeEvent;

pauseController.didPauseEvent += LevelPausedEvent;
pauseController.didResumeEvent += LevelUnpausedEvent;
Expand Down Expand Up @@ -139,7 +140,7 @@ public void Dispose()
if (scoreController is ScoreController && multiplayerController is MultiplayerController) //In a multiplayer lobby
{
scoreController.scoreDidChangeEvent -= ScoreDidChangeEvent;
scoreController.immediateMaxPossibleScoreDidChangeEvent -= ImmediateMaxPossibleScoreDidChangeEvent;
//scoreController.immediateMaxPossibleScoreDidChangeEvent -= ImmediateMaxPossibleScoreDidChangeEvent;

multiplayerController.stateChangedEvent -= MultiplayerController_stateChangedEvent;
}
Expand All @@ -150,7 +151,7 @@ public void Dispose()
else if (scoreController is ScoreController && pauseController is PauseController && standardLevelGameplayManager is StandardLevelGameplayManager) //Singleplayer/New replay.
{
scoreController.scoreDidChangeEvent -= ScoreDidChangeEvent; //In replay mode this does not fire so 'RelativeScoreOrImmediateRankDidChangeEvent' will read from the UI
scoreController.immediateMaxPossibleScoreDidChangeEvent -= ImmediateMaxPossibleScoreDidChangeEvent;
//scoreController.immediateMaxPossibleScoreDidChangeEvent -= ImmediateMaxPossibleScoreDidChangeEvent;

pauseController.didPauseEvent -= LevelPausedEvent;
pauseController.didResumeEvent -= LevelUnpausedEvent;
Expand Down Expand Up @@ -368,7 +369,7 @@ private void RelativeScoreOrImmediateRankDidChangeEvent() //For replay mode
TextMeshProUGUI textMeshProUGUI = scoreUIController.GetField<TextMeshProUGUI, ScoreUIController>("_scoreText");
LiveData.Score = int.Parse(textMeshProUGUI.text.Replace(" ", ""));
LiveData.ScoreWithMultipliers = ScoreModel.GetModifiedScoreForGameplayModifiersScoreMultiplier(LiveData.Score, MapData.ModifiersMultiplier);
LiveData.MaxScore = ScoreModel.MaxRawScoreForNumberOfNotes(NoteCount);
//LiveData.MaxScore = ScoreModel.MaxRawScoreForNumberOfNotes(NoteCount);
LiveData.MaxScoreWithMultipliers = ScoreModel.GetModifiedScoreForGameplayModifiersScoreMultiplier(LiveData.MaxScore, MapData.ModifiersMultiplier);
SetRankAndAccuracy();
}
Expand Down Expand Up @@ -401,7 +402,7 @@ private void NoteWasCutEvent(NoteController arg1, in NoteCutInfo _noteCutInfo)
LiveData.ColorType = arg1.noteData.colorType;
LiveData.Combo++;
NoteCount++;
_noteCutInfo.swingRatingCounter.RegisterDidFinishReceiver(new SwingRatingCounterDidFinishController(_noteCutInfo));
//_noteCutInfo.swingRatingCounter.RegisterDidFinishReceiver(new SwingRatingCounterDidFinishController(_noteCutInfo));
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions src/Controllers/SwingRatingCounterDidFinishController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public SwingRatingCounterDidFinishController(NoteCutInfo _noteCutInfo)

public void HandleSaberSwingRatingCounterDidFinish(ISaberSwingRatingCounter saberSwingRatingCounter)
{
ScoreModel.RawScoreWithoutMultiplier(saberSwingRatingCounter, noteCutInfo.cutDistanceToCenter, out int beforeCutRawScore, out int afterCutRawScore, out int cutDistanceRawScore);
LiveData.BlockHitScore = new int[] { beforeCutRawScore, afterCutRawScore, cutDistanceRawScore };
noteCutInfo.swingRatingCounter.UnregisterDidFinishReceiver(this);
//ScoreModel.RawScoreWithoutMultiplier(saberSwingRatingCounter, noteCutInfo.cutDistanceToCenter, out int beforeCutRawScore, out int afterCutRawScore, out int cutDistanceRawScore);
//LiveData.BlockHitScore = new int[] { beforeCutRawScore, afterCutRawScore, cutDistanceRawScore };
//noteCutInfo.swingRatingCounter.UnregisterDidFinishReceiver(this);
}
}
}
100 changes: 42 additions & 58 deletions src/DataPuller.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,105 +45,89 @@
<DisableZipRelease>True</DisableZipRelease>
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony, Version=2.0.2.0, Culture=neutral, processorArchitecture=MSIL">
<Reference Include="0Harmony">
<HintPath>$(BeatSaberDir)\Libs\0Harmony.dll</HintPath>
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
<HintPath>A:\Program Files (x86)\Steam\steamapps\common\Beat Saber\IPA\Libs\0Harmony.dll</HintPath>
</Reference>
<Reference Include="BeatmapCore, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" />
<Reference Include="BeatSaverSharp, Version=3.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<Reference Include="BeatmapCore">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\BeatmapCore.dll</HintPath>
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
<HintPath>A:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Libs\BeatSaverSharp.dll</HintPath>
</Reference>
<Reference Include="BSML">
<HintPath>A:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Plugins\BSML.dll</HintPath>
</Reference>
<Reference Include="GameplayCore, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" />
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<Reference Include="BeatSaverSharp">
<HintPath>$(BeatSaberDir)\Libs\BeatSaverSharp.dll</HintPath>
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="Main">
<HintPath>A:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\Main.dll</HintPath>
<Reference Include="GameplayCore">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\GameplayCore.dll</HintPath>
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="HMLib">
<HintPath>A:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\HMLib.dll</HintPath>
<Reference Include="IPA.Loader">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\IPA.Loader.dll</HintPath>
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="HMUI">
<HintPath>A:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\HMUI.dll</HintPath>
<Reference Include="Main">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Main.dll</HintPath>
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="IPA.Loader">
<HintPath>A:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\IPA.Loader.dll</HintPath>
<Reference Include="Newtonsoft.Json">
<HintPath>$(BeatSaberDir)\Libs\Newtonsoft.Json.dll</HintPath>
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="SiraUtil, Version=2.3.1.0, Culture=neutral, processorArchitecture=MSIL">
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="SiraUtil">
<HintPath>$(BeatSaberDir)\Plugins\SiraUtil.dll</HintPath>
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
<HintPath>A:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Plugins\SiraUtil.dll</HintPath>
</Reference>
<Reference Include="SongCore, Version=3.0.1.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>$(BeatSaberDir)\Plugins\SongCore.dll</HintPath>
</Reference>
<Reference Include="SongDetailsCache, Version=1.1.11.0, Culture=neutral, processorArchitecture=MSIL">
<Reference Include="SongDetailsCache">
<HintPath>$(BeatSaberDir)\Libs\SongDetailsCache.dll</HintPath>
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
<HintPath>A:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Libs\SongDetailsCache.dll</HintPath>
</Reference>
<Reference Include="System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL" />
<Reference Include="System" />
<Reference Include="Unity.TextMeshPro">
<HintPath>A:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\Unity.TextMeshPro.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine">
<HintPath>A:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.dll</HintPath>
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Unity.TextMeshPro.dll</HintPath>
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>A:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.JSONSerializeModule">
<HintPath>A:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.JSONSerializeModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.PhysicsModule">
<HintPath>A:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.PhysicsModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>A:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.UI.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.UIElementsModule">
<HintPath>A:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.UIElementsModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.UIModule">
<HintPath>A:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.UIModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.VRModule">
<HintPath>A:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.VRModule.dll</HintPath>
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="websocket-sharp, Version=1.0.2.1803, Culture=neutral, PublicKeyToken=5660b08a1845a91e, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>$(BeatSaberDir)\Libs\websocket-sharp.dll</HintPath>
</Reference>
<Reference Include="WindowsBase" />
<Reference Include="Zenject, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<Reference Include="Zenject">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Zenject.dll</HintPath>
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
<HintPath>A:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\Zenject.dll</HintPath>
</Reference>
<Reference Include="Zenject-usage, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<Reference Include="Zenject-usage">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Zenject-usage.dll</HintPath>
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
<HintPath>A:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\Zenject-usage.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Client\LiveData.cs" />
<Compile Include="Client\MapData.cs" />
<Compile Include="Controllers\SwingRatingCounterDidFinishController.cs" />
<Compile Include="HarmonyPatches.cs" />
<Compile Include="Installers\ClientInstaller.cs" />
<Compile Include="Server\Server.cs" />
<Compile Include="Client\MapEvents.cs" />
Expand Down
46 changes: 46 additions & 0 deletions src/HarmonyPatches.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using DataPuller.Client;
using HarmonyLib;

namespace DataPuller
{
[HarmonyPatch(typeof(BeatmapObjectExecutionRatingsRecorder), "HandleScoringForNoteDidFinish")]
internal class HandleScoringForNoteDidFinishPatch
{
static void Postfix(ScoringElement scoringElement)
{
//Plugin.Logger.Debug("in Postfix");

if (scoringElement != null)
{
/*NoteData noteData = scoringElement.noteData;
if (noteData.colorType == ColorType.None)
{
LiveData.FullCombo = false;
}*/

GoodCutScoringElement goodCutScoringElement;
if ((goodCutScoringElement = (scoringElement as GoodCutScoringElement)) != null)
{
LiveData.Combo++;
LiveData.BlockHitScore = new int[] {goodCutScoringElement.cutScoreBuffer.beforeCutScore, goodCutScoringElement.cutScoreBuffer.afterCutScore, goodCutScoringElement.cutScoreBuffer.centerDistanceCutScore};
LiveData.Score += goodCutScoringElement.cutScore * goodCutScoringElement.multiplier;
LiveData.MaxScore += goodCutScoringElement.maxPossibleCutScore * goodCutScoringElement.multiplier;

Plugin.Logger.Info("Postfix: " + LiveData.Combo + " " + LiveData.BlockHitScore[0] + "," + LiveData.BlockHitScore[1] + "," + LiveData.BlockHitScore[2] + " " + LiveData.Score + " " + LiveData.MaxScore);
}

/*if (scoringElement is BadCutScoringElement)
{
LiveData.Misses++;
LiveData.FullCombo = false;
}

if (scoringElement is MissScoringElement)
{
LiveData.Misses++;
LiveData.FullCombo = false;
}*/
}
}
}
}
36 changes: 36 additions & 0 deletions src/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using IPALogger = IPA.Logging.Logger;
using SiraUtil.Zenject;
using DataPuller.Installers;
using System;
using System.Reflection;

namespace DataPuller
{
Expand All @@ -13,6 +15,9 @@ public class Plugin

internal Server.Server webSocketServer;

public const string HarmonyId = "com.DataPuller";
internal static readonly HarmonyLib.Harmony harmony = new HarmonyLib.Harmony(HarmonyId);

[Init]
public void Init(IPALogger _logger, Zenjector zenjector)
{
Expand All @@ -32,13 +37,44 @@ public void Init(IPALogger _logger, Zenjector zenjector)
public void OnApplicationStart()
{
Logger.Debug("OnApplicationStart");
//ApplyHarmonyPatches();
}

[OnExit]
public void OnApplicationQuit()
{
webSocketServer?.Dispose();
RemoveHarmonyPatches();

Logger.Debug("OnApplicationQuit");
}

internal static void ApplyHarmonyPatches()
{
try
{
//Logger.Debug("Applying Harmony patches.");
harmony.PatchAll(Assembly.GetExecutingAssembly());
}
catch (Exception ex)
{
//Logger.Error("Error applying Harmony patches: " + ex.Message);
Logger.Debug(ex);
}
}


internal static void RemoveHarmonyPatches()
{
try
{
harmony.UnpatchSelf();
}
catch (Exception ex)
{
//Logger.Error("Error removing Harmony patches: " + ex.Message);
Logger.Debug(ex);
}
}
}
}