public static XmlWriter GetWriter(this ScribeSaver scribeSaver) { FieldInfo fieldInfo = typeof(ScribeSaver).GetField("writer", BindingFlags.Instance | BindingFlags.NonPublic); XmlWriter result = (XmlWriter)fieldInfo.GetValue(scribeSaver); return(result); }
static bool Prefix(ScribeSaver __instance) { if (!PersistentWorldManager.GetInstance().PersistentWorldNotNull()) { return(true); } var writer = WriterField.GetValue(__instance); if (writer == null) { return(true); } var curPath = (string)CurPathField.GetValue(__instance); if (curPath.EndsWith("thing")) { // Reset thing index. ScribeSaver_EnterNode_Patch.ResetThingIndex(); } var length = curPath.LastIndexOf('/'); curPath = length <= 0 ? null : curPath.Substring(0, length); CurPathField.SetValue(__instance, curPath); return(true); }
public static bool Prefix(ScribeSaver __instance, string filePath, string documentElementName) { if (!Enable) { return(true); } Loger.Log("ScribeSaver_InitSaving_Patch Start"); var that = Traverse.Create(__instance); if (Scribe.mode != 0) { Log.Error("Called InitSaving() but current mode is " + Scribe.mode); Scribe.ForceStop(); } if (that.Field("curPath").GetValue <string>() != null) { Log.Error("Current path is not null in InitSaving"); that.Field("curPath").SetValue(null); that.Field("savedNodes").GetValue <HashSet <string> >().Clear(); that.Field("nextListElementTemporaryId").SetValue(0); } try { Scribe.mode = LoadSaveMode.Saving; var saveStream = SaveData = new MemoryStream(); //var saveStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None); File.WriteAllText(filePath, "Online save"); that.Field("saveStream").SetValue(saveStream); XmlWriterSettings xmlWriterSettings = new XmlWriterSettings(); xmlWriterSettings.Indent = true; xmlWriterSettings.IndentChars = "\t"; var writer = XmlWriter.Create(saveStream, xmlWriterSettings); that.Field("writer").SetValue(writer); writer.WriteStartDocument(); __instance.EnterNode(documentElementName); } catch (Exception ex) { Log.Error("Exception while init saving file: " + filePath + "\n" + ex); __instance.ForceStop(); throw; } Loger.Log("ScribeSaver_InitSaving_Patch End"); return(false); }
public static void SetWriter(this ScribeSaver scribeSaver, XmlWriter writer) { FieldInfo fieldInfo = typeof(ScribeSaver).GetField("writer", BindingFlags.Instance | BindingFlags.NonPublic); fieldInfo.SetValue(scribeSaver, writer); }
static bool Prefix(ScribeSaver __instance, string nodeName) { if (!PersistentWorldManager.GetInstance().PersistentWorldNotNull()) { return(true); } var writer = WriterField.GetValue(__instance); if (writer == null) { return(true); } var curPath = (string)CurPathField.GetValue(__instance); curPath = curPath + "/" + nodeName; var currentListIndex = Regex.Matches(curPath + "/", "\\/li\\[(\\d+)\\]\\/").Count; if (nodeName == "li") { ++currentListIndex; } FileLog.Log("Current list index before: " + currentListIndex); FileLog.Log("Curpath before: " + curPath); if (nodeName == "li" || nodeName == "thing") { if (nodeName == "li") { if (ListIndexes.ContainsKey(currentListIndex)) { ListIndexes[currentListIndex] += 1; } else { ListIndexes.Add(currentListIndex, 0); } FileLog.Log("CurPath b4 set: " + curPath); curPath = curPath + "[" + ListIndexes[currentListIndex] + "]"; FileLog.Log("CurPath after set: " + curPath); } else { curPath = curPath + "[" + currentThingIndex++ + "]"; } } else { if (currentListIndex < ListIndexes.Count) { ListIndexes.RemoveAll(set => set.Key > currentListIndex); } } FileLog.Log("Current list index after: " + currentListIndex); FileLog.Log("Curpath after: " + curPath); CurPathField.SetValue(__instance, curPath); return(true); }