예제 #1
0
 public SecondGenCacheFile(IReader reader, BuildInformation buildInfo, string buildString)
 {
     _buildInfo = buildInfo;
     _segmenter = new FileSegmenter(buildInfo.SegmentAlignment);
     Allocator = new MetaAllocator(this, 0x10000);
     Load(reader, buildInfo, buildString);
 }
예제 #2
0
		public ThirdGenCacheFile(IReader reader, EngineDescription buildInfo, string buildString)
		{
			_buildInfo = buildInfo;
			_segmenter = new FileSegmenter(buildInfo.SegmentAlignment);
			Allocator = new MetaAllocator(this, 0x10000);
			Load(reader, buildString);
		}
예제 #3
0
 /// <summary>
 ///     Gets an enumerable collection of FileSegments wrapping the segments in a FileSegmenter.
 /// </summary>
 /// <remarks>
 ///     Note that the returned segments will be newly allocated and will not have the same references as other wrapper
 ///     objects that have been created for the segmenter.
 /// </remarks>
 /// <returns>An enumerable collection of FileSegments for the segmenter.</returns>
 public static IEnumerable <FileSegment> GetWrappers(this FileSegmenter segmenter)
 {
     foreach (int segmentId in segmenter.Segments)
     {
         yield return(new FileSegment(segmentId, segmenter));
     }
 }
예제 #4
0
		private void Load(StructureValueCollection values, FileSegmenter segmenter)
		{
			_eofSegment = segmenter.WrapEOF((int) values.GetInteger("file size"));

			var metaOffset = (int) values.GetInteger("meta offset");
			var metaSize = (int) values.GetInteger("meta size");
			uint metaOffsetMask = values.GetInteger("meta offset mask");

			var metaSegment = new FileSegment(
				segmenter.DefineSegment(metaOffset, metaSize, 0x200, SegmentResizeOrigin.Beginning), segmenter);
			MetaArea = new FileSegmentGroup(new MetaOffsetConverter(metaSegment, metaOffsetMask));
			IndexHeaderLocation = MetaArea.AddSegment(metaSegment);

			Type = (CacheFileType) values.GetInteger("type");

			var headerGroup = new FileSegmentGroup();
			headerGroup.AddSegment(segmenter.WrapSegment(0, HeaderSize, 1, SegmentResizeOrigin.None));

			StringIDCount = (int) values.GetInteger("string table count");
			var sidDataSize = (int) values.GetInteger("string table size");
			StringIDData = segmenter.WrapSegment((int) values.GetInteger("string table offset"), sidDataSize, 1,
				SegmentResizeOrigin.End);
			StringIDIndexTable = segmenter.WrapSegment((int) values.GetInteger("string index table offset"), StringIDCount*4, 4,
				SegmentResizeOrigin.End);

			FileNameCount = (int) values.GetInteger("file table count");
			var fileDataSize = (int) values.GetInteger("file table size");
			FileNameData = segmenter.WrapSegment((int) values.GetInteger("file table offset"), fileDataSize, 1,
				SegmentResizeOrigin.End);
			FileNameIndexTable = segmenter.WrapSegment((int) values.GetInteger("file index table offset"), FileNameCount*4, 4,
				SegmentResizeOrigin.End);

			InternalName = values.GetString("internal name");
			ScenarioName = values.GetString("scenario name");

			StringArea = new FileSegmentGroup();
			StringArea.AddSegment(segmenter.WrapSegment((int) values.GetInteger("string block offset"), StringIDCount*0x80, 0x80,
				SegmentResizeOrigin.End));
			StringArea.AddSegment(StringIDIndexTable);
			StringArea.AddSegment(StringIDData);
			StringArea.AddSegment(FileNameIndexTable);
			StringArea.AddSegment(FileNameData);

			StringIDIndexTableLocation = SegmentPointer.FromOffset(StringIDIndexTable.Offset, StringArea);
			StringIDDataLocation = SegmentPointer.FromOffset(StringIDData.Offset, StringArea);
			FileNameIndexTableLocation = SegmentPointer.FromOffset(FileNameIndexTable.Offset, StringArea);
			FileNameDataLocation = SegmentPointer.FromOffset(FileNameData.Offset, StringArea);

			LocaleArea = new FileSegmentGroup();

			var rawTableOffset = (int) values.GetInteger("raw table offset");
			var rawTableSize = (int) values.GetInteger("raw table size");
			RawTable = segmenter.WrapSegment(rawTableOffset, rawTableSize, 1, SegmentResizeOrigin.End);

			Checksum = values.GetInteger("checksum");

			// Set up a bogus partition table
			Partitions = new Partition[1];
			Partitions[0] = new Partition(SegmentPointer.FromOffset(MetaArea.Offset, MetaArea), (uint) MetaArea.Size);
		}
예제 #5
0
        public FourthGenCacheFile(IReader map_reader, IReader tag_reader, IReader string_reader, IReader tagnames_reader, EngineDescription buildInfo, string buildString)
		{
			_buildInfo = buildInfo;
			_segmenter = new FileSegmenter(buildInfo.SegmentAlignment);
			Allocator = new MetaAllocator(this, 0x10000);
            Load(map_reader, tag_reader, string_reader, tagnames_reader, buildString);
		}
예제 #6
0
        public ThirdGenHeader(StructureValueCollection values, EngineDescription info, string buildString,
			FileSegmenter segmenter)
        {
            BuildString = buildString;
            HeaderSize = info.HeaderSize;
            Load(values, segmenter);
        }
        public ThirdGenLanguageGlobals(StructureValueCollection values, FileSegmenter segmenter, IPointerConverter localePointerConverter, BuildInformation buildInfo)
        {
            LocaleArea = new FileSegmentGroup(localePointerConverter);

            _languages = LoadLanguages(values, segmenter, buildInfo);
            _alignment = buildInfo.SegmentAlignment;
        }
        private List<ThirdGenLanguage> LoadLanguages(StructureValueCollection values, FileSegmenter segmenter, BuildInformation buildInfo)
        {
            StructureValueCollection[] languageSet = values.GetArray("languages");

            var result = from language in languageSet
                         select new ThirdGenLanguage(language, segmenter, LocaleArea, buildInfo);
            return result.ToList<ThirdGenLanguage>();
        }
예제 #9
0
        public FourthGenHeader(StructureValueCollection map_values, StructureValueCollection tag_values, StructureValueCollection string_values, EngineDescription info, string buildString,
			FileSegmenter segmenter)
		{
            EngineInfo = info;
			BuildString = buildString;
			HeaderSize = info.HeaderSize;
            Load(map_values, tag_values, string_values, segmenter);
		}
예제 #10
0
        public ThirdGenLanguage(GameLanguage language, StructureValueCollection values, FileSegmenter segmenter,
			FileSegmentGroup localeArea, EngineDescription buildInfo)
        {
            Language = language;
            _pointerLayout = buildInfo.Layouts.GetLayout("locale index table entry");
            _encryptionKey = buildInfo.LocaleKey;
            _sizeAlign = (_encryptionKey != null) ? AES.BlockSize : 1;
            Load(values, segmenter, localeArea);
        }
예제 #11
0
        private List<ThirdGenLanguage> LoadLanguages(StructureValueCollection values, FileSegmenter segmenter,
			EngineDescription buildInfo)
        {
            StructureValueCollection[] languageSet = values.GetArray("languages");

            IEnumerable<ThirdGenLanguage> result =
                languageSet.Select((l, i) => new ThirdGenLanguage((GameLanguage) i, l, segmenter, LocaleArea, buildInfo));
            return result.ToList();
        }
예제 #12
0
 public ThirdGenLanguage(StructureValueCollection values, FileSegmenter segmenter, FileSegmentGroup localeArea, BuildInformation buildInfo)
 {
     _pointerLayout = buildInfo.GetLayout("locale index table entry");
     _encryptionKey = buildInfo.LocaleKey;
     _symbols = buildInfo.LocaleSymbols;
     _localeArea = localeArea;
     _sizeAlign = (_encryptionKey != null) ? AES.BlockSize : 1;
     Load(values, segmenter, localeArea);
 }
예제 #13
0
		private List<FourthGenLanguage> LoadLanguages(StructureValueCollection values, FileSegmenter segmenter,
			EngineDescription buildInfo)
		{
			StructureValueCollection[] languageSet = values.GetArray("languages");

            List<FourthGenLanguage> list = new List<FourthGenLanguage>();

            for(int i=0;i<languageSet.Length;i++) list.Add(new FourthGenLanguage((GameLanguage) i, languageSet[i], segmenter, LocaleArea, buildInfo));


			//IEnumerable<FourthGenLanguage> result = languageSet.Select((l, i) => new FourthGenLanguage((GameLanguage) i, l, segmenter, LocaleArea, buildInfo));
            //return result.ToList();
            return list;
		}
