55using CodeStage . AntiCheat . Storage ;
66using CodeStage . AntiCheat . ObscuredTypes ;
77using System . Collections . Generic ;
8+ using MonoMod . Cil ;
9+ using BepInEx . Logging ;
810
911namespace WarmTofuMod
1012{
11- [ BepInPlugin ( "com.kert.warmtofumod" , "WarmTofuMod" , "1.2 .0" ) ]
13+ [ BepInPlugin ( "com.kert.warmtofumod" , "WarmTofuMod" , "1.3 .0" ) ]
1214 public class WarmTofuMod : BaseUnityPlugin
1315 {
1416 public enum Menus
@@ -28,7 +30,9 @@ public enum Menus
2830 const int INT_PREF_NOT_EXIST_VAL = - 999 ;
2931 const float FLOAT_PREF_NOT_EXIST_VAL = - 999 ;
3032 const string STRING_PREF_NOT_EXIST_VAL = "" ;
31- int ontyping = 0 ;
33+ bool achievements100kmh = false ;
34+ bool achievements200kmh = false ;
35+ bool inTuningMenu = false ;
3236
3337 Dictionary < string , int > prefsInt = new Dictionary < string , int >
3438 {
@@ -49,11 +53,26 @@ public enum Menus
4953 Dictionary < string , string > prefsString = new Dictionary < string , string >
5054 {
5155 { "ControllerTypeChoose" , STRING_PREF_NOT_EXIST_VAL } ,
52- { "BreakBtnUsedMX5(Clone" , STRING_PREF_NOT_EXIST_VAL } ,
5356 { "HistoriqueDesMessages" , STRING_PREF_NOT_EXIST_VAL } ,
5457 { "DERNIERMESSAGE" , STRING_PREF_NOT_EXIST_VAL }
5558 } ;
5659
60+ Dictionary < string , int > obscuredInt = new Dictionary < string , int >
61+ {
62+ { "ONTYPING" , INT_PREF_NOT_EXIST_VAL } ,
63+ { "BoostQuantity" , INT_PREF_NOT_EXIST_VAL } ,
64+ { "TOTALWINMONEY" , INT_PREF_NOT_EXIST_VAL } ,
65+ { "MyLvl" , INT_PREF_NOT_EXIST_VAL } ,
66+ { "XP" , INT_PREF_NOT_EXIST_VAL }
67+ } ;
68+
69+ Dictionary < string , bool > obscuredBool = new Dictionary < string , bool >
70+ {
71+ { "TOFU RUN" , false } ,
72+ { "BackCamToogle" , false }
73+ } ;
74+
75+
5776 private void Awake ( )
5877 {
5978 Logger . LogInfo ( $ "Plugin { PluginInfo . PLUGIN_GUID } is loaded!") ;
@@ -89,6 +108,25 @@ private void Awake()
89108
90109 On . CodeStage . AntiCheat . Storage . ObscuredPrefs . GetInt += ObscuredPrefs_GetInt ;
91110 On . CodeStage . AntiCheat . Storage . ObscuredPrefs . SetInt += ObscuredPrefs_SetInt ;
111+ On . CodeStage . AntiCheat . Storage . ObscuredPrefs . GetBool += ObscuredPrefs_GetBool ;
112+ On . CodeStage . AntiCheat . Storage . ObscuredPrefs . SetBool += ObscuredPrefs_SetBool ;
113+ On . CodeStage . AntiCheat . Storage . ObscuredPrefs . HasKey += ObscuredPrefs_HasKey ;
114+
115+ IL . SRConcessionManager . Update += SRConcessionManager_Update ;
116+ On . EnterArea . Update += EnterArea_Update ;
117+ On . EnterAreaGarage . Update += EnterAreaGarage_Update ;
118+ On . SRTransitionMap . Update += SRTransitionMap_Update ;
119+ IL . SRUIManager . Update += SRUIManager_Update ;
120+
121+ // missing lights fix
122+ On . RCC_LightEmission . Update += RCC_LightEmission_Update ;
123+
124+ // don't grant achievements all the time
125+ On . SRPlayerFonction . More100kmh += SRPlayerFonction_More100kmh ;
126+ On . SRPlayerFonction . More200kmh += SRPlayerFonction_More200kmh ;
127+
128+ // Skidmarks amount config
129+ On . RCC_Skidmarks . Start += RCC_Skidmarks_Start ;
92130 }
93131 catch ( Exception e )
94132 {
@@ -103,7 +141,10 @@ int PlayerPrefs_GetInt_string(On.UnityEngine.PlayerPrefs.orig_GetInt_string orig
103141 {
104142 int val = prefsInt [ str ] ;
105143 if ( val == INT_PREF_NOT_EXIST_VAL )
106- return orig ( str ) ;
144+ {
145+ val = orig ( str ) ;
146+ prefsInt [ str ] = val ;
147+ }
107148 return val ;
108149 }
109150 else
@@ -119,7 +160,10 @@ float PlayerPrefs_GetFloat_string(On.UnityEngine.PlayerPrefs.orig_GetFloat_strin
119160 {
120161 float val = prefsFloat [ str ] ;
121162 if ( val == FLOAT_PREF_NOT_EXIST_VAL )
122- return orig ( str ) ;
163+ {
164+ val = orig ( str ) ;
165+ prefsFloat [ str ] = val ;
166+ }
123167 return val ;
124168 }
125169 else
@@ -131,11 +175,16 @@ float PlayerPrefs_GetFloat_string(On.UnityEngine.PlayerPrefs.orig_GetFloat_strin
131175
132176 string PlayerPrefs_GetString_string ( On . UnityEngine . PlayerPrefs . orig_GetString_string orig , string str )
133177 {
134- if ( prefsString . ContainsKey ( str ) )
178+ if ( prefsString . ContainsKey ( str ) || str . StartsWith ( "BreakBtnUsed" ) )
135179 {
180+ if ( ! prefsString . ContainsKey ( str ) )
181+ prefsString [ str ] = orig ( str ) ;
136182 string val = prefsString [ str ] ;
137183 if ( val == STRING_PREF_NOT_EXIST_VAL )
138- return orig ( str ) ;
184+ {
185+ val = orig ( str ) ;
186+ prefsString [ str ] = val ;
187+ }
139188 return val ;
140189 }
141190 else
@@ -184,21 +233,198 @@ void PlayerPrefs_SetString(On.UnityEngine.PlayerPrefs.orig_SetString orig, strin
184233
185234 int ObscuredPrefs_GetInt ( On . CodeStage . AntiCheat . Storage . ObscuredPrefs . orig_GetInt orig , string key , int defaultValue )
186235 {
187- if ( key == "ONTYPING" )
188- return ontyping ;
236+ if ( obscuredInt . ContainsKey ( key ) || key . StartsWith ( "UsedPlateForFutureSpawn" ) || key . StartsWith ( "BuyPlateNumber" ) )
237+ {
238+ if ( ! obscuredInt . ContainsKey ( key ) )
239+ {
240+ obscuredInt [ key ] = orig ( key , defaultValue ) ;
241+ }
242+ int val = obscuredInt [ key ] ;
243+ if ( val == INT_PREF_NOT_EXIST_VAL )
244+ {
245+ val = orig ( key , defaultValue ) ;
246+ obscuredInt [ key ] = val ;
247+ }
248+ return val ;
249+ }
189250 return orig ( key , defaultValue ) ;
190251 }
191252
192253 void ObscuredPrefs_SetInt ( On . CodeStage . AntiCheat . Storage . ObscuredPrefs . orig_SetInt orig , string key , int value )
193254 {
194- if ( key == "ONTYPING" )
255+ if ( obscuredInt . ContainsKey ( key ) )
256+ obscuredInt [ key ] = value ;
257+ else
195258 {
196- ontyping = value ;
259+ //Debug.Log("Setting int " + key);
260+ }
261+ if ( key == "ONTYPING" )
197262 return ;
263+ Debug . Log ( "Setting int " + key ) ;
264+ orig ( key , value ) ;
265+ }
266+
267+ bool ObscuredPrefs_GetBool ( On . CodeStage . AntiCheat . Storage . ObscuredPrefs . orig_GetBool orig , string key , bool defaultValue )
268+ {
269+ if ( obscuredBool . ContainsKey ( key ) )
270+ {
271+ return obscuredBool [ key ] ;
272+ }
273+ else
274+ {
275+ return orig ( key , defaultValue ) ;
276+ }
277+ }
278+
279+ bool ObscuredPrefs_HasKey ( On . CodeStage . AntiCheat . Storage . ObscuredPrefs . orig_HasKey orig , string key )
280+ {
281+ if ( ! obscuredInt . ContainsKey ( key ) )
282+ {
283+ if ( key . StartsWith ( "UsedPlateForFutureSpawn" ) )
284+ {
285+ if ( orig ( key ) )
286+ {
287+ obscuredInt [ key ] = ObscuredPrefs . GetInt ( key , 0 ) ;
288+ return true ;
289+ }
290+ obscuredInt [ key ] = INT_PREF_NOT_EXIST_VAL ;
291+ return false ;
292+ }
293+ else
294+ return orig ( key ) ;
295+ }
296+ else
297+ {
298+ if ( obscuredInt [ key ] == INT_PREF_NOT_EXIST_VAL )
299+ return false ;
300+ return true ;
301+ }
302+ }
303+
304+ void ObscuredPrefs_SetBool ( On . CodeStage . AntiCheat . Storage . ObscuredPrefs . orig_SetBool orig , string key , bool value )
305+ {
306+ if ( obscuredBool . ContainsKey ( key ) )
307+ obscuredBool [ key ] = value ;
308+ else
309+ {
310+ Debug . Log ( "Setting bool " + key ) ;
198311 }
312+ Debug . Log ( "Setting bool " + key ) ;
199313 orig ( key , value ) ;
200314 }
201315
316+ void SRConcessionManager_Update ( ILContext il )
317+ {
318+ try
319+ {
320+ var c = new ILCursor ( il ) ;
321+ c . GotoNext ( MoveType . After ,
322+ i => i . MatchStfld < SRConcessionManager > ( "NombreDeSkin" )
323+ ) ;
324+
325+ // skip the rest of the code
326+ c . Emit ( Mono . Cecil . Cil . OpCodes . Ret ) ;
327+ }
328+ catch ( Exception e )
329+ {
330+ Logger . LogError ( e ) ;
331+ throw ;
332+ }
333+ }
334+
335+ void EnterArea_Update ( On . EnterArea . orig_Update orig , EnterArea self )
336+ {
337+ if ( self . CarDealer . activeSelf )
338+ GameObject . FindObjectOfType < SRConcessionManager > ( ) . MoneyDisplay . text = ObscuredPrefs . GetInt ( "MyBalance" , 0 ) + "¥" ;
339+ orig ( self ) ;
340+ }
341+
342+ void EnterAreaGarage_Update ( On . EnterAreaGarage . orig_Update orig , EnterAreaGarage self )
343+ {
344+ if ( self . GarageMana . ButtonList != null && self . GarageMana . ButtonList . active )
345+ inTuningMenu = true ;
346+ else
347+ inTuningMenu = false ;
348+
349+ orig ( self ) ;
350+ }
351+
352+ void RCC_Skidmarks_Start ( On . RCC_Skidmarks . orig_Start orig , RCC_Skidmarks self )
353+ {
354+ orig ( self ) ;
355+ self . maxMarks = 256 ;
356+ }
357+
358+ void SRTransitionMap_Update ( On . SRTransitionMap . orig_Update orig , SRTransitionMap self )
359+ {
360+ // changed order of conditions
361+ int lint = ( int ) typeof ( SRTransitionMap ) . GetField ( "lint" , BindingFlags . Instance | BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Static ) . GetValue ( self ) ;
362+ if ( lint == 0 && self . UIFadeout . activeSelf )
363+ {
364+ typeof ( SRTransitionMap ) . GetField ( "lint" , BindingFlags . Instance | BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Static ) . SetValue ( self , 1 ) ;
365+ base . GetComponentInChildren < UnityEngine . UI . Text > ( ) . text = self . lestips [ UnityEngine . Random . Range ( 0 , self . lestips . Length ) ] ;
366+ }
367+ if ( lint == 1 && GameObject . FindGameObjectsWithTag ( "CanvasFadeOut" ) . Length > 1 )
368+ GameObject . Destroy ( self . RCCCanvasPhoton ) ;
369+ }
370+
371+ void SRUIManager_Update ( ILContext il )
372+ {
373+ try
374+ {
375+ var c = new ILCursor ( il ) ;
376+ c . GotoNext ( MoveType . After ,
377+ i => i . MatchCall < SRUIManager > ( "ExitMenuNo" )
378+ ) ;
379+
380+ c . EmitDelegate < Action > ( ( ) =>
381+ {
382+ if ( ObscuredPrefs . GetInt ( "MyLvl" , 0 ) >= 1000 && ObscuredPrefs . GetInt ( "TOTALWINMONEY" , 0 ) < 5000 )
383+ {
384+ obscuredInt [ "Mylvl" ] = 0 ;
385+ obscuredInt [ "XP" ] = 0 ;
386+ }
387+ } ) ;
388+
389+ // skip the rest of the code
390+ c . Emit ( Mono . Cecil . Cil . OpCodes . Ret ) ;
391+ }
392+ catch ( Exception e )
393+ {
394+ Logger . LogError ( e ) ;
395+ throw ;
396+ }
397+ }
398+
399+ void RCC_LightEmission_Update ( On . RCC_LightEmission . orig_Update orig , RCC_LightEmission self )
400+ {
401+ if ( typeof ( RCC_LightEmission ) . GetField ( "material" , BindingFlags . Instance | BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Static ) . GetValue ( self ) == null )
402+ {
403+ return ;
404+ }
405+ orig ( self ) ;
406+ }
407+
408+ void SRPlayerFonction_More100kmh ( On . SRPlayerFonction . orig_More100kmh orig , SRPlayerFonction self )
409+ {
410+ if ( ! achievements100kmh )
411+ {
412+ Steamworks . SteamUserStats . GetAchievement ( "100KMH" , out achievements100kmh ) ;
413+ if ( ! achievements100kmh )
414+ orig ( self ) ;
415+ }
416+ }
417+
418+ void SRPlayerFonction_More200kmh ( On . SRPlayerFonction . orig_More200kmh orig , SRPlayerFonction self )
419+ {
420+ if ( ! achievements200kmh )
421+ {
422+ Steamworks . SteamUserStats . GetAchievement ( "200KMH" , out achievements200kmh ) ;
423+ if ( ! achievements200kmh )
424+ orig ( self ) ;
425+ }
426+ }
427+
202428 void SRPlayerCollider_Update ( On . SRPlayerCollider . orig_Update orig , SRPlayerCollider self )
203429 {
204430
@@ -270,11 +496,8 @@ void OnGUI()
270496 InitMenuStyles ( ) ;
271497
272498 // Additional suspension settings menus
273- GameObject gameObject = GameObject . Find ( "Button_List" ) ; // Original game tuning shop menu
274- if ( gameObject != null && gameObject . activeSelf )
275- {
499+ if ( inTuningMenu )
276500 ShowModTuningMenu ( ) ;
277- }
278501 else if ( currentMenu != Menus . MENU_NONE )
279502 {
280503 RCC_CarControllerV3 activePlayerVehicle = RCC_SceneManager . Instance . activePlayerVehicle ;
0 commit comments