Skip to content

Instantly share code, notes, and snippets.

@notfood
Created September 7, 2019 19:29
Show Gist options
  • Save notfood/9492d87e4c6ac0cb51875122ba87897e to your computer and use it in GitHub Desktop.
Save notfood/9492d87e4c6ac0cb51875122ba87897e to your computer and use it in GitHub Desktop.
Adds a button to the debug panel to dump the resulting xml into console.
using System;
using Verse;
using Harmony;
using System.Xml;
using System.IO;
namespace DebugActions
{
class DebugActions : Mod
{
public DebugActions(ModContentPack content) : base(content)
{
HarmonyInstance.Create("rimworld.debugactions").PatchAll();
}
}
[HarmonyPatch (typeof(LoadedModManager), "CombineIntoUnifiedXML")]
internal static class SaveXML
{
public static XmlDocument instance;
static void Postfix(XmlDocument __result)
{
if (instance == null) instance = __result;
}
}
[HarmonyPatch (typeof(Dialog_DebugActionsMenu), "DoListingItems_Entry")]
static class AddDebugActions
{
static void Prefix(Dialog_DebugActionsMenu __instance)
{
var menu = __instance;
menu.DoLabel("XML");
menu.DebugAction("Dump", delegate {
StringWriter sw = new StringWriter();
SaveXML.instance.Save(sw);
string formattedXml = sw.ToString();
Log.Message(formattedXml);
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment