66namespace PolyMod . Managers ;
77internal static class Compatibility
88{
9- internal static string signature = string . Empty ;
10- internal static string looseSignature = string . Empty ;
9+ internal static string checksum = string . Empty ;
10+ internal static bool shouldResetSettings = false ;
1111 private static bool sawSignatureWarning ;
1212
13- public static void HashSignatures ( StringBuilder looseSignatureString , StringBuilder signatureString )
13+ public static void HashSignatures ( StringBuilder checksumString )
1414 {
15- looseSignature = Util . Hash ( looseSignatureString ) ;
16- signature = Util . Hash ( signatureString ) ;
15+ checksum = Util . Hash ( checksumString ) ;
1716 }
1817
1918 private static bool CheckSignatures ( Action < int , BaseEventData > action , int id , BaseEventData eventData , Il2CppSystem . Guid gameId )
@@ -24,15 +23,15 @@ private static bool CheckSignatures(Action<int, BaseEventData> action, int id, B
2423 return true ;
2524 }
2625
27- string [ ] signatures = { string . Empty , string . Empty } ;
26+ string signature = string . Empty ;
2827 try
2928 {
30- signatures = File . ReadAllLines ( Path . Combine ( Application . persistentDataPath , $ "{ gameId } .signatures") ) ;
29+ signature = File . ReadAllText ( Path . Combine ( Application . persistentDataPath , $ "{ gameId } .signatures") ) ;
3130 }
3231 catch { }
33- if ( signatures [ 0 ] == string . Empty && signatures [ 1 ] == string . Empty ) return true ;
32+ if ( signature == string . Empty ) return true ;
3433 if ( Plugin . config . debug ) return true ;
35- if ( looseSignature != signatures [ 0 ] )
34+ if ( checksum != signature )
3635 {
3736 PopupManager . GetBasicPopup ( new (
3837 Localization . Get ( "polymod.signature.mismatch" ) ,
@@ -43,30 +42,29 @@ private static bool CheckSignatures(Action<int, BaseEventData> action, int id, B
4342 ) ) . Show ( ) ;
4443 return false ;
4544 }
46- if ( signature != signatures [ 1 ] )
47- {
48- PopupManager . GetBasicPopup ( new (
49- Localization . Get ( "polymod.signature.mismatch" ) ,
50- Localization . Get ( "polymod.signature.maybe.incompatible" ) ,
51- new ( new PopupBase . PopupButtonData [ ] {
52- new (
53- "OK" ,
54- callback : ( UIButtonBase . ButtonAction ) ( ( int _ , BaseEventData _ ) => {
55- sawSignatureWarning = true ;
56- action ( id , eventData ) ;
57- } )
58- )
59- } )
60- ) ) . Show ( ) ;
61- return false ;
62- }
6345 return true ;
6446 }
6547
6648 [ HarmonyPostfix ]
6749 [ HarmonyPatch ( typeof ( StartScreen ) , nameof ( StartScreen . Start ) ) ]
6850 private static void StartScreen_Start ( )
6951 {
52+ string lastChecksum = checksum ;
53+ try
54+ {
55+ lastChecksum = new ( File . ReadAllText ( Plugin . CHECKSUM_PATH ) ) ;
56+ }
57+ catch ( FileNotFoundException ) { }
58+
59+ File . WriteAllText (
60+ Plugin . CHECKSUM_PATH ,
61+ checksum
62+ ) ;
63+ if ( lastChecksum != checksum )
64+ {
65+ shouldResetSettings = true ;
66+ }
67+
7068 Version incompatibilityWarningLastVersion = Plugin . POLYTOPIA_VERSION . CutRevision ( ) ;
7169 try
7270 {
@@ -139,10 +137,29 @@ private static void ClientBase_CreateSession(GameSettings settings, Il2CppSystem
139137 {
140138 File . WriteAllLinesAsync (
141139 Path . Combine ( Application . persistentDataPath , $ "{ gameId } .signatures") ,
142- new string [ ] { looseSignature , signature }
140+ new string [ ] { checksum }
143141 ) ;
144142 }
145143
144+ [ HarmonyPrefix ]
145+ [ HarmonyPatch ( typeof ( TribeSelectorScreen ) , nameof ( TribeSelectorScreen . Show ) ) ]
146+ private static bool TribeSelectorScreen_Show ( bool instant = false )
147+ {
148+ if ( shouldResetSettings )
149+ {
150+ RestorePreliminaryGameSettings ( ) ;
151+ shouldResetSettings = false ;
152+ }
153+ return true ;
154+ }
155+
156+ internal static void RestorePreliminaryGameSettings ( )
157+ {
158+ GameManager . PreliminaryGameSettings . disabledTribes . Clear ( ) ;
159+ GameManager . PreliminaryGameSettings . selectedSkins . Clear ( ) ;
160+ GameManager . PreliminaryGameSettings . SaveToDisk ( ) ;
161+ }
162+
146163 internal static void Init ( )
147164 {
148165 Harmony . CreateAndPatchAll ( typeof ( Compatibility ) ) ;
0 commit comments