Skip to content

Commit ceb5b37

Browse files
Added a mod whitelist to allow mods which depended on a bug which was fixed in 2.21 from displaying errors. The errors will still be logged to the log file
1 parent 7582aef commit ceb5b37

16 files changed

+127
-43
lines changed

B9PartSwitch.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"MAJOR": 2,
1111
"MINOR": 21,
1212
"PATCH": 0,
13-
"BUILD": 1
13+
"BUILD": 2
1414
},
1515
"KSP_VERSION": {
1616
"MAJOR": 1,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"RootPath":"D:\\github\\KSP-1-Mods\\B9PartSwitch\\B9PartSwitch","ProjectFileName":"B9PartSwitch.csproj","Configuration":"Debug|AnyCPU","FrameworkPath":"","Sources":[],"References":[],"Analyzers":[],"Outputs":[{"OutputItemFullPath":"D:\\github\\KSP-1-Mods\\B9PartSwitch\\B9PartSwitch\\bin\\Debug\\B9PartSwitch.dll","OutputItemRelativePath":"B9PartSwitch.dll"},{"OutputItemFullPath":"","OutputItemRelativePath":""}],"CopyToOutputEntries":[]}

B9PartSwitch/AssemblyVersion.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55

66
using System.Reflection;
77

8-
[assembly: AssemblyVersion("2.21.0.1")]
9-
[assembly: AssemblyFileVersion("2.21.0.1")]
8+
[assembly: AssemblyVersion("2.21.0.2")]
9+
[assembly: AssemblyFileVersion("2.21.0.2")]

B9PartSwitch/B9PartSwitch.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,4 @@ if $(ConfigurationName) == Release (
216216
<Target Name="AfterBuild">
217217
</Target>
218218
-->
219-
</Project>
219+
</Project>

B9PartSwitch/PartSwitch/AttachNodeModifierInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ public void Save(ConfigNode node, OperationContext context)
3030
this.SaveFields(node, context);
3131
}
3232

33-
public IEnumerable<IPartModifier> CreatePartModifiers(Part part, ILinearScaleProvider linearScaleProvider, Action<string> onError)
33+
public IEnumerable<IPartModifier> CreatePartModifiers(Part part, ILinearScaleProvider linearScaleProvider, Action<string, bool> onError)
3434
{
3535
AttachNode node = part.attachNodes.FirstOrDefault(n => (n.nodeType == AttachNode.NodeType.Stack || n.nodeType == AttachNode.NodeType.Dock) && nodeID.Match(n.id));
3636

3737
if (node == null)
3838
{
39-
onError($"Attach node with id matching '{nodeID}' not found for attach node modifier");
39+
onError($"Attach node with id matching '{nodeID}' not found for attach node modifier", false);
4040
yield break;
4141
}
4242

B9PartSwitch/PartSwitch/MaterialModifierInfo.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class MaterialModifierInfo : IContextualNode
3333

3434
public void Save(ConfigNode node, OperationContext context) => this.SaveFields(node, context);
3535

36-
public IEnumerable<IPartModifier> CreateModifiers(Transform rootTransform, Action<string> onError)
36+
public IEnumerable<IPartModifier> CreateModifiers(Transform rootTransform, Action<string, bool> onError)
3737
{
3838
rootTransform.ThrowIfNullArgument(nameof(rootTransform));
3939

@@ -75,7 +75,7 @@ public IEnumerable<IPartModifier> CreateModifiers(Transform rootTransform, Actio
7575
}
7676
}
7777

78-
private IEnumerable<Renderer> GetBaseTransformRenderers(Transform rootTransform, Action<string> onError)
78+
private IEnumerable<Renderer> GetBaseTransformRenderers(Transform rootTransform, Action<string, bool> onError)
7979
{
8080
IEnumerable<Renderer> result = Enumerable.Empty<Renderer>();
8181
if (baseTransformNames == null) return result;
@@ -92,20 +92,20 @@ private IEnumerable<Renderer> GetBaseTransformRenderers(Transform rootTransform,
9292

9393
if (transformRenderers.Length == 0)
9494
{
95-
onError($"No renderers found on transform '{baseTransformName}'");
95+
onError($"No renderers found on transform '{baseTransformName}'", false);
9696
continue;
9797
}
9898

9999
result = result.Concat(transformRenderers);
100100
}
101101

102-
if (!foundTransform) onError($"No transforms matching '{baseTransformName}' found");
102+
if (!foundTransform) onError($"No transforms matching '{baseTransformName}' found", false);
103103
}
104104

105105
return result;
106106
}
107107

108-
private IEnumerable<Renderer> GetTransformRenderers(Transform rootTransform, Action<string> onError)
108+
private IEnumerable<Renderer> GetTransformRenderers(Transform rootTransform, Action<string, bool> onError)
109109
{
110110
IEnumerable<Renderer> result = Enumerable.Empty<Renderer>();
111111
if (transformNames == null) return result;
@@ -121,14 +121,14 @@ private IEnumerable<Renderer> GetTransformRenderers(Transform rootTransform, Act
121121

122122
if (transformRenderers.Length == 0)
123123
{
124-
onError($"No renderers found on transform '{transformName}'");
124+
onError($"No renderers found on transform '{transformName}'", false);
125125
continue;
126126
}
127127

128128
result = result.Concat(transformRenderers);
129129
}
130130

131-
if (!foundTransform) onError($"No transforms matching '{transformName}' found");
131+
if (!foundTransform) onError($"No transforms matching '{transformName}' found", false);
132132
}
133133

134134
return result;

