static void saveXml(bloPane pane, XmlWriter writer) { var typeID = "pane"; if (pane is bloTextbox) { typeID = "textbox"; } else if (pane is bloWindow) { typeID = "window"; } else if (pane is bloPicture) { typeID = "picture"; } writer.WriteStartElement(typeID); pane.saveXml(writer); if (pane.getChildPane() > 0) { writer.WriteComment("children"); foreach (var childpane in pane) { saveXml(childpane, writer); } } writer.WriteEndElement(); }
static void saveCompact(bloPane pane, aBinaryWriter writer) { var typeID = cPaneID; if (pane is bloTextbox) { typeID = cTextboxID; } else if (pane is bloWindow) { typeID = cWindowID; } else if (pane is bloPicture) { typeID = cPictureID; } writer.Write16(typeID); pane.saveCompact(writer); if (pane.getChildPane() > 0) { writer.Write16(cBeginID); foreach (var childpane in pane) { saveCompact(childpane, writer); } writer.Write16(cEndID); } }
static void saveBlo1(bloPane pane, aBinaryWriter writer, ref uint blockcount) { var typeID = cPAN1; if (pane is bloTextbox) { typeID = cTBX1; } else if (pane is bloWindow) { typeID = cWIN1; } else if (pane is bloPicture) { typeID = cPIC1; } var blockstart = writer.Position; writer.Write32(typeID); writer.Write32(0u); // dummy size pane.saveBlo1(writer); writer.WritePadding(4, 0); var blockend = writer.Position; writer.Goto(blockstart + 4); writer.Write32((uint)(blockend - blockstart)); writer.Goto(blockend); ++blockcount; if (pane.getChildPane() > 0) { writer.Write32(cBGN1); writer.Write32(0x8u); ++blockcount; foreach (var childpane in pane) { saveBlo1(childpane, writer, ref blockcount); } writer.Write32(cEND1); writer.Write32(0x8u); ++blockcount; } }
static void loadXml(bloPane parent, xElement element) { foreach (var childElement in element) { bloPane pane; switch (childElement.Name.ToLowerInvariant()) { case "pane": pane = new bloPane(); break; case "picture": pane = new bloPicture(); break; case "window": pane = new bloWindow(); break; case "textbox": pane = new bloTextbox(); break; default: continue; } pane.load(parent, childElement, bloFormat.Xml); loadXml(pane, childElement); } }
static bool loadCompact(bloPane parent, aBinaryReader reader) { bloPane lastPane = parent; for (;;) { long start = reader.Position; ushort typeID = reader.Read16(); // this is actually a peek in SMS, but f**k that switch (typeID) { default: { Console.WriteLine(">>> Unknown '{0:X4}' section at 0x{1:X6}", typeID, start); return(false); } case cExitID: { return(true); } case cEndID: { reader.Step(2); return(true); } case cBeginID: { reader.Step(2); if (!loadCompact(lastPane, reader)) { return(false); } break; } case cPaneID: { lastPane = new bloPane(); lastPane.load(parent, reader, bloFormat.Compact); if (parent is bloScreen) { var oldrect = lastPane.getRectangle(); var newrect = new bloRectangle(0, 0, oldrect.width, oldrect.height); parent.setRectangle(newrect); } break; } case cWindowID: { lastPane = new bloWindow(); lastPane.load(parent, reader, bloFormat.Compact); break; } case cPictureID: { lastPane = new bloPicture(); lastPane.load(parent, reader, bloFormat.Compact); break; } case cTextboxID: { lastPane = new bloTextbox(); lastPane.load(parent, reader, bloFormat.Compact); break; } } } }
static bool loadBlo1(bloPane parent, aBinaryReader reader) { bloPane lastPane = parent; for (;;) { long start = reader.Position; uint typeID = reader.Read32(); long length = reader.Read32(); long end = (start + length); switch (typeID) { case cPAN1: { lastPane = new bloPane(); lastPane.load(parent, reader, bloFormat.Blo1); if (reader.Position != end) { Console.WriteLine(">>> Bad '{0}' section at {1:X6} (header size {2:X6} actual size {3:X6})", idToString(typeID), start, length, (reader.Position - start)); reader.Goto(end); } break; } case cPIC1: { lastPane = new bloPicture(); lastPane.load(parent, reader, bloFormat.Blo1); if (reader.Position != end) { Console.WriteLine(">>> Bad '{0}' section at {1:X6} (header size {2:X6} actual size {3:X6})", idToString(typeID), start, length, (reader.Position - start)); reader.Goto(end); } break; } case cWIN1: { lastPane = new bloWindow(); lastPane.load(parent, reader, bloFormat.Blo1); if (reader.Position != end) { Console.WriteLine(">>> Bad '{0}' section at {1:X6} (header size {2:X6} actual size {3:X6})", idToString(typeID), start, length, (reader.Position - start)); reader.Goto(end); } break; } case cTBX1: { lastPane = new bloTextbox(); lastPane.load(parent, reader, bloFormat.Blo1); reader.Goto(end); break; } case cBGN1: { reader.Goto(end); if (!loadBlo1(lastPane, reader)) { return(false); } break; } case cEND1: { reader.Goto(end); return(true); } case cEXT1: { // we should skip to the end of this section just in case, // but SMS doesn't so to keep compatibility neither do we return(true); } default: { Console.WriteLine(">>> Unknown '{0}' section at {1:X6} (size {2:X6})", idToString(typeID), start, length); return(false); } } } }