public override void Load(string filename) { using (FileStream file = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Delete | FileShare.ReadWrite)) { BinaryReader binReader = new BinaryReader(file); if (binReader.ReadTagType() != "INDX") throw new Exception(); DateTime time = DateTime.FromBinary(binReader.ReadInt64()); Offset = binReader.ReadInt32(); int count = binReader.ReadInt32(); Entries = new List<Entry>(count); for (int i = 0; i < count; i++) Entries.Add(new Entry() { Type = binReader.ReadTagType(), Index = binReader.ReadInt32(), Address = binReader.ReadInt32(), Length = binReader.ReadInt32() }); } }
public MapStream(string filename) : base(filename, FileMode.Open, FileAccess.Read, FileShare.Read) { this.MemoryBlocks = new MemoryMappedAddress[2]; //HEADER BinaryReader bin = new BinaryReader(this, Encoding.UTF8); this.Lock(0, 2048); this.Seek(0, SeekOrigin.Begin); if (bin.ReadTagClass() != (TagClass)"head") throw new InvalidDataException("Not a halo-map file"); //this.Seek(36, SeekOrigin.Begin); //var version = bin.ReadInt32(); //switch (version) //{ // case 0: // BuildVersion = Version.XBOX_RETAIL; // break; // case -1: // BuildVersion = Version.PC_RETAIL; // break; // default: //} BuildVersion = Version.PC_RETAIL; this.Seek(16, SeekOrigin.Begin); int indexAddress = bin.ReadInt32(); int indexLength = bin.ReadInt32(); int tagCacheLength = bin.ReadInt32(); if (BuildVersion == Version.PC_RETAIL) this.Seek(12, SeekOrigin.Current); this.Seek(332, SeekOrigin.Current); int stringTableLength = bin.ReadInt32(); this.Seek(4, SeekOrigin.Current); int stringTableAddress = bin.ReadInt32(); this.Seek(36, SeekOrigin.Current); MapName = bin.ReadFixedString(32); this.Seek(4, SeekOrigin.Current); Scenario = bin.ReadFixedString(256); this.Seek(4, SeekOrigin.Current); int pathsCount = bin.ReadInt32(); int pathsTableAddress = bin.ReadInt32(); int pathsTableLength = bin.ReadInt32(); this.Unlock(0, 2048); this.Seek(pathsTableAddress, SeekOrigin.Begin); var Paths = Encoding.UTF8.GetString(bin.ReadBytes(pathsTableLength - 1)).Split(char.MinValue); //STRINGS this.Seek(stringTableAddress, SeekOrigin.Begin); Strings = Encoding.UTF8.GetString(bin.ReadBytes(stringTableLength - 1)).Split(char.MinValue); // INDEX /* * Vista doesn't use memory addresses for the following address-values. (they are instead 0-based from the index-address) * * 0x00 Address to Classes array * 0x04 Classes array length * 0x08 Address to Tags array * 0x0C Scenario tag_id * 0x10 Match-Globals tag_id * 0x14 ~ * 0x18 Tags array length * 0xC0 'sgat' four_cc * * */ this.Seek(indexAddress, SeekOrigin.Begin); int tagClassTableVirtualAddress = bin.ReadInt32(); this.IndexVirtualAddress = tagClassTableVirtualAddress - 32; this.Seek(4, SeekOrigin.Current); int tagDatumTableVirtualAddress = bin.ReadInt32(); var ScenarioID = bin.ReadTagID(); var GlobalsID = bin.ReadTagID(); int tagDatumTableOffset = tagDatumTableVirtualAddress - tagClassTableVirtualAddress; this.Seek(4, SeekOrigin.Current); int tagDatumCount = bin.ReadInt32(); this.Seek(4 + tagDatumTableOffset, SeekOrigin.Current); Tags = new Tag[tagDatumCount]; for (int i = 0; i < tagDatumCount; i++) { Tags[i] = new Tag() { Type = bin.ReadTagType(), Identifier = bin.ReadInt32(), VirtualAddress = bin.ReadInt32(), Length = bin.ReadInt32() }; if (i == 0) { SecondaryMagic = Tags[0].VirtualAddress - (indexAddress + indexLength); } //Borky vista fix - broken paths are broken //if (Tags[i].VirtualAddress == 0) continue; //var tag = Tags[i]; //Tags[i].Path = Paths[Tags[i].Identifier.SaltedIndex]; } this.MemoryBlocks[1] = new MemoryMappedAddress() { Address = Tags[0].VirtualAddress, Length = tagCacheLength, Magic = SecondaryMagic, }; /* Intent: read the sbsp and lightmap address and lengths from the scenario tag * and store them in the Tags array. */ if (BuildVersion == Version.XBOX_RETAIL) { this.Seek(Tags[ScenarioID.Index].VirtualAddress - SecondaryMagic + 528, SeekOrigin.Begin); var count = bin.ReadInt32(); var address = bin.ReadInt32(); for (int i = 0; i < count; ++i) { this.Seek(address - SecondaryMagic + i * 68, SeekOrigin.Begin); var sbsp_offset = bin.ReadInt32(); var sbsp_length = bin.ReadInt32(); var sbsp_virtual_address = bin.ReadInt32(); if (i == 0) { this.PrimaryMagic = sbsp_virtual_address - sbsp_offset; this.MemoryBlocks[0].Address = sbsp_virtual_address; this.MemoryBlocks[0].Magic = this.PrimaryMagic; } this.MemoryBlocks[0].Length += sbsp_length; Seek(8, SeekOrigin.Current); var sbsp_identifier = bin.ReadTagID(); Seek(4, SeekOrigin.Current); var ltmp_identifier = bin.ReadTagID(); var ltmp_offset = bin.ReadInt32(); var ltmp_length = sbsp_offset + sbsp_length - ltmp_offset; Tags[sbsp_identifier.Index].VirtualAddress = sbsp_virtual_address; Tags[sbsp_identifier.Index].Length = sbsp_length - ltmp_length; if (ltmp_identifier != TagIdentifier.null_identifier) { Tags[ltmp_identifier.Index].VirtualAddress = sbsp_virtual_address + ltmp_offset; Tags[ltmp_identifier.Index].Length = ltmp_length; } } //UNICODE this.Seek(Tags[GlobalsID.Index].VirtualAddress - SecondaryMagic + 400, SeekOrigin.Begin); int unicodeCount = bin.ReadInt32(); int unicodeTableLength = bin.ReadInt32(); int unicodeIndexAddress = bin.ReadInt32(); int unicodeTableAddress = bin.ReadInt32(); Unicode = new UnicodeValueNamePair[unicodeCount]; StringID[] strRefs = new StringID[unicodeCount]; int[] strOffsets = new int[unicodeCount]; this.Seek(unicodeIndexAddress, SeekOrigin.Begin); for (int i = 0; i < unicodeCount; i++) { strRefs[i] = (StringID)bin.ReadInt32(); strOffsets[i] = bin.ReadInt32(); } for (int i = 0; i < unicodeCount; i++) { this.Seek(unicodeTableAddress + strOffsets[i], SeekOrigin.Begin); StringBuilder unicodeString = new StringBuilder(byte.MaxValue); while (bin.PeekChar() != char.MinValue) unicodeString.Append(bin.ReadChar()); Unicode[i] = new UnicodeValueNamePair { Name = strRefs[i], Value = unicodeString.ToString() }; } } }
public override void Load(string filename) { using (FileStream file = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete)) { BinaryReader binReader = new BinaryReader(file); if (binReader.ReadTagType() != "TAGN") throw new Exception(); DateTime time = DateTime.FromBinary(binReader.ReadInt64()); Offset = binReader.ReadInt32(); int count = binReader.ReadInt32(); Tagnames = new List<string>(count); for (int i = 0; i < count; i++) Tagnames.Add(binReader.ReadString()); } }
public override void Load(string filename) { using (FileStream file = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete)) { BinaryReader binReader = new BinaryReader(file); if (binReader.ReadTagType() != "UNIC") throw new Exception(); DateTime time = DateTime.FromBinary(binReader.ReadInt64()); Offset = binReader.ReadInt32(); int count = binReader.ReadInt32(); Values = new List<Entry>(count); for (int i = 0; i < count; i++) { Values.Add(new Entry() { StringId = binReader.ReadStringReference(), UnicodeString = binReader.ReadString() }); } } }
public override void Load(string filename) { using (FileStream file = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.None)) { BinaryReader binReader = new BinaryReader(file); if (binReader.ReadTagType() != "STRC") throw new Exception(); DateTime time = DateTime.FromBinary(binReader.ReadInt64()); Offset = binReader.ReadInt32(); int count = binReader.ReadInt32(); int indexAddress = binReader.ReadInt32(); int stringsLength = binReader.ReadInt32(); int stringsAddress = binReader.ReadInt32(); Values = new List<string>(count); int[] strIndices = new int[count]; file.Seek(indexAddress, SeekOrigin.Begin); for (int i = 0; i < count; i++) strIndices[i] = binReader.ReadInt32(); file.Seek(stringsAddress, SeekOrigin.Begin); for (int i = 0; i < count - 1; i++) { file.Seek(stringsAddress + strIndices[i], SeekOrigin.Begin); Values.Add(binReader.ReadUTF8String(strIndices[i + 1] - strIndices[i] - 1)); } file.Seek(stringsAddress + strIndices[strIndices.Length-1], SeekOrigin.Begin); Values.Add(binReader.ReadUTF8String(stringsLength - strIndices[strIndices.Length - 1] - 1)); } }
public override void Load(string filename) { using (FileStream file = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete)) { BinaryReader binReader = new BinaryReader(file); //Write Cache Header if (binReader.ReadTagType() != "RAWC") throw new Exception(); DateTime time = DateTime.FromBinary(binReader.ReadInt64()); Offset = binReader.ReadInt32(); int indexAddress = binReader.ReadInt32(); int count = binReader.ReadInt32(); int streamAddress = binReader.ReadInt32(); int streamLength = binReader.ReadInt32(); Tags = new List<Entry>(count); TagIDs = new List<int>(count); //Write Cache Index for (int i = 0; i < count; i++) { TagIDs.Add(binReader.ReadInt32()); Tags.Add(new Entry() { Offset = binReader.ReadInt32(), Length = binReader.ReadInt32() }); } //Write Cache Data file.Seek(streamAddress, SeekOrigin.Begin); Stream = new MemoryStream(binReader.ReadBytes(streamLength)); } }
public override void Load(string filename) { using (FileStream file = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Delete | FileShare.ReadWrite)) { BinaryReader binReader = new BinaryReader(file); if (binReader.ReadTagType() != "METC") throw new Exception(); DateTime time = DateTime.FromBinary(binReader.ReadInt64()); Offset = binReader.ReadInt32(); VirtualOffset = binReader.ReadInt32(); int indexAddress = binReader.ReadInt32(); int count = binReader.ReadInt32(); int streamAddress = binReader.ReadInt32(); int streamLength = binReader.ReadInt32(); TagIndexers = new List<int>(count); Entries = new List<Entry>(count); for (int i = 0; i < count; i++) { TagIndexers.Add(binReader.ReadInt32()); Entry e = new Entry(); e.Offset = binReader.ReadInt32(); e.Length = binReader.ReadInt32(); e.PointerOffsets = new int[binReader.ReadInt32()]; for (int x = 0; x < e.PointerOffsets.Length; x++) e.PointerOffsets[x] = binReader.ReadInt32(); e.RawOffsets = new int[binReader.ReadInt32()]; for (int x = 0; x < e.RawOffsets.Length; x++) e.RawOffsets[x] = binReader.ReadInt32(); e.StringIDOffsets = new int[binReader.ReadInt32()]; for (int x = 0; x < e.StringIDOffsets.Length; x++) e.StringIDOffsets[x] = binReader.ReadInt32(); e.TagIDOffsets = new int[binReader.ReadInt32()]; for (int x = 0; x < e.TagIDOffsets.Length; x++) e.TagIDOffsets[x] = binReader.ReadInt32(); Entries.Add(e); } file.Seek(streamAddress, SeekOrigin.Begin); Stream = new MemoryStream(binReader.ReadBytes(streamLength)); } }