11using System ;
22using System . Collections . Concurrent ;
33using System . Collections . Generic ;
4+ using System . Diagnostics ;
45using System . Linq ;
6+ using System . Threading ;
57using System . Threading . Tasks ;
68using System . Windows . Controls ;
79using NLog ;
2224
2325namespace Concealment
2426{
25- [ Plugin ( "Concealment" , "1.0 " , "17f44521-b77a-4e85-810f-ee73311cf75d" ) ]
27+ [ Plugin ( "Concealment" , "1.1 " , "17f44521-b77a-4e85-810f-ee73311cf75d" ) ]
2628 public class ConcealmentPlugin : TorchPluginBase , IWpfPlugin
2729 {
2830 public Persistent < Settings > Settings { get ; }
@@ -74,7 +76,7 @@ public override void Update()
7476 if ( _init )
7577 return ;
7678
77- MySession . Static . Players . PlayerRequesting += RevealSpawns ;
79+ // MySession.Static.Players.PlayerRequesting += RevealSpawns;
7880 MyMultiplayer . Static . ClientJoined += RevealCryoPod ;
7981
8082 _init = true ;
@@ -183,18 +185,18 @@ private int ConcealGroup(ConcealGroup group)
183185 if ( _concealGroups . Any ( g => g . Id == group . Id ) )
184186 return 0 ;
185187
186- Log . Info ( $ "Concealing grids: { string . Join ( ", " , group . Grids . Select ( g => g . DisplayName ) ) } ") ;
187- group . ConcealTime = DateTime . Now ;
188+ Log . Info ( $ "Concealing grids: { group . GridNames } ") ;
188189 group . Grids . ForEach ( ConcealEntity ) ;
190+ var aabb = group . WorldAABB ;
191+ group . ProxyId = _concealedAabbTree . AddProxy ( ref aabb , group , 0 ) ;
192+ group . Closing += Group_Closing ;
189193 Task . Run ( ( ) =>
190194 {
191195 group . UpdatePostConceal ( ) ;
192- var aabb = group . WorldAABB ;
193- group . ProxyId = _concealedAabbTree . AddProxy ( ref aabb , group , 0 ) ;
194196 Log . Debug ( $ "Group { group . Id } cached") ;
197+ group . IsConcealed = true ;
195198 Torch . Invoke ( ( ) => _concealGroups . Add ( group ) ) ;
196199 } ) ;
197- group . Closing += Group_Closing ;
198200 return group . Grids . Count ;
199201 }
200202
@@ -205,7 +207,13 @@ private void Group_Closing(ConcealGroup group)
205207
206208 public int RevealGroup ( ConcealGroup group )
207209 {
208- Log . Info ( $ "Revealing grids: { string . Join ( ", " , group . Grids . Select ( g => g . DisplayName ) ) } ") ;
210+ if ( ! group . IsConcealed )
211+ {
212+ Log . Warn ( $ "Attempted to reveal a group that wasn't concealed: { group . GridNames } ") ;
213+ Log . Warn ( new StackTrace ( ) ) ;
214+ return 0 ;
215+ }
216+ Log . Debug ( $ "Revealing grids: { group . GridNames } ") ;
209217 group . Grids . ForEach ( RevealEntity ) ;
210218 _concealGroups . Remove ( group ) ;
211219 _concealedAabbTree . RemoveProxy ( group . ProxyId ) ;
@@ -232,6 +240,8 @@ public int RevealNearbyGrids(double distanceFromPlayers)
232240 foreach ( var sphere in playerSpheres )
233241 revealed += RevealGridsInSphere ( sphere ) ;
234242
243+ if ( revealed != 0 )
244+ Log . Info ( $ "Revealed { revealed } grids near players.") ;
235245 return revealed ;
236246 }
237247
@@ -260,6 +270,9 @@ public int ConcealDistantGrids(double distanceFromPlayers)
260270 concealed += ConcealGroup ( group ) ;
261271 }
262272
273+ if ( concealed != 0 )
274+ Log . Info ( $ "Concealed { concealed } grids distant from players.") ;
275+
263276 return concealed ;
264277 }
265278
0 commit comments