@@ -49,45 +49,15 @@ private static void ExecuteLoadCustomLevel(object directorInstance, string Level
4949 return ;
5050 }
5151
52- int currentLevelIndex ;
5352 object gameLevel ;
54- levelBuilder . InitCustomLevelFromCode ( LevelCode , out currentLevelIndex , out gameLevel ) ;
53+ levelBuilder . InitCustomLevelFromCode ( LevelCode , out gameLevel ) ;
5554
5655 if ( gameLevel == null )
5756 {
5857 Debug . LogError ( "Failed to load custom level — aborting LoadCustomLevel!" ) ;
5958 return ;
6059 }
6160
62- Type levelManagerType = AccessTools . TypeByName ( "LevelManager" ) ;
63- levelManagerType ? . GetMethod ( "Init" ) ? . Invoke ( null , new object [ ] { currentLevelIndex } ) ;
64-
65- var ui = UIManager . instance ;
66- if ( ui != null )
67- {
68- var menuLayer = AccessTools . Field ( ui . GetType ( ) , "menuLayer" ) ? . GetValue ( ui ) ;
69- if ( menuLayer != null )
70- {
71- var levelButtons = AccessTools . Field ( menuLayer . GetType ( ) , "levelButtons" ) ? . GetValue ( menuLayer ) as IEnumerable < object > ;
72- if ( levelButtons != null )
73- {
74- foreach ( var btn in levelButtons )
75- {
76- if ( btn is Component comp )
77- {
78- AccessTools . Method ( comp . GetType ( ) , "Init" ) ? . Invoke ( comp , new object [ ] { currentLevelIndex } ) ;
79- }
80- }
81- }
82- else Debug . LogWarning ( "UIManager menuLayer.levelButtons is null!" ) ;
83- }
84- else Debug . LogWarning ( "UIManager menuLayer is null!" ) ;
85- }
86- else
87- {
88- Debug . LogError ( "UIManager instance still null after waiting!" ) ;
89- return ;
90- }
9161 AccessTools . TypeByName ( "LevelNumber" ) ? . GetMethod ( "ChangeLevelText" ) ? . Invoke ( null , new object [ ] { LevelCode } ) ;
9262
9363 AccessTools . Method ( directorInstance . GetType ( ) , "InitCommonSystems" ) ? . Invoke ( directorInstance , null ) ;
@@ -128,15 +98,13 @@ private static void ExecuteLoadCustomLevel(object directorInstance, string Level
12898 Debug . LogWarning ( "ReplayManager is null!" ) ;
12999
130100 AccessTools . Method ( directorInstance . GetType ( ) , "InitVisuals" ) ? . Invoke ( directorInstance , null ) ;
131-
132- Debug . Log ( $ "<color=green>Custom level loaded successfully: Index { currentLevelIndex } </color>") ;
133101 }
134102
135103
136104 public static void SafeInitVisuals ( object directorInstance )
137105 {
138106 var traverse = Traverse . Create ( directorInstance ) ;
139- var gameMode = ( GameMode ) traverse . Field ( "gameMode" ) . GetValue ( ) ;
107+ var gameMode = Director . gameMode ; // (GameMode)traverse.Field("gameMode").GetValue();
140108
141109 ( float , int , bool , float ) tuple ;
142110
@@ -145,30 +113,44 @@ public static void SafeInitVisuals(object directorInstance)
145113 Debug . Log ( "[Patch] Using fallback tuple for GameMode 3" ) ;
146114 tuple = ( 0.75f , 1 , false , 4.5f ) ;
147115 }
116+ else if ( SandboxStateMapping . mapping . TryGetValue ( gameMode , out var mappedTuple ) )
117+ {
118+ Debug . Log ( "[Patch] gamemode: " + gameMode . ToString ( ) ) ;
119+ tuple = mappedTuple ;
120+ }
148121 else
149122 {
150- tuple = SandboxStateMapping . mapping [ gameMode ] ;
123+ Debug . LogWarning ( $ "[Patch] Unknown GameMode: { gameMode } , using default fallback") ;
124+ tuple = ( 0.75f , 1 , false , 4.5f ) ;
151125 }
152126
127+
128+
153129 CameraSizeManager . SetAdditiveSize ( tuple . Item1 ) ;
154130
155- var gridLines = AccessTools . Field ( AccessTools . TypeByName ( "GridLines" ) , "instance" ) ? . GetValue ( null ) ;
156- if ( gridLines != null )
157- {
158- AccessTools . Method ( gridLines . GetType ( ) , "SetGameGrid" ) ? . Invoke ( gridLines , new object [ ] { tuple . Item2 } ) ;
131+ //var gridLines = AccessTools.Field(AccessTools.TypeByName("GridLines"), "instance")?.GetValue(null);
132+ GridLines . instance ? . SetGameGrid ( tuple . Item2 ) ;
133+ //if (gridLines != null)
134+ //{
135+ //AccessTools.Method(gridLines.GetType(), "SetGameGrid")?.Invoke(gridLines, new object[] { tuple.Item2 });
159136
160137 if ( tuple . Item3 )
161138 {
162- var selectedButton = AccessTools . Field ( AccessTools . TypeByName ( "LayerSandbox" ) , "selectedButton" ) ? . GetValue ( null ) ;
163- bool willPlaceOut = selectedButton is SandboxButtonEntity entity && entity . willPlaceOut ;
164- AccessTools . Method ( gridLines . GetType ( ) , "ShowCantPlace" ) ? . Invoke ( gridLines , new object [ ] { willPlaceOut } ) ;
139+ //var selectedButton = AccessTools.Field(AccessTools.TypeByName("LayerSandbox"), "selectedButton")?.GetValue(null);
140+ //bool willPlaceOut = selectedButton is SandboxButtonEntity entity && entity.willPlaceOut;
141+ //AccessTools.Method(gridLines.GetType(), "ShowCantPlace")?.Invoke(gridLines, new object[] { willPlaceOut });
142+ GridLines . instance ? . ShowCantPlace ( LayerSandbox . selectedButton is SandboxButtonEntity sandboxButtonEntity && sandboxButtonEntity . willPlaceOut ) ;
165143 }
166144 else
167145 {
168- AccessTools . Method ( gridLines . GetType ( ) , "ResetCantPlace" ) ? . Invoke ( gridLines , null ) ;
169- }
170- }
171-
146+ //AccessTools.Method(gridLines.GetType(), "ResetCantPlace")?.Invoke(gridLines, null);
147+ GridLines . instance ? . ResetCantPlace ( ) ;
148+ }
149+ ( UIManager . instance . sandboxLayer . allEntityButtons . Last ( ) as SandboxButtonEntity ) . SetSprite ( ) ;
150+ var heartContainer = traverse . Field ( "heartContainer" ) . GetValue ( ) ;
151+ AccessTools . Method ( heartContainer . GetType ( ) , "MoveContainerY" ) ? . Invoke ( heartContainer , new object [ ] { tuple . Item4 } ) ;
152+ //}
153+ /*
172154 var ui = UIManager.instance;
173155 var lastButton = ui?.sandboxLayer?.allEntityButtons?.LastOrDefault();
174156 if (lastButton is SandboxButtonEntity sbEntity)
@@ -178,6 +160,8 @@ public static void SafeInitVisuals(object directorInstance)
178160
179161 var heartContainer = traverse.Field("heartContainer").GetValue();
180162 AccessTools.Method(heartContainer.GetType(), "MoveContainerY")?.Invoke(heartContainer, new object[] { tuple.Item4 });
163+ */
164+ UIManager . instance ? . menuLayer . CalculateMenu ( ) ;
181165 }
182166
183167 }
0 commit comments