예제 #14
0
		private void Load(StructureValueCollection values, FileSegmenter segmenter, FileSegmentGroup localeArea)
		{
			StringCount = (int) values.GetInteger("string count");
			if (StringCount > 0)
			{
				// Index table offset, segment, and pointer
				int localeIndexTableOffset = localeArea.PointerToOffset(values.GetInteger("locale index table offset"));
				LocaleIndexTable = segmenter.WrapSegment(localeIndexTableOffset, StringCount*8, 8, SegmentResizeOrigin.End);
				LocaleIndexTableLocation = localeArea.AddSegment(LocaleIndexTable);

				// Data offset, segment, and pointer
				int localeDataOffset = localeArea.PointerToOffset(values.GetInteger("locale data index offset"));
				var localeDataSize = (int) values.GetInteger("locale table size");
				LocaleData = segmenter.WrapSegment(localeDataOffset, localeDataSize, _sizeAlign, SegmentResizeOrigin.End);
				LocaleDataLocation = localeArea.AddSegment(LocaleData);

				// Load hashes if they exist
				if (values.HasRaw("index table hash"))
					IndexTableHash = values.GetRaw("index table hash");
				if (values.HasRaw("string data hash"))
					StringDataHash = values.GetRaw("string data hash");
			}
		}
예제 #15
0
        private void Load(StructureValueCollection values, FileSegmenter segmenter)
        {
            segmenter.DefineSegment(0, HeaderSize, 1, SegmentResizeOrigin.Beginning); // Define a segment for the header
            _eofSegment = segmenter.WrapEOF((int) values.GetInteger("file size"));

            LoadInteropData(values);
            RawTable = CalculateRawTableSegment(segmenter);

            Type = (CacheFileType) values.GetInteger("type");
            InternalName = values.GetString("internal name");
            ScenarioName = values.GetString("scenario name");
            XDKVersion = (int) values.GetInteger("xdk version");

            FileSegment metaSegment = CalculateTagDataSegment(values, segmenter);
            if (metaSegment != null)
            {
                uint virtualBase = values.GetInteger("virtual base address");
                MetaArea = new FileSegmentGroup(new MetaAddressConverter(metaSegment, virtualBase));
                MetaArea.AddSegment(metaSegment);

                IndexHeaderLocation = SegmentPointer.FromPointer(values.GetInteger("index header address"), MetaArea);
                Partitions = LoadPartitions(values.GetArray("partitions"));
            }
            else
            {
                Partitions = new Partition[0];
            }

            CalculateStringGroup(values, segmenter);
        }
예제 #16
0
 private FileSegment CalculateTagDataSegment(StructureValueCollection values, FileSegmenter segmenter)
 {
     if (TagBufferPointerConverter != null)
     {
         int tagDataOffset = TagBufferPointerConverter.PointerToOffset(TagBufferPointerConverter.BasePointer);
         var tagDataSize = (int) values.GetInteger("virtual size");
         return segmenter.WrapSegment(tagDataOffset, tagDataSize, 0x10000, SegmentResizeOrigin.Beginning);
     }
     return null;
 }
예제 #17
0
        private void CalculateStringGroup(StructureValueCollection values, FileSegmenter segmenter)
        {
            if (DebugPointerConverter == null)
                return;

            StringArea = new FileSegmentGroup(DebugPointerConverter);

            // StringIDs
            StringIDCount = (int) values.GetInteger("string table count");
            if (StringIDCount > 0)
            {
                int sidIndexTableOff = DebugPointerConverter.PointerToOffset(values.GetInteger("string index table offset"));
                int sidDataOff = DebugPointerConverter.PointerToOffset(values.GetInteger("string table offset"));

                var sidTableSize = (int) values.GetInteger("string table size");
                StringIDIndexTable = segmenter.WrapSegment(sidIndexTableOff, StringIDCount*4, 4, SegmentResizeOrigin.End);
                StringIDData = segmenter.WrapSegment(sidDataOff, sidTableSize, 1, SegmentResizeOrigin.End);

                StringIDIndexTableLocation = StringArea.AddSegment(StringIDIndexTable);
                StringIDDataLocation = StringArea.AddSegment(StringIDData);

                // idk what this is, but H3Beta has it
                if (values.HasInteger("string block offset"))
                {
                    int sidBlockOff = DebugPointerConverter.PointerToOffset(values.GetInteger("string block offset"));
                    StringBlock = segmenter.WrapSegment(sidBlockOff, StringIDCount*0x80, 0x80, SegmentResizeOrigin.End);
                    StringBlockLocation = StringArea.AddSegment(StringBlock);
                }
            }

            // Tag names
            FileNameCount = (int) values.GetInteger("file table count");
            if (FileNameCount > 0)
            {
                int nameIndexTableOff = DebugPointerConverter.PointerToOffset(values.GetInteger("file index table offset"));
                int nameDataOff = DebugPointerConverter.PointerToOffset(values.GetInteger("file table offset"));

                var fileTableSize = (int) values.GetInteger("file table size");
                FileNameIndexTable = segmenter.WrapSegment(nameIndexTableOff, FileNameCount*4, 4, SegmentResizeOrigin.End);
                FileNameData = segmenter.WrapSegment(nameDataOff, fileTableSize, 1, SegmentResizeOrigin.End);

                FileNameIndexTableLocation = StringArea.AddSegment(FileNameIndexTable);
                FileNameDataLocation = StringArea.AddSegment(FileNameData);
            }

            // Some H4-only unknown table
            if (values.HasInteger("unknown table count") && values.HasInteger("unknown table offset"))
            {
                UnknownCount = (int) values.GetInteger("unknown table count");
                if (UnknownCount > 0)
                {
                    int unknownOff = DebugPointerConverter.PointerToOffset(values.GetInteger("unknown table offset"));
                    UnknownTable = segmenter.WrapSegment(unknownOff, UnknownCount*0x10, 0x10, SegmentResizeOrigin.End);
                    UnknownTableLocation = StringArea.AddSegment(UnknownTable);
                }
            }
        }
예제 #18
0
 private FileSegment CalculateRawTableSegment(FileSegmenter segmenter)
 {
     if (ResourcePointerConverter != null)
     {
         int rawTableOffset = ResourcePointerConverter.PointerToOffset(ResourcePointerConverter.BasePointer);
         var rawTableSize = (int) Sections[(int) ThirdGenInteropSectionType.Resource].Size;
         return segmenter.WrapSegment(rawTableOffset, rawTableSize, 0x1000, SegmentResizeOrigin.End);
     }
     return null;
 }
예제 #19
0
        private FileSegment CalculateMetaSegment(StructureValueCollection values, FileSegmenter segmenter)
        {
            int metaSize = (int)values.GetInteger("virtual size");
            if (metaSize == 0)
                return null;

            int metaOffset = CalculateMetaOffset(values);
            if (metaOffset == 0)
                return null;

            return segmenter.WrapSegment(metaOffset, metaSize, 0x10000, SegmentResizeOrigin.Beginning);
        }
예제 #20
0
        private FileSegment CalculateRawTableSegment(StructureValueCollection values, FileSegmenter segmenter)
        {
            // WAT. H3BETA DOESN'T HAVE THIS. WAT.
            if (values.HasInteger("raw table size") && values.HasInteger("raw table offset"))
            {
                // Load the basic values
                int rawTableSize = (int)values.GetInteger("raw table size");
                int rawTableOffset = (int)values.GetInteger("raw table offset");
                _originalRawTableOffset = rawTableOffset;

                // If the original raw table offset was 0, load it from the alternate pointer
                if (rawTableOffset == 0)
                    rawTableOffset = (int)values.GetInteger("alternate raw table offset");

                return segmenter.WrapSegment(rawTableOffset, rawTableSize, 0x1000, SegmentResizeOrigin.End);
            }
            else
            {
                return null;
            }
        }
예제 #21
0
 public SecondGenHeader(StructureValueCollection values, BuildInformation info, string buildString, FileSegmenter segmenter)
 {
     BuildString = buildString;
     HeaderSize = info.HeaderSize;
     Load(values, segmenter);
 }
예제 #22
0
 public ThirdGenCacheFile(IReader reader, BuildInformation buildInfo, string buildString)
 {
     _buildInfo = buildInfo;
     _segmenter = new FileSegmenter(buildInfo.SegmentAlignment);
     Load(reader, buildString);
 }
