Skip to content

Commit 4e17510

Browse files
committed
1.5.6 - Fix % and editing of node without a name
1 parent 41fd232 commit 4e17510

3 files changed

Lines changed: 68 additions & 40 deletions

File tree

ModuleManager.csproj

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,21 @@
3030
<ConsolePause>False</ConsolePause>
3131
</PropertyGroup>
3232
<ItemGroup>
33-
<Reference Include="System">
34-
<HintPath>..\..\..\..\..\Games\ksp-win-0-21-1\KSP_Data\Managed\System.dll</HintPath>
35-
<Private>False</Private>
36-
</Reference>
37-
<Reference Include="UnityEngine">
38-
<HintPath>..\..\..\..\..\Games\ksp-win-0-21-1\KSP_Data\Managed\UnityEngine.dll</HintPath>
39-
<Private>False</Private>
40-
</Reference>
41-
<Reference Include="Assembly-CSharp">
42-
<HintPath>..\..\..\..\..\Games\ksp-win-0-21-1\KSP_Data\Managed\Assembly-CSharp.dll</HintPath>
43-
<Private>False</Private>
44-
</Reference>
33+
<Compile Include="moduleManager.cs" />
34+
<Compile Include="Properties\AssemblyInfo.cs" />
4535
</ItemGroup>
4636
<ItemGroup>
47-
<Compile Include="Properties/AssemblyInfo.cs" />
48-
<Compile Include="moduleManager.cs" />
37+
<Reference Include="Assembly-CSharp, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
38+
<SpecificVersion>False</SpecificVersion>
39+
</Reference>
40+
<Reference Include="System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, processorArchitecture=MSIL" />
41+
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
42+
<SpecificVersion>False</SpecificVersion>
43+
</Reference>
4944
</ItemGroup>
5045
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
5146
<PropertyGroup>
52-
<PostBuildEvent>copy "$(TargetPath)" "C:\Games\ksp-win-0-22-0\GameData"
53-
copy "$(TargetPath)" "C:\Games\ksp-win-0-22-0_dev\GameData"</PostBuildEvent>
47+
<PostBuildEvent>copy "$(TargetPath)" "C:\Games\ksp-win\GameData"
48+
copy "$(TargetPath)" "C:\Games\ksp-win_dev\GameData"</PostBuildEvent>
5449
</PropertyGroup>
55-
</Project>
50+
</Project>

Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
1818
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
1919

20-
[assembly: AssemblyVersion("1.5.5")]
20+
[assembly: AssemblyVersion("1.5.6")]
2121

2222
// The following attributes are used to specify the signing key for the assembly,
2323
// if desired. See the Mono documentation for more information about signing.

moduleManager.cs

