Skip to content

Commit

Permalink
Support [Persistent] Guids
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanKell authored and gotmachine committed Jan 30, 2023
1 parent 144206d commit a94f48a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions GameData/KSPCommunityFixes/Settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ KSP_COMMUNITY_FIXES
// Implement `IConfigNode` members marked as `[Persistent]` serialization support when using
// the `CreateObjectFromConfig()`, `LoadObjectFromConfig()` and `CreateConfigFromObject()` methods.
// Disabled by default, you can enable it with a MM patch.
// Also adds support for [Persistent] tags on System.Guid
PersistentIConfigNode = false

BaseFieldListUseFieldHost = true
Expand Down
16 changes: 14 additions & 2 deletions KSPCommunityFixes/Modding/PersistentIConfigNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ private static bool ConfigNode_WriteObject_Prefix(object obj, ConfigNode node, i
WriteValue(fieldName, typeof(int), writeLinks.AssignLink(value), node);
}
}
// begin edit 1
else if (fieldType == typeof(Guid))
{
node.AddValue(fieldName, ((Guid)value).ToString());
}
// end edit
else if (IsValue(fieldType))
{
WriteValue(fieldName, fieldType, value, node);
Expand All @@ -86,7 +92,7 @@ private static bool ConfigNode_WriteObject_Prefix(object obj, ConfigNode node, i
{
WriteArrayTypes(fieldName, fieldType, value, node, persistent);
}
// begin edit
// begin edit 2
else if (IsIConfigNode(fieldType))
{
WriteIConfigNode(fieldName, value, node);
Expand Down Expand Up @@ -158,6 +164,12 @@ private static bool ConfigNode_ReadObject_Prefix(object obj, ConfigNode node, ou
value.name = "";
}
}
// begin edit 1
else if (fieldItem.fieldType == typeof(Guid))
{
fieldItem.fieldInfo.SetValue(fieldItem.host, new Guid(value.value));
}
// end edit
else if (IsValue(fieldItem.fieldType))
{
object obj2 = ReadValue(fieldItem.fieldType, value.value);
Expand All @@ -178,7 +190,7 @@ private static bool ConfigNode_ReadObject_Prefix(object obj, ConfigNode node, ou
ReadFieldList.FieldItem fieldItem2 = readFieldList[configNode.name];
if (fieldItem2 != null)
{
// begin edit
// begin edit 2
if (IsIConfigNode(fieldItem2.fieldType))
{
ReadIConfigNode(fieldItem2, configNode);
Expand Down

0 comments on commit a94f48a

Please sign in to comment.