B9PartSwitch/PartSwitch/PartSubtype.cs

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using UniLinq;
4-
using UnityEngine;
51
using B9PartSwitch.Fishbones;
62
using B9PartSwitch.Fishbones.Context;
73
using B9PartSwitch.PartSwitch.PartModifiers;
84
using 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

1012
namespace 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

B9PartSwitch/PartSwitch/TexturePropertyModifierInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ public class TexturePropertyModifierInfo : IContextualNode
2525

2626
public void Save(ConfigNode node, OperationContext context) => this.SaveFields(node, context);
2727

28-
public IEnumerable<IPartModifier> CreateModifiers(IEnumerable<Renderer> renderers, Action<string> onError)
28+
public IEnumerable<IPartModifier> CreateModifiers(IEnumerable<Renderer> renderers, Action<string, bool> onError)
2929
{
3030
if (string.IsNullOrEmpty(newTexturePath))
3131
{
32-
onError("texture name is empty");
32+
onError("texture name is empty", false);
3333
yield break;
3434
}
3535

3636
Texture newTexture = GameDatabase.Instance.GetTexture(newTexturePath, isNormalMap);
3737

3838
if (newTexture == null)
3939
{
40-
onError($"Texture '{newTexturePath}' not found!");
40+
onError($"Texture '{newTexturePath}' not found!", false);
4141
yield break;
4242
}
4343

B9PartSwitch/PartSwitch/TextureSwitchInfo.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,21 @@ public void Save(ConfigNode node, OperationContext context)
3939
this.SaveFields(node, context);
4040
}
4141

42-
public IEnumerable<TextureReplacement> CreateTextureReplacements(Part part, Action<string> onError)
42+
public IEnumerable<TextureReplacement> CreateTextureReplacements(Part part, Action<string, bool> onError)
4343
{
4444
part.ThrowIfNullArgument(nameof(part));
4545

4646
if (string.IsNullOrEmpty(newTexturePath))
4747
{
48-
onError("texture name is empty");
48+
onError("texture name is empty", false);
4949
yield break;
5050
}
5151

5252
Texture newTexture = GameDatabase.Instance.GetTexture(newTexturePath, isNormalMap);
5353

5454
if (newTexture == null)
5555
{
56-
onError($"Texture '{newTexturePath}' not found!");
56+
onError($"Texture '{newTexturePath}' not found!", false);
5757
yield break;
5858
}
5959

@@ -93,7 +93,7 @@ public IEnumerable<TextureReplacement> CreateTextureReplacements(Part part, Acti
9393
}
9494
}
9595

96-
private IEnumerable<Renderer> GetBaseTransformRenderers(Part part, Action<string> onError)
96+
private IEnumerable<Renderer> GetBaseTransformRenderers(Part part, Action<string, bool> onError)
9797
{
9898
IEnumerable<Renderer> result = Enumerable.Empty<Renderer>();
9999
if (baseTransformNames == null) return result;
@@ -110,20 +110,20 @@ private IEnumerable<Renderer> GetBaseTransformRenderers(Part part, Action<string
110110

111111
if (transformRenderers.Length == 0)
112112
{
113-
onError($"No renderers found on transform '{baseTransformName}'");
113+
onError($"No renderers found on transform '{baseTransformName}'", false);
114114
continue;
115115
}
116116

117117
result = result.Concat(transformRenderers);
118118
}
119119

120-
if (!foundTransform) onError($"No transforms matching '{baseTransformName}' found");
120+
if (!foundTransform) onError($"No transforms matching '{baseTransformName}' found", false);
121121
}
122122

123123
return result;
124124
}
125125

126-
private IEnumerable<Renderer> GetTransformRenderers(Part part, Action<string> onError)
126+
private IEnumerable<Renderer> GetTransformRenderers(Part part, Action<string, bool> onError)
127127
{
128128
IEnumerable<Renderer> result = Enumerable.Empty<Renderer>();
129129
if (transformNames == null) return result;
@@ -139,14 +139,14 @@ private IEnumerable<Renderer> GetTransformRenderers(Part part, Action<string> on
139139

140140
if (transformRenderers.Length == 0)
141141
{
142-
onError($"No renderers found on transform '{transformName}'");
142+
onError($"No renderers found on transform '{transformName}'", false);
143143
continue;
144144
}
145145

146146
result = result.Concat(transformRenderers);
147147
}
148148

149-
if (!foundTransform) onError($"No transforms matching '{transformName}' found");
149+
if (!foundTransform) onError($"No transforms matching '{transformName}' found", false);
150150
}
151151

152152
return result;

B9PartSwitch/PartSwitch/TransformModifierInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ public class TransformModifierInfo : IContextualNode
2727
public void Load(ConfigNode node, OperationContext context) => this.LoadFields(node, context);
2828
public void Save(ConfigNode node, OperationContext context) => this.SaveFields(node, context);
2929

30-
public IEnumerable<IPartModifier> CreatePartModifiers(Part part, Action<string> onError)
30+
public IEnumerable<IPartModifier> CreatePartModifiers(Part part, Action<string, bool> onError)
3131
{
3232
part.ThrowIfNullArgument(nameof(part));
3333
onError.ThrowIfNullArgument(nameof(onError));
3434

3535
if (transformName == null)
3636
{
37-
onError("transform name is null");
37+
onError("transform name is null", false);
3838
yield break;
3939
}
4040

@@ -58,7 +58,7 @@ public IEnumerable<IPartModifier> CreatePartModifiers(Part part, Action<string>
5858
}
5959
}
6060

61-
if (!foundTransform) onError($"Could not find any transform named '{transformName}'");
61+
if (!foundTransform) onError($"Could not find any transform named '{transformName}'", false);
6262
}
6363
}
6464
}

0 commit comments

Comments
 (0)