44using Il2CppEffects ;
55using Il2CppGame ;
66using Il2CppLoadingScreen ;
7+ using Il2CppSystem . IO ;
78using MelonLoader ;
8- using PawMapLoader . Res . Abstractions ;
99using UnityEngine ;
1010using UnityEngine . SceneManagement ;
1111
@@ -17,45 +17,75 @@ public static class GameManager_StartGame_Patch
1717 [ HarmonyPrefix ]
1818 public static bool Prefix ( GameManager __instance )
1919 {
20+ if ( Store . FirePrevention . IsGameStarted ) return true ;
21+
22+ Store . FirePrevention . IsGameStarted = true ;
23+
24+ MelonLogger . Msg ( "Get Selected Scene" ) ;
2025 string scenename = ConfigManager . Instance . Level . Scene . SceneName ;
2126 Store . IsMapCustom = false ;
2227 if ( scenename == "AtroCity" || scenename == "DownTown" ) return true ;
28+
29+ MelonLogger . Msg ( scenename + " is custom." ) ;
30+ Stream stream = null ;
2331 try
2432 {
2533 Store . IsMapCustom = true ;
34+
2635 MelonLogger . Msg ( "Loading " + scenename ) ;
27- var stream = FileManagement . OpenMapFile ( scenename ) ;
36+ MelonLogger . Msg ( "| Opening stream..." ) ;
37+ stream = FileManagement . OpenMapFile ( scenename ) ;
38+
39+ MelonLogger . Msg ( "|| Done." ) ;
40+ MelonLogger . Msg ( "| Loading From Stream..." ) ;
2841 Store . LoadedAssetBundle = AssetBundle . LoadFromStream ( stream ) ;
42+
43+ MelonLogger . Msg ( "|| Done." ) ;
2944 MelonLogger . Msg ( "Loaded " + scenename ) ;
30- stream . Close ( ) ;
31- stream . Dispose ( ) ;
45+ MelonLogger . Msg ( "| Disposing stream..." ) ;
46+ stream ? . Close ( ) ;
47+
48+ MelonLogger . Msg ( "|| Closed." ) ;
49+ stream ? . Dispose ( ) ;
50+
51+ MelonLogger . Msg ( "|| Disposed." ) ;
3252 }
3353 catch ( Exception e )
3454 {
55+ Store . FirePrevention . IsGameStarted = false ;
56+
3557 MelonLogger . Error ( "Failed to load bundle " + e ) ;
58+ stream ? . Close ( ) ;
59+ stream ? . Dispose ( ) ;
3660 }
3761
3862 return true ;
3963 }
4064 }
4165
42- [ HarmonyPatch ( typeof ( GameManager ) , nameof ( GameManager . GoToMainMenu ) ) ]
43- public static class GameManager_GoToMainMenu_Patch
66+ [ HarmonyPatch ( typeof ( GameManager ) , nameof ( GameManager . OnLobbySceneLoaded ) ) ]
67+ public static class GameManager_OnLobbySceneLoaded_Patch
4468 {
4569 [ HarmonyPrefix ]
4670 public static bool Prefix ( GameManager __instance )
4771 {
72+ if ( ! Store . FirePrevention . IsGameStarted ) return true ;
73+ Store . FirePrevention . IsGameStarted = false ;
74+ Store . FirePrevention . HasBlockConfig = false ;
75+
76+ MelonLogger . Msg ( "Unloading Scene Assetbundle" ) ;
4877 if ( ! Store . IsMapCustom ) return true ;
4978 Store . LoadedAssetBundle ? . Unload ( true ) ;
5079 Store . LoadedAssetBundle = null ;
80+ MelonLogger . Msg ( "Done." ) ;
5181 return true ;
5282 }
5383 }
5484
5585 [ HarmonyPatch ( typeof ( LoadingScreenController ) , nameof ( LoadingScreenController . Show ) ) ]
5686 public static class LoadingScreenController_Show_Patch
5787 {
58- [ HarmonyPrefix ]
88+ [ HarmonyPostfix ]
5989 public static void Postfix ( LoadingScreenController __instance )
6090 {
6191 __instance . Hide ( ) ;
@@ -68,41 +98,35 @@ public static class BuildingsManager_Init_Patch
6898 [ HarmonyPrefix ]
6999 public static void Prefix ( BuildingsManager __instance )
70100 {
71- if ( AbUe . GetTypeAll < CityBlockGrid > ( ) [ 0 ] == null )
101+ if ( Store . FirePrevention . HasBlockConfig ) return ;
102+ if ( Store . IsMapCustom )
72103 {
104+ MelonLogger . Msg ( "Finding SceneConfig" ) ;
73105 foreach ( var go in SceneManager
74- . GetSceneByName ( GameManager . _instance . GameplaySceneName ) . GetRootGameObjects ( ) )
106+ . GetSceneByName ( ConfigManager . Instance . Level . Scene . SceneName ) . GetRootGameObjects ( ) )
75107 {
76108 if ( go . name == "SceneConfig" )
77109 {
110+ MelonLogger . Msg ( "| \" " + go . name + "\" is SceneConfig." ) ;
78111 var cblock = new GameObject ( "CityBlock" ) ;
79112 cblock . transform . SetParent ( go . transform ) ;
80113 cblock . AddComponent < CityBlockGrid > ( ) ;
114+ Store . FirePrevention . HasBlockConfig = true ;
81115 break ;
82116 }
117+ MelonLogger . Msg ( "| \" " + go . name + "\" is not SceneConfig" ) ;
83118 }
84- GameManager . _instance . OnGameplaySceneLoaded ( ) ;
85119 }
86120 }
87121 }
88122
89123 [ HarmonyPatch ( typeof ( GroundDecalController ) , nameof ( GroundDecalController . IsGroundConcrete ) ) ]
90124 public static class GroundDecalController_IsGroundConcrete_Patch
91125 {
92- [ HarmonyPrefix ]
93- public static bool Prefix ( GroundDecalController __instance , bool __result )
94- {
95- if ( Store . IsMapCustom )
96- {
97- __result = false ;
98- return false ;
99- }
100- return true ;
101- }
102-
103126 [ HarmonyFinalizer ]
104127 public static Exception Finalizer ( Exception __exception , ref bool __result )
105128 {
129+
106130 if ( __exception is IndexOutOfRangeException )
107131 {
108132 __result = false ;
0 commit comments