Lines changed: 55 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public static ConfigNode FindConfigNodeIn(ConfigNode src, string nodeType,
2727
print ("Searching node for " + nodeType + "[" + nodeName + "," + nodeTag + "]");
2828
#endif
2929
foreach (ConfigNode n in src.GetNodes(nodeType)) {
30+
if (nodeName == null && nodeTag == null)
31+
return n;
3032
if (n.HasValue("name") && WildcardMatch(n.GetValue("name"), nodeName) &&
3133
(nodeTag == null ||
3234
(n.HasValue("tag") && WildcardMatch(n.GetValue("tag"), nodeTag)))) {
@@ -54,6 +56,7 @@ public static string RemoveWS(string withWhite)
5456
{ // Removes ALL whitespace of a string.
5557
return new string(withWhite.ToCharArray().Where(c => !Char.IsWhiteSpace(c)).ToArray());
5658
}
59+
5760
// ModifyNode applies the ConfigNode mod as a 'patch' to ConfigNode original, then returns the patched ConfigNode.
5861
// it uses FindConfigNodeIn(src, nodeType, nodeName, nodeTag) to recurse.
5962
public static ConfigNode ModifyNode(ConfigNode original, ConfigNode mod)
@@ -93,8 +96,8 @@ public static ConfigNode ModifyNode(ConfigNode original, ConfigNode mod)
9396
newNode.AddNode(subMod);
9497
else {
9598
ConfigNode subNode;
96-
if (subMod.name[0] == '@' && subMod.name[0] != '%')
97-
subNode = null;
99+
//if (subMod.name[0] == '@' && subMod.name[0] != '%')
100+
// subNode = null;
98101

99102
if (subMod.name.Contains("[")) {
100103
// format @NODETYPE[Name] {...} or @NODETYPE[Name, Tag] {...} or ! instead of @
@@ -112,6 +115,9 @@ public static ConfigNode ModifyNode(ConfigNode original, ConfigNode mod)
112115
string nodeType = subMod.name.Substring(1);
113116

114117
// format @NODETYPE,N {...} or ! instead of @
118+
// The problem with ! is that the index is messed up
119+
// So the patch need to take that into account
120+
// and lower the index for the next search
115121
int index = 0;
116122
if (nodeType.Contains(",")) {
117123
int.TryParse(nodeType.Split(',')[1], out index);
@@ -134,14 +140,30 @@ public static ConfigNode ModifyNode(ConfigNode original, ConfigNode mod)
134140
if (subMod.name[0] == '%') {
135141
// if the original node exist add it
136142
if (subNode != null) {
137-
newNode.nodes.Add(subNode);
143+
ConfigNode newSubNode = ModifyNode(subNode, subMod);
144+
newNode.nodes.Add(newSubNode);
138145
}
139-
else { // if not add the mod node without the % in its name
140-
if (subMod.name.Contains("["))
141-
subMod.name = subMod.name.Substring(1).Split('[')[0];
142-
else
143-
subMod.name = subMod.name.Substring(1);
144-
newNode.nodes.Add(subMod);
146+
else { // if not add the mod node without the % in its name
147+
// This part is messy. ialdabaoth is right, i need to rewrite.
148+
string type;
149+
string name;
150+
if (subMod.name.Contains("[")) {
151+
type = subMod.name.Substring(1).Split('[')[0];
152+
name = subMod.name.Split('[')[1].Replace("]", "");
153+
}
154+
else
155+
{
156+
type = subMod.name.Substring(1);
157+
name = null;
158+
}
159+
160+
ConfigNode copy = new ConfigNode(type);
161+
162+
if (name != null)
163+
copy.AddValue("name", name);
164+
165+
ConfigNode newSubNode = ModifyNode(copy, subMod);
166+
newNode.nodes.Add(newSubNode);
145167
}
146168
}
147169
if (subMod.name[0] == '$')
@@ -178,7 +200,7 @@ public static ConfigNode ModifyNode(ConfigNode original, ConfigNode mod)
178200

179201
int patchCount = 0;
180202

181-
public void Update()
203+
public void OnGUI()
182204
{
183205
/*
184206
* It should be a code to reload when the Reload Database debug button is used.
@@ -196,6 +218,8 @@ public void Update()
196218
}
197219
*/
198220

221+
222+
199223
if (!GameDatabase.Instance.IsReady() && ((HighLogic.LoadedScene == GameScenes.MAINMENU) || (HighLogic.LoadedScene == GameScenes.SPACECENTER)))
200224
{
201225
return;
@@ -293,17 +317,20 @@ public void ApplyPatch(List<String> excludePaths, bool final)
293317
if (!final ^ mod.name.EndsWith(":Final")) {
294318
char[] sep = new char[] { '[', ']' };
295319
string name = RemoveWS(mod.name);
320+
string cond = "";
296321
if (final)
297322
name = name.Substring(0, name.LastIndexOf(":Final"));
298-
string[] splits = name.Split(sep, 3);
299-
string pattern = splits[1];
300-
string type = splits[0].Substring(1);
301323

302-
String cond = "";
303-
if (splits.Length > 2 && splits[2].Length > 5) {
304-
int start = splits[2].IndexOf("HAS[") + 4;
305-
cond = splits[2].Substring(start, splits[2].LastIndexOf(']') - start);
324+
if (name.Contains(":HAS[")) {
325+
int start = name.IndexOf(":HAS[");
326+
cond = name.Substring(start + 5, name.LastIndexOf(']') - start - 5);
327+
name = name.Substring(0, start);
306328
}
329+
330+
string[] splits = name.Split(sep, 3);
331+
string pattern = splits.Length>1?splits[1]:null;
332+
string type = splits[0].Substring(1);
333+
307334
foreach (UrlDir.UrlConfig url in GameDatabase.Instance.root.AllConfigs) {
308335
if (url.type == type
309336
&& WildcardMatch(url.name, pattern)
@@ -364,15 +391,19 @@ public static bool CheckCondition(ConfigNode node, string conds)
364391
if (condsList.Count == 1) {
365392
conds = condsList[0];
366393

394+
395+
367396
string remainCond = "";
368397
if (conds.Contains("HAS[")) {
369398
int start = conds.IndexOf("HAS[") + 4;
370399
remainCond = conds.Substring(start, condsList[0].LastIndexOf(']') - start);
371400
conds = conds.Substring(0, start - 5);
372401
}
373402

374-
string type = conds.Substring(1).Split('[')[0];
375-
string name = conds.Split('[')[1].Replace("]", "");
403+
char[] sep = new char[] { '[', ']' };
404+
string[] splits = conds.Split(sep, 3);
405+
string type = splits[0].Substring(1);
406+
string name = splits.Length > 1 ? splits[1] : null;
376407

377408
switch (conds[0]) {
378409
case '@':
@@ -402,6 +433,7 @@ public static bool CheckCondition(ConfigNode node, string conds)
402433

403434
public static bool WildcardMatch(String s, String wildcard)
404435
{
436+
if (wildcard == null) return true;
405437
String pattern = "^" + Regex.Escape(wildcard).Replace(@"\*", ".*").Replace(@"\?", ".") + "$";
406438
Regex regex;
407439
regex = new Regex(pattern);
@@ -436,13 +468,14 @@ public static ConfigNode SearchNodesSwitch(ConfigNode node, String rootName)
436468
{
437469
if (cas.name == "DEFAULT" || (cas.name == "CASE" && TestSwitchCase(cas)))
438470
{
439-
foreach (ConfigNode n in cas.nodes)
440-
newNode.AddNode(n);
441-
442471
string list = "";
443472
foreach (ConfigNode.Value value in cas.values)
444473
list += " " + value.name + "=" + value.value;
445474
log("MM_SWITCH processed for " + rootName + " using " + cas.name + list);
475+
476+
foreach (ConfigNode n in cas.nodes)
477+
newNode.AddNode(SearchNodesSwitch(n, rootName));
478+
446479
break;
447480
}
448481
}

0 commit comments

Comments
 (0)