11using HarmonyLib ;
2+ using Polytopia . IO ;
23using System . Text ;
34using UnityEngine ;
45using UnityEngine . EventSystems ;
@@ -79,6 +80,32 @@ private static bool CheckSignatures(Action<int, BaseEventData> action, int id, B
7980 return true ;
8081 }
8182
83+ /// <summary>
84+ /// Restores removed polytopia method which lets you get all guids of single player sessions.
85+ /// </summary>
86+ private static Il2CppSystem . Guid [ ] GetSinglePlayerSessions ( ) // CHECKMATE MIDJIWAN
87+ {
88+ string saveDirectoryPath = Paths . GetSaveDirectoryPath ( "Singleplayer" ) ;
89+ if ( PolytopiaDirectory . Exists ( saveDirectoryPath ) )
90+ {
91+ string [ ] files = PolytopiaDirectory . GetFiles ( saveDirectoryPath , "*.state" ) ;
92+ if ( files != null && files . Length != 0 )
93+ {
94+ List < Il2CppSystem . Guid > list = new List < Il2CppSystem . Guid > ( files . Length ) ;
95+ for ( int i = 0 ; i < files . Length ; i ++ )
96+ {
97+ Il2CppSystem . Guid guid ;
98+ if ( Il2CppSystem . Guid . TryParse ( Path . GetFileNameWithoutExtension ( files [ i ] ) , out guid ) )
99+ {
100+ list . Add ( guid ) ;
101+ }
102+ }
103+ return list . ToArray ( ) ;
104+ }
105+ }
106+ return new Il2CppSystem . Guid [ ] { } ;
107+ }
108+
82109 /// <summary>
83110 /// Performs compatibility checks when the start screen is shown.
84111 /// </summary>
@@ -146,7 +173,7 @@ private static bool GameInfoPopup_OnMainButtonClicked(GameInfoPopup __instance,
146173 [ HarmonyPatch ( typeof ( StartScreen ) , nameof ( StartScreen . OnResumeButtonClick ) ) ]
147174 private static bool StartScreen_OnResumeButtonClick ( StartScreen __instance , int id , BaseEventData eventData )
148175 {
149- return CheckSignatures ( __instance . OnResumeButtonClick , id , eventData , ClientBase . GetSinglePlayerSessions ( ) [ 0 ] ) ;
176+ return CheckSignatures ( __instance . OnResumeButtonClick , id , eventData , GetSinglePlayerSessions ( ) [ 0 ] ) ;
150177 }
151178
152179 /// <summary>
@@ -159,19 +186,6 @@ private static void ClientBase_DeletePassAndPlayGame(GameInfoPopup __instance)
159186 File . Delete ( Path . Combine ( Application . persistentDataPath , $ "{ __instance . gameId } .signatures") ) ;
160187 }
161188
162- /// <summary>
163- /// Deletes the signature files of all single-player games when they are deleted.
164- /// </summary>
165- [ HarmonyPrefix ]
166- [ HarmonyPatch ( typeof ( ClientBase ) , nameof ( ClientBase . DeleteSinglePlayerGames ) ) ]
167- private static void ClientBase_DeleteSinglePlayerGames ( )
168- {
169- foreach ( var gameId in ClientBase . GetSinglePlayerSessions ( ) )
170- {
171- File . Delete ( Path . Combine ( Application . persistentDataPath , $ "{ gameId } .signatures") ) ;
172- }
173- }
174-
175189 /// <summary>
176190 /// Deletes the signature file of a game when the match ends.
177191 /// </summary>
0 commit comments