public virtual void Load(string filename) { BinaryReaderBE reader = new BinaryReaderBE(File.Open(filename, FileMode.Open)); try { // is it MacBinary? int fork_start = 0; int resourceOffset = MacBinaryHeader(reader.ReadBytes(128)); if (resourceOffset > 0) { fork_start = 128; resourceOffset = 128 + ((resourceOffset + 0x7f) & ~0x7f); } reader.BaseStream.Seek(fork_start, SeekOrigin.Begin); // read the header version = reader.ReadInt16(); DataVersion = reader.ReadInt16(); Filename = reader.ReadMacString(maxFilename); checksum = reader.ReadUInt32(); directoryOffset = reader.ReadInt32(); short wadCount = reader.ReadInt16(); applicationSpecificDirectoryDataSize = reader.ReadInt16(); entryHeaderSize = reader.ReadInt16(); directoryEntryBaseSize = reader.ReadInt16(); // sanity check the map if (Version < 2 || entryHeaderSize != 16 || directoryEntryBaseSize != 10) { throw new BadMapException("Only Marathon 2 and higher maps are supported"); } ParentChecksum = reader.ReadUInt32(); reader.ReadBytes(2 * 20); // unused // load the directory reader.BaseStream.Seek(directoryOffset + fork_start, SeekOrigin.Begin); for (int i = 0; i < wadCount; ++i) { DirectoryEntry entry = new DirectoryEntry(); entry.LoadEntry(reader); Directory[entry.Index] = entry; LoadApplicationSpecificDirectoryData(reader, entry.Index); } // load all the wads(!) foreach (KeyValuePair <int, DirectoryEntry> kvp in Directory) { reader.BaseStream.Seek(kvp.Value.Offset + fork_start, SeekOrigin.Begin); kvp.Value.LoadChunks(reader); } if (resourceOffset > 0) { reader.BaseStream.Seek(resourceOffset, SeekOrigin.Begin); UInt32 dataOffset = reader.ReadUInt32(); UInt32 mapOffset = reader.ReadUInt32(); UInt32 dataLength = reader.ReadUInt32(); UInt32 mapLength = reader.ReadUInt32(); Debug.Log(resourceOffset); Debug.Log(dataOffset); Debug.Log(mapOffset); Debug.Log(dataLength); Debug.Log(mapLength); dataOffset += (UInt32)resourceOffset; mapOffset += (UInt32)resourceOffset; ResourceMap resourceMap = new ResourceMap(); resourceMap.load(ref reader, mapOffset); for (int i = 0; i < resourceMap.refs.Count; i++) { string name = ""; if (resourceMap.refs[i].nameListOffset > 0) { reader.BaseStream.Seek(resourceMap.refs[i].nameListOffset + resourceMap.nameListOffset + mapOffset, SeekOrigin.Begin); int nameLength = reader.ReadByte(); name = reader.ReadMacString(nameLength); } if (resourceMap.refs[i].type == Pict.Tag || resourceMap.refs[i].type == Pict.Tag2) { Pict pict = new Pict(); reader.BaseStream.Seek(resourceMap.refs[i].dataOffset + dataOffset, SeekOrigin.Begin); pict.LoadWithName(reader, name); pictResources.Add(pict); } if (resourceMap.refs[i].type == Clut.Tag) { Clut clut = new Clut(); reader.BaseStream.Seek(resourceMap.refs[i].dataOffset + dataOffset, SeekOrigin.Begin); clut.Load(reader); clutResources.Add(clut); } if (resourceMap.refs[i].type == SoundResource.Tag) { SoundResource snd = new SoundResource(); reader.BaseStream.Seek(resourceMap.refs[i].dataOffset + dataOffset, SeekOrigin.Begin); snd.Load(reader); soundResources.Add(snd); } if (resourceMap.refs[i].type == TextResource.Tag || resourceMap.refs[i].type == TextResource.Tag2) { TextResource txt = new TextResource(); reader.BaseStream.Seek(resourceMap.refs[i].dataOffset + dataOffset, SeekOrigin.Begin); txt.Load(reader); textResources.Add(txt); } } } } finally { reader.Close(); } }