예제 #23
0
		/// <summary>
		///     Adds a tag to the table and allocates space for its base data.
		/// </summary>
		/// <param name="classMagic">The magic number (ID) of the tag's class.</param>
		/// <param name="baseSize">The size of the data to initially allocate for the tag.</param>
		/// <param name="stream">The stream to write to.</param>
		/// <returns>
		///     The tag that was allocated.
		/// </returns>
		public override ITag AddTag(int classMagic, int baseSize, IStream stream)
		{
            /*
			//if (_indexHeaderLocation == null)
			//	throw new InvalidOperationException("Tags cannot be added to a shared map");

			ITagClass tagClass = Classes.FirstOrDefault(c => (c.Magic == classMagic));
			if (tagClass == null)
				throw new InvalidOperationException("Invalid tag class");

			uint address = _allocator.Allocate(baseSize, stream);
			var index = new DatumIndex(0x4153, (ushort) _tags.Count); // 0x4153 = 'AS' because the salt doesn't matter
            var result = new FourthGenTag(index, tagClass, (uint)stream.Position);
			_tags.Add(result);

			return result;
             * */

            ITagClass tagClass = Classes.FirstOrDefault(c => (c.Magic == classMagic));
            if (tagClass == null)
                throw new InvalidOperationException("Invalid tag class");

            var offset = stream.BaseStream.Position;
            uint address = _allocator.Allocate(baseSize, stream);
            var index = new DatumIndex(0x4153, (ushort)_tags.Count); // 0x4153 = 'AS' because the salt doesn't matter

            // File Segment
            FileSegmenter segmenter = new FileSegmenter();
            segmenter.DefineSegment(0, (int)stream.Length, 0x4, SegmentResizeOrigin.Beginning); // Define a segment for the header
            //_eofSegment = segmenter.WrapEOF((int)map_values.GetInteger("file size"));
            FileSegment segment = new FileSegment(0, segmenter);
            FileSegmentGroup segmentgroup = new FileSegmentGroup();

            SegmentPointer pointer = new SegmentPointer(segment, segmentgroup, (int)offset);
            FourthGenTag result = new FourthGenTag(index, tagClass, pointer, pointer);

            _tags.Add(result);

            return result;
		}
예제 #24
0
 /// <summary>
 ///     Constructs a new FileSegment, wrapping a segment ID in a FileSegmenter.
 /// </summary>
 /// <param name="id">The ID of the segment to wrap.</param>
 /// <param name="segmenter">The FileSegmenter that the segment belongs to.</param>
 public FileSegment(int id, FileSegmenter segmenter)
 {
     ID         = id;
     _segmenter = segmenter;
     _segmenter.SegmentResized += SegmentResized;
 }
예제 #25
0
 /// <summary>
 ///     Defines a segment and returns a FileSegment that wraps it.
 /// </summary>
 /// <param name="offset">The offset at which the segment starts.</param>
 /// <param name="size">The size of the segment.</param>
 /// <param name="offsetAlignment">A power of two which the offset must be a multiple of (e.g. 0x1000 = 4kb-aligned).</param>
 /// <param name="sizeAlignment">A power of two which the size must be a multiple of (e.g. 0x1000 = 4kb-aligned).</param>
 /// <param name="resizeOrigin">The origin at which to insert/remove data in the segment.</param>
 /// <returns>The segment's ID number which can be used to retrieve information about it.</returns>
 public static FileSegment WrapSegment(this FileSegmenter segmenter, int offset, int size, int offsetAlignment,
                                       int sizeAlignment, SegmentResizeOrigin resizeOrigin)
 {
     return(new FileSegment(segmenter.DefineSegment(offset, size, offsetAlignment, sizeAlignment, resizeOrigin), segmenter));
 }
예제 #26
0
 /// <summary>
 ///     Defines an empty segment in the file representing the end of the file and returns a FileSegment that wraps it.
 /// </summary>
 /// <param name="offset">The offset of the end of the file.</param>
 /// <param name="alignment">The file's size alignment.</param>
 /// <returns>The segment's ID number which can be used to retrieve information about it.</returns>
 public static FileSegment WrapEOF(this FileSegmenter segmenter, int offset, int alignment)
 {
     return(new FileSegment(segmenter.DefineEOF(offset, alignment), segmenter));
 }
예제 #27
0
        public ThirdGenLanguageGlobals(StructureValueCollection values, FileSegmenter segmenter,
			IPointerConverter localePointerConverter, EngineDescription buildInfo)
        {
            LocaleArea = new FileSegmentGroup(localePointerConverter);
            Languages = LoadLanguages(values, segmenter, buildInfo);
        }
