From 4cc40a01b4061d3adfdb392da2885aeba305f6b5 Mon Sep 17 00:00:00 2001 From: Zephyr <67527746+zeph-yr@users.noreply.github.com> Date: Tue, 22 Mar 2022 21:13:35 +0800 Subject: [PATCH] Get BlockHitScore, Score, MaxScore --- src/Client/MapEvents.cs | 17 +-- .../SwingRatingCounterDidFinishController.cs | 6 +- src/DataPuller.csproj | 100 ++++++++---------- src/HarmonyPatches.cs | 46 ++++++++ src/Plugin.cs | 36 +++++++ 5 files changed, 136 insertions(+), 69 deletions(-) create mode 100644 src/HarmonyPatches.cs diff --git a/src/Client/MapEvents.cs b/src/Client/MapEvents.cs index 289a67b..8ef6242 100644 --- a/src/Client/MapEvents.cs +++ b/src/Client/MapEvents.cs @@ -4,7 +4,6 @@ using System.Reflection; using System.Threading.Tasks; using UnityEngine; -using System.Timers; using System.IO; using SongDetailsCache; using SongDetailsCache.Structs; @@ -14,6 +13,8 @@ using TMPro; using IPA.Utilities; using DataPuller.Controllers; +using System.Threading; +using System.Timers; namespace DataPuller.Client { @@ -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() @@ -60,7 +61,7 @@ public void Initialize() multiplayerController.stateChangedEvent += MultiplayerController_stateChangedEvent; scoreController.scoreDidChangeEvent += ScoreDidChangeEvent; - scoreController.immediateMaxPossibleScoreDidChangeEvent += ImmediateMaxPossibleScoreDidChangeEvent; + //scoreController.immediateMaxPossibleScoreDidChangeEvent += ImmediateMaxPossibleScoreDidChangeEvent; MapData.IsMultiplayer = true; } @@ -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; @@ -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; } @@ -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; @@ -368,7 +369,7 @@ private void RelativeScoreOrImmediateRankDidChangeEvent() //For replay mode TextMeshProUGUI textMeshProUGUI = scoreUIController.GetField("_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(); } @@ -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 { diff --git a/src/Controllers/SwingRatingCounterDidFinishController.cs b/src/Controllers/SwingRatingCounterDidFinishController.cs index 5ea1313..672ee29 100644 --- a/src/Controllers/SwingRatingCounterDidFinishController.cs +++ b/src/Controllers/SwingRatingCounterDidFinishController.cs @@ -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); } } } diff --git a/src/DataPuller.csproj b/src/DataPuller.csproj index f54c4e9..5895612 100644 --- a/src/DataPuller.csproj +++ b/src/DataPuller.csproj @@ -45,105 +45,89 @@ True - + + $(BeatSaberDir)\Libs\0Harmony.dll + False False - A:\Program Files (x86)\Steam\steamapps\common\Beat Saber\IPA\Libs\0Harmony.dll - - + + $(BeatSaberDir)\Beat Saber_Data\Managed\BeatmapCore.dll + False False - A:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Libs\BeatSaverSharp.dll - - - A:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Plugins\BSML.dll - - - packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll + + $(BeatSaberDir)\Libs\BeatSaverSharp.dll + False + False - - - - A:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\Main.dll + + $(BeatSaberDir)\Beat Saber_Data\Managed\GameplayCore.dll False + False - - A:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\HMLib.dll + + $(BeatSaberDir)\Beat Saber_Data\Managed\IPA.Loader.dll False + False - - A:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\HMUI.dll + + $(BeatSaberDir)\Beat Saber_Data\Managed\Main.dll False + False - - A:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\IPA.Loader.dll + + $(BeatSaberDir)\Libs\Newtonsoft.Json.dll False + False - + + + + $(BeatSaberDir)\Plugins\SiraUtil.dll + False False - A:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Plugins\SiraUtil.dll False $(BeatSaberDir)\Plugins\SongCore.dll - + + $(BeatSaberDir)\Libs\SongDetailsCache.dll + False False - A:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Libs\SongDetailsCache.dll - + - A:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\Unity.TextMeshPro.dll - False - - - A:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.dll + $(BeatSaberDir)\Beat Saber_Data\Managed\Unity.TextMeshPro.dll False + False - A:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.CoreModule.dll - False - - - A:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.JSONSerializeModule.dll - - - A:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.PhysicsModule.dll - - - A:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.UI.dll - False - - - A:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.UIElementsModule.dll - False - - - A:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.UIModule.dll - False - - - A:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.VRModule.dll + $(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.CoreModule.dll False + False False $(BeatSaberDir)\Libs\websocket-sharp.dll - + + $(BeatSaberDir)\Beat Saber_Data\Managed\Zenject.dll + False False - A:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\Zenject.dll - + + $(BeatSaberDir)\Beat Saber_Data\Managed\Zenject-usage.dll + False False - A:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\Zenject-usage.dll + diff --git a/src/HarmonyPatches.cs b/src/HarmonyPatches.cs new file mode 100644 index 0000000..ce3c9d5 --- /dev/null +++ b/src/HarmonyPatches.cs @@ -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; + }*/ + } + } + } +} diff --git a/src/Plugin.cs b/src/Plugin.cs index d23273c..833e18c 100644 --- a/src/Plugin.cs +++ b/src/Plugin.cs @@ -2,6 +2,8 @@ using IPALogger = IPA.Logging.Logger; using SiraUtil.Zenject; using DataPuller.Installers; +using System; +using System.Reflection; namespace DataPuller { @@ -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) { @@ -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); + } + } } }