Skip to content

Commit

Permalink
Fix nested Persistent IConfigNode objects that each call LoadObjectFr…
Browse files Browse the repository at this point in the history
…omConfig or CreateConfigFromObject (#86)
  • Loading branch information
NathanKell authored and gotmachine committed Jan 30, 2023
1 parent 8d8d229 commit 9143397
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions KSPCommunityFixes/Modding/PersistentIConfigNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,30 @@ private static void ConfigNode_LoadObjectFromConfig_Postfix(LoadState __state)
readLinks = __state.links;
}

private static bool ConfigNode_WriteObject_Prefix(object obj, ConfigNode node, int pass)
{
__state = writeLinks;
}

// and restore it
private static void ConfigNode_CreateConfigFromObject_Postfix(WriteLinkList __state)
{
writeLinks = __state;
}

// This will fail if nested, so we cache off the old readlinks and remove.
private static void ConfigNode_LoadObjectFromConfig_Prefix(out LoadState __state)
{
__state = new LoadState(removeAfterUse, readLinks);
}

// and restore them
private static void ConfigNode_LoadObjectFromConfig_Postfix(LoadState __state)
{
removeAfterUse = __state.wasRemove;
readLinks = __state.links;
}

// used by TypeCache since we can't make the below method return a value.
public static bool WriteSuccess;

Expand Down

0 comments on commit 9143397

Please sign in to comment.