예제 #28
0
        /*
		private void AdjustPartitions()
		{
			if (MetaArea == null)
				return;

			// Find the first partition with a non-null address and change it to the meta area's base address
			Partition partition = Partitions.First(p => p.BasePointer != null);
			if (partition != null)
				partition.BasePointer = SegmentPointer.FromPointer(MetaArea.BasePointer, MetaArea);

			// Recalculate the size of each partition
			int partitionEnd = MetaArea.Offset + MetaArea.Size;
			for (int i = Partitions.Length - 1; i >= 0; i--)
			{
				if (Partitions[i].BasePointer == null)
					continue;

				int offset = Partitions[i].BasePointer.AsOffset();
				Partitions[i].Size = (uint) (partitionEnd - offset);
				partitionEnd = offset;
			}
		}
        */

        /*
		private StructureValueCollection[] SerializePartitions()
		{
			if (Partitions == null)
				return new StructureValueCollection[0];

			var results = new StructureValueCollection[Partitions.Length];
			for (int i = 0; i < Partitions.Length; i++)
			{
				var values = new StructureValueCollection();
				values.SetInteger("load address", Partitions[i].BasePointer != null ? Partitions[i].BasePointer.AsPointer() : 0);
				values.SetInteger("size", Partitions[i].Size);
				results[i] = values;
			}
			return results;
		}
        */

		/// <summary>
		///     Rebuilds the interop data table in a cache file.
		/// </summary>
		/// <param name="localeArea">The localization area of the file.</param>
        /*
		private void RebuildInteropData(FileSegmentGroup localeArea)
		{
            
			FourthGenInteropSection debugSection = Sections[(int) FourthGenInteropSectionType.Debug];
			FourthGenInteropSection rsrcSection = Sections[(int) FourthGenInteropSectionType.Resource];
			FourthGenInteropSection tagSection = Sections[(int) FourthGenInteropSectionType.Tag];
			FourthGenInteropSection localeSection = Sections[(int) FourthGenInteropSectionType.Localization];
            
			// Recompute base addresses
			// Section addresses are usually in the following order: resource, locale, tag, debug.
			// Each address can immediately follow after the previous non-null section,
			// even though this isn't the case in some of the official files (because of removed debug data).
			//
			// TODO: This could possibly be made into a for loop and cleaned up if the pointer converters are stored in an array.
			// I just want to get this working for now.
			rsrcSection.VirtualAddress = 0; // This is always zero
			rsrcSection.Size = (ResourcePointerConverter != null) ? (uint) RawTable.Size : 0;
			localeSection.VirtualAddress = (LocalePointerConverter != null) ? rsrcSection.VirtualAddress + rsrcSection.Size : 0;
			localeSection.Size = (LocalePointerConverter != null) ? (uint) localeArea.Size : 0;
			tagSection.VirtualAddress = (TagBufferPointerConverter != null)
				? rsrcSection.VirtualAddress + rsrcSection.Size + localeSection.Size
				: 0;
			tagSection.Size = (TagBufferPointerConverter != null) ? (uint) MetaArea.Size : 0;
			debugSection.VirtualAddress = (DebugPointerConverter != null)
				? rsrcSection.VirtualAddress + rsrcSection.Size + localeSection.Size + tagSection.Size
				: 0;
			debugSection.Size = (DebugPointerConverter != null) ? (uint) StringArea.Size : 0;

			// If the offset mask for the debug section wasn't originally zero, then we have to subtract the first partition size from the debug base address
			// Not entirely sure why this is the case, but that's what the official files do
			if (debugSection.VirtualAddress != 0 && SectionOffsetMasks[(int) FourthGenInteropSectionType.Debug] != 0)
				debugSection.VirtualAddress -= Partitions[0].Size;

			// Recompute offset masks
			SectionOffsetMasks[(int) FourthGenInteropSectionType.Debug] = (debugSection.Size > 0)
				? (uint) (StringArea.Offset - debugSection.VirtualAddress)
				: 0;
			SectionOffsetMasks[(int) FourthGenInteropSectionType.Resource] = (rsrcSection.Size > 0)
				? (uint) (RawTable.Offset - rsrcSection.VirtualAddress)
				: 0;
			SectionOffsetMasks[(int) FourthGenInteropSectionType.Tag] = (tagSection.Size > 0)
				? (uint) (MetaArea.Offset - tagSection.VirtualAddress)
				: 0;
			SectionOffsetMasks[(int) FourthGenInteropSectionType.Localization] = (localeSection.Size > 0)
				? (uint) (localeArea.Offset - localeSection.VirtualAddress)
				: 0;

			// Update pointer converters
			if (DebugPointerConverter != null)
				DebugPointerConverter.BasePointer = debugSection.VirtualAddress;
			if (ResourcePointerConverter != null)
				ResourcePointerConverter.BasePointer = rsrcSection.VirtualAddress;
			if (TagBufferPointerConverter != null)
				TagBufferPointerConverter.BasePointer = tagSection.VirtualAddress;
			if (LocalePointerConverter != null)
				LocalePointerConverter.BasePointer = localeSection.VirtualAddress;
		}
        */

        private void Load(StructureValueCollection map_values, StructureValueCollection tag_values, StructureValueCollection string_values, FileSegmenter map_segmenter)
		{
            map_segmenter.DefineSegment(0, HeaderSize, 1, SegmentResizeOrigin.Beginning); // Define a segment for the header
            _eofSegment = map_segmenter.WrapEOF((int)map_values.GetInteger("file size"));



            //LoadInteropData(map_values, tag_values);
			//RawTable = CalculateRawTableSegment(segmenter);

            Type = (CacheFileType)map_values.GetInteger("type");
            InternalName = map_values.GetString("internal name");
            ScenarioPath = map_values.GetString("scenario path");

            uint index_header_address = map_values.GetInteger("index header address");

            // File Segment
            FileSegmenter tags_segmenter = new FileSegmenter();
            tags_segmenter.DefineSegment(0, (int)EngineInfo.TagsDataSize, 0x1, SegmentResizeOrigin.Beginning); // Define a segment for the header
            FileSegment metaSegment = new FileSegment(0, tags_segmenter);

            //FileSegment metaSegment = CalculateTagDataSegment(tag_values, segmenter);
            MetaArea = new FileSegmentGroup(new MetaAddressConverter(metaSegment, index_header_address));
            MetaArea.AddSegment(metaSegment);
            IndexHeaderLocation = SegmentPointer.FromPointer(index_header_address, MetaArea);

			//XDKVersion = (int) values.GetInteger("xdk version");
            /*
			FileSegment metaSegment = CalculateTagDataSegment(values, segmenter);
			if (metaSegment != null)
			{
				uint virtualBase = values.GetInteger("virtual base address");
				MetaArea = new FileSegmentGroup(new MetaAddressConverter(metaSegment, virtualBase));
				MetaArea.AddSegment(metaSegment);

				IndexHeaderLocation = SegmentPointer.FromPointer(values.GetInteger("index header address"), MetaArea);
				Partitions = LoadPartitions(values.GetArray("partitions"));
			}
			else
			{
				Partitions = new Partition[0];
			}
            */
            CalculateStringGroup(string_values, map_segmenter);
		}
