From b54b8676c1e9af035774cc34b017f4b157bfce7d Mon Sep 17 00:00:00 2001 From: akanyan Date: Sun, 7 Jul 2024 23:47:46 +0900 Subject: [PATCH] feat(NaiveRating): make it togglable --- Mu3Mods.csproj | 2 +- NaiveRating/MU3.Data/patch_GameData.cs | 6 ++- .../patch_Scene_32_PrePlayMusic_Confirm.cs | 10 ++++ NaiveRating/MU3.User/patch_UserManager.cs | 11 ----- NaiveRating/MU3.User/patch_UserUtil.cs | 7 ++- NaiveRating/MU3/patch_ANM_CMN_User.cs | 11 +++++ NaiveRating/MU3/patch_ANM_SWH_Profile.cs | 16 ++++--- NaiveRating/MU3/patch_MU3UICounter.cs | 18 +++++++ .../MU3/patch_OptionSelecterController.cs | 23 +++++++++ .../MU3/patch_Scene_37_Result_Score.cs | 22 --------- NaiveRating/MU3/patch_UIResultBattlePoint.cs | 47 +++++++++++++++++++ NaiveRating/MU3/patch_UserOption.cs | 36 ++++++++++++++ NaiveRating/{MU3 => }/NaiveRating.cs | 10 ++-- 13 files changed, 174 insertions(+), 45 deletions(-) create mode 100644 NaiveRating/MU3.User/patch_Scene_32_PrePlayMusic_Confirm.cs delete mode 100644 NaiveRating/MU3.User/patch_UserManager.cs create mode 100644 NaiveRating/MU3/patch_ANM_CMN_User.cs create mode 100644 NaiveRating/MU3/patch_MU3UICounter.cs create mode 100644 NaiveRating/MU3/patch_OptionSelecterController.cs delete mode 100644 NaiveRating/MU3/patch_Scene_37_Result_Score.cs create mode 100644 NaiveRating/MU3/patch_UIResultBattlePoint.cs create mode 100644 NaiveRating/MU3/patch_UserOption.cs rename NaiveRating/{MU3 => }/NaiveRating.cs (82%) diff --git a/Mu3Mods.csproj b/Mu3Mods.csproj index d51658b..65d3fd0 100644 --- a/Mu3Mods.csproj +++ b/Mu3Mods.csproj @@ -2,7 +2,7 @@ net35 7EVENDAYS⇔HOLIDAYS - 1.8.1 + 1.9.0 true latest x64 diff --git a/NaiveRating/MU3.Data/patch_GameData.cs b/NaiveRating/MU3.Data/patch_GameData.cs index 312e15f..cb159f0 100644 --- a/NaiveRating/MU3.Data/patch_GameData.cs +++ b/NaiveRating/MU3.Data/patch_GameData.cs @@ -5,6 +5,10 @@ namespace MU3.Data; class patch_GameData: GameData { public extern static RatingColorID orig_getRatingColorIDFromRating100(int rating100); public static new RatingColorID getRatingColorIDFromRating100(int rating100) { - return orig_getRatingColorIDFromRating100(NaiveRating.Get()); + if(NaiveRating.IsEnabled()) { + return orig_getRatingColorIDFromRating100(NaiveRating.Get()); + } else { + return orig_getRatingColorIDFromRating100(rating100); + } } } \ No newline at end of file diff --git a/NaiveRating/MU3.User/patch_Scene_32_PrePlayMusic_Confirm.cs b/NaiveRating/MU3.User/patch_Scene_32_PrePlayMusic_Confirm.cs new file mode 100644 index 0000000..059a84d --- /dev/null +++ b/NaiveRating/MU3.User/patch_Scene_32_PrePlayMusic_Confirm.cs @@ -0,0 +1,10 @@ +namespace MU3; + +// It doesn't have to be PrePlayMusic_Confirm, but it prev rating has to be stored at some point +class patch_Scene_32_PrePlayMusic_Confirm: Scene_32_PrePlayMusic_Confirm { + private extern void orig_Enter_Select(); + private void Enter_Select() { + NaiveRating.SavePrev(); + orig_Enter_Select(); + } +} \ No newline at end of file diff --git a/NaiveRating/MU3.User/patch_UserManager.cs b/NaiveRating/MU3.User/patch_UserManager.cs deleted file mode 100644 index db80a0a..0000000 --- a/NaiveRating/MU3.User/patch_UserManager.cs +++ /dev/null @@ -1,11 +0,0 @@ -using MU3.Game; - -namespace MU3.User; - -class patch_UserManager: UserManager { - public extern void orig_updateUserRating(SessionInfo sessionInfo, SessionResult result); - public new void updateUserRating(SessionInfo sessionInfo, SessionResult result) { - NaiveRating.PrevRating = NaiveRating.Get(); - orig_updateUserRating(sessionInfo, result); - } -} \ No newline at end of file diff --git a/NaiveRating/MU3.User/patch_UserUtil.cs b/NaiveRating/MU3.User/patch_UserUtil.cs index 765dc82..be89be2 100644 --- a/NaiveRating/MU3.User/patch_UserUtil.cs +++ b/NaiveRating/MU3.User/patch_UserUtil.cs @@ -4,7 +4,12 @@ namespace MU3.User; [MonoModPatch("global::MU3.User.UserUtil")] public static class patch_UserUtil { + public extern static float orig_toRatingFloat(int rating); public static float toRatingFloat(int rating) { - return NaiveRating.Get() * 0.01f + 1E-05f; + if(NaiveRating.IsEnabled()) { + return orig_toRatingFloat(NaiveRating.Get()); + } else { + return orig_toRatingFloat(rating); + } } } \ No newline at end of file diff --git a/NaiveRating/MU3/patch_ANM_CMN_User.cs b/NaiveRating/MU3/patch_ANM_CMN_User.cs new file mode 100644 index 0000000..f3099c8 --- /dev/null +++ b/NaiveRating/MU3/patch_ANM_CMN_User.cs @@ -0,0 +1,11 @@ +using MU3.CustomUI; + +namespace MU3.SceneObject; +class patch_ANM_CMN_UserDeta_01: ANM_CMN_UserDeta_01 { + private MU3UICounter rating; + public extern void orig_setUserDetail(); + public new void setUserDetail() { + ((patch_MU3UICounter)rating).isDispSuffix = NaiveRating.IsEnabled(); + orig_setUserDetail(); + } +} diff --git a/NaiveRating/MU3/patch_ANM_SWH_Profile.cs b/NaiveRating/MU3/patch_ANM_SWH_Profile.cs index b3d596c..caf8364 100644 --- a/NaiveRating/MU3/patch_ANM_SWH_Profile.cs +++ b/NaiveRating/MU3/patch_ANM_SWH_Profile.cs @@ -9,11 +9,15 @@ class patch_ANM_SWH_Profile: ANM_SWH_Profile { // Fixes login display public new void setUpLogin() { UserManager instance = Singleton.instance; - var prev = instance.userPreview; - var temp = prev; - temp.dispRating = 0; - instance.userPreview = temp; - orig_setUpLogin(); - instance.userPreview = prev; + var up = instance.userPreview; + if(NaiveRating.IsEnabled()) { + up.dispRating = 0; + instance.userPreview = up; + orig_setUpLogin(); + up.dispRating = 2; + instance.userPreview = up; + } else { + orig_setUpLogin(); + } } } \ No newline at end of file diff --git a/NaiveRating/MU3/patch_MU3UICounter.cs b/NaiveRating/MU3/patch_MU3UICounter.cs new file mode 100644 index 0000000..71534e0 --- /dev/null +++ b/NaiveRating/MU3/patch_MU3UICounter.cs @@ -0,0 +1,18 @@ +namespace MU3.CustomUI; +class patch_MU3UICounter: MU3UICounter { + protected extern void orig_calcNumFiguresFloat(double value); + protected new void calcNumFiguresFloat(double value) { + orig_calcNumFiguresFloat(value); + if(isDispSuffix) { + pushFigureFront(10); + } + } + public bool isDispSuffix { get; set; } + protected void pushFigureFront(byte c) { + for(int i = numFigures_; i > 0; --i) { + figures_[i] = figures_[i - 1]; + } + figures_[0] = c; + numFigures_ += 1; + } +} diff --git a/NaiveRating/MU3/patch_OptionSelecterController.cs b/NaiveRating/MU3/patch_OptionSelecterController.cs new file mode 100644 index 0000000..ffa0615 --- /dev/null +++ b/NaiveRating/MU3/patch_OptionSelecterController.cs @@ -0,0 +1,23 @@ +using MU3.CustomUI; +using MU3.User; +using MU3.Util; + +namespace MU3; +class patch_OptionSelecterController: OptionSelecterController { + private chengeParamFuncArray[] cpFuncArray = new chengeParamFuncArray[35]; + public extern void orig_init(UserOption.OptionName id); + private extern void orig_chengeParamOther(int currentParam); + public new void init(UserOption.OptionName id) { + orig_init(id); + cpFuncArray[33].max = 2; + } + private void chengeParamOther(int currentParam) { + if(myOptionId == UserOption.OptionName.Rating) { + transform.Find("NUL_SWH_Option_00/NUL_Select/PAT_OnOff").GetComponent().patternNumber = currentParam != 0 ? 0f : 1f; + Singleton.instance.userOption.customSet.Rating = (UserOption.eRating)currentParam; + SingletonMonoBehaviour.instance.userData.setUserDetail(); + } else { + orig_chengeParamOther(currentParam); + } + } +} diff --git a/NaiveRating/MU3/patch_Scene_37_Result_Score.cs b/NaiveRating/MU3/patch_Scene_37_Result_Score.cs deleted file mode 100644 index 663c96b..0000000 --- a/NaiveRating/MU3/patch_Scene_37_Result_Score.cs +++ /dev/null @@ -1,22 +0,0 @@ -using MU3.Sequence; - -namespace MU3; - -class patch_Scene_37_Result_Score: Scene_37_Result_Score { - private PlayInfo playInfo_; - private extern void orig_TechRating_Init(); - - // Fixes rating+/rating- display - private void TechRating_Init() { - var origRating = playInfo_.sessionResult.rating_; - var origPrevRating = playInfo_.sessionResult.prevRating_; - - playInfo_.sessionResult.rating_ = NaiveRating.Get(); - playInfo_.sessionResult.prevRating_ = NaiveRating.PrevRating; - - orig_TechRating_Init(); - - playInfo_.sessionResult.rating_ = origRating; - playInfo_.sessionResult.prevRating_ = origPrevRating; - } -} \ No newline at end of file diff --git a/NaiveRating/MU3/patch_UIResultBattlePoint.cs b/NaiveRating/MU3/patch_UIResultBattlePoint.cs new file mode 100644 index 0000000..db9df6b --- /dev/null +++ b/NaiveRating/MU3/patch_UIResultBattlePoint.cs @@ -0,0 +1,47 @@ +using MU3.CustomUI; +using MU3.Sequence; +using MU3.User; +using UnityEngine; + +namespace MU3; +class patch_UIResultBattlePoint: UIResultBattlePoint { + private Animator animator_; + private MU3UICounter counterScore_; + private MU3UIImageChanger imageHeader_; + private MU3UICounter counterScorePlus_; + private MU3UICounter counterScoreMinus_; + private GameObject hideScore_; + + private extern void orig_disable(MU3UICounter counter); + private void disable(MU3UICounter counter) => orig_disable(counter); + public extern void orig_initTechRating(PlayInfo playInfo); + public new void initTechRating(PlayInfo playInfo) { + ((patch_MU3UICounter)counterScore_).isDispSuffix = NaiveRating.IsEnabled(); + if(!NaiveRating.IsEnabled()) { + orig_initTechRating(playInfo); + return; + } + int prevRating = NaiveRating.PrevRating; + int rating1 = NaiveRating.Get(); + if((bool)hideScore_) { + hideScore_.SetActive(false); + } + counterScore_.Counter = (double)UserUtil.toRatingFloat(rating1); + int ratingPatternNo = UserUtil.toRatingPatternNo(rating1); + counterScore_.SpriteIndex = ratingPatternNo; + imageHeader_.patternNumber = (float)ratingPatternNo; + int rating2 = rating1 - prevRating; + if(rating2 == 0) { + disable(counterScorePlus_); + disable(counterScoreMinus_); + animator_.SetInteger(MU3.Sys.Const.AnimatorID_State, 2); + } else if(0 < rating2) { + disable(counterScoreMinus_); + if((bool)counterScorePlus_) { + counterScorePlus_.Counter = rating2 * 0.01f + 1E-05f; + } + animator_.SetInteger(MU3.Sys.Const.AnimatorID_State, 0); + } + animator_.SetTrigger(MU3.Sys.Const.AnimatorID_In); + } +} diff --git a/NaiveRating/MU3/patch_UserOption.cs b/NaiveRating/MU3/patch_UserOption.cs new file mode 100644 index 0000000..ae2dc7f --- /dev/null +++ b/NaiveRating/MU3/patch_UserOption.cs @@ -0,0 +1,36 @@ +using MonoMod; + +namespace MU3.User; + +class patch_UserOption: UserOption { + [MonoModEnumReplace] + public enum patch_eRating { + OFF = 0, + Default = 1, + ON = 1, + Naive = 2, + MAX = 2 + } + class patch_DataSet: DataSet { + private patch_eRating rating = patch_eRating.ON; + public extern bool orig_isMax(OptionName id); + public new bool isMax(OptionName id) { + if(id == OptionName.Rating) { + return rating == patch_eRating.MAX; + } + return orig_isMax(id); + } + public new patch_eRating Rating { + get => rating; + set { + if(patch_eRating.MAX < value) { + rating = patch_eRating.MAX; + } else if(value < patch_eRating.OFF) { + rating = patch_eRating.OFF; + } else { + rating = value; + } + } + } + } +} \ No newline at end of file diff --git a/NaiveRating/MU3/NaiveRating.cs b/NaiveRating/NaiveRating.cs similarity index 82% rename from NaiveRating/MU3/NaiveRating.cs rename to NaiveRating/NaiveRating.cs index bc3b5dd..f09b94b 100644 --- a/NaiveRating/MU3/NaiveRating.cs +++ b/NaiveRating/NaiveRating.cs @@ -5,10 +5,8 @@ using MU3.Util; using System.Collections.Generic; using System.Linq; -namespace MU3; - public static class NaiveRating { - public static int PrevRating { get; set; } + public static int PrevRating { get; private set; } // Adapted from MU3.User.UserRating.calcBest() private static RatingList calcSane() { @@ -48,4 +46,10 @@ public static class NaiveRating { } return res / 45; } + public static bool IsEnabled() { + return Singleton.instance.userOption.customSet.Rating == (UserOption.eRating)patch_UserOption.patch_eRating.Naive; + } + public static void SavePrev() { + PrevRating = Get(); + } } \ No newline at end of file