public ObcdBlock Read(ScummBlockHeader header, ScummBinaryReader reader) { var result = new ObcdBlock { Header = header }; long endIndex = reader.BaseStream.Position + result.Header.ContentLength; while (reader.BaseStream.Position < endIndex) { var childHeader = reader.ReadBlockHeader(); switch (childHeader.HeaderName) { case "CDHD": //if (result.Room != null) throw new DuplicateBlockException(childHeader.HeaderName); reader.BaseStream.Seek(childHeader.ContentLength, SeekOrigin.Current); break; case "VERB": if (result.Verb != null) throw new DuplicateBlockException(childHeader.HeaderName); result.Verb = new VerbReader().Read(childHeader, reader); break; case "OBNA": if (result.Name != null) throw new DuplicateBlockException(childHeader.HeaderName); var bytes = reader.ReadBytes((int)childHeader.ContentLength); result.Name = System.Text.Encoding.ASCII.GetString(bytes); result.Name = result.Name.TrimEnd('\0'); break; default: throw new UnexpectedObjectScriptBlockException(childHeader.HeaderName); } } return result; }
public BoxdBlock Read(ScummBlockHeader header, ScummBinaryReader reader) { var numBlocks = reader.ReadUInt16(); var boxList = new List<BoxdBlock.Box>(); for (int i = 0; i < numBlocks; i++) { var box = new BoxdBlock.Box() { UpperLeftX = reader.ReadUInt16(), UpperLeftY = reader.ReadUInt16(), UpperRightX = reader.ReadUInt16(), UpperRightY = reader.ReadUInt16(), LowerRightX = reader.ReadUInt16(), LowerRightY = reader.ReadUInt16(), LowerLeftX = reader.ReadUInt16(), LowerLeftY = reader.ReadUInt16(), Mask = reader.ReadByte(), Flags = reader.ReadByte(), Scale = reader.ReadUInt16() }; boxList.Add(box); } var result = new BoxdBlock { Header = header, BoxList = boxList }; return result; }
public BoxmBlock Read(ScummBlockHeader header, ScummBinaryReader reader) { var pathList = new List<List<byte>>(); long endIndex = reader.BaseStream.Position + header.ContentLength; List<byte> path = null; while (reader.BaseStream.Position < endIndex) { if (path == null) path = new List<byte>(); var curByte = reader.ReadByte(); if (curByte != 0xff) { path.Add(curByte); } else { pathList.Add(path); path = null; } } return new BoxmBlock { Header = header, AllPossibleBlockPaths = pathList }; }
public VerbBlock Read(ScummBlockHeader header, ScummBinaryReader reader) { //var bytes = reader.ReadBytes(100).Select(x => (char) x); List<VerbBlock.VerbEntry> verbEntries = new List<VerbBlock.VerbEntry>(); while (true) { var verb = reader.ReadByte(); if (verb == 0) break; verbEntries.Add(new VerbBlock.VerbEntry { Verb = verb, Offset = reader.ReadUInt16() }); } uint endIndex = header.ContentLength; foreach (var verb in verbEntries.OrderByDescending(x => x.Offset)) { verb.Length = endIndex - (verb.Offset - 8); verb.Content = reader.ReadBytes((int)verb.Length); endIndex = (uint)(verb.Offset - 8); } var result = new VerbBlock { Header = header, VerbEntries = verbEntries }; return result; }
public TrnsBlock Read(ScummBlockHeader header, ScummBinaryReader reader) { return new TrnsBlock { Header = header, Content = reader.ReadBytes((int)header.ContentLength) }; }
public ScummBlockHeader ReadBlockHeader() { var result = new ScummBlockHeader { HeaderName = ReadHeaderName(), ContentLength = ReadContentLength() }; return result; }
public RmhdBlock Read(ScummBlockHeader header, ScummBinaryReader reader) { return new RmhdBlock { Header = header, Width = reader.ReadUInt16(), Height = reader.ReadUInt16(), NumObjects = reader.ReadUInt16(), }; }
public RoomBlock Read(ScummBlockHeader header, ScummBinaryReader reader) { var result = new RoomBlock { Header = header }; long endIndex = reader.BaseStream.Position + result.Header.ContentLength; while (reader.BaseStream.Position < endIndex) { var childHeader = reader.ReadBlockHeader(); switch (childHeader.HeaderName) { case "RMHD": if (result.RoomHeader != null) throw new DuplicateBlockException(childHeader.HeaderName); result.RoomHeader = new RoomHeaderReader().Read(childHeader, reader); break; case "EPAL": if (result.EgaPalette != null) throw new DuplicateBlockException(childHeader.HeaderName); result.EgaPalette = new EgaPaletteReader().Read(childHeader, reader); break; case "CLUT": if (result.Clut != null) throw new DuplicateBlockException(childHeader.HeaderName); result.Clut = new ClutReader().Read(childHeader, reader); break; case "CYCL": if (result.ColorCycle != null) throw new DuplicateBlockException(childHeader.HeaderName); result.ColorCycle = new ColorCycleReader().Read(childHeader, reader); break; case "TRNS": if (result.Transparent != null) throw new DuplicateBlockException(childHeader.HeaderName); result.Transparent = new TransparentReader().Read(childHeader, reader); break; case "PALS": if (result.Palette != null) throw new DuplicateBlockException(childHeader.HeaderName); result.Palette = new PaletteReader().Read(childHeader, reader); break; case "RMIM": if (result.RoomImage != null) throw new DuplicateBlockException(childHeader.HeaderName); result.RoomImage = new RoomImageReader().Read(childHeader, reader); break; case "OBIM": result.ObjImages.Add(new ObjImageReader().Read(childHeader, reader)); break; case "OBCD": result.ObjectScripts.Add(new ObjectScriptReader().Read(childHeader, reader)); break; case "EXCD": if (result.ExitScript != null) throw new DuplicateBlockException(childHeader.HeaderName); result.ExitScript = new ExitScriptReader().Read(childHeader, reader); break; case "ENCD": if (result.EntryScript != null) throw new DuplicateBlockException(childHeader.HeaderName); result.EntryScript = new EntryScriptReader().Read(childHeader, reader); break; case "NLSC": if (result.NumScripts != null) throw new DuplicateBlockException(childHeader.HeaderName); result.NumScripts = new NumScriptsReader().Read(childHeader, reader); break; case "LSCR": result.LocalScripts.Add(new LocalScriptReader().Read(childHeader, reader)); break; case "BOXD": if (result.BoxData != null) throw new DuplicateBlockException(childHeader.HeaderName); result.BoxData = new BoxDataReader().Read(childHeader, reader); break; case "BOXM": if (result.BoxMatrix != null) throw new DuplicateBlockException(childHeader.HeaderName); result.BoxMatrix = new BoxMatrixReader().Read(childHeader, reader); break; case "SCAL": if (result.ScaleSlots != null) throw new DuplicateBlockException(childHeader.HeaderName); result.ScaleSlots = new ScaleSlotsReader().Read(childHeader, reader); break; default: throw new UnexpectedRoomBlockException(childHeader.HeaderName); } } return result; }