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); } } } }