public static void Load(CharFileInfoClothes __instance, BinaryReader br) { Debug.Log(HSExtSave._logPrefix + "Loading extended data for coordinate..."); long cachedPosition = br.BaseStream.Position; //br.ReadInt64(); try { XmlDocument doc = new XmlDocument(); doc.Load(br.BaseStream); HashSet <HSExtSave.HandlerGroup> calledHandlers = new HashSet <HSExtSave.HandlerGroup>(); foreach (XmlNode node in doc.ChildNodes) { switch (node.Name) { case "clothesExtData": foreach (XmlNode child in node.ChildNodes) { try { HSExtSave.HandlerGroup group; if (HSExtSave._handlers.TryGetValue(child.Name, out group) && group.onClothesRead != null) { group.onClothesRead(__instance, child); calledHandlers.Add(group); } } catch (Exception e) { Debug.LogError(HSExtSave._logPrefix + "Exception happened in handler \"" + child.Name + "\" during coordinate loading. The exception was: " + e); } } break; } } foreach (KeyValuePair <string, HSExtSave.HandlerGroup> handler in HSExtSave._handlers) { if (handler.Value.onClothesRead != null && calledHandlers.Contains(handler.Value) == false) { handler.Value.onClothesRead(__instance, null); } } } catch (XmlException) { Debug.Log(HSExtSave._logPrefix + "No ext data in reader."); foreach (KeyValuePair <string, HSExtSave.HandlerGroup> kvp in HSExtSave._handlers) { if (kvp.Value.onClothesRead != null) { kvp.Value.onClothesRead(__instance, null); } } br.BaseStream.Seek(cachedPosition, SeekOrigin.Begin); } }
public static void Save(CharFileInfoClothes __instance, BinaryWriter bw) { Debug.Log(HSExtSave._logPrefix + "Saving extended data for coordinates..."); using (XmlTextWriter xmlWriter = new XmlTextWriter(bw.BaseStream, Encoding.UTF8)) { xmlWriter.Formatting = Formatting.None; xmlWriter.WriteStartElement("clothesExtData"); foreach (KeyValuePair <string, HSExtSave.HandlerGroup> kvp in HSExtSave._handlers) { if (kvp.Value.onClothesWrite == null) { continue; } using (StringWriter stringWriter = new StringWriter()) { using (XmlTextWriter xmlWriter2 = new XmlTextWriter(stringWriter)) { try { xmlWriter2.WriteStartElement(kvp.Key); kvp.Value.onClothesWrite(__instance, xmlWriter2); xmlWriter2.WriteEndElement(); // Checking if xml is well formed XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(stringWriter.ToString()); xmlWriter.WriteRaw(stringWriter.ToString()); } catch (Exception e) { Debug.LogError(HSExtSave._logPrefix + "Exception happened in handler \"" + kvp.Key + "\" during coordinates saving. The exception was: " + e); } } } } xmlWriter.WriteEndElement(); } Debug.Log(HSExtSave._logPrefix + "Saving done."); }
public static void Injected(CharFileInfoClothes __instance, BinaryWriter bw) { CharFileInfoClothes_Extensions.Save(__instance, bw); }
public static void Postfix(CharFileInfoClothes __instance, BinaryReader br, bool noSetPng = false) { CharFileInfoClothes_Extensions.Load(__instance, br); }