1- using System ;
2- using System . Collections . Generic ;
3- using UniLinq ;
4- using UnityEngine ;
51using B9PartSwitch . Fishbones ;
62using B9PartSwitch . Fishbones . Context ;
73using B9PartSwitch . PartSwitch . PartModifiers ;
84using B9PartSwitch . Utils ;
5+ using System ;
6+ using System . Collections . Generic ;
7+ using System . IO ;
8+ using System . Reflection ;
9+ using UniLinq ;
10+ using UnityEngine ;
911
1012namespace B9PartSwitch
1113{
@@ -228,7 +230,7 @@ private void OnLoad(ConfigNode node, OperationContext context)
228230
229231 public void OnBeforeReinitializeInactiveSubtype ( )
230232 {
231- foreach ( IPartModifier modifier in partModifiers )
233+ foreach ( IPartModifier modifier in partModifiers )
232234 {
233235 modifier . OnBeforeReinitializeInactiveSubtype ( ) ;
234236 }
@@ -257,6 +259,8 @@ public void OnAfterReinitializeActiveSubtype()
257259 modifier . OnAfterReinitializeActiveSubtype ( ) ;
258260 }
259261 }
262+ static UrlDir . UrlConfig [ ] configs = null ;
263+ static List < string > whitedListedMods = null ;
260264
261265 public void Setup ( ModuleB9PartSwitch parent , bool displayWarnings = true )
262266 {
@@ -265,6 +269,9 @@ public void Setup(ModuleB9PartSwitch parent, bool displayWarnings = true)
265269 if ( parent . part == null )
266270 throw new ArgumentNullException ( "parent.part cannot be null" ) ;
267271
272+
273+ InitializePartModWhitelist ( ) ;
274+
268275 this . parent = parent ;
269276
270277 aspectLocks . Clear ( ) ;
@@ -277,11 +284,11 @@ public void Setup(ModuleB9PartSwitch parent, bool displayWarnings = true)
277284
278285 string errorString = null ;
279286
280- void OnInitializationError ( string message )
287+ void OnInitializationError ( string message , bool overrideDisplayWarnings = false )
281288 {
282289 LogError ( message ) ;
283290
284- if ( displayWarnings )
291+ if ( displayWarnings && ! overrideDisplayWarnings )
285292 {
286293 if ( errorString == null ) errorString = $ "Initialization errors on { parent } subtype '{ Name } '";
287294
@@ -296,9 +303,10 @@ void MaybeAddModifier(IPartModifier modifier)
296303 if ( modifier is IPartAspectLock partAspectLockHolder )
297304 {
298305 object partAspectLock = partAspectLockHolder . PartAspectLock ;
306+
299307 if ( aspectLocksOnOtherModules . Contains ( partAspectLock ) )
300308 {
301- OnInitializationError ( $ "More than one module can't manage { modifier . Description } ") ;
309+ OnInitializationError ( $ "More than one module can't manage { modifier . Description } ", whitedListedMods . Contains ( FindPartMod ( parent . part . partInfo ) ) ) ;
302310 return ;
303311 }
304312 else
@@ -309,6 +317,42 @@ void MaybeAddModifier(IPartModifier modifier)
309317
310318 partModifiers . Add ( modifier ) ;
311319 }
320+ void InitializePartModWhitelist ( )
321+ {
322+ if ( configs == null )
323+ {
324+ configs = GameDatabase . Instance . GetConfigs ( "PART" ) ;
325+ whitedListedMods = new List < string > ( ) ;
326+
327+ Assembly execAssembly = Assembly . GetExecutingAssembly ( ) ; string _pluginDirectory = Path . GetDirectoryName ( execAssembly . Location ) ;
328+
329+ string whitelistFilePath = Path . Combine ( _pluginDirectory , "../PluginData/whiteList.cfg" ) ;
330+ ConfigNode whitelistFile = ConfigNode . Load ( whitelistFilePath ) ;
331+ try
332+ {
333+ ConfigNode blackListNode = whitelistFile . GetNode ( "B9_WHITELIST_MODS" ) ;
334+ foreach ( string item in blackListNode . GetValues ( "mod" ) )
335+ whitedListedMods . Add ( item ) ;
336+ }
337+ catch ( Exception e )
338+ {
339+ Debug . Log ( "[B9PartSwitch]: An exception occurred while loading the mod whitelist: " + e . Message ) ;
340+ }
341+ }
342+ }
343+ string FindPartMod ( AvailablePart part )
344+ {
345+ UrlDir . UrlConfig config = Array . Find < UrlDir . UrlConfig > ( configs , ( c => ( part . name == c . name . Replace ( '_' , '.' ) . Replace ( ' ' , '.' ) ) ) ) ;
346+ if ( config == null )
347+ {
348+ config = Array . Find < UrlDir . UrlConfig > ( configs , ( c => ( part . name == c . name ) ) ) ;
349+ if ( config == null )
350+ return "" ;
351+ }
352+ var id = new UrlDir . UrlIdentifier ( config . url ) ;
353+ return id [ 0 ] ;
354+ }
355+
312356
313357 if ( maxTemp > 0 )
314358 MaybeAddModifier ( new PartMaxTempModifier ( part , partPrefab . maxTemp , maxTemp ) ) ;
@@ -354,15 +398,15 @@ void MaybeAddModifier(IPartModifier modifier)
354398
355399 foreach ( AttachNodeModifierInfo info in attachNodeModifierInfos )
356400 {
357- foreach ( IPartModifier partModifier in info . CreatePartModifiers ( part , parent , OnInitializationError ) )
401+ foreach ( IPartModifier partModifier in info . CreatePartModifiers ( part , parent , OnInitializationError ) )
358402 {
359403 MaybeAddModifier ( partModifier ) ;
360404 }
361405 }
362406
363407 foreach ( TextureSwitchInfo info in textureSwitches )
364408 {
365- foreach ( TextureReplacement replacement in info . CreateTextureReplacements ( part , OnInitializationError ) )
409+ foreach ( TextureReplacement replacement in info . CreateTextureReplacements ( part , OnInitializationError ) )
366410 {
367411 MaybeAddModifier ( replacement ) ;
368412 }
@@ -466,7 +510,7 @@ void MaybeAddModifier(IPartModifier modifier)
466510 SeriousWarningHandler . DisplaySeriousWarning ( errorString ) ;
467511 }
468512
469- #endregion
513+ #endregion
470514
471515 #region Public Methods
472516
0 commit comments