11using System ;
22using System . Reflection ;
33using AquaMai . Config . Attributes ;
4+ using AquaMai . Core . Attributes ;
5+ using AquaMai . Core . Helpers ;
6+ using DB ;
47using HarmonyLib ;
58using MAI2 . Util ;
69using Manager ;
710using Manager . UserDatas ;
811using MelonLoader ;
12+ using Monitor ;
913using Process ;
1014using UnityEngine ;
1115
@@ -18,8 +22,10 @@ namespace AquaMai.Mods.UX;
1822// 收编自 https://github.com/Starrah/DontRuinMyAccount/blob/master/Core.cs
1923public class DontRuinMyAccount
2024{
25+ [ ConfigEntry ( zh : "AutoPlay 激活后显示提示" , en : "Show notice when AutoPlay is activated" ) ]
26+ public static readonly bool showNotice = true ;
2127 private static uint currentTrackNumber => GameManager . MusicTrackNumber ;
22- private static bool ignoreScore ;
28+ public static bool ignoreScore ;
2329 private static UserScore oldScore ;
2430
2531 [ HarmonyPatch ( typeof ( GameProcess ) , "OnUpdate" ) ]
@@ -33,6 +39,14 @@ public static void OnUpdate()
3339 }
3440 }
3541
42+ [ HarmonyPatch ( typeof ( GameProcess ) , "OnStart" ) ]
43+ [ HarmonyPostfix ]
44+ [ EnableIf ( nameof ( showNotice ) ) ]
45+ public static void OnStart ( GameMonitor [ ] ____monitors )
46+ {
47+ ____monitors [ 0 ] . gameObject . AddComponent < NoticeUI > ( ) ;
48+ }
49+
3650 [ HarmonyPrefix ]
3751 [ HarmonyPatch ( typeof ( UserData ) , "UpdateScore" ) ]
3852 public static bool BeforeUpdateScore ( int musicid , int difficulty , uint achive , uint romVersion )
@@ -78,10 +92,10 @@ public static void AfterResultProcessStart()
7892 // current music playlog
7993 var score = Singleton < GamePlayManager > . Instance . GetGameScore ( 0 , ( int ) currentTrackNumber - 1 ) ;
8094 // score.Achivement = 0; // Private setter, so reflection is essential
81- typeof ( GameScoreList ) . GetProperty ( "Achivement" , BindingFlags . Public | BindingFlags . Instance ) ? . GetSetMethod ( true ) ? . Invoke ( score , new object [ ]
82- {
83- new Decimal ( 0 )
84- } ) ;
95+ typeof ( GameScoreList ) . GetProperty ( "Achivement" , BindingFlags . Public | BindingFlags . Instance ) ? . GetSetMethod ( true ) ? . Invoke ( score , [ 0m ] ) ;
96+ typeof ( GameScoreList ) . GetProperty ( "ComboType" , BindingFlags . Public | BindingFlags . Instance ) ? . GetSetMethod ( true ) ? . Invoke ( score , [ PlayComboflagID . None ] ) ;
97+ typeof ( GameScoreList ) . GetProperty ( "NowComboType" , BindingFlags . Public | BindingFlags . Instance ) ? . GetSetMethod ( true ) ? . Invoke ( score , [ PlayComboflagID . None ] ) ;
98+ score . SyncType = PlaySyncflagID . None ;
8599 // user's all scores
86100 var userData = Singleton < UserDataManager > . Instance . GetUserData ( 0 ) ;
87101 var userScoreDict = userData . ScoreDic [ difficulty ] ;
@@ -96,4 +110,23 @@ public static void AfterResultProcessStart()
96110 MelonLogger . Msg ( "[DontRuinMyAccount] Reset scores: trackNo {0}, music {1}:{2}, set current music playlog to 0.0000%, and userScoreDict[{1}:{2}] to {3}" , currentTrackNumber ,
97111 musicid , difficulty , oldScore ? . achivement ) ;
98112 }
113+
114+ private class NoticeUI : MonoBehaviour
115+ {
116+ public void OnGUI ( )
117+ {
118+ if ( ! ignoreScore ) return ;
119+ var y = Screen . height * .075f ;
120+ var width = GuiSizes . FontSize * 20f ;
121+ var x = GuiSizes . PlayerCenter + GuiSizes . PlayerWidth / 2f - width ;
122+ var rect = new Rect ( x , y , width , GuiSizes . LabelHeight * 2.5f ) ;
123+
124+ var labelStyle = GUI . skin . GetStyle ( "label" ) ;
125+ labelStyle . fontSize = ( int ) ( GuiSizes . FontSize * 1.2 ) ;
126+ labelStyle . alignment = TextAnchor . MiddleCenter ;
127+
128+ GUI . Box ( rect , "" ) ;
129+ GUI . Label ( rect , "AutoPlay" ) ;
130+ }
131+ }
99132}
0 commit comments