11using BepInEx ;
22using BepInEx . Configuration ;
3+ using HarmonyLib ;
34using System . Linq ;
45using UnityEngine ;
56
@@ -10,9 +11,15 @@ public class Main : BaseUnityPlugin
1011 {
1112 public const string GUID = "de.benediktwerner.desperados3.progressrestorer" ;
1213 public const string Name = "ProgressRestorer" ;
13- public const string Version = "1.0 .0" ;
14+ public const string Version = "1.1 .0" ;
1415
16+ static bool showBadges = false ;
17+ static bool showAchievements = false ;
1518 static int ? selectedMission = null ;
19+ static string achievementIDString = "" ;
20+ static int ? achievementID = null ;
21+ static string message = "" ;
22+ static int progress = 0 ;
1623
1724 void Awake ( )
1825 {
@@ -41,6 +48,42 @@ static void Draw(ConfigEntryBase entry)
4148 MiSingletonNoMono < SaveGameManager > . instance . saveSaveGameUser ( ) ;
4249 }
4350
51+ if ( GUILayout . Button ( "Badges" ) )
52+ {
53+ showBadges = ! showBadges ;
54+ showAchievements = false ;
55+ }
56+
57+ if ( showBadges )
58+ {
59+ GUILayout . BeginVertical ( "box" ) ;
60+ DrawBadges ( saveGameUser ) ;
61+ GUILayout . EndVertical ( ) ;
62+ }
63+
64+ if ( GUILayout . Button ( "Achievements" ) )
65+ {
66+ showAchievements = ! showAchievements ;
67+ showBadges = false ;
68+ }
69+
70+ if ( showAchievements )
71+ {
72+ GUILayout . BeginVertical ( "box" ) ;
73+ DrawAchievements ( ) ;
74+ GUILayout . EndVertical ( ) ;
75+ }
76+
77+ if ( ! string . IsNullOrWhiteSpace ( message ) )
78+ {
79+ GUILayout . Label ( message ) ;
80+ }
81+
82+ GUILayout . EndVertical ( ) ;
83+ }
84+
85+ static void DrawBadges ( SaveGameUser saveGameUser )
86+ {
4487 foreach ( var mission in saveGameUser . lSaveMissionData )
4588 {
4689 if ( mission . m_liBadgeData . Count == 0 ) continue ;
@@ -79,16 +122,96 @@ static void Draw(ConfigEntryBase entry)
79122 GUILayout . BeginHorizontal ( ) ;
80123 GUILayout . Label ( badge . badgeRef . lstrText . strText ) ;
81124 if ( badge . bCompleted ) GUILayout . Label ( "Completed" , GUILayout . Width ( 200 ) ) ;
82- else if ( GUILayout . Button ( "Complete" , GUILayout . Width ( 200 ) ) ) {
125+ else if ( GUILayout . Button ( "Complete" , GUILayout . Width ( 200 ) ) )
126+ {
83127 badge . setComplete ( 0 ) ;
84128 MiSingletonNoMono < SaveGameManager > . instance . saveSaveGameUser ( ) ;
85129 }
86130 GUILayout . EndHorizontal ( ) ;
87131 }
88132 GUILayout . EndVertical ( ) ;
89133 }
134+ }
90135
91- GUILayout . EndVertical ( ) ;
136+ static void DrawAchievements ( )
137+ {
138+ var service = PrimaryGameUser . gameUserHolder . achievementsService as MiCoreServices . AchievementsServiceBase ;
139+ if ( service == null )
140+ {
141+ GUILayout . Label ( "Unable to retrieve achievement service status" ) ;
142+ }
143+ else
144+ {
145+ GUILayout . Label ( "Achievement service state: " + service . eStateAchievements ) ;
146+ GUILayout . Label ( "Achievement service API running: " + MiCoreServices . GlobalManager . instance . API . bAPIRunning ) ;
147+ GUILayout . Label ( "Achievement service connected: " + service . IsConnected ) ;
148+ GUILayout . Label ( "Achievement service activated: " + service . IsActivated ) ;
149+ }
150+
151+ GUILayout . BeginHorizontal ( ) ;
152+ GUILayout . Label ( "Achievement ID:" ) ;
153+ achievementIDString = GUILayout . TextField ( achievementIDString ) ;
154+ if ( GUILayout . Button ( "Load" ) )
155+ {
156+ if ( int . TryParse ( achievementIDString , out var newAchievementID ) )
157+ {
158+ achievementID = newAchievementID ;
159+ message = "" ;
160+ }
161+ else
162+ {
163+ achievementID = null ;
164+ message = "Invalid ID" ;
165+ }
166+ }
167+ GUILayout . EndHorizontal ( ) ;
168+
169+ if ( achievementID != null )
170+ {
171+ var a = AchievementCollection . instance . liAchievements . Where ( x => x . iEnumID == ( int ) achievementID ) . SingleOrDefault ( ) as Achievement ;
172+ if ( a == null )
173+ {
174+ message = "No achievement with ID " + achievementID ;
175+ return ;
176+ }
177+
178+ GUILayout . Label ( "ID: " + achievementID ) ;
179+ GUILayout . Label ( "Name: " + a . strName ) ;
180+ GUILayout . Label ( "Type: " + a . eType ) ;
181+ if ( a . eType == Achievement . Type . Progress ) GUILayout . Label ( "Progress: " + a . iProgress + "/" + a . iProgressCount ) ;
182+ GUILayout . Label ( "State: " + a . eCompleteState ) ;
183+
184+ if ( GUILayout . Button ( "Reset progress" ) )
185+ {
186+ AccessTools . Field ( typeof ( Achievement ) , "m_iProgress" ) . SetValue ( a , 0 ) ;
187+ }
188+
189+ if ( GUILayout . Button ( "Reset state" ) )
190+ {
191+ AccessTools . Field ( typeof ( Achievement ) , "m_eCompleteState" ) . SetValue ( a , Achievement . CompleteState . Running ) ;
192+ }
193+
194+ GUILayout . BeginHorizontal ( ) ;
195+ var progressString = GUILayout . TextField ( progress . ToString ( ) ) ;
196+ if ( string . IsNullOrWhiteSpace ( progressString ) ) progress = 0 ;
197+ else int . TryParse ( progressString , out progress ) ;
198+ if ( GUILayout . Button ( "Set Progress" ) )
199+ {
200+ AccessTools . Field ( typeof ( Achievement ) , "m_iProgress" ) . SetValue ( a , progress ) ;
201+ }
202+ GUILayout . EndHorizontal ( ) ;
203+
204+ if ( GUILayout . Button ( "Trigger increase progress" ) )
205+ {
206+ a . progressCount ( 1 ) ;
207+ }
208+
209+ if ( GUILayout . Button ( "Trigger completion" ) )
210+ {
211+ AccessTools . Field ( typeof ( Achievement ) , "m_eCompleteState" ) . SetValue ( a , Achievement . CompleteState . CompletingAwaitingApiCall ) ;
212+ PrimaryGameUser . gameUserHolder . achievementsService . completeAchievement ( a ) ;
213+ }
214+ }
92215 }
93216 }
94217}
0 commit comments