예제 #29
0
		/// <summary>
		///     Constructs a new FileSegment, wrapping a segment ID in a FileSegmenter.
		/// </summary>
		/// <param name="id">The ID of the segment to wrap.</param>
		/// <param name="segmenter">The FileSegmenter that the segment belongs to.</param>
		public FileSegment(int id, FileSegmenter segmenter)
		{
			ID = id;
			_segmenter = segmenter;
			_segmenter.SegmentResized += SegmentResized;
		}
예제 #30
0
		private List<ITag> LoadTags(IReader reader, StructureValueCollection headerValues, IList<ITagClass> classes)
		{
            /*
            StructureLayout layout = _buildInfo.Layouts.GetLayout("tag entry");
			StructureValueCollection[] entries = ReflexiveReader.ReadReflexive(reader, count, address, layout, _metaArea);
			return
				entries.Select<StructureValueCollection, ITag>((e, i) => new FourthGenTag(e, (ushort) i, _metaArea, classes))
					.ToList();
             */

            List<ITag> tags = new List<ITag>(); // New list of tags
            reader.SeekTo(0);
            var count = (int) headerValues.GetInteger("number of tags");
			uint address = headerValues.GetInteger("tag table address");
            StructureLayout layout = _buildInfo.Layouts.GetLayout("tag entry");

            // File Segment
            FileSegmenter segmenter = new FileSegmenter();
            segmenter.DefineSegment(0, (int)reader.Length, 0x4, SegmentResizeOrigin.Beginning); // Define a segment for the header
            //_eofSegment = segmenter.WrapEOF((int)map_values.GetInteger("file size"));
            FileSegment segment = new FileSegment(0, segmenter);
            FileSegmentGroup segmentgroup = new FileSegmentGroup();

            // Find all of the tag offsets
            reader.BaseStream.Position = address; // Start at the beginning og the offsets
            List<uint> tagOffsets = new List<uint>();
            for (int i = 0; i < count; i++) tagOffsets.Add(reader.ReadUInt32());

            reader.BaseStream.Position = tagOffsets[0];
            for (int i = 0; i < count; i++) // Loop through each offset
            {
                //if (tagOffsets[i] == 0) tags.Add(null);
                //else
                if (tagOffsets[i] != 0)
                {
                    //var headerOffset = (uint)reader.BaseStream.Position;
                    /*
                    var checksum = reader.ReadUInt32();                         // 0x00 uint32 checksum?
                    var totalSize = reader.ReadUInt32();                        // 0x04 uint32 total size
                    var numDependencies = reader.ReadInt16();                   // 0x08 int16  dependencies count
                    var numDataFixups = reader.ReadInt16();                     // 0x0A int16  data fixup count
                    var numResourceFixups = reader.ReadInt16();                 // 0x0C int16  resource fixup count
                    reader.BaseStream.Position += 2;                            // 0x0E int16  (padding)
                    var mainStructOffset = reader.ReadUInt32();                 // 0x10 uint32 main struct offset
                    var tagClass = reader.ReadInt32();                          // 0x14 int32  class
                    var parentClass = reader.ReadInt32();                       // 0x18 int32  parent class
                    var grandparentClass = reader.ReadInt32();                  // 0x1C int32  grandparent class
                    var classId = reader.ReadUInt32();                          // 0x20 uint32 class stringid
                    */
                    /*

                    reader.BaseStream.Position = tagOffsets[i];
                    StructureValueCollection tag_entry_values = StructureReader.ReadStructure(reader, layout);
                    uint id = tag_entry_values.GetInteger("magic");
                    if(id == 0x3c66783e )
                    {
                        uint x = id;
                    }
                    //ITagClass tagclass = TryAddClass(tag_entry_values);
                    //FourthGenTag tag = new FourthGenTag(new DatumIndex(headerOffset), tagclass, headerOffset);

                    uint tag_offset = tagOffsets[i];
                    //SegmentPointer pointer = new SegmentPointer(segment, segmentgroup, (int)tag_offset);

                    uint dep_size = (tag_entry_values.GetInteger("dependencies count") * 4 + tag_entry_values.GetInteger("data fixups count") * 4 + tag_entry_values.GetInteger("resource fixups count") * 4);
                    tag_offset += tag_entry_values.GetInteger("total size") - (tag_entry_values.GetInteger("main struct offset") + dep_size);

                    ITagClass tagclass = TryAddClass(tag_entry_values);
                    //FourthGenTag tag = new FourthGenTag(new DatumIndex(headerOffset), tagclass, headerOffset);

                    SegmentPointer pointer = new SegmentPointer(segment, segmentgroup, (int)(tag_offset));

                    FourthGenTag tag = new FourthGenTag(new DatumIndex(tag_offset), tagclass, pointer);
                    tags.Add(tag);
                     * */

                    var headerOffset = tagOffsets[i];
                    reader.BaseStream.Position = headerOffset;

                    StructureValueCollection tag_entry_values = StructureReader.ReadStructure(reader, layout);

                    reader.BaseStream.Position = tagOffsets[i] + 0x24;

                    int structOffset = (int)tag_entry_values.GetInteger("main struct offset");
                    int metaOffset = (int)tagOffsets[i] + structOffset;

                    ITagClass tagclass = TryAddClass(tag_entry_values);

                    //SegmentPointer pointer = new SegmentPointer(segment, segmentgroup, metaOffset);
                    //FourthGenTag tag = new FourthGenTag(new DatumIndex((uint)i), tagclass, pointer);
                    SegmentPointer hdrPointer = new SegmentPointer(segment, segmentgroup, (int)headerOffset);
                    SegmentPointer pointer = new SegmentPointer(segment, segmentgroup, metaOffset);
                    FourthGenTag tag = new FourthGenTag(new DatumIndex((uint)i), tagclass, hdrPointer, pointer);
                    tags.Add(tag);
                }
                else // Null Tag
                {
                    FourthGenTag tag = new FourthGenTag(new DatumIndex((uint)i), null, null, null);
                    tags.Add(tag);
                }
            }

            return tags.Where(t => t != null).ToList(); // Remove NULL